summaryrefslogtreecommitdiff
path: root/src/bin/evas/dummy_slave.c
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-11-04 11:51:42 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-11-04 11:51:42 +0000
commitc15e9c6575c3b5f39ded167dda5259de3de96151 (patch)
tree5115d7ae3620af24c2bc094cd062575af7adeda9 /src/bin/evas/dummy_slave.c
parenta5ac6a987caec5a7f7596a25d0a065b9cc94c50c (diff)
merge: and now Evas
I've tested make -j 3 install and it works nicely I've tested expedite with software and opengl xlib, and it works. Not tested other engines, so please report any problems (engines or other) on the ML. TODO: examples and tests, I'll add them later ISSUE: Eina_Unicode size check. It indirectly depends on eina_config.h, which is created at the end of the configure script. So its size is always 0. I don't know how that size is used, so I can't do a lot, for now. SVN revision: 78895
Diffstat (limited to 'src/bin/evas/dummy_slave.c')
-rw-r--r--src/bin/evas/dummy_slave.c207
1 files changed, 207 insertions, 0 deletions
diff --git a/src/bin/evas/dummy_slave.c b/src/bin/evas/dummy_slave.c
new file mode 100644
index 0000000000..ba815dc661
--- /dev/null
+++ b/src/bin/evas/dummy_slave.c
@@ -0,0 +1,207 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <errno.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <time.h>
9#include <sys/mman.h>
10#include <fcntl.h>
11#include <unistd.h>
12
13#include "evas_cserve2.h"
14
15static Eina_Bool
16command_read(int fd, Slave_Command *cmd, void **params)
17{
18 ssize_t ret;
19 int ints[2], size, got = 0;
20 char *buf;
21
22 ret = read(fd, ints, sizeof(int) * 2);
23 if (ret < (int)sizeof(int) * 2)
24 return EINA_FALSE;
25
26 size = ints[0];
27 buf = malloc(size);
28 if (!buf) return EINA_FALSE;
29
30 do {
31 ret = read(fd, buf + got, size - got);
32 if (ret < 0)
33 {
34 /* EINTR means we were interrupted by a signal before anything
35 * was sent, and if we are back here it means that signal was
36 * not meant for us to die. Any other error here is fatal and
37 * should result in the slave terminating.
38 */
39 if (errno == EINTR)
40 continue;
41 free(buf);
42 return EINA_FALSE;
43 }
44 got += ret;
45 } while (got < size);
46
47 *cmd = ints[1];
48 *params = buf;
49
50 return EINA_TRUE;
51}
52
53static Eina_Bool
54response_send(int fd, Slave_Command cmd, void *resp, int size)
55{
56 int sent = 0, ints[2];
57 const char *data = resp;
58 ssize_t ret;
59
60 ints[0] = size;
61 ints[1] = cmd;
62 ret = write(fd, ints, sizeof(int) * 2);
63 if (ret < 0)
64 return EINA_FALSE;
65 if (!size)
66 return EINA_TRUE;
67 do {
68 ret = write(fd, data + sent, size - sent);
69 if (ret < 0)
70 {
71 /* EINTR means we were interrupted by a signal before anything
72 * was sent, and if we are back here it means that signal was
73 * not meant for us to die. Any other error here is fatal and
74 * should result in the slave terminating.
75 */
76 if (errno == EINTR)
77 continue;
78 return EINA_FALSE;
79 }
80 sent += ret;
81 } while (sent < size);
82
83 return EINA_TRUE;
84}
85
86static Eina_Bool
87error_send(int fd, Error_Type err)
88{
89 return response_send(fd, ERROR, &err, sizeof(Error_Type));
90}
91
92static void *
93_cserve2_shm_map(const char *name, size_t length, off_t offset)
94{
95 void *map;
96 int fd;
97
98 fd = shm_open(name, O_RDWR, 0);
99 if (fd == -1)
100 return MAP_FAILED;
101
102 map = mmap(NULL, length, PROT_WRITE, MAP_SHARED, fd, offset);
103
104 close(fd);
105
106 return map;
107}
108
109/*
110static void
111_cserve2_shm_unmap(void *map, size_t length)
112{
113 munmap(map, length);
114}
115*/
116
117static Error_Type
118image_open(const char *file EINA_UNUSED, const char *key EINA_UNUSED, Slave_Msg_Image_Opened *result)
119{
120 memset(result, 0, sizeof(*result));
121 result->w = 32;
122 result->h = 32;
123 result->frame_count = 1;
124 result->loop_count = 0;
125 result->loop_hint = 0;
126 result->alpha = EINA_TRUE;
127 return CSERVE2_NONE;
128}
129
130static Error_Type
131image_load(const char *shmfile, Slave_Msg_Image_Load *params)
132{
133 char *map = _cserve2_shm_map(shmfile, params->shm.mmap_size,
134 params->shm.mmap_offset);
135 if (map == MAP_FAILED)
136 return CSERVE2_RESOURCE_ALLOCATION_FAILED;
137
138 memset(map + params->shm.image_offset, 'A', params->shm.image_size);
139
140 return CSERVE2_NONE;
141}
142
143int main(int c, char **v)
144{
145 int wfd, rfd;
146 Slave_Command cmd;
147 void *params = NULL;;
148 Eina_Bool quit = EINA_FALSE;
149
150 if (c < 3)
151 return 1;
152
153 wfd = atoi(v[1]);
154 rfd = atoi(v[2]);
155
156 while (!quit)
157 {
158 if (!command_read(rfd, &cmd, &params))
159 {
160 error_send(wfd, CSERVE2_INVALID_COMMAND);
161 continue;
162 }
163
164 switch (cmd)
165 {
166 case IMAGE_OPEN:
167 {
168 Slave_Msg_Image_Opened result;
169 Slave_Msg_Image_Open *p;
170 Error_Type err;
171 const char *file, *key;
172 p = params;
173 file = (const char *)(p + sizeof(*p));
174 key = file + strlen(file) + 1;
175 if ((err = image_open(file, key, &result)) != CSERVE2_NONE)
176 error_send(wfd, err);
177 else
178 response_send(wfd, IMAGE_OPEN, &result,
179 sizeof(Slave_Msg_Image_Opened));
180 break;
181 }
182 case IMAGE_LOAD:
183 {
184 Slave_Msg_Image_Load *load_args = params;
185 Error_Type err;
186 const char *shmfile = ((const char *)params) +
187 sizeof(Slave_Msg_Image_Load);
188 if ((err = image_load(shmfile, load_args)) != CSERVE2_NONE)
189 error_send(wfd, err);
190 else
191 response_send(wfd, IMAGE_LOAD, NULL, 0);
192 break;
193 }
194 case SLAVE_QUIT:
195 {
196 quit = EINA_TRUE;
197 break;
198 }
199
200 default:
201 error_send(wfd, CSERVE2_INVALID_COMMAND);
202 }
203 free(params);
204 }
205
206 return 0;
207}