summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-03-17 09:36:32 -0300
committerGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-03-17 09:36:32 -0300
commitce324a5891d83167ee32bce0274b72b780c0da8c (patch)
treec6d357a78a4f00fda388779b3962cdde7b3529b5
parentd82d61c2d70d99818be4c3c33f9c039b9ce1c7e9 (diff)
soap_model: Soap call on loading and response as child.
-rw-r--r--src/lib/soap_model.c45
-rw-r--r--src/tests/soap_model_test_soap_model.c16
2 files changed, 34 insertions, 27 deletions
diff --git a/src/lib/soap_model.c b/src/lib/soap_model.c
index 1dadcc7..755dd32 100644
--- a/src/lib/soap_model.c
+++ b/src/lib/soap_model.c
@@ -26,7 +26,7 @@ static void _soap_model_properties_load(Soap_Model_Data *);
26static void _soap_model_children_load(Soap_Model_Data *); 26static void _soap_model_children_load(Soap_Model_Data *);
27static bool _soap_model_init(Soap_Model_Data *); 27static bool _soap_model_init(Soap_Model_Data *);
28static void _soap_model_clear(Soap_Model_Data *); 28static void _soap_model_clear(Soap_Model_Data *);
29static void _soap_model_send(Soap_Model_Data *, const char *); 29static void _soap_model_perform(Soap_Model_Data *, const char *);
30static void _soap_model_perform_cb(Soap_Model_Perform_Data *, Ecore_Thread *); 30static void _soap_model_perform_cb(Soap_Model_Perform_Data *, Ecore_Thread *);
31static void _soap_model_perform_end_cb(Soap_Model_Perform_Data *, Ecore_Thread *); 31static void _soap_model_perform_end_cb(Soap_Model_Perform_Data *, Ecore_Thread *);
32static void _soap_model_perform_cancel_cb(Soap_Model_Perform_Data *, Ecore_Thread *); 32static void _soap_model_perform_cancel_cb(Soap_Model_Perform_Data *, Ecore_Thread *);
@@ -161,22 +161,20 @@ _soap_model_emodel_properties_load(Eo *obj, Soap_Model_Data *pd)
161 if (!_soap_model_init(pd)) 161 if (!_soap_model_init(pd))
162 return; 162 return;
163 163
164 emodel_load_set(pd->obj, &pd->load, EMODEL_LOAD_STATUS_LOADING_PROPERTIES);
165
166 _soap_model_properties_load(pd); 164 _soap_model_properties_load(pd);
167
168 emodel_load_set(pd->obj, &pd->load, EMODEL_LOAD_STATUS_LOADED_PROPERTIES);
169} 165}
170 166
171static void 167static void
172_soap_model_properties_load(Soap_Model_Data *pd) 168_soap_model_properties_load(Soap_Model_Data *pd)
173{ 169{
174 DBG("(%p)", pd->obj); 170 DBG("(%p)", pd->obj);
171 emodel_load_set(pd->obj, &pd->load, EMODEL_LOAD_STATUS_LOADING_PROPERTIES);
175 eo_do(pd->xml, emodel_properties_load()); 172 eo_do(pd->xml, emodel_properties_load());
173 emodel_load_set(pd->obj, &pd->load, EMODEL_LOAD_STATUS_LOADED_PROPERTIES);
176} 174}
177 175
178static Emodel_Load_Status 176static Emodel_Load_Status
179_soap_model_emodel_property_set(Eo *obj, 177_soap_model_emodel_property_set(Eo *obj EINA_UNUSED,
180 Soap_Model_Data *pd, 178 Soap_Model_Data *pd,
181 const char *property, 179 const char *property,
182 Eina_Value value) 180 Eina_Value value)
@@ -211,18 +209,10 @@ _soap_model_emodel_load(Eo *obj EINA_UNUSED, Soap_Model_Data *pd)
211 return; 209 return;
212 210
213 if (!(pd->load.status & EMODEL_LOAD_STATUS_LOADED_PROPERTIES)) 211 if (!(pd->load.status & EMODEL_LOAD_STATUS_LOADED_PROPERTIES))
214 { 212 _soap_model_properties_load(pd);
215 emodel_load_set(pd->obj, &pd->load, EMODEL_LOAD_STATUS_LOADING_PROPERTIES);
216 _soap_model_properties_load(pd);
217 }
218 213
219 if (!(pd->load.status & EMODEL_LOAD_STATUS_LOADED_CHILDREN)) 214 if (!(pd->load.status & EMODEL_LOAD_STATUS_LOADED_CHILDREN))
220 { 215 _soap_model_children_load(pd);
221 emodel_load_set(pd->obj, &pd->load, EMODEL_LOAD_STATUS_LOADING_CHILDREN);
222 _soap_model_children_load(pd);
223 }
224
225 emodel_load_set(pd->obj, &pd->load, EMODEL_LOAD_STATUS_LOADED);
226} 216}
227 217
228static Emodel_Load_Status 218static Emodel_Load_Status
@@ -299,11 +289,7 @@ _soap_model_emodel_children_load(Eo *obj EINA_UNUSED, Soap_Model_Data *pd)
299 if (!_soap_model_init(pd)) 289 if (!_soap_model_init(pd))
300 return; 290 return;
301 291
302 emodel_load_set(pd->obj, &pd->load, EMODEL_LOAD_STATUS_LOADING_CHILDREN);
303
304 _soap_model_children_load(pd); 292 _soap_model_children_load(pd);
305
306 //emodel_load_set(pd->obj, &pd->load, EMODEL_LOAD_STATUS_LOADED_CHILDREN);
307} 293}
308 294
309static void 295static void
@@ -311,19 +297,21 @@ _soap_model_children_load(Soap_Model_Data *pd)
311{ 297{
312 DBG("(%p)", pd->obj); 298 DBG("(%p)", pd->obj);
313 299
300 emodel_load_set(pd->obj, &pd->load, EMODEL_LOAD_STATUS_LOADING_CHILDREN);
301
314 Eina_Value xml_value; 302 Eina_Value xml_value;
315 Emodel_Load_Status status = eo_do(pd->xml, emodel_property_get("/", &xml_value)); 303 Emodel_Load_Status status = eo_do(pd->xml, emodel_property_get("/", &xml_value));
316 EINA_SAFETY_ON_FALSE_RETURN(EMODEL_LOAD_STATUS_LOADED_PROPERTIES & status); 304 EINA_SAFETY_ON_FALSE_RETURN(EMODEL_LOAD_STATUS_LOADED_PROPERTIES & status);
317 305
318 const char *xml = NULL; 306 const char *xml = NULL;
319 eina_value_get(&xml_value, &xml); 307 eina_value_get(&xml_value, &xml);
320 _soap_model_send(pd, xml); 308 _soap_model_perform(pd, xml);
321 eina_value_flush(&xml_value); 309 eina_value_flush(&xml_value);
322} 310}
323 311
324static Eina_Bool 312static Eina_Bool
325_soap_model_properties_changed_cb(void *data, 313_soap_model_properties_changed_cb(void *data,
326 Eo *child, 314 Eo *child EINA_UNUSED,
327 const Eo_Event_Description *desc EINA_UNUSED, 315 const Eo_Event_Description *desc EINA_UNUSED,
328 void *event_info) 316 void *event_info)
329{ 317{
@@ -338,7 +326,7 @@ _soap_model_init(Soap_Model_Data *pd)
338 return true; 326 return true;
339 327
340 pd->xml = eo_add(EFLAT_XML_MODEL_CLASS, NULL, 328 pd->xml = eo_add(EFLAT_XML_MODEL_CLASS, NULL,
341 eflat_xml_model_constructor()); 329 eflat_xml_model_constructor(NULL));
342 330
343 eo_do(pd->xml, eo_event_callback_add(EMODEL_EVENT_PROPERTIES_CHANGED, 331 eo_do(pd->xml, eo_event_callback_add(EMODEL_EVENT_PROPERTIES_CHANGED,
344 _soap_model_properties_changed_cb, 332 _soap_model_properties_changed_cb,
@@ -372,8 +360,9 @@ _soap_model_write_data_cb(void *ptr, size_t size, size_t nmeb, void *data)
372} 360}
373 361
374static void 362static void
375_soap_model_send(Soap_Model_Data *pd, const char *xml) 363_soap_model_perform(Soap_Model_Data *pd, const char *xml)
376{ 364{
365 DBG("(%p)", pd->obj);
377 Soap_Model_Perform_Data *data = calloc(1, sizeof(Soap_Model_Perform_Data)); 366 Soap_Model_Perform_Data *data = calloc(1, sizeof(Soap_Model_Perform_Data));
378 data->pd = pd; 367 data->pd = pd;
379 data->response = eina_strbuf_new(); 368 data->response = eina_strbuf_new();
@@ -403,6 +392,7 @@ _soap_model_send(Soap_Model_Data *pd, const char *xml)
403static void 392static void
404_soap_model_perform_cb(Soap_Model_Perform_Data *data, Ecore_Thread *thread) 393_soap_model_perform_cb(Soap_Model_Perform_Data *data, Ecore_Thread *thread)
405{ 394{
395 DBG("(%p)", data->pd->obj);
406 CURLcode res = curl_easy_perform(data->curl); 396 CURLcode res = curl_easy_perform(data->curl);
407 if (CURLE_OK != res) 397 if (CURLE_OK != res)
408 { 398 {
@@ -416,10 +406,13 @@ static void
416_soap_model_perform_end_cb(Soap_Model_Perform_Data *data, 406_soap_model_perform_end_cb(Soap_Model_Perform_Data *data,
417 Ecore_Thread *thread EINA_UNUSED) 407 Ecore_Thread *thread EINA_UNUSED)
418{ 408{
409 DBG("(%p)", data->pd->obj);
419 const char *response = eina_strbuf_string_get(data->response); 410 const char *response = eina_strbuf_string_get(data->response);
420 411
412 DBG("(%p) response: ", data->pd->obj, response);
413
421 Eo *child = eo_add(EFLAT_XML_MODEL_CLASS, NULL, 414 Eo *child = eo_add(EFLAT_XML_MODEL_CLASS, NULL,
422 eflat_xml_model_constructor()); 415 eflat_xml_model_constructor(response));
423 data->pd->children_list = eina_list_append(data->pd->children_list, child); 416 data->pd->children_list = eina_list_append(data->pd->children_list, child);
424 417
425 unsigned int count = eina_list_count(data->pd->children_list); 418 unsigned int count = eina_list_count(data->pd->children_list);
@@ -436,6 +429,7 @@ static void
436_soap_model_perform_cancel_cb(Soap_Model_Perform_Data *data, 429_soap_model_perform_cancel_cb(Soap_Model_Perform_Data *data,
437 Ecore_Thread *thread EINA_UNUSED) 430 Ecore_Thread *thread EINA_UNUSED)
438{ 431{
432 DBG("(%p)", data->pd->obj);
439 emodel_error_notify(data->pd->obj); 433 emodel_error_notify(data->pd->obj);
440 _soap_model_perform_data_free(data); 434 _soap_model_perform_data_free(data);
441} 435}
@@ -443,6 +437,7 @@ _soap_model_perform_cancel_cb(Soap_Model_Perform_Data *data,
443static void 437static void
444_soap_model_perform_data_free(Soap_Model_Perform_Data *data) 438_soap_model_perform_data_free(Soap_Model_Perform_Data *data)
445{ 439{
440 DBG("(%p)", data->pd->obj);
446 curl_easy_cleanup(data->curl); 441 curl_easy_cleanup(data->curl);
447 eina_strbuf_free(data->response); 442 eina_strbuf_free(data->response);
448 free(data); 443 free(data);
diff --git a/src/tests/soap_model_test_soap_model.c b/src/tests/soap_model_test_soap_model.c
index 798964d..9a4b306 100644
--- a/src/tests/soap_model_test_soap_model.c
+++ b/src/tests/soap_model_test_soap_model.c
@@ -190,7 +190,6 @@ START_TEST(load_children)
190{ 190{
191 Emodel *soap = _create_soap_model(); 191 Emodel *soap = _create_soap_model();
192 192
193 //_check_emodel_load(soap);
194 eo_do(soap, emodel_properties_load()); 193 eo_do(soap, emodel_properties_load());
195 _wait_until_load_status(soap, EMODEL_LOAD_STATUS_LOADED_PROPERTIES); 194 _wait_until_load_status(soap, EMODEL_LOAD_STATUS_LOADED_PROPERTIES);
196 195
@@ -203,7 +202,20 @@ START_TEST(load_children)
203 eo_do(soap, emodel_children_load()); 202 eo_do(soap, emodel_children_load());
204 _wait_until_load_status(soap, EMODEL_LOAD_STATUS_LOADED_CHILDREN); 203 _wait_until_load_status(soap, EMODEL_LOAD_STATUS_LOADED_CHILDREN);
205 204
206 // TODO: Check child for response 205 _check_emodel_children_count_eq(soap, 1);
206
207 Emodel *child = _emodel_nth_child_get(soap, 1);
208 _check_emodel_load(child);
209
210 _check_emodel_properties(child, (const char*[]){
211 "soapenv:Envelope@xmlns:soapenv",
212 "soapenv:Envelope/soapenv:Body/ns1:echoString@xmlns:ns1",
213 "soapenv:Envelope/soapenv:Body/ns1:echoString/text",
214 NULL});
215
216 _check_emodel_property_str_eq(child, "soapenv:Envelope@xmlns:soapenv", "http://www.w3.org/2003/05/soap-envelope");
217 _check_emodel_property_str_eq(child, "soapenv:Envelope/soapenv:Body/ns1:echoString@xmlns:ns1", "http://ws.apache.org/axis2/c/samples");
218 _check_emodel_property_str_eq(child, "soapenv:Envelope/soapenv:Body/ns1:echoString/text", "Hello World!");
207 219
208 eo_unref(soap); 220 eo_unref(soap);
209} 221}