aboutsummaryrefslogtreecommitdiffstats
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
parentedje: edje_cc_parse should check pair of parens. (diff)
downloadefl-9dcb827d12c58ea24d1ad2ce0f6aacb1f57b1146.tar.gz
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;
*/
typedef struct _Ecore_Con_Event_Proxy_Bind Ecore_Con_Event_Proxy_Bind;
+#ifdef EFL_EO_API_SUPPORT
+/**
+ * @typedef Efl_Network_Event_Url_Data
+ * Used as the @p data param for the corresponding event
+ * EFL_NETWORK_EVENT_URL_DATA
+ * @ingroup Ecore_Con_Url_Group
+ */
+typedef struct _Efl_Network_Event_Url_Data Efl_Network_Event_Url_Data;
+#endif
+
/**
* @typedef Ecore_Con_Event_Url_Data
* 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;
*/
typedef struct _Ecore_Con_Event_Url_Complete Ecore_Con_Event_Url_Complete;
+#ifdef EFL_EO_API_SUPPORT
+/**
+ * @typedef Efl_Network_Event_Url_Complete
+ * Used as the @p data param for the corresponding event
+ * EFL_NETWORK_EVENT_URL_COMPLETE
+ * @ingroup Ecore_Con_Url_Group
+ */
+typedef struct _Ecore_Con_Event_Url_Complete Efl_Network_Event_Url_Complete;
+#endif
+
/**
* @typedef Ecore_Con_Event_Url_Progress
* 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;
*/
typedef struct _Ecore_Con_Event_Url_Progress Ecore_Con_Event_Url_Progress;
+#ifdef EFL_EO_API_SUPPORT
+/**
+ * @typedef Efl_Network_Event_Url_Progress
+ * Used as the @p data param for the corresponding event
+ * EFL_NETWORK_EVENT_URL_PROGRESS
+ * @ingroup Ecore_Con_Url_Group
+ */
+typedef struct _Ecore_Con_Event_Url_Progress Efl_Network_Event_Url_Progress;
+#endif
+
/**
* @struct _Ecore_Con_Event_Client_Add
* 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
int port; /**< the proxy-bound port */
};
+#ifdef EFL_EO_API_SUPPORT
+/**
+ * @struct _Efl_Network_Event_Url_Data
+ * Used as the @p data param for the @ref EFL_NETWORK_EVENT_URL_DATA event
+ * @ingroup Ecore_Con_Url_Group
+ */
+struct _Efl_Network_Event_Url_Data
+{
+ Efl_Network_Url *url_con; /**< a pointer to the connection object */
+ int size; /**< the size of the current received data (in bytes) */
+ unsigned char *data; /**< pointer to the data received on this event */
+};
+#endif
+
/**
* @struct _Ecore_Con_Event_Url_Data
* 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)
extern Ecore_Con_Socks *_ecore_con_proxy_global;
+static Eina_Bool
+_efl_network_url_event_complete_cb(void *data EINA_UNUSED, Eo *child, const Eo_Event_Description *desc EINA_UNUSED, void *einfo)
+{
+ Ecore_Con_Event_Url_Complete *e, *f = einfo;
+
+ e = calloc(1, sizeof(Ecore_Con_Event_Url_Complete));
+ if (!e) return EO_CALLBACK_STOP;
+
+ e->status = f->status;
+ e->url_con = f->url_con;
+ ecore_event_add(ECORE_CON_EVENT_URL_COMPLETE, e,
+ (Ecore_End_Cb)_ecore_con_event_url_free, child);
+
+ return EO_CALLBACK_STOP;
+}
+
+static Eina_Bool
+_efl_network_url_event_data_cb(void *data EINA_UNUSED, Eo *child, const Eo_Event_Description *desc EINA_UNUSED, void *einfo)
+{
+ Ecore_Con_Event_Url_Data *e;
+ Efl_Network_Event_Url_Data *f = einfo;
+
+ e = malloc(sizeof(Ecore_Con_Event_Url_Data) + sizeof(unsigned char) * f->size);
+
+ if (!e) return EO_CALLBACK_CONTINUE;
+
+ e->url_con = f->url_con;
+ e->size = f->size;
+ memcpy(e->data, f->data, f->size);
+ ecore_event_add(ECORE_CON_EVENT_URL_DATA, e,
+ (Ecore_End_Cb)_ecore_con_event_url_free, child);
+
+ return EO_CALLBACK_CONTINUE;
+}
+
+static Eina_Bool
+_efl_network_url_event_progress_cb(void *data EINA_UNUSED, Eo *child, const Eo_Event_Description *desc EINA_UNUSED, void *einfo)
+{
+ Ecore_Con_Event_Url_Progress *e, *f = einfo;
+
+ e = malloc(sizeof(Ecore_Con_Event_Url_Progress));
+ if (!e) return EO_CALLBACK_CONTINUE;
+
+ e->url_con = f->url_con;
+ e->down.total = f->down.total;
+ e->down.now = f->down.now;
+ e->up.total = f->up.total;
+ e->up.now = f->up.now;
+ ecore_event_add(ECORE_CON_EVENT_URL_PROGRESS, e,
+ (Ecore_End_Cb)_ecore_con_event_url_free, child);
+
+ return EO_CALLBACK_CONTINUE;
+}
+
+EO_CALLBACKS_ARRAY_DEFINE(efl_network_url_event_table_callbacks,
+ { EFL_NETWORK_URL_EVENT_DATA, _efl_network_url_event_data_cb },
+ { EFL_NETWORK_URL_EVENT_PROGRESS, _efl_network_url_event_progress_cb },
+ { EFL_NETWORK_URL_EVENT_COMPLETE, _efl_network_url_event_complete_cb }
+);
+
EAPI Ecore_Con_Url *
ecore_con_url_new(const char *url)
{
@@ -450,6 +510,10 @@ ecore_con_url_new(const char *url)
url_obj = eo_add(EFL_NETWORK_URL_CLASS, NULL,
efl_network_url_set(url));
+ eo_do(url_obj,
+ eo_event_callback_array_add(efl_network_url_event_table_callbacks(),
+ NULL));
+
return url_obj;
}
@@ -591,6 +655,10 @@ ecore_con_url_free(Ecore_Con_Url *url_obj)
if (!eo_isa(url_obj, EFL_NETWORK_URL_CLASS))
return;
+ eo_do(url_obj,
+ eo_event_callback_array_del(efl_network_url_event_table_callbacks(),
+ NULL));
+
eo_del(url_obj);
}
@@ -1326,13 +1394,11 @@ _ecore_con_url_status_get(Ecore_Con_Url *url_obj)
static void
_ecore_con_url_event_url_complete(Ecore_Con_Url *url_obj, CURLMsg *curlmsg)
{
- Ecore_Con_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS);
- Ecore_Con_Event_Url_Complete *e;
+ Efl_Network_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS);
+ Efl_Network_Event_Url_Complete e;
int status = url_con->status;
if (!_c) return;
- e = calloc(1, sizeof(Ecore_Con_Event_Url_Complete));
- if (!e) return;
if (!curlmsg)
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)
ERR("Curl message have errors: %d (%s)",
curlmsg->data.result, _c->curl_easy_strerror(curlmsg->data.result));
}
- e->status = status;
- e->url_con = url_obj;
+ e.status = status;
+ e.url_con = url_obj;
url_con->event_count++;
- ecore_event_add(ECORE_CON_EVENT_URL_COMPLETE, e,
- (Ecore_End_Cb)_ecore_con_event_url_free, url_obj);
+ eo_do(url_obj, eo_event_callback_call(EFL_NETWORK_URL_EVENT_COMPLETE, &e));
}
static void
@@ -1405,11 +1470,11 @@ _ecore_con_url_timeout_cb(void *data)
static size_t
_ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp)
{
- Ecore_Con_Url *url_obj = (Ecore_Con_Url *)userp;
- Ecore_Con_Event_Url_Data *e;
+ Efl_Network_Url *url_obj = (Efl_Network_Url *)userp;
+ Efl_Network_Event_Url_Data e;
size_t real_size = size * nitems;
- Ecore_Con_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS);
+ Efl_Network_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS);
if (!eo_isa(url_obj, EFL_NETWORK_URL_CLASS))
return -1;
@@ -1417,18 +1482,11 @@ _ecore_con_url_data_cb(void *buffer, size_t size, size_t nitems, void *userp)
INF("reading from %s", url_con->url);
if (url_con->write_fd < 0)
{
- e =
- malloc(sizeof(Ecore_Con_Event_Url_Data) + sizeof(unsigned char) *
- (real_size - 1));
- if (e)
- {
- e->url_con = url_obj;
- e->size = real_size;
- memcpy(e->data, buffer, real_size);
- url_con->event_count++;
- ecore_event_add(ECORE_CON_EVENT_URL_DATA, e,
- (Ecore_End_Cb)_ecore_con_event_url_free, url_obj);
- }
+ e.url_con = url_obj;
+ e.size = real_size;
+ e.data = buffer;
+ url_con->event_count++;
+ eo_do(url_obj, eo_event_callback_call(EFL_NETWORK_URL_EVENT_DATA, &e));
}
else
{
@@ -1476,23 +1534,19 @@ _ecore_con_url_header_cb(void *ptr, size_t size, size_t nitems, void *stream)
static int
_ecore_con_url_progress_cb(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
{
- Ecore_Con_Event_Url_Progress *e;
- Ecore_Con_Url *url_obj = clientp;
+ Efl_Network_Event_Url_Progress e;
+ Efl_Network_Url *url_obj = clientp;
- Ecore_Con_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS);
+ Efl_Network_Url_Data *url_con = eo_data_scope_get(url_obj, MY_CLASS);
+
+ e.url_con = url_obj;
+ e.down.total = dltotal;
+ e.down.now = dlnow;
+ e.up.total = ultotal;
+ e.up.now = ulnow;
+ url_con->event_count++;
+ eo_do(url_obj, eo_event_callback_call(EFL_NETWORK_URL_EVENT_PROGRESS, &e));
- e = malloc(sizeof(Ecore_Con_Event_Url_Progress));
- if (e)
- {
- e->url_con = url_obj;
- e->down.total = dltotal;
- e->down.now = dlnow;
- e->up.total = ultotal;
- e->up.now = ulnow;
- url_con->event_count++;
- ecore_event_add(ECORE_CON_EVENT_URL_PROGRESS, e,
- (Ecore_End_Cb)_ecore_con_event_url_free, url_obj);
- }
return 0;
}
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) {
Eo.Base.destructor;
Eo.Base.finalize;
}
+ events {
+ data; /*@ Triggered when data arrives at the socket. */
+ progress; /*@ Triggered when progress is made in upload/download. */
+ complete; /*@ Triggered when the operation is complete. */
+ }
}
/* FIXME: Actually migrate all of the functions. */