summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2015-11-11 11:35:09 +0200
committerDaniel Zaoui <daniel.zaoui@samsung.com>2015-11-11 15:14:13 +0200
commit9ecefbedcb50097a349680511f17ebe121d182d3 (patch)
tree052d9aa27591d41feae47988322855b8214290e4
parent63ae5db4c4b6782af661908c984437e38e5547db (diff)
Eolian: encoding refactoring
Public types have been added to describe the parameter type. Type resolving function has been implemented.
-rw-r--r--src/lib/Eolian_Debug.h22
-rw-r--r--src/lib/eolian_debug.c205
2 files changed, 107 insertions, 120 deletions
diff --git a/src/lib/Eolian_Debug.h b/src/lib/Eolian_Debug.h
index b8f0da5..df1ceff 100644
--- a/src/lib/Eolian_Debug.h
+++ b/src/lib/Eolian_Debug.h
@@ -3,13 +3,18 @@
3 3
4#define EOLIAN_DEBUG_MAXARGS 15 4#define EOLIAN_DEBUG_MAXARGS 15
5 5
6typedef struct 6typedef enum
7{ 7{
8 const char *name; 8 EOLIAN_DEBUG_INVALID_TYPE = 0,
9 const char *print_format; 9 EOLIAN_DEBUG_POINTER,
10 void *ffi_type_p;//ffi_type 10 EOLIAN_DEBUG_STRING,
11 const unsigned int size; 11 EOLIAN_DEBUG_INT,
12} Eolian_Debug_Param_Type; 12 EOLIAN_DEBUG_SHORT,
13 EOLIAN_DEBUG_DOUBLE,
14 EOLIAN_DEBUG_BOOLEAN,
15 EOLIAN_DEBUG_LONG,
16 EOLIAN_DEBUG_UINT
17} Eolian_Debug_Basic_Type;
13 18
14typedef union 19typedef union
15{ 20{
@@ -18,7 +23,7 @@ typedef union
18 23
19typedef struct 24typedef struct
20{ 25{
21 const Eolian_Debug_Param_Type *type; 26 Eolian_Debug_Basic_Type type;
22 Eolian_Debug_Un_Vals value; 27 Eolian_Debug_Un_Vals value;
23} Eolian_Debug_Parameter; 28} Eolian_Debug_Parameter;
24 29
@@ -37,9 +42,6 @@ typedef struct
37 Eina_List *functions; 42 Eina_List *functions;
38} Eolian_Debug_Class; 43} Eolian_Debug_Class;
39 44
40EAPI const Eolian_Debug_Param_Type *
41eolian_debug_find_param_type(const char *type);
42
43EAPI void 45EAPI void
44eolian_debug_list_free(Eina_List *class_infos); 46eolian_debug_list_free(Eina_List *class_infos);
45 47
diff --git a/src/lib/eolian_debug.c b/src/lib/eolian_debug.c
index f22d1d1..aa3672e 100644
--- a/src/lib/eolian_debug.c
+++ b/src/lib/eolian_debug.c
@@ -37,69 +37,58 @@ static int _init_counter = 0;
37 37
38static uint32_t _obj_info_op = EINA_DEBUG_OPCODE_INVALID; 38static uint32_t _obj_info_op = EINA_DEBUG_OPCODE_INVALID;
39 39
40const Eolian_Debug_Param_Type eolian_debug_param_types[] = 40typedef struct
41{ 41{
42 {"pointer", "%p", &ffi_type_pointer, 8}, 42 Eolian_Debug_Basic_Type type;
43 {"char *", "%s", &ffi_type_pointer, 8}, 43 const char *name;
44 {"int", "%d", &ffi_type_sint, 4}, 44 const char *print_format;
45 {"short", "%d", &ffi_type_sint, 4}, 45 void *ffi_type_p;//ffi_type
46 {"double", "%f", &ffi_type_pointer, 8}, 46 const unsigned int size;
47 {"bool", "%d", &ffi_type_uint, 1}, 47} Param_Type_Info;
48 {"long", "%f", &ffi_type_pointer, 8}, 48
49 {"uint", "%u", &ffi_type_uint, 4}, 49const Param_Type_Info param_types[] =
50 {NULL, NULL, NULL, 0} 50{
51 {EOLIAN_DEBUG_INVALID_TYPE, "", "", &ffi_type_pointer, 0},
52 {EOLIAN_DEBUG_POINTER, "pointer", "%p", &ffi_type_pointer, 8},
53 {EOLIAN_DEBUG_STRING, "char *", "%s", &ffi_type_pointer, 8},
54 {EOLIAN_DEBUG_INT, "int", "%d", &ffi_type_sint, 4},
55 {EOLIAN_DEBUG_SHORT, "short", "%d", &ffi_type_sint, 4},
56 {EOLIAN_DEBUG_DOUBLE, "double", "%f", &ffi_type_pointer, 8},
57 {EOLIAN_DEBUG_BOOLEAN, "bool", "%d", &ffi_type_uint, 1},
58 {EOLIAN_DEBUG_LONG, "long", "%f", &ffi_type_pointer, 8},
59 {EOLIAN_DEBUG_UINT, "uint", "%u", &ffi_type_uint, 4},
60 {0, NULL, NULL, NULL, 0}
51}; 61};
52 62
53static const char * 63static Eolian_Debug_Basic_Type
54_type_to_string(const Eolian_Type *param_eolian_type) 64_eolian_type_resolve(const Eolian_Function_Parameter *eo_param)
55{ 65{
56 if ((eolian_type_type_get(param_eolian_type) == EOLIAN_TYPE_REGULAR)//if its one of the base type or alias 66 const Eolian_Type *eo_type = eolian_parameter_type_get(eo_param);
57 && !eolian_type_base_type_get(param_eolian_type)) 67 Eolian_Type_Type type = eolian_type_type_get(eo_type);
58 { 68 if (type == EOLIAN_TYPE_REGULAR)
59 return eolian_type_name_get(param_eolian_type);
60 }
61 else
62 { 69 {
63 const Eolian_Type *base = eolian_type_base_type_get(param_eolian_type); 70 const char *full_name = eolian_type_full_name_get(eo_type);
64 if ((eolian_type_type_get(base) == EOLIAN_TYPE_REGULAR) || 71 const Eolian_Type *alias = eolian_type_alias_get_by_name(full_name);
65 (eolian_type_type_get(base) == EOLIAN_TYPE_CLASS)) 72 if (alias)
66 {
67 return eolian_type_full_name_get(base);
68 }
69 else if (eolian_type_type_get(base) == EOLIAN_TYPE_POINTER)
70 {
71 return "AGAIN POINTER";
72 }
73 else if (eolian_type_type_get(base) == EOLIAN_TYPE_VOID)
74 {
75 return "void *";
76 }
77 else if (eolian_type_type_get(base) == EOLIAN_TYPE_ENUM)
78 {
79 return eolian_type_full_name_get(param_eolian_type);
80 }
81 else if (eolian_type_type_get(base) == EOLIAN_TYPE_ALIAS)
82 { 73 {
83 return eolian_type_full_name_get(base); 74 eo_type = eolian_type_base_type_get(alias);
84 }
85 else
86 {
87 return "NULL";
88 } 75 }
89 } 76 }
90} 77 switch(type)
91
92EAPI const Eolian_Debug_Param_Type *
93eolian_debug_find_param_type(const char *type)
94{
95 const Eolian_Debug_Param_Type *param_type = eolian_debug_param_types;
96 while(param_type->name)
97 { 78 {
98 if(!strcmp(param_type->name, type)) 79 case EOLIAN_TYPE_REGULAR:
99 return param_type; 80 {
100 param_type++; 81 int i;
82 const char *full_name = eolian_type_full_name_get(eo_type);
83 for (i = 0; param_types[i].name; i++)
84 if (!strcmp(full_name, param_types[i].name)) return i;
85 }
86 default:
87 {
88 printf("Type %s not supported\n", eolian_parameter_name_get(eo_param));
89 return EOLIAN_DEBUG_INVALID_TYPE;
90 }
101 } 91 }
102 return eolian_debug_param_types;//take the first - for pointers
103} 92}
104 93
105static const Eolian_Class * 94static const Eolian_Class *
@@ -138,6 +127,7 @@ _class_find_by_name(const char *eo_klname)
138 return kl; 127 return kl;
139} 128}
140 129
130#if 0
141static const Eolian_Function * 131static const Eolian_Function *
142_function_find_by_name(const char *func_klname, 132_function_find_by_name(const char *func_klname,
143 const char *func_name, Eolian_Function_Type ftype) 133 const char *func_name, Eolian_Function_Type ftype)
@@ -151,71 +141,64 @@ _function_find_by_name(const char *func_klname,
151 141
152 return func; 142 return func;
153} 143}
144#endif
154 145
155static Eina_Bool 146static Eina_Bool
156_function_params_prepare(Eo *ptr, const Eolian_Function *foo, 147_function_params_prepare(Eo *ptr, const Eolian_Function *foo,
157 Eolian_Debug_Parameter params[], int *argnum) 148 Eolian_Debug_Parameter params[], int *argnum)
158{ 149{
159 if (foo) 150 if (!foo) return EINA_FALSE;
151 ffi_type *types[EOLIAN_DEBUG_MAXARGS];
152 void *values[EOLIAN_DEBUG_MAXARGS];
153 void *pointers[EOLIAN_DEBUG_MAXARGS];
154 Eolian_Function_Parameter *eo_param;
155 Eina_Iterator *itr = eolian_property_values_get(foo, EOLIAN_PROP_GET);
156 Eina_Bool ret = EINA_FALSE;
157 *argnum = 0;
158
159 EINA_ITERATOR_FOREACH(itr, eo_param)
160 { 160 {
161 ffi_type *types[EOLIAN_DEBUG_MAXARGS]; 161 Eolian_Debug_Basic_Type type = _eolian_type_resolve(eo_param);
162 void *values[EOLIAN_DEBUG_MAXARGS];
163 void *pointers[EOLIAN_DEBUG_MAXARGS];
164 Eolian_Function_Parameter *eo_param;
165 Eina_Iterator *itr = eolian_property_values_get(foo, EOLIAN_PROP_GET);
166 *argnum = 0;
167 162
168 EINA_ITERATOR_FOREACH(itr, eo_param) 163 if (type && *argnum < (EOLIAN_DEBUG_MAXARGS - 1))
169 { 164 {
170 const Eolian_Type *param_eolian_type = eolian_parameter_type_get(eo_param); 165 params[*argnum].value.value = 0;
171 const char *c_type2 = _type_to_string(param_eolian_type); 166 params[*argnum].type = type;
172 const Eolian_Debug_Param_Type *p_type = eolian_debug_find_param_type(c_type2); 167 // FIXME ffi type should correspond to the type
173 168 types[*argnum] = &ffi_type_pointer;
174 if ((eolian_type_type_get(param_eolian_type) == EOLIAN_TYPE_POINTER || 169 pointers[*argnum] = &(params[*argnum].value.value);
175 (eolian_type_type_get(param_eolian_type) == EOLIAN_TYPE_REGULAR && 170 values[*argnum] = &pointers[*argnum];
176 p_type != eolian_debug_param_types)) && 171 (*argnum)++;
177 *argnum < (EOLIAN_DEBUG_MAXARGS - 1)
178 )
179 {
180 printf("%d type supported = %s\n", *argnum, c_type2);
181 params[*argnum].value.value = 0;
182 params[*argnum].type = p_type;
183 types[*argnum] = &ffi_type_pointer;
184 pointers[*argnum] = &(params[*argnum].value.value);
185 values[*argnum] = &pointers[*argnum];
186 (*argnum)++;
187 }
188 else
189 {
190 printf("param type not supported! = %s function = %s\n", c_type2,
191 eolian_function_name_get(foo));
192 return EINA_FALSE;
193 }
194 } 172 }
195 eina_iterator_free(itr); 173 else goto end;
174 }
196 175
197 printf("dlsym %s\n", eolian_function_full_c_name_get(foo, EOLIAN_PROP_GET, EINA_FALSE)); 176 // FIXME got to handle return type here (eolian_function_return_type_get)
198 void *eo_func = dlsym(RTLD_DEFAULT, 177
199 eolian_function_full_c_name_get(foo, EOLIAN_PROP_GET, EINA_FALSE)); 178 const char *full_func_name = eolian_function_full_c_name_get(foo, EOLIAN_PROP_GET, EINA_FALSE);
200 if (_eo_do_start((Eo *)ptr, NULL, EINA_FALSE, _eo_stack_get())) 179 printf("dlsym %s\n", full_func_name);
201 { 180 void *eo_func = dlsym(RTLD_DEFAULT, full_func_name);
202 ffi_cif cif; 181 if (_eo_do_start((Eo *)ptr, NULL, EINA_FALSE, _eo_stack_get()))
182 {
183 ffi_cif cif;
203#if 0 184#if 0
204 ffi_type *ffi_type_p = &ffi_type_pointer; 185 ffi_type *ffi_type_p = &ffi_type_pointer;
205 if(*argnum == 1) 186 if(*argnum == 1)
206 ffi_type_p = params[0].type->ffi_type_p; 187 ffi_type_p = params[0].type->ffi_type_p;
207#endif 188#endif
208 if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, *argnum, &ffi_type_pointer, types) == FFI_OK) 189 if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, *argnum, &ffi_type_pointer, types) == FFI_OK)
209 { 190 {
210 void *result; 191 void *result;
211 ffi_call(&cif, eo_func, &result, values); 192 ffi_call(&cif, eo_func, &result, values);
212 if(*argnum == 1) 193 if(*argnum == 1)
213 params[0].value.value = (uint64_t) result; 194 params[0].value.value = (uint64_t) result;
214 }
215 _eo_do_end(_eo_stack_get());
216 } 195 }
196 _eo_do_end(_eo_stack_get());
217 } 197 }
218 return EINA_TRUE; 198 ret = EINA_TRUE;
199end:
200 eina_iterator_free(itr);
201 return ret;
219} 202}
220 203
221static unsigned int 204static unsigned int
@@ -252,11 +235,11 @@ _class_buffer_fill(Eo *obj, const Eolian_Class *ekl, char *buf)
252 size += len; 235 size += len;
253 for(i = 0; i < argnum; i++) //print params 236 for(i = 0; i < argnum; i++) //print params
254 { 237 {
255 printf("%d result %s = ", i, params[i].type->print_format); 238 printf("%d result %s = ", i, param_types[params[i].type].print_format);
256 printf(params[i].type->print_format, params[i].value.value); 239 printf(param_types[params[i].type].print_format, params[i].value.value);
257 printf("\n"); 240 printf("\n");
258 //if its a string we wont copy the pointer but the values 241 //if its a string we wont copy the pointer but the values
259 if(!strcmp(params[i].type->name, "char *")) 242 if (params[i].type == EOLIAN_DEBUG_STRING)
260 { 243 {
261 len = strlen((char *)params[i].value.value) + 1; 244 len = strlen((char *)params[i].value.value) + 1;
262 memcpy(buf + size, (char *)params[i].value.value, len); 245 memcpy(buf + size, (char *)params[i].value.value, len);
@@ -264,8 +247,8 @@ _class_buffer_fill(Eo *obj, const Eolian_Class *ekl, char *buf)
264 } 247 }
265 else 248 else
266 { 249 {
267 memcpy(buf + size, &(params[i].value.value), params[i].type->size); 250 memcpy(buf + size, &(params[i].value.value), param_types[params[i].type].size);
268 size += params[i].type->size; 251 size += param_types[params[i].type].size;
269 } 252 }
270 } 253 }
271 } 254 }
@@ -311,6 +294,7 @@ _obj_info_req_cb(Eina_Debug_Client *src, void *buffer, int size EINA_UNUSED)
311 return EINA_TRUE; 294 return EINA_TRUE;
312} 295}
313 296
297#if 0
314EAPI void 298EAPI void
315eolian_debug_list_free(Eina_List *class_infos) 299eolian_debug_list_free(Eina_List *class_infos)
316{ 300{
@@ -391,7 +375,7 @@ eolian_debug_list_response_decode(char *buffer, unsigned int size)
391 { 375 {
392 const Eolian_Type *param_eolian_type = eolian_parameter_type_get(eo_param); 376 const Eolian_Type *param_eolian_type = eolian_parameter_type_get(eo_param);
393 const char *c_type2 = _type_to_string(param_eolian_type); 377 const char *c_type2 = _type_to_string(param_eolian_type);
394 const Eolian_Debug_Param_Type *p_type = eolian_debug_find_param_type(c_type2); 378 const Eolian_Debug_Param_Type *p_type = _find_param_type(c_type2);
395 379
396 if ((eolian_type_type_get(param_eolian_type) == EOLIAN_TYPE_POINTER || 380 if ((eolian_type_type_get(param_eolian_type) == EOLIAN_TYPE_POINTER ||
397 (eolian_type_type_get(param_eolian_type) == EOLIAN_TYPE_REGULAR && 381 (eolian_type_type_get(param_eolian_type) == EOLIAN_TYPE_REGULAR &&
@@ -440,6 +424,7 @@ error:
440 eolian_debug_list_free(list); 424 eolian_debug_list_free(list);
441 return NULL; 425 return NULL;
442} 426}
427#endif
443 428
444static const Eina_Debug_Opcode _debug_ops[] = 429static const Eina_Debug_Opcode _debug_ops[] =
445{ 430{