internal.h

Go to the documentation of this file.
00001 #ifndef INTERNAL_H_
00002 #define INTERNAL_H_
00003 
00004 /**
00005  * @addtogroup eripc
00006  * @{
00007  * @file internal.h
00008  * @brief This file contains internal definitions.
00009  */
00010  
00011 /*
00012  * This file is part of liberipc.
00013  *
00014  * liberipc is free software: you can redistribute it and/or modify
00015  * it under the terms of the GNU General Public License as published by
00016  * the Free Software Foundation, either version 2 of the License, or
00017  * (at your option) any later version.
00018  *
00019  * liberipc is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License
00025  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00026  */
00027 
00028 /**
00029  * Copyright (C) 2008 iRex Technologies B.V. 
00030  * All rights reserved.
00031  *
00032  * Based on code found in libosso library by Kimmo Hämäläinen <kimmo.hamalainen@nokia.com>
00033  */
00034 
00035 #define DBUS_API_SUBJECT_TO_CHANGE
00036 
00037 #ifdef HAVE_CONFIG_H
00038 # include <config.h>
00039 #endif
00040 
00041 #include <stdio.h>
00042 #include <stdarg.h>
00043 #include <string.h>
00044 #include <malloc.h>
00045 
00046 #include <dbus/dbus.h>
00047 #include <dbus/dbus-glib-lowlevel.h>
00048 
00049 #include "log.h"
00050 #include "eripc.h"
00051 
00052 #define OSSO_BUS_ROOT          "com.irexnet"
00053 #define OSSO_BUS_ROOT_PATH     "/com/irexnet"
00054 
00055 #define ERIPC_PATH_MATCH_ALL "eripc_path_match_all"
00056 #define ERIPC_MEMBER_MATCH_ALL "eripc_member_match_all"
00057 
00058 /* DBus interface, service, and object path maximum lengths */
00059 #define MAX_IF_LEN 255
00060 #define MAX_SVC_LEN 255
00061 #define MAX_OP_LEN 255
00062 #define MAX_MEMBER_LEN 255
00063 #define MAX_ERROR_LEN 255
00064 #define MAX_HASH_KEY_LEN (MAX_IF_LEN + MAX_SVC_LEN + MAX_OP_LEN)
00065 #define MAX_OPM_HASH_KEY_LEN (MAX_OP_LEN + MAX_MEMBER_LEN)
00066 #define MAX_MSGID_LEN (MAX_SVC_LEN + 20 + 20 + 2)
00067 
00068 #define MAX_APP_NAME_LEN 50
00069 #define MAX_VERSION_LEN 30
00070 
00071 #define ERIPC_MAX_ARGS 256
00072 #define ERIPC_MAX_MATCH_SIZE 256
00073 
00074 /* data given by the library user */
00075 typedef struct {
00076     gpointer user_cb;
00077 
00078     gpointer user_data;
00079     const char *match_rule;
00080     gpointer data;
00081     eripc_event_t event_type;
00082     eripc_bus_t bus_type;
00083     unsigned int message_id;
00084 
00085     char *service;    /* service name or NULL */
00086     char *path;       /* object path or NULL */
00087     char *interface;  /* interface name or NULL */
00088     char *name;       /* name of message/signal or NULL */
00089 
00090 } _osso_callback_data_t;
00091 
00092 typedef void (_osso_handler_f)(osso_context_t *osso,
00093                                DBusMessage *msg,
00094                                _osso_callback_data_t *data,
00095                                eripc_bus_t bus_type);
00096 
00097 typedef struct {
00098     _osso_handler_f *handler;
00099     _osso_callback_data_t *data;
00100     gboolean method;
00101     gboolean can_free_data;
00102     gboolean call_once_per_handler_id;
00103     int handler_id;
00104 } _osso_handler_t;
00105 
00106 typedef struct {
00107     GSList *handlers;
00108 } _osso_hash_value_t;
00109 
00110 /**
00111  * This structure is used to store library specific stuff
00112  */
00113 
00114 typedef struct osso_af_context_t {
00115     DBusConnection *conn;
00116     DBusConnection *sys_conn;
00117     DBusConnection *cur_conn;
00118     gchar application[MAX_APP_NAME_LEN + 1];
00119     gchar version[MAX_VERSION_LEN + 1];
00120     char object_path[MAX_OP_LEN + 1];
00121     char interface[MAX_IF_LEN + 1];
00122     char service[MAX_SVC_LEN + 1];
00123     gboolean systembus_service_registered;
00124     gboolean sessionbus_service_registered;
00125     GHashTable *uniq_hash;  /* handlers hashed by the triplet: service,
00126                                object path, and interface. */
00127     GHashTable *if_hash;    /* handlers hashed by interface only */
00128     GHashTable *id_hash;    /* handlers hashed by id */
00129     GHashTable *opm_hash;   /* handlers hashed by object path + member */
00130 #ifdef LIBOSSO_DEBUG
00131     guint log_handler;
00132 #endif
00133     guint timeout_ms;
00134     GHashTable *cp_plugins;
00135     int next_handler_id;    /* next available handler id, unique in this
00136                                context */
00137     const DBusMessage *reply_dummy, *error_dummy;
00138     gboolean eripc_filters_setup;
00139 } _eripc_context_t;
00140 
00141 
00142 typedef struct _eripc_context_t {
00143     DBusConnection *conn;
00144     DBusConnection *sys_conn;
00145     DBusConnection *cur_conn;
00146     gchar application[MAX_APP_NAME_LEN + 1];
00147     gchar version[MAX_VERSION_LEN + 1];
00148     char object_path[MAX_OP_LEN + 1];
00149     char interface[MAX_IF_LEN + 1];
00150     char service[MAX_SVC_LEN + 1];
00151     gboolean systembus_service_registered;
00152     gboolean sessionbus_service_registered;
00153     GHashTable *uniq_hash;  /* handlers hashed by the triplet: service,
00154                                object path, and interface. */
00155     GHashTable *if_hash;    /* handlers hashed by interface only */
00156     GHashTable *id_hash;    /* handlers hashed by id */
00157     GHashTable *opm_hash;   /* handlers hashed by object path + member */
00158 #ifdef LIBOSSO_DEBUG
00159     guint log_handler;
00160 #endif
00161     guint timeout_ms;
00162     GHashTable *cp_plugins;
00163     int next_handler_id;    /* next available handler id, unique in this
00164                                context */
00165     const DBusMessage *reply_dummy, *error_dummy;
00166     gboolean eripc_filters_setup;
00167 } _eripc_this_type_is_not_used_t;
00168 
00169 
00170 #ifdef LIBOSSO_DEBUG
00171 #  define dprint(f, a...) (fprintf(stderr, "%s:%d %s(): "f"\n", __FILE__, \
00172                  __LINE__, __func__, ##a),fflush(stderr))
00173 # else
00174 #  define dprint(f, a...)
00175 # endif 
00176 
00177 
00178 extern int __attribute__ ((visibility("hidden")))
00179 eripc_convert_msgtype(int t);
00180 
00181 eripc_arg_t* _get_args(DBusMessageIter *iter);
00182 
00183 
00184 DBusHandlerResult __attribute__ ((visibility("hidden")))
00185 _msg_handler(DBusConnection *conn, DBusMessage *msg, void *data);
00186 
00187 void __attribute__ ((visibility("hidden")))
00188 make_default_interface(const char *application, char *interface);
00189 
00190 void __attribute__ ((visibility("hidden")))
00191 make_default_service(const char *application, char *service);
00192 
00193 void __attribute__ ((visibility("hidden")))
00194 make_default_object_path(const char *application, char *path);
00195 
00196 void __attribute__ ((visibility("hidden")))
00197 make_default_error_name(const char *service, const char *name,
00198                         char *ready_name);
00199 
00200 gboolean __attribute__ ((visibility("hidden")))
00201 _eripc_set_handler(_eripc_context_t *context,
00202                    _osso_handler_f *handler,
00203                    _osso_callback_data_t *data,
00204                    int handler_id,
00205                    gboolean call_once_per_handler_id);
00206 
00207 gboolean __attribute__ ((visibility("hidden")))
00208 _unset_handler(_eripc_context_t *context, int handler_id);
00209 
00210 gboolean validate_appname(const gchar *application);
00211 
00212 extern void __attribute__ ((visibility("hidden")))
00213 _parse_id(const char *id, eripc_bus_t *bus, char *sender,
00214                 int *serial);
00215 
00216 extern void __attribute__ ((visibility("hidden")))
00217 _make_id(eripc_bus_t bus, const char *sender, int serial, char *id);
00218 
00219 /** @} */
00220 
00221 #endif /* INTERNAL_H_ */
Generated by  doxygen 1.6.2-20100208