simple-signal-emit.c

Server that registers a service interface and emits simple signals.

Server that registers a service interface and emits simple signals.

//Compile with:
// gcc -o simple-signal-emit simple-signal-emit.c `pkg-config --cflags --libs eldbus`
#include <Eldbus.h>
enum {
TEST_SIGNAL_ALIVE,
TEST_SIGNAL_PROP,
TEST_SIGNAL_NAME,
};
static const Eldbus_Signal test_signals[] = {
[TEST_SIGNAL_ALIVE] = { "Alive" },
[TEST_SIGNAL_PROP] = { "Properties", ELDBUS_ARGS({ "a{ss}", "properties"}) },
[TEST_SIGNAL_NAME] = { "Name", ELDBUS_ARGS({ "s", "name"}) },
{ }
};
/* signal with complex arguments (a dict) */
static void emit_properties(Eldbus_Service_Interface *iface)
{
Eldbus_Message *alive2;
Eldbus_Message_Iter *iter, *dict;
struct keyval {
const char *key;
const char *val;
} keyval[] = {
{ "key1", "val1" },
{ "key2", "val2" },
{ }
};
struct keyval *k;
alive2 = eldbus_service_signal_new(iface, TEST_SIGNAL_PROP);
iter = eldbus_message_iter_get(alive2);
dict = eldbus_message_iter_container_new(iter, 'a', "{ss}");
for (k = keyval; k && k->key; k++)
{
NULL);
eldbus_message_iter_arguments_append(entry, "ss", k->key, k->val);
}
}
/* signal with basic args */
static void emit_name(Eldbus_Service_Interface *iface)
{
eldbus_service_signal_emit(iface, TEST_SIGNAL_NAME, "TEST");
}
/* simple signal example */
static void emit_alive(Eldbus_Service_Interface *iface)
{
eldbus_service_signal_emit(iface, TEST_SIGNAL_ALIVE);
}
static const Eldbus_Service_Interface_Desc iface_desc = {
"org.enlightenment.Test", NULL, test_signals
};
int main(void)
{
Eldbus_Service_Interface *iface;
conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
iface = eldbus_service_interface_register(conn, "/org/enlightenment",
&iface_desc);
emit_alive(iface);
emit_name(iface);
emit_properties(iface);
return 0;
}
void eldbus_connection_unref(Eldbus_Connection *conn)
Decrement connection reference count.
Definition: eldbus_core.c:1306
Eldbus_Connection * eldbus_connection_get(Eldbus_Connection_Type type)
Establish a connection to bus and integrate it with the ecore main loop.
Definition: eldbus_core.c:1102
struct _Eldbus_Message_Iter Eldbus_Message_Iter
Represents an iterator over a complex message type (array, dict, struct, or variant).
Definition: Eldbus.h:181
struct _Eldbus_Message Eldbus_Message
Represents the way data is sent and received in DBus.
Definition: Eldbus.h:173
EAPI int eldbus_shutdown(void)
Shutdown eldbus.
Definition: eldbus_core.c:246
EAPI int eldbus_init(void)
Initialize eldbus.
Definition: eldbus_core.c:128
Eina_Bool eldbus_message_iter_container_close(Eldbus_Message_Iter *iter, Eldbus_Message_Iter *sub)
Closes a container-typed value appended to the message.
Definition: eldbus_message.c:548
Eldbus_Message_Iter * eldbus_message_iter_container_new(Eldbus_Message_Iter *iter, int type, const char *contained_signature)
Create and append a typed iterator to another iterator.
Definition: eldbus_message.c:526
Eldbus_Message_Iter * eldbus_message_iter_get(const Eldbus_Message *msg)
Get the main Eldbus_Message_Iter from the Eldbus_Message.
Definition: eldbus_message.c:264
Eina_Bool eldbus_message_iter_arguments_append(Eldbus_Message_Iter *iter, const char *signature,...)
Append an argument into an Eldbus_Message_Iter.
Definition: eldbus_message.c:379
Eldbus_Service_Interface * eldbus_service_interface_register(Eldbus_Connection *conn, const char *path, const Eldbus_Service_Interface_Desc *desc)
Register an interface in the given path and connection.
Definition: eldbus_service.c:998
Eina_Bool eldbus_service_signal_emit(const Eldbus_Service_Interface *iface, unsigned int signal_id,...)
Emit a signal handler of the interface with non-complex types.
Definition: eldbus_service.c:1414
Eldbus_Message * eldbus_service_signal_new(const Eldbus_Service_Interface *iface, unsigned int signal_id)
Create signal message.
Definition: eldbus_service.c:1402
#define ELDBUS_ARGS(args...)
Used to insert complete types to signature of methods or signals.
Definition: eldbus_service.h:33
Eina_Bool eldbus_service_signal_send(const Eldbus_Service_Interface *iface, Eldbus_Message *signal_msg)
Send a signal message.
Definition: eldbus_service.c:1444
struct _Eldbus_Connection Eldbus_Connection
Represents a connection of one the type of connection with the DBus daemon.
Definition: Eldbus.h:227
Definition: eldbus_service.h:103
Definition: eldbus_service.h:87