summaryrefslogtreecommitdiff
path: root/src/lib/ecore_ipc
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-22 23:20:40 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-22 23:20:40 -0200
commit89c326cd00e2b2a21ec7529e82a40fa5a14d7826 (patch)
tree5391467ff909d4216bd1931c8155e62769aea62f /src/lib/ecore_ipc
parent915034b9e0574ca98f3397101d08db3cca218058 (diff)
ecore_ipc: refactor code related to event posting.
When we move to efl_net we'll reuse the same event posting, thus refactor the code in their own function so it can be reused.
Diffstat (limited to 'src/lib/ecore_ipc')
-rw-r--r--src/lib/ecore_ipc/ecore_ipc.c138
1 files changed, 83 insertions, 55 deletions
diff --git a/src/lib/ecore_ipc/ecore_ipc.c b/src/lib/ecore_ipc/ecore_ipc.c
index d8515b0bd3..9d10be71ef 100644
--- a/src/lib/ecore_ipc/ecore_ipc.c
+++ b/src/lib/ecore_ipc/ecore_ipc.c
@@ -223,6 +223,84 @@ static int _ecore_ipc_init_count = 0;
223static Eina_List *servers = NULL; 223static Eina_List *servers = NULL;
224static Ecore_Event_Handler *handler[6]; 224static Ecore_Event_Handler *handler[6];
225 225
226static void
227ecore_ipc_post_event_server_add(Ecore_Ipc_Server *svr)
228{
229 Ecore_Ipc_Event_Server_Add *ev;
230
231 if (svr->delete_me) return;
232
233 ev = calloc(1, sizeof(Ecore_Ipc_Event_Server_Add));
234 EINA_SAFETY_ON_NULL_RETURN(ev);
235
236 svr->event_count++;
237 ev->server = svr;
238 ecore_event_add(ECORE_IPC_EVENT_SERVER_ADD, ev,
239 _ecore_ipc_event_server_add_free, NULL);
240}
241
242static void
243ecore_ipc_post_event_server_del(Ecore_Ipc_Server *svr)
244{
245 Ecore_Ipc_Event_Server_Del *ev;
246
247 if (svr->delete_me) return;
248
249 ev = calloc(1, sizeof(Ecore_Ipc_Event_Server_Del));
250 EINA_SAFETY_ON_NULL_RETURN(ev);
251
252 svr->event_count++;
253 ev->server = svr;
254 ecore_event_add(ECORE_IPC_EVENT_SERVER_DEL, ev,
255 _ecore_ipc_event_server_del_free, NULL);
256}
257
258static void
259ecore_ipc_post_event_client_add(Ecore_Ipc_Client *cl)
260{
261 Ecore_Ipc_Event_Client_Add *ev;
262
263 if (cl->delete_me) return;
264
265 ev = calloc(1, sizeof(Ecore_Ipc_Event_Client_Add));
266 EINA_SAFETY_ON_NULL_RETURN(ev);
267
268 cl->event_count++;
269 ev->client = cl;
270 ecore_event_add(ECORE_IPC_EVENT_CLIENT_ADD, ev,
271 _ecore_ipc_event_client_add_free, NULL);
272}
273
274static void
275ecore_ipc_post_event_client_del(Ecore_Ipc_Client *cl)
276{
277 Ecore_Ipc_Event_Client_Del *ev;
278
279 if (cl->delete_me) return;
280
281 ev = calloc(1, sizeof(Ecore_Ipc_Event_Client_Del));
282 EINA_SAFETY_ON_NULL_RETURN(ev);
283
284 cl->event_count++;
285 ev->client = cl;
286 ecore_event_add(ECORE_IPC_EVENT_CLIENT_DEL, ev,
287 _ecore_ipc_event_client_del_free, NULL);
288}
289
290static Ecore_Ipc_Client *
291ecore_ipc_client_add(Ecore_Ipc_Server *svr)
292{
293 Ecore_Ipc_Client *cl;
294
295 cl = calloc(1, sizeof(Ecore_Ipc_Client));
296 EINA_SAFETY_ON_NULL_RETURN_VAL(cl, NULL);
297 cl->svr = svr;
298 ECORE_MAGIC_SET(cl, ECORE_MAGIC_IPC_CLIENT);
299 svr->clients = eina_list_append(svr->clients, cl);
300
301 return cl;
302}
303
226EAPI int 304EAPI int
227ecore_ipc_init(void) 305ecore_ipc_init(void)
228{ 306{
@@ -784,29 +862,14 @@ _ecore_ipc_event_client_add(void *data EINA_UNUSED, int ev_type EINA_UNUSED, voi
784 if (!eina_list_data_find(servers, svr)) return ECORE_CALLBACK_RENEW; 862 if (!eina_list_data_find(servers, svr)) return ECORE_CALLBACK_RENEW;
785 /* handling code here */ 863 /* handling code here */
786 { 864 {
787 Ecore_Ipc_Client *cl; 865 Ecore_Ipc_Client *cl = ecore_ipc_client_add(svr);
788 866
789 cl = calloc(1, sizeof(Ecore_Ipc_Client));
790 if (!cl) return ECORE_CALLBACK_CANCEL; 867 if (!cl) return ECORE_CALLBACK_CANCEL;
791 cl->svr = svr;
792 ECORE_MAGIC_SET(cl, ECORE_MAGIC_IPC_CLIENT);
793 cl->client = e->client; 868 cl->client = e->client;
794 cl->max_buf_size = 32 * 1024; 869 cl->max_buf_size = 32 * 1024;
795 ecore_con_client_data_set(cl->client, (void *)cl); 870 ecore_con_client_data_set(cl->client, (void *)cl);
796 svr->clients = eina_list_append(svr->clients, cl);
797 if (!cl->delete_me)
798 {
799 Ecore_Ipc_Event_Client_Add *e2;
800 871
801 e2 = calloc(1, sizeof(Ecore_Ipc_Event_Client_Add)); 872 ecore_ipc_post_event_client_add(cl);
802 if (e2)
803 {
804 cl->event_count++;
805 e2->client = cl;
806 ecore_event_add(ECORE_IPC_EVENT_CLIENT_ADD, e2,
807 _ecore_ipc_event_client_add_free, NULL);
808 }
809 }
810 } 873 }
811 return ECORE_CALLBACK_CANCEL; 874 return ECORE_CALLBACK_CANCEL;
812} 875}
@@ -827,21 +890,8 @@ _ecore_ipc_event_client_del(void *data EINA_UNUSED, int ev_type EINA_UNUSED, voi
827 890
828 cl = ecore_con_client_data_get(e->client); 891 cl = ecore_con_client_data_get(e->client);
829 cl->client = NULL; 892 cl->client = NULL;
830 {
831 Ecore_Ipc_Event_Client_Del *e2;
832 893
833 if (!cl->delete_me) 894 ecore_ipc_post_event_client_del(cl);
834 {
835 e2 = calloc(1, sizeof(Ecore_Ipc_Event_Client_Del));
836 if (e2)
837 {
838 cl->event_count++;
839 e2->client = cl;
840 ecore_event_add(ECORE_IPC_EVENT_CLIENT_DEL, e2,
841 _ecore_ipc_event_client_del_free, NULL);
842 }
843 }
844 }
845 } 895 }
846 return ECORE_CALLBACK_CANCEL; 896 return ECORE_CALLBACK_CANCEL;
847} 897}
@@ -858,19 +908,8 @@ _ecore_ipc_event_server_add(void *data EINA_UNUSED, int ev_type EINA_UNUSED, voi
858 Ecore_Ipc_Server *svr; 908 Ecore_Ipc_Server *svr;
859 909
860 svr = ecore_con_server_data_get(e->server); 910 svr = ecore_con_server_data_get(e->server);
861 if (!svr->delete_me)
862 {
863 Ecore_Ipc_Event_Server_Add *e2;
864 911
865 e2 = calloc(1, sizeof(Ecore_Ipc_Event_Server_Add)); 912 ecore_ipc_post_event_server_add(svr);
866 if (e2)
867 {
868 svr->event_count++;
869 e2->server = svr;
870 ecore_event_add(ECORE_IPC_EVENT_SERVER_ADD, e2,
871 _ecore_ipc_event_server_add_free, NULL);
872 }
873 }
874 } 913 }
875 return ECORE_CALLBACK_CANCEL; 914 return ECORE_CALLBACK_CANCEL;
876} 915}
@@ -888,19 +927,8 @@ _ecore_ipc_event_server_del(void *data EINA_UNUSED, int ev_type EINA_UNUSED, voi
888 927
889 svr = ecore_con_server_data_get(e->server); 928 svr = ecore_con_server_data_get(e->server);
890 svr->server = NULL; 929 svr->server = NULL;
891 if (!svr->delete_me)
892 {
893 Ecore_Ipc_Event_Server_Del *e2;
894 930
895 e2 = calloc(1, sizeof(Ecore_Ipc_Event_Server_Del)); 931 ecore_ipc_post_event_server_del(svr);
896 if (e2)
897 {
898 svr->event_count++;
899 e2->server = svr;
900 ecore_event_add(ECORE_IPC_EVENT_SERVER_DEL, e2,
901 _ecore_ipc_event_server_del_free, NULL);
902 }
903 }
904 } 932 }
905 return ECORE_CALLBACK_CANCEL; 933 return ECORE_CALLBACK_CANCEL;
906} 934}