acquire.c File Reference


Detailed Description

Functions for manage connection to DBus bus.
Date:
Created: 06/07/07 23:49:35 CEST
Author:
Daniele Rondina aka ge@@ru <geaaru@gmail.com>

Definition in file acquire.c.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "easydbus-core.h"
#include "debug.h"
#include "utils.h"
#include "acquire_internal.h"
#include "monitor_internal.h"
#include "message_internal.h"

Include dependency graph for acquire.c:

Go to the source code of this file.

Functions

EasyDbus_conneasydbus_conn_create (void)
 Create and init EasyDbus_conn object.
int easydbus_conn_destroy (EasyDbus_conn *conn)
 Deinitialize EasyDbus_conn object, close connection to Dbus and remove registered objects.
int easydbus_conn_get_address (EasyDbus_conn *conn, char *serviceName, enum easydbus_bus bus, int flags)
 Acquire source address.
void * easydbus_conn_get_closure (EasyDbus_conn *c)
 Get closure of EasyDbus_conn object.
int easydbus_conn_get_fd (EasyDbus_conn *data)
 Get connection file descriptor of connection.
int easydbus_conn_get_n_object (EasyDbus_conn *conn)
 Get number of objects of EasyDbus_conn connection.
EasyDbus_objecteasydbus_conn_get_object (EasyDbus_conn *conn, unsigned int n)
 Get n-EasyDbus_object of connection.
const char * easydbus_conn_get_service_name (const EasyDbus_conn *conn)
 Get service name.
int easydbus_conn_get_system_service_address (EasyDbus_conn *data, char *serviceName)
 Acquire source address from environment variable.
int easydbus_conn_reconnect (EasyDbus_conn *conn, int sleep_time)
 Try to reconnect to DBus through previous data.
void easydbus_conn_set_closure (EasyDbus_conn *c, void *closure)
 Set closure of EasyDbus_conn object.
int easydbus_conn_set_error_cb (EasyDbus_conn *conn, easydbus_error_cb_f cb, void *user_closure)
 Set user callback for handle error on Dbus connection.
int easydbus_conn_set_error_message_cb (EasyDbus_conn *conn, easydbus_error_message_cb_f e_cb, void *user_closure)
 Set user callback for handle error message not connected to a pending message.
int easydbus_conn_set_reply_async_cb (EasyDbus_conn *conn, easydbus_reply_async_cb_f r_cb, void *user_closure)
 Set user callback for handle reply to asynchronous method call on easydbus_main_loop or through watcher.
int easydbus_conn_set_reply_message_cb (EasyDbus_conn *conn, easydbus_reply_message_cb_f r_cb)
 Set user callback for handle reply message connected to a pending message.


Function Documentation

void* easydbus_conn_get_closure ( EasyDbus_conn c  ) 

Get closure of EasyDbus_conn object.

Parameters:
c EasyDbus_conn object pointer
Returns:
pointer to closure data

Definition at line 380 of file acquire.c.

References EasyDbus_conn::closure.

00381 {
00382    return (c ? c->closure : NULL);
00383 }

int easydbus_conn_reconnect ( EasyDbus_conn conn,
int  sleep_time 
)

Try to reconnect to DBus through previous data.

Parameters:
conn EasyDbus_conn object pointer
sleep_time time before reconnect (in seconds)
Note:
This function MUST be called only if a Disconnect signal is handled and on easydbus_error_cb_f callback. However, it is advise use of this function for system service because libdbus leave a reference count of 1 on DBusConnection and so doesn't free all data until easydbus_deinit is called.
Returns:
-1 error

EASYDBUS_CONN_NAME_SERVICE_EXISTS name service exists.

EASYDBUS_CONN_NAME_SERVICE_IN_QUEUE name service in queue.

EASYDBUS_CONN_NAME_SERVICE_PRIMARY name service is primary name.

EASYDBUS_CONN_NAME_SERVICE_RENAMED name service is been renamed.

Definition at line 112 of file acquire.c.

References EasyDbus_conn::bus, EasyDbus_core::conn, EasyDbus_object_box::core, easydbus_acquire_name(), EASYDBUS_CONN_DO_NOT_QUEUE, easydbus_conn_enable_filters(), EASYDBUS_CONN_NAME_SERVICE_EXISTS, EASYDBUS_CONN_NAME_SERVICE_RENAMED, easydbus_connect_to_bus(), easydbus_found_new_name(), EASYDBUS_SESSION, EASYDBUS_SESSION_SERVER, EASYDBUS_SYSTEM, EASYDBUS_SYSTEM_SERVER, easydbus_watcher_enable(), EasyDbusDebug, EasyDbus_conn::flags, EasyDbus_object_box::next, EasyDbus_core::objects, EasyDbus_object::path, EasyDbus_conn::registered_ondbus, EasyDbus_core::service_name, EasyDbus_object_box::vtable, EasyDbus_conn::watcher_add_cb, EasyDbus_conn::watcher_closure, and EasyDbus_conn::watcher_remove_cb.

00113 {
00114    DBusError err;
00115    int result = -1;
00116    struct EasyDbus_object_box *object;
00117    struct EasyDbus_core *core = 
00118       (struct EasyDbus_core *)conn;
00119    char *new_service_name = NULL;
00120 
00121    if (!conn || !core->service_name)
00122       return -1;
00123 
00124    if (core->conn)
00125       dbus_connection_unref(core->conn);
00126    core->conn = NULL;
00127    conn->registered_ondbus = 0;
00128 
00129    dbus_error_init (&err);
00130 
00131    sleep (sleep_time);
00132 
00133    // Acquire bus address
00134    switch (conn->bus) {
00135       case EASYDBUS_SESSION:
00136       case EASYDBUS_SESSION_SERVER:
00137          if (easydbus_connect_to_bus (core, &err, DBUS_BUS_SESSION))
00138             goto error;
00139          break;
00140       case EASYDBUS_SYSTEM:
00141       case EASYDBUS_SYSTEM_SERVER:
00142          if (easydbus_connect_to_bus (core, &err, DBUS_BUS_SYSTEM))
00143             goto error;
00144          break;
00145       default:
00146          goto error;
00147          break;
00148    }
00149 
00150    result = easydbus_acquire_name (core, core->service_name, 
00151                                    conn->flags, &err);
00152 
00153    if (result == EASYDBUS_CONN_NAME_SERVICE_EXISTS &&
00154        // probably this isn't needed because without this flags
00155        // return value is EASYDBUS_CONN_NAME_SERVICE_IN_QUEUE
00156        (conn->flags & EASYDBUS_CONN_DO_NOT_QUEUE)) {
00157       if (conn->flags & EASYDBUS_CONN_NAME_SERVICE_RENAMED) {
00158          new_service_name = easydbus_found_new_name
00159             (core, core->service_name, conn->flags, &err);
00160          if (new_service_name == NULL)
00161             goto error;
00162          result = EASYDBUS_CONN_NAME_SERVICE_RENAMED;
00163       }
00164       else
00165          goto error;
00166    }
00167 
00168    conn->registered_ondbus = 1;
00169    if (new_service_name) {
00170       if (core->service_name)
00171          free (core->service_name);
00172       core->service_name = new_service_name;
00173    }
00174 
00175    if (core->objects) {
00176       for (object = core->objects; object; 
00177            object = object->next) {
00178          if (!dbus_connection_register_object_path (core->conn,
00179                                      (const char *) object->core.path, 
00180                                                     &object->vtable,
00181                                                     core)) {
00182             EasyDbusDebug ("Error on register object %s", object->core.path);
00183             goto error;
00184          }
00185       }
00186       easydbus_conn_enable_filters (conn);
00187    }
00188 
00189    // check if there is watcher
00190    if (conn->watcher_add_cb && conn->watcher_remove_cb) {
00191       if (easydbus_watcher_enable (conn, conn->watcher_add_cb,
00192                                    conn->watcher_remove_cb,
00193                                    conn->watcher_closure))
00194          goto error;
00195    }
00196 
00197    dbus_error_free (&err);
00198 
00199    return result;
00200 error:
00201    if (conn->registered_ondbus)
00202       dbus_bus_release_name (core->conn, core->service_name, &err);
00203 
00204    if (core->conn != NULL)
00205       dbus_connection_unref (core->conn);
00206 
00207    dbus_error_free (&err);
00208    return -1;
00209 }

Here is the call graph for this function:

void easydbus_conn_set_closure ( EasyDbus_conn c,
void *  closure 
)

Set closure of EasyDbus_conn object.

Parameters:
c EasyDbus_conn object pointer
closure pointer to user data.

Definition at line 369 of file acquire.c.

References EasyDbus_conn::closure.

00371 {
00372    c->closure = closure;
00373 }


Generated on Thu Apr 10 10:00:20 2008 for EasyDbus-0.2 by  doxygen 1.5.4