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++)
{
Eldbus_Message_Iter *entry = eldbus_message_iter_container_new(dict, 'e',
NULL);
eldbus_message_iter_arguments_append(entry, "ss", k->key, k->val);
eldbus_message_iter_container_close(dict, entry);
}
eldbus_message_iter_container_close(iter, dict);
eldbus_service_signal_send(iface, alive2);
}
/* 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_Connection *conn;
Eldbus_Service_Interface *iface;
eldbus_init();
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);
eldbus_connection_unref(conn);
eldbus_shutdown();
return 0;
}
eldbus_connection_unref
void eldbus_connection_unref(Eldbus_Connection *conn)
Decrement connection reference count.
Definition eldbus_core.c:1306
eldbus_connection_get
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
eldbus_shutdown
EAPI int eldbus_shutdown(void)
Shutdown eldbus.
Definition eldbus_core.c:246
Eldbus_Message
struct _Eldbus_Message Eldbus_Message
Represents the way data is sent and received in DBus.
Definition Eldbus.h:173
Eldbus_Message_Iter
struct _Eldbus_Message_Iter Eldbus_Message_Iter
Represents an iterator over a complex message type (array, dict, struct, or variant).
Definition Eldbus.h:181
eldbus_init
EAPI int eldbus_init(void)
Initialize eldbus.
Definition eldbus_core.c:128
eldbus_message_iter_container_close
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_container_new
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_get
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
eldbus_message_iter_arguments_append
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_register
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
eldbus_service_signal_emit
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_service_signal_new
Eldbus_Message * eldbus_service_signal_new(const Eldbus_Service_Interface *iface, unsigned int signal_id)
Create signal message.
Definition eldbus_service.c:1402
ELDBUS_ARGS
#define ELDBUS_ARGS(args...)
Used to insert complete types to signature of methods or signals.
Definition eldbus_service.h:33
eldbus_service_signal_send
Eina_Bool eldbus_service_signal_send(const Eldbus_Service_Interface *iface, Eldbus_Message *signal_msg)
Send a signal message.
Definition eldbus_service.c:1444
Eldbus_Connection
struct _Eldbus_Connection Eldbus_Connection
Represents a connection of one the type of connection with the DBus daemon.
Definition Eldbus.h:227