2 This library is free software; you can redistribute it and/or
3 modify it under the terms of the GNU Lesser General Public
4 License as published by the Free Software Foundation;
5 version 2.1 of the License.
7 This library is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 Lesser General Public License for more details.
12 You should have received a copy of the GNU Lesser General Public
13 License along with this library; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 Copyright 2006 ComArch S.A.
28 typedef struct _WSDBusCBData WSDBusCBData;
31 static void ws_dbus_fill_message (DBusMessage *msg, void *data)
38 temp = (GArray *) data;
40 for (i=0;((i<temp->len) && (i<250));++i)
42 buffer = g_array_index (temp, gchar *, i);
43 dbus_message_append_args (msg,
44 DBUS_TYPE_STRING, &buffer,
47 g_debug ("DBUS: Added %d words\n", i);
51 static gint ws_dbus_cb_handler (const gchar * interface,
63 dbus_cb_data = (GArray *) data;
67 g_debug ("DBUS: Method: %s\n", method);
69 temp = g_quark_try_string (method);
75 cb_data = g_array_index (dbus_cb_data, WSDBusCBData, temp-1);
77 if (cb_data.id == temp)
79 cb = (ws_dbus_cb) cb_data.handler;
80 tmp = cb_data.user_data;
87 for (i=0; i < dbus_cb_data->len; ++i)
89 cb_data = g_array_index (dbus_cb_data,
92 if (cb_data.id == temp)
94 cb = (ws_dbus_cb) cb_data.handler;
95 tmp = cb_data.user_data;
103 g_debug ("Error in function %s, couldn't find the signal %s\n",
111 g_debug ("\nDBUS: Running callback for %s\n", method);
112 cb (NULL, arguments, tmp);
113 retval = DBUS_TYPE_INVALID;
118 g_debug ("DBUS: No callback defined for this function\n");
125 static void ws_dbus_libosso_errors (osso_return_t result)
130 g_debug ("All OK\n");
134 g_debug ("Ordinary Error\n");
138 g_debug ("At least one parameter is invalid\n");
142 g_debug ("Osso RPC method returned an error\n");
145 case OSSO_ERROR_NAME:
146 g_debug ("Error Name\n");
149 case OSSO_ERROR_NO_STATE:
150 g_debug ("No state file found to read\n");
153 case OSSO_ERROR_STATE_SIZE:
154 g_debug("The size of the given structure");
155 g_debug(" is different from the saved size\n");
161 WSDBusData * ws_dbus_create (gchar *name, gchar *version)
163 gchar *cb_table[] = {"find_word",
166 "return_translations",
168 "update_progressbar",
173 "extract_dictionary",
174 "return_extracted_dict",
175 "search_home_applet",
178 guint array_size = 0;
181 while (cb_table[array_size] != NULL) array_size++;
184 WSDBusCBData temp_cb_data;
187 temp = (gpointer) g_try_malloc (sizeof (WSDBusData));
189 g_debug ("\nDBUS: ");
193 g_debug ("Error in function %s - cannot allocate memory\n",
195 g_assert_not_reached();
198 else g_debug ("Memory allocation successful\n");
200 temp->name = g_strconcat (name, NULL);
201 temp->version = g_strconcat (version, NULL);
203 temp->cb_data = g_array_new (TRUE, TRUE, sizeof (WSDBusCBData));
205 for (i = 0; i < array_size; i++)
207 temp_quark = g_quark_try_string (cb_table[i]);
212 "DBUS: \"%s\" - signal has already been registered - %d\n",
214 g_quark_from_string(cb_table[i]));
219 temp_quark = g_quark_from_string (cb_table[i]);
220 g_debug ("DBUS: Assigning signal \"%s\" an id %d\n",
223 temp_cb_data.id = temp_quark;
224 temp_cb_data.handler = NULL;
225 temp_cb_data.user_data = NULL;
226 g_array_append_val (temp->cb_data, temp_cb_data);
231 g_debug ("DBUS: Signals were successfully added\n");
236 /* added by Gadomska Anna - HISA */
237 WSDBusStatus ws_dbus_server_search_home_applet (WSDBusData * ws_dbus_data, gchar * word)
239 osso_return_t result;
242 retval = g_try_malloc (sizeof (osso_rpc_t));
246 g_debug("DBUS: Error in function %s:",__FUNCTION__);
247 g_debug(" Couldn't allocate memory for message's return value\n");
250 result = osso_rpc_run (ws_dbus_data->context,
251 ws_dbus_data->remote_service,
252 ws_dbus_data->remote_object,
253 ws_dbus_data->remote_iface,
254 "search_home_applet",
260 g_debug ("\nDBUS: %s: ", __FUNCTION__);
262 ws_dbus_libosso_errors (result);
264 if (result != OSSO_OK)
266 g_debug ("Error message: %s\n", retval->value.s);
267 osso_rpc_free_val (retval);
269 return WS_DBUS_STATUS_ERROR;
272 osso_rpc_free_val (retval);
274 return WS_DBUS_STATUS_OK;
277 WSDBusStatus ws_dbus_config (WSDBusData * ws_dbus_data,
282 if (ws_dbus_data == NULL)
284 g_debug ("\nDBUS: Error in function %s - ws_dbus_data is NULL\n",
290 case WS_DBUS_CONFIG_SERVICE :
291 ws_dbus_data->service = g_strconcat (value, NULL);
293 case WS_DBUS_CONFIG_OBJECT :
294 ws_dbus_data->object = g_strconcat (value, NULL);
296 case WS_DBUS_CONFIG_IFACE :
297 ws_dbus_data->iface = g_strconcat (value, NULL);
299 case WS_DBUS_CONFIG_REMOTE_SERVICE :
300 ws_dbus_data->remote_service = g_strconcat (value, NULL);
302 case WS_DBUS_CONFIG_REMOTE_OBJECT :
303 ws_dbus_data->remote_object = g_strconcat (value, NULL);
305 case WS_DBUS_CONFIG_REMOTE_IFACE :
306 ws_dbus_data->remote_iface = g_strconcat (value, NULL);
310 return WS_DBUS_STATUS_OK;
313 WSDBusStatus ws_dbus_connect (WSDBusData * ws_dbus_data)
316 osso_return_t result;
318 ws_dbus_data->context = osso_initialize (ws_dbus_data->name,
319 ws_dbus_data->version,
322 osso_rpc_set_timeout (ws_dbus_data->context, 100);
324 result = osso_rpc_set_cb_f(ws_dbus_data->context,
325 ws_dbus_data->service,
326 ws_dbus_data->object,
329 ws_dbus_data->cb_data);
331 if (result == OSSO_OK) return WS_DBUS_STATUS_OK;
332 else return WS_DBUS_STATUS_ERROR;
335 void ws_dbus_destroy (WSDBusData * ws_dbus_data)
338 if (ws_dbus_data == NULL)
340 g_debug ("\nDBUS: Error in function %s - cannot free osso_context\n",
342 g_free (ws_dbus_data);
343 g_assert_not_reached();
346 g_debug ("\nDBUS deinitialization by %s:\n---------------------------\n",
347 ws_dbus_data->service);
348 osso_deinitialize (ws_dbus_data->context);
349 g_debug ("| Deinitializing osso context |\n");
350 if (ws_dbus_data->cb_data != NULL)
352 g_array_free (ws_dbus_data->cb_data, TRUE);
353 g_debug ("| Freeing callback pointers list |\n");
356 g_free (ws_dbus_data->name);
357 g_free (ws_dbus_data->version);
358 g_free (ws_dbus_data->service);
359 g_free (ws_dbus_data->object);
360 g_free (ws_dbus_data->iface);
362 g_free (ws_dbus_data->remote_service);
363 g_free (ws_dbus_data->remote_object);
364 g_free (ws_dbus_data->remote_iface);
366 g_free (ws_dbus_data);
367 g_debug ("| Freeing WSDBusData structure |\n----------------------\n");
371 WSDBusStatus ws_dbus_set_cb (WSDBusData * ws_dbus_data,
372 gchar * detailed_signal,
377 WSDBusCBData cb_data;
381 temp = g_quark_try_string (detailed_signal);
385 g_debug ("DBUS:\"%s\"-signal not defined or invalid signal name\n",
387 return WS_DBUS_STATUS_ERROR;
392 for (i = 0; i < ws_dbus_data->cb_data->len; ++i)
394 cb_data = g_array_index (ws_dbus_data->cb_data,
397 if (cb_data.id == temp)
400 cb_data.handler = c_func;
401 cb_data.user_data = user_data;
402 g_array_insert_val(ws_dbus_data->cb_data,
405 g_array_remove_index (ws_dbus_data->cb_data,
413 return WS_DBUS_STATUS_OK;
416 WSDBusStatus ws_dbus_notify (WSDBusData * ws_dbus_data,
417 WSDBusNotify ws_dbus_info)
419 osso_return_t result;
422 retval = g_try_malloc (sizeof (osso_rpc_t));
426 g_debug("DBUS: Error in function %s: ",__FUNCTION__);
427 g_debug("Couldn't allocate memory for message's return value\n");
430 result = osso_rpc_run (ws_dbus_data->context,
431 ws_dbus_data->remote_service,
432 ws_dbus_data->remote_object,
433 ws_dbus_data->remote_iface,
439 g_debug ("\nDBUS: %s: ", __FUNCTION__);
440 ws_dbus_libosso_errors (result);
442 if (result != OSSO_OK)
444 g_debug ("Error message: %s\n", retval->value.s);
445 if (/*strcmp */g_ascii_strcasecmp(retval->value.s,
446 "No reply within specified time") != 0)
448 osso_rpc_free_val (retval);
450 return WS_DBUS_STATUS_ERROR;
454 osso_rpc_free_val (retval);
456 return WS_DBUS_STATUS_OK;
459 WSDBusStatus ws_dbus_client_find_word (WSDBusData * ws_dbus_data, gchar * word)
461 osso_return_t result;
464 retval = g_try_malloc (sizeof (osso_rpc_t));
468 g_debug("DBUS: Error in function %s:",__FUNCTION__);
469 g_debug(" Couldn't allocate memory for message's return value\n");
472 result = osso_rpc_run (ws_dbus_data->context,
473 ws_dbus_data->remote_service,
474 ws_dbus_data->remote_object,
475 ws_dbus_data->remote_iface,
482 g_debug ("\nDBUS: %s: ", __FUNCTION__);
484 ws_dbus_libosso_errors (result);
486 if (result != OSSO_OK)
488 g_debug ("Error message: %s\n", retval->value.s);
489 osso_rpc_free_val (retval);
491 return WS_DBUS_STATUS_ERROR;
494 osso_rpc_free_val (retval);
496 return WS_DBUS_STATUS_OK;
499 WSDBusStatus ws_dbus_client_find_translation (WSDBusData * ws_dbus_data,
502 osso_return_t result;
505 retval = g_try_malloc (sizeof (osso_rpc_t));
509 g_debug("DBUS: Error in function %s: ",__FUNCTION__);
510 g_debug(" Couldn't allocate memory for message's return value\n");
513 result = osso_rpc_run (ws_dbus_data->context,
514 ws_dbus_data->remote_service,
515 ws_dbus_data->remote_object,
516 ws_dbus_data->remote_iface,
523 g_debug ("\nDBUS: %s: ", __FUNCTION__);
525 ws_dbus_libosso_errors (result);
527 if (result != OSSO_OK)
529 g_debug ("Error message: %s\n", retval->value.s);
530 osso_rpc_free_val (retval);
532 return WS_DBUS_STATUS_ERROR;
535 osso_rpc_free_val (retval);
537 return WS_DBUS_STATUS_OK;
540 WSDBusStatus ws_dbus_client_search_in_history (WSDBusData* ws_dbus_data,
543 osso_return_t result;
546 retval = g_try_malloc (sizeof (osso_rpc_t));
550 g_debug("DBUS: Error in function %s:",__FUNCTION__);
551 g_debug(" Couldn't allocate memory for message's return value\n");
554 result = osso_rpc_run (ws_dbus_data->context,
555 ws_dbus_data->remote_service,
556 ws_dbus_data->remote_object,
557 ws_dbus_data->remote_iface,
564 g_debug ("\nDBUS: %s: ", __FUNCTION__);
566 ws_dbus_libosso_errors (result);
568 if (result != OSSO_OK)
570 g_debug ("Error message: %s\n", retval->value.s);
571 osso_rpc_free_val (retval);
573 return WS_DBUS_STATUS_ERROR;
576 osso_rpc_free_val (retval);
578 return WS_DBUS_STATUS_OK;
581 WSDBusStatus ws_dbus_server_return_words (WSDBusData * ws_dbus_data,
585 osso_return_t result;
588 retval = g_try_malloc (sizeof (osso_rpc_t));
592 g_debug("DBUS: Error in function %s:",__FUNCTION__);
593 g_debug(" Couldn't allocate memory for message's return value\n");
596 result = osso_rpc_run_with_argfill (ws_dbus_data->context,
597 ws_dbus_data->remote_service,
598 ws_dbus_data->remote_object,
599 ws_dbus_data->remote_iface,
602 ws_dbus_fill_message,
604 g_debug ("\nDBUS: %s: ", __FUNCTION__);
606 ws_dbus_libosso_errors (result);
608 if (result != OSSO_OK)
610 g_debug ("Error message: %s\n", retval->value.s);
611 osso_rpc_free_val (retval);
613 return WS_DBUS_STATUS_ERROR;
616 osso_rpc_free_val (retval);
618 return WS_DBUS_STATUS_OK;
621 WSDBusStatus ws_dbus_server_return_words_last(WSDBusData * ws_dbus_data,
625 osso_return_t result;
628 retval = g_try_malloc (sizeof (osso_rpc_t));
632 g_debug("DBUS: Error in function %s:",__FUNCTION__);
633 g_debug(" Couldn't allocate memory for message's return value\n");
636 result = osso_rpc_run_with_argfill (ws_dbus_data->context,
637 ws_dbus_data->remote_service,
638 ws_dbus_data->remote_object,
639 ws_dbus_data->remote_iface,
642 ws_dbus_fill_message,
645 g_debug ("\nDBUS: %s: ", __FUNCTION__);
647 ws_dbus_libosso_errors (result);
649 if (result != OSSO_OK)
651 g_debug ("Error message: %s\n", retval->value.s);
652 osso_rpc_free_val (retval);
654 return WS_DBUS_STATUS_ERROR;
657 osso_rpc_free_val (retval);
659 return WS_DBUS_STATUS_OK;
662 WSDBusStatus ws_dbus_server_return_translations(WSDBusData * ws_dbus_data,
666 osso_return_t result;
669 retval = g_try_malloc (sizeof (osso_rpc_t));
673 g_debug("DBUS: Error in function %s:", __FUNCTION__);
674 g_debug(" Couldn't allocate memory for message's return value\n");
677 result = osso_rpc_run (ws_dbus_data->context,
678 ws_dbus_data->remote_service,
679 ws_dbus_data->remote_object,
680 ws_dbus_data->remote_iface,
681 "return_translations",
687 g_debug ("\nDBUS: %s: ", __FUNCTION__);
689 ws_dbus_libosso_errors (result);
691 if (result != OSSO_OK)
693 g_debug ("Error message: %s\n", retval->value.s);
694 osso_rpc_free_val (retval);
696 return WS_DBUS_STATUS_ERROR;
699 osso_rpc_free_val (retval);
701 return WS_DBUS_STATUS_OK;
704 WSDBusStatus ws_dbus_send_ptrtodata(WSDBusData * ws_dbus_data,
709 osso_return_t result;
712 retval = g_try_malloc (sizeof (osso_rpc_t));
716 g_debug("DBUS: Error in function %s:",__FUNCTION__);
717 g_debug(" Couldn't allocate memory for message's return value\n");
720 result = osso_rpc_run (ws_dbus_data->context,
721 ws_dbus_data->remote_service,
722 ws_dbus_data->remote_object,
723 ws_dbus_data->remote_iface,
730 g_debug ("\nDBUS: %s: ", __FUNCTION__);
732 ws_dbus_libosso_errors (result);
734 if (result != OSSO_OK)
736 g_debug ("Error message: %s\n", retval->value.s);
737 osso_rpc_free_val (retval);
739 return WS_DBUS_STATUS_ERROR;
742 osso_rpc_free_val (retval);
744 return WS_DBUS_STATUS_OK;
749 WSDBusStatus ws_dbus_server_return_translations_last(WSDBusData * ws_dbus_data,
753 osso_return_t result;
756 retval = g_try_malloc (sizeof (osso_rpc_t));
760 g_debug("DBUS: Error in function %s:", __FUNCTION__);
761 g_debug(" Couldn't allocate memory for message's return value\n");
764 result = osso_rpc_run(ws_dbus_data->context,
765 ws_dbus_data->remote_service,
766 ws_dbus_data->remote_object,
767 ws_dbus_data->remote_iface,
768 "return_translations",
774 g_debug ("\nDBUS: %s: ", __FUNCTION__);
776 ws_dbus_libosso_errors (result);
778 if (result != OSSO_OK)
780 g_debug ("Error message: %s\n", retval->value.s);
781 osso_rpc_free_val (retval);
783 return WS_DBUS_STATUS_ERROR;
786 osso_rpc_free_val (retval);
788 return WS_DBUS_STATUS_OK;
791 gpointer ws_dbus_concat_data (GArray *garray)
795 gulong total_len = 0;
796 gpointer temp = NULL, start;
799 for (i=0;i<garray->len;++i)
801 array = g_array_index (garray, gchar *, i);
802 g_debug ("DBUS: %s: text added: %s\n", __FUNCTION__, array);
804 temp_len = strlen (array);
805 g_debug ("length: %d\n", temp_len);
806 start = g_malloc (total_len + temp_len + 1);
807 memcpy (start, temp, total_len);
808 if (i > 0) g_free (temp);
809 temp = start + total_len;
810 memcpy (temp, &temp_len, 1);
811 memcpy (temp+1, array, temp_len);
812 total_len = total_len + temp_len + 1;
817 GArray * ws_dbus_split_data (gpointer buffer)
829 buffer_len = strlen (buffer);
831 g_debug ("Buffer length %d\n", strlen (buffer));
832 garray = g_array_new (TRUE, TRUE, sizeof(gchar *));
837 total_len = total_len + len;
838 str = g_malloc (len + 1);
839 memcpy (str, temp+1, len);
841 temp = temp + len + 1;
842 g_debug ("Received text: %s, %d\n", str, len);
843 g_array_append_val (garray, str);
850 WSDBusStatus ws_dbus_server_update_progressbar (WSDBusData * ws_dbus_data,
854 osso_return_t result;
857 retval = g_try_malloc (sizeof (osso_rpc_t));
861 g_debug("DBUS: Error in function %s:", __FUNCTION__);
862 g_debug(" Couldn't allocate memory for message's return value\n");
865 result = osso_rpc_run (ws_dbus_data->context,
866 ws_dbus_data->remote_service,
867 ws_dbus_data->remote_object,
868 ws_dbus_data->remote_iface,
869 "update_progressbar",
875 g_debug ("\nDBUS: %s: ", __FUNCTION__);
877 ws_dbus_libosso_errors (result);
879 if (result != OSSO_OK)
881 g_debug ("Error message: %s\n", retval->value.s);
882 osso_rpc_free_val (retval);
884 return WS_DBUS_STATUS_ERROR;
887 osso_rpc_free_val (retval);
889 return WS_DBUS_STATUS_OK;
892 WSDBusStatus ws_dbus_client_add_bookmark (WSDBusData * ws_dbus_data, gchar * word, gchar *translation)
895 osso_return_t result;
898 retval = g_try_malloc (sizeof (osso_rpc_t));
902 g_debug("DBUS: Error in function %s:",__FUNCTION__);
903 g_debug(" Couldn't allocate memory for message's return value\n");
906 result = osso_rpc_run (ws_dbus_data->context,
907 ws_dbus_data->remote_service,
908 ws_dbus_data->remote_object,
909 ws_dbus_data->remote_iface,
918 g_debug ("\nDBUS: %s: ", __FUNCTION__);
920 ws_dbus_libosso_errors (result);
922 if (result != OSSO_OK)
924 g_debug ("Error message: %s\n", retval->value.s);
925 osso_rpc_free_val (retval);
927 return WS_DBUS_STATUS_ERROR;
930 osso_rpc_free_val (retval);
932 return WS_DBUS_STATUS_OK;
935 WSDBusStatus ws_dbus_client_remove_bookmark (WSDBusData * ws_dbus_data, gchar * word)
938 osso_return_t result;
941 retval = g_try_malloc (sizeof (osso_rpc_t));
945 g_debug("DBUS: Error in function %s:",__FUNCTION__);
946 g_debug(" Couldn't allocate memory for message's return value\n");
949 result = osso_rpc_run (ws_dbus_data->context,
950 ws_dbus_data->remote_service,
951 ws_dbus_data->remote_object,
952 ws_dbus_data->remote_iface,
959 g_debug ("\nDBUS: %s: ", __FUNCTION__);
961 ws_dbus_libosso_errors (result);
963 if (result != OSSO_OK)
965 g_debug ("Error message: %s\n", retval->value.s);
966 osso_rpc_free_val (retval);
968 return WS_DBUS_STATUS_ERROR;
971 osso_rpc_free_val (retval);
973 return WS_DBUS_STATUS_OK;
976 WSDBusStatus ws_dbus_server_send_message (WSDBusData * ws_dbus_data, gchar * word)
979 osso_return_t result;
982 retval = g_try_malloc (sizeof (osso_rpc_t));
986 g_debug("DBUS: Error in function %s:",__FUNCTION__);
987 g_debug(" Couldn't allocate memory for message's return value\n");
990 result = osso_rpc_run (ws_dbus_data->context,
991 ws_dbus_data->remote_service,
992 ws_dbus_data->remote_object,
993 ws_dbus_data->remote_iface,
1000 g_debug ("\nDBUS: %s: ", __FUNCTION__);
1002 ws_dbus_libosso_errors (result);
1004 if (result != OSSO_OK)
1006 g_debug ("Error message: %s\n", retval->value.s);
1007 osso_rpc_free_val (retval);
1009 return WS_DBUS_STATUS_ERROR;
1012 osso_rpc_free_val (retval);
1014 return WS_DBUS_STATUS_OK;
1017 WSDBusStatus ws_dbus_client_extract_dictionary(WSDBusData * ws_dbus_data,
1021 osso_return_t result;
1024 retval = g_try_malloc (sizeof (osso_rpc_t));
1028 g_debug("DBUS: Error in function %s:",__FUNCTION__);
1029 g_debug(" Couldn't allocate memory for message's return value\n");
1032 result = osso_rpc_run(ws_dbus_data->context,
1033 ws_dbus_data->remote_service,
1034 ws_dbus_data->remote_object,
1035 ws_dbus_data->remote_iface,
1036 "extract_dictionary",
1042 g_debug ("\nDBUS: %s: ", __FUNCTION__);
1044 ws_dbus_libosso_errors (result);
1046 if (result != OSSO_OK)
1048 g_debug ("Error message: %s\n", retval->value.s);
1049 osso_rpc_free_val (retval);
1051 return WS_DBUS_STATUS_ERROR;
1054 osso_rpc_free_val (retval);
1056 return WS_DBUS_STATUS_OK;
1059 WSDBusStatus ws_dbus_server_return_extracted_dict(WSDBusData* ws_dbus_data,
1062 osso_return_t result;
1065 retval = g_try_malloc (sizeof (osso_rpc_t));
1069 g_debug("DBUS: Error in function %s:", __FUNCTION__);
1070 g_debug(" Couldn't allocate memory for message's return value\n");
1073 result = osso_rpc_run(ws_dbus_data->context,
1074 ws_dbus_data->remote_service,
1075 ws_dbus_data->remote_object,
1076 ws_dbus_data->remote_iface,
1077 "return_extracted_dict",
1083 g_debug ("\nDBUS: %s: ", __FUNCTION__);
1085 ws_dbus_libosso_errors (result);
1087 if (result != OSSO_OK)
1089 g_debug ("Error message: %s\n", retval->value.s);
1090 osso_rpc_free_val (retval);
1092 return WS_DBUS_STATUS_ERROR;
1095 osso_rpc_free_val (retval);
1097 return WS_DBUS_STATUS_OK;