message_internal
[Internal functions of Easydbus Library]

Collaboration diagram for message_internal:

Detailed Description

Module for manage EasyDbus Message Internal

TO COMPLETE

Message Meta Information

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


Modules

 signal_internal
 method_internal
 reply_internal

Functions

int easydbus_message_send (struct EasyDbus_core *core, DBusMessage *msg, unsigned int flush, dbus_uint32_t *mserial)
 Send DBusMessage or insert message on queue.
int easydbus_message_send_async (struct EasyDbus_core *core, struct EasyDbus_Pending *p, DBusMessage *msg)
 Send DBusMessage on async mode.
struct EasyDbus_Pendingeasydbus_pending_create_skeleton (struct EasyDbus_core *core, EasyDbus_method *method, easydbus_method_async_reply_cb_f p_cb, void *closure, int timeout)
 Create EasyDbus_Pending object skeleton.
void easydbus_pending_destroy (struct EasyDbus_Pending *p)
 Free EasyDbus_Pending object.
void easydbus_pending_msg_handler (DBusPendingCall *pcall, void *data)
 Handler for manage pending messages.


Function Documentation

int easydbus_message_send ( struct EasyDbus_core core,
DBusMessage *  msg,
unsigned int  flush,
dbus_uint32_t *  mserial 
) [inline]

Send DBusMessage or insert message on queue.

For internal use only.

Parameters:
core EasyDbus_core object pointer
msg DBusMessage to send.
flush field to enable flush of queue.
mserial pointer to a dbus_uint32_t variable where is saved serial number of message.
Returns:
-1 on error

0 ok

Definition at line 59 of file message.c.

References EasyDbus_core::conn, and EasyDbusDebug.

Referenced by easydbus_method_send_async(), easydbus_reply_send(), easydbus_reply_send_error(), and easydbus_signal_send().

00061 {
00062    EasyDbusDebug ("Message serial %d", 
00063                    mserial ? *mserial : 0);
00064    
00065    if (!dbus_connection_send (core->conn, msg, mserial)) {
00066       fprintf (stderr, "Could not send message on D-BUS.");
00067       return -1;
00068    }
00069 
00070    EasyDbusDebug ("Message serial %d", 
00071                    mserial ? *mserial : 0);
00072 
00073    if (flush)
00074       dbus_connection_flush (core->conn);
00075 
00076    return 0;
00077 }

int easydbus_message_send_async ( struct EasyDbus_core core,
struct EasyDbus_Pending p,
DBusMessage *  msg 
)

Send DBusMessage on async mode.

Returns:
-1 on error

0 message on outgoing queue.

For internal use only.

Definition at line 87 of file message.c.

References EasyDbus_core::conn, easydbus_pending_msg_handler(), EasyDbusDebug, EasyDbus_Pending::pcall, and EasyDbus_Pending::timeout.

Referenced by easydbus_method_send_async_with_notify().

00090 {
00091    if (!core || !p || !msg)
00092       return -1;
00093 
00094    if (!dbus_connection_send_with_reply (core->conn, msg, 
00095                                          &(p->pcall), p->timeout))
00096       return -1;
00097 
00098    EasyDbusDebug ("Created Pending Object (%p)", p->pcall);
00099 
00100    if (!dbus_pending_call_set_notify (p->pcall, 
00101                                       easydbus_pending_msg_handler, 
00102                                       (void *) p, NULL))
00103       return -1;
00104 
00105    EasyDbusDebug ("Message insert on queue");
00106    return 0;
00107 }

Here is the call graph for this function:

struct EasyDbus_Pending* easydbus_pending_create_skeleton ( struct EasyDbus_core core,
EasyDbus_method method,
easydbus_method_async_reply_cb_f  p_cb,
void *  closure,
int  timeout 
) [read]

Create EasyDbus_Pending object skeleton.

Parameters:
core pointer to EasyDbus_core object
method pointer to EasyDbus_method object with request message.
p_cb user callback to call on event.
closure user closure passed to callback
timeout timeout on wait reply message. -1 is default value.

For internal use only.

Definition at line 192 of file message.c.

References EasyDbus_Pending::closure, EasyDbus_Pending::core, EasyDbus_Pending::message, EasyDbus_Pending::message_serial, EasyDbus_Pending::next, EasyDbus_Pending::p_cb, EasyDbus_Pending::pcall, and EasyDbus_Pending::timeout.

Referenced by easydbus_method_send_async(), and easydbus_method_send_async_with_notify().

00196 {
00197    struct EasyDbus_Pending *p;
00198 
00199    if (!core || !method)
00200       return NULL;
00201 
00202    p = (struct EasyDbus_Pending *) 
00203        malloc (sizeof (struct EasyDbus_Pending));
00204    
00205    if (!p) 
00206       return NULL;
00207    
00208    memset (p, 0, sizeof (struct EasyDbus_Pending));
00209 
00210    p->core = core;
00211    p->message = method;
00212    p->message_serial = 0;
00213    p->p_cb = p_cb;
00214    p->closure = closure;
00215    p->next = NULL;
00216    p->timeout = timeout;
00217    p->pcall = NULL;
00218   
00219    return p;
00220 }

void easydbus_pending_destroy ( struct EasyDbus_Pending p  ) 

Free EasyDbus_Pending object.

Precondition:
p != NULL
Parameters:
p pointer to EasyDbus_Pending object.

For internal use only.

Definition at line 230 of file message.c.

References EasyDbus_Pending::closure, EasyDbus_Pending::core, easydbus_method_free_skeleton(), EasyDbusDebug, EasyDbus_Pending::message, EasyDbus_Pending::message_serial, EasyDbus_Pending::next, EasyDbus_Pending::p_cb, and EasyDbus_Pending::pcall.

Referenced by easydbus_conn_destroy(), easydbus_error_handler(), easydbus_method_send_async(), easydbus_method_send_async_with_notify(), easydbus_pending_msg_handler(), and easydbus_reply_handler().

00231 {
00232    if (!p) return;
00233 
00234    if (p->message)
00235       easydbus_method_free_skeleton(p->message);
00236 
00237    if (p->pcall) {
00238       EasyDbusDebug ("Free EasyDbus_Pending object (%p)", p->pcall);
00239       dbus_pending_call_unref (p->pcall);
00240       p->pcall = NULL;
00241    }
00242 
00243    p->message = NULL;
00244    p->message_serial = 0;
00245    p->core = NULL;
00246    p->p_cb = NULL;
00247    p->next = NULL;
00248    p->closure = NULL;
00249 
00250    free(p);
00251    
00252 }

Here is the call graph for this function:

void easydbus_pending_msg_handler ( DBusPendingCall *  pcall,
void *  data 
)

Handler for manage pending messages.

Parameters:
pcall DBusPendingCall object connect to async message.
data pointer to EasyDbus_Pending object.

For internal use only.

TODO

Definition at line 117 of file message.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(), EasyDbusDebug, EasyDbus_Pending::message, EasyDbus_Pending::next, EasyDbus_Pending::p_cb, EasyDbus_Pending::pcall, EasyDbus_core::pending_msgs, EasyDbus_method::reply, and EasyDbus_method::retry.

Referenced by easydbus_message_send_async().

00119 {
00120    DBusMessage *reply_msg = NULL;
00121    EasyDbus_reply *reply = NULL;
00122    struct EasyDbus_Pending *p, **temp;
00123    
00124    p = (struct EasyDbus_Pending *) data;
00125    EasyDbusDebug ("Use Pending Object (%p)", pcall);
00126 
00127    if (!p || p->pcall != pcall) {
00128       EasyDbusDebug ("Error data mismatch");
00129       return;
00130    }
00131 
00132    // initialize retry field of method
00133    p->message->retry = 0;
00134    reply_msg = dbus_pending_call_steal_reply(pcall);
00135    if (reply_msg) {
00136       // there is a reply
00137       reply = easydbus_reply_create_skeleton ();
00138       if (!reply) 
00139          goto error;
00140 
00141       if (easydbus_build_skeleton_data (reply_msg, EASYDBUS_ET_REPLY,
00142                                         reply))
00143          goto error;
00144       p->message->reply = reply;
00145    } 
00146    // else a timeout is handled.
00147 
00148    p->p_cb ((EasyDbus_conn *) p->core, p->message,
00149             p->closure);
00150 
00151    if (p->message->retry) {
00152       // retry method call
00153       if (p->message->reply) {
00154          easydbus_reply_free_skeleton (p->message->reply);
00155          p->message->reply = NULL;
00156       }
00158       dbus_pending_call_unref (p->pcall);
00159    }
00160    else {
00161       // remove pending object from list
00162       for (temp = &(p->core->pending_msgs); *temp;
00163            temp = &(*temp)->next)
00164          if (*temp == p) {
00165             *temp = (*temp)->next;
00166             break;
00167          }
00168       if (reply_msg)
00169          dbus_message_unref (reply_msg);
00170       easydbus_pending_destroy (p);
00171    }
00172 
00173    return;
00174 error:
00175    EasyDbusDebug ("Error not managed");
00176    if (reply) 
00177       easydbus_reply_free_skeleton (reply);
00178 }

Here is the call graph for this function:


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