watcher
[monitor]

Collaboration diagram for watcher:

Detailed Description

Module for manage EasyDbus_watcher object

This module is under hard development phase and could be change on new versions.

EasyDbus_watcher Meta Information

Contact:
Daniele Rondina aka Ge@@ru <geaaru@gmail.com>
Status:
EasyDbus Core Library
License:
GPL
Contributor(s):


Data Structures

struct  EasyDbus_watcher
 This struct is a list for manage watching, In this moment this list could be only an element for connection. More...

Functions

void easydbus_toggle_watch_callback (DBusWatch *watch, void *data)
 Handler of dbus watch toggle callback.
int easydbus_watcher_enable (EasyDbus_conn *conn, easydbus_watcher_add_cb_f watcher_add_cb, easydbus_watcher_remove_cb_f watcher_remove_cb, void *closure)
 Enable watcher for current connection.
EasyDbus_conneasydbus_watcher_get_conn (EasyDbus_watcher *watch)
 Recover EasyDbus_conn object connected to Easydbus_watcher object.
int easydbus_watcher_get_fd (EasyDbus_watcher *watcher)
 Get file descriptor of EasyDbus_watcher object.
int * easydbus_watcher_get_fd_list (EasyDbus_conn *data, int *num_fd)
 Recover watcher fd list enabled.
unsigned int easydbus_watcher_get_flags (EasyDbus_watcher *watch)
 Recover type of watcher.


Function Documentation

void easydbus_toggle_watch_callback ( DBusWatch *  watch,
void *  data 
)

Handler of dbus watch toggle callback.

Note:
When a watch is toggled off, it must be remove from file descriptor watch system.
Parameters:
watch DBusWatch object pointer that will be removed.
data Closure data.

Definition at line 208 of file watch_events_internal.c.

References easydbus_remove_watch_callback(), and EasyDbusDebug.

Referenced by easydbus_watcher_enable().

00210 {
00211    EasyDbusDebug ("Toggle callback");
00212    easydbus_remove_watch_callback (watch, data);
00213 }

Here is the call graph for this function:

int easydbus_watcher_enable ( EasyDbus_conn conn,
easydbus_watcher_add_cb_f  watcher_add_cb,
easydbus_watcher_remove_cb_f  watcher_remove_cb,
void *  closure 
)

Enable watcher for current connection.

Parameters:
conn EasyDbus_conn object pointer.
watcher_add_cb user callback called for add a new watcher to user event loop
watcher_remove_cb user callback called for remove a previous added watcher.
closure user closure passed to watcher_add_cb and watcher_remove_cb callbacks
Returns:
0 init step done.

-1 error;

Definition at line 273 of file watch_events.c.

References EasyDbus_core::conn, easydbus_add_watch_callback(), easydbus_remove_watch_callback(), easydbus_toggle_watch_callback(), EasyDbus_conn::watcher_add_cb, EasyDbus_conn::watcher_closure, and EasyDbus_conn::watcher_remove_cb.

Referenced by easydbus_conn_reconnect().

00277 {
00278    struct EasyDbus_core *core = (struct EasyDbus_core *) conn;
00279    int ret_val;
00280 
00281    if (!conn || !watcher_add_cb || !watcher_remove_cb)
00282       return -1;
00283 
00284    conn->watcher_add_cb = watcher_add_cb;
00285    conn->watcher_remove_cb = watcher_remove_cb;
00286    conn->watcher_closure = closure;
00287 //#ifdef EASYDBUS_TESTING
00288 //   dbus_connection_set_dispatch_status_function
00289 //    (core->conn, easydbus_dispatch_status_callback,
00290 //     (void *) core, NULL);
00291 //#endif
00292    dbus_connection_set_watch_functions (core->conn,
00293                                         easydbus_add_watch_callback,
00294                                         easydbus_remove_watch_callback,
00295                                         easydbus_toggle_watch_callback,
00296                                         core, NULL);
00297 // dbus_connection_set_timeout_functions (core->conn,
00298 //    easydbus_add_timeout, 
00299 //    easydbus_remove_timeout, 
00300 //    easydbus_toggle_timeout, core,
00301 //    NULL);
00302 
00303    do {
00304       ret_val = dbus_connection_dispatch (core->conn);
00305    } while (ret_val == DBUS_DISPATCH_DATA_REMAINS);
00306 
00307 // dbus_connection_set_wakeup_main_function 
00308 // (core->conn,
00309 //    easydbus_wakeup_main_callback,
00310 // core, NULL);
00311 
00312    return 0;
00313 }

Here is the call graph for this function:

EasyDbus_conn* easydbus_watcher_get_conn ( EasyDbus_watcher watch  )  [inline]

Recover EasyDbus_conn object connected to Easydbus_watcher object.

Returns:
Easydbus_conn object connected to input EasyDbus_watcher.
Parameters:
watch EasyDbus_watcher object pointer

Definition at line 250 of file watcher.c.

References EasyDbus_watcher::core.

00251 {
00252    return (watch != NULL ? (EasyDbus_conn *) watch->core : NULL);
00253 }

int easydbus_watcher_get_fd ( EasyDbus_watcher watcher  ) 

Get file descriptor of EasyDbus_watcher object.

Parameters:
watcher pointer to EasyDbus_watcher object.
Returns:
-1 on error;

file descriptor of EasyDbus_watcher object.

Definition at line 52 of file watch_events.c.

References EasyDbus_watcher::watch.

00053 {
00054    if (watcher)
00055 #if defined(__DBUS_VERSION__) && (__DBUS_VERSION__ <= 102)
00056       return dbus_watch_get_fd (watcher->watch);
00057 #else
00058       return dbus_watch_get_unix_fd (watcher->watch);
00059 #endif
00060    return -1;
00061 }

int* easydbus_watcher_get_fd_list ( EasyDbus_conn data,
int *  num_fd 
)

Recover watcher fd list enabled.

Parameters:
data EasyDbus_conn object pointer.
num_fd pointer where is saved number of file descriptors.
Returns:
NULL on error or no watcher enabled.

pointer to an area of memory with file descriptors that must be free.

Definition at line 325 of file watch_events.c.

References EasyDbusDebug, EasyDbus_watcher::next, EasyDbus_watcher::watch, and EasyDbus_core::watcher.

00327 {
00328    int *list_fd = NULL, *fd = NULL;
00329    int i = 0;
00330    struct EasyDbus_watcher *watch = NULL;
00331    struct EasyDbus_core *core = (struct EasyDbus_core *) data;
00332 
00333    if (data == NULL || num_fd == NULL)
00334       return NULL;
00335 
00336    if (core->watcher == NULL)
00337       return NULL;
00338 
00339    // count watcher 
00340    watch = core->watcher;
00341    while (watch != NULL) {
00342       i++;
00343       watch = watch->next;
00344    }
00345 
00346    EasyDbusDebug ("Founded %d watcher", i);
00347 
00348    list_fd = (int *) malloc (sizeof (int) * i);
00349    if (list_fd == NULL)
00350       return NULL;
00351 
00352    memset (list_fd, 0, sizeof (int) * i);
00353 
00354    // save fd
00355    watch = core->watcher;
00356    fd = list_fd;
00357    while (watch != NULL) {
00358 #if defined(__DBUS_VERSION__) && (__DBUS_VERSION__ <= 102)
00359       *fd = dbus_watch_get_fd (watch->watch);
00360 #else
00361       *fd = dbus_watch_get_unix_fd(watch->watch);
00362 #endif
00363       fd++;
00364       watch = watch->next;
00365    }
00366    *num_fd = i;
00367    return list_fd;
00368 }

unsigned int easydbus_watcher_get_flags ( EasyDbus_watcher watch  ) 

Recover type of watcher.

Parameters:
watch EasyDbus_watcher object pointer.
Returns:
EASYDBUS_WATCHER_WRITABLE

EASYDBUS_WATCHER_READABLE

EASYDBUS_WATCHER_ERROR

EASYDBUS_WATCHER_HANGUP

EASYDBUS_WATCHER_INVALID on error

Definition at line 215 of file watcher.c.

References EASYDBUS_WATCHER_ERROR, EASYDBUS_WATCHER_HANGUP, EASYDBUS_WATCHER_INVALID, EASYDBUS_WATCHER_READABLE, EASYDBUS_WATCHER_WRITABLE, EasyDbusDebug, and EasyDbus_watcher::watch.

00216 {
00217    int flags = EASYDBUS_WATCHER_INVALID;
00218    int easydbus_flags = EASYDBUS_WATCHER_INVALID;
00219 
00220    if (!watch)
00221       return EASYDBUS_WATCHER_INVALID;
00222 
00223    flags = dbus_watch_get_flags (watch->watch);
00224    if (flags & DBUS_WATCH_READABLE) 
00225       easydbus_flags |= EASYDBUS_WATCHER_READABLE;
00226    if (flags & DBUS_WATCH_WRITABLE) 
00227       easydbus_flags |= EASYDBUS_WATCHER_WRITABLE;
00228    if (flags & DBUS_WATCH_HANGUP)
00229       easydbus_flags |= EASYDBUS_WATCHER_HANGUP;
00230    if (flags & DBUS_WATCH_ERROR)
00231       easydbus_flags |= EASYDBUS_WATCHER_ERROR;
00232 
00233    EasyDbusDebug ("EasyDbus_watcher (%p) flags are: %s%s%s%s",
00234                   watch,
00235                   flags & DBUS_WATCH_READABLE ? "readable " : "",
00236                   flags & DBUS_WATCH_WRITABLE ? "writable " : "",
00237                   flags & DBUS_WATCH_HANGUP ? "hangup " : "",
00238                   flags & DBUS_WATCH_ERROR ? "error" : "");
00239 
00240    return easydbus_flags;
00241 }


Generated on Thu Apr 10 10:02:06 2008 for EasyDbus-0.2 by  doxygen 1.5.4