aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/ephoto_ipc.c
blob: a5b781a19c944553396ac144d685c83848495e6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "ephoto.h"
#undef ERR
#define ERR(...) do { printf(__VA_ARGS__); putc('\n', stdout); } while (0)

#ifdef USE_IPC
/* local subsystem functions */
static Eina_Bool _e_ipc_cb_client_del(void *data EINA_UNUSED,
                                      int type EINA_UNUSED, void *event);
static Eina_Bool _e_ipc_cb_client_data(void *data EINA_UNUSED,
                                       int type EINA_UNUSED, void *event);

/* local subsystem globals */
static Ecore_Ipc_Server *_e_ipc_server = NULL;
#endif

/* externally accessible functions */
int
e_ipc_init(void)
{
#ifdef USE_IPC
   int port = getpid();
   /* NOTE: windows has no getppid(), so use an envvar */
   char port_str[sizeof("2147483648")] = "";
   snprintf(port_str, sizeof(port_str), "%d", port);
   setenv("EPHOTO_IPC_PORT", port_str, 1);
   _e_ipc_server = ecore_ipc_server_add
       (ECORE_IPC_LOCAL_SYSTEM, "ephoto", port, NULL);
   if (!_e_ipc_server)
     {
        ERR("Couldn't create Ephoto IPC server port=%d", port);
        return 0;
     }
   ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL,
                           _e_ipc_cb_client_del, NULL);
   ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA,
                           _e_ipc_cb_client_data, NULL);
#endif
   return 1;
}

int
e_ipc_shutdown(void)
{
#ifdef USE_IPC
   if (_e_ipc_server)
     {
        ecore_ipc_server_del(_e_ipc_server);
        _e_ipc_server = NULL;
     }
#endif
   return 1;
}

#ifdef USE_IPC
/* local subsystem globals */
static Eina_Bool
_e_ipc_cb_client_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
{
   Ecore_Ipc_Event_Client_Del *e;

   e = event;
   if (ecore_ipc_client_server_get(e->client) != _e_ipc_server)
     return ECORE_CALLBACK_PASS_ON;
   /* delete client sruct */
   e_thumb_client_del(e);
   ecore_ipc_client_del(e->client);
   return ECORE_CALLBACK_PASS_ON;
}

static Eina_Bool
_e_ipc_cb_client_data(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
{
   Ecore_Ipc_Event_Client_Data *e;

   e = event;
   if (ecore_ipc_client_server_get(e->client) != _e_ipc_server)
     return ECORE_CALLBACK_PASS_ON;
   switch (e->major)
     {
      case EPHOTO_IPC_DOMAIN_THUMB:
        e_thumb_client_data(e);
        break;

      default:
        break;
     }
   return ECORE_CALLBACK_PASS_ON;
}

#endif