summaryrefslogtreecommitdiff
path: root/src/lib/ecore_con
diff options
context:
space:
mode:
authorSrivardhan Hebbar <sri.hebbar@samsung.com>2015-05-29 18:12:50 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-05-29 18:22:09 +0200
commit9dcb827d12c58ea24d1ad2ce0f6aacb1f57b1146 (patch)
treeebbf17fc0c96d2194c0411577fbef4b396223f24 /src/lib/ecore_con
parent7d33ae501b2263ff1450c6351dea181573afe517 (diff)
ecore_con: add eo_event handler to efl_networ_url.
Summary: Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com> Reviewers: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2556 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib/ecore_con')
-rw-r--r--src/lib/ecore_con/Ecore_Con.h44
-rw-r--r--src/lib/ecore_con/ecore_con_url.c130
-rw-r--r--src/lib/ecore_con/efl_network_url.eo5
3 files changed, 141 insertions, 38 deletions
diff --git a/src/lib/ecore_con/Ecore_Con.h b/src/lib/ecore_con/Ecore_Con.h
index bf10fadd95..4fde11b047 100644
--- a/src/lib/ecore_con/Ecore_Con.h
+++ b/src/lib/ecore_con/Ecore_Con.h
@@ -414,6 +414,16 @@ typedef struct _Ecore_Con_Event_Server_Write Ecore_Con_Event_Server_Write;
414 */ 414 */
415typedef struct _Ecore_Con_Event_Proxy_Bind Ecore_Con_Event_Proxy_Bind; 415typedef struct _Ecore_Con_Event_Proxy_Bind Ecore_Con_Event_Proxy_Bind;
416 416
417#ifdef EFL_EO_API_SUPPORT
418/**
419 * @typedef Efl_Network_Event_Url_Data
420 * Used as the @p data param for the corresponding event
421 * EFL_NETWORK_EVENT_URL_DATA
422 * @ingroup Ecore_Con_Url_Group
423 */
424typedef struct _Efl_Network_Event_Url_Data Efl_Network_Event_Url_Data;
425#endif
426
417/** 427/**
418 * @typedef Ecore_Con_Event_Url_Data 428 * @typedef Ecore_Con_Event_Url_Data
419 * Used as the @p data param for the corresponding event 429 * Used as the @p data param for the corresponding event
@@ -428,6 +438,16 @@ typedef struct _Ecore_Con_Event_Url_Data Ecore_Con_Event_Url_Data;
428 */ 438 */
429typedef struct _Ecore_Con_Event_Url_Complete Ecore_Con_Event_Url_Complete; 439typedef struct _Ecore_Con_Event_Url_Complete Ecore_Con_Event_Url_Complete;
430 440
441#ifdef EFL_EO_API_SUPPORT
442/**
443 * @typedef Efl_Network_Event_Url_Complete
444 * Used as the @p data param for the corresponding event
445 * EFL_NETWORK_EVENT_URL_COMPLETE
446 * @ingroup Ecore_Con_Url_Group
447 */
448typedef struct _Ecore_Con_Event_Url_Complete Efl_Network_Event_Url_Complete;
449#endif
450
431/** 451/**
432 * @typedef Ecore_Con_Event_Url_Progress 452 * @typedef Ecore_Con_Event_Url_Progress
433 * Used as the @p data param for the corresponding event 453 * Used as the @p data param for the corresponding event
@@ -435,6 +455,16 @@ typedef struct _Ecore_Con_Event_Url_Complete Ecore_Con_Event_Url_Complete;
435 */ 455 */
436typedef struct _Ecore_Con_Event_Url_Progress Ecore_Con_Event_Url_Progress; 456typedef struct _Ecore_Con_Event_Url_Progress Ecore_Con_Event_Url_Progress;
437 457
458#ifdef EFL_EO_API_SUPPORT
459/**
460 * @typedef Efl_Network_Event_Url_Progress
461 * Used as the @p data param for the corresponding event
462 * EFL_NETWORK_EVENT_URL_PROGRESS
463 * @ingroup Ecore_Con_Url_Group
464 */
465typedef struct _Ecore_Con_Event_Url_Progress Efl_Network_Event_Url_Progress;
466#endif
467
438/** 468/**
439 * @struct _Ecore_Con_Event_Client_Add 469 * @struct _Ecore_Con_Event_Client_Add
440 * Used as the @p data param for the @ref ECORE_CON_EVENT_CLIENT_ADD event 470 * Used as the @p data param for the @ref ECORE_CON_EVENT_CLIENT_ADD event
@@ -566,6 +596,20 @@ struct _Ecore_Con_Event_Proxy_Bind
566 int port; /**< the proxy-bound port */ 596 int port; /**< the proxy-bound port */
567}; 597};
568 598
599#ifdef EFL_EO_API_SUPPORT
600/**
601 * @struct _Efl_Network_Event_Url_Data
602 * Used as the @p data param for the @ref EFL_NETWORK_EVENT_URL_DATA event
603 * @ingroup Ecore_Con_Url_Group
604 */
605struct _Efl_Network_Event_Url_Data
606{
607 Efl_Network_Url *url_con; /**< a pointer to the connection object */
608 int size; /**< the size of the current received data (in bytes) */
609 unsigned char *data; /**< pointer to the data received on this event */
610};
611#endif
612
569/** 613/**
570 * @struct _Ecore_Con_Event_Url_Data 614 * @struct _Ecore_Con_Event_Url_Data
571 * Used as the @p data param for the @ref ECORE_CON_EVENT_URL_DATA event 615 * Used as the @p data param for the @ref ECORE_CON_EVENT_URL_DATA event
diff --git a/src/lib/ecore_con/ecore_con_url.c b/src/lib/ecore_con/ecore_con_url.c
index 348785ce1e..82eaf21ba1 100644
--- a/src/lib/ecore_con/ecore_con_url.c
+++ b/src/lib/ecore_con/ecore_con_url.c
@@ -443,6 +443,66 @@ ecore_con_url_pipeline_get(void)
443 443
444extern Ecore_Con_Socks *_ecore_con_proxy_global; 444extern Ecore_Con_Socks *_ecore_con_proxy_global;
445 445
446static Eina_Bool
447_efl_network_url_event_complete_cb(void *data EINA_UNUSED, Eo *child, const Eo_Event_Description *desc EINA_UNUSED, void *einfo)
448{
449 Ecore_Con_Event_Url_Complete *e, *f = einfo;
450
451 e = calloc(1, sizeof(Ecore_Con_Event_Url_Complete));
452 if (!e) return EO_CALLBACK_STOP;
453
454 e->status = f->status;
455 e->url_con = f->url_con;
456 ecore_event_add(ECORE_CON_EVENT_URL_COMPLETE, e,
457 (Ecore_End_Cb)_ecore_con_event_url_free, child);
458
459 return EO_CALLBACK_STOP;
460}
461
462static Eina_Bool
463_efl_network_url_event_data_cb(void *data EINA_UNUSED, Eo *child, const Eo_Event_Description *desc EINA_UNUSED, void *einfo)
464{
465 Ecore_Con_Event_Url_Data *e;
466 Efl_Network_Event_Url_Data *f = einfo;
467
468 e = malloc(sizeof(Ecore_Con_Event_Url_Data) + sizeof(unsigned char) * f->size);
469
470 if (!e) return EO_CALLBACK_CONTINUE;
471
472 e->url_con = f->url_con;
473 e->size = f->size;
474 memcpy(e->data, f->data, f->size);
475 ecore_event_add(ECORE_CON_EVENT_URL_DATA, e,
476 (Ecore_End_Cb)_ecore_con_event_url_free, child);
477
478 return EO_CALLBACK_CONTINUE;
479}
480
481static Eina_Bool
482_efl_network_url_event_progress_cb(void *data EINA_UNUSED, Eo *child, const Eo_Event_Description *desc EINA_UNUSED, void *einfo)
483{
484 Ecore_Con_Event_Url_Progress *e, *f = einfo;
485
486 e = malloc(sizeof(Ecore_Con_Event_Url_Progress));
487 if (!e) return EO_CALLBACK_CONTINUE;
488
489 e->url_con = f->url_con;
490 e->down.total = f->down.total;
491 e->down.now = f->down.now;
492 e->up.total = f->up.total;
493 e->up.now = f->up.now;
494 ecore_event_add(ECORE_CON_EVENT_URL_PROGRESS, e,
495 (Ecore_End_Cb)_ecore_con_event_url_free, child);
496
497 return EO_CALLBACK_CONTINUE;
498}
499
500EO_CALLBACKS_ARRAY_DEFINE(efl_network_url_event_table_callbacks,
501 { EFL_NETWORK_URL_EVENT_DATA, _efl_network_url_event_data_cb },
502 { EFL_NETWORK_URL_EVENT_PROGRESS, _efl_network_url_event_progress_cb },
503 { EFL_NETWORK_URL_EVENT_COMPLETE, _efl_network_url_event_complete_cb }
504);
505
446EAPI Ecore_Con_Url * 506EAPI Ecore_Con_Url *
447ecore_con_url_new(const char *url) 507ecore_con_url_new(const char *url)
448{ 508{
@@ -450,6 +510,10 @@ ecore_con_url_new(const char *url)
450 url_obj = eo_add(EFL_NETWORK_URL_CLASS, NULL, 510 url_obj = eo_add(EFL_NETWORK_URL_CLASS, NULL,
451 efl_network_url_set(url)); 511 efl_network_url_set(url));
452 512
513 eo_do(url_obj,
514 eo_event_callback_array_add(efl_network_url_event_table_callbacks(),
515 NULL));
516
453 return url_obj; 517 return url_obj;
454} 518}
455 519
@@ -591,6 +655,10 @@ ecore_con_url_free(Ecore_Con_Url *url_obj)
591 if (!eo_isa(url_obj, EFL_NETWORK_URL_CLASS)) 655 if (!eo_isa(url_obj, EFL_NETWORK_URL_CLASS))
592 return; 656 return;
593 657
658 eo_do(url_obj,
659 eo_event_callback_array_del(efl_network_url_event_table_callbacks(),
660 NULL));
661
594 eo_del(url_obj); 662 eo_del(url_obj);
595} 663}
596 664
@@ -1326,13 +1394,11 @@ _ecore_con_url_status_get(Ecore_Con_Url *url_obj)
1326static void 1394static void
1327_ecore_con_url_event_url_complete(Ecore_Con_Url *url_obj, CURLMsg *curlmsg) 1395_ecore_con_url_event_url_complete(Ecore_Con_Url *url_obj, CURLMsg *curlmsg)
1328{ 1396{
1329 Ecore_Con_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS); 1397 Efl_Network_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS);
1330 Ecore_Con_Event_Url_Complete *e; 1398 Efl_Network_Event_Url_Complete e;
1331 int status = url_con->status; 1399 int status = url_con->status;
1332 1400
1333 if (!_c) return; 1401 if (!_c) return;
1334 e = calloc(1, sizeof(Ecore_Con_Event_Url_Complete));
1335 if (!e) return;
1336 1402
1337 if (!curlmsg) 1403 if (!curlmsg)
1338 ERR("Event completed without CURL message handle. Shouldn't happen"); 1404 ERR("Event completed without CURL message handle. Shouldn't happen");
@@ -1356,11 +1422,10 @@ _ecore_con_url_event_url_complete(Ecore_Con_Url *url_obj, CURLMsg *curlmsg)
1356 ERR("Curl message have errors: %d (%s)", 1422 ERR("Curl message have errors: %d (%s)",
1357 curlmsg->data.result, _c->curl_easy_strerror(curlmsg->data.result)); 1423 curlmsg->data.result, _c->curl_easy_strerror(curlmsg->data.result));
1358 } 1424 }
1359 e->status = status; 1425 e.status = status;
1360 e->url_con = url_obj; 1426 e.url_con = url_obj;
1361 url_con->event_count++; 1427 url_con->event_count++;
1362 ecore_event_add(ECORE_CON_EVENT_URL_COMPLETE, e, 1428 eo_do(url_obj, eo_event_callback_call(EFL_NETWORK_URL_EVENT_COMPLETE, &e));
1363 (Ecore_End_Cb)_ecore_con_event_url_free, url_obj);
1364} 1429}
1365 1430
1366static void 1431static void
@@ -1405,11 +1470,11 @@ _ecore_con_url_timeout_cb(void *data)
1405static size_t 1470static size_t
1406_ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp) 1471_ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp)
1407{ 1472{
1408 Ecore_Con_Url *url_obj = (Ecore_Con_Url *)userp; 1473 Efl_Network_Url *url_obj = (Efl_Network_Url *)userp;
1409 Ecore_Con_Event_Url_Data *e; 1474 Efl_Network_Event_Url_Data e;
1410 size_t real_size = size * nitems; 1475 size_t real_size = size * nitems;
1411 1476
1412 Ecore_Con_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS); 1477 Efl_Network_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS);
1413 if (!eo_isa(url_obj, EFL_NETWORK_URL_CLASS)) 1478 if (!eo_isa(url_obj, EFL_NETWORK_URL_CLASS))
1414 return -1; 1479 return -1;
1415 1480
@@ -1417,18 +1482,11 @@ _ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp)
1417 INF("reading from %s", url_con->url); 1482 INF("reading from %s", url_con->url);
1418 if (url_con->write_fd < 0) 1483 if (url_con->write_fd < 0)
1419 { 1484 {
1420 e = 1485 e.url_con = url_obj;
1421 malloc(sizeof(Ecore_Con_Event_Url_Data) + sizeof(unsigned char) * 1486 e.size = real_size;
1422 (real_size - 1)); 1487 e.data = buffer;
1423 if (e) 1488 url_con->event_count++;
1424 { 1489 eo_do(url_obj, eo_event_callback_call(EFL_NETWORK_URL_EVENT_DATA, &e));
1425 e->url_con = url_obj;
1426 e->size = real_size;
1427 memcpy(e->data, buffer, real_size);
1428 url_con->event_count++;
1429 ecore_event_add(ECORE_CON_EVENT_URL_DATA, e,
1430 (Ecore_End_Cb)_ecore_con_event_url_free, url_obj);
1431 }
1432 } 1490 }
1433 else 1491 else
1434 { 1492 {
@@ -1476,23 +1534,19 @@ _ecore_con_url_header_cb(void *ptr, size_t size, size_t nitems, void *stream)
1476static int 1534static int
1477_ecore_con_url_progress_cb(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) 1535_ecore_con_url_progress_cb(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
1478{ 1536{
1479 Ecore_Con_Event_Url_Progress *e; 1537 Efl_Network_Event_Url_Progress e;
1480 Ecore_Con_Url *url_obj = clientp; 1538 Efl_Network_Url *url_obj = clientp;
1481 1539
1482 Ecore_Con_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS); 1540 Efl_Network_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS);
1541
1542 e.url_con = url_obj;
1543 e.down.total = dltotal;
1544 e.down.now = dlnow;
1545 e.up.total = ultotal;
1546 e.up.now = ulnow;
1547 url_con->event_count++;
1548 eo_do(url_obj, eo_event_callback_call(EFL_NETWORK_URL_EVENT_PROGRESS, &e));
1483 1549
1484 e = malloc(sizeof(Ecore_Con_Event_Url_Progress));
1485 if (e)
1486 {
1487 e->url_con = url_obj;
1488 e->down.total = dltotal;
1489 e->down.now = dlnow;
1490 e->up.total = ultotal;
1491 e->up.now = ulnow;
1492 url_con->event_count++;
1493 ecore_event_add(ECORE_CON_EVENT_URL_PROGRESS, e,
1494 (Ecore_End_Cb)_ecore_con_event_url_free, url_obj);
1495 }
1496 return 0; 1550 return 0;
1497} 1551}
1498 1552
diff --git a/src/lib/ecore_con/efl_network_url.eo b/src/lib/ecore_con/efl_network_url.eo
index e05c940adc..4c199cd6fd 100644
--- a/src/lib/ecore_con/efl_network_url.eo
+++ b/src/lib/ecore_con/efl_network_url.eo
@@ -21,6 +21,11 @@ class Efl.Network.Url (Eo.Base) {
21 Eo.Base.destructor; 21 Eo.Base.destructor;
22 Eo.Base.finalize; 22 Eo.Base.finalize;
23 } 23 }
24 events {
25 data; /*@ Triggered when data arrives at the socket. */
26 progress; /*@ Triggered when progress is made in upload/download. */
27 complete; /*@ Triggered when the operation is complete. */
28 }
24} 29}
25 30
26/* FIXME: Actually migrate all of the functions. */ 31/* FIXME: Actually migrate all of the functions. */