watcher_internal
[monitor_internal]

Collaboration diagram for watcher_internal:

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):


Functions

dbus_bool_t easydbus_add_watch_callback (DBusWatch *watch, void *data)
 Hander for manage new watcher.
void easydbus_remove_watch_callback (DBusWatch *watch, void *data)
 Handler of remove watch callback.
int easydbus_watcher_add (struct EasyDbus_core *core, struct EasyDbus_watcher *watcher)
 Add EasyDbus_watcher object on watchers list and call user callback.
EasyDbus_watchereasydbus_watcher_create_skeleton (void)
 Create EasyDbus_watcher skeleton object.
struct EasyDbus_watchereasydbus_watcher_get_from_fd (struct EasyDbus_watcher *list, int fd, enum easydbus_watcher_flags flags)
 Find EasyDbus_watcher object from file descriptor.
EasyDbus_watchereasydbus_watcher_get_from_watch (EasyDbus_watcher *list, DBusWatch *watch)
 Recover EasyDbus_watcher from DBusWatch object.
int easydbus_watcher_remove_dbus_watch (struct EasyDbus_core *core, DBusWatch *watch)
 Found EasyDbus_watcher object connect to DBusWatch and remove it from list.


Function Documentation

dbus_bool_t easydbus_add_watch_callback ( DBusWatch *  watch,
void *  data 
)

Hander for manage new watcher.

Parameters:
watch pointer to new DBusWatch object to add.
data pointer to EasyDbus_core object.
Returns:
TRUE

FALSE

For internal use only.

Definition at line 114 of file watch_events_internal.c.

References easydbus_watcher_add(), easydbus_watcher_create_skeleton(), easydbus_watcher_get_from_watch(), EasyDbusDebug, EasyDbus_core::user_data, EasyDbus_watcher::watch, EasyDbus_core::watcher, EasyDbus_conn::watcher_add_cb, and EasyDbus_conn::watcher_closure.

Referenced by easydbus_watcher_enable().

00116 {
00117    struct EasyDbus_core *core = (struct EasyDbus_core *) data;
00118    struct EasyDbus_watcher *watcher = NULL;
00119    int flags = 0, fd = 0;
00120 
00121    flags = dbus_watch_get_flags (watch);
00122 #if defined(__DBUS_VERSION__) && (__DBUS_VERSION__ <= 102)
00123    fd = dbus_watch_get_fd (watch);
00124 #else
00125    fd = dbus_watch_get_unix_fd (watch);
00126 #endif
00127 
00128    watcher = easydbus_watcher_get_from_watch (core->watcher,
00129                                               watch);
00130    if (watcher) {
00131       // if watcher is already on list
00132       EasyDbusDebug ("Enable already create watcher (%p %s) "
00133                      "with fd %d",
00134                      watch, 
00135                      (flags & DBUS_WATCH_READABLE ? "readable" :
00136                       ((flags & DBUS_WATCH_WRITABLE) ? "writable" : 
00137                         "error" )), fd);
00138       
00139       core->user_data.watcher_add_cb (watcher, 
00140                                       core->user_data.watcher_closure);
00141    } else {
00142       dbus_watch_set_data (watch, data, NULL);
00143       watcher = easydbus_watcher_create_skeleton ();
00144       // see how manage this exception
00145       if (watcher == NULL)
00146          return FALSE;
00147 
00148       watcher->watch = watch;
00149       easydbus_watcher_add (core, watcher);
00150 
00151       EasyDbusDebug ("Add %s watcher (%p %s) with fd %d", 
00152                      (flags & DBUS_WATCH_READABLE ? "readable" :
00153                       ((flags & DBUS_WATCH_WRITABLE) ? "writable" : 
00154                         "error" )), watch, 
00155                      dbus_watch_get_enabled (watch) ? "enable" : "not enable",
00156                      fd);
00157    }
00158    return TRUE;
00159 }

Here is the call graph for this function:

void easydbus_remove_watch_callback ( DBusWatch *  watch,
void *  data 
)

Handler of remove watch callback.

Parameters:
watch DBusWatch object pointer that will be removed.
data Closure data.

For internal use only.

Definition at line 168 of file watch_events_internal.c.

References easydbus_watcher_remove_dbus_watch(), and EasyDbusDebug.

Referenced by easydbus_toggle_watch_callback(), and easydbus_watcher_enable().

00170 {
00171    struct EasyDbus_core *core = (struct EasyDbus_core *) data;
00172    int flags = 0;
00173    
00174    flags = dbus_watch_get_flags (watch);
00175 
00176    if (easydbus_watcher_remove_dbus_watch (core, watch))
00177      EasyDbusDebug ("Error on remove watcher (%s) with fd "
00178                     "%d or already removed.",
00179                     (flags & DBUS_WATCH_READABLE ? "readable" :
00180                      ((flags & DBUS_WATCH_WRITABLE) ? "writable" : 
00181                        "error" )), 
00182 #if defined(__DBUS_VERSION__) && (__DBUS_VERSION__ <= 102)
00183                     dbus_watch_get_fd (watch));
00184 #else
00185                     dbus_watch_get_unix_fd (watch));
00186 #endif
00187    else
00188     EasyDbusDebug ("Remove Watcher (%s) with fd = %d",
00189                    (flags & DBUS_WATCH_READABLE ? "readable" :
00190                     ((flags & DBUS_WATCH_WRITABLE) ? "writable" : 
00191                       "error" )),
00192 #if defined(__DBUS_VERSION__) && (__DBUS_VERSION__ <= 102)
00193                    dbus_watch_get_fd (watch));
00194 #else
00195                   dbus_watch_get_unix_fd(watch));
00196 #endif
00197 }

Here is the call graph for this function:

int easydbus_watcher_add ( struct EasyDbus_core core,
struct EasyDbus_watcher watcher 
)

Add EasyDbus_watcher object on watchers list and call user callback.

Parameters:
core EasyDbus_core object pointer
watcher EasyDbus_watcher object pointer to add.
Returns:
-1 on error

0 ok

For internal use only.

Definition at line 78 of file watcher.c.

References EasyDbus_watcher::core, EasyDbus_watcher::next, EasyDbus_core::user_data, EasyDbus_watcher::watch, EasyDbus_core::watcher, EasyDbus_conn::watcher_add_cb, and EasyDbus_conn::watcher_closure.

Referenced by easydbus_add_watch_callback().

00080 {
00081    struct EasyDbus_watcher *watch = NULL;
00082 
00083    if (!core || !watcher)
00084       return -1;
00085 
00086    if (!core->watcher) {
00087       // no watcher
00088       core->watcher = watcher;
00089    }
00090    else {
00091       watch = core->watcher;
00092       while (watch->next)
00093          watch = watch->next;
00094       watch->next = watcher;
00095    }
00096    watcher->core = core;
00097    if (dbus_watch_get_enabled (watcher->watch))
00098       core->user_data.watcher_add_cb (watcher, 
00099                                       core->user_data.watcher_closure);
00100    return 0;
00101 }

EasyDbus_watcher* easydbus_watcher_create_skeleton ( void   )  [read]

Create EasyDbus_watcher skeleton object.

Returns:
NULL on error

pointer to a new EasyDbus_watcher skeleton.

For internal use only.

Definition at line 50 of file watcher.c.

References EasyDbus_watcher::next, and EasyDbus_watcher::watch.

Referenced by easydbus_add_watch_callback().

00051 {
00052    struct EasyDbus_watcher *watcher = NULL;
00053 
00054    watcher = (struct EasyDbus_watcher *)
00055       malloc (sizeof (struct EasyDbus_watcher));
00056 
00057    if (!watcher)
00058       return NULL;
00059 
00060    memset (watcher, 0, sizeof (struct EasyDbus_watcher));
00061 
00062    watcher->watch = NULL;
00063    watcher->next = NULL;
00064 
00065    return watcher;
00066 }

struct EasyDbus_watcher* easydbus_watcher_get_from_fd ( struct EasyDbus_watcher list,
int  fd,
enum easydbus_watcher_flags  flags 
) [read]

Find EasyDbus_watcher object from file descriptor.

Parameters:
list pointer to EasyDbus_watcher list.
fd file descriptor used for research.
flags EASYDBUS_WATCHER_READABLE | EASYDBUS_WATCHER_WRITABLE
Returns:
NULL on error or if there is a watcher for fd descriptor.

pointer to struct EasyDbus_watcher on list that watchs a file descriptor equal to fd.

For internal use only.

Definition at line 156 of file watcher.c.

References EASYDBUS_WATCHER_READABLE, EasyDbus_watcher::next, and EasyDbus_watcher::watch.

Referenced by easydbus_object_handle_message().

00159 {
00160    if (!list || fd < 0)
00161       return NULL;
00162 
00163    while (list) {
00164       if (list->watch) {
00165          if (dbus_watch_get_enabled (list->watch))
00166 #if defined(__DBUS_VERSION__) && (__DBUS_VERSION__ <= 102)
00167             if (dbus_watch_get_fd (list->watch) == fd) {
00168 #else
00169             if (dbus_watch_get_unix_fd (list->watch) == fd) {
00170 #endif
00171                if (dbus_watch_get_flags (list->watch) & 
00172                    (flags & EASYDBUS_WATCHER_READABLE ? DBUS_WATCH_READABLE : 
00173                      DBUS_WATCH_WRITABLE))
00174                return list;
00175             }
00176       }
00177       list = list->next;
00178    }
00179 
00180    return NULL;
00181 }

EasyDbus_watcher* easydbus_watcher_get_from_watch ( EasyDbus_watcher list,
DBusWatch *  watch 
) [read]

Recover EasyDbus_watcher from DBusWatch object.

Parameters:
list watchers list pointer
watch pointer to DBusWatch object to found
Returns:
NULL if object is not founded

pointer to EasyDbus_watcher object.

For internal use only.

Definition at line 192 of file watcher.c.

References EasyDbus_watcher::next, and EasyDbus_watcher::watch.

Referenced by easydbus_add_watch_callback().

00194 {
00195    if (list && watch)
00196       while (list) {
00197          if (list->watch == watch)
00198             return list;
00199          list = list->next;
00200       }
00201 
00202    return NULL;
00203 }

int easydbus_watcher_remove_dbus_watch ( struct EasyDbus_core core,
DBusWatch *  watch 
)

Found EasyDbus_watcher object connect to DBusWatch and remove it from list.

Parameters:
core EasyDbus_core object pointer
watch DBusWatch object pointer to remove
Returns:
-1 on error

0 ok

For internal use only.

TODO see problem with valgrind with this instruction.

Definition at line 113 of file watcher.c.

References EasyDbus_watcher::next, EasyDbus_core::user_data, EasyDbus_watcher::watch, EasyDbus_core::watcher, EasyDbus_conn::watcher_closure, and EasyDbus_conn::watcher_remove_cb.

Referenced by easydbus_remove_watch_callback().

00115 {
00116    struct EasyDbus_watcher *current, *prev;
00117 
00118    if (!watch || !core)
00119       return -1;
00120 
00122    prev = current = core->watcher;
00123 
00124    while (current) {
00125       if (watch == current->watch) {
00126          if (core->user_data.watcher_remove_cb &&
00127              dbus_watch_get_enabled (watch))
00128             core->user_data.watcher_remove_cb (current, 
00129                                                core->user_data.watcher_closure);
00130          if (prev == current)
00131             core->watcher = current->next;
00132          else
00133             prev->next = current->next;
00134          free (current);
00135          return 0;
00136       }
00137       prev = current;
00138       current = current->next;
00139    }
00140 
00141    return -1;
00142 }


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