along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \file ws_manager.c
+ * \brief mDictionary Manager main module code.
+ *
+ * \author Ćukasz Pawlik \<lukasz.pawlik\@comarch.com\>
+ */
+
+/** \addtogroup Manager
+ *
+ */
+/*@{*/
+
#include <ws_manager.h>
#include <ws_mng_searching_threads.h>
/**
- * Public function, see ws_manager.h
+ * \return new instance of WSMngSearchData structure
*/
WSMngSearchData* ws_manager_create() {
g_debug("<--> %s", __FUNCTION__);
}
/**
- * Public function, see ws_manager.h
+ * \param serach_data structure which contains all data of program
+ * \return TRUE if successfully run main loop, FALSE otherwise
*/
gboolean ws_mng_start_main_loop(WSMngSearchData* search_data)
{
return TRUE;
}
-
-
-
/**
- *Public function, see ws_manager.h
+ * \param data structure stores variables which are need to comunicate by D-BUS.
*/
void ws_mng_init_dbus (WSMngSearchData *data)
{
- g_debug("->%s", __FUNCTION__);
-
- if (!g_thread_supported ()) g_thread_init (NULL);
+ g_debug("->%s", __FUNCTION__);
+
+ /* initialize GThread support if it is not initialized yet */
+ if (!g_thread_supported ()) g_thread_init (NULL);
/* create data structure needed to comunicate with dbus wrapper */
- data->dbus_data = ws_dbus_create ("mdictionaryManager", "v1.0");
+ data->dbus_data = ws_dbus_create ("mdictionaryManager", "v1.0");
/* set data used to comunicate with gui */
ws_dbus_config(data->dbus_data,
WS_DBUS_CONFIG_REMOTE_IFACE,
GUI_IFACE);
+ /* defines all methods which could be called through D-Bus */
+ ws_dbus_add_method ( data->dbus_data,
+ "find_word",
+ WS_DBUS_TYPE_STRING,
+ WS_DBUS_TYPE_INVALID );
+ ws_dbus_add_method ( data->dbus_data,
+ "find_translation",
+ WS_DBUS_TYPE_STRING,
+ WS_DBUS_TYPE_INVALID );
+ ws_dbus_add_method ( data->dbus_data,
+ "signal",
+ WS_DBUS_TYPE_SIGNAL,
+ WS_DBUS_TYPE_INVALID );
+ ws_dbus_add_method ( data->dbus_data,
+ "add_bookmark",
+ WS_DBUS_TYPE_STRING,
+ WS_DBUS_TYPE_STRING,
+ WS_DBUS_TYPE_INVALID );
+ ws_dbus_add_method ( data->dbus_data,
+ "remove_bookmark",
+ WS_DBUS_TYPE_STRING,
+ WS_DBUS_TYPE_INVALID );
+ ws_dbus_add_method ( data->dbus_data,
+ "extract_dictionary",
+ WS_DBUS_TYPE_STRING,
+ WS_DBUS_TYPE_INVALID );
- ws_dbus_add_method (data->dbus_data, "find_word", WS_DBUS_TYPE_STRING,
- WS_DBUS_TYPE_INVALID);
-
- ws_dbus_add_method (data->dbus_data, "find_translation",
- WS_DBUS_TYPE_STRING, WS_DBUS_TYPE_INVALID);
-
- ws_dbus_add_method (data->dbus_data, "signal", WS_DBUS_TYPE_SIGNAL,
- WS_DBUS_TYPE_INVALID);
-
- ws_dbus_add_method (data->dbus_data, "add_bookmark",
- WS_DBUS_TYPE_STRING, WS_DBUS_TYPE_STRING,
- WS_DBUS_TYPE_INVALID);
- ws_dbus_add_method (data->dbus_data, "remove_bookmark",
- WS_DBUS_TYPE_STRING, WS_DBUS_TYPE_INVALID);
-
- ws_dbus_add_method (data->dbus_data, "extract_dictionary",
- WS_DBUS_TYPE_STRING, WS_DBUS_TYPE_INVALID);
-
/* set callback for find word signal */
- ws_dbus_set_cb(data->dbus_data,
- "find_word",
- ws_mng_on_search_word,
- data);
+ ws_dbus_set_cb( data->dbus_data,
+ "find_word",
+ ws_mng_on_search_word,
+ data );
/* set callback for find translation signal */
- ws_dbus_set_cb(data->dbus_data,
- "find_translation",
- ws_mng_on_search_translation,
- data);
+ ws_dbus_set_cb( data->dbus_data,
+ "find_translation",
+ ws_mng_on_search_translation,
+ data );
/* set callback for close program signal */
- ws_dbus_set_cb(data->dbus_data,
- "signal",
- ws_mng_signal_handling,
- data);
+ ws_dbus_set_cb( data->dbus_data,
+ "signal",
+ ws_mng_signal_handling,
+ data );
/* set callback for add bookmarks signal */
- ws_dbus_set_cb(data->dbus_data,
- "add_bookmark",
- ws_mng_add_bookmark,
- data);
+ ws_dbus_set_cb( data->dbus_data,
+ "add_bookmark",
+ ws_mng_add_bookmark,
+ data );
/* set callback for remove bookmarks signal */
- ws_dbus_set_cb(data->dbus_data,
- "remove_bookmark",
- ws_mng_remove_bookmark,
- data);
+ ws_dbus_set_cb( data->dbus_data,
+ "remove_bookmark",
+ ws_mng_remove_bookmark,
+ data );
/* set callback for extracting dictionary */
- ws_dbus_set_cb(data->dbus_data,
- "extract_dictionary",
- ws_mng_extract_dictionary,
- data);
+ ws_dbus_set_cb( data->dbus_data,
+ "extract_dictionary",
+ ws_mng_extract_dictionary,
+ data );
+ /* initialize d-bus connection with remote service - UI */
ws_dbus_connect(data->dbus_data);
-
g_debug("<-%s", __FUNCTION__);
}
/**
- *Public fuction, see ws_manager.h
+ *
+ * Fuction loads from modules pointers to functions used to service searching
+ * in dictionaries and stores them in WSMngSearchData structure
+ *
+ * \param data pointer to structure WSMngSearchData which stores variables
+ * needed to service manager
*/
void ws_mng_init (WSMngSearchData *data)
{
- g_debug("->%s", __FUNCTION__);
- data->dict = g_array_new(TRUE, TRUE, sizeof(Engine *));
- data->modules = g_array_new(TRUE, TRUE, sizeof(EngineModule));
- data->libraries = g_array_new(TRUE, TRUE, sizeof(GModule*));
+ g_debug("->%s", __FUNCTION__);
+
+ /* create and initialize all data in WSMngSearchData structure */
+ data->dict = g_array_new(TRUE, TRUE, sizeof(Engine *));
+ data->modules = g_array_new(TRUE, TRUE, sizeof(EngineModule));
+ data->libraries = g_array_new(TRUE, TRUE, sizeof(GModule*));
data->word_list = NULL;
- data->last_search = NULL;
- data->trans = NULL;
- data->search_in_history = FALSE;
+ data->last_search = NULL;
+ data->trans = NULL;
+ data->search_in_history = FALSE;
data->word = NULL;
data->bookmark = NULL;
- data->bookmark_mode = FALSE;
+ data->bookmark_mode = FALSE;
/* added by Dariusz Wiechecki
* mutex initialization */
data->action_working = (GStaticMutex*)g_try_malloc(sizeof(GStaticMutex));
g_static_rec_mutex_init (data->action_stop);
/* initialize static stop_if_needed function mutex*/
stop_if_needed (NULL);
- /* initialize GThread structure */
- //data->action_thread = NULL;
+ /* send signal if there is not proper sqlite library */
#ifdef SQLITE
- if (g_file_test(LIBRARY,
- G_FILE_TEST_EXISTS) == FALSE)
+ if( FALSE == g_file_test(LIBRARY, G_FILE_TEST_EXISTS) )
{
ws_dbus_notify(data->dbus_data, WS_DBUS_LOAD_BOOKMARK_FAILED);
}
#endif
-
- GArray* dict_directory = ws_mng_read_gconf(); //paths to dictionaries
- gint i = 0;
+ /* load GConf configuration */
+ GArray* dict_directory = ws_mng_read_gconf();
data->library_path = ws_mng_get_engines_location();
- //load the engine function
- for (i = 0; i < data->library_path->len; i++)
- {
- gchar* path= g_array_index(data->library_path, gchar*, i);
- GModule* library = g_module_open(path, G_MODULE_BIND_LAZY);
+
+ gint i = 0;
+ for (; i < data->library_path->len; ++i)
+ {
+ gchar* path= g_array_index(data->library_path, gchar*, i);
+ GModule* library = g_module_open(path, G_MODULE_BIND_LAZY);
g_array_append_val(data->libraries, library);
g_debug("%p library pinter %d iter", library, i);
- //g_free(path);
}
- //data->library = g_module_open(library_to_path, G_MODULE_BIND_LAZY);
-
+
+ getting_additional_t get_functions = NULL;
for (i=0; i<data->libraries->len; i++)
{
- getting_additional_t get_functions = NULL;
- //get_functions = NULL;
- //data->library
g_debug("%p", g_array_index(data->libraries, GModule*, i));
- g_module_symbol(g_array_index(data->libraries, GModule*, i),
- GLOBAL_FUNCTIONS_NAME,
- (gpointer)&get_functions);
+ g_module_symbol( g_array_index(data->libraries, GModule*, i),
+ GLOBAL_FUNCTIONS_NAME,
+ (gpointer)&get_functions );
g_debug("%d %p", i, &get_functions);
- if (NULL == get_functions) //check if function was loaded
- {
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_ERROR_ENGINE_NOT_FOUND);
- for (i=0; i<dict_directory->len; i++)
- {
- g_free(g_array_index(dict_directory, gchar*, i));
- }
- g_array_free(dict_directory, TRUE);
- ws_mng_close(data);
- exit(0); //exit program
- }
+
+ /* if function was not properly imported close manager */
+ if (NULL == get_functions)
+ {
+ ws_dbus_notify( data->dbus_data,
+ WS_DBUS_ERROR_ENGINE_NOT_FOUND );
+ for (i=0; i<dict_directory->len; i++)
+ {
+ g_free(g_array_index(dict_directory, gchar*, i));
+ }
+ g_array_free(dict_directory, TRUE);
+ ws_mng_close(data);
+ exit(0);
+ }
+
+ /* get EngineModule struct and append it to the array*/
EngineModule module = get_functions();
- //tmp = (EngineModule*) g_memdup(&module, sizeof(EngineModule));
- //module = (EngineModule**) &tmp;
g_array_append_val(data->modules, module);
-
}
-
+
+ /* load each dictionary */
ws_mng_load_bookmark(data);
if (dict_directory->len > 0)
{
- /*ws_dbus_notify(data->dbus_data, WS_DBUS_INFO_CACHING); */
-
ws_mng_load_dict(dict_directory, data);
guint i = 0;
g_debug("Trace bookmark engine %p", data->bookmark);
for (i=0; i<data->dict->len; i++)
{
- g_debug("dict engines at %p",
- g_array_index(data->dict, Engine*, i));
+ g_debug( "dict engines at %p",
+ g_array_index(data->dict, Engine*, i) );
}
- /*ws_dbus_notify(data->dbus_data,
- WS_DBUS_INFO_CACHING_FINISHED);*/
- }
- else
- {
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_ERROR_FILE_NOT_FOUND);
- }
- for (i=0; i<dict_directory->len; i++)
- {
- g_free(g_array_index(dict_directory, gchar*, i));
+ }
+ else
+ {
+ ws_dbus_notify( data->dbus_data,
+ WS_DBUS_ERROR_FILE_NOT_FOUND );
}
+
+ /* free memory used by dictionaries path array */
+ for (i=0; i<dict_directory->len; i++)
+ {
+ g_free(g_array_index(dict_directory, gchar*, i));
+ }
g_array_free(dict_directory, TRUE);
+
g_debug("<-%s", __FUNCTION__);
}
/**
- *Public function, see ws_manager.h
+ * \param data structure holds pointers to data which need to be freed from
+ * memory
*/
void ws_mng_close (WSMngSearchData *data)
{
- int i = 0;
- g_debug("->%s", __FUNCTION__);
+ int i = 0;
+ g_debug("->%s", __FUNCTION__);
- ws_dbus_destroy (data->dbus_data); // deinitialization of dbus
- if (data->bookmark != NULL)
+ ws_dbus_destroy (data->dbus_data);
+ if (data->bookmark != NULL)
{
dict_eng_destroy(data->bookmark);
}
-
- for (i = 0; i < data->dict->len; i++)
- {
- //free memory taken by engine
- dict_eng_destroy(g_array_index (data->dict, Engine*,i));
- }
- g_array_free(data->dict, TRUE);
-
- /*for (i=0; i<data->word_list->len; i++)
- {
- g_free(g_array_index(data->word_list, gchar*, i));
- }
-
- g_array_free(data->word_list, TRUE);*/
-
- //free memory used by modules
- //g_array_free(data->modules, TRUE);
- //free memory taken by dictionaries
- g_free(data->last_search);
-
- g_free(data->loop);
-
+
+ for (i = 0; i < data->dict->len; i++)
+ {
+ dict_eng_destroy(g_array_index (data->dict, Engine*,i));
+ }
+ g_array_free(data->dict, TRUE);
+
+ g_free(data->last_search);
+ g_free(data->loop);
g_static_mutex_free(data->thread_creation);
g_static_mutex_free(data->action_working);
g_static_rec_mutex_free(data->action_stop);
- /*if (data->word != NULL) g_free(data->word);*/
-
- //if (data->trans != NULL) g_free(data->trans);
-
+
for (i=0; i<data->library_path->len; i++)
- {
- g_free(g_array_index(data->library_path, gchar*, i));
- }
+ {
+ g_free(g_array_index(data->library_path, gchar*, i));
+ }
g_array_free(data->library_path, TRUE);
-
g_array_free(data->modules, TRUE); data->modules = NULL;
for (i=0; i< data->libraries->len; i++)
- {
- if (g_array_index(data->libraries, GModule*, i) != NULL)
- {
- //close library
- g_module_close(g_array_index(data->libraries,
- GModule*, i));
+ {
+ if (g_array_index(data->libraries, GModule*, i) != NULL)
+ {
+ g_module_close(g_array_index( data->libraries,
+ GModule*,
+ i ));
}
-
- }
-
+ }
g_array_free(data->libraries, TRUE);
-
g_free(data);
-
- g_debug("<-%s", __FUNCTION__);
+ g_debug("<-%s", __FUNCTION__);
}
-
+/*@}*/