summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Hirt <daniel.hirt@samsung.com>2015-09-13 11:49:37 +0300
committerYakov Goldberg <yakov.g@samsung.com>2015-09-28 19:21:35 +0300
commit885b72304f0dc3e295f34e334a78ecd9d41f027c (patch)
tree3c3e4a292ceb1d8e68a9a6549b733312bcc084f8
parent27f70ecf157afe2227dfb3fe4d6a7b05c460d273 (diff)
Remove file workaround and use something else
-rw-r--r--src/client.c64
-rw-r--r--src/debugd.c83
2 files changed, 35 insertions, 112 deletions
diff --git a/src/client.c b/src/client.c
index a9b01f8..9292798 100644
--- a/src/client.c
+++ b/src/client.c
@@ -10,7 +10,6 @@
10#define BUFFER_SIZE 1024 10#define BUFFER_SIZE 1024
11 11
12Ecore_Exe *g_child = NULL; 12Ecore_Exe *g_child = NULL;
13char *g_bridge_file = NULL;
14Eina_Bool test_mode = EINA_FALSE; 13Eina_Bool test_mode = EINA_FALSE;
15 14
16static Eina_Bool 15static Eina_Bool
@@ -29,30 +28,6 @@ _send_message_test(char *msg)
29} 28}
30 29
31static Eina_Bool 30static Eina_Bool
32_send_message(char *msg)
33{
34 char tmp[1024];
35 char msg2[1024];
36 static char seq = 1;
37
38 if (!g_bridge_file) return EINA_FALSE;
39
40 sprintf(tmp, "sdb push msg %s &> /dev/null", g_bridge_file);
41
42 msg2[0] = seq++;
43
44 strcpy(msg2 + 1, msg);
45
46 FILE *f = fopen("msg", "w+");
47 fprintf(f, "%s\n", msg2);
48 fclose(f);
49
50 ecore_exe_run(tmp, NULL);
51
52 return EINA_TRUE;
53}
54
55static Eina_Bool
56_fd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED) 31_fd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
57{ 32{
58 char msg[BUFFER_SIZE]; 33 char msg[BUFFER_SIZE];
@@ -70,7 +45,8 @@ _fd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
70 } 45 }
71 else 46 else
72 { 47 {
73 _send_message(msg); 48// _send_message(msg);
49 _send_message_test(msg);
74 } 50 }
75 return ECORE_CALLBACK_RENEW; 51 return ECORE_CALLBACK_RENEW;
76} 52}
@@ -81,19 +57,11 @@ _msg_from_child_handler(void *data EINA_UNUSED, int type EINA_UNUSED,
81{ 57{
82 Ecore_Exe_Event_Data *cdata = event; 58 Ecore_Exe_Event_Data *cdata = event;
83 char msg[BUFFER_SIZE]; 59 char msg[BUFFER_SIZE];
60
84 strncpy(msg, cdata->data, cdata->size); 61 strncpy(msg, cdata->data, cdata->size);
85 msg[cdata->size] = 0; 62 msg[cdata->size] = 0;
86 fprintf(stdout, "Father: my child sent me: %s\n", msg); 63 fprintf(stdout, "Father: my child sent me: %s\n", msg);
87 64
88 /* First message initializes the file path to push */
89 if (!g_bridge_file)
90 {
91 int len = strlen(msg);
92 msg[len - 1] = 0; /* removing the newline */
93 g_bridge_file = strdup(msg);
94 fprintf(stdout, "Dest file set to %s\n", g_bridge_file);
95 }
96
97 return ECORE_CALLBACK_DONE; 65 return ECORE_CALLBACK_DONE;
98} 66}
99 67
@@ -102,11 +70,9 @@ static int count = 0;
102static Ecore_Exe * 70static Ecore_Exe *
103_init_bridge(void) 71_init_bridge(void)
104{ 72{
105 /* Listen to port and after connect start receiving. 73 Ecore_Exe *exe;
106 * Recieved messages should contain ASCII text. Send back UPPERCASE 74 const char *cmd_sdb = "sdb shell";
107 * conversion of these messages */ 75 const char *cmd_bridge = "/home/developer/debugd bridge\n";
108
109 const char *cmd_bridge = "sdb shell /home/developer/debugd bridge";
110 const char *cmd_test = "./debugd bridge test"; 76 const char *cmd_test = "./debugd bridge test";
111 77
112 const char *cmd; 78 const char *cmd;
@@ -120,16 +86,30 @@ _init_bridge(void)
120 } 86 }
121 else 87 else
122 { 88 {
123 cmd = cmd_bridge; 89 cmd = cmd_sdb;
124 } 90 }
125 91
126 printf ("Starting bridge with command: %s\n", cmd); 92 printf ("Starting bridge with command: %s\n", cmd);
127 93
128 return ecore_exe_pipe_run(cmd, 94 exe = ecore_exe_pipe_run(cmd,
129 ECORE_EXE_PIPE_WRITE | 95 ECORE_EXE_PIPE_WRITE |
130 ECORE_EXE_PIPE_READ_LINE_BUFFERED | 96 ECORE_EXE_PIPE_READ_LINE_BUFFERED |
131 ECORE_EXE_PIPE_READ, 97 ECORE_EXE_PIPE_READ,
132 NULL); 98 NULL);
99
100 if (exe && !test_mode)
101 {
102 /* Once we have the shell, we will run the bridge start command.
103 * This is a workaround because 'sdb shell [command]' does
104 * '/bin/sh -' */
105 printf("Executing bridge command on sdb shell\n");
106 if (!ecore_exe_send(exe, cmd_bridge, strlen(cmd_bridge)))
107 {
108 printf("Failed sending cmd to sdb exe\n");
109
110 }
111 }
112 return exe;
133} 113}
134 114
135int main (int argc, char **argv) 115int main (int argc, char **argv)
diff --git a/src/debugd.c b/src/debugd.c
index 2431222..92e1c49 100644
--- a/src/debugd.c
+++ b/src/debugd.c
@@ -229,76 +229,6 @@ debug_daemon_init(void)
229} 229}
230 230
231/////// Bridge-CLI Comm ///////// 231/////// Bridge-CLI Comm /////////
232
233///////// SDB MODE /////////////
234const char *tmp_dir = "/home/developer/tmp";
235int tmpcount = 0;
236
237static char *
238_check_strip_cmd(char* cmd)
239{
240 static char seq = 1;
241 char tmp = *cmd;
242
243 if (tmp != seq)
244 {
245 return NULL;
246 }
247
248 seq++; /* all ok. increment seq */
249 return cmd + 1;
250}
251
252static void
253_tmp_file_monitor_cb(void *data, Ecore_File_Monitor *em,
254 Ecore_File_Event event, const char *path)
255{
256 if (event == ECORE_FILE_EVENT_MODIFIED)
257 {
258 char line[BUFFER_SIZE];
259 char arg1[256], arg2[256];
260 char *cmd;
261 FILE *f = fopen(path, "r");
262
263 fgets(line, BUFFER_SIZE, f);
264 fclose(f);
265 cmd = _check_strip_cmd(line);
266
267 if (cmd)
268 {
269 _bridge_send(cmd, strlen(cmd));
270 }
271 }
272}
273
274static Eina_Bool
275_bridge_sdb(void)
276{
277 char tmp[1024];
278 FILE *f;
279 Ecore_File_Monitor *fm;
280
281 /* We use files here. Yeah... */
282 if (!ecore_file_init())
283 {
284 return EINA_FALSE;
285 }
286
287 /* Send first message to client with the required cmd file path to push */
288 sprintf(tmp, "%s/bridge-%d", tmp_dir, getpid());
289
290 f = fopen(tmp, "w+");
291 fprintf(stdout, "%s\n", tmp);
292 fclose(f);
293
294 fm = ecore_file_monitor_add(tmp, _tmp_file_monitor_cb, NULL);
295
296 ecore_main_loop_begin();
297 ecore_file_shutdown();
298
299 return EINA_TRUE;
300}
301
302////////// TEST MODE ///////////////// 232////////// TEST MODE /////////////////
303static Eina_Bool 233static Eina_Bool
304_fd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED) 234_fd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
@@ -321,6 +251,19 @@ _fd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
321 return ECORE_CALLBACK_RENEW; 251 return ECORE_CALLBACK_RENEW;
322} 252}
323 253
254
255///////// SDB MODE /////////////
256static Eina_Bool
257_bridge_sdb(void)
258{
259 ecore_main_fd_handler_add(STDIN_FILENO,
260 ECORE_FD_READ,
261 _fd_handler_cb,
262 NULL, NULL, NULL);
263 ecore_main_loop_begin();
264 return EINA_TRUE;
265}
266
324static Eina_Bool 267static Eina_Bool
325_bridge_test(void) 268_bridge_test(void)
326{ 269{