method
[message]

Collaboration diagram for method:

Detailed Description

Module for manage EasyDbus Method objects

TO COMPLETE

See also:
skeleton module for functions to use for insert args on methods. In particular must be used EASYDBUS_ET_METHOD as event type value.

Method Meta Information

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


Data Structures

struct  EasyDbus_method
 EasyDbus_method object. More...

Functions

EasyDbus_methodeasydbus_method_create_skeleton (char *destination, char *path, char *interface, char *method)
 Create EasyDbus_method object skeleton.
void easydbus_method_free_skeleton (EasyDbus_method *method)
 Free a EasyDbus_method object.
int easydbus_method_get_args (EasyDbus_method *method)
 Get number of args on EasyDbus_method object.
const char * easydbus_method_get_destination (EasyDbus_method *method)
 Get destination of method.
const EasyDbus_elemeasydbus_method_get_element (EasyDbus_method *method, unsigned int n)
 Get N-element of EasyDbus_method object.
const char * easydbus_method_get_interface (EasyDbus_method *method)
 Get interface of method.
const char * easydbus_method_get_name (EasyDbus_method *method)
 Get name of method.
const char * easydbus_method_get_path (EasyDbus_method *method)
 Get path of method.
const EasyDbus_replyeasydbus_method_get_reply (EasyDbus_method *method)
 Get method reply message pointer from method.
int easydbus_method_send_async (EasyDbus_conn *conn, EasyDbus_method *method, void *closure)
 Call method and blocking for a reply.
int easydbus_method_send_async_with_notify (EasyDbus_conn *conn, EasyDbus_method *method, easydbus_method_async_reply_cb_f r_cb, void *closure, int timeout)
 Call method message async and notify a reply or a timeout.
enum easydbus_ret_values easydbus_method_send_blocking (EasyDbus_conn *conn, EasyDbus_method *method, int timeout)
 Call method and blocking for a reply.
int easydbus_method_set_reply (EasyDbus_method *method, EasyDbus_reply *reply)
 Set method reply message.


Function Documentation

EasyDbus_method* easydbus_method_create_skeleton ( char *  destination,
char *  path,
char *  interface,
char *  method 
)

Create EasyDbus_method object skeleton.

Parameters:
destination destination of method call
path path of method
interface interface of method
method method name
Returns:
pointer to a new EasyDbus_method object

NULL error

Definition at line 134 of file method.c.

References EasyDbus_method::destination, EASYDBUS_MEMCOPY, EasyDbus_method::first, EasyDbus_method::interface, EasyDbus_method::name, EasyDbus_method::path, EasyDbus_method::reply, and EasyDbus_method::retry.

Referenced by easydbus_method_build_skeleton().

00137 {
00138    int len = 0;
00139    struct EasyDbus_method *m = NULL;
00140 
00141    m = (struct EasyDbus_method *)
00142       malloc (sizeof (struct EasyDbus_method));
00143 
00144    if (m == NULL || path == NULL)
00145       return NULL;
00146 
00147    memset (m, 0, sizeof (struct EasyDbus_method));
00148 
00149    m->name = m->path = m->destination = m->interface = NULL;
00150    m->first = NULL;
00151    m->reply = NULL;
00152    m->retry = 0;
00153 
00154    len = strlen (method) + 1;
00155    m->name = (char *) malloc (len);
00156    if (!m->name)
00157       goto out_of_memory_error;
00158    EASYDBUS_MEMCOPY (m->name, method, len)
00159 
00160    if (interface) {
00161       len = strlen (interface) + 1;
00162       m->interface = (char *) malloc (len);
00163       if (!m->interface)
00164          goto out_of_memory_error;
00165       EASYDBUS_MEMCOPY (m->interface, interface, len);
00166    }
00167 
00168    len = strlen (path) + 1;
00169    m->path = (char *) malloc (len);
00170    if (!m->path)
00171       goto out_of_memory_error;
00172    EASYDBUS_MEMCOPY (m->path, path, len);
00173 
00174    if (destination) {
00175       len = strlen (destination) + 1;
00176       m->destination = (char *) malloc (len);
00177       if (!m->destination)
00178          goto out_of_memory_error;
00179       EASYDBUS_MEMCOPY (m->destination, destination, len);
00180    }
00181 
00182    return m;
00183 
00184  out_of_memory_error:
00185    if (m->path)
00186       free (m->path);
00187    if (m->interface)
00188       free (m->interface);
00189    if (m->name)
00190       free (m->name);
00191    if (m)
00192       free (m);
00193    return NULL;
00194 }

void easydbus_method_free_skeleton ( EasyDbus_method method  )  [inline]

Free a EasyDbus_method object.

Precondition:
method != NULL
Parameters:
method EasyDbus_method object pointer.

Definition at line 57 of file method.c.

References EasyDbus_method::args, EasyDbus_method::destination, easydbus_elem_free(), easydbus_reply_free_skeleton(), EasyDbus_method::first, EasyDbus_method::interface, EasyDbus_method::name, EasyDbus_elem::next, EasyDbus_method::path, and EasyDbus_method::reply.

Referenced by easydbus_method_build_skeleton(), easydbus_pending_destroy(), easydbus_verify_match_and_prepare_reply(), and easydbus_watch_method_blocking().

00058 {
00059    struct EasyDbus_elem *el = NULL;
00060 
00061    if (method == NULL)
00062       return;
00063 
00064    if (method->name != NULL)
00065       free (method->name);
00066    if (method->path != NULL)
00067       free (method->path);
00068    if (method->destination != NULL)
00069       free (method->destination);
00070    if (method->interface != NULL)
00071       free (method->interface);
00072 
00073    method->name = method->path = method->interface = NULL;
00074 
00075    while (method->args) {
00076       if (method->first != NULL) {
00077          el = method->first;
00078          method->first = method->first->next;
00079          easydbus_elem_free (el);
00080       }
00081       method->args--;
00082    }
00083 
00084    if (method->reply != NULL)
00085       easydbus_reply_free_skeleton (method->reply);
00086 
00087    free (method);
00088 }

Here is the call graph for this function:

int easydbus_method_get_args ( EasyDbus_method method  ) 

Get number of args on EasyDbus_method object.

Precondition:
method != NULL
Parameters:
method EasyDbus_method object pointer
Returns:
-1 on error

number of args on EasyDbus_method object.

Definition at line 303 of file method.c.

References EasyDbus_method::args.

00304 {
00305    return (method ? method->args : -1);
00306 }

const char* easydbus_method_get_destination ( EasyDbus_method method  ) 

Get destination of method.

Precondition:
method != NULL
Parameters:
method EasyDbus_method object pointer
Returns:
method interface string.

NULL on error or no interface set.

Definition at line 289 of file method.c.

References EasyDbus_method::destination.

00290 {
00291    return (method ? (const char *) method->destination : NULL);
00292 }

const EasyDbus_elem* easydbus_method_get_element ( EasyDbus_method method,
unsigned int  n 
)

Get N-element of EasyDbus_method object.

Precondition:
method != NULL n >= 1 && n <= method arguments number
Parameters:
method EasyDbus_method object pointer
n element to recover.
Returns:
NULL on error

pointer to n-EasyDbus_elem of signal.

Definition at line 319 of file method.c.

References EasyDbus_method::args, easydbus_elem_get_element(), and EasyDbus_method::first.

00320 {
00321    return ((!method || n > method->args) ? NULL :
00322            easydbus_elem_get_element (method->first, n));
00323 }

Here is the call graph for this function:

const char* easydbus_method_get_interface ( EasyDbus_method method  ) 

Get interface of method.

Precondition:
method != NULL
Parameters:
method EasyDbus_method object pointer
Returns:
method interface string.

NULL on error or no interface set.

Definition at line 247 of file method.c.

References EasyDbus_method::interface.

00248 {
00249    return (method ? (const char *) method->interface : NULL);
00250 }

const char* easydbus_method_get_name ( EasyDbus_method method  ) 

Get name of method.

Precondition:
method != NULL
Parameters:
method EasyDbus_method object pointer
Returns:
method interface string.

NULL on error or no interface set.

Definition at line 261 of file method.c.

References EasyDbus_method::name.

00262 {
00263    return (method ? (const char *) method->name : NULL);
00264 }

const char* easydbus_method_get_path ( EasyDbus_method method  ) 

Get path of method.

Precondition:
method != NULL
Parameters:
method EasyDbus_method object pointer
Returns:
method interface string.

NULL on error or no interface set.

Definition at line 275 of file method.c.

References EasyDbus_method::path.

00276 {
00277    return (method ? (const char *) method->path : NULL);
00278 }

const EasyDbus_reply* easydbus_method_get_reply ( EasyDbus_method method  )  [inline]

Get method reply message pointer from method.

Parameters:
method EasyDbus_method object pointer
Returns:
pointer to reply of method.

NULL on error or if there is a reply.

Definition at line 116 of file method.c.

References EasyDbus_method::reply.

00117 {
00118    if (method == NULL)
00119       return NULL;
00120 
00121    return method->reply;
00122 }

int easydbus_method_send_async ( EasyDbus_conn conn,
EasyDbus_method method,
void *  closure 
)

Call method and blocking for a reply.

Returns:
-1 on error

0 message in outgoing queue

Parameters:
conn EasyDbus_conn object pointer
method method to sent that is free from library.
closure user closure passed to CALLBACK

see if this is needed

Definition at line 423 of file method.c.

References create_method_msg(), easydbus_message_send(), easydbus_pending_create_skeleton(), easydbus_pending_destroy(), EasyDbusDebug, EasyDbus_Pending::message, EasyDbus_Pending::message_serial, EasyDbus_Pending::next, and EasyDbus_core::pending_msgs.

00426 {
00427    struct EasyDbus_core *core =
00428       (struct EasyDbus_core *) conn;
00429    struct EasyDbus_Pending *p = NULL;
00430    DBusMessage *msg = NULL;
00431 
00432    if (!conn || !method)
00433       return -1;
00434 
00435    p = easydbus_pending_create_skeleton (core, method, NULL,
00436                                          closure, 0);
00437    if (!p) goto error;
00438 
00439    msg = create_method_msg (core, method);
00440 
00441    if (!msg) {
00442       EasyDbusDebug ("Error on create method message");
00443       goto error;
00444    }
00445 
00446    if (easydbus_message_send(core, msg, 0, &p->message_serial)) {
00447       EasyDbusDebug ("Error on send message");
00448       goto error;
00449    }
00450 
00451    // add EasyDbus_Pending object to list
00452    if (core->pending_msgs)
00453       p->next = core->pending_msgs;
00454    core->pending_msgs = p;
00455 
00456    dbus_message_unref (msg);
00457 
00458    return 0;
00459 error:
00460    if (p) {
00462       p->message = NULL;
00463       easydbus_pending_destroy (p);
00464    }
00465    if (msg)
00466       dbus_message_unref(msg);
00467 
00468    return -1;
00469 }

Here is the call graph for this function:

int easydbus_method_send_async_with_notify ( EasyDbus_conn conn,
EasyDbus_method method,
easydbus_method_async_reply_cb_f  r_cb,
void *  closure,
int  timeout 
)

Call method message async and notify a reply or a timeout.

Note:
With this solution replies messages of methods aren't filter on main loop but are handled before watcher or main loop.
Parameters:
conn EasyDbus_conn object pointer
method EasyDbus_method object pointer with method to call.
r_cb user callback called on
closure user closure passed to callback
timeout timeout on wait reply. -1 is default value.
Returns:
-1 on error

0 message insert on outgoing queue.

see if this is needed

Definition at line 370 of file method.c.

References create_method_msg(), easydbus_message_send_async(), easydbus_pending_create_skeleton(), easydbus_pending_destroy(), EasyDbus_Pending::message, EasyDbus_Pending::next, and EasyDbus_core::pending_msgs.

00375 {
00376    DBusMessage *msg = NULL;
00377    struct EasyDbus_core *core = 
00378       (struct EasyDbus_core *) conn;
00379    struct EasyDbus_Pending *p = NULL;
00380 
00381    if (!conn || !method || !r_cb)
00382       return -1;
00383 
00384    p = easydbus_pending_create_skeleton (core, method, r_cb,
00385                                          closure, timeout);
00386    if (!p) goto error;
00387 
00388    msg = create_method_msg (core, method);
00389    if (!msg) goto error;
00390 
00391    if (easydbus_message_send_async(core, p, msg))
00392       goto error;
00393 
00394    // add EasyDbus_Pending object to list
00395    if (core->pending_msgs)
00396       p->next = core->pending_msgs;
00397    core->pending_msgs = p;
00398 
00399    dbus_message_unref (msg);
00400    return 0;
00401 
00402 error:
00403    if (p) {
00405       p->message = NULL;
00406       easydbus_pending_destroy (p);
00407    }
00408    if (msg)
00409       dbus_message_unref(msg);
00410    return -1;
00411 }

Here is the call graph for this function:

enum easydbus_ret_values easydbus_method_send_blocking ( EasyDbus_conn conn,
EasyDbus_method method,
int  timeout 
)

Call method and blocking for a reply.

Returns:
EASYDBUS_ERROR on error

EASYDBUS_METHOD_NOT_SENT method not sent.

EASYDBUS_METHOD_SENT method sent

Parameters:
conn EasyDbus_conn object pointer
method method to sent
timeout timeout value. -1 (wait until receive reply)

Definition at line 482 of file method.c.

References create_method_msg(), EASYDBUS_ERROR, EASYDBUS_METHOD_NOT_SENT, EASYDBUS_METHOD_SENT, easydbus_send_method_withReply_Blocking(), and EasyDbusDebug.

00485 {
00486    struct EasyDbus_core *core =
00487       (struct EasyDbus_core *) conn;
00488    int ret_val = EASYDBUS_METHOD_NOT_SENT;
00489 
00490    if (!conn || !method)
00491       return EASYDBUS_ERROR;
00492 
00493    DBusMessage *msg = create_method_msg (core, method);
00494 
00495    if (!msg) {
00496       EasyDbusDebug ("Error on create method message");
00497       return EASYDBUS_ERROR;
00498    }
00499 
00500    if (!easydbus_send_method_withReply_Blocking
00501        (core, msg, method, timeout))
00502       ret_val = EASYDBUS_METHOD_SENT;
00503 
00504    dbus_message_unref (msg);
00505 
00506    return ret_val;
00507 }

Here is the call graph for this function:

int easydbus_method_set_reply ( EasyDbus_method method,
EasyDbus_reply reply 
) [inline]

Set method reply message.

Parameters:
method pointer to EasyDbus_method object
reply pointer to EasyDbus_reply object
Returns:
-1 error

0 ok

Definition at line 98 of file method.c.

References EasyDbus_method::reply.

00100 {
00101    if (reply == NULL || method == NULL)
00102       return -1;
00103 
00104    method->reply = reply;
00105 
00106    return 0;
00107 }


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