object_internal
[service_internal]

Collaboration diagram for object_internal:

Detailed Description

Module for manage Dbus Object handling

TO COMPLETE

Object Meta Information

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


Modules

 obj_method_internal
 obj_signal_internal
 obj_interface_internal

Functions

DBusHandlerResult easydbus_core_filter_func (DBusConnection *conn, DBusMessage *msg, void *user_data)
 This callback manage disconnection from dbus and try to do a new connection.
static DBusHandlerResult easydbus_error_handler (struct EasyDbus_core *core, DBusMessage *msg)
 Functions for manage error message from DBus and call user callback for error messages.
DBusHandlerResult easydbus_filter_func (DBusConnection *conn, DBusMessage *msg, void *user_data)
 EasyDbus filter function callback.
DBusHandlerResult easydbus_obj_path_msg_function (DBusConnection *conn, DBusMessage *msg, void *user_data)
 This function is static and must be used with struct EasyDbus_object for registered object callback.
void easydbus_obj_path_unregister_function (DBusConnection *conn, void *user_data)
 Unregister callback functions.
static DBusHandlerResult easydbus_reply_handler (struct EasyDbus_core *core, DBusMessage *msg)
 Functions for manage return message from DBus and call user callback for return messages.
static DBusHandlerResult easydbus_signal_handler (struct EasyDbus_core *core, DBusMessage *msg)
 Functions for manage signal from DBus and call user callback of external signal registered.
int easydbus_verify_signal_match (const char *member, const char *interface, const char *path, const char *sender, const char *destination, struct EasyDbus_ext_signal *el)
 Verify signal matching.


Function Documentation

DBusHandlerResult easydbus_core_filter_func ( DBusConnection *  conn,
DBusMessage *  msg,
void *  user_data 
)

This callback manage disconnection from dbus and try to do a new connection.

Returns:
DBUS_HANDLER_RESULT_NOT_YET_HANDLED

DBUS_HANDLER_RESULT_HANDLED

DBUS_HANDLER_RESULT_NEED_MEMORY

Parameters:
conn DBusConnection handler
msg DBusMessage message
user_data user data
Note:
Seems that when a Disconnected event is handle it is needed destroy EasyDbus_conn object and create a new connection. Probably, in this moment is more efficient restart service process beacause libdbus maintains internally a reference count of DBusConnection to 1 always still after dbus_connection_unref call. Creation is new connection is advised only for user application connect to Session bus, not to system service that remains in memory a lot of time.

For internal use only.

Definition at line 509 of file register_obj_internal.c.

References EasyDbusDebug, EasyDbus_conn::error_cb, EasyDbus_conn::error_closure, and EasyDbus_core::user_data.

Referenced by easydbus_conn_disable_filters(), and easydbus_conn_enable_filters().

00511 {
00512    struct EasyDbus_core *core =
00513     (struct EasyDbus_core *) user_data;
00514 
00515    if (dbus_message_is_signal (msg,
00516                                DBUS_INTERFACE_LOCAL,
00517                                "Disconnected")) {
00518       EasyDbusDebug ("Error DBUS disconnected!!!");
00519 
00520       if (core->user_data.error_cb)
00521          core->user_data.error_cb ((EasyDbus_conn *) user_data, 
00522                                    core->user_data.error_closure);
00523       return DBUS_HANDLER_RESULT_HANDLED;
00524    }
00525 
00526    EasyDbusDebug ("Core filter analysis");
00527    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
00528 }

static DBusHandlerResult easydbus_error_handler ( struct EasyDbus_core core,
DBusMessage *  msg 
) [static]

Functions for manage error message from DBus and call user callback for error messages.

Parameters:
core EasyDbus_core object pointer
msg DBusMessage message with error message.
Returns:
DBUS_HANDLER_RESULT_HANDLED

DBUS_HANDLER_RESULT_NOT_YET_HANDLED

DBUS_HANDLER_RESULT_NEED_MEMORY

For internal use only.

Definition at line 301 of file register_obj_internal.c.

References EasyDbus_Pending::closure, EasyDbus_Pending::core, easydbus_build_skeleton_data(), EASYDBUS_ET_FAILURE, easydbus_pending_destroy(), easydbus_reply_create_skeleton(), easydbus_reply_free_skeleton(), easydbus_reply_set_interface(), easydbus_reply_set_path(), easydbus_reply_set_sender(), easydbus_reply_set_type(), EasyDbusDebug, EasyDbus_conn::error_message_cb, EasyDbus_conn::error_message_closure, EasyDbus_Pending::message, EasyDbus_Pending::message_serial, EasyDbus_Pending::next, EasyDbus_Pending::pcall, EasyDbus_core::pending_msgs, EasyDbus_method::reply, EasyDbus_conn::reply_message_cb, and EasyDbus_core::user_data.

Referenced by easydbus_filter_func().

00303 {
00304    EasyDbus_reply *error_message = NULL;
00305    struct EasyDbus_Pending *p = NULL, **pp = NULL;
00306    const char *msg_interface = NULL;
00307    const char *msg_path = NULL;
00308    const char *msg_sender = NULL;
00309    dbus_uint32_t serial = 0;
00310 
00311    // get interface
00312    msg_interface = dbus_message_get_interface (msg);
00313    // get path
00314    msg_path = dbus_message_get_path (msg);
00315    // get sender
00316    msg_sender = dbus_message_get_sender (msg);
00317 
00318    EasyDbusDebug ("\n"
00319                   "- Handle error message ----------\n"
00320                   "path = %s\n"
00321                   "interface = %s\n"
00322                   "member = %s\n"
00323                   "sender = %s\n"
00324                   "---------------------------------\n",
00325                   msg_path, msg_interface, 
00326                   dbus_message_get_member (msg), msg_sender);
00327 
00328    error_message = easydbus_reply_create_skeleton ();
00329    if (!error_message)
00330       goto need_memory;
00331 
00332    easydbus_reply_set_type (error_message, EASYDBUS_ET_FAILURE);
00333 
00334    if (msg_interface)
00335       if (easydbus_reply_set_interface (error_message, msg_interface))
00336          goto need_memory;
00337    if (msg_path)
00338       if (easydbus_reply_set_path (error_message, msg_path))
00339          goto need_memory;
00340    if (msg_sender)
00341       if (easydbus_reply_set_sender (error_message, msg_sender))
00342          goto need_memory;
00343 
00344    easydbus_build_skeleton_data (msg, EASYDBUS_ET_FAILURE, 
00345                                  error_message);
00346 
00347    serial = dbus_message_get_reply_serial (msg);
00348    EasyDbusDebug ("Message serial = %d", serial);
00349 
00350    for (p = core->pending_msgs; p; p = p->next) 
00351       // if p->pcall is equal to null then is a pending struct
00352       // not connected to async message with notify
00353       if (!p->pcall && p->message_serial == serial) {
00354          p->message->reply = error_message;
00355          // remove EasyDbus_pending object from list
00356          for (pp = &(p->core->pending_msgs); *pp; pp = &(*pp)->next)
00357             if (*pp == p) {
00358                *pp = (*pp)->next;
00359                break;
00360             }
00361          if (core->user_data.reply_message_cb) 
00362             core->user_data.reply_message_cb ((EasyDbus_conn *) core,
00363                                               (const EasyDbus_method *) p->message,
00364                                               p->closure);
00365          break;
00366       }
00367 
00368    if (p)
00369       // error_message is free on easydbus_pending_destroy if 
00370       // it is connected to a EasyDbus_pending object
00371       easydbus_pending_destroy (p);
00372    else {
00373       if (core->user_data.error_message_cb)
00374          core->user_data.error_message_cb ((EasyDbus_conn *) core,
00375                                            (const EasyDbus_reply *) error_message,
00376                                            core->user_data.error_message_closure);
00377       easydbus_reply_free_skeleton (error_message);
00378    }
00379 
00380    return DBUS_HANDLER_RESULT_HANDLED;
00381 
00382 need_memory:
00383    if (error_message)
00384       easydbus_reply_free_skeleton (error_message);
00385 
00386    return DBUS_HANDLER_RESULT_NEED_MEMORY;
00387 }

Here is the call graph for this function:

DBusHandlerResult easydbus_filter_func ( DBusConnection *  conn,
DBusMessage *  msg,
void *  user_data 
)

EasyDbus filter function callback.

For internal use only.

Parameters:
conn DBusConnection handler
msg DBusMessage message
user_data user data
Returns:
DBUS_HANDLER_RESULT_HANDLED

DBUS_HANDLER_RESULT_NOT_YET_HANDLED

Definition at line 540 of file register_obj_internal.c.

References easydbus_error_handler(), easydbus_reply_handler(), easydbus_signal_handler(), and EasyDbusDebug.

Referenced by easydbus_conn_disable_filters(), and easydbus_conn_enable_filters().

00542 {
00543    struct EasyDbus_core *core = (struct EasyDbus_core *) user_data;
00544    int msg_type;
00545 
00546    if (!conn || !msg || !user_data) {
00547       EasyDbusDebug ("Error");
00548       return DBUS_HANDLER_RESULT_HANDLED;
00549    }
00550 
00551    EasyDbusDebug ("Message under filter analysis");
00552 
00553    // get message type
00554    msg_type = dbus_message_get_type (msg);
00555 
00556    if (msg_type == DBUS_MESSAGE_TYPE_SIGNAL) 
00557       return easydbus_signal_handler (core, msg);
00558    else if (msg_type == DBUS_MESSAGE_TYPE_ERROR) 
00559       return easydbus_error_handler (core, msg);
00560    else if (msg_type == DBUS_MESSAGE_TYPE_METHOD_RETURN) 
00561       return easydbus_reply_handler (core, msg);
00562 
00563    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
00564 }

Here is the call graph for this function:

DBusHandlerResult easydbus_obj_path_msg_function ( DBusConnection *  conn,
DBusMessage *  msg,
void *  user_data 
)

This function is static and must be used with struct EasyDbus_object for registered object callback.

Returns:
DBUS_HANDLER_RESULT_HANDLED Message has had its effect - no need to run more handlers.

DBUS_HANDLER_RESULT_NOT_YET_HANDLED Message has not had any effect - see if other handlers want it.

DBUS_HANDLER_RESULT_NEED_MEMORY Need more memory. Try again later with more memory

Parameters:
conn DBusConnection object pointer
msg DBusMessage mssage
user_data user data.
Todo:
  • enhancement management of user reply.

For internal use only.

Definition at line 78 of file register_obj_internal.c.

References EasyDbus_object_box::core, EASYDBUS_FAILURE_HANDLED, easydbus_get_obj(), EASYDBUS_METHOD_HANDLED, EASYDBUS_METHOD_RETURN_HANDLED, easydbus_reply_free_skeleton(), easydbus_reply_send(), easydbus_reply_send_error(), EASYDBUS_SIGNAL_HANDLED, easydbus_verify_match_and_prepare_reply(), EasyDbusDebug, EasyDbus_object::handled_interfaces, EasyDbus_obj_interface::next, and EasyDbus_core::objects.

Referenced by easydbus_object_register().

00081 {
00082    struct EasyDbus_core *core = (struct EasyDbus_core *) user_data;
00083    struct EasyDbus_object_box *obj = NULL;
00084    struct EasyDbus_obj_interface *interface = NULL;
00085    EasyDbus_reply *reply = NULL;
00086    const char *msg_member = NULL;
00087    const char *msg_interface = NULL;
00088    const char *msg_path = NULL;
00089    int ret_val = -1;
00090 
00091    // Check input param
00092    if (!msg || !conn || !user_data ||
00093        (dbus_message_get_type (msg) != 
00094         DBUS_MESSAGE_TYPE_METHOD_CALL)) {
00095       EasyDbusDebug ("Error");
00096       // see how manage this error. Maybe with an error msg.
00097       return DBUS_HANDLER_RESULT_HANDLED;
00098    }
00099 
00100    msg_path = dbus_message_get_path (msg);
00101    msg_member = dbus_message_get_member (msg);
00102    msg_interface = dbus_message_get_interface (msg);
00103 
00104    EasyDbusDebug ("Message %s for \n"
00105                   "path = %s\n"
00106                   "interface = %s\n"
00107                   "member = %s\n",
00108                   dbus_message_type_to_string (
00109                      dbus_message_get_type (msg)),
00110                   msg_path, msg_interface, msg_member);
00111 
00112    // check object path string of message with object
00113    // path string of registered objects.
00114    obj = easydbus_get_obj (core->objects, msg_path);
00115    if (!obj)
00116       goto obj_not_found;
00117 
00118    /* control any interface connect to object:
00119     * - first match meet is used */
00120    for (interface = obj->core.handled_interfaces;
00121         interface; interface = interface->next) {
00122       reply = easydbus_verify_match_and_prepare_reply (interface, 
00123                                                        msg, msg_interface, 
00124                                                        msg_member, &ret_val);
00125       if (ret_val == EASYDBUS_METHOD_HANDLED ||
00126           ret_val == EASYDBUS_FAILURE_HANDLED) {
00127          easydbus_reply_send (core, msg, reply);
00128          easydbus_reply_free_skeleton (reply);
00129          return DBUS_HANDLER_RESULT_HANDLED;
00130          // this must be managed correctly still
00131       }
00132       else if (ret_val == EASYDBUS_SIGNAL_HANDLED ||
00133                ret_val == EASYDBUS_METHOD_RETURN_HANDLED) {
00134          easydbus_reply_send_error (core, msg,
00135                                     "Error",
00136                                     "Error: unpredictable error");
00137          return DBUS_HANDLER_RESULT_HANDLED;
00138       }
00139    }
00140 
00141 obj_not_found:
00142    // send obj path doesn't exist error msg.
00143    // send_not_found_error ();
00144    easydbus_reply_send_error (core, msg, "NotFound",
00145                               "Error: method not found");
00146    return DBUS_HANDLER_RESULT_HANDLED;
00147 }

Here is the call graph for this function:

void easydbus_obj_path_unregister_function ( DBusConnection *  conn,
void *  user_data 
)

Unregister callback functions.

For internal use only.

Note:
Do nothings in this moment
Parameters:
conn DBusConnection handler.
user_data user data.

Definition at line 158 of file register_obj_internal.c.

Referenced by easydbus_object_register().

00160 {
00161 }

static DBusHandlerResult easydbus_reply_handler ( struct EasyDbus_core core,
DBusMessage *  msg 
) [static]

Functions for manage return message from DBus and call user callback for return messages.

Note:
If message isn't connected to pending object then message is drop.
Parameters:
core EasyDbus_core object pointer
msg DBusMessage message with error message.
Returns:
DBUS_HANDLER_RESULT_HANDLED

DBUS_HANDLER_RESULT_NOT_YET_HANDLED

For internal use only.

Definition at line 402 of file register_obj_internal.c.

References EasyDbus_Pending::closure, EasyDbus_Pending::core, easydbus_build_skeleton_data(), EASYDBUS_ET_REPLY, easydbus_pending_destroy(), easydbus_reply_create_skeleton(), easydbus_reply_free_skeleton(), easydbus_reply_set_interface(), easydbus_reply_set_path(), easydbus_reply_set_sender(), easydbus_reply_set_type(), EasyDbusDebug, EasyDbus_Pending::message, EasyDbus_Pending::message_serial, EasyDbus_Pending::next, EasyDbus_Pending::pcall, EasyDbus_core::pending_msgs, EasyDbus_method::reply, EasyDbus_conn::reply_message_cb, and EasyDbus_core::user_data.

Referenced by easydbus_filter_func().

00404 {
00405    EasyDbus_reply *reply = NULL;
00406    struct EasyDbus_Pending *p = NULL, **pp = NULL;
00407    const char *msg_member = NULL;
00408    const char *msg_interface = NULL;
00409    const char *msg_path = NULL;
00410    const char *msg_sender = NULL;
00411    dbus_uint32_t serial = 0;
00412 
00413    // get member
00414    msg_member = dbus_message_get_member (msg);
00415    // get interface
00416    msg_interface = dbus_message_get_interface (msg);
00417    // get path
00418    msg_path = dbus_message_get_path (msg);
00419    // get sender
00420    msg_sender = dbus_message_get_sender (msg);
00421 
00422    EasyDbusDebug ("\n"
00423                   "- Message reply -----------------\n"
00424                   "path = %s\n"
00425                   "interface = %s\n"
00426                   "member = %s\n"
00427                   "sender = %s\n"
00428                   "---------------------------------\n",
00429                   msg_path, msg_interface, msg_member, msg_sender);
00430 
00431    reply = easydbus_reply_create_skeleton ();
00432    if (!reply)
00433       goto need_memory;
00434 
00435    easydbus_reply_set_type (reply, EASYDBUS_ET_REPLY);
00436 
00437    if (msg_interface)
00438       if (easydbus_reply_set_interface (reply, msg_interface))
00439          goto need_memory;
00440    if (msg_path)
00441       if (easydbus_reply_set_path (reply, msg_path))
00442          goto need_memory;
00443    if (msg_sender)
00444       if (easydbus_reply_set_sender (reply, msg_sender))
00445          goto need_memory;
00446 
00447    easydbus_build_skeleton_data (msg, EASYDBUS_ET_REPLY, 
00448                                  reply);
00449 
00450    serial = dbus_message_get_reply_serial (msg);
00451    EasyDbusDebug ("Message serial = %d", serial);
00452 
00453    for (p = core->pending_msgs; p; p = p->next)
00454       // if p->pcall is equal to null then is a pending struct
00455       // not connected to async message with notify
00456       if (!p->pcall && p->message_serial == serial) {
00457          p->message->reply = reply;
00458          // remove EasyDbus_pending object from list
00459          for (pp = &(p->core->pending_msgs); *pp; pp = &(*pp)->next)
00460             if (*pp == p) {
00461                *pp = (*pp)->next;
00462                break;
00463             }
00464          if (core->user_data.reply_message_cb)
00465             core->user_data.reply_message_cb ((EasyDbus_conn *) core,
00466                                               (const EasyDbus_method *) p->message,
00467                                               p->closure);
00468          break;
00469       }
00470 
00471    if (p)
00472       easydbus_pending_destroy (p);
00473    else
00474       easydbus_reply_free_skeleton (reply);
00475 
00476    return DBUS_HANDLER_RESULT_HANDLED;
00477 
00478 need_memory:
00479 
00480    if (reply)
00481       easydbus_reply_free_skeleton (reply);
00482 
00483    return DBUS_HANDLER_RESULT_NEED_MEMORY;
00484 }

Here is the call graph for this function:

static DBusHandlerResult easydbus_signal_handler ( struct EasyDbus_core core,
DBusMessage *  msg 
) [static]

Functions for manage signal from DBus and call user callback of external signal registered.

Parameters:
core EasyDbus_core object pointer
msg DBusMessage message with signal.
Returns:
DBUS_HANDLER_RESULT_HANDLED

DBUS_HANDLER_RESULT_NOT_YET_HANDLED

For internal use only.

TODO: manage user return value

Definition at line 235 of file register_obj_internal.c.

References easydbus_signal_build_skeleton(), easydbus_signal_free_skeleton(), easydbus_signal_set_sender(), easydbus_verify_signal_match(), EasyDbusDebug, EasyDbus_core::handled_ext_signals, EasyDbus_core::handled_signal, EasyDbus_ext_signal::next, and EasyDbus_ext_signal::signal_callback.

Referenced by easydbus_filter_func().

00237 {
00238    struct EasyDbus_ext_signal *el = NULL;
00239    struct EasyDbus_signal *handled_signal = NULL;
00240    const char *msg_member = NULL;
00241    const char *msg_interface = NULL;
00242    const char *msg_path = NULL;
00243    const char *msg_sender = NULL;
00244    const char *msg_destination = NULL;
00245 
00246    // get member
00247    msg_member = dbus_message_get_member (msg);
00248    // get interface
00249    msg_interface = dbus_message_get_interface (msg);
00250    // get path
00251    msg_path = dbus_message_get_path (msg);
00252    // get sender
00253    msg_sender = dbus_message_get_sender (msg);
00254    // get destination
00255    msg_destination = dbus_message_get_destination (msg);
00256 
00257    if (core->handled_signal)
00258       for (el = core->handled_ext_signals; el; el = el->next)
00259          if (!easydbus_verify_signal_match
00260              (msg_member, msg_interface, msg_path, msg_sender, 
00261               msg_destination, el)) {
00262             EasyDbusDebug ("Extern Signal Handled");
00263             handled_signal = easydbus_signal_build_skeleton (msg);
00264             if (handled_signal) {
00266                if (msg_sender)
00267                   easydbus_signal_set_sender (handled_signal, msg_sender);
00268                el->signal_callback ((struct EasyDbus_conn *) core,
00269                                     handled_signal);
00270                easydbus_signal_free_skeleton (handled_signal);
00271             }
00272             goto out;
00273          }
00274 
00275    EasyDbusDebug ("\n"
00276                   "- Drop signal -------------------\n"
00277                   "path = %s\n"
00278                   "interface = %s\n"
00279                   "member = %s\n"
00280                   "sender = %s\n"
00281                   "destination = %s\n"
00282                   "---------------------------------\n",
00283                   msg_path, msg_interface, msg_member, 
00284                   msg_sender, msg_destination);
00285 
00286 out:
00287    return DBUS_HANDLER_RESULT_HANDLED;
00288 }

Here is the call graph for this function:

int easydbus_verify_signal_match ( const char *  member,
const char *  interface,
const char *  path,
const char *  sender,
const char *  destination,
struct EasyDbus_ext_signal el 
)

Verify signal matching.

Parameters:
member signal name string
interface interface of string
path path of signal
sender sender of signal
el EasyDbus_ext_signal object pointer.
Returns:
-1 error/ match not found

0 found match

For internal use only.

Definition at line 578 of file register_obj_internal.c.

References EasyDbus_ext_signal::destination, EasyDbus_ext_signal::interface, EasyDbus_ext_signal::path, EasyDbus_ext_signal::sender, and EasyDbus_ext_signal::signal.

Referenced by easydbus_signal_handler().

00584 {
00585    if (!el || !member )
00586       return -1;
00587 
00588    if (strcmp (el->signal, member))
00589       return -1;
00590 
00591    if (interface && el->interface)
00592       if (strcmp (el->interface, interface))
00593          return -1;
00594 
00595    if (path && el->path)
00596       if (strcmp (el->path, path))
00597          return -1;
00598 
00599    if (sender && el->sender)
00600       if (strcmp (el->sender, sender))
00601          return -1;
00602 
00603    if (destination && el->destination)
00604       if (strcmp (el->destination, destination))
00605          return -1;
00606 
00607    return 0;
00608 }


Generated on Thu Apr 10 10:03:21 2008 for EasyDbus-0.2 by  doxygen 1.5.4