summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2015-08-03 11:05:56 +0300
committerDaniel Zaoui <daniel.zaoui@samsung.com>2015-08-16 08:18:23 +0300
commitee0036b049a5efbb41307925753ba3ad52a99d98 (patch)
tree8661c7a86bf03720f56e86939c5d91bce0201d55
parent1f960ca03b8c03bc961f0dad73fd08b5cd813212 (diff)
Add List command handling
Network support has been added. debug_* files are responsible of packing/unpacking the information received from the network. The design has to be modified a little to be more scalable. The CLI should not be synchronous, so it will behave as for a GUI.
-rw-r--r--src/bin/cli.c22
-rw-r--r--src/lib/CMakeLists.txt2
-rw-r--r--src/lib/debug_common.c49
-rw-r--r--src/lib/debug_common.h15
-rw-r--r--src/lib/debug_eo.c104
-rw-r--r--src/lib/debug_eo.h21
-rw-r--r--src/lib/edbg_preload.c48
-rw-r--r--src/lib/network.c15
-rw-r--r--src/lib/network.h2
9 files changed, 240 insertions, 38 deletions
diff --git a/src/bin/cli.c b/src/bin/cli.c
index 99b84ab..af2fd4a 100644
--- a/src/bin/cli.c
+++ b/src/bin/cli.c
@@ -6,6 +6,8 @@
6#include <Eolian.h> 6#include <Eolian.h>
7 7
8#include "network.h" 8#include "network.h"
9#include "debug_eo.h"
10#include "debug_common.h"
9 11
10#define MAX_EVENTS 5 12#define MAX_EVENTS 5
11 13
@@ -126,10 +128,20 @@ _char_consume(Lexer *l, char c)
126 break; 128 break;
127 case LIST_COMMAND: 129 case LIST_COMMAND:
128 { 130 {
129 char buf[10]; 131 int size, size2;
130 network_send("SEND", 5); 132 void *buf, *buf2;
131 network_receive(buf, 10); 133 char *word = _next_word(l, NULL);
132 printf("Received: %s\n", buf); 134 debug_eo_list_request_pack(word, &buf, &size);
135 free(word);
136 debug_pack("LIST_REQ", buf, size, &buf2, &size2);
137 network_send(-1, buf2, size2);
138 free(buf);
139 buf = malloc(10000000);
140 int nb = network_receive(buf, 10000000);
141 Eina_List *objs = debug_eo_objects_list(buf, nb);
142 Obj_Info *info;
143 EINA_LIST_FREE(objs, info) printf("Object %p (%s)\n", info->ptr, info->kl_name);
144
133 break; 145 break;
134 } 146 }
135 case PRINT_COMMAND: 147 case PRINT_COMMAND:
@@ -225,6 +237,8 @@ main()
225 237
226 events = calloc(MAX_EVENTS, sizeof(event)); 238 events = calloc(MAX_EVENTS, sizeof(event));
227 239
240 debug_common_init();
241 debug_eo_init();
228 network_init(NETWORK_CLIENT); 242 network_init(NETWORK_CLIENT);
229 while(!exit_required) 243 while(!exit_required)
230 { 244 {
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index ac75f53..ecda0d8 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -1,6 +1,6 @@
1set(CMAKE_BUILD_TYPE Debug) 1set(CMAKE_BUILD_TYPE Debug)
2 2
3LIST(APPEND EDBG_COMMON_SOURCES network.c) 3LIST(APPEND EDBG_COMMON_SOURCES network.c debug_common.c debug_eo.c)
4LIST(APPEND EDBG_PRELOAD_SOURCES edbg_preload.c ${EDBG_COMMON_SOURCES}) 4LIST(APPEND EDBG_PRELOAD_SOURCES edbg_preload.c ${EDBG_COMMON_SOURCES})
5 5
6STRING(REGEX REPLACE "\n" "" EOLIAN_EO_DIR ${EOLIAN_EO_DIR}) 6STRING(REGEX REPLACE "\n" "" EOLIAN_EO_DIR ${EOLIAN_EO_DIR})
diff --git a/src/lib/debug_common.c b/src/lib/debug_common.c
new file mode 100644
index 0000000..c86072a
--- /dev/null
+++ b/src/lib/debug_common.c
@@ -0,0 +1,49 @@
1#include <Eet.h>
2#include <Eina.h>
3
4#include "debug_common.h"
5
6typedef struct
7{
8 unsigned int len;
9 char opcode[50];
10} _Eo_Request;
11
12static Eina_Hash *_opcodes_hash = NULL;
13
14void
15debug_common_init()
16{
17 _opcodes_hash = eina_hash_string_small_new(NULL);
18}
19
20void
21debug_opcode_register(const char *opcode, Debug_Handler_Cb handler)
22{
23 eina_hash_set(_opcodes_hash, opcode, handler);
24}
25
26Eina_Bool
27debug_pack(const char *opcode, void *buf, int size, void **buf_ret, int *size_ret)
28{
29 _Eo_Request r;
30 int sz_ret = sizeof(r) + size;
31 char *_buf = malloc(sz_ret);
32 r.len = sz_ret;
33 memcpy(r.opcode, opcode, strlen(opcode) + 1);
34 memcpy(_buf, &r, sizeof(r));
35 memcpy(_buf + sizeof(r), buf, size);
36 *buf_ret = _buf;
37 *size_ret = sz_ret;
38 return EINA_TRUE;
39}
40
41Eina_Bool
42debug_unpack(const void *buf, int size, void *buf_ret, int *size_ret)
43{
44 const _Eo_Request *r = buf;
45 printf("Request %s\n", r->opcode);
46 Debug_Handler_Cb handler = eina_hash_find(_opcodes_hash, r->opcode);
47 if (handler) handler((char *)buf + sizeof(*r), size - sizeof(*r), buf_ret, size_ret);
48 return EINA_TRUE;
49}
diff --git a/src/lib/debug_common.h b/src/lib/debug_common.h
new file mode 100644
index 0000000..af2773a
--- /dev/null
+++ b/src/lib/debug_common.h
@@ -0,0 +1,15 @@
1#ifndef __DEBUG_COMMON_H
2#define __DEBUG_COMMON_H
3
4typedef Eina_Bool (*Debug_Handler_Cb)(const void *buf, int size, void **buf_ret, int *size_ret);
5
6void debug_common_init();
7
8Eina_Bool debug_pack(const char *opcode, void *buf, int size, void **buf_ret, int *size_ret);
9
10Eina_Bool debug_unpack(const void *buf, int size, void *buf_ret, int *size_ret);
11
12void debug_opcode_register(const char *opcode, Debug_Handler_Cb handler);
13
14#endif
15
diff --git a/src/lib/debug_eo.c b/src/lib/debug_eo.c
new file mode 100644
index 0000000..b1f6cc5
--- /dev/null
+++ b/src/lib/debug_eo.c
@@ -0,0 +1,104 @@
1#include <Eet.h>
2
3#include "debug_eo.h"
4#include "debug_common.h"
5
6typedef struct
7{
8 const char *classname;
9} _List_Request;
10
11typedef struct
12{
13 Eina_List *objs;
14} _List_Response;
15
16static Eet_Data_Descriptor *_list_req_edd = NULL, *_list_resp_edd = NULL, *_obj_info_edd = NULL;
17
18static Eina_List *objs_list = NULL; /* List of Obj_Info */
19
20static Eina_Bool
21_list_req_handle(const void *buf, int size, void **buf_ret, int *size_ret)
22{
23 _List_Request *req = eet_data_descriptor_decode(_list_req_edd, buf, size);
24 printf("LIST_REQ %s\n", req->classname);
25 _List_Response resp;
26 resp.objs = NULL;
27 Eina_List *itr;
28 Obj_Info *info;
29 if (req->classname)
30 EINA_LIST_FOREACH(objs_list, itr, info)
31 {
32 if (!strcmp(info->kl_name, req->classname))
33 resp.objs = eina_list_append(resp.objs, info);
34 }
35 else resp.objs = objs_list;
36
37 int sz;
38 *buf_ret = eet_data_descriptor_encode(_list_resp_edd, &resp, size_ret);
39 //void *_buf = eet_data_descriptor_encode(_list_resp_edd, &resp, &sz);
40 //debug_pack("LIST_RESP", _buf, sz, buf_ret, size_ret);
41 if (req->classname) eina_list_free(resp.objs);
42
43 return EINA_TRUE;
44}
45
46Eina_List *
47debug_eo_objects_list(const void *buf, int size)
48{
49 _List_Response *r = eet_data_descriptor_decode(_list_resp_edd, buf, size);
50 Eina_List *ret = r->objs;
51 free(r);
52 return ret;
53}
54
55static Eina_Bool
56_info_del(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
57{
58 objs_list = eina_list_remove(objs_list, data);
59 return EINA_TRUE;
60}
61
62void
63debug_eo_object_add(Eo *obj)
64{
65 Obj_Info *info = calloc(1, sizeof(info));
66 info->ptr = obj;
67 info->kl_name = eo_class_name_get(obj);
68 objs_list = eina_list_append(objs_list, info);
69
70 eo_do(obj, eo_event_callback_add(EO_EV_DEL, _info_del, info));
71}
72
73#define EDDC_INIT(name, type, edd) \
74 Eet_Data_Descriptor_Class name; \
75 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&name, type); \
76 edd = eet_data_descriptor_stream_new(&name);
77
78void
79debug_eo_init()
80{
81 eet_init();
82 EDDC_INIT(list_req_eddc, _List_Request, _list_req_edd);
83 EDDC_INIT(list_resp_eddc, _List_Response, _list_resp_edd);
84 EDDC_INIT(obj_info_eddc, Obj_Info, _obj_info_edd);
85
86 EET_DATA_DESCRIPTOR_ADD_BASIC(_list_req_edd, _List_Request, "classname", classname, EET_T_STRING);
87
88 EET_DATA_DESCRIPTOR_ADD_BASIC(_obj_info_edd, Obj_Info, "ptr", ptr, EET_T_ULONG_LONG);
89 EET_DATA_DESCRIPTOR_ADD_BASIC(_obj_info_edd, Obj_Info, "kl_name", kl_name, EET_T_STRING);
90 EET_DATA_DESCRIPTOR_ADD_LIST(_list_resp_edd, _List_Response, "objects", objs, _obj_info_edd);
91
92 debug_opcode_register("LIST_REQ", _list_req_handle);
93// debug_opcode_register("LIST_RESP", _list_resp_handle);
94}
95
96Eina_Bool
97debug_eo_list_request_pack(const char *classname, void **buf_ret, int *size_ret)
98{
99 _List_Request *r = calloc(1, sizeof(*r));
100 r->classname = classname;
101 *buf_ret = eet_data_descriptor_encode(_list_req_edd, r, size_ret);
102 return EINA_TRUE;
103}
104
diff --git a/src/lib/debug_eo.h b/src/lib/debug_eo.h
new file mode 100644
index 0000000..11ce2d1
--- /dev/null
+++ b/src/lib/debug_eo.h
@@ -0,0 +1,21 @@
1#ifndef __DEBUG_EO_H
2#define __DEBUG_EO_H
3
4#include <Eina.h>
5#include <Eo.h>
6
7typedef struct
8{
9 Eo *ptr;
10 const char *kl_name;
11} Obj_Info;
12
13void debug_eo_init();
14
15void debug_eo_object_add(Eo *obj);
16
17Eina_Bool debug_eo_list_request_pack(const char *classname, void **buf_ret, int *size_ret);
18
19Eina_List *debug_eo_objects_list(const void *buf, int size);
20
21#endif
diff --git a/src/lib/edbg_preload.c b/src/lib/edbg_preload.c
index eb91bec..e0601f8 100644
--- a/src/lib/edbg_preload.c
+++ b/src/lib/edbg_preload.c
@@ -8,22 +8,24 @@
8#include <Eolian.h> 8#include <Eolian.h>
9 9
10#include "network.h" 10#include "network.h"
11 11#include "debug_eo.h"
12typedef struct 12#include "debug_common.h"
13{
14 Eo *ptr;
15 const char *kl_name;
16} Obj_Info;
17
18static Eina_List *objs_list = NULL; /* List of Obj_Info */
19 13
20static Eina_Bool 14static Eina_Bool
21_buffer_recv(int fd) 15_buffer_recv(int fd)
22{ 16{
23 char buffer[100]; 17 char buffer[10000];
24 int nbBytes = recv(fd, buffer, 100, 0); 18 int nbBytes = recv(fd, buffer, 10000, 0);
25 printf("%s %s\n", __FUNCTION__, buffer); 19 if (nbBytes <=0 ) return EINA_FALSE;
26 send(fd, "RECV", 5, 0); 20 else
21 {
22 void *buf_ret;
23 int size_ret;
24 if (debug_unpack(buffer, nbBytes, &buf_ret, &size_ret))
25 {
26 if (size_ret) send(fd, buf_ret, size_ret, 0);
27 }
28 }
27 return EINA_TRUE; 29 return EINA_TRUE;
28} 30}
29 31
@@ -31,8 +33,12 @@ static pthread_t thread;
31static void * 33static void *
32_thread_start(void *arg EINA_UNUSED) 34_thread_start(void *arg EINA_UNUSED)
33{ 35{
34 network_init(NETWORK_APP); 36 if (network_init(NETWORK_APP))
35 network_loop(_buffer_recv); 37 {
38 debug_common_init();
39 debug_eo_init();
40 network_loop(_buffer_recv);
41 }
36 return NULL; 42 return NULL;
37} 43}
38 44
@@ -61,13 +67,6 @@ eo_shutdown(void)
61 return EINA_FALSE; 67 return EINA_FALSE;
62} 68}
63 69
64static Eina_Bool
65_info_del(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
66{
67 objs_list = eina_list_remove(objs_list, data);
68 return EINA_TRUE;
69}
70
71EAPI Eo * 70EAPI Eo *
72_eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo *parent_id, Eina_Bool ref) 71_eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo *parent_id, Eina_Bool ref)
73{ 72{
@@ -75,12 +74,7 @@ _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo
75 Eo *(*_eo_add_start)(const char *, int, const Eo_Class *, Eo *, Eina_Bool) = dlsym(RTLD_NEXT, __func__); 74 Eo *(*_eo_add_start)(const char *, int, const Eo_Class *, Eo *, Eina_Bool) = dlsym(RTLD_NEXT, __func__);
76 ret = _eo_add_start(file, line, klass_id, parent_id, ref); 75 ret = _eo_add_start(file, line, klass_id, parent_id, ref);
77 76
78 Obj_Info *info = calloc(1, sizeof(info)); 77 debug_eo_object_add(ret);
79 info->ptr = ret;
80 info->kl_name = eo_class_name_get(ret);
81 objs_list = eina_list_append(objs_list, info);
82
83 eo_do(ret, eo_event_callback_add(EO_EV_DEL, _info_del, info));
84 78
85 return ret; 79 return ret;
86} 80}
diff --git a/src/lib/network.c b/src/lib/network.c
index ef60757..c777394 100644
--- a/src/lib/network.c
+++ b/src/lib/network.c
@@ -47,8 +47,14 @@ network_init(Network_Type _type)
47 { 47 {
48 struct epoll_event event; 48 struct epoll_event event;
49 serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); 49 serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
50 setsockopt(mainfd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int));
50 51
51 bind(mainfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); 52 if (bind(mainfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)))
53 {
54 perror("Bind");
55 ret = EINA_FALSE;
56 break;
57 }
52 58
53 listen(mainfd, 10); 59 listen(mainfd, 10);
54 60
@@ -75,10 +81,9 @@ network_shutdown(void)
75} 81}
76 82
77void 83void
78network_send(const void *buffer, int len) 84network_send(int fd, const void *buffer, int len)
79{ 85{
80 if (type != NETWORK_CLIENT) return; 86 send(fd == -1 ? mainfd : fd, buffer, len, 0);
81 send(mainfd, buffer, len, 0);
82} 87}
83 88
84int 89int
@@ -117,7 +122,7 @@ network_loop(Network_Handler_Cb handler)
117 } 122 }
118 else 123 else
119 { 124 {
120 handler(events[i].data.fd); 125 if (!handler(events[i].data.fd)) network_close(events[i].data.fd);
121 } 126 }
122 } 127 }
123 } 128 }
diff --git a/src/lib/network.h b/src/lib/network.h
index ea48a4a..d4f6250 100644
--- a/src/lib/network.h
+++ b/src/lib/network.h
@@ -18,7 +18,7 @@ void
18network_shutdown(void); 18network_shutdown(void);
19 19
20void 20void
21network_send(const void *buffer, int len); 21network_send(int fd, const void *buffer, int len);
22 22
23int 23int
24network_receive(void *buffer, unsigned int max_len); 24network_receive(void *buffer, unsigned int max_len);