forked from enlightenment/efl
edbus: Refactor examples
Patch by: José Roberto de Souza <zehortigoza@profusion.mobi> SVN revision: 80690
This commit is contained in:
parent
3134ba4ad0
commit
848788e65b
|
@ -4,10 +4,7 @@
|
|||
#define BUS "org.Enlightenment"
|
||||
#define PATH "/org/enlightenment"
|
||||
#define INTERFACE "org.enlightenment.Test"
|
||||
#define NTESTS 7
|
||||
|
||||
static int i = 0;
|
||||
static EDBus_Signal_Handler *sh;
|
||||
#define NTESTS 8
|
||||
|
||||
static void
|
||||
_on_alive(void *context, const EDBus_Message *msg)
|
||||
|
@ -15,20 +12,10 @@ _on_alive(void *context, const EDBus_Message *msg)
|
|||
printf("Alive\n\n");
|
||||
}
|
||||
|
||||
static void
|
||||
_on_alive2(void *context, const EDBus_Message *msg)
|
||||
{
|
||||
printf("Alive2\n\n");
|
||||
i++;
|
||||
if (i == 2)
|
||||
edbus_signal_handler_unref(sh);
|
||||
}
|
||||
|
||||
static void
|
||||
_on_hello(void *context, const EDBus_Message *msg)
|
||||
{
|
||||
char *txt;
|
||||
|
||||
const char *txt;
|
||||
if (edbus_message_arguments_get(msg, "s", &txt))
|
||||
printf("%s\n", txt);
|
||||
}
|
||||
|
@ -45,10 +32,11 @@ static void
|
|||
test(void)
|
||||
{
|
||||
static int n = 0;
|
||||
|
||||
n++;
|
||||
if (n == NTESTS)
|
||||
if (n >= NTESTS)
|
||||
printf("Passed in all tests\n");
|
||||
else
|
||||
printf("Passed in %d/%d tests\n", n, NTESTS);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -216,12 +204,7 @@ _on_async_test(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
|
|||
}
|
||||
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
static void
|
||||
on_name_owner_changed2(void *data, const char *bus, const char *old_id, const char *new_id)
|
||||
{
|
||||
printf("2 - Bus=%s | old=%s | new=%s\n", bus, old_id, new_id);
|
||||
test();
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -231,12 +214,10 @@ on_name_owner_changed(void *data, const char *bus, const char *old_id, const cha
|
|||
}
|
||||
|
||||
static Eina_Bool
|
||||
add_name_owner2(void *data)
|
||||
finish(void *data)
|
||||
{
|
||||
EDBus_Connection *conn = data;
|
||||
edbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed2,
|
||||
NULL, EINA_TRUE);
|
||||
return EINA_FALSE;
|
||||
ecore_main_loop_quit();
|
||||
return ECORE_CALLBACK_CANCEL;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -254,7 +235,6 @@ main(void)
|
|||
obj = edbus_object_get(conn, BUS, PATH);
|
||||
proxy = edbus_proxy_get(obj, INTERFACE);
|
||||
edbus_proxy_signal_handler_add(proxy, "Alive", _on_alive, NULL);
|
||||
sh = edbus_proxy_signal_handler_add(proxy, "Alive", _on_alive2, NULL);
|
||||
edbus_proxy_signal_handler_add(proxy, "Hello", _on_hello, NULL);
|
||||
|
||||
edbus_proxy_call(proxy, "SendBool", _on_send_bool, NULL, -1, "b", bool_value);
|
||||
|
@ -268,13 +248,10 @@ main(void)
|
|||
|
||||
edbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed,
|
||||
conn, EINA_TRUE);
|
||||
ecore_timer_add(3, add_name_owner2, conn);
|
||||
ecore_timer_add(30, finish, NULL);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
edbus_name_owner_changed_callback_del(conn, BUS, on_name_owner_changed, conn);
|
||||
edbus_name_owner_changed_callback_del(conn, BUS, on_name_owner_changed2,
|
||||
NULL);
|
||||
edbus_connection_unref(conn);
|
||||
|
||||
edbus_shutdown();
|
||||
|
|
|
@ -10,9 +10,9 @@ EDBus_Connection *conn;
|
|||
static Eina_Bool
|
||||
_timer1_cb(void *data)
|
||||
{
|
||||
printf("\n## ecore_main_loop_quit()\n");
|
||||
printf("\nFishing...\n");
|
||||
ecore_main_loop_quit();
|
||||
return EINA_TRUE;
|
||||
return ECORE_CALLBACK_CANCEL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -15,9 +15,9 @@ _receive_array(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
|||
{
|
||||
EDBus_Message *reply = edbus_message_method_return_new(msg);
|
||||
EDBus_Message_Iter *array;
|
||||
char *txt;
|
||||
const char *txt;
|
||||
|
||||
printf("receiveArray\n");
|
||||
printf("- receiveArray\n");
|
||||
if (!edbus_message_arguments_get(msg, "as", &array))
|
||||
{
|
||||
printf("Error on edbus_message_arguments_get()\n");
|
||||
|
@ -26,8 +26,7 @@ _receive_array(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
|||
|
||||
while (edbus_message_iter_get_and_next(array, 's', &txt))
|
||||
printf("%s\n", txt);
|
||||
|
||||
printf("\n");
|
||||
printf("}\n\n");
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
@ -36,11 +35,10 @@ static EDBus_Message *
|
|||
_receive_array_of_string_int_with_size(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
||||
{
|
||||
EDBus_Message *reply = edbus_message_method_return_new(msg);
|
||||
EDBus_Message_Iter *array;
|
||||
EDBus_Message_Iter *struct_si;
|
||||
EDBus_Message_Iter *array, *struct_si;
|
||||
int size, i = 0;
|
||||
|
||||
printf("receiveArrayOfStringIntWithSize\n");
|
||||
printf("- receiveArrayOfStringIntWithSize\n{\n");
|
||||
if (!edbus_message_arguments_get(msg, "ia(si)", &size, &array))
|
||||
{
|
||||
printf("Error on edbus_message_arguments_get()\n");
|
||||
|
@ -49,9 +47,8 @@ _receive_array_of_string_int_with_size(const EDBus_Service_Interface *iface, con
|
|||
|
||||
while (edbus_message_iter_get_and_next(array, 'r', &struct_si))
|
||||
{
|
||||
char *txt;
|
||||
const char *txt;
|
||||
int num;
|
||||
|
||||
if (!edbus_message_iter_arguments_get(struct_si, "si", &txt, &num))
|
||||
{
|
||||
printf("Error on edbus_message_arguments_get()\n");
|
||||
|
@ -61,7 +58,7 @@ _receive_array_of_string_int_with_size(const EDBus_Service_Interface *iface, con
|
|||
i++;
|
||||
}
|
||||
printf("size in msg %d | size read %d\n", size, i);
|
||||
printf("\n");
|
||||
printf("}\n\n");
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
@ -73,7 +70,7 @@ _send_variant(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
|||
EDBus_Message_Iter *variant;
|
||||
char *type;
|
||||
|
||||
printf("sendVariantData\n");
|
||||
printf("- sendVariantData\n{\n");
|
||||
if (!edbus_message_arguments_get(msg, "v", &variant))
|
||||
{
|
||||
printf("Error on edbus_message_arguments_get()\n");
|
||||
|
@ -81,7 +78,7 @@ _send_variant(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
|||
}
|
||||
|
||||
type = edbus_message_iter_signature_get(variant);
|
||||
if (type[1] || type[0] == 'v')
|
||||
if (type[1])
|
||||
{
|
||||
printf("It is a complex type, not handle yet.\n");
|
||||
free(type);
|
||||
|
@ -111,7 +108,7 @@ _send_variant(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
|||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
printf("}\n\n");
|
||||
|
||||
free(type);
|
||||
return reply;
|
||||
|
@ -124,7 +121,7 @@ _send_array_int(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
|||
EDBus_Message_Iter *iter, *array;
|
||||
int i;
|
||||
|
||||
printf("sendArrayInt\n\n");
|
||||
printf("- sendArrayInt\n\n");
|
||||
|
||||
iter = edbus_message_iter_get(reply);
|
||||
array = edbus_message_iter_container_new(iter, 'a', "i");
|
||||
|
@ -160,7 +157,7 @@ _plus_one(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
|||
EDBus_Message *reply = edbus_message_method_return_new(msg);
|
||||
int num;
|
||||
|
||||
printf("plusOne\n\n");
|
||||
printf("- plusOne\n\n");
|
||||
if (!edbus_message_arguments_get(msg, "i", &num))
|
||||
{
|
||||
printf("Error on edbus_message_arguments_get()\n");
|
||||
|
@ -185,7 +182,7 @@ _double_container(const EDBus_Service_Interface *iface, const EDBus_Message *msg
|
|||
return NULL;
|
||||
}
|
||||
|
||||
printf("DoubleCountainer\nArray1:\n");
|
||||
printf("DoubleCountainer\n{\nArray1:\n");
|
||||
while (edbus_message_iter_get_and_next(array1, 'r', &structure))
|
||||
{
|
||||
edbus_message_iter_arguments_get(structure, "ii", &num1, &num2);
|
||||
|
@ -198,7 +195,7 @@ _double_container(const EDBus_Service_Interface *iface, const EDBus_Message *msg
|
|||
edbus_message_iter_arguments_get(structure, "ii", &num1, &num2);
|
||||
printf("1 %d - 2 %d\n", num1, num2);
|
||||
}
|
||||
printf("\n");
|
||||
printf("}\n\n");
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
@ -242,7 +239,7 @@ _properties_set(const EDBus_Service_Interface *iface, const char *propname, cons
|
|||
if (type[0] != 's')
|
||||
{
|
||||
reply = edbus_message_error_new(msg, "org.freedesktop.DBus.Error.InvalidSignature",
|
||||
"Invalid type.");
|
||||
"Invalid type.");
|
||||
free(type);
|
||||
return reply;
|
||||
}
|
||||
|
@ -260,7 +257,7 @@ _properties_set(const EDBus_Service_Interface *iface, const char *propname, cons
|
|||
static const EDBus_Method methods[] = {
|
||||
{
|
||||
"ReceiveArray", EDBUS_ARGS({"as", "array_of_strings"}),
|
||||
NULL, _receive_array, 0
|
||||
NULL, _receive_array
|
||||
},
|
||||
{
|
||||
"ReceiveArrayOfStringIntWithSize",
|
||||
|
@ -269,7 +266,7 @@ static const EDBus_Method methods[] = {
|
|||
},
|
||||
{
|
||||
"SendVariantData", EDBUS_ARGS({"v", "variant_data"}),
|
||||
NULL, _send_variant, 0
|
||||
NULL, _send_variant
|
||||
},
|
||||
{
|
||||
"SendArrayInt", NULL,
|
||||
|
@ -277,24 +274,24 @@ static const EDBus_Method methods[] = {
|
|||
},
|
||||
{
|
||||
"SendArray", NULL, EDBUS_ARGS({"as", "array_string"}),
|
||||
_send_array, 0
|
||||
_send_array
|
||||
},
|
||||
{
|
||||
"PlusOne", EDBUS_ARGS({"i", "integer"}),
|
||||
EDBUS_ARGS({"i", "integer_plus_one"}), _plus_one, 0
|
||||
EDBUS_ARGS({"i", "integer_plus_one"}), _plus_one
|
||||
},
|
||||
{
|
||||
"DoubleContainner", EDBUS_ARGS({"a(ii)", "array1"}, {"a(ii)", "array2"}),
|
||||
NULL, _double_container, 0
|
||||
NULL, _double_container
|
||||
},
|
||||
{ }
|
||||
};
|
||||
|
||||
static const EDBus_Property properties[] = {
|
||||
{ "Resp2", "s", NULL, _properties_set },
|
||||
{ "text", "s", NULL, NULL },
|
||||
{ "int32", "i", NULL, NULL },
|
||||
{ "st", "(ss)", NULL, NULL},
|
||||
{ "text", "s" },
|
||||
{ "int32", "i" },
|
||||
{ "st", "(ss)" },
|
||||
{ }
|
||||
};
|
||||
|
||||
|
@ -307,7 +304,7 @@ static Eina_Bool _emit_changed(void *data)
|
|||
EDBus_Service_Interface *iface = data;
|
||||
edbus_service_property_changed(iface, "int32");
|
||||
edbus_service_property_invalidate_set(iface, "Resp2", EINA_TRUE);
|
||||
return EINA_TRUE;
|
||||
return ECORE_CALLBACK_RENEW;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#define PATH_TEST_SON "/org/enlightenment/son"
|
||||
#define INTERFACE "org.enlightenment.Test"
|
||||
|
||||
EDBus_Connection *conn;
|
||||
static EDBus_Connection *conn;
|
||||
|
||||
static EDBus_Message *
|
||||
_hello(const EDBus_Service_Interface *iface, const EDBus_Message *message)
|
||||
|
@ -117,7 +117,7 @@ static EDBus_Message *
|
|||
_send_string(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
||||
{
|
||||
EDBus_Message *reply = edbus_message_method_return_new(msg);
|
||||
char *txt;
|
||||
const char *txt;
|
||||
if (!edbus_message_arguments_get(msg, "s", &txt))
|
||||
printf("edbus_message_arguments_get() error\n");
|
||||
edbus_message_arguments_set(reply, "s", txt);
|
||||
|
@ -140,7 +140,7 @@ _async_test(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
|||
EDBus_Message *reply = edbus_message_method_return_new(msg);
|
||||
printf("Received a call to AsyncTest.\n");
|
||||
printf("Response will be send in 5 seconds.\n");
|
||||
ecore_timer_add (5, _resp_async, reply);
|
||||
ecore_timer_add(5, _resp_async, reply);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -153,35 +153,35 @@ static const EDBus_Signal signals[] = {
|
|||
static const EDBus_Method methods[] = {
|
||||
{
|
||||
"Hello", NULL, EDBUS_ARGS({"s", "message"}),
|
||||
_hello, 0
|
||||
_hello
|
||||
},
|
||||
{
|
||||
"Quit", NULL, NULL,
|
||||
_quit, EDBUS_METHOD_FLAG_DEPRECATED
|
||||
},
|
||||
{ "SendBool", EDBUS_ARGS({"b", "bool"}), EDBUS_ARGS({"b", "bool"}),
|
||||
_send_bool, 0
|
||||
_send_bool
|
||||
},
|
||||
{ "SendByte", EDBUS_ARGS({"y", "byte"}), EDBUS_ARGS({"y", "byte"}),
|
||||
_send_byte, 0
|
||||
_send_byte
|
||||
},
|
||||
{ "SendUint32", EDBUS_ARGS({"u", "uint32"}), EDBUS_ARGS({"u", "uint32"}),
|
||||
_send_uint32, 0
|
||||
_send_uint32
|
||||
},
|
||||
{ "SendInt32", EDBUS_ARGS({"i", "int32"}), EDBUS_ARGS({"i", "int32"}),
|
||||
_send_int32, 0
|
||||
_send_int32
|
||||
},
|
||||
{ "SendInt16", EDBUS_ARGS({"n", "int16"}), EDBUS_ARGS({"n", "int16"}),
|
||||
_send_int16, 0
|
||||
_send_int16
|
||||
},
|
||||
{ "SendDouble", EDBUS_ARGS({"d", "double"}), EDBUS_ARGS({"d", "double"}),
|
||||
_send_double, 0
|
||||
_send_double
|
||||
},
|
||||
{ "SendString", EDBUS_ARGS({"s", "string"}), EDBUS_ARGS({"s", "string"}),
|
||||
_send_string, 0
|
||||
_send_string
|
||||
},
|
||||
{ "AsyncTest", NULL, EDBUS_ARGS({"s", "text"}),
|
||||
_async_test, 0
|
||||
_async_test
|
||||
},
|
||||
{ }
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue