forked from enlightenment/efl
edbus: Use separate struct for description of Service Interface
Patch by: José Roberto de Souza <zehortigoza@profusion.mobi> SVN revision: 78801
This commit is contained in:
parent
71ab3d6a17
commit
5719e45bbd
|
@ -6,7 +6,6 @@
|
||||||
#define IFACE "com.profusion.Test"
|
#define IFACE "com.profusion.Test"
|
||||||
|
|
||||||
static char *resp2;
|
static char *resp2;
|
||||||
static Ecore_Timer *timer;
|
|
||||||
|
|
||||||
static EDBus_Message *
|
static EDBus_Message *
|
||||||
_receive_array(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
_receive_array(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
||||||
|
@ -344,59 +343,15 @@ static const EDBus_Signal properties_signals[] = {
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
static Eina_Bool _emmit_changed(void *data)
|
static const EDBus_Service_Interface_Desc iface_desc = {
|
||||||
{
|
IFACE, methods
|
||||||
EDBus_Service_Interface *iface = data;
|
};
|
||||||
EDBus_Message *sig = edbus_service_signal_new(iface, 0);
|
|
||||||
EDBus_Message_Iter *main_iter, *array, *entry, *var, *invalidate, *st;
|
|
||||||
|
|
||||||
main_iter = edbus_message_iter_get(sig);
|
|
||||||
if (!edbus_message_iter_arguments_set(main_iter, "sa{sv}", IFACE, &array))
|
|
||||||
{
|
|
||||||
printf("Error setting arguments of signal");
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
edbus_message_iter_arguments_set(array, "{sv}", &entry);
|
|
||||||
edbus_message_iter_arguments_set(entry, "s", "text");
|
|
||||||
var = edbus_message_iter_container_new(entry, 'v', "s");
|
|
||||||
edbus_message_iter_arguments_set(var, "s", "lalala text");
|
|
||||||
edbus_message_iter_container_close(entry, var);
|
|
||||||
edbus_message_iter_container_close(array, entry);
|
|
||||||
|
|
||||||
edbus_message_iter_arguments_set(array, "{sv}", &entry);
|
|
||||||
edbus_message_iter_arguments_set(entry, "s", "int32");
|
|
||||||
var = edbus_message_iter_container_new(entry, 'v', "i");
|
|
||||||
edbus_message_iter_arguments_set(var, "i", 35);
|
|
||||||
edbus_message_iter_container_close(entry, var);
|
|
||||||
edbus_message_iter_container_close(array, entry);
|
|
||||||
|
|
||||||
edbus_message_iter_arguments_set(array, "{sv}", &entry);
|
|
||||||
edbus_message_iter_arguments_set(entry, "s", "st");
|
|
||||||
var = edbus_message_iter_container_new(entry, 'v', "(ss)");
|
|
||||||
edbus_message_iter_arguments_set(var, "(ss)", &st);
|
|
||||||
edbus_message_iter_arguments_set(st, "ss", "string1", "string2");
|
|
||||||
edbus_message_iter_container_close(var, st);
|
|
||||||
edbus_message_iter_container_close(entry, var);
|
|
||||||
edbus_message_iter_container_close(array, entry);
|
|
||||||
|
|
||||||
edbus_message_iter_container_close(main_iter, array);
|
|
||||||
|
|
||||||
edbus_message_iter_arguments_set(main_iter, "as", &invalidate);
|
|
||||||
edbus_message_iter_container_close(main_iter, invalidate);
|
|
||||||
|
|
||||||
edbus_service_signal_send(iface, sig);
|
|
||||||
end:
|
|
||||||
edbus_message_unref(sig);
|
|
||||||
return EINA_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_name_request(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
|
on_name_request(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
|
||||||
{
|
{
|
||||||
EDBus_Connection *conn = data;
|
EDBus_Connection *conn = data;
|
||||||
unsigned int flag;
|
unsigned int flag;
|
||||||
EDBus_Service_Interface *piface;
|
|
||||||
|
|
||||||
resp2 = malloc(sizeof(char) * 5);
|
resp2 = malloc(sizeof(char) * 5);
|
||||||
strcpy(resp2, "test");
|
strcpy(resp2, "test");
|
||||||
|
@ -419,10 +374,7 @@ on_name_request(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
edbus_service_interface_register(conn, PATH, IFACE, methods, NULL);
|
edbus_service_interface_register(conn, PATH, &iface_desc);
|
||||||
piface = edbus_service_interface_register(conn, PATH, EDBUS_FDO_INTERFACE_PROPERTIES,
|
|
||||||
properties_methods, properties_signals);
|
|
||||||
timer = ecore_timer_add(3, _emmit_changed, piface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -440,7 +392,6 @@ main(void)
|
||||||
ecore_main_loop_begin();
|
ecore_main_loop_begin();
|
||||||
|
|
||||||
free(resp2);
|
free(resp2);
|
||||||
ecore_timer_del(timer);
|
|
||||||
edbus_connection_unref(conn);
|
edbus_connection_unref(conn);
|
||||||
|
|
||||||
edbus_shutdown();
|
edbus_shutdown();
|
||||||
|
|
|
@ -185,6 +185,10 @@ static const EDBus_Method methods[] = {
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const EDBus_Service_Interface_Desc iface_desc = {
|
||||||
|
INTERFACE, methods, signals
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_name_request(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
|
on_name_request(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
|
||||||
{
|
{
|
||||||
|
@ -209,8 +213,7 @@ on_name_request(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
iface = edbus_service_interface_register(conn, PATH, INTERFACE, methods,
|
iface = edbus_service_interface_register(conn, PATH, &iface_desc);
|
||||||
signals);
|
|
||||||
ecore_timer_add(5, send_signal_alive, iface);
|
ecore_timer_add(5, send_signal_alive, iface);
|
||||||
ecore_timer_add(6, send_signal_hello, iface);
|
ecore_timer_add(6, send_signal_hello, iface);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,10 @@ static void emit_alive(EDBus_Service_Interface *iface)
|
||||||
edbus_service_signal_emit(iface, TEST_SIGNAL_ALIVE);
|
edbus_service_signal_emit(iface, TEST_SIGNAL_ALIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const EDBus_Service_Interface_Desc iface_desc = {
|
||||||
|
"org.enlightenment.Test", NULL, test_signals
|
||||||
|
};
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
EDBus_Connection *conn;
|
EDBus_Connection *conn;
|
||||||
|
@ -64,8 +68,8 @@ int main(void)
|
||||||
edbus_init();
|
edbus_init();
|
||||||
|
|
||||||
conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION);
|
conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION);
|
||||||
iface = edbus_service_interface_register(
|
iface = edbus_service_interface_register(conn, "/org/enlightenment",
|
||||||
conn, "/org/enlightenment", "org.enlightenment.Test", NULL, test_signals);
|
&iface_desc);
|
||||||
|
|
||||||
emit_alive(iface);
|
emit_alive(iface);
|
||||||
emit_name(iface);
|
emit_name(iface);
|
||||||
|
|
|
@ -293,7 +293,7 @@ _edbus_service_method_add(EDBus_Service_Interface *interface, EDBus_Method *meth
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI EDBus_Service_Interface *
|
EAPI EDBus_Service_Interface *
|
||||||
edbus_service_interface_register(EDBus_Connection *conn, const char *path, const char *interface, const EDBus_Method methods[], const EDBus_Signal signals[])
|
edbus_service_interface_register(EDBus_Connection *conn, const char *path, const EDBus_Service_Interface_Desc *desc)
|
||||||
{
|
{
|
||||||
EDBus_Service_Object *obj;
|
EDBus_Service_Object *obj;
|
||||||
EDBus_Service_Interface *iface;
|
EDBus_Service_Interface *iface;
|
||||||
|
@ -303,7 +303,8 @@ edbus_service_interface_register(EDBus_Connection *conn, const char *path, const
|
||||||
|
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(conn, EINA_FALSE);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(conn, EINA_FALSE);
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(path, EINA_FALSE);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(path, EINA_FALSE);
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(interface, EINA_FALSE);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(desc, EINA_FALSE);
|
||||||
|
EINA_SAFETY_ON_NULL_RETURN_VAL(desc->interface, EINA_FALSE);
|
||||||
|
|
||||||
if (!dbus_connection_get_object_path_data(conn->dbus_conn, path,
|
if (!dbus_connection_get_object_path_data(conn->dbus_conn, path,
|
||||||
(void*)&obj))
|
(void*)&obj))
|
||||||
|
@ -316,7 +317,7 @@ edbus_service_interface_register(EDBus_Connection *conn, const char *path, const
|
||||||
obj = _edbus_service_object_add(conn, path);
|
obj = _edbus_service_object_add(conn, path);
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
|
||||||
|
|
||||||
iface = _edbus_service_interface_add(obj, interface);
|
iface = _edbus_service_interface_add(obj, desc->interface);
|
||||||
if (!iface)
|
if (!iface)
|
||||||
{
|
{
|
||||||
if (eina_hash_population(obj->interfaces) < 2)
|
if (eina_hash_population(obj->interfaces) < 2)
|
||||||
|
@ -324,21 +325,23 @@ edbus_service_interface_register(EDBus_Connection *conn, const char *path, const
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (method = (EDBus_Method *)methods; method && method->member; method++)
|
for (method = (EDBus_Method *)desc->methods; method && method->member; method++)
|
||||||
_edbus_service_method_add(iface, method);
|
_edbus_service_method_add(iface, method);
|
||||||
|
|
||||||
if (!iface->sign_of_signals)
|
if (!iface->sign_of_signals)
|
||||||
iface->sign_of_signals = eina_array_new(1);
|
iface->sign_of_signals = eina_array_new(1);
|
||||||
for (i = 0; &signals[i] && signals[i].name; i++)
|
for (i = 0; &desc->signals[i] && desc->signals[i].name; i++)
|
||||||
{
|
{
|
||||||
buf = eina_strbuf_new();
|
buf = eina_strbuf_new();
|
||||||
for (z = 0; &signals[i].args[z] && signals[i].args[z].signature; z++)
|
for (z = 0;
|
||||||
eina_strbuf_append(buf, signals[i].args[z].signature);
|
&desc->signals[i].args[z] && desc->signals[i].args[z].signature;
|
||||||
|
z++)
|
||||||
|
eina_strbuf_append(buf, desc->signals[i].args[z].signature);
|
||||||
|
|
||||||
if (!dbus_signature_validate(eina_strbuf_string_get(buf), NULL))
|
if (!dbus_signature_validate(eina_strbuf_string_get(buf), NULL))
|
||||||
{
|
{
|
||||||
ERR("Signal with invalid signature: interface=%s signal=%s",
|
ERR("Signal with invalid signature: interface=%s signal=%s",
|
||||||
iface->name, signals[i].name);
|
iface->name, desc->signals[i].name);
|
||||||
eina_strbuf_free(buf);
|
eina_strbuf_free(buf);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -347,7 +350,7 @@ edbus_service_interface_register(EDBus_Connection *conn, const char *path, const
|
||||||
eina_stringshare_add(eina_strbuf_string_get(buf)));
|
eina_stringshare_add(eina_strbuf_string_get(buf)));
|
||||||
eina_strbuf_free(buf);
|
eina_strbuf_free(buf);
|
||||||
}
|
}
|
||||||
iface->signals = signals;
|
iface->signals = desc->signals;
|
||||||
|
|
||||||
return iface;
|
return iface;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,13 @@ typedef struct _EDBus_Signal
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
} EDBus_Signal;
|
} EDBus_Signal;
|
||||||
|
|
||||||
|
typedef struct _EDBus_Service_Interface_Desc
|
||||||
|
{
|
||||||
|
const char *interface;
|
||||||
|
const EDBus_Method *methods;
|
||||||
|
const EDBus_Signal *signals;
|
||||||
|
} EDBus_Service_Interface_Desc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Register an interface in the given path and connection.
|
* @brief Register an interface in the given path and connection.
|
||||||
*
|
*
|
||||||
|
@ -60,7 +67,8 @@ typedef struct _EDBus_Signal
|
||||||
*
|
*
|
||||||
* @return Interface
|
* @return Interface
|
||||||
*/
|
*/
|
||||||
EAPI EDBus_Service_Interface *edbus_service_interface_register(EDBus_Connection *conn, const char *path, const char *interface, const EDBus_Method methods[], const EDBus_Signal signals[]);
|
EAPI EDBus_Service_Interface *edbus_service_interface_register(EDBus_Connection *conn, const char *path, const EDBus_Service_Interface_Desc *desc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unregister a interface.
|
* @brief Unregister a interface.
|
||||||
* If this is the last interface of the object path, the object path will be
|
* If this is the last interface of the object path, the object path will be
|
||||||
|
|
Loading…
Reference in New Issue