init.c File Reference

This file implements all initialisation and shutdown of the library. More...

#include "stdio.h"
#include "internal.h"
#include "init.h"
#include <assert.h>
#include "eripc.h"
Include dependency graph for init.c:

Go to the source code of this file.

Defines

#define UNUSED(x)   (void)(x)

Functions

static DBusHandlerResult _filter_session (DBusConnection *conn, DBusMessage *msg, void *data)
static DBusHandlerResult _filter_system (DBusConnection *conn, DBusMessage *msg, void *data)
static DBusHandlerResult _filter (DBusConnection *conn, DBusMessage *msg, void *data, eripc_bus_t dbus_type)
static void compose_opm_hash_key (const char *object_path, const char *member, char *key)
gboolean __attribute__ ((visibility("hidden")))
eripc_context_teripc_init (const char *program_name, const char *program_version, GMainContext *context)
static gboolean _validate (const gchar *application, const gchar *version)
static void free_handler (gpointer data, gpointer user_data)
static void free_uniq_hash_value (gpointer data)
static void free_if_hash_value (gpointer data)
static osso_context_t_init (const char *application, const char *version)
static void _deinit (osso_context_t *osso)
static DBusConnection * _dbus_setup (osso_context_t *osso, DBusBusType bus_type, GMainContext *context)
int eripc_convert_msgtype (int t)
static int types_match (int a, int b)
static int str_match (const char *a, const char *b)
static void opm_match_helper (const char *object_path, const char *member, char *key)
static GSList * opm_match (osso_context_t *ipc, const char *path, const char *member)
static gboolean add_to_opm_hash (osso_context_t *osso, const _osso_handler_t *handler, const char *opm_key)
static void remove_from_opm_hash (_eripc_context_t *context, int handler_id, const char *opm_key)

Variables

static const char * opm_match_all_key

Detailed Description

This file implements all initialisation and shutdown of the library.

Definition in file init.c.


Define Documentation

#define UNUSED (  )     (void)(x)

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Based on code found in libosso library by Kimmo Hämäläinen <kimmo.hamalainen@nokia.com>

Definition at line 36 of file init.c.


Function Documentation

gboolean __attribute__ ( (visibility("hidden"))   ) 

Definition at line 866 of file init.c.

References _osso_callback_data_t::bus_type, compose_opm_hash_key(), _osso_handler_t::data, ERIPC_BUS_BOTH, ERIPC_BUS_SESSION, ERIPC_BUS_SYSTEM, ERIPC_MEMBER_MATCH_ALL, ERIPC_PATH_MATCH_ALL, _osso_hash_value_t::handlers, _osso_callback_data_t::interface, _osso_callback_data_t::match_rule, MAX_OPM_HASH_KEY_LEN, _osso_callback_data_t::name, _osso_callback_data_t::path, remove_from_opm_hash(), _osso_callback_data_t::service, ULOG_DEBUG_F, ULOG_ERR_F, and ULOG_WARN_F.

00868 {
00869     _osso_hash_value_t *elem;
00870     GSList *list;
00871 
00872     ULOG_DEBUG_F("context=%p", context);
00873     elem = g_hash_table_lookup(context->id_hash, GINT_TO_POINTER(handler_id));
00874     if (elem == NULL) {
00875         ULOG_ERR_F("couldn't find handler_id %d from id_hash", handler_id);
00876         return FALSE;
00877     }
00878 
00879     /* remove handlers from the interface hash */
00880     list = elem->handlers;
00881     while (list != NULL) {
00882         char opm_key[MAX_OPM_HASH_KEY_LEN + 1];
00883         DBusError err;
00884         _osso_handler_t *h = list->data;
00885 
00886         compose_opm_hash_key(h->data->path, h->data->name, opm_key);
00887         remove_from_opm_hash(context, handler_id, opm_key);
00888 
00889         dbus_error_init(&err);
00890 
00891         if (h->data->match_rule && (h->data->bus_type == ERIPC_BUS_SYSTEM
00892             || h->data->bus_type == ERIPC_BUS_BOTH)) {
00893             dbus_bus_remove_match(context->sys_conn, h->data->match_rule,
00894                                   &err);
00895             if (dbus_error_is_set(&err)) {
00896                 ULOG_WARN_F("dbus_bus_remove_match failed for %s: %s",
00897                             h->data->match_rule, err.message);
00898                 dbus_error_free(&err);
00899                 dbus_error_init(&err);
00900             }
00901         }
00902 
00903         if (h->data->match_rule && (h->data->bus_type == ERIPC_BUS_SESSION
00904             || h->data->bus_type == ERIPC_BUS_BOTH)) {
00905             dbus_bus_remove_match(context->conn, h->data->match_rule,
00906                                   &err);
00907             if (dbus_error_is_set(&err)) {
00908                 ULOG_WARN_F("dbus_bus_remove_match failed for %s: %s",
00909                             h->data->match_rule, err.message);
00910                 dbus_error_free(&err);
00911             }
00912         }
00913 
00914         free(h->data->service); h->data->service = NULL;
00915         if (h->data->path != NULL
00916             && strcmp(ERIPC_PATH_MATCH_ALL, h->data->path) != 0) {
00917             free(h->data->path); h->data->path = NULL;
00918         }
00919         free(h->data->interface); h->data->interface = NULL;
00920         if (h->data->name != NULL
00921             && strcmp(ERIPC_MEMBER_MATCH_ALL, h->data->name) != 0) {
00922             free(h->data->name); h->data->name = NULL;
00923         }
00924         free(h->data); h->data = NULL;
00925 
00926         list = g_slist_next(list);
00927     }
00928 
00929     if (!g_hash_table_remove(context->id_hash, GINT_TO_POINTER(handler_id))) {
00930         ULOG_ERR_F("couldn't find handler_id %d from id_hash", handler_id);
00931         assert(0); /* this is a bug */
00932     }
00933 
00934     return TRUE;
00935 }

Here is the call graph for this function:

static DBusConnection* _dbus_setup ( osso_context_t osso,
DBusBusType  bus_type,
GMainContext *  context 
) [static]

Definition at line 322 of file init.c.

References _filter_session(), _filter_system(), dprint, osso_af_context_t::service, and ULOG_ERR_F.

Referenced by eripc_init().

00325 {
00326     DBusConnection *conn;
00327     DBusError err;
00328     int ret;
00329     
00330     dbus_error_init(&err);
00331 
00332     /* TODO: add dbus_connection_unref calls when the fixed D-Bus
00333      * is available */
00334     conn = dbus_bus_get(bus_type, &err);
00335     if (conn == NULL) {
00336         ULOG_ERR_F("Unable to connect to the D-Bus %s bus: %s",
00337                    bus_type == DBUS_BUS_SESSION ? "session" : "system",
00338                    err.message);
00339         dbus_error_free(&err);
00340         return NULL;
00341     }
00342     dbus_connection_setup_with_g_main(conn, context);
00343 
00344     ret = dbus_bus_request_name(conn, osso->service,
00345                                 DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &err);
00346     if (ret == -1) {
00347         ULOG_ERR_F("dbus_bus_request_name failed: %s", err.message);
00348    dbus_error_free(&err);
00349    return NULL;
00350     }
00351 
00352     dbus_connection_set_exit_on_disconnect(conn, FALSE);
00353 
00354     if (bus_type == DBUS_BUS_SESSION) {
00355         if (!dbus_connection_add_filter(conn, _filter_session,
00356                                         osso, NULL)) {
00357             ULOG_ERR_F("dbus_connection_add_filter failed");
00358        return NULL;
00359         }
00360     } else {
00361         if (!dbus_connection_add_filter(conn, _filter_system,
00362                                         osso, NULL)) {
00363             ULOG_ERR_F("dbus_connection_add_filter failed");
00364        return NULL;
00365         }
00366     }
00367 
00368     dprint("My base service is '%s'", dbus_bus_get_unique_name(conn));
00369 
00370     return conn;
00371 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void _deinit ( osso_context_t osso  )  [static]

Definition at line 294 of file init.c.

References osso_af_context_t::cp_plugins, osso_af_context_t::id_hash, osso_af_context_t::if_hash, osso_af_context_t::opm_hash, and osso_af_context_t::uniq_hash.

Referenced by eripc_init().

00295 {
00296     if (osso == NULL) {
00297    return;
00298     }
00299     if (osso->uniq_hash != NULL) {
00300         g_hash_table_destroy(osso->uniq_hash);
00301     }
00302     if (osso->if_hash != NULL) {
00303         g_hash_table_destroy(osso->if_hash);
00304     }
00305     if (osso->opm_hash != NULL) {
00306         g_hash_table_destroy(osso->opm_hash);
00307     }
00308     if (osso->id_hash != NULL) {
00309         g_hash_table_destroy(osso->id_hash);
00310     }
00311     if (osso->cp_plugins != NULL) {
00312         g_hash_table_destroy(osso->cp_plugins);
00313     }
00314     
00315     memset(osso, 0, sizeof(osso_context_t));
00316     free(osso);
00317     osso = NULL;
00318 }

Here is the caller graph for this function:

static DBusHandlerResult _filter ( DBusConnection *  conn,
DBusMessage *  msg,
void *  data,
eripc_bus_t  dbus_type 
) [inline, static]

Definition at line 569 of file init.c.

References _osso_callback_data_t::bus_type, _osso_handler_t::call_once_per_handler_id, osso_af_context_t::cur_conn, _osso_handler_t::data, ERIPC_BUS_BOTH, eripc_convert_msgtype(), ERIPC_EVENT_NONE, ERIPC_EVENT_SIGNAL, _osso_callback_data_t::event_type, _osso_handler_t::handler, handler_id, _osso_handler_t::handler_id, _osso_hash_value_t::handlers, _osso_callback_data_t::interface, _osso_callback_data_t::message_id, opm_match(), _osso_callback_data_t::service, str_match(), types_match(), and ULOG_DEBUG_F.

Referenced by _filter_session(), and _filter_system().

00571 {
00572     osso_context_t *ipc;
00573     GSList *elem_list, *elem_list_p, *rm_list = NULL, *rm_list_p;
00574     int msgtype;
00575     unsigned int reply_to;
00576     gboolean found = FALSE;
00577     
00578     ipc = data;
00579 
00580     assert(ipc != NULL);
00581     ipc->cur_conn = conn;
00582 
00583     msgtype = eripc_convert_msgtype(dbus_message_get_type(msg));
00584     if (msgtype == ERIPC_EVENT_NONE) {
00585         ULOG_DEBUG_F("_filter: ERIPC_EVENT_NONE");
00586         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
00587     }
00588     reply_to = dbus_message_get_reply_serial(msg);
00589 
00590     elem_list = opm_match(ipc, dbus_message_get_path(msg),
00591                           dbus_message_get_member(msg));
00592 
00593     elem_list_p = elem_list;
00594     while (elem_list_p != NULL) {
00595         _osso_hash_value_t *elem;
00596 
00597         elem = elem_list_p->data;
00598 
00599         if (elem != NULL) {
00600             GSList *list;
00601             int last_id = 0;
00602 
00603             list = elem->handlers;
00604             while (list != NULL) {
00605                 _osso_handler_t *handler;
00606                 _osso_callback_data_t *cb_data;
00607                 gboolean match_sender = TRUE;
00608 
00609                 handler = list->data;
00610 
00611 /*
00612                 if (handler) {
00613                         ULOG_DEBUG_F("found handler");
00614                         if (handler->data != NULL) {
00615                                 ULOG_DEBUG_F("s/p/n t/i: %s/%s/%s %d/%s",
00616                                     handler->data->service,
00617                                     handler->data->path,
00618                                     handler->data->name,
00619                                     handler->data->event_type,
00620                                     handler->data->interface);
00621 
00622                                 ULOG_DEBUG_F("s/p/n t/i: %s/%s/%s %d/%s",
00623                                     dbus_message_get_sender(msg),
00624                                     dbus_message_get_path(msg),
00625                                     dbus_message_get_member(msg),
00626                                     msgtype,
00627                                     dbus_message_get_interface(msg));
00628 
00629                                 ULOG_DEBUG_F("types: %d %d",
00630                                     handler->data->event_type, msgtype);
00631                         }
00632                 }
00633 */
00634 
00635                 /* Note: this relies on the fact that the handlers with the
00636                  * same id are adjacent in the list */
00637                 if (handler->call_once_per_handler_id
00638                     && handler->handler_id == last_id) {
00639                         /* do not call the callback this time, workaround for
00640                          * ERIPC_EVENT_MESSAGE_OR_SIGNAL etc. implementation */
00641                         ULOG_DEBUG_F("handler already called, skip");
00642                         list = g_slist_next(list);
00643                         continue;
00644                 }
00645 
00646                 cb_data = handler->data;
00647                 
00648                 if (cb_data != NULL && cb_data->message_id != 0
00649                     && cb_data->message_id == reply_to) {
00650                         /* this (one-shot) handler was created for this
00651                          * (reply) message */
00652                         ULOG_DEBUG_F("calling one-shot handler at %p,"
00653                                      " data=%p", handler->handler, cb_data);
00654                         (*handler->handler)(ipc, msg, cb_data, dbus_type);
00655                         ULOG_DEBUG_F("after calling handler at %p",
00656                                      handler->handler);
00657                         found = TRUE;
00658                         /* The handler is one-shot (because the serial is
00659                          * supposed to be unique). Add it to list to remove
00660                          * it later safely outside this loop. */
00661                         rm_list = g_slist_prepend(rm_list,
00662                                       GINT_TO_POINTER(handler->handler_id));
00663 
00664                         list = g_slist_next(list);
00665                         continue;
00666                 }
00667 
00668                 if (cb_data != NULL && cb_data->bus_type != ERIPC_BUS_BOTH
00669                     && cb_data->bus_type != dbus_type) {
00670                         /* handler is not for this bus type */
00671                         ULOG_DEBUG_F("handler is not for this bus type, skip");
00672                         list = g_slist_next(list);
00673                         continue;
00674                 }
00675 
00676                 if (msgtype == ERIPC_EVENT_SIGNAL) {
00677                         /* does not make sense to match sender in case
00678                          * of a D-Bus signal, because D-Bus uses the
00679                          * (practically random) unique bus name as the
00680                          * sender */
00681                         match_sender = FALSE;
00682                 }
00683 
00684                 if (cb_data != NULL &&
00685                     types_match(cb_data->event_type, msgtype) &&
00686                     (!match_sender || str_match(cb_data->service,
00687                                           dbus_message_get_sender(msg))) &&
00688                     str_match(cb_data->interface,
00689                               dbus_message_get_interface(msg))) {
00690                     /* object path and member have matched already */
00691 
00692                     ULOG_DEBUG_F("before calling the handler at %p, data=%p",
00693                                  handler->handler, cb_data);
00694                     (*handler->handler)(ipc, msg, cb_data, dbus_type);
00695                     ULOG_DEBUG_F("after calling handler at %p",
00696                                  handler->handler);
00697                     found = TRUE;
00698                 }
00699 
00700                 last_id = handler->handler_id;
00701                 list = g_slist_next(list);
00702             }
00703         }
00704 
00705         elem_list_p = g_slist_next(elem_list_p);
00706     }
00707     
00708     if (elem_list != NULL) {
00709         g_slist_free(elem_list);
00710     }
00711 
00712     if (rm_list != NULL) {
00713         rm_list_p = rm_list;
00714         do {
00715             gboolean ret;
00716             int handler_id = GPOINTER_TO_INT(rm_list_p->data);
00717 
00718             assert(handler_id != 0);
00719             ret = _unset_handler(ipc, handler_id);
00720             assert(ret);
00721 
00722             rm_list_p = g_slist_next(rm_list_p);
00723         } while (rm_list_p != NULL);
00724         g_slist_free(rm_list);
00725     }
00726 
00727     if (!found) {
00728         ULOG_DEBUG_F("suitable handler not found for '%s/%s'",
00729                      dbus_message_get_path(msg),
00730                      dbus_message_get_member(msg));
00731     }
00732     else {
00733         return DBUS_HANDLER_RESULT_HANDLED;
00734     }
00735     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
00736 }

Here is the call graph for this function:

Here is the caller graph for this function:

static DBusHandlerResult _filter_session ( DBusConnection *  conn,
DBusMessage *  msg,
void *  data 
) [static]

Definition at line 510 of file init.c.

References _filter(), and ERIPC_BUS_SESSION.

Referenced by _dbus_setup().

00511 {
00512     return _filter(conn, msg, data, ERIPC_BUS_SESSION);
00513 }

Here is the call graph for this function:

Here is the caller graph for this function:

static DBusHandlerResult _filter_system ( DBusConnection *  conn,
DBusMessage *  msg,
void *  data 
) [static]

Definition at line 516 of file init.c.

References _filter(), and ERIPC_BUS_SYSTEM.

Referenced by _dbus_setup().

00517 {
00518     return _filter(conn, msg, data, ERIPC_BUS_SYSTEM);
00519 }

Here is the call graph for this function:

Here is the caller graph for this function:

static osso_context_t* _init ( const char *  application,
const char *  version 
) [static]

Definition at line 255 of file init.c.

References _validate(), osso_af_context_t::application, osso_af_context_t::cp_plugins, free_if_hash_value(), free_uniq_hash_value(), osso_af_context_t::id_hash, osso_af_context_t::interface, MAX_APP_NAME_LEN, MAX_VERSION_LEN, osso_af_context_t::next_handler_id, osso_af_context_t::object_path, osso_af_context_t::opm_hash, osso_af_context_t::service, osso_af_context_t::timeout_ms, ULOG_ERR_F, and osso_af_context_t::version.

Referenced by eripc_init().

00257 {
00258     osso_context_t *osso;
00259     
00260     if (!_validate(application, version)) {
00261    ULOG_ERR_F("invalid arguments");
00262    return NULL;
00263     }
00264 
00265     osso = calloc(1, sizeof(osso_context_t));
00266     if (osso == NULL) {
00267    ULOG_ERR_F("calloc failed");
00268    return NULL;
00269     } 
00270 
00271     g_snprintf(osso->application, MAX_APP_NAME_LEN, "%s", application);
00272     g_snprintf(osso->version, MAX_VERSION_LEN, "%s", version);
00273     make_default_interface((const char*)application, osso->interface);
00274     make_default_service((const char*)application, osso->service);
00275     make_default_object_path((const char*)application, osso->object_path);
00276 
00277     osso->opm_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
00278                                           free, free_if_hash_value);
00279     osso->id_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
00280                                           NULL, free_uniq_hash_value);
00281     if (osso->id_hash == NULL || osso->opm_hash == NULL) {
00282         ULOG_ERR_F("g_hash_table_new_full failed");
00283         free(osso);
00284         return NULL;
00285     }
00286     osso->cp_plugins = g_hash_table_new(g_str_hash, g_str_equal);
00287     osso->timeout_ms = 500; /* ms */
00288     osso->next_handler_id = 1;
00289     return osso;
00290 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean _validate ( const gchar *  application,
const gchar *  version 
) [static]

Definition at line 130 of file init.c.

References ULOG_ERR_F, and validate_appname().

Referenced by _init().

00131 {
00132     if (application == NULL || version == NULL) {
00133    return FALSE;
00134     }
00135     if (!validate_appname(application)) {
00136    return FALSE;
00137     }
00138     if (strchr(version, '/') != NULL) {
00139         ULOG_ERR_F("invalid version string '%s'", version);
00140    return FALSE;
00141     }
00142     return TRUE;
00143 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean add_to_opm_hash ( osso_context_t osso,
const _osso_handler_t handler,
const char *  opm_key 
) [static]

Definition at line 740 of file init.c.

References _osso_hash_value_t::handlers, osso_af_context_t::opm_hash, and ULOG_ERR_F.

00743 {
00744     _osso_hash_value_t *old;
00745 
00746     old = g_hash_table_lookup(osso->opm_hash, opm_key);
00747     if (old != NULL) {
00748         old->handlers = g_slist_append(old->handlers,
00749                                        (_osso_handler_t*)handler);
00750     } else {
00751         _osso_hash_value_t *new_elem;
00752         char *new_key;
00753 
00754         /* we need to allocate a new hash table element */
00755         new_elem = calloc(1, sizeof(_osso_hash_value_t));
00756         if (new_elem == NULL) {
00757             ULOG_ERR_F("calloc() failed");
00758             return FALSE;
00759         }
00760 
00761         new_key = strdup(opm_key);
00762         if (new_key == NULL) {
00763             ULOG_ERR_F("calloc() failed");
00764             free(new_elem);
00765             return FALSE;
00766         }
00767 
00768         new_elem->handlers = g_slist_append(NULL, (_osso_handler_t*)handler);
00769 
00770         g_hash_table_insert(osso->opm_hash, new_key, new_elem);
00771     }
00772     return TRUE;
00773 }

static void compose_opm_hash_key ( const char *  object_path,
const char *  member,
char *  key 
) [inline, static]

Definition at line 52 of file init.c.

References ERIPC_MEMBER_MATCH_ALL, ERIPC_PATH_MATCH_ALL, MAX_MEMBER_LEN, MAX_OP_LEN, and opm_match_all_key.

Referenced by __attribute__().

00054 {
00055     key[0] = '\0';
00056     if (object_path == NULL && member == NULL) {
00057         strncat(key, opm_match_all_key, MAX_OP_LEN + MAX_MEMBER_LEN);
00058     } else if (object_path == NULL) {
00059         strncat(key, ERIPC_PATH_MATCH_ALL, MAX_OP_LEN);
00060         strncat(key, member, MAX_MEMBER_LEN);
00061     } else if (member == NULL) {
00062         strncat(key, object_path, MAX_OP_LEN);
00063         strncat(key, ERIPC_MEMBER_MATCH_ALL, MAX_MEMBER_LEN);
00064     } else {
00065         strncat(key, object_path, MAX_OP_LEN);
00066         strncat(key, member, MAX_MEMBER_LEN);
00067     }
00068 }

Here is the caller graph for this function:

int eripc_convert_msgtype ( int  t  ) 

Definition at line 460 of file init.c.

References ERIPC_EVENT_ERROR, ERIPC_EVENT_MESSAGE, ERIPC_EVENT_NONE, ERIPC_EVENT_REPLY, ERIPC_EVENT_SIGNAL, and ULOG_ERR_F.

Referenced by _filter(), and eripc_reply_handler().

00461 {
00462     switch (t) {
00463             case DBUS_MESSAGE_TYPE_METHOD_CALL:
00464                     return ERIPC_EVENT_MESSAGE;
00465             case DBUS_MESSAGE_TYPE_SIGNAL:
00466                     return ERIPC_EVENT_SIGNAL;
00467             case DBUS_MESSAGE_TYPE_ERROR:
00468                     return ERIPC_EVENT_ERROR;
00469             case DBUS_MESSAGE_TYPE_METHOD_RETURN:
00470                     return ERIPC_EVENT_REPLY;
00471             default:
00472                     ULOG_ERR_F("unknown message type %d", t);
00473                     return ERIPC_EVENT_NONE;
00474     }
00475 }

Here is the caller graph for this function:

static void free_handler ( gpointer  data,
gpointer  user_data 
) [static]

Definition at line 214 of file init.c.

References _osso_handler_t::can_free_data, _osso_handler_t::data, and UNUSED.

Referenced by free_uniq_hash_value().

00215 {
00216     UNUSED(user_data);
00217     _osso_handler_t *h = data;
00218 
00219     if (h != NULL) {
00220         if (h->can_free_data) {
00221             free(h->data);
00222             h->data = NULL;
00223         }
00224         free(h);
00225     }
00226 }

Here is the caller graph for this function:

static void free_if_hash_value ( gpointer  data  )  [static]

Definition at line 242 of file init.c.

References _osso_hash_value_t::handlers.

Referenced by _init().

00243 {
00244     _osso_hash_value_t *elem = data;
00245 
00246     if (elem != NULL) {
00247         if (elem->handlers != NULL) {
00248             g_slist_free(elem->handlers);
00249             elem->handlers = NULL;
00250         }
00251         free(elem);
00252     }
00253 }

Here is the caller graph for this function:

static void free_uniq_hash_value ( gpointer  data  )  [static]

Definition at line 228 of file init.c.

References free_handler(), and _osso_hash_value_t::handlers.

Referenced by _init().

00229 {
00230     _osso_hash_value_t *elem = data;
00231 
00232     if (elem != NULL) {
00233         if (elem->handlers != NULL) {
00234             g_slist_foreach(elem->handlers, free_handler, NULL);
00235             g_slist_free(elem->handlers);
00236             elem->handlers = NULL;
00237         }
00238         free(elem);
00239     }
00240 }

Here is the call graph for this function:

Here is the caller graph for this function:

static GSList* opm_match ( osso_context_t ipc,
const char *  path,
const char *  member 
) [inline, static]

Definition at line 531 of file init.c.

References ERIPC_MEMBER_MATCH_ALL, ERIPC_PATH_MATCH_ALL, MAX_OPM_HASH_KEY_LEN, osso_af_context_t::opm_hash, opm_match_all_key, and opm_match_helper().

Referenced by _filter().

00534 {
00535     GSList *list = NULL;
00536     _osso_hash_value_t *elem;
00537     char opm_key[MAX_OPM_HASH_KEY_LEN + 1];
00538 
00539     if (path != NULL && member != NULL) {
00540         /* direct match? */
00541         opm_match_helper(path, member, opm_key);
00542         elem = g_hash_table_lookup(ipc->opm_hash, opm_key);
00543         if (elem != NULL) list = g_slist_prepend(list, elem);
00544     }
00545 
00546     /* return list of match-'em-all handlers */
00547     elem = g_hash_table_lookup(ipc->opm_hash, opm_match_all_key);
00548     if (elem != NULL) list = g_slist_prepend(list, elem);
00549 
00550     if (member != NULL) {
00551         /* any path + member? */
00552         opm_match_helper(ERIPC_PATH_MATCH_ALL, member, opm_key);
00553         elem = g_hash_table_lookup(ipc->opm_hash, opm_key);
00554         if (elem != NULL) list = g_slist_prepend(list, elem);
00555     }
00556 
00557     if (path != NULL) {
00558         /* path + any member? */
00559         opm_match_helper(path, ERIPC_MEMBER_MATCH_ALL, opm_key);
00560         elem = g_hash_table_lookup(ipc->opm_hash, opm_key);
00561         if (elem != NULL) list = g_slist_prepend(list, elem);
00562     }
00563 
00564     return list;
00565 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void opm_match_helper ( const char *  object_path,
const char *  member,
char *  key 
) [inline, static]

Definition at line 521 of file init.c.

References MAX_MEMBER_LEN, and MAX_OP_LEN.

Referenced by opm_match().

00524 {
00525     key[0] = '\0';
00526     strncat(key, object_path, MAX_OP_LEN);
00527     strncat(key, member, MAX_MEMBER_LEN);
00528 }

Here is the caller graph for this function:

static void remove_from_opm_hash ( _eripc_context_t context,
int  handler_id,
const char *  opm_key 
) [static]

Definition at line 832 of file init.c.

References _osso_handler_t::handler_id, _osso_hash_value_t::handlers, _eripc_context_t::opm_hash, and ULOG_DEBUG_F.

Referenced by __attribute__().

00835 {
00836     _osso_hash_value_t *elem;
00837 
00838     elem = g_hash_table_lookup(context->opm_hash, opm_key);
00839     if (elem != NULL) {
00840         GSList *list;
00841 
00842         list = elem->handlers;
00843         while (list != NULL) {
00844             _osso_handler_t *h = list->data;
00845             GSList *next_elem;
00846 
00847             next_elem = g_slist_next(list);
00848 
00849             if (h->handler_id == handler_id) {
00850                 ULOG_DEBUG_F("found handler_id %d from if_hash", handler_id);
00851                 elem->handlers = g_slist_remove_link(elem->handlers, list);
00852                 g_slist_free_1(list); /* free the removed link */
00853 
00854                 /* if this was the last element in the list, free the
00855                  * list and the hash element */
00856                 if (g_slist_length(elem->handlers) == 0) {
00857                     g_hash_table_remove(context->opm_hash, opm_key);
00858                     return;
00859                 }
00860             }
00861             list = next_elem;
00862         }
00863     }
00864 }

Here is the caller graph for this function:

static int str_match ( const char *  a,
const char *  b 
) [inline, static]

Definition at line 500 of file init.c.

Referenced by _filter().

00501 {
00502     if (a == NULL || b == NULL) return 1;
00503 
00504     if (strcmp(a, b) == 0) return 1;
00505 
00506     return 0;
00507 }

Here is the caller graph for this function:

static int types_match ( int  a,
int  b 
) [inline, static]

Definition at line 477 of file init.c.

References ERIPC_EVENT_ERROR, ERIPC_EVENT_MESSAGE, ERIPC_EVENT_MESSAGE_OR_SIGNAL, ERIPC_EVENT_REPLY, ERIPC_EVENT_REPLY_OR_ERROR, and ERIPC_EVENT_SIGNAL.

Referenced by _filter().

00478 {
00479     if (a == b) return 1;
00480 
00481     if (a == ERIPC_EVENT_MESSAGE_OR_SIGNAL &&
00482         (b == ERIPC_EVENT_MESSAGE || b == ERIPC_EVENT_SIGNAL))
00483             return 1;
00484 
00485     if (a == ERIPC_EVENT_REPLY_OR_ERROR &&
00486         (b == ERIPC_EVENT_REPLY || b == ERIPC_EVENT_ERROR))
00487             return 1;
00488 
00489     if (b == ERIPC_EVENT_MESSAGE_OR_SIGNAL &&
00490         (a == ERIPC_EVENT_MESSAGE || a == ERIPC_EVENT_SIGNAL))
00491             return 1;
00492 
00493     if (b == ERIPC_EVENT_REPLY_OR_ERROR &&
00494         (a == ERIPC_EVENT_REPLY || a == ERIPC_EVENT_ERROR))
00495             return 1;
00496 
00497     return 0;
00498 }

Here is the caller graph for this function:


Variable Documentation

const char* opm_match_all_key [static]
Initial value:

Definition at line 48 of file init.c.

Referenced by compose_opm_hash_key(), and opm_match().

Generated by  doxygen 1.6.2-20100208