summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Hirt <daniel.hirt@samsung.com>2015-09-17 18:20:43 +0300
committerYakov Goldberg <yakov.g@samsung.com>2015-09-28 19:21:35 +0300
commitbe9b60d83c50add2722f07674e78fd7ef3bb3cd9 (patch)
treec9a984ba1a0d6d34a0cc39b3b0df1798609e3519
parent885b72304f0dc3e295f34e334a78ecd9d41f027c (diff)
Add proper test environment
-rw-r--r--src/Makefile2
-rw-r--r--src/client.c14
-rw-r--r--src/debugd.c173
3 files changed, 99 insertions, 90 deletions
diff --git a/src/Makefile b/src/Makefile
index 94a83f4..5cf5d7c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -8,7 +8,7 @@ client: client.c
8 $(CC) -o client client.c `pkg-config --cflags --libs efl ecore ecore-ipc` 8 $(CC) -o client client.c `pkg-config --cflags --libs efl ecore ecore-ipc`
9 9
10debugd: debugd.c 10debugd: debugd.c
11 $(CC) -o debugd debugd.c `pkg-config --cflags --libs efl ecore ecore-file ecore-ipc` 11 $(CC) -o debugd debugd.c `pkg-config --cflags --libs efl ecore ecore-ipc`
12 12
13clean: 13clean:
14 rm client debugd 14 rm client debugd
diff --git a/src/client.c b/src/client.c
index 9292798..1df4fb3 100644
--- a/src/client.c
+++ b/src/client.c
@@ -13,7 +13,7 @@ Ecore_Exe *g_child = NULL;
13Eina_Bool test_mode = EINA_FALSE; 13Eina_Bool test_mode = EINA_FALSE;
14 14
15static Eina_Bool 15static Eina_Bool
16_send_message_test(char *msg) 16_send_message(char *msg)
17{ 17{
18 if (!ecore_exe_send(g_child, msg, strlen(msg))) 18 if (!ecore_exe_send(g_child, msg, strlen(msg)))
19 { 19 {
@@ -39,15 +39,7 @@ _fd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
39 } 39 }
40 40
41 fprintf(stdout, "Father: User entered: %s\n", msg); 41 fprintf(stdout, "Father: User entered: %s\n", msg);
42 if (test_mode) 42 _send_message(msg);
43 {
44 _send_message_test(msg);
45 }
46 else
47 {
48// _send_message(msg);
49 _send_message_test(msg);
50 }
51 return ECORE_CALLBACK_RENEW; 43 return ECORE_CALLBACK_RENEW;
52} 44}
53 45
@@ -73,7 +65,7 @@ _init_bridge(void)
73 Ecore_Exe *exe; 65 Ecore_Exe *exe;
74 const char *cmd_sdb = "sdb shell"; 66 const char *cmd_sdb = "sdb shell";
75 const char *cmd_bridge = "/home/developer/debugd bridge\n"; 67 const char *cmd_bridge = "/home/developer/debugd bridge\n";
76 const char *cmd_test = "./debugd bridge test"; 68 const char *cmd_test = "./debugd bridge";
77 69
78 const char *cmd; 70 const char *cmd;
79 const char *profile = getenv("DBG_PROFILE"); 71 const char *profile = getenv("DBG_PROFILE");
diff --git a/src/debugd.c b/src/debugd.c
index 92e1c49..75285ca 100644
--- a/src/debugd.c
+++ b/src/debugd.c
@@ -16,22 +16,45 @@ static Ecore_Event_Handler *hnd_add = NULL;
16static Ecore_Event_Handler *hnd_del = NULL; 16static Ecore_Event_Handler *hnd_del = NULL;
17static Ecore_Event_Handler *hnd_data = NULL; 17static Ecore_Event_Handler *hnd_data = NULL;
18 18
19static Ecore_Ipc_Client *g_test_client = NULL;
20
21#define IPC_HEAD(_type) \
22 Ecore_Ipc_Event_Client_##_type *e = event; \
23 if (ecore_ipc_client_server_get(e->client) != ipc) \
24 return ECORE_CALLBACK_PASS_ON
25
19static Eina_Bool 26static Eina_Bool
20_cb_client_add(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) 27_cb_client_add(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
21{ 28{
29 IPC_HEAD(Data);
22 return ECORE_CALLBACK_DONE; 30 return ECORE_CALLBACK_DONE;
23} 31}
24 32
25static Eina_Bool 33static Eina_Bool
26_cb_client_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) 34_cb_client_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
27{ 35{
36 IPC_HEAD(Del);
37 printf("Client deleted\n");
38 ecore_ipc_client_del(e->client);
28 return ECORE_CALLBACK_DONE; 39 return ECORE_CALLBACK_DONE;
29} 40}
30 41
31#define IPC_HEAD(_type) \ 42static void
32 Ecore_Ipc_Event_Client_##_type *e = event; \ 43_broadcast(Ecore_Ipc_Server *svr, int major, int minor, void *data, int size,
33 if (ecore_ipc_client_server_get(e->client) != ipc) \ 44 Ecore_Ipc_Client *ignore)
34 return ECORE_CALLBACK_PASS_ON 45{
46 Eina_List *ipc_clients = ecore_ipc_server_clients_get(svr);
47 Eina_List *l;
48 Ecore_Ipc_Client *cl;
49
50 EINA_LIST_FOREACH(ipc_clients, l, cl)
51 {
52 if (cl != ignore)
53 {
54 ecore_ipc_client_send(cl, major, minor, 0, 0, 0, data, size);
55 }
56 }
57}
35 58
36static Eina_Bool 59static Eina_Bool
37_cb_client_data(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) 60_cb_client_data(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
@@ -43,32 +66,12 @@ _cb_client_data(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
43 66
44 strncpy(tmp, e->data, e->size); 67 strncpy(tmp, e->data, e->size);
45 68
46#if 1 69 _broadcast(ipc, 1, 0, tmp, e->size, e->client);
47 for (c = tmp; *c != 0; c++)
48 *c = toupper(toupper(*c));
49#endif
50 70
51 if (e->major == 1)
52 {
53 ecore_ipc_client_send(e->client, 1, 0, 0, 0, 0, tmp, e->size);
54 }
55 return ECORE_CALLBACK_DONE; 71 return ECORE_CALLBACK_DONE;
56} 72}
57 73
58////// Server //////////////////// 74////// Server ////////////////////
59static void
60_broadcast(Ecore_Ipc_Server *svr, int major, int minor, void *data, int size)
61{
62 Eina_List *ipc_clients = ecore_ipc_server_clients_get(svr);
63 Eina_List *l;
64 Ecore_Ipc_Client *cl;
65
66 EINA_LIST_FOREACH(ipc_clients, l, cl)
67 {
68 ecore_ipc_client_send(cl, major, minor, 0, 0, 0, data, size);
69 }
70}
71
72static Eina_Bool 75static Eina_Bool
73_server_shutdown(void) 76_server_shutdown(void)
74{ 77{
@@ -110,33 +113,23 @@ typedef enum
110{ 113{
111 DAEMON_MODE_NORMAL, 114 DAEMON_MODE_NORMAL,
112 DAEMON_MODE_TEST, 115 DAEMON_MODE_TEST,
113 DAEMON_MODE_BRIDGE_NORMAL, 116 DAEMON_MODE_BRIDGE
114 DAEMON_MODE_BRIDGE_TEST
115} Daemon_Mode; 117} Daemon_Mode;
116 118
117Eina_Bool 119Eina_Bool
118_daemon(Daemon_Mode mode) 120_daemon(void)
119{ 121{
120#if 1
121 if (!_server_init()) 122 if (!_server_init())
122 { 123 {
123 return EINA_FALSE; 124 return EINA_FALSE;
124 } 125 }
125#endif
126 ecore_main_loop_begin(); 126 ecore_main_loop_begin();
127#if 1
128 _server_shutdown(); 127 _server_shutdown();
129#endif
130 128
131 return EINA_TRUE; 129 return EINA_TRUE;
132} 130}
133 131
134//////////////////////////////////////////////////////////////////////////
135/////////////////// Bridge (Client) //////////////////////////////////////
136/////////////////////////////////////////////////////////////////////////
137
138/////// Bridge-Daemon Comm. ///////// 132/////// Bridge-Daemon Comm. /////////
139#include <Ecore_File.h>
140static Ecore_Ipc_Server *srv_ipc = NULL; 133static Ecore_Ipc_Server *srv_ipc = NULL;
141/* Server-to-client cb's */ 134/* Server-to-client cb's */
142static Ecore_Event_Handler *svr_hnd_add = NULL; 135static Ecore_Event_Handler *svr_hnd_add = NULL;
@@ -207,7 +200,7 @@ _ipc_launch(void)
207} 200}
208 201
209static Eina_Bool 202static Eina_Bool
210debug_daemon_init(void) 203_bridge_init(void)
211{ 204{
212 srv_ipc = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, "debugd", 0, NULL); 205 srv_ipc = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, "debugd", 0, NULL);
213 206
@@ -229,7 +222,6 @@ debug_daemon_init(void)
229} 222}
230 223
231/////// Bridge-CLI Comm ///////// 224/////// Bridge-CLI Comm /////////
232////////// TEST MODE /////////////////
233static Eina_Bool 225static Eina_Bool
234_fd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED) 226_fd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
235{ 227{
@@ -241,54 +233,87 @@ _fd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
241 fprintf(stderr, "nothing\n"); 233 fprintf(stderr, "nothing\n");
242 return ECORE_CALLBACK_RENEW; 234 return ECORE_CALLBACK_RENEW;
243 } 235 }
244#if 0
245 for (c = msg; *c != 0; c++)
246 *c = toupper(toupper(*c));
247
248 fprintf(stdout, "%s\n", msg);
249#endif
250 _bridge_send(msg, strlen(msg)); 236 _bridge_send(msg, strlen(msg));
251 return ECORE_CALLBACK_RENEW; 237 return ECORE_CALLBACK_RENEW;
252} 238}
253 239
254
255///////// SDB MODE /////////////
256static Eina_Bool 240static Eina_Bool
257_bridge_sdb(void) 241_bridge(void)
258{ 242{
243 /* Initialize debug daemon */
244 if (!_bridge_init())
245 {
246 perror("Exiting...\n");
247 return EINA_FALSE;
248 }
249
259 ecore_main_fd_handler_add(STDIN_FILENO, 250 ecore_main_fd_handler_add(STDIN_FILENO,
260 ECORE_FD_READ, 251 ECORE_FD_READ,
261 _fd_handler_cb, 252 _fd_handler_cb,
262 NULL, NULL, NULL); 253 NULL, NULL, NULL);
263 ecore_main_loop_begin(); 254 ecore_main_loop_begin();
255
264 return EINA_TRUE; 256 return EINA_TRUE;
265} 257}
266 258
267static Eina_Bool 259static Eina_Bool
268_bridge_test(void) 260_cb_server_data_test(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
269{ 261{
270 ecore_main_fd_handler_add(STDIN_FILENO, 262 SVR_IPC_HEAD(Data);
271 ECORE_FD_READ, 263 char tmp[1024];
272 _fd_handler_cb, 264 char *c;
273 NULL, NULL, NULL); 265
274 ecore_main_loop_begin(); 266 strncpy(tmp, e->data, e->size);
275 return EINA_TRUE; 267 tmp[e->size] = 0;
268
269 for (c = tmp; *c != 0; c++)
270 {
271 *c = toupper(*c);
272 }
273
274 if (e->major == 1)
275 {
276 ecore_ipc_server_send(srv_ipc, 1, 0, 0, 0, 0, tmp, e->size);
277 }
278 return ECORE_CALLBACK_DONE;
276} 279}
277 280
278static Eina_Bool 281static Eina_Bool
279_bridge(Daemon_Mode mode) 282_test_client_init(void)
280{ 283{
284 srv_ipc = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, "debugd", 0, NULL);
285
286 if (!srv_ipc)
287 {
288 ecore_ipc_shutdown();
289 return EINA_FALSE;
290 }
291 svr_hnd_add = ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD,
292 _cb_server_add, NULL);
293 svr_hnd_del = ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL,
294 _cb_server_del, NULL);
295 svr_hnd_data = ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA,
296 _cb_server_data_test, NULL);
297
298 return EINA_TRUE;;
299}
300
301static Eina_Bool
302_test(void)
303{
304 printf("Test mode\n");
281 /* Initialize debug daemon */ 305 /* Initialize debug daemon */
282 if (!debug_daemon_init()) 306 if (!_test_client_init())
283 { 307 {
284 perror("Exiting...\n"); 308 printf("Could not connect to server\n");
285 return EINA_FALSE; 309 return EINA_FALSE;
286 } 310 }
287 311
288 if (mode == DAEMON_MODE_BRIDGE_TEST) 312 ecore_main_fd_handler_add(STDIN_FILENO,
289 _bridge_test(); 313 ECORE_FD_READ,
290 else //BRIDGE_NORMAL 314 _fd_handler_cb,
291 _bridge_sdb(); 315 NULL, NULL, NULL);
316 ecore_main_loop_begin();
292 317
293 return EINA_TRUE; 318 return EINA_TRUE;
294} 319}
@@ -297,13 +322,13 @@ _bridge(Daemon_Mode mode)
297///////////////// Main ///////////////////////////////////// 322///////////////// Main /////////////////////////////////////
298//////////////////////////////////////////////////////////// 323////////////////////////////////////////////////////////////
299 324
300/* All modes require ipc comm. */
301int main (int argc, char **argv) 325int main (int argc, char **argv)
302{ 326{
303 Daemon_Mode mode; 327 Daemon_Mode mode;
304 Eina_Bool ret; 328 Eina_Bool ret;
305 Eina_Bool test = EINA_FALSE; 329 Eina_Bool test = EINA_FALSE;
306 if (!ecore_init()) goto exit; 330 if (!ecore_init()) goto exit;
331 /* All modes require ipc comm. */
307 if (!ecore_ipc_init()) 332 if (!ecore_ipc_init())
308 { 333 {
309 ecore_shutdown(); 334 ecore_shutdown();
@@ -315,7 +340,7 @@ int main (int argc, char **argv)
315 { 340 {
316 if (!strcmp(argv[1], "bridge")) 341 if (!strcmp(argv[1], "bridge"))
317 { 342 {
318 mode = DAEMON_MODE_BRIDGE_NORMAL; 343 mode = DAEMON_MODE_BRIDGE;
319 } 344 }
320 else if (!strcmp(argv[1], "test")) 345 else if (!strcmp(argv[1], "test"))
321 { 346 {
@@ -323,21 +348,13 @@ int main (int argc, char **argv)
323 } 348 }
324 349
325 } 350 }
326 if ((argc == 3) && !strcmp(argv[2], "test"))
327 {
328 if (mode == DAEMON_MODE_BRIDGE_NORMAL)
329 {
330 mode = DAEMON_MODE_BRIDGE_TEST;
331 }
332 else
333 {
334 mode = DAEMON_MODE_TEST;
335 }
336 }
337 351
338 if (mode > DAEMON_MODE_TEST) 352 if (mode == DAEMON_MODE_BRIDGE)
339 _bridge(mode); 353 _bridge();
340 else _daemon(mode); 354 else if (mode == DAEMON_MODE_TEST)
355 _test();
356 else
357 _daemon();
341 358
342 ecore_shutdown(); 359 ecore_shutdown();
343 360