2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
15 #include "tts_setting.h"
17 #include "tts_setting_dbus.h"
20 static DBusConnection* g_conn = NULL;
22 int tts_setting_dbus_open_connection()
25 SLOG(LOG_WARN, TAG_TTSC, "Already existed connection");
32 /* initialise the error value */
33 dbus_error_init(&err);
35 /* connect to the DBUS system bus, and check for errors */
36 g_conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
38 if (dbus_error_is_set(&err)) {
39 SLOG(LOG_ERROR, TAG_TTSC, "Dbus Connection Error (%s)\n", err.message);
40 dbus_error_free(&err);
44 SLOG(LOG_ERROR, TAG_TTSC, "Fail to get dbus connection \n");
45 return TTS_SETTING_ERROR_OPERATION_FAILED;
50 char service_name[64];
51 memset(service_name, 0, 64);
52 snprintf(service_name, 64, "%s%d", TTS_SETTING_SERVICE_NAME, pid);
54 SLOG(LOG_DEBUG, TAG_TTSC, "service name is %s\n", service_name);
56 /* register our name on the bus, and check for errors */
57 ret = dbus_bus_request_name(g_conn, service_name, DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
59 if (dbus_error_is_set(&err)) {
60 SLOG(LOG_ERROR, TAG_TTSC, "Name Error (%s)\n", err.message);
61 dbus_error_free(&err);
64 if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
65 printf("fail dbus_bus_request_name()\n");
66 return TTS_SETTING_ERROR_OPERATION_FAILED;
72 int tts_setting_dbus_close_connection()
75 dbus_error_init(&err);
79 char service_name[64];
80 memset(service_name, 0, 64);
81 snprintf(service_name, 64, "%s%d", TTS_SETTING_SERVICE_NAME, pid);
83 dbus_bus_release_name(g_conn, service_name, &err);
85 dbus_connection_close(g_conn);
92 int tts_setting_dbus_request_hello()
96 msg = dbus_message_new_method_call(
97 TTS_SERVER_SERVICE_NAME,
98 TTS_SERVER_SERVICE_OBJECT_PATH,
99 TTS_SERVER_SERVICE_INTERFACE,
100 TTS_SETTING_METHOD_HELLO);
103 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting hello : Fail to make message \n");
104 return TTS_SETTING_ERROR_OPERATION_FAILED;
108 dbus_error_init(&err);
110 DBusMessage* result_msg = NULL;
113 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 500, &err);
115 dbus_message_unref(msg);
117 if (NULL != result_msg) {
118 dbus_message_unref(result_msg);
120 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting hello");
129 int tts_setting_dbus_request_initialize()
133 msg = dbus_message_new_method_call(
134 TTS_SERVER_SERVICE_NAME,
135 TTS_SERVER_SERVICE_OBJECT_PATH,
136 TTS_SERVER_SERVICE_INTERFACE,
137 TTS_SETTING_METHOD_INITIALIZE);
140 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting initialize : Fail to make message \n");
141 return TTS_SETTING_ERROR_OPERATION_FAILED;
143 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting initialize");
148 dbus_message_append_args( msg,
149 DBUS_TYPE_INT32, &pid,
153 dbus_error_init(&err);
155 DBusMessage* result_msg;
156 int result = TTS_SETTING_ERROR_OPERATION_FAILED;
158 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
160 if (NULL != result_msg) {
161 dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
163 if (dbus_error_is_set(&err)) {
164 SLOG(LOG_ERROR, TAG_TTSC, "Get arguments error (%s)\n", err.message);
165 dbus_error_free(&err);
166 result = TTS_SETTING_ERROR_OPERATION_FAILED;
168 dbus_message_unref(result_msg);
172 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting initialize : result = %d \n", result);
174 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting initialize : result = %d \n", result);
177 dbus_message_unref(msg);
182 int tts_setting_dbus_request_finalilze()
186 msg = dbus_message_new_method_call(
187 TTS_SERVER_SERVICE_NAME,
188 TTS_SERVER_SERVICE_OBJECT_PATH,
189 TTS_SERVER_SERVICE_INTERFACE,
190 TTS_SETTING_METHOD_FINALIZE);
193 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting finalize : Fail to make message \n");
194 return TTS_SETTING_ERROR_OPERATION_FAILED;
196 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting finalize");
201 dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
204 dbus_error_init(&err);
206 DBusMessage* result_msg;
209 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
211 if (NULL != result_msg) {
212 dbus_message_get_args(result_msg, &err,
213 DBUS_TYPE_INT32, &result,
216 if (dbus_error_is_set(&err)) {
217 SLOG(LOG_ERROR, TAG_TTSC, "Get arguments error (%s)\n", err.message);
218 dbus_error_free(&err);
219 result = TTS_SETTING_ERROR_OPERATION_FAILED;
221 dbus_message_unref(result_msg);
225 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting finalize : result = %d \n", result);
227 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting finalize : result = %d \n", result);
230 dbus_message_unref(msg);
235 int tts_setting_dbus_request_get_engine_list(tts_setting_supported_engine_cb callback, void* user_data)
239 msg = dbus_message_new_method_call(
240 TTS_SERVER_SERVICE_NAME,
241 TTS_SERVER_SERVICE_OBJECT_PATH,
242 TTS_SERVER_SERVICE_INTERFACE,
243 TTS_SETTING_METHOD_GET_ENGINE_LIST);
246 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting get engine list : Fail to make message \n");
247 return TTS_SETTING_ERROR_OPERATION_FAILED;
249 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting get engine list");
254 dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
257 dbus_error_init(&err);
259 DBusMessage* result_msg;
260 int result = TTS_SETTING_ERROR_OPERATION_FAILED;
262 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
264 if (NULL != result_msg) {
265 DBusMessageIter args;
267 if (dbus_message_iter_init(result_msg, &args)) {
269 if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
270 dbus_message_iter_get_basic(&args, &result);
271 dbus_message_iter_next(&args);
275 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting get engine list : result = %d \n", result);
282 /* Get engine count */
283 if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
284 dbus_message_iter_get_basic(&args, &size);
285 dbus_message_iter_next(&args);
289 for (i=0 ; i<size ; i++) {
290 dbus_message_iter_get_basic(&args, &(temp_id));
291 dbus_message_iter_next(&args);
293 dbus_message_iter_get_basic(&args, &(temp_name));
294 dbus_message_iter_next(&args);
296 dbus_message_iter_get_basic(&args, &(temp_path));
297 dbus_message_iter_next(&args);
299 if (true != callback(temp_id, temp_name, temp_path, user_data)) {
304 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting get engine list : result = %d \n", result);
307 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting get engine list : invalid message \n");
310 dbus_message_unref(result_msg);
312 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting get engine list : result message is NULL!! \n");
315 dbus_message_unref(msg);
320 int tts_setting_dbus_request_get_engine(char** engine_id)
322 if (NULL == engine_id) {
323 SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL");
324 return TTS_SETTING_ERROR_INVALID_PARAMETER;
329 msg = dbus_message_new_method_call(
330 TTS_SERVER_SERVICE_NAME,
331 TTS_SERVER_SERVICE_OBJECT_PATH,
332 TTS_SERVER_SERVICE_INTERFACE,
333 TTS_SETTING_METHOD_GET_ENGINE);
336 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting get engine : Fail to make message \n");
337 return TTS_SETTING_ERROR_OPERATION_FAILED;
339 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting get engine ");
344 dbus_message_append_args( msg,
345 DBUS_TYPE_INT32, &pid,
349 dbus_error_init(&err);
351 DBusMessage* result_msg;
352 int result = TTS_SETTING_ERROR_OPERATION_FAILED;
355 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
357 if (NULL != result_msg) {
358 dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID);
360 if (dbus_error_is_set(&err)) {
361 SLOG(LOG_ERROR, TAG_TTSC, "Get arguments error (%s)\n", err.message);
362 dbus_error_free(&err);
363 result = TTS_SETTING_ERROR_OPERATION_FAILED;
365 dbus_message_unref(result_msg);
369 *engine_id = strdup(temp);
371 if (NULL == *engine_id) {
372 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting get engine : Out of memory \n");
373 result = TTS_SETTING_ERROR_OUT_OF_MEMORY;
375 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting get engine : result(%d), engine id(%s)\n", result, *engine_id);
378 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting get engine : result(%d) \n", result);
381 dbus_message_unref(msg);
387 int tts_setting_dbus_request_set_engine(const char* engine_id)
389 if (NULL == engine_id) {
390 SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL");
391 return TTS_SETTING_ERROR_INVALID_PARAMETER;
396 msg = dbus_message_new_method_call(
397 TTS_SERVER_SERVICE_NAME,
398 TTS_SERVER_SERVICE_OBJECT_PATH,
399 TTS_SERVER_SERVICE_INTERFACE,
400 TTS_SETTING_METHOD_SET_ENGINE);
403 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting set engine : Fail to make message \n");
404 return TTS_SETTING_ERROR_OPERATION_FAILED;
406 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting set engine : engine id(%s)", engine_id);
411 dbus_message_append_args( msg,
412 DBUS_TYPE_INT32, &pid,
413 DBUS_TYPE_STRING, &engine_id,
417 dbus_error_init(&err);
419 DBusMessage* result_msg;
420 int result = TTS_SETTING_ERROR_OPERATION_FAILED;
422 result_msg = dbus_connection_send_with_reply_and_block ( g_conn, msg, 3000, &err);
424 if (NULL != result_msg) {
425 dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
427 if (dbus_error_is_set(&err)) {
428 SLOG(LOG_ERROR, TAG_TTSC, "Get arguments error (%s)\n", err.message);
429 dbus_error_free(&err);
430 result = TTS_SETTING_ERROR_OPERATION_FAILED;
432 dbus_message_unref(result_msg);
436 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting set engine : result(%d) \n", result);
438 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting set engine : result(%d) \n", result);
441 dbus_message_unref(msg);
446 int tts_setting_dbus_request_get_voice_list(tts_setting_supported_voice_cb callback, void* user_data)
448 if (NULL == callback) {
449 SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL");
450 return TTS_SETTING_ERROR_INVALID_PARAMETER;
455 msg = dbus_message_new_method_call(
456 TTS_SERVER_SERVICE_NAME,
457 TTS_SERVER_SERVICE_OBJECT_PATH,
458 TTS_SERVER_SERVICE_INTERFACE,
459 TTS_SETTING_METHOD_GET_VOICE_LIST);
462 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting get voice list : Fail to make message \n");
463 return TTS_SETTING_ERROR_OPERATION_FAILED;
465 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting get voice list");
470 dbus_message_append_args( msg,
471 DBUS_TYPE_INT32, &pid,
475 dbus_error_init(&err);
477 DBusMessage* result_msg;
478 int result = TTS_SETTING_ERROR_OPERATION_FAILED;
480 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
482 DBusMessageIter args;
484 if (NULL != result_msg) {
485 if (dbus_message_iter_init(result_msg, &args)) {
487 if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
488 dbus_message_iter_get_basic(&args, &result);
489 dbus_message_iter_next(&args);
493 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting get voice list : result = %d \n", result);
496 char* temp_id = NULL;
497 char* temp_lang = NULL;
500 /* Get current voice */
501 dbus_message_iter_get_basic(&args, &temp_id);
502 dbus_message_iter_next(&args);
504 if (NULL != temp_id) {
505 /* Get voice count */
506 if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
507 dbus_message_iter_get_basic(&args, &size);
508 dbus_message_iter_next(&args);
512 for (i=0 ; i<size ; i++) {
513 dbus_message_iter_get_basic(&args, &(temp_lang) );
514 dbus_message_iter_next(&args);
516 dbus_message_iter_get_basic(&args, &(temp_type) );
517 dbus_message_iter_next(&args);
519 if (true != callback(temp_id, temp_lang, temp_type, user_data)) {
524 SLOG(LOG_ERROR, TAG_TTSC, "Engine ID is NULL \n");
525 result = TTS_SETTING_ERROR_OPERATION_FAILED;
529 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting get voice list : result = %d \n", result);
533 dbus_message_unref(result_msg);
535 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting get voice list : Result message is NULL!!");
538 dbus_message_unref(msg);
543 int tts_setting_dbus_request_get_default_voice(char** language, tts_setting_voice_type_e* voice_type)
545 if (NULL == language || NULL == voice_type) {
546 SLOG(LOG_ERROR, TAG_TTSC, "Input Parameter is NULL");
547 return TTS_SETTING_ERROR_INVALID_PARAMETER;
552 msg = dbus_message_new_method_call(
553 TTS_SERVER_SERVICE_NAME,
554 TTS_SERVER_SERVICE_OBJECT_PATH,
555 TTS_SERVER_SERVICE_INTERFACE,
556 TTS_SETTING_METHOD_GET_DEFAULT_VOICE);
559 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting get default voice : Fail to make message \n");
560 return TTS_SETTING_ERROR_OPERATION_FAILED;
562 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting get default voice");
567 dbus_message_append_args( msg,
568 DBUS_TYPE_INT32, &pid,
572 dbus_error_init(&err);
574 DBusMessage* result_msg;
575 int result = TTS_SETTING_ERROR_OPERATION_FAILED;
579 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
581 if (NULL != result_msg) {
582 dbus_message_get_args(result_msg, &err,
583 DBUS_TYPE_INT32, &result,
584 DBUS_TYPE_STRING, &temp_char,
585 DBUS_TYPE_INT32, &temp_int,
588 if (dbus_error_is_set(&err)) {
589 SLOG(LOG_ERROR, TAG_TTSC, "Get arguments error (%s)\n", err.message);
590 dbus_error_free(&err);
591 result = TTS_SETTING_ERROR_OPERATION_FAILED;
594 dbus_message_unref(result_msg);
598 *language = strdup(temp_char);
599 *voice_type = (tts_setting_voice_type_e)temp_int;
601 if (NULL == *language) {
602 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting get default voice : Out of memory \n");
603 result = TTS_SETTING_ERROR_OUT_OF_MEMORY;
605 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting get default voice : result(%d), lang(%s), vctype(%d) \n", result, *language, *voice_type);
608 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting get default voice : result(%d) \n", result);
611 dbus_message_unref(msg);
616 int tts_setting_dbus_request_set_default_voice(const char* language, const int voicetype )
618 if (NULL == language) {
619 SLOG(LOG_ERROR, TAG_TTSC, "Input Parameter is NULL");
620 return TTS_SETTING_ERROR_INVALID_PARAMETER;
625 msg = dbus_message_new_method_call(
626 TTS_SERVER_SERVICE_NAME,
627 TTS_SERVER_SERVICE_OBJECT_PATH,
628 TTS_SERVER_SERVICE_INTERFACE,
629 TTS_SETTING_METHOD_SET_DEFAULT_VOICE);
632 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting set default voice : Fail to make message \n");
633 return TTS_SETTING_ERROR_OPERATION_FAILED;
635 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting set default voice : language(%s), type(%d)", language, voicetype);
640 dbus_message_append_args( msg,
641 DBUS_TYPE_INT32, &pid,
642 DBUS_TYPE_STRING, &language,
643 DBUS_TYPE_INT32, &voicetype,
647 dbus_error_init(&err);
649 DBusMessage* result_msg;
650 int result = TTS_SETTING_ERROR_OPERATION_FAILED;
652 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
654 if (NULL != result_msg) {
655 dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
657 if (dbus_error_is_set(&err)) {
658 SLOG(LOG_ERROR, TAG_TTSC, "Get arguments error (%s)\n", err.message);
659 dbus_error_free(&err);
660 result = TTS_SETTING_ERROR_OPERATION_FAILED;
662 dbus_message_unref(result_msg);
666 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting set default voice : result(%d)", result);
668 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting set default voice : result(%d)", result);
671 dbus_message_unref(msg);
676 int tts_setting_dbus_request_get_default_speed(int* speed)
679 SLOG(LOG_ERROR, TAG_TTSC, "Input Parameter is NULL");
680 return TTS_SETTING_ERROR_INVALID_PARAMETER;
685 msg = dbus_message_new_method_call(
686 TTS_SERVER_SERVICE_NAME,
687 TTS_SERVER_SERVICE_OBJECT_PATH,
688 TTS_SERVER_SERVICE_INTERFACE,
689 TTS_SETTING_METHOD_GET_DEFAULT_SPEED);
692 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting get default speed : Fail to make message \n");
693 return TTS_SETTING_ERROR_OPERATION_FAILED;
695 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting get default speed ");
700 dbus_message_append_args( msg,
701 DBUS_TYPE_INT32, &pid,
705 dbus_error_init(&err);
707 DBusMessage* result_msg;
709 int result = TTS_SETTING_ERROR_OPERATION_FAILED;
711 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
713 if (NULL != result_msg) {
714 dbus_message_get_args(result_msg, &err,
715 DBUS_TYPE_INT32, &result,
716 DBUS_TYPE_INT32, &temp_int,
719 if (dbus_error_is_set(&err)) {
720 SLOG(LOG_ERROR, TAG_TTSC, "Get arguments error (%s)\n", err.message);
721 dbus_error_free(&err);
722 result = TTS_SETTING_ERROR_OPERATION_FAILED;
724 dbus_message_unref(result_msg);
729 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting get default speed : result(%d), speed(%d)", result, *speed);
731 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting get default speed : result(%d)", result);
734 dbus_message_unref(msg);
739 int tts_setting_dbus_request_set_default_speed(const int speed)
743 msg = dbus_message_new_method_call(
744 TTS_SERVER_SERVICE_NAME,
745 TTS_SERVER_SERVICE_OBJECT_PATH,
746 TTS_SERVER_SERVICE_INTERFACE,
747 TTS_SETTING_METHOD_SET_DEFAULT_SPEED);
750 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting set default speed : Fail to make message \n");
751 return TTS_SETTING_ERROR_OPERATION_FAILED;
753 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting set default speed : speed(%d)", speed);
758 dbus_message_append_args(msg,
759 DBUS_TYPE_INT32, &pid,
760 DBUS_TYPE_INT32, &speed,
764 dbus_error_init(&err);
766 DBusMessage* result_msg;
767 int result = TTS_SETTING_ERROR_OPERATION_FAILED;
768 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
770 if (NULL != result_msg) {
771 dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
773 if (dbus_error_is_set(&err)) {
774 SLOG(LOG_ERROR, TAG_TTSC, "Get arguments error (%s)\n", err.message);
775 dbus_error_free(&err);
776 result = TTS_SETTING_ERROR_OPERATION_FAILED;
778 dbus_message_unref(result_msg);
782 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting set default speed : result(%d)", result);
784 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting set default speed : result(%d)", result);
787 dbus_message_unref(msg);
792 int tts_setting_dbus_request_get_engine_setting(tts_setting_engine_setting_cb callback, void* user_data)
794 if (NULL == callback) {
795 SLOG(LOG_ERROR, TAG_TTSC, "Input Parameter is NULL");
796 return TTS_SETTING_ERROR_INVALID_PARAMETER;
801 msg = dbus_message_new_method_call(
802 TTS_SERVER_SERVICE_NAME,
803 TTS_SERVER_SERVICE_OBJECT_PATH,
804 TTS_SERVER_SERVICE_INTERFACE,
805 TTS_SETTING_METHOD_GET_ENGINE_SETTING);
808 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting get engine setting : Fail to make message \n");
809 return TTS_SETTING_ERROR_OPERATION_FAILED;
811 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting get engine setting");
816 dbus_message_append_args( msg,
817 DBUS_TYPE_INT32, &pid,
821 dbus_error_init(&err);
823 DBusMessage* result_msg;
824 int result = TTS_SETTING_ERROR_OPERATION_FAILED;
826 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
828 if (NULL != result_msg) {
829 DBusMessageIter args;
831 if (dbus_message_iter_init(result_msg, &args)) {
833 if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
834 dbus_message_iter_get_basic(&args, &result);
835 dbus_message_iter_next(&args);
839 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< get engine setting : result = %d \n", result);
841 char* temp_id = NULL;
846 dbus_message_iter_get_basic(&args, &temp_id);
847 dbus_message_iter_next(&args);
849 if (NULL != temp_id) {
850 /* Get setting count */
851 if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
852 dbus_message_iter_get_basic(&args, &size);
853 dbus_message_iter_next(&args);
857 for (i=0 ; i<size ; i++) {
858 dbus_message_iter_get_basic(&args, &(temp_key) );
859 dbus_message_iter_next(&args);
861 dbus_message_iter_get_basic(&args, &(temp_value) );
862 dbus_message_iter_next(&args);
864 if (true != callback(temp_id, temp_key, temp_value, user_data)) {
869 SLOG(LOG_ERROR, TAG_TTSC, "<<<< get engine setting : result message is invalid \n");
870 result = TTS_SETTING_ERROR_OPERATION_FAILED;
874 SLOG(LOG_ERROR, TAG_TTSC, "<<<< get engine setting : result message is invalid \n");
875 result = TTS_SETTING_ERROR_OPERATION_FAILED;
878 dbus_message_unref(result_msg);
880 SLOG(LOG_ERROR, TAG_TTSC, "<<<< get engine setting : Result message is NULL!! \n");
883 dbus_message_unref(msg);
888 int tts_setting_dbus_request_set_engine_setting(const char* key, const char* value)
890 if (NULL == key || NULL == value) {
891 SLOG(LOG_ERROR, TAG_TTSC, "Input Parameter is NULL");
892 return TTS_SETTING_ERROR_INVALID_PARAMETER;
897 msg = dbus_message_new_method_call(
898 TTS_SERVER_SERVICE_NAME,
899 TTS_SERVER_SERVICE_OBJECT_PATH,
900 TTS_SERVER_SERVICE_INTERFACE,
901 TTS_SETTING_METHOD_SET_ENGINE_SETTING);
904 SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting set engine setting : Fail to make message \n");
905 return TTS_SETTING_ERROR_OPERATION_FAILED;
907 SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting set engine setting : key(%s), value(%s)", key, value);
912 dbus_message_append_args( msg,
913 DBUS_TYPE_INT32, &pid,
914 DBUS_TYPE_STRING, &key,
915 DBUS_TYPE_STRING, &value,
919 dbus_error_init(&err);
921 DBusMessage* result_msg;
922 int result = TTS_SETTING_ERROR_OPERATION_FAILED;
924 result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err);
926 if (NULL != result_msg) {
927 dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
929 if (dbus_error_is_set(&err)) {
930 SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get arguments error (%s)\n", err.message);
931 dbus_error_free(&err);
934 dbus_message_unref(result_msg);
938 SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting set engine setting : result(%d)", result);
940 SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting set engine setting : result(%d)", result);
943 dbus_message_unref(msg);