2
// gcc -o server server.c `pkg-config --cflags --libs eldbus ecore`
7
#define BUS "org.Enlightenment"
8
#define PATH "/org/enlightenment"
9
#define PATH_TEST_SON "/org/enlightenment/son"
10
#define INTERFACE "org.enlightenment.Test"
12
static Eldbus_Connection *conn;
14
static Eldbus_Message *
15
_hello(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *message)
17
Eldbus_Message *reply = eldbus_message_method_return_new(message);
18
eldbus_message_arguments_append(reply, "s", "Hello World");
23
static Eldbus_Message *
24
_quit(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *message)
27
ecore_main_loop_quit();
28
return eldbus_message_method_return_new(message);
33
TEST_SIGNAL_ALIVE = 0,
38
send_signal_alive(void *data)
40
Eldbus_Service_Interface *iface = data;
41
eldbus_service_signal_emit(iface, TEST_SIGNAL_ALIVE);
42
return ECORE_CALLBACK_RENEW;
46
send_signal_hello(void *data)
48
Eldbus_Service_Interface *iface = data;
49
eldbus_service_signal_emit(iface, TEST_SIGNAL_HELLO, "Hello World");
50
return ECORE_CALLBACK_RENEW;
53
static Eldbus_Message *
54
_send_bool(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
56
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
58
if (!eldbus_message_arguments_get(msg, "b", &bool))
59
printf("eldbus_message_arguments_get() error\n");
60
eldbus_message_arguments_append(reply, "b", bool);
64
static Eldbus_Message *
65
_send_byte(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
67
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
69
if (!eldbus_message_arguments_get(msg, "y", &byte))
70
printf("eldbus_message_arguments_get() error\n");
71
eldbus_message_arguments_append(reply, "y", byte);
75
static Eldbus_Message *
76
_send_uint32(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
78
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
80
if (!eldbus_message_arguments_get(msg, "u", &uint32))
81
printf("eldbus_message_arguments_get() error\n");
82
eldbus_message_arguments_append(reply, "u", uint32);
86
static Eldbus_Message *
87
_send_int32(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
89
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
91
if (!eldbus_message_arguments_get(msg, "i", &int32))
92
printf("eldbus_message_arguments_get() error\n");
93
eldbus_message_arguments_append(reply, "i", int32);
97
static Eldbus_Message *
98
_send_int16(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
100
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
102
if (!eldbus_message_arguments_get(msg, "n", &int16))
103
printf("eldbus_message_arguments_get() error\n");
104
eldbus_message_arguments_append(reply, "n", int16);
108
static Eldbus_Message *
109
_send_double(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
111
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
113
if (!eldbus_message_arguments_get(msg, "d", &d))
114
printf("eldbus_message_arguments_get() error\n");
115
eldbus_message_arguments_append(reply, "d", d);
119
static Eldbus_Message *
120
_send_string(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
122
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
124
if (!eldbus_message_arguments_get(msg, "s", &txt))
125
printf("eldbus_message_arguments_get() error\n");
126
eldbus_message_arguments_append(reply, "s", txt);
131
_resp_async(void *data)
133
Eldbus_Message *msg = data;
134
eldbus_message_arguments_append(msg, "s", "Async test ok");
135
eldbus_connection_send(conn, msg, NULL, NULL, -1);
136
return ECORE_CALLBACK_CANCEL;
139
static Eldbus_Message *
140
_async_test(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
142
Eldbus_Message *reply = eldbus_message_method_return_new(msg);
143
printf("Received a call to AsyncTest.\n");
144
printf("Response will be send in 5 seconds.\n");
145
ecore_timer_add(5, _resp_async, reply);
149
static const Eldbus_Signal signals[] = {
150
[TEST_SIGNAL_ALIVE] = {"Alive", NULL, 0},
151
[TEST_SIGNAL_HELLO] = {"Hello", ELDBUS_ARGS({ "s", "message" }), 0},
155
static const Eldbus_Method methods[] = {
157
"Hello", NULL, ELDBUS_ARGS({"s", "message"}),
162
_quit, ELDBUS_METHOD_FLAG_DEPRECATED
164
{ "SendBool", ELDBUS_ARGS({"b", "bool"}), ELDBUS_ARGS({"b", "bool"}),
167
{ "SendByte", ELDBUS_ARGS({"y", "byte"}), ELDBUS_ARGS({"y", "byte"}),
170
{ "SendUint32", ELDBUS_ARGS({"u", "uint32"}), ELDBUS_ARGS({"u", "uint32"}),
173
{ "SendInt32", ELDBUS_ARGS({"i", "int32"}), ELDBUS_ARGS({"i", "int32"}),
176
{ "SendInt16", ELDBUS_ARGS({"n", "int16"}), ELDBUS_ARGS({"n", "int16"}),
179
{ "SendDouble", ELDBUS_ARGS({"d", "double"}), ELDBUS_ARGS({"d", "double"}),
182
{ "SendString", ELDBUS_ARGS({"s", "string"}), ELDBUS_ARGS({"s", "string"}),
185
{ "AsyncTest", NULL, ELDBUS_ARGS({"s", "text"}),
191
static const Eldbus_Service_Interface_Desc iface_desc = {
192
INTERFACE, methods, signals
196
on_name_request(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
198
Eldbus_Service_Interface *iface;
202
if (eldbus_message_error_get(msg, NULL, NULL))
204
printf("error on on_name_request\n");
208
if (!eldbus_message_arguments_get(msg, "u", &reply))
210
printf("error geting arguments on on_name_request\n");
214
if (reply != ELDBUS_NAME_REQUEST_REPLY_PRIMARY_OWNER)
216
printf("error name already in use\n");
220
ecore_timer_add(5, send_signal_alive, iface);
221
ecore_timer_add(6, send_signal_hello, iface);
227
Eldbus_Service_Interface *iface;
232
conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
234
iface = eldbus_service_interface_register(conn, PATH, &iface_desc);
235
eldbus_name_request(conn, BUS, ELDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE,
236
on_name_request, iface);
238
eldbus_service_interface_register(conn, PATH_TEST_SON, &iface_desc);
240
ecore_main_loop_begin();
242
eldbus_connection_unref(conn);