Eldbus

Date
  2012 (created)

# Table of Contents

- Introduction
- How to compile
- Next Steps
- Introductory Example

# Introduction

Eldbus is a wrapper around the dbus library, which is a message bus system. It also implements a set of specifications using dbus as interprocess communication.

## Modules

- Core
- Connection
- Object Mapper
- Proxy
- Message
  - Iterator
  - Message Helpers
  - Eina_Value to/from Message
- Signal Handler
- Pending
- Service
- Basic FreeDesktop.Org Methods

# How to compile

Eldbus is a library your application links to. The procedure for this is very simple. You simply have to compile your application with the appropriate compiler flags that the `pkg-config` script outputs. For example:

Compiling C or C++ files into object files:

    gcc -c -o main.o main.c `pkg-config --cflags eldbus`

Linking object files into a binary executable:

    gcc -o my_application main.o `pkg-config --libs eldbus`

See pkgconfig

# Next Steps

After you understood what Eldbus is and installed it in your system you should proceed understanding the programming interface.

Recommended reading:

- Core for library init, shutdown and getting a connection.
- Proxy to easily bind a client object to an interface.
- Object Mapper to monitor server objects and properties.

# Introductory Example

//Compile with:
// gcc -o ofono-dial ofono-dial.c `pkg-config --cflags --libs eldbus ecore`
#include "Eldbus.h"
#include <Ecore.h>
static void
on_dial(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
{
const char *errname, *errmsg;
const char *call_path;
if (eldbus_message_error_get(msg, &errname, &errmsg))
{
fprintf(stderr, "Error: %s %s\n", errname, errmsg);
return;
}
if (!eldbus_message_arguments_get(msg, "o", &call_path))
{
fprintf(stderr, "Error: could not get call path\n");
return;
}
printf("dialed! call path: %s\n", call_path);
}
int
main(int argc, char *argv[])
{
Eldbus_Connection *conn;
Eldbus_Object *obj;
Eldbus_Proxy *manager;
Eldbus_Pending *pending;
const char *number, *hide_callerid;
if (argc < 2)
{
fprintf(stderr, "Usage:\n\t%s <number> [hide_callerid]\n", argv[0]);
return EXIT_FAILURE;
}
number = argv[1];
hide_callerid = (argc > 2) ? argv[2] : "";
ecore_init();
eldbus_init();
conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
if (!conn)
{
fprintf(stderr, "Error: could not get system bus\n");
return EXIT_FAILURE;
}
obj = eldbus_object_get(conn, "org.ofono", "/");
if (!obj)
{
fprintf(stderr, "Error: could not get object\n");
return EXIT_FAILURE;
}
manager = eldbus_proxy_get(obj, "org.ofono.Manager");
if (!manager)
{
fprintf(stderr, "Error: could not get proxy\n");
return EXIT_FAILURE;
}
pending = eldbus_proxy_call(manager, "Dial", on_dial, NULL,
-1, "ss", number, hide_callerid);
if (!pending)
{
fprintf(stderr, "Error: could not call\n");
return EXIT_FAILURE;
}
ecore_main_loop_begin();
eldbus_proxy_unref(manager);
eldbus_object_unref(obj);
eldbus_connection_unref(conn);
eldbus_shutdown();
ecore_shutdown();
return 0;
}
ecore_shutdown
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition: ecore.c:371
ecore_init
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition: ecore.c:230
ecore_main_loop_begin
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
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_Message
struct _Eldbus_Message Eldbus_Message
Represents the way data is sent and received in DBus.
Definition: Eldbus.h:173
eldbus_shutdown
EAPI int eldbus_shutdown(void)
Shutdown eldbus.
Definition: eldbus_core.c:246
Eldbus_Pending
struct _Eldbus_Pending Eldbus_Pending
Represents a message that has been sent but has not yet reached its destination.
Definition: Eldbus.h:188
eldbus_init
EAPI int eldbus_init(void)
Initialize eldbus.
Definition: eldbus_core.c:128
eldbus_message_error_get
Eina_Bool eldbus_message_error_get(const Eldbus_Message *msg, const char **name, const char **text)
Get the error text and name from a Eldbus_Message.
Definition: eldbus_message.c:233
eldbus_message_arguments_get
Eina_Bool eldbus_message_arguments_get(const Eldbus_Message *msg, const char *signature,...)
Get the arguments from an Eldbus_Message.
Definition: eldbus_message.c:274
eldbus_object_get
Eldbus_Object * eldbus_object_get(Eldbus_Connection *conn, const char *bus, const char *path)
Get an object of the given bus and path.
Definition: eldbus_object.c:188
eldbus_object_unref
void eldbus_object_unref(Eldbus_Object *obj)
Decrease object reference.
Definition: eldbus_object.c:250
eldbus_proxy_call
Eldbus_Pending * eldbus_proxy_call(Eldbus_Proxy *proxy, const char *member, Eldbus_Message_Cb cb, const void *cb_data, double timeout, const char *signature,...)
Call a method in proxy.
Definition: eldbus_proxy.c:621
eldbus_proxy_get
Eldbus_Proxy * eldbus_proxy_get(Eldbus_Object *obj, const char *interface)
Get a proxy of the following interface name in a Eldbus_Object.
Definition: eldbus_proxy.c:208
eldbus_proxy_unref
void eldbus_proxy_unref(Eldbus_Proxy *proxy)
Decrease proxy reference.
Definition: eldbus_proxy.c:263
Eldbus_Connection
struct _Eldbus_Connection Eldbus_Connection
Represents a connection of one the type of connection with the DBus daemon.
Definition: Eldbus.h:227
Eldbus_Proxy
struct _Eldbus_Proxy Eldbus_Proxy
Represents a client object bound to an interface.
Definition: Eldbus.h:221
Eldbus_Object
struct _Eldbus_Object Eldbus_Object
Represents an object path already attached with bus name or unique id.
Definition: Eldbus.h:233

More examples can be found at Eldbus Examples.