Files | |
file | ws_dbus.h |
API for D-Bus Wrapper Library. | |
file | ws_services.h |
D-Bus Services and Interfaces names for mDictionary modules. | |
file | ws_dbus.c |
API for D-Bus Wrapper Library - code. | |
Data Structures | |
struct | _WSDBusData |
This structure contains data vital for DBUS communication. More... | |
struct | _WSDBusMethodData |
Functions to be called by client (GUI) | |
#define | ws_dbus_client_find_word(structure, arg) |
Instructs the manager to start search of words matching a given pattern. | |
#define | ws_dbus_client_find_translation(structure, arg) |
Instructs the manager to start search of translations for a specific word. | |
#define | ws_dbus_client_add_bookmark(structure, arg1, arg2) |
Instructs the manager to bookmark a given pair of word, translation. | |
#define | ws_dbus_client_remove_bookmark(structure, arg) |
Instructs the manager to remove the specified bookmark. | |
#define | ws_dbus_client_extract_dictionary(structure, arg) |
Instructs the manager to extract a dictionary from a tar.bz2 archive. | |
Functions to be called by server (thread's manager) | |
#define | ws_dbus_server_return_extracted_dict(structure, arg) |
Informs GUI that a dictionary has been extracted. | |
#define | ws_dbus_server_return_words(structure, arg) |
Returns a list of words to GUI. | |
#define | ws_dbus_server_return_translations(structure, arg) |
Returns to GUI a list of translations for a given word. | |
#define | ws_dbus_server_update_progressbar(structure, arg) |
Updates the search progressbar. | |
Functions to be called by both client and server | |
#define | ws_dbus_notify(structure, arg) |
Sends a predefined signal. | |
D-Bus Services and Interfaces names for mDictionary modules | |
These defines how are called services, remote objects and interfaces in both mDictionary modules. | |
#define | MANAGER_SERVICE "org.maemo.mdictionaryManager" |
Service's name for manager module. | |
#define | MANAGER_OBJECT "/org/maemo/mdictionaryManager" |
Remote object's name for manager module. | |
#define | MANAGER_IFACE "org.maemo.mdictionaryManager" |
Interface's name for manager module. | |
#define | GUI_SERVICE "org.maemo.mdictionaryGui" |
Service's name for GUI module. | |
#define | GUI_OBJECT "/org/maemo/mdictionaryGui" |
Remote object's name for GUI module. | |
#define | GUI_IFACE "org.maemo.mdictionaryGui" |
Interface's name for GUI module. | |
Typedefs | |
typedef void(*) | ws_dbus_cb (GError *error, gpointer data, gpointer user_data) |
Callback function definition. | |
typedef _WSDBusData | WSDBusData |
typedef _WSDBusMethodData | WSDBusMethodData |
Enumerations | |
enum | WSDBusDataType |
An enumeration of data types to be sent via DBUS. More... | |
enum | WSDBusStatus { WS_DBUS_STATUS_OK = 0, WS_DBUS_STATUS_ERROR } |
An enumeration of return values. More... | |
enum | WSDBusNotify { WS_DBUS_INFO_TERMINATE = 1, WS_DBUS_INFO_STOP_SEARCH, WS_DBUS_INFO_SEARCH_FINISHED, WS_DBUS_INFO_CACHING, WS_DBUS_INFO_CACHING_FINISHED, WS_DBUS_INFO_CONFIG_CHANGED, WS_DBUS_ERROR_INVALID_FILE_FORMAT, WS_DBUS_ERROR_FILE_NOT_FOUND, WS_DBUS_ERROR_NO_PERMISSION, WS_DBUS_ERROR_UNKNOWN, WS_DBUS_ERROR_OUT_OF_MEMORY, WS_DBUS_ERROR_ENGINE_NOT_FOUND, WS_DBUS_ERROR_DICTIONARY_NOT_LOAD, WS_DBUS_BOOKMARKS_ADDED_OK, WS_DBUS_BOOKMARKS_REMOVED_OK, WS_DBUS_BOOKMARKS_ADDED_FAIL, WS_DBUS_BOOKMARKS_REMOVED_FAIL, WS_DBUS_LOAD_BOOKMARK_FAILED, WS_DBUS_BOOKMARK_MODE_ON, WS_DBUS_BOOKMARK_MODE_OFF, WS_DBUS_EXTRACT_FILE, WS_DBUS_EXTRACT_FILE_FINISHED, WS_DBUS_WORDS_LIST_STARTED, WS_DBUS_TRANSLATION_STARTED, WS_DBUS_WORDS_LIST_FINISHED, WS_DBUS_TRANSLATION_FINISHED, WS_DBUS_WORDS_LIST_FULL, WS_DBUS_WORDS_LIST_FILLED_NOT_FULL } |
Specifies the possible kinds of event notifications that can be sent via DBus. More... | |
enum | WSDBusConfig |
This structure is used for specifying the field of WSDBusData structure one would like to modify. More... | |
Functions | |
WSDBusData * | ws_dbus_create (gchar *name, gchar *version) |
First function to be called in every program using this wrapper. | |
WSDBusStatus | ws_dbus_config (WSDBusData *ws_dbus_data, WSDBusConfig field, gchar *value) |
This function is used for setting dbus service/client parameters. | |
WSDBusStatus | ws_dbus_connect (WSDBusData *ws_dbus_data) |
Initialize D-BUS communication. | |
void | ws_dbus_destroy (WSDBusData *ws_dbus_data) |
Function deinitializing D-BUS wrapper library. | |
WSDBusStatus | ws_dbus_set_cb (WSDBusData *ws_dbus_data, gchar *detailed_signal, gpointer c_func, gpointer user_data) |
This function is used for setting a callback function for a specific method name. | |
WSDBusStatus | ws_dbus_add_method (WSDBusData *ws_dbus_data, gchar *method,...) |
Function registering a method to be called remotely. | |
WSDBusStatus | ws_dbus_call_method (WSDBusData *ws_dbus_data, gchar *method,...) |
Function deinitializing D-BUS wrapper library. | |
static gchar * | ws_dbus_get_ptr2method (GArray *methods, gchar *name) |
static void | ws_dbus_libosso_errors (osso_return_t result) |
static void | ws_dbus_fill_message (DBusMessage *msg, void *data) |
static WSDBusStatus | ws_dbus_run_cb (WSDBusMethodData *method_data, gpointer data) |
static gint | ws_dbus_cb_handler (const gchar *interface, const gchar *method, GArray *arguments, gpointer data, osso_rpc_t *retval) |
void | ws_dbus_add_remote_methods (GError *error, gpointer data, gpointer user_data) |
WSDBusStatus | ws_dbus_add_garray (GArray *data_bundle, GArray *strings) |
WSDBusStatus | ws_dbus_call_registered_method (WSDBusData *ws_dbus_data, gchar *method,...) |
#define GUI_IFACE "org.maemo.mdictionaryGui" |
Interface's name for GUI module.
Definition at line 67 of file ws_services.h.
Referenced by main(), and ws_mng_init_dbus().
#define GUI_OBJECT "/org/maemo/mdictionaryGui" |
Remote object's name for GUI module.
Definition at line 63 of file ws_services.h.
Referenced by main(), and ws_mng_init_dbus().
#define GUI_SERVICE "org.maemo.mdictionaryGui" |
Service's name for GUI module.
Definition at line 59 of file ws_services.h.
Referenced by main(), and ws_mng_init_dbus().
#define MANAGER_IFACE "org.maemo.mdictionaryManager" |
Interface's name for manager module.
Definition at line 53 of file ws_services.h.
Referenced by main(), and ws_mng_init_dbus().
#define MANAGER_OBJECT "/org/maemo/mdictionaryManager" |
Remote object's name for manager module.
Definition at line 49 of file ws_services.h.
Referenced by main(), and ws_mng_init_dbus().
#define MANAGER_SERVICE "org.maemo.mdictionaryManager" |
Service's name for manager module.
Definition at line 45 of file ws_services.h.
Referenced by main(), and ws_mng_init_dbus().
#define ws_dbus_client_add_bookmark | ( | structure, | |||
arg1, | |||||
arg2 | ) |
Value:
ws_dbus_call_method(structure,\ "add_bookmark",\ WS_DBUS_TYPE_STRING,\ arg1,\ WS_DBUS_TYPE_STRING,\ arg2,\ WS_DBUS_TYPE_INVALID)
Definition at line 329 of file ws_dbus.h.
Referenced by ws_gui_add_bookmark_dialog().
#define ws_dbus_client_extract_dictionary | ( | structure, | |||
arg | ) |
Value:
ws_dbus_call_method(structure,\ "extract_dictionary",\ WS_DBUS_TYPE_STRING,\ arg,\ WS_DBUS_TYPE_INVALID)
Definition at line 349 of file ws_dbus.h.
Referenced by ws_gui_dictionary_loader().
#define ws_dbus_client_find_translation | ( | structure, | |||
arg | ) |
Value:
ws_dbus_call_method(structure,\ "find_translation",\ WS_DBUS_TYPE_STRING,\ arg,\ WS_DBUS_TYPE_INVALID)
Definition at line 320 of file ws_dbus.h.
Referenced by create_and_fill_model(), ws_gui_dbus_return_words(), and ws_gui_view_cursor_changed().
#define ws_dbus_client_find_word | ( | structure, | |||
arg | ) |
Value:
ws_dbus_call_method(structure,\ "find_word",\ WS_DBUS_TYPE_STRING,\ arg,\ WS_DBUS_TYPE_INVALID)
Definition at line 310 of file ws_dbus.h.
Referenced by ws_gui_dictionary_open_bookmark(), ws_gui_dictionary_remove_bookmark(), ws_gui_history_back(), ws_gui_history_next(), ws_gui_popup_search(), ws_gui_remove_bookmark_dialog(), ws_gui_search(), and ws_refresh_search_results().
#define ws_dbus_client_remove_bookmark | ( | structure, | |||
arg | ) |
Value:
ws_dbus_call_method(structure,\ "remove_bookmark",\ WS_DBUS_TYPE_STRING,\ arg,\ WS_DBUS_TYPE_INVALID)
Definition at line 340 of file ws_dbus.h.
Referenced by ws_gui_remove_bookmark_dialog().
#define ws_dbus_notify | ( | structure, | |||
arg | ) |
Value:
ws_dbus_call_method(structure,\ "signal",\ WS_DBUS_TYPE_SIGNAL,\ arg,\ WS_DBUS_TYPE_INVALID)
Definition at line 402 of file ws_dbus.h.
Referenced by main(), stop_if_needed(), ws_gui_dictionary_chooser(), ws_gui_dictionary_close_bookmark(), ws_gui_dictionary_open_bookmark(), ws_gui_dictionary_optimizer(), ws_gui_dictionary_remover(), ws_gui_load_dict(), ws_gui_menu_quit(), ws_gui_on_exit(), ws_gui_search_stop(), ws_mng_add_bookmark(), ws_mng_extract_dictionary(), ws_mng_init(), ws_mng_remove_bookmark(), ws_mng_search_translation(), ws_mng_search_word(), ws_mng_signal_handling(), and ws_remove_multiple_words().
#define ws_dbus_server_return_extracted_dict | ( | structure, | |||
arg | ) |
Value:
ws_dbus_call_method(structure,\ "return_extracted_dict",\ WS_DBUS_TYPE_STRING,\ arg,\ WS_DBUS_TYPE_INVALID)
Definition at line 362 of file ws_dbus.h.
Referenced by ws_mng_extract_dictionary().
#define ws_dbus_server_return_translations | ( | structure, | |||
arg | ) |
Value:
ws_dbus_call_method(structure,\ "return_translations",\ WS_DBUS_TYPE_STRING,\ arg,\ WS_DBUS_TYPE_INVALID)
#define ws_dbus_server_return_words | ( | structure, | |||
arg | ) |
Value:
ws_dbus_call_method(structure,\ "return_words",\ WS_DBUS_TYPE_GARRAY,\ arg,\ WS_DBUS_TYPE_INVALID)
#define ws_dbus_server_update_progressbar | ( | structure, | |||
arg | ) |
Value:
ws_dbus_call_method(structure,\ "update_progressbar",\ WS_DBUS_TYPE_DOUBLE,\ arg,\ WS_DBUS_TYPE_INVALID)
Definition at line 389 of file ws_dbus.h.
Referenced by ws_mng_progress_bar().
typedef void(* ) ws_dbus_cb(GError *error, gpointer data, gpointer user_data) |
Callback function definition.
error | - pointer to a GError structure. Currently not used | |
data | - GArray of osso_rpc_t structures containing sent data | |
user_data | - data passed by user while setting the callback function with ws_dbus_set_cb |
enum WSDBusConfig |
This structure is used for specifying the field of WSDBusData structure one would like to modify.
It is used in the ws_dbus_config function. Its main purpose is to clarify D-BUS configuration.
Definition at line 197 of file ws_dbus.h.
00198 { 00199 WS_DBUS_CONFIG_SERVICE = 1, 00200 WS_DBUS_CONFIG_OBJECT, 00201 WS_DBUS_CONFIG_IFACE, 00202 WS_DBUS_CONFIG_REMOTE_SERVICE, 00203 WS_DBUS_CONFIG_REMOTE_OBJECT, 00204 WS_DBUS_CONFIG_REMOTE_IFACE 00205 } WSDBusConfig;
enum WSDBusDataType |
An enumeration of data types to be sent via DBUS.
Definition at line 60 of file ws_dbus.h.
00061 { 00062 WS_DBUS_TYPE_STRING = DBUS_TYPE_STRING, 00063 WS_DBUS_TYPE_INT = DBUS_TYPE_INT32, 00064 WS_DBUS_TYPE_UINT = DBUS_TYPE_UINT32, 00065 WS_DBUS_TYPE_BOOLEAN = DBUS_TYPE_BOOLEAN, 00066 WS_DBUS_TYPE_DOUBLE = DBUS_TYPE_DOUBLE, 00067 WS_DBUS_TYPE_INVALID = DBUS_TYPE_INVALID, 00068 WS_DBUS_TYPE_GARRAY = ((int) 'a'), 00069 WS_DBUS_TYPE_SIGNAL = DBUS_TYPE_INT32 00070 } WSDBusDataType;
enum WSDBusNotify |
Specifies the possible kinds of event notifications that can be sent via DBus.
Definition at line 123 of file ws_dbus.h.
00124 { 00125 WS_DBUS_INFO_TERMINATE = 1, 00127 WS_DBUS_INFO_STOP_SEARCH, 00129 WS_DBUS_INFO_SEARCH_FINISHED, 00133 WS_DBUS_INFO_CACHING, 00135 WS_DBUS_INFO_CACHING_FINISHED, 00137 WS_DBUS_INFO_CONFIG_CHANGED, 00141 WS_DBUS_ERROR_INVALID_FILE_FORMAT, 00143 WS_DBUS_ERROR_FILE_NOT_FOUND, 00145 WS_DBUS_ERROR_NO_PERMISSION, 00147 WS_DBUS_ERROR_UNKNOWN, 00149 WS_DBUS_ERROR_OUT_OF_MEMORY, 00151 WS_DBUS_ERROR_ENGINE_NOT_FOUND, 00154 WS_DBUS_ERROR_DICTIONARY_NOT_LOAD, 00158 WS_DBUS_BOOKMARKS_ADDED_OK, 00160 WS_DBUS_BOOKMARKS_REMOVED_OK, 00162 WS_DBUS_BOOKMARKS_ADDED_FAIL, 00164 WS_DBUS_BOOKMARKS_REMOVED_FAIL, 00166 WS_DBUS_LOAD_BOOKMARK_FAILED, 00168 WS_DBUS_BOOKMARK_MODE_ON, 00170 WS_DBUS_BOOKMARK_MODE_OFF, 00172 WS_DBUS_EXTRACT_FILE, 00174 WS_DBUS_EXTRACT_FILE_FINISHED, 00176 WS_DBUS_WORDS_LIST_STARTED, 00178 WS_DBUS_TRANSLATION_STARTED, 00180 WS_DBUS_WORDS_LIST_FINISHED, 00182 WS_DBUS_TRANSLATION_FINISHED, 00184 WS_DBUS_WORDS_LIST_FULL, 00186 WS_DBUS_WORDS_LIST_FILLED_NOT_FULL 00188 } WSDBusNotify;
enum WSDBusStatus |
An enumeration of return values.
Definition at line 112 of file ws_dbus.h.
00113 { 00114 WS_DBUS_STATUS_OK = 0, 00116 WS_DBUS_STATUS_ERROR 00118 } WSDBusStatus;
WSDBusStatus ws_dbus_add_garray | ( | GArray * | data_bundle, | |
GArray * | strings | |||
) |
Converts an array of strings to an array of osso_rpc_t which is necessary then sending data via DBUS
data_bundle | - a preallocated GArray of osso_rpc_t | |
strings | - a GArray of strings to be converted |
Definition at line 590 of file ws_dbus.c.
References WS_DBUS_STATUS_ERROR, and WS_DBUS_STATUS_OK.
Referenced by ws_dbus_call_method().
00591 { 00592 osso_rpc_t *temp; 00593 guint i; 00594 00595 if (strings != NULL) 00596 { 00597 for (i = 0; i < strings->len; ++i) 00598 { 00599 temp = g_try_malloc (sizeof (osso_rpc_t)); 00600 temp->type = WS_DBUS_TYPE_STRING; 00601 temp->value.s = g_array_index (strings, gchar *, i); 00602 g_debug ("%d, %s", temp->type, temp->value.s); 00603 g_array_append_val (data_bundle, temp); 00604 }; 00605 return WS_DBUS_STATUS_OK; 00606 } 00607 else 00608 { 00609 printf ("\n%s - Error - GArray is NULL", __FUNCTION__); 00610 return WS_DBUS_STATUS_ERROR; 00611 }; 00612 };
WSDBusStatus ws_dbus_add_method | ( | WSDBusData * | ws_dbus_data, | |
gchar * | method, | |||
... | ||||
) |
Function registering a method to be called remotely.
ws_dbus_data | - pointer to a structure uniquely identifying the application for DBus | |
method | - method name | |
arglist | - a comma separated list of method's arguments (actually just their datatypes) finished with WS_DBUS_TYPE_INVALID |
Definition at line 526 of file ws_dbus.c.
References _WSDBusMethodData::data_types, _WSDBusMethodData::id, _WSDBusData::method_data, _WSDBusMethodData::name, WS_DBUS_STATUS_ERROR, and WS_DBUS_STATUS_OK.
Referenced by main(), and ws_mng_init_dbus().
00527 { 00528 WSDBusMethodData *method_data; 00529 WSDBusDataType data_type; 00530 GQuark temp; 00531 gchar *buffer; 00532 va_list arglist; 00533 00534 /* Check if a unique GQuark id exists for a given string */ 00535 temp = g_quark_try_string (method); 00536 00537 if (temp != 0) 00538 { 00539 g_debug( "DBUS:\"%s\"- method has already been registered\n", 00540 method ); 00541 return WS_DBUS_STATUS_ERROR; 00542 } 00543 00544 method_data = g_try_malloc (sizeof (WSDBusMethodData)); 00545 if (method_data != NULL) 00546 { 00547 va_start (arglist, method); 00548 00549 method_data->id = g_quark_from_string (method); 00550 method_data->name = g_strdup (method); 00551 data_type = va_arg (arglist, WSDBusDataType); 00552 method_data->data_types = g_strdup(""); 00553 00554 /* Add all datatypes in arglist as arguments to method */ 00555 while (data_type != WS_DBUS_TYPE_INVALID) 00556 { 00557 buffer = method_data->data_types; 00558 00559 method_data->data_types = 00560 g_strdup_printf( "%s%c", 00561 method_data->data_types, 00562 (gchar) data_type ); 00563 g_free (buffer); 00564 data_type = va_arg (arglist, WSDBusDataType); 00565 }; 00566 00567 g_debug( "%d, %s, %s\n", 00568 method_data->id, 00569 method_data->name, 00570 method_data->data_types ); 00571 va_end (arglist); 00572 g_array_append_val( ws_dbus_data->method_data, 00573 method_data ); 00574 } 00575 else 00576 { 00577 g_debug( "DBUS: Failed to allocate memory for method data"); 00578 return WS_DBUS_STATUS_ERROR; 00579 } 00580 00581 return WS_DBUS_STATUS_OK; 00582 };
void ws_dbus_add_remote_methods | ( | GError * | error, | |
gpointer | data, | |||
gpointer | user_data | |||
) |
Function will be used in future version of dbus wrapper library, as soon as introspection is implemented
error | - a GError error | |
data | - a GArray of methods (listed in a string form) | |
user_data | - a pointer WSDBusData structure |
Definition at line 256 of file ws_dbus.c.
References _WSDBusData::remote_method_data.
00259 { 00260 WSDBusData *ws_dbus_data = (WSDBusData *) user_data; 00261 GArray *methods_list = (GArray *) data; 00262 guint i=0; 00263 00264 osso_rpc_t *temp; 00265 00266 for (i = 0; i < methods_list->len; ++i) 00267 { 00268 temp = g_array_index (methods_list, osso_rpc_t *, i); 00269 g_array_append_val( ws_dbus_data->remote_method_data, 00270 temp->value ); 00271 }; 00272 00273 return; 00274 };
WSDBusStatus ws_dbus_call_method | ( | WSDBusData * | ws_dbus_data, | |
gchar * | method, | |||
... | ||||
) |
Function deinitializing D-BUS wrapper library.
Runs a remote method with specific name
ws_dbus_data | - pointer to a structure uniquely identifying the application for DBus | |
method | - method name | |
arglist | - a comma separated list of pairs: datatype, value finished with WS_DBUS_TYPE_INVALID |
Definition at line 624 of file ws_dbus.c.
References _WSDBusData::context, _WSDBusData::remote_iface, _WSDBusData::remote_object, _WSDBusData::remote_service, ws_dbus_add_garray(), ws_dbus_fill_message(), ws_dbus_libosso_errors(), WS_DBUS_STATUS_ERROR, and WS_DBUS_STATUS_OK.
00625 { 00626 va_list arglist; 00627 GArray *data_to_send; 00628 osso_rpc_t *temp, *retval; 00629 osso_return_t result; 00630 GArray *temp_garray; 00631 00632 data_to_send = g_array_new (TRUE, TRUE, sizeof (osso_rpc_t *)); 00633 va_start (arglist, method); 00634 00635 /* convert all given arguments to a GArray of osso_rpc_t */ 00636 while (TRUE) 00637 { 00638 temp = g_try_malloc (sizeof (osso_rpc_t)); 00639 temp->type = va_arg (arglist, WSDBusDataType); 00640 /* g_debug ("Type: %c ", temp->type); */ 00641 if (temp->type == WS_DBUS_TYPE_INVALID) 00642 { 00643 break; 00644 } 00645 00646 switch (temp->type) 00647 { 00648 case WS_DBUS_TYPE_STRING: 00649 temp->value.s = va_arg (arglist, gchar *); 00650 g_debug ("Value: %s\n", temp->value.s); 00651 break; 00652 case WS_DBUS_TYPE_INT: 00653 temp->value.i = va_arg (arglist, gint); 00654 g_debug ("Value: %d\n", temp->value.i); 00655 break; 00656 case WS_DBUS_TYPE_UINT: 00657 temp->value.u = va_arg (arglist, guint); 00658 g_debug ("Value: %d\n", temp->value.u); 00659 break; 00660 case WS_DBUS_TYPE_DOUBLE: 00661 temp->value.d = va_arg (arglist, gdouble); 00662 g_debug ("Value: %f\n", temp->value.d); 00663 break; 00664 case WS_DBUS_TYPE_BOOLEAN: 00665 temp->value.b = va_arg (arglist, gboolean); 00666 g_debug ("Value: %d\n", temp->value.b); 00667 break; 00668 case WS_DBUS_TYPE_GARRAY: 00669 temp_garray = va_arg (arglist, GArray *); 00670 ws_dbus_add_garray (data_to_send, 00671 temp_garray); 00672 g_debug ("Value: GArray of strings"); 00673 break; 00674 }; 00675 g_debug ("Type: %c %d", temp->type, temp->value.i); 00676 00677 if (temp->type != WS_DBUS_TYPE_GARRAY) 00678 { 00679 g_array_append_val (data_to_send, temp); 00680 } 00681 }; 00682 00683 va_end (arglist); 00684 g_debug( "%s, method %s, added %d arguments", 00685 __FUNCTION__, 00686 method, data_to_send->len); 00687 00688 /* allocate memory for return value */ 00689 retval = g_try_malloc (sizeof (osso_rpc_t)); 00690 if (retval == NULL) 00691 { 00692 g_debug("DBUS: Error in function %s:",__FUNCTION__); 00693 g_debug("Couldn't allocate memory for message return value\n"); 00694 }; 00695 00696 result = osso_rpc_run_with_argfill (ws_dbus_data->context, 00697 ws_dbus_data->remote_service, 00698 ws_dbus_data->remote_object, 00699 ws_dbus_data->remote_iface, 00700 method, 00701 retval, 00702 ws_dbus_fill_message, 00703 data_to_send); 00704 00705 g_debug ("\nDBUS: %s: ", __FUNCTION__); 00706 ws_dbus_libosso_errors (result); 00707 00708 guint i; 00709 for (i = 0; i < data_to_send->len; ++i) 00710 { 00711 g_free (g_array_index(data_to_send, osso_rpc_t*,i)); 00712 }; 00713 00714 g_array_free (data_to_send, TRUE); 00715 if (result != OSSO_OK) 00716 { 00717 g_debug ("Error message: %s\n", retval->value.s); 00718 osso_rpc_free_val (retval); 00719 g_free (retval); 00720 return WS_DBUS_STATUS_ERROR; 00721 }; 00722 00723 osso_rpc_free_val (retval); 00724 g_free (retval); 00725 return WS_DBUS_STATUS_OK; 00726 };
WSDBusStatus ws_dbus_call_registered_method | ( | WSDBusData * | ws_dbus_data, | |
gchar * | method, | |||
... | ||||
) |
This function will be used in future version of DBUS as soon as introspection is implemented
Definition at line 731 of file ws_dbus.c.
References _WSDBusData::context, _WSDBusMethodData::data_types, _WSDBusData::remote_iface, _WSDBusData::remote_method_data, _WSDBusData::remote_object, _WSDBusData::remote_service, ws_dbus_fill_message(), ws_dbus_get_ptr2method(), ws_dbus_libosso_errors(), WS_DBUS_STATUS_ERROR, and WS_DBUS_STATUS_OK.
00733 { 00734 va_list arglist; 00735 guint i; 00736 GArray *data_to_send; 00737 osso_rpc_t *temp; 00738 osso_return_t result; 00739 osso_rpc_t *retval; 00740 00741 gchar* data_types = ws_dbus_get_ptr2method ( 00742 ws_dbus_data->remote_method_data, 00743 method ); 00744 g_debug ("\n%s\n", data_types); 00745 00746 data_to_send = g_array_new (TRUE, TRUE, sizeof (osso_rpc_t *)); 00747 00748 va_start (arglist, method); 00749 00750 for (i = 0; i < strlen (data_types); ++i) 00751 { 00752 temp = g_try_malloc (sizeof (osso_rpc_t)); 00753 00754 switch ((char) data_types[i]) 00755 { 00756 case WS_DBUS_TYPE_STRING: 00757 temp->value.s = va_arg (arglist, gchar *); 00758 break; 00759 case WS_DBUS_TYPE_INT: 00760 temp->value.i = va_arg (arglist, gint); 00761 break; 00762 case WS_DBUS_TYPE_UINT: 00763 temp->value.u = va_arg (arglist, guint); 00764 break; 00765 case WS_DBUS_TYPE_DOUBLE: 00766 temp->value.d = va_arg (arglist, gdouble); 00767 break; 00768 case WS_DBUS_TYPE_BOOLEAN: 00769 temp->value.b = va_arg (arglist, gboolean); 00770 break; 00771 }; 00772 g_array_append_val (data_to_send, temp); 00773 }; 00774 va_end (arglist); 00775 00776 retval = g_try_malloc (sizeof (osso_rpc_t)); 00777 00778 if (retval == NULL) 00779 { 00780 g_debug("DBUS: Error in function %s:",__FUNCTION__); 00781 g_debug("Couldn't allocate memory for message return value\n"); 00782 }; 00783 00784 result = osso_rpc_run_with_argfill (ws_dbus_data->context, 00785 ws_dbus_data->remote_service, 00786 ws_dbus_data->remote_object, 00787 ws_dbus_data->remote_iface, 00788 method, 00789 retval, 00790 ws_dbus_fill_message, 00791 data_to_send); 00792 g_debug ("\nDBUS: %s: ", __FUNCTION__); 00793 00794 ws_dbus_libosso_errors (result); 00795 00796 if (result != OSSO_OK) 00797 { 00798 g_debug ("Error message: %s\n", retval->value.s); 00799 osso_rpc_free_val (retval); 00800 g_free (retval); 00801 return WS_DBUS_STATUS_ERROR; 00802 }; 00803 00804 osso_rpc_free_val (retval); 00805 g_free (retval); 00806 return WS_DBUS_STATUS_OK; 00807 };
WSDBusStatus ws_dbus_config | ( | WSDBusData * | ws_dbus_data, | |
WSDBusConfig | field, | |||
gchar * | value | |||
) |
This function is used for setting dbus service/client parameters.
Setting DBUS wrapper configuration.
ws_dbus_data | - pointer to a structure uniquely identifying the application for DBus. The possible values of this parameter are listed here: WSDBusConfig | |
field | - the name of the variable, this function is supposed to set. | |
value | - the value of the variable |
Definition at line 319 of file ws_dbus.c.
References _WSDBusData::iface, _WSDBusData::object, _WSDBusData::remote_iface, _WSDBusData::remote_object, _WSDBusData::remote_service, _WSDBusData::service, WS_DBUS_STATUS_ERROR, and WS_DBUS_STATUS_OK.
Referenced by main(), and ws_mng_init_dbus().
00322 { 00323 if (ws_dbus_data == NULL) 00324 { 00325 g_debug ("DBUS: Error in function %s - ws_dbus_data is NULL\n", 00326 __FUNCTION__); 00327 return WS_DBUS_STATUS_ERROR; 00328 }; 00329 00330 switch (field) 00331 { 00332 case WS_DBUS_CONFIG_SERVICE : 00333 ws_dbus_data->service = g_strconcat(value, NULL); 00334 break; 00335 case WS_DBUS_CONFIG_OBJECT : 00336 ws_dbus_data->object = g_strconcat(value, NULL); 00337 break; 00338 case WS_DBUS_CONFIG_IFACE : 00339 ws_dbus_data->iface = g_strconcat(value, NULL); 00340 break; 00341 case WS_DBUS_CONFIG_REMOTE_SERVICE : 00342 ws_dbus_data->remote_service = g_strconcat(value, NULL); 00343 break; 00344 case WS_DBUS_CONFIG_REMOTE_OBJECT : 00345 ws_dbus_data->remote_object = g_strconcat(value, NULL); 00346 break; 00347 case WS_DBUS_CONFIG_REMOTE_IFACE : 00348 ws_dbus_data->remote_iface = g_strconcat(value, NULL); 00349 break; 00350 }; 00351 00352 return WS_DBUS_STATUS_OK; 00353 };
WSDBusStatus ws_dbus_connect | ( | WSDBusData * | ws_dbus_data | ) |
Initialize D-BUS communication.
It should be the called after ws_dbus_create and after setting all DBUS parameters with the ws_dbus_config function. The structure it returns is necessary to call every function implemented in this wrapper library.
ws_dbus_data | - it's a structure containing the unique paths to objects and interfaces to be registered in the DBus session daemon |
Definition at line 365 of file ws_dbus.c.
References _WSDBusData::context, _WSDBusData::iface, _WSDBusData::method_data, _WSDBusData::name, _WSDBusData::object, _WSDBusData::service, _WSDBusData::version, ws_dbus_cb_handler(), WS_DBUS_STATUS_ERROR, and WS_DBUS_STATUS_OK.
Referenced by main(), and ws_mng_init_dbus().
00366 { 00367 osso_return_t result; 00368 /* initialize osso_rpc */ 00369 ws_dbus_data->context = osso_initialize (ws_dbus_data->name, 00370 ws_dbus_data->version, 00371 FALSE, 00372 NULL); 00373 osso_rpc_set_timeout (ws_dbus_data->context, 100); 00374 00375 /* set a dispatcher function which runs local methods when asked via 00376 * DBUS */ 00377 result = osso_rpc_set_cb_f(ws_dbus_data->context, 00378 ws_dbus_data->service, 00379 ws_dbus_data->object, 00380 ws_dbus_data->iface, 00381 ws_dbus_cb_handler, 00382 ws_dbus_data->method_data); 00383 00384 g_debug ("\nSending method data\n"); 00385 /*sends methods list to remote receiver 00386 * ws_dbus_send_method_data (ws_dbus_data); */ 00387 00388 if (result == OSSO_OK) 00389 { 00390 return WS_DBUS_STATUS_OK; 00391 } 00392 else 00393 { 00394 return WS_DBUS_STATUS_ERROR; 00395 } 00396 };
WSDBusData * ws_dbus_create | ( | gchar * | name, | |
gchar * | version | |||
) |
First function to be called in every program using this wrapper.
This function is used for allocating memory for the WSDBusData structure and setting some basic parameters.
name | - name of the application | |
version | - app's version |
Definition at line 283 of file ws_dbus.c.
References _WSDBusData::method_data, _WSDBusData::name, and _WSDBusData::version.
Referenced by main(), and ws_mng_init_dbus().
00284 { 00285 WSDBusData *temp; 00286 temp = (gpointer) g_try_malloc (sizeof (WSDBusData)); 00287 g_debug ("\nDBUS: "); 00288 00289 if (temp == NULL) 00290 { 00291 g_debug ("Error in function %s - cannot allocate memory\n", 00292 __FUNCTION__); 00293 g_assert_not_reached(); 00294 } 00295 else 00296 { 00297 g_debug ("Memory allocation successful\n"); 00298 } 00299 00300 temp->name = g_strconcat (name, NULL); 00301 temp->version = g_strconcat (version, NULL); 00302 00303 temp->method_data = g_array_new( TRUE, 00304 TRUE, 00305 sizeof(WSDBusMethodData *) ); 00306 return temp; 00307 };
void ws_dbus_destroy | ( | WSDBusData * | ws_dbus_data | ) |
Function deinitializing D-BUS wrapper library.
Before the program exits, all memory allocated by DBUS wrapper should be freed.
ws_dbus_data | - pointer to a structure uniquely identifying the application for DBus |
Definition at line 404 of file ws_dbus.c.
References _WSDBusData::context, _WSDBusData::iface, _WSDBusData::method_data, _WSDBusData::name, _WSDBusData::object, _WSDBusData::remote_iface, _WSDBusData::remote_object, _WSDBusData::remote_service, _WSDBusData::service, and _WSDBusData::version.
Referenced by ws_gui_menu_quit(), ws_gui_on_exit(), and ws_mng_close().
00405 { 00406 guint i; 00407 00408 if (ws_dbus_data == NULL) 00409 { 00410 g_debug ("DBUS: Error in fun %s - cannot free osso_context\n", 00411 __FUNCTION__); 00412 g_free (ws_dbus_data); 00413 g_assert_not_reached(); 00414 }; 00415 00416 g_debug( "DBUS deinitialization by %s:\n---------------------------\n", 00417 ws_dbus_data->service); 00418 osso_deinitialize (ws_dbus_data->context); 00419 g_debug ("| Deinitializing osso context |\n"); 00420 if (ws_dbus_data->method_data != NULL) 00421 { 00422 for (i = 0; i < ws_dbus_data->method_data->len; ++i) 00423 { 00424 WSDBusMethodData *temp = 00425 g_array_index(ws_dbus_data->method_data, 00426 WSDBusMethodData *, i); 00427 g_free (temp->data_types); 00428 g_free (temp->name); 00429 g_free (temp); 00430 }; 00431 00432 g_array_free (ws_dbus_data->method_data, TRUE); 00433 g_debug ("| Freeing callback pointers list |\n"); 00434 }; 00435 00436 g_free (ws_dbus_data->name); 00437 g_free (ws_dbus_data->version); 00438 g_free (ws_dbus_data->service); 00439 g_free (ws_dbus_data->object); 00440 g_free (ws_dbus_data->iface); 00441 00442 g_free (ws_dbus_data->remote_service); 00443 g_free (ws_dbus_data->remote_object); 00444 g_free (ws_dbus_data->remote_iface); 00445 00446 /* Introspection not implemented yet. This piece of code will be used 00447 *in future version.*/ 00448 /* if (ws_dbus_data->remote_method_data != NULL) 00449 * { 00450 * for (i = 0; i < ws_dbus_data->remote_method_data->len; ++i) 00451 * { 00452 * g_free (g_array_index(ws_dbus_data->remote_method_data, 00453 * gchar*, i)); 00454 * }; 00455 * g_array_free (ws_dbus_data->remote_method_data, TRUE); 00456 * }; 00457 */ 00458 00459 g_free (ws_dbus_data); 00460 g_debug ("| Freeing WSDBusData structure |\n----------------------\n"); 00461 };
static void ws_dbus_fill_message | ( | DBusMessage * | msg, | |
void * | data | |||
) | [static] |
This function adds words stored in a GArray as arguments to a DBUS message
msg | - DBusMessage structure | |
data | - GArray of osso_rpc_t containing arguments and its types |
Definition at line 191 of file ws_dbus.c.
Referenced by ws_dbus_call_method(), and ws_dbus_call_registered_method().
00192 { 00193 guint i; 00194 osso_rpc_t *data_unit; 00195 GArray *data_bundle; 00196 gpointer buffer; 00197 00198 data_bundle = (GArray *) data; 00199 00200 g_debug ("%s, number of fields: %d", __FUNCTION__, data_bundle->len); 00201 00202 if (data_bundle->len > 255) 00203 { 00204 g_debug ("DBUS: Number of fields in message exceeds 255\n"); 00205 } 00206 00207 for (i = 0; ((i < data_bundle->len) && (i < 255)); ++i) 00208 { 00209 data_unit = g_array_index (data_bundle, osso_rpc_t *, i); 00210 g_debug ("%s, type: %c, value: ", __FUNCTION__, data_unit->type); 00211 00212 switch (data_unit->type) 00213 { 00214 case DBUS_TYPE_STRING: 00215 buffer = &data_unit->value.s; 00216 g_debug ("%s", data_unit->value.s); 00217 break; 00218 case DBUS_TYPE_INT32: 00219 buffer = &data_unit->value.i; 00220 g_debug ("%d", data_unit->value.i); 00221 break; 00222 case DBUS_TYPE_DOUBLE: 00223 buffer = &data_unit->value.d; 00224 g_debug ("%f", data_unit->value.d); 00225 break; 00226 case DBUS_TYPE_BOOLEAN: 00227 buffer = &data_unit->value.b; 00228 g_debug ("%d", data_unit->value.b); 00229 break; 00230 }; 00231 00232 if (data_unit->value.s != NULL) { 00233 dbus_message_append_args( msg, 00234 data_unit->type, 00235 buffer, 00236 DBUS_TYPE_INVALID ); 00237 } 00238 else 00239 { 00240 if (data_bundle->len > 1) 00241 { 00242 g_debug ("One argument ommited"); 00243 } 00244 } 00245 }; 00246 00247 g_debug ("DBUS: Added %d words\n", i); 00248 };
static gchar * ws_dbus_get_ptr2method | ( | GArray * | methods, | |
gchar * | name | |||
) | [static] |
This function will be used in future version of DBUS as soon as introspection is implemented
Definition at line 53 of file ws_dbus.c.
Referenced by ws_dbus_call_registered_method().
00054 { 00055 guint i; 00056 gchar* temp; 00057 00058 g_debug ("%d", methods->len); 00059 00060 return NULL; 00061 00062 for (i = 0; i < methods->len; i+=2) 00063 { 00064 temp = g_array_index (methods, gchar *,i); 00065 00066 if (strcmp (name, temp) == 0) { 00067 temp = g_array_index (methods, gchar *,i+1); 00068 g_debug ("\nData types: %s\n", temp); 00069 return temp; 00070 } 00071 }; 00072 00073 return NULL; 00074 };
WSDBusStatus ws_dbus_set_cb | ( | WSDBusData * | ws_dbus_data, | |
gchar * | method, | |||
gpointer | c_func, | |||
gpointer | user_data | |||
) |
This function is used for setting a callback function for a specific method name.
ws_dbus_data | - pointer to a structure uniquely identifying the application for D-BUS | |
detailed_signal | - string containing the signal name which will trigger the function passed in the c_func parameter. | |
c_func | - is a pointer to the signal handling function. | |
user_data | - is the data passed directly to the signal handling function |
Definition at line 474 of file ws_dbus.c.
References _WSDBusMethodData::handler, _WSDBusMethodData::id, _WSDBusData::method_data, _WSDBusMethodData::user_data, and WS_DBUS_STATUS_ERROR.
Referenced by main(), and ws_mng_init_dbus().
00478 { 00479 WSDBusMethodData *method_data; 00480 GQuark temp; 00481 guint i; 00482 00483 /* check if a unique GQuark id for this method has been generated */ 00484 temp = g_quark_try_string (method); 00485 00486 if (temp == 0) 00487 { 00488 g_debug ("DBUS:%s- method not defined or invalid method name\n", 00489 method); 00490 return WS_DBUS_STATUS_ERROR; 00491 } 00492 else 00493 { 00494 for (i = 0; i < ws_dbus_data->method_data->len; ++i) 00495 { 00496 method_data = g_array_index (ws_dbus_data->method_data, 00497 WSDBusMethodData *, 00498 i); 00499 00500 /* Add method data (callback pointer and data) for a 00501 * given method */ 00502 if (method_data->id == temp) 00503 { 00504 method_data->handler = c_func; 00505 method_data->user_data = user_data; 00506 g_array_insert_val(ws_dbus_data->method_data, 00507 i, method_data); 00508 g_array_remove_index (ws_dbus_data->method_data, 00509 i+1); 00510 }; 00511 }; 00512 }; 00513 00514 /* ws_dbus_send_method_data (ws_dbus_data); */ 00515 return WS_DBUS_STATUS_OK; 00516 };