~ubuntu-branches/ubuntu/utopic/lebiniou/utopic

« back to all changes in this revision

Viewing changes to plugins/stable/output/erlang/v7.c

  • Committer: Package Import Robot
  • Author(s): Olivier Girondel
  • Date: 2011-10-22 21:04:28 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20111022210428-98wk8rbx1mj3wuzo
Tags: 3.13-1
* New upstream release 3.13.
* Put all library flags in LIBS instead of LDFLAGS. (Closes: #647100)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright 1994-2011 Olivier Girondel
 
3
 *
 
4
 *  This file is part of lebiniou.
 
5
 *
 
6
 *  lebiniou is free software: you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation, either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  lebiniou is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with lebiniou. If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "erlang.h"
 
21
 
 
22
/*
 
23
 * Protocol v7:
 
24
 *
 
25
 * Input:
 
26
 * Output:
 
27
 *  [C][To, Cmd, Arg]        // keyboard command
 
28
 *  [U][C|P|S][uint32_t id]  // update event
 
29
 */
 
30
 
 
31
extern int write_exact(const u_char *, const int);
 
32
 
 
33
 
 
34
extern uint32_t last_colormap;
 
35
extern uint32_t last_picture;
 
36
extern uint32_t last_sequence;
 
37
 
 
38
extern char send_colormap_update;
 
39
extern char send_picture_update;
 
40
extern char send_sequence_update;
 
41
 
 
42
 
 
43
static void
 
44
v7_send_event(const Event_t *e)
 
45
{
 
46
  uint32_t proto = 7, proto2;
 
47
  uint32_t total, total2;
 
48
  Pixel_t *src;
 
49
  u_char val;
 
50
  int ret;
 
51
 
 
52
  /* send packet size */
 
53
  total = sizeof(uint32_t)+4*sizeof(u_char);
 
54
  total2 = htonl(total);
 
55
  ret = write_exact((const u_char *)&total2, sizeof(uint32_t));
 
56
 
 
57
  /* protocol version */
 
58
  proto2 = htonl(proto);
 
59
  ret = write_exact((const u_char *)&proto2, sizeof(uint32_t));
 
60
 
 
61
  val = 'C';
 
62
  ret = write_exact(&val, sizeof(u_char));
 
63
  val = e->to;
 
64
  ret = write_exact(&val, sizeof(u_char));
 
65
  val = e->cmd;
 
66
  ret = write_exact(&val, sizeof(u_char));
 
67
  val = e->arg0;
 
68
  ret = write_exact(&val, sizeof(u_char));
 
69
}
 
70
 
 
71
 
 
72
static void
 
73
v7_send_events(Context_t *ctx)
 
74
{
 
75
  GList *t;
 
76
 
 
77
  for (t = ctx->events; t != NULL; t = g_list_next(t)) {
 
78
    Event_t *e = (Event_t *)t->data;
 
79
    v7_send_event(e);
 
80
  }
 
81
}
 
82
 
 
83
 
 
84
static void
 
85
v7_send_id(const u_char what, const uint32_t id)
 
86
{
 
87
  uint32_t proto = 7, proto2;
 
88
  uint32_t total, total2;
 
89
  uint32_t id2;
 
90
  Pixel_t *src;
 
91
  u_char val;
 
92
  int ret;
 
93
 
 
94
  /* send packet size */
 
95
  total = sizeof(uint32_t)+2*sizeof(u_char)+sizeof(uint32_t);
 
96
  total2 = htonl(total);
 
97
  ret = write_exact((const u_char *)&total2, sizeof(uint32_t));
 
98
 
 
99
  /* protocol version */
 
100
  proto2 = htonl(proto);
 
101
  ret = write_exact((const u_char *)&proto2, sizeof(uint32_t));
 
102
 
 
103
  val = UPDATE_CHAR;
 
104
  ret = write_exact(&val, sizeof(u_char));
 
105
  val = what;
 
106
  ret = write_exact(&val, sizeof(u_char));
 
107
 
 
108
  id2 = htonl(id);
 
109
  ret = write_exact((const u_char *)&id2, sizeof(uint32_t));
 
110
}
 
111
 
 
112
 
 
113
static void
 
114
v7_send_sequence(const uint32_t id)
 
115
{
 
116
  uint32_t proto = 7, proto2;
 
117
  uint32_t total, total2;
 
118
  uint32_t id2;
 
119
  Pixel_t *src;
 
120
  u_char val;
 
121
  int ret;
 
122
  Sequence_t *seq;
 
123
  GList *tmp;
 
124
  uint8_t seq_size, i;
 
125
 
 
126
  seq = Sequences_find(id);
 
127
  assert(NULL != seq);
 
128
  seq_size = Sequence_size(seq);
 
129
 
 
130
  /* send packet size */
 
131
  total = sizeof(uint32_t)           /* proto */
 
132
    + 2*sizeof(u_char)               /* 'US' */
 
133
    + sizeof(uint32_t)               /* sequence id */
 
134
    + sizeof(uint8_t)                /* sequence size */
 
135
    + (seq_size * sizeof(uint32_t)); /* N plugins */ /* TODO plugin_id -> uint32_t */
 
136
  total2 = htonl(total);
 
137
  ret = write_exact((const u_char *)&total2, sizeof(uint32_t));
 
138
 
 
139
  /* protocol version */
 
140
  proto2 = htonl(proto);
 
141
  ret = write_exact((const u_char *)&proto2, sizeof(uint32_t));
 
142
 
 
143
  val = UPDATE_CHAR;
 
144
  ret = write_exact(&val, sizeof(u_char));
 
145
  val = UPDATE_SEQUENCE_CHAR;
 
146
  ret = write_exact(&val, sizeof(u_char));
 
147
 
 
148
  /* sequence id */
 
149
  id2 = htonl(id);
 
150
  ret = write_exact((const u_char *)&id2, sizeof(uint32_t));
 
151
 
 
152
  /* the sequence */
 
153
  ret = write_exact((const u_char *)&seq_size, sizeof(uint8_t));
 
154
  tmp = seq->layers;
 
155
  for (i = 0; i < seq_size; i++) {
 
156
    Layer_t *l = (Layer_t *)tmp->data;
 
157
 
 
158
    id2 = htonl(l->plugin->id);
 
159
    ret = write_exact((const u_char *)&id2, sizeof(uint32_t));
 
160
    tmp = g_list_next(tmp);
 
161
  }
 
162
}
 
163
 
 
164
 
 
165
void
 
166
v7(Context_t *ctx)
 
167
{
 
168
  v7_send_events(ctx);
 
169
 
 
170
  if (send_colormap_update)
 
171
    if (ctx->sm->cur->cmap_id != last_colormap) {
 
172
      v7_send_id(UPDATE_COLORMAP_CHAR, ctx->sm->cur->cmap_id);
 
173
      last_colormap = ctx->sm->cur->cmap_id;
 
174
    }
 
175
 
 
176
  if (send_picture_update)
 
177
    if (ctx->sm->cur->picture_id != last_picture) {
 
178
      v7_send_id(UPDATE_PICTURE_CHAR, ctx->sm->cur->picture_id);
 
179
      last_picture = ctx->sm->cur->picture_id;
 
180
    }
 
181
 
 
182
  if (send_sequence_update)
 
183
    if (ctx->sm->cur->id != last_sequence) {
 
184
      v7_send_sequence(ctx->sm->cur->id);
 
185
      last_sequence = ctx->sm->cur->id;
 
186
    }
 
187
}