![]() |
This module contains functions for manage connections to DBus bus. In particular, for now it is only supported connection to normal DBus system or session, no TCP or other solutions.
Data Structures | |
struct | EasyDbus_conn |
EasyDbus_conn object Struct used for. More... | |
Functions | |
int | easydbus_conn_add_match_rule (EasyDbus_conn *data, enum event_type type, char *sender, char *interface, char *member, char *path, char *destination) |
easydbus includes | |
EasyDbus_conn * | easydbus_conn_create (void) |
Create and init EasyDbus_conn object. | |
int | easydbus_conn_destroy (EasyDbus_conn *conn) |
Deinitialize EasyDbus_conn object, close connection to Dbus and remove registered objects. | |
int | easydbus_conn_disable_filters (EasyDbus_conn *conn) |
Disable filters for objects. | |
int | easydbus_conn_enable_filters (EasyDbus_conn *conn) |
Enable filters for objects. In particular, this function MUST be called for manage Disconnected signal, reply message on service and for manage external signal object. | |
int | easydbus_conn_get_address (EasyDbus_conn *conn, char *serviceName, enum easydbus_bus bus, int flags) |
Acquire source address. | |
int | easydbus_conn_get_fd (EasyDbus_conn *data) |
Get connection file descriptor of connection. | |
int | easydbus_conn_get_n_object (EasyDbus_conn *conn) |
Get number of objects of EasyDbus_conn connection. | |
EasyDbus_object * | easydbus_conn_get_object (EasyDbus_conn *conn, unsigned int n) |
Get n-EasyDbus_object of connection. | |
const char * | easydbus_conn_get_service_name (const EasyDbus_conn *conn) |
Get service name. | |
int | easydbus_conn_get_system_service_address (EasyDbus_conn *data, char *serviceName) |
Acquire source address from environment variable. | |
int | easydbus_conn_remove_match_rule (EasyDbus_conn *data, enum event_type type, char *sender, char *interface, char *member, char *path, char *destination) |
Remove match rule on dbus. | |
int | easydbus_conn_set_error_cb (EasyDbus_conn *conn, easydbus_error_cb_f cb, void *user_closure) |
Set user callback for handle error on Dbus connection. | |
int | easydbus_conn_set_error_message_cb (EasyDbus_conn *conn, easydbus_error_message_cb_f e_cb, void *user_closure) |
Set user callback for handle error message not connected to a pending message. | |
int | easydbus_conn_set_reply_async_cb (EasyDbus_conn *conn, easydbus_reply_async_cb_f r_cb, void *user_closure) |
Set user callback for handle reply to asynchronous method call on easydbus_main_loop or through watcher. | |
int | easydbus_conn_set_reply_message_cb (EasyDbus_conn *conn, easydbus_reply_message_cb_f r_cb) |
Set user callback for handle reply message connected to a pending message. |
int easydbus_conn_add_match_rule | ( | EasyDbus_conn * | data, | |
enum event_type | type, | |||
char * | sender, | |||
char * | interface, | |||
char * | member, | |||
char * | path, | |||
char * | destination | |||
) | [inline] |
easydbus includes
Add match to dbus
data | EasyDbus_conn object pointer | |
type | enum event_type that identify message | |
sender | sender of message. (can be equal to NULL) | |
interface | interface of message (can be equal to NULL) | |
member | member of message (can be equal to NULL) | |
path | path of message (can be equal to NULL) | |
destination | destination of message (can be equal to NULL) |
-1 error
Definition at line 61 of file match_rules.c.
References EasyDbus_core::conn, EasyDbusDebug, and prepare_match_string().
00065 { 00066 DBusError err; 00067 00068 dbus_error_init (&err); 00069 00070 struct EasyDbus_core *core = (struct EasyDbus_core *) data; 00071 char *buffer = NULL; 00072 00073 buffer = prepare_match_string (type, sender, 00074 interface, member, path, 00075 destination); 00076 if (buffer == NULL) 00077 return -1; 00078 00079 EasyDbusDebug ("MATCH_RULE = %s\n", buffer); 00080 00081 dbus_bus_add_match (core->conn, buffer, &err); 00082 dbus_connection_flush (core->conn); 00083 00084 if (dbus_error_is_set (&err)) { 00085 EasyDbusDebug ("Matched error (%s)\n", err.message); 00086 free (buffer); 00087 dbus_error_free (&err); 00088 return -1; 00089 } 00090 00091 dbus_error_free (&err); 00092 free (buffer); 00093 return 0; 00094 }
EasyDbus_conn* easydbus_conn_create | ( | void | ) |
Create and init EasyDbus_conn object.
pointer to EasyDbus_conn object
Definition at line 335 of file acquire.c.
References EasyDbus_conn::bus, EasyDbus_core::conn, EASYDBUS_INVALID, EasyDbus_conn::error_cb, EasyDbus_conn::error_closure, EasyDbus_conn::error_message_cb, EasyDbus_conn::error_message_closure, EasyDbus_conn::flags, EasyDbus_core::handled_ext_signals, EasyDbus_core::objects, EasyDbus_core::pending_msgs, EasyDbus_conn::reply_async_cb, EasyDbus_conn::reply_message_cb, EasyDbus_core::service_name, EasyDbus_core::user_data, and EasyDbus_core::watcher.
00336 { 00337 struct EasyDbus_core *conn = 00338 (struct EasyDbus_core *) 00339 malloc (sizeof (struct EasyDbus_core)); 00340 00341 if (!conn) 00342 return NULL; 00343 00344 memset (conn, 0, sizeof (struct EasyDbus_core)); 00345 00346 conn->objects = NULL; 00347 conn->conn = NULL; 00348 conn->service_name = NULL; 00349 conn->watcher = NULL; 00350 conn->handled_ext_signals = NULL; 00351 conn->user_data.error_cb = NULL; 00352 conn->user_data.error_closure = NULL; 00353 conn->user_data.flags = 0; 00354 conn->user_data.bus = EASYDBUS_INVALID; 00355 conn->pending_msgs = NULL; 00356 conn->user_data.reply_async_cb = NULL; 00357 conn->user_data.error_message_cb = NULL; 00358 conn->user_data.error_message_closure = NULL; 00359 conn->user_data.reply_message_cb = NULL; 00360 00361 return (EasyDbus_conn *) conn; 00362 }
int easydbus_conn_destroy | ( | EasyDbus_conn * | conn | ) |
Deinitialize EasyDbus_conn object, close connection to Dbus and remove registered objects.
conn | EasyDbus_conn object pointer |
-1 error
Definition at line 403 of file acquire.c.
References EasyDbus_core::conn, EasyDbus_object_box::core, easydbus_ext_signal_free_skeleton(), easydbus_object_free_skeleton(), easydbus_object_unregister(), easydbus_pending_destroy(), EasyDbusDebug, EasyDbus_core::handled_ext_signals, EasyDbus_core::n_objs, EasyDbus_watcher::next, EasyDbus_Pending::next, EasyDbus_ext_signal::next, EasyDbus_object_box::next, EasyDbus_core::objects, EasyDbus_core::pending_msgs, EasyDbus_conn::registered_ondbus, EasyDbus_core::service_name, EasyDbus_ext_signal::signal, EasyDbus_watcher::watch, EasyDbus_core::watcher, EasyDbus_conn::watcher_add_cb, EasyDbus_conn::watcher_closure, and EasyDbus_conn::watcher_remove_cb.
00404 { 00405 struct EasyDbus_core *core = 00406 (struct EasyDbus_core *) conn; 00407 struct EasyDbus_object_box *object = NULL; 00408 struct EasyDbus_watcher *watch = NULL; 00409 struct EasyDbus_Pending *p = NULL; 00410 struct EasyDbus_ext_signal *signal = NULL; 00411 DBusError err; 00412 int ret_val = 0; 00413 int i; 00414 00415 EasyDbusDebug ("Destroy service %s...", 00416 core->service_name ? core-> 00417 service_name : "."); 00418 00419 dbus_error_init (&err); 00420 00421 00422 if (core->n_objs) { 00423 for (i = 0; i < core->n_objs; i++) { 00424 object = core->objects; 00425 core->objects = object->next; 00426 easydbus_object_unregister (conn, &object->core); 00427 easydbus_object_free_skeleton (&object->core); 00428 } 00429 } 00430 00431 /* remove external signals */ 00432 while (core->handled_ext_signals) { 00433 signal = core->handled_ext_signals; 00434 core->handled_ext_signals = signal->next; 00435 easydbus_ext_signal_free_skeleton (signal); 00436 } 00437 00438 if (core->conn != NULL) { 00439 if (core->service_name != NULL) { 00440 if (conn->registered_ondbus) 00441 // dbus_bus_release_name (core->conn, 00442 // core->service_name, &err); 00443 free (core->service_name); 00444 conn->registered_ondbus = 0; 00445 } 00446 00447 for (p = core->pending_msgs; core->pending_msgs; 00448 p = core->pending_msgs) { 00449 core->pending_msgs = p->next; 00450 easydbus_pending_destroy(p); 00451 } 00452 00453 while (core->watcher != NULL) { 00454 watch = core->watcher; 00455 if (conn->watcher_remove_cb && 00456 dbus_watch_get_enabled (core->watcher->watch)) 00457 conn->watcher_remove_cb(core->watcher, 00458 conn->watcher_closure); 00459 core->watcher = core->watcher->next; 00460 free (watch); 00461 } 00462 // use watcher_remove_cb field for detect 00463 // if was watcher. 00464 if (conn->watcher_remove_cb) { 00465 conn->watcher_remove_cb = NULL; 00466 conn->watcher_add_cb = NULL; 00467 // remove watch callbacks. Workaround for resolve problem 00468 // on call of callback when data are invalid. 00469 // (An another solution could be check connection data) 00470 dbus_connection_set_watch_functions (core->conn, 00471 NULL, NULL, NULL, 00472 NULL, NULL); 00473 } 00474 00475 // dbus_connection_remove_filter (core->conn, 00476 // easydbus_core_filter_func, core); 00477 dbus_connection_unref (core->conn); 00478 } 00479 00480 free (core); 00481 dbus_error_free (&err); 00482 00483 return ret_val; 00484 }
int easydbus_conn_disable_filters | ( | EasyDbus_conn * | conn | ) |
Disable filters for objects.
conn | EasyDbus_conn object pointer |
0 ok
Definition at line 164 of file register_obj.c.
References EasyDbus_core::conn, easydbus_core_filter_func(), easydbus_filter_func(), easydbus_introspect_filter_func(), EasyDbusDebug, and EasyDbus_core::handled_introspect.
00165 { 00166 struct EasyDbus_core *core = (struct EasyDbus_core *) conn; 00167 00168 if (!conn) 00169 return -1; 00170 00171 dbus_connection_remove_filter (core->conn, 00172 easydbus_core_filter_func, core); 00173 00174 dbus_connection_remove_filter (core->conn, 00175 easydbus_filter_func, core); 00176 00177 if (core->handled_introspect) 00178 dbus_connection_remove_filter (core->conn, 00179 easydbus_introspect_filter_func, 00180 core); 00181 00182 EasyDbusDebug ("Filters Removed"); 00183 return 0; 00184 }
int easydbus_conn_enable_filters | ( | EasyDbus_conn * | conn | ) |
Enable filters for objects. In particular, this function MUST be called for manage Disconnected signal, reply message on service and for manage external signal object.
conn | EasyDbus_conn object pointer. |
0 ok
add core filter
Definition at line 201 of file register_obj.c.
References EasyDbus_core::conn, easydbus_core_filter_func(), easydbus_filter_func(), easydbus_introspect_filter_func(), EasyDbusDebug, and EasyDbus_core::handled_introspect.
Referenced by easydbus_conn_reconnect().
00202 { 00203 struct EasyDbus_core *core = (struct EasyDbus_core *) conn; 00204 00205 if (!conn) 00206 return -1; 00207 00209 // This solution works only for register object 00210 // not for simple client. See for an another solution. 00211 if (!dbus_connection_add_filter (core->conn, 00212 easydbus_core_filter_func, core, 00213 NULL)) { 00214 EasyDbusDebug ("Error on add core filter"); 00215 return -1; 00216 } 00217 00218 if (core->handled_introspect) 00219 if (!dbus_connection_add_filter (core->conn, 00220 easydbus_introspect_filter_func, 00221 core, NULL)) { 00222 EasyDbusDebug ("Error on add filter"); 00223 return -1; 00224 } 00225 00226 if (!dbus_connection_add_filter (core->conn, 00227 easydbus_filter_func, core, 00228 NULL)) { 00229 EasyDbusDebug ("Error on add filter"); 00230 return -1; 00231 } 00232 00233 EasyDbusDebug ("Filters activated"); 00234 00235 return 0; 00236 }
int easydbus_conn_get_address | ( | EasyDbus_conn * | conn, | |
char * | serviceName, | |||
enum easydbus_bus | bus, | |||
int | flags | |||
) |
Acquire source address.
serviceName | Name of service that must be acquired. | |
bus | bus type. see enum easydbus_bus for more informations. | |
conn | pointer to EasyDbus_conn object. | |
flags | easydbus connection flags. |
EASYDBUS_CONN_NAME_SERVICE_EXISTS name service exists.
EASYDBUS_CONN_NAME_SERVICE_IN_QUEUE name service in queue.
EASYDBUS_CONN_NAME_SERVICE_PRIMARY name service is primary name.
EASYDBUS_CONN_NAME_SERVICE_RENAMED name service is been renamed.
Definition at line 66 of file acquire.c.
References EasyDbus_conn::bus, easydbus_get_address_onsession(), easydbus_get_address_onsystem(), easydbus_get_address_serverSession(), EASYDBUS_SESSION, EASYDBUS_SESSION_SERVER, EASYDBUS_SYSTEM, and EasyDbus_conn::flags.
00069 { 00070 if (serviceName == NULL || conn == NULL) 00071 return -1; 00072 00073 conn->flags = flags; 00074 conn->bus = bus; 00075 switch (bus) { 00076 case EASYDBUS_SESSION: 00077 return 00078 easydbus_get_address_onsession (conn, serviceName); 00079 break; 00080 case EASYDBUS_SYSTEM: 00081 return 00082 easydbus_get_address_onsystem (conn, serviceName); 00083 break; 00084 case EASYDBUS_SESSION_SERVER: 00085 return 00086 easydbus_get_address_serverSession (conn, serviceName); 00087 break; 00088 default: 00089 break; 00090 } 00091 00092 return -1; 00093 }
int easydbus_conn_get_fd | ( | EasyDbus_conn * | data | ) |
Get connection file descriptor of connection.
data | EasyDbus_conn object pointer |
-1 error
Definition at line 600 of file acquire.c.
References EasyDbus_core::conn.
00601 { 00602 struct EasyDbus_core *core = (struct EasyDbus_core *) data; 00603 int fd; 00604 00605 if (data) 00606 //if (dbus_connection_get_fd (core->conn, &fd)) 00607 if (dbus_connection_get_unix_fd (core->conn, &fd)) 00608 return fd; 00609 00610 return -1; 00611 }
int easydbus_conn_get_n_object | ( | EasyDbus_conn * | conn | ) | [inline] |
Get number of objects of EasyDbus_conn connection.
conn | EasyDbus_conn object pointer. |
number of objects managed of service connection.
Definition at line 238 of file acquire.c.
References EasyDbus_core::n_objs.
00239 { 00240 return (conn ? 00241 ((struct EasyDbus_core *) conn)->n_objs : -1); 00242 }
EasyDbus_object* easydbus_conn_get_object | ( | EasyDbus_conn * | conn, | |
unsigned int | n | |||
) |
Get n-EasyDbus_object of connection.
conn | pointer to EasyDbus_conn object. | |
n | number of the object to get. |
pointer to EasyDbus_object.
Definition at line 255 of file acquire.c.
References EasyDbus_core::n_objs, EasyDbus_object_box::next, and EasyDbus_core::objects.
00257 { 00258 int i; 00259 struct EasyDbus_core *core = 00260 (struct EasyDbus_core *) conn; 00261 struct EasyDbus_object_box *ans = NULL; 00262 00263 if (conn && (((int) n) <= core->n_objs)) 00264 for (i = 0, ans = core->objects; 00265 i < core->n_objs; 00266 i++, ans = ans->next); 00267 00268 return (EasyDbus_object *) ans; 00269 }
const char* easydbus_conn_get_service_name | ( | const EasyDbus_conn * | conn | ) |
Get service name.
conn | EasyDbus_conn object pointer. |
Definition at line 584 of file acquire.c.
References EasyDbus_core::service_name.
00585 { 00586 return conn ? (const char *) 00587 ((struct EasyDbus_core *)conn)->service_name : NULL; 00588 }
int easydbus_conn_get_system_service_address | ( | EasyDbus_conn * | data, | |
char * | serviceName | |||
) | [inline] |
Acquire source address from environment variable.
Used for dbus service started by dbus daemon.
data | EasyDbus_conn object pointer | |
serviceName | name of service that must be acquired. |
-1 error
Definition at line 499 of file acquire.c.
References EasyDbus_core::conn, easydbus_save_serviceName(), EasyDbusDebug, and EasyDbus_conn::registered_ondbus.
00501 { 00502 struct EasyDbus_core *core = (struct EasyDbus_core *) data; 00503 char *dbus_starter_address = NULL; 00504 DBusError err; 00505 00506 dbus_error_init (&err); 00507 00508 /* recover DBUS_STARTER_ADDRESS environment variable */ 00509 dbus_starter_address = getenv ("DBUS_STARTER_ADDRESS"); 00510 00511 if (dbus_starter_address == NULL) { 00512 EasyDbusDebug ("Error on recover dbus_starter_address"); 00513 return -1; 00514 } 00515 00516 core->conn = dbus_connection_open (dbus_starter_address, &err); 00517 00518 if (!core->conn) { 00519 EasyDbusDebug ("Error %s from " 00520 "dbus_connection_open: %s", 00521 err.name, err.message); 00522 return -1; 00523 } 00524 00525 /* do not allw libdbus to exit on connection failure ( This 00526 * may around random exit () on SIGPIPE errors) */ 00527 dbus_connection_set_exit_on_disconnect (core->conn, FALSE); 00528 00529 dbus_bus_register (core->conn, &err); 00530 00531 if (dbus_error_is_set (&err)) { 00532 EasyDbusDebug ("Error %s from " 00533 "dbus_bus_register: %s", err.name, err.message); 00534 goto error_acquire; 00535 } 00536 00537 /* TODO: manage return values correctly */ 00538 /* request for set service name */ 00539 dbus_bus_request_name (core->conn, serviceName, 0, &err); 00540 00541 00542 if (dbus_error_is_set (&err)) { 00543 EasyDbusDebug ("Error %s from " 00544 "dbus_bus_request_name: %s", 00545 err.name, err.message); 00546 goto error_acquire; 00547 } 00548 00549 /* see if this is correct and what it do. */ 00550 //if (set_unique_nameID (core, serviceName)) { 00551 // EasyDbusDebug ("Error on set unique nameID"); 00552 // goto error_acquire; 00553 //} 00554 00555 data->registered_ondbus = 1; 00556 00557 if (easydbus_save_serviceName (core, serviceName)) { 00558 EasyDbusDebug ("Error on set unique nameID"); 00559 goto error_acquire; 00560 } 00561 00562 dbus_error_free (&err); 00563 00564 return 0; 00565 00566 error_acquire: 00567 if (data->registered_ondbus) 00568 dbus_bus_release_name (core->conn, serviceName, &err); 00569 00570 if (core->conn != NULL) 00571 dbus_connection_unref (core->conn); 00572 00573 dbus_error_free (&err); 00574 00575 return -1; 00576 }
int easydbus_conn_remove_match_rule | ( | EasyDbus_conn * | data, | |
enum event_type | type, | |||
char * | sender, | |||
char * | interface, | |||
char * | member, | |||
char * | path, | |||
char * | destination | |||
) | [inline] |
Remove match rule on dbus.
data | EasyDbus_conn object pointer | |
type | enum event_type that identify message | |
sender | sender of message. (can be equal to NULL) | |
interface | interface of message (can be equal to NULL) | |
member | member of message (can be equal to NULL) | |
path | path of message (can be equal to NULL) | |
destination | destination of message (can be equal to NULL) |
-1 error
Definition at line 110 of file match_rules.c.
References EasyDbus_core::conn, EasyDbusDebug, and prepare_match_string().
00114 { 00115 DBusError err; 00116 00117 struct EasyDbus_core *core = (struct EasyDbus_core *) data; 00118 char *buffer = NULL; 00119 00120 dbus_error_init (&err); 00121 00122 buffer = prepare_match_string (type, sender, 00123 interface, member, path, 00124 destination); 00125 if (buffer == NULL) 00126 return -1; 00127 00128 EasyDbusDebug ("Remove MATCH_RULE = %s\n", buffer); 00129 00130 dbus_bus_remove_match (core->conn, buffer, &err); 00131 dbus_connection_flush (core->conn); 00132 00133 if (dbus_error_is_set (&err)) { 00134 EasyDbusDebug ("Remove match error (%s)\n", err.message); 00135 dbus_error_free (&err); 00136 free (buffer); 00137 return -1; 00138 } 00139 00140 dbus_error_free (&err); 00141 free (buffer); 00142 return 0; 00143 }
int easydbus_conn_set_error_cb | ( | EasyDbus_conn * | conn, | |
easydbus_error_cb_f | cb, | |||
void * | user_closure | |||
) |
Set user callback for handle error on Dbus connection.
0 ok
Definition at line 218 of file acquire.c.
References EasyDbus_conn::error_cb, and EasyDbus_conn::error_closure.
00221 { 00222 if (!conn || !cb) 00223 return -1; 00224 00225 conn->error_cb = cb; 00226 conn->error_closure = user_closure; 00227 00228 return 0; 00229 }
int easydbus_conn_set_error_message_cb | ( | EasyDbus_conn * | conn, | |
easydbus_error_message_cb_f | e_cb, | |||
void * | user_closure | |||
) |
Set user callback for handle error message not connected to a pending message.
0 ok
Definition at line 298 of file acquire.c.
References EasyDbus_conn::error_message_cb, and EasyDbus_conn::error_message_closure.
00301 { 00302 if (!conn || !e_cb) 00303 return -1; 00304 conn->error_message_cb = e_cb; 00305 conn->error_message_closure = user_closure; 00306 00307 return 0; 00308 }
int easydbus_conn_set_reply_async_cb | ( | EasyDbus_conn * | conn, | |
easydbus_reply_async_cb_f | r_cb, | |||
void * | user_closure | |||
) |
Set user callback for handle reply to asynchronous method call on easydbus_main_loop or through watcher.
0 ok
Definition at line 279 of file acquire.c.
References EasyDbus_conn::reply_async_cb, and EasyDbus_conn::reply_async_closure.
00282 { 00283 if (!conn || !r_cb) 00284 return -1; 00285 conn->reply_async_cb = r_cb; 00286 conn->reply_async_closure = user_closure; 00287 00288 return 0; 00289 }
int easydbus_conn_set_reply_message_cb | ( | EasyDbus_conn * | conn, | |
easydbus_reply_message_cb_f | r_cb | |||
) |
Set user callback for handle reply message connected to a pending message.
0 ok
Definition at line 317 of file acquire.c.
References EasyDbus_conn::reply_message_cb.
00319 { 00320 if (!conn || !r_cb) 00321 return -1; 00322 conn->reply_message_cb = r_cb; 00323 00324 return 0; 00325 }