From: sooyeon.kim Date: Fri, 21 Sep 2018 06:21:52 +0000 (+0900) Subject: Initial version X-Git-Tag: submit/tizen/20180921.100546^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2bbb348e3fe5381181eca4ec9d7f23d52762b28e;p=platform%2Fcore%2Fuifw%2Fwakeup-engine-default.git Initial version Change-Id: I9d43bdf35e2463fcb4b2135f363b74db903a64a2 Signed-off-by: sooyeon.kim --- diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ef4ef01 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,129 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(org.tizen.multi-assistant-service CXX C) + +# DEFAULT DATA +SET ( PACKAGE "org.tizen.multi-assistant-service") +SET ( PKGNAME ${PACKAGE}) +SET ( PREFIX ${CMAKE_INSTALL_PREFIX}) +SET ( BINDIR "${PREFIX}/bin") +SET ( RESDIR "${PREFIX}/res") +SET ( LIBDIR "${PREFIX}/lib") +SET ( SHARED_RESDIR "${PREFIX}/shared/res") +SET ( BINNAME org.tizen.multi-assistant-service) + +# SET FLAG --------------------------------------------------------------------------------------- +# Find Packages +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + capi-appfw-application + capi-appfw-app-manager + capi-appfw-package-manager + capi-appfw-service-application + capi-media-audio-io + capi-network-connection + dlog + ecore + dbus-1 + glib-2.0 +) + + + +# SET FLAG --------------------------------------------------------------------------------------- +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +#SET(COMMON_LIBS easr-nlu embeddedasr wakeup-verify ) +SET(COMMON_LIBS multi-wakeup-recognizer boost_iostream n66asrdll opus speex voiceactivity voice-transport) + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIC -fPIE -std=gnu++0x -mthumb -Wa,-mimplicit-it=thumb -fvisibility=hidden -fvisibility-inlines-hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -fPIE -fvisibility=hidden") + +# SET WARNNING OPTION ---------------------------------------------------------------------------- +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + +# OPTION DEBUG ----------------------------------------------------------------------------------- +IF("${_SDEBUG}" MATCHES "debug") + MESSAGE("Building in debug mode.") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} -O0") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG} -O0") +ELSE() + MESSAGE("Building in release mode.") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}") +ENDIF() + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") + +LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) + +SET(SRCS src/multi_assistant_service.c + src/multi_assistant_service_plugin.c + src/multi_assistant_dbus.c + src/multi_assistant_dbus_server.c +) +ADD_EXECUTABLE(${BINNAME} ${SRCS}) + +#TARGET_LINK_LIBRARIES(${BINNAME} -Llib -lopus -lboost_iostreams -ln66asrdll -lspeex -lvoiceactivity -lvoice-transport -lmulti-wakeup-recognizer ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS}) + +INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE.Flora DESTINATION /usr/share/license/) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/${PKGNAME}.xml DESTINATION /usr/share/packages) +INSTALL(TARGETS ${BINNAME} DESTINATION ${BINDIR}) + + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") + +# Install libraries +IF("${ARCH}" MATCHES "^arm.*") +TARGET_LINK_LIBRARIES(${BINNAME} -Llib/armv7l -lopus -lboost_iostreams -ln66asrdll -lspeex -lvoiceactivity -lvoice-transport -lmulti-wakeup-recognizer ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/armv7l/libmulti-wakeup-recognizer.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/armv7l/libopus.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/armv7l/libboost_iostreams.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/armv7l/libn66asrdll.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/armv7l/libspeex.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/armv7l/libvoiceactivity.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/armv7l/libvoice-transport.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +ELSEIF("${ARCH}" MATCHES "^i586.*") +TARGET_LINK_LIBRARIES(${BINNAME} -Llib/i586 -lopus -lboost_iostreams -ln66asrdll -lspeex -lvoiceactivity -lvoice-transport -lmulti-wakeup-recognizer ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libmulti-wakeup-recognizer.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libopus.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libboost_iostreams.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libn66asrdll.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libspeex.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libvoiceactivity.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libvoice-transport.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +ELSEIF("${ARCH}" MATCHES "^i686.*") +TARGET_LINK_LIBRARIES(${BINNAME} -Llib/i586 -lopus -lboost_iostreams -ln66asrdll -lspeex -lvoiceactivity -lvoice-transport -lmulti-wakeup-recognizer ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libmulti-wakeup-recognizer.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libopus.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libboost_iostreams.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libn66asrdll.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libspeex.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libvoiceactivity.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/i586/libvoice-transport.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +ELSEIF("${ARCH}" MATCHES "^aarch64.*") +TARGET_LINK_LIBRARIES(${BINNAME} -Llib/aarch64 -lopus -lboost_iostreams -ln66asrdll -lspeex -lvoiceactivity -lvoice-transport -lmulti-wakeup-recognizer ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/aarch64/libmulti-wakeup-recognizer.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/aarch64/libopus.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/aarch64/libboost_iostreams.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/aarch64/libn66asrdll.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/aarch64/libspeex.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/aarch64/libvoiceactivity.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/aarch64/libvoice-transport.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +ELSEIF("${ARCH}" MATCHES "^x86_64.*") +TARGET_LINK_LIBRARIES(${BINNAME} -Llib/x86_64 -lopus -lboost_iostreams -ln66asrdll -lspeex -lvoiceactivity -lvoice-transport -lmulti-wakeup-recognizer ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/x86_64/libmulti-wakeup-recognizer.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/x86_64/libopus.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/x86_64/libboost_iostreams.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/x86_64/libn66asrdll.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/x86_64/libspeex.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/x86_64/libvoiceactivity.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/x86_64/libvoice-transport.so DESTINATION ${PREFIX}/lib COMPONENT RuntimeLibraries) +ENDIF() + diff --git a/LICENSE.Flora b/LICENSE.Flora new file mode 100644 index 0000000..571fe79 --- /dev/null +++ b/LICENSE.Flora @@ -0,0 +1,206 @@ +Flora License + +Version 1.1, April, 2013 + +http://floralicense.org/license/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and +all other entities that control, are controlled by, or are +under common control with that entity. For the purposes of +this definition, "control" means (i) the power, direct or indirect, +to cause the direction or management of such entity, +whether by contract or otherwise, or (ii) ownership of fifty percent (50%) +or more of the outstanding shares, or (iii) beneficial ownership of +such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, +made available under the License, as indicated by a copyright notice +that is included in or attached to the work (an example is provided +in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, +that is based on (or derived from) the Work and for which the editorial +revisions, annotations, elaborations, or other modifications represent, +as a whole, an original work of authorship. For the purposes of this License, +Derivative Works shall not include works that remain separable from, +or merely link (or bind by name) to the interfaces of, the Work and +Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor +for inclusion in the Work by the copyright owner or by an individual or +Legal Entity authorized to submit on behalf of the copyright owner. +For the purposes of this definition, "submitted" means any form of +electronic, verbal, or written communication sent to the Licensor or +its representatives, including but not limited to communication on +electronic mailing lists, source code control systems, and issue +tracking systems that are managed by, or on behalf of, the Licensor +for the purpose of discussing and improving the Work, but excluding +communication that is conspicuously marked or otherwise designated +in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +"Tizen Certified Platform" shall mean a software platform that complies +with the standards set forth in the Tizen Compliance Specification +and passes the Tizen Compliance Tests as defined from time to time +by the Tizen Technical Steering Group and certified by the Tizen +Association or its designated agent. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work +solely as incorporated into a Tizen Certified Platform, where such +license applies only to those patent claims licensable by such +Contributor that are necessarily infringed by their Contribution(s) +alone or by combination of their Contribution(s) with the Work solely +as incorporated into a Tizen Certified Platform to which such +Contribution(s) was submitted. If You institute patent litigation +against any entity (including a cross-claim or counterclaim +in a lawsuit) alleging that the Work or a Contribution incorporated +within the Work constitutes direct or contributory patent infringement, +then any patent licenses granted to You under this License for that +Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof pursuant to the copyright license +above, in any medium, with or without modifications, and in Source or +Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works + a copy of this License; and + 2. You must cause any modified files to carry prominent notices stating + that You changed the files; and + 3. You must retain, in the Source form of any Derivative Works that + You distribute, all copyright, patent, trademark, and attribution + notices from the Source form of the Work, excluding those notices + that do not pertain to any part of the Derivative Works; and + 4. If the Work includes a "NOTICE" text file as part of its distribution, + then any Derivative Works that You distribute must include a readable + copy of the attribution notices contained within such NOTICE file, + excluding those notices that do not pertain to any part of + the Derivative Works, in at least one of the following places: + within a NOTICE text file distributed as part of the Derivative Works; + within the Source form or documentation, if provided along with the + Derivative Works; or, within a display generated by the Derivative Works, + if and wherever such third-party notices normally appear. + The contents of the NOTICE file are for informational purposes only + and do not modify the License. You may add Your own attribution notices + within Derivative Works that You distribute, alongside or as an addendum + to the NOTICE text from the Work, provided that such additional attribution + notices cannot be construed as modifying the License. You may add Your own + copyright statement to Your modifications and may provide additional or + different license terms and conditions for use, reproduction, or + distribution of Your modifications, or for any such Derivative Works + as a whole, provided Your use, reproduction, and distribution of + the Work otherwise complies with the conditions stated in this License + and your own copyright statement or terms and conditions do not conflict + the conditions stated in the License including section 3. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Flora License to your work + +To apply the Flora License to your work, attach the following +boilerplate notice, with the fields enclosed by brackets "[]" +replaced with your own identifying information. (Don't include +the brackets!) The text should be enclosed in the appropriate +comment syntax for the file format. We also recommend that a +file or class name and description of purpose be included on the +same "printed page" as the copyright notice for easier +identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Flora License, Version 1.1 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://floralicense.org/license/ + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/inc/multi_assistant_main.h b/inc/multi_assistant_main.h new file mode 100644 index 0000000..65dc3d7 --- /dev/null +++ b/inc/multi_assistant_main.h @@ -0,0 +1,73 @@ +#ifndef __MULTI_ASSISTANT_SERVICE_H__ +#define __MULTI_ASSISTANT_SERVICE_H__ + +#include +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "multi-assistant" + +#define MAS_SECURE_LOG_(id, prio, tag, fmt, arg...) \ + ({ do { \ + __dlog_print(id, prio, tag, "%s: %s(%d) > [SECURE_LOG] " fmt, __MODULE__, __func__, __LINE__, ##arg); \ + } while (0); }) + +#define MAS_LOG_(prio, tag, fmt, arg...) \ + ({ do { \ + dlog_print(prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \ + } while (0); }) + +#define MAS_LOGD(fmt, args...) MAS_LOG_(DLOG_DEBUG, LOG_TAG, fmt, ##args) +#define MAS_LOGI(fmt, args...) MAS_LOG_(DLOG_INFO, LOG_TAG, fmt, ##args) +#define MAS_LOGW(fmt, args...) MAS_LOG_(DLOG_WARN, LOG_TAG, fmt, ##args) +#define MAS_LOGE(fmt, args...) MAS_LOG_(DLOG_ERROR, LOG_TAG, fmt, ##args) + +#define MAS_SLOGD(fmt, args...) MAS_SECURE_LOG_(DLOG_DEBUG, LOG_TAG, fmt, ##args) +#define MAS_SLOGI(fmt, args...) MAS_SECURE_LOG_(DLOG_INFO, LOG_TAG, fmt, ##args) +#define MAS_SLOGW(fmt, args...) MAS_SECURE_LOG_(DLOG_WARN, LOG_TAG, fmt, ##args) +#define MAS_SLOGE(fmt, args...) MAS_SECURE_LOG_(DLOG_ERROR, LOG_TAG, fmt, ##args) + + +/************************************************************************************** + *** Definitions for DBus + *************************************************************************************/ +#define MA_CLIENT_SERVICE_NAME "org.tizen.multiassistant.maclient" +#define MA_CLIENT_SERVICE_OBJECT_PATH "/org/tizen/multiassistant/maclient" +#define MA_CLIENT_SERVICE_INTERFACE "org.tizen.multiassistant.maclient" + +#define MA_UI_CLIENT_SERVICE_NAME "org.tizen.multiassistant.mauiclient" +#define MA_UI_CLIENT_SERVICE_OBJECT_PATH "/org/tizen/multiassistant/mauiclient" +#define MA_UI_CLIENT_SERVICE_INTERFACE "org.tizen.multiassistant.mauiclient" + +#define MA_SERVER_SERVICE_NAME "org.tizen.multiassistant.maserver" +#define MA_SERVER_SERVICE_OBJECT_PATH "/org/tizen/multiassistant/maserver" +#define MA_SERVER_SERVICE_INTERFACE "org.tizen.multiassistant.maserver" + +/************************************************************************************** + *** Definitions for DBus methods + *************************************************************************************/ +#define MA_METHOD_HELLO "ma_method_hello" + +#define MA_METHOD_INITIALIZE "ma_method_initialize" +#define MA_METHOD_DEINITIALIZE "ma_method_deinitialize" +#define MA_METHOD_GET_RECORDING_AUDIO_FORMAT "ma_method_get_recording_audio_format" +#define MA_METHOD_SEND_ASR_RESULT "ma_method_send_asr_result" +#define MA_METHOD_SEND_RESULT "ma_method_send_result" + +#define MA_UI_METHOD_INITIALIZE "ma_ui_method_initialize" +#define MA_UI_METHOD_DEINITIALIZE "ma_ui_method_deinitialize" +#define MA_UI_METHOD_CHANGE_ASSISTANT "ma_ui_method_change_assistant" + +#define MAS_METHOD_HELLO "mas_method_hello" +#define MAS_METHOD_SEND_SPEECH_DATA "mas_method_send_speech_data" +#define MAS_METHOD_ERROR "mas_method_error" + +#define MAS_UI_METHOD_SEND_ASR_RESULT "mas_ui_method_send_asr_result" +#define MAS_UI_METHOD_SEND_RESULT "mas_ui_method_send_result" +#define MAS_UI_METHOD_ERROR "mas_ui_method_error" + + +#endif /* __MULTI_ASSISTANT_SERVICE_H__ */ diff --git a/inc/multi_assistant_service.h b/inc/multi_assistant_service.h new file mode 100644 index 0000000..30aee06 --- /dev/null +++ b/inc/multi_assistant_service.h @@ -0,0 +1,50 @@ +/* + * Copyright 2018 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef _MULTI_ASSISTANT_SERVICE_H_ +#define _MULTI_ASSISTANT_SERVICE_H_ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +int mas_client_initialize(int pid); + +int mas_client_deinitialize(int pid); + +int mas_client_get_audio_format(int pid, int* rate, int* channel, int* audio_type); + +int mas_client_send_asr_result(int pid, int event, char* asr_result); + +int mas_client_send_result(int pid, char* display_text, char* utterance_text, char* result_json); + +int mas_ui_client_initialize(int pid); + +int mas_ui_client_deinitialize(int pid); + +int mas_ui_client_change_assistant(char* app_id); + + +#ifdef __cplusplus +} +#endif + +#endif /* _MULTI_ASSISTANT_SERVICE_H_ */ diff --git a/inc/multi_assistant_service_plugin.h b/inc/multi_assistant_service_plugin.h new file mode 100644 index 0000000..dc4432a --- /dev/null +++ b/inc/multi_assistant_service_plugin.h @@ -0,0 +1,65 @@ +/* + * Samsung TTS + * Copyright 2012-2014 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef _MULTI_ASSISTANT_SERVICE_PLUGIN_H_ +#define _MULTI_ASSISTANT_SERVICE_PLUGIN_H_ + +#include + +#include "multi_wakeup_recognizer.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +int multi_assistant_service_plugin_initialize(void); + +int multi_assistant_service_plugin_deinitialize(void); + +int multi_assistant_service_plugin_set_language(const char* language); + +int multi_assistant_service_plugin_set_wakeup_word(const char* language, const char* wakeup_word); + +int multi_assistant_service_plugin_start_recording(void); + +int multi_assistant_service_plugin_stop_recording(void); + +int multi_assistant_service_plugin_cancel_recording(void); + +int multi_assistant_service_plugin_request_speech_data(void); + +int multi_assistant_service_plugin_get_recording_audio_format(int *rate, int *channel, int *audio_type); + +int multi_assistant_service_plugin_set_callbacks(void); + +int multi_assistant_service_plugin_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data); + +int multi_assistant_service_plugin_set_speech_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data); + +int multi_assistant_service_plugin_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data); + +int multi_assistant_service_plugin_set_error_callback(wakeup_service_error_cb callback, void* user_data); + + +#ifdef __cplusplus +} +#endif + +#endif /* _MULTI_ASSISTANT_SERVICE_PLUGIN_H_ */ diff --git a/inc/multi_wakeup_recognizer.h b/inc/multi_wakeup_recognizer.h new file mode 100644 index 0000000..c793a4b --- /dev/null +++ b/inc/multi_wakeup_recognizer.h @@ -0,0 +1,101 @@ +/* + * Samsung TTS + * Copyright 2012-2014 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef _MULTI_WAKEUP_RECOGNIZER_H_ +#define _MULTI_WAKEUP_RECOGNIZER_H_ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/* +#define ENGINE_UUID "27F277E9-BBC4-4dca-B553-D9884A3CDAA0" +#define ENGINE_NAME "Samsung TTS" +#define ENGINE_UG_NAME "tts_smt_setting_ug.so" +*/ + +typedef enum { + WAKEUP_EVENT_ERROR = -1, /**< Event when the wakeup recognition has failed */ + WAKEUP_EVENT_SUCCESS = 1, /**< Event when the wakeup word is matched succesfully */ + WAKEUP_EVENT_REJECTED = 2 /**< Event when the wakeup word is not matched */ +} wakeup_service_wakeup_event_e; + +typedef enum { + WAKEUP_SPEECH_STREAMING_EVENT_FAIL = -1, /**< Failed */ + WAKEUP_SPEECH_STREAMING_EVENT_START = 1, /**< Start event */ + WAKEUP_SPEECH_STREAMING_EVENT_CONTINUE = 2, /**< Continue event */ + WAKEUP_SPEECH_STREAMING_EVENT_FINISH = 3 /**< Finish event */ +} wakeup_service_speech_streaming_event_e; + +typedef enum { + WAKEUP_SPEECH_STATUS_NONE = -1, /**< None */ + WAKEUP_SPEECH_STATUS_BEGINNING_POINT_DETECTED = 1, /**< Beginning point of speech is detected */ + WAKEUP_SPEECH_STATUS_END_POINT_DETECTED = 2 /**< End point of speech is detected */ +} wakeup_service_speech_status_e; + +typedef enum { + WAKEUP_ASR_RESULT_EVENT_FINAL = 0, /**< Event when either the full matched or the final result is delivered */ + WAKEUP_ASR_RESULT_EVENT_PARTIAL, /**< Event when the partial matched result is delivered */ + WAKEUP_ASR_RESULT_EVENT_ERROR /**< Event when the recognition has failed */ +} wakeup_asr_result_event_e; + + +typedef void (*wakeup_service_wakeup_event_cb)(wakeup_service_wakeup_event_e event, const char* wakeup_word, void* user_data); + +typedef void (*wakeup_service_speech_streaming_cb)(wakeup_service_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data); + +typedef void (*wakeup_service_speech_status_cb)(wakeup_service_speech_status_e status, void *user_data); + +typedef void (*wakeup_service_error_cb)(int error, const char* err_msg, void* user_data); + + +int wakeup_service_initialize(void); + +int wakeup_service_deinitialize(void); + +int wakeup_service_set_language(const char* language); + +int wakeup_service_set_wakeup_word(const char* language, const char* wakeup_word); + +int wakeup_service_start_recording(void); + +int wakeup_service_stop_recording(void); + +int wakeup_service_cancel_recording(void); + +int wakeup_service_request_speech_data(void); + +int wakeup_service_get_recording_audio_format(int *rate, int *channel, int *audio_type); + +int wakeup_service_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data); + +int wakeup_service_set_speech_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data); + +int wakeup_service_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data); + +int wakeup_service_set_error_callback(wakeup_service_error_cb callback, void* user_data); + + +#ifdef __cplusplus +} +#endif + +#endif /* _MULTI_WAKEUP_RECOGNIZER_H_ */ diff --git a/inc/multi_wakeup_recognizer.h.org b/inc/multi_wakeup_recognizer.h.org new file mode 100644 index 0000000..734374d --- /dev/null +++ b/inc/multi_wakeup_recognizer.h.org @@ -0,0 +1,94 @@ +/* + * Samsung TTS + * Copyright 2012-2014 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef _MULTI_WAKEUP_RECOGNIZER_H_ +#define _MULTI_WAKEUP_RECOGNIZER_H_ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/* +#define ENGINE_UUID "27F277E9-BBC4-4dca-B553-D9884A3CDAA0" +#define ENGINE_NAME "Samsung TTS" +#define ENGINE_UG_NAME "tts_smt_setting_ug.so" +*/ + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "multi-wakeup" + +typedef enum { + WAKEUP_EVENT_ERROR = -1, /**< Event when the wakeup recognition has failed */ + WAKEUP_EVENT_SUCCESS = 1, /**< Event when the wakeup word is matched succesfully */ + WAKEUP_EVENT_REJECTED = 2 /**< Event when the wakeup word is not matched */ +} wakeup_service_wakeup_event_e; + +typedef enum { + WAKEUP_SPEECH_STREAMING_EVENT_FAIL = -1, /**< Failed */ + WAKEUP_SPEECH_STREAMING_EVENT_START = 1, /**< Start event */ + WAKEUP_SPEECH_STREAMING_EVENT_CONTINUE = 2, /**< Continue event */ + WAKEUP_SPEECH_STREAMING_EVENT_FINISH = 3 /**< Finish event */ +} wakeup_service_speech_streaming_event_e; + +typedef enum { + WAKEUP_SPEECH_STATUS_NONE = -1, /**< None */ + WAKEUP_SPEECH_STATUS_STARTED = 1, /**< Event when speech is started */ + WAKEUP_SPEECH_STATUS_COMPLETED = 2, /**< Event when speech is completed (EPD) */ + WAKEUP_SPEECH_STATUS_CANCELED = 3 /**< Event when speech is cancelled */ +} wakeup_service_speech_status_e; + + +typedef void (*wakeup_service_wakeup_event_cb)(wakeup_service_wakeup_event_e event, void* user_data); + +typedef void (*wakeup_service_speech_streaming_cb)(wakeup_service_speech_streaming_event_e event, char* buffer, int len, void *user_data); + +typedef void (*wakeup_service_speech_status_cb)(wakeup_service_speech_status_e status, void *user_data); + + +int wakeup_service_initialize(void); + +int wakeup_service_deinitialize(void); + +int wakeup_service_set_language(const char* language); + +int wakeup_service_set_wakeup_word(const char* language, const char* wakeup_word); + +int wakeup_service_start_recording(void); + +int wakeup_service_stop_recording(void); + +int wakeup_service_cancel_recording(void); + +int wakeup_service_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data); + +int wakeup_service_set_speech_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data); + +int wakeup_service_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _MULTI_WAKEUP_RECOGNIZER_H_ */ diff --git a/lib/aarch64/libboost_iostreams.so b/lib/aarch64/libboost_iostreams.so new file mode 100644 index 0000000..4378c64 Binary files /dev/null and b/lib/aarch64/libboost_iostreams.so differ diff --git a/lib/aarch64/libmulti-wakeup-recognizer.so b/lib/aarch64/libmulti-wakeup-recognizer.so new file mode 100644 index 0000000..30eb3eb Binary files /dev/null and b/lib/aarch64/libmulti-wakeup-recognizer.so differ diff --git a/lib/aarch64/libn66asrdll.so b/lib/aarch64/libn66asrdll.so new file mode 100755 index 0000000..39e84f3 Binary files /dev/null and b/lib/aarch64/libn66asrdll.so differ diff --git a/lib/aarch64/libopus.so b/lib/aarch64/libopus.so new file mode 100755 index 0000000..337f181 Binary files /dev/null and b/lib/aarch64/libopus.so differ diff --git a/lib/aarch64/libspeex.so b/lib/aarch64/libspeex.so new file mode 100644 index 0000000..674f11e Binary files /dev/null and b/lib/aarch64/libspeex.so differ diff --git a/lib/aarch64/libvoice-transport.so b/lib/aarch64/libvoice-transport.so new file mode 100755 index 0000000..f98cbdc Binary files /dev/null and b/lib/aarch64/libvoice-transport.so differ diff --git a/lib/aarch64/libvoiceactivity.so b/lib/aarch64/libvoiceactivity.so new file mode 100644 index 0000000..73220fa Binary files /dev/null and b/lib/aarch64/libvoiceactivity.so differ diff --git a/lib/armv7l/libboost_iostreams.so b/lib/armv7l/libboost_iostreams.so new file mode 100644 index 0000000..b87cc02 Binary files /dev/null and b/lib/armv7l/libboost_iostreams.so differ diff --git a/lib/armv7l/libmulti-wakeup-recognizer.so b/lib/armv7l/libmulti-wakeup-recognizer.so new file mode 100644 index 0000000..eab51b6 Binary files /dev/null and b/lib/armv7l/libmulti-wakeup-recognizer.so differ diff --git a/lib/armv7l/libn66asrdll.so b/lib/armv7l/libn66asrdll.so new file mode 100644 index 0000000..ba52ec7 Binary files /dev/null and b/lib/armv7l/libn66asrdll.so differ diff --git a/lib/armv7l/libopus.so b/lib/armv7l/libopus.so new file mode 100644 index 0000000..ccec2c9 Binary files /dev/null and b/lib/armv7l/libopus.so differ diff --git a/lib/armv7l/libspeex.so b/lib/armv7l/libspeex.so new file mode 100644 index 0000000..369f1f6 Binary files /dev/null and b/lib/armv7l/libspeex.so differ diff --git a/lib/armv7l/libvoice-transport.so b/lib/armv7l/libvoice-transport.so new file mode 100644 index 0000000..2e5aac2 Binary files /dev/null and b/lib/armv7l/libvoice-transport.so differ diff --git a/lib/armv7l/libvoiceactivity.so b/lib/armv7l/libvoiceactivity.so new file mode 100644 index 0000000..545ce36 Binary files /dev/null and b/lib/armv7l/libvoiceactivity.so differ diff --git a/lib/i586/libboost_iostreams.so b/lib/i586/libboost_iostreams.so new file mode 100644 index 0000000..2da0ba0 Binary files /dev/null and b/lib/i586/libboost_iostreams.so differ diff --git a/lib/i586/libmulti-wakeup-recognizer.so b/lib/i586/libmulti-wakeup-recognizer.so new file mode 100644 index 0000000..e5e8421 Binary files /dev/null and b/lib/i586/libmulti-wakeup-recognizer.so differ diff --git a/lib/i586/libn66asrdll.so b/lib/i586/libn66asrdll.so new file mode 100755 index 0000000..d0c6b7a Binary files /dev/null and b/lib/i586/libn66asrdll.so differ diff --git a/lib/i586/libopus.so b/lib/i586/libopus.so new file mode 100755 index 0000000..01f1ffe Binary files /dev/null and b/lib/i586/libopus.so differ diff --git a/lib/i586/libspeex.so b/lib/i586/libspeex.so new file mode 100644 index 0000000..2ac1b64 Binary files /dev/null and b/lib/i586/libspeex.so differ diff --git a/lib/i586/libvoice-transport.so b/lib/i586/libvoice-transport.so new file mode 100755 index 0000000..fc3f91b Binary files /dev/null and b/lib/i586/libvoice-transport.so differ diff --git a/lib/i586/libvoiceactivity.so b/lib/i586/libvoiceactivity.so new file mode 100644 index 0000000..ea5870a Binary files /dev/null and b/lib/i586/libvoiceactivity.so differ diff --git a/lib/x86_64/libboost_iostreams.so b/lib/x86_64/libboost_iostreams.so new file mode 100644 index 0000000..dc5e357 Binary files /dev/null and b/lib/x86_64/libboost_iostreams.so differ diff --git a/lib/x86_64/libmulti-wakeup-recognizer.so b/lib/x86_64/libmulti-wakeup-recognizer.so new file mode 100644 index 0000000..07244a1 Binary files /dev/null and b/lib/x86_64/libmulti-wakeup-recognizer.so differ diff --git a/lib/x86_64/libn66asrdll.so b/lib/x86_64/libn66asrdll.so new file mode 100755 index 0000000..fc313a8 Binary files /dev/null and b/lib/x86_64/libn66asrdll.so differ diff --git a/lib/x86_64/libopus.so b/lib/x86_64/libopus.so new file mode 100755 index 0000000..beb869f Binary files /dev/null and b/lib/x86_64/libopus.so differ diff --git a/lib/x86_64/libspeex.so b/lib/x86_64/libspeex.so new file mode 100644 index 0000000..d4c7a95 Binary files /dev/null and b/lib/x86_64/libspeex.so differ diff --git a/lib/x86_64/libvoice-transport.so b/lib/x86_64/libvoice-transport.so new file mode 100755 index 0000000..16372bc Binary files /dev/null and b/lib/x86_64/libvoice-transport.so differ diff --git a/lib/x86_64/libvoiceactivity.so b/lib/x86_64/libvoiceactivity.so new file mode 100644 index 0000000..a289369 Binary files /dev/null and b/lib/x86_64/libvoiceactivity.so differ diff --git a/org.tizen.multi-assistant-service.manifest b/org.tizen.multi-assistant-service.manifest new file mode 100644 index 0000000..41a9320 --- /dev/null +++ b/org.tizen.multi-assistant-service.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml new file mode 100644 index 0000000..e95522e --- /dev/null +++ b/org.tizen.multi-assistant-service.xml @@ -0,0 +1,33 @@ + + + + Won Nam Jang + Sooyeon Kim + Seongrae Jo + Multi Assistant Service + + org.tizen.multi-assistant-service.png + + + + + http://tizen.org/privilege/application.launch + http://tizen.org/privilege/power + http://tizen.org/privilege/packagemanager.info + http://tizen.org/privilege/appmanager.launch + http://tizen.org/privilege/keygrab + http://tizen.org/privilege/recorder + http://tizen.org/privilege/appdir.shareddata + http://tizen.org/privilege/internet + http://tizen.org/privilege/network.get + + diff --git a/packaging/org.tizen.multi-assistant-service.manifest b/packaging/org.tizen.multi-assistant-service.manifest new file mode 100644 index 0000000..a76fdba --- /dev/null +++ b/packaging/org.tizen.multi-assistant-service.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec new file mode 100644 index 0000000..2281a21 --- /dev/null +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -0,0 +1,81 @@ +Name: org.tizen.multi-assistant-service +Summary: Multi assistant service +Version: 0.0.1 +Release: 1 +Group: Applications +License: Samsung Proprietary License +URL: TO_BE_FIELD +Source0: %{name}-%{version}.tar.gz + +#ExclusiveArch: %arm + +BuildRequires: pkgconfig(capi-appfw-application) +BuildRequires: pkgconfig(capi-appfw-app-manager) +BuildRequires: pkgconfig(capi-appfw-package-manager) +BuildRequires: pkgconfig(capi-appfw-service-application) +BuildRequires: pkgconfig(capi-media-audio-io) +BuildRequires: pkgconfig(capi-network-connection) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(ecore) +BuildRequires: pkgconfig(dbus-1) +BuildRequires: pkgconfig(libtzplatform-config) + +BuildRequires: boost-system +BuildRequires: boost-thread +BuildRequires: cmake +BuildRequires: hash-signer + + +%description +org.tizen.multi-assistant-service (application) + +%define _usrdir /usr +#%define _appdir %{_usrdir}/apps/org.tizen.multi-assistant-service/ +%define _appdir %{TZ_SYS_RO_APP}/%{name} +%define _bindir %{_appdir}/bin/ + +%prep +%setup -q + +%build +LDFLAGS="$LDFLAGS -Wl,-z -Wl,nodelete" +%if 0%{?sec_build_binary_debug_enable} + export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" + export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" + export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" +%endif + +export LDFLAGS +cmake \ + -DCMAKE_INSTALL_PREFIX=%{_appdir} \ + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} + +%make_install +%define tizen_sign 1 +%define tizen_sign_base /usr/apps/org.tizen.multi-assistant-service +%define tizen_sign_level platform +%define tizen_author_sign 1 +%define tizen_dist_sign 1 + +%post +mkdir -p %{_bindir} +#/usr/bin/signing-client/hash-signer-client.sh -a -d -p platform /usr/apps/org.tizen.multi-assistant-service +mv %{_appdir}/lib/libboost_iostreams.so %{_appdir}/lib/libboost_iostreams.so.1.58.0 +ln -s %{_appdir}/lib/libboost_iostreams.so.1.58.0 %{_appdir}/lib/libboost_iostreams.so + +# INITIALIZE VCONF ------------------------------------------------------------ + +%files +%manifest org.tizen.multi-assistant-service.manifest +%defattr(-,root,root,-) +/usr/share/license/* +/usr/share/packages/org.tizen.multi-assistant-service.xml +%{_appdir}/author-signature.xml +%{_appdir}/signature1.xml +%{_appdir}/lib/* +%defattr(-,app,app,-) +%{_bindir}/org.tizen.multi-assistant-service diff --git a/src/N66asrWrapper.cpp.org b/src/N66asrWrapper.cpp.org new file mode 100644 index 0000000..e916f2e --- /dev/null +++ b/src/N66asrWrapper.cpp.org @@ -0,0 +1,614 @@ +/* + * N66asrWrapper.cpp + * + * Created on: Jun 18, 2015 + * Author: S. Biplab Raut + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "../inc/vsf/N66asrWrapper.h" +#include "../inc/vsf/Wrapper.h" +//#include +#include "utils/SHL_Log.h" + +#define PATTERN_CREDENTIAL "Samsung_TizenGear" + +EXTERNC void _add_asrresult_key_value(const char *key, const char *value); + +using namespace std; + +#include +#include +#include + + +void N66asrWrapper::InitLocaleList () +{ + /* Unix vs Posix */ + if(tzLocaleMap.empty ()) + { + tzLocaleMap.insert(std::pair("en_US", "en-US")); + tzLocaleMap.insert(std::pair("es_US", "es-US")); + tzLocaleMap.insert(std::pair("fr_FR", "fr-FR")); + + tzLocaleMap.insert(std::pair("ko_KR", "ko-KR")); + tzLocaleMap.insert(std::pair("zh_CN", "zh-CN")); + tzLocaleMap.insert(std::pair("ja_JP", "ja-JP")); + + tzLocaleMap.insert(std::pair("zh_TW", "zh-TW")); + tzLocaleMap.insert(std::pair("zh_SG", "zh-SG")); + tzLocaleMap.insert(std::pair("zh_HK", "zh-HK")); + + tzLocaleMap.insert(std::pair("de_DE", "de-DE")); + tzLocaleMap.insert(std::pair("ru_RU", "ru-RU")); + tzLocaleMap.insert(std::pair("pt_BR", "pt-BR")); + + tzLocaleMap.insert(std::pair("es_ES", "es-ES")); + tzLocaleMap.insert(std::pair("en_GB", "en-GB")); + tzLocaleMap.insert(std::pair("it_IT", "it-IT")); + } +} + + +bool N66asrWrapper::isSupported(const char* language) +{ + bool isSupport = false; + std::string tempLocale(language); + std::pair last = *tzLocaleMap.rbegin(); + std::map::iterator it = tzLocaleMap.begin(); + + if (tempLocale.find('-') !=std::string::npos) { + do { + if (it->second.compare(language) == 0) { + isSupport = true; + break; + } + } while (tzLocaleMap.value_comp()(*it++, last)); + } else { + do { + if (it->first.compare(language) == 0) { + isSupport = true; + break; + } + } while (tzLocaleMap.value_comp()(*it++, last)); + } + + return isSupport; +} + +string N66asrWrapper::toSVoiceLocale(string locale) +{ + string tempLocale = locale; + + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::toSVoiceLocale() begin : %s ", locale.c_str()); + + string::size_type pos = string::npos; + while ((pos = tempLocale.find("-")) != std::string::npos) + tempLocale.replace(pos, 1, "_"); + + auto search = tzLocaleMap.find(tempLocale); + + if(search != tzLocaleMap.end()) { + + string convertedLocale = search->second; + + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::toSVoiceLocale() end : %s ", convertedLocale.c_str()); + + return convertedLocale.length() > 0 ? convertedLocale : locale; + } + else { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::toSVoiceLocale() end : %s ", ""); + + return ""; + } +} + +bool N66asrWrapper::checkCredential (string credential) +{ + if( credential.find(PATTERN_CREDENTIAL) != std::string::npos) + { + return true; + } + else + { + return false; + } +} +std::string N66asrWrapper::getProxyUrl() +{ + int err = CONNECTION_ERROR_NONE; + + char* tmp = NULL; + std::string proxy; + connection_h conn; + + err = connection_create(&conn); + if(err == CONNECTION_ERROR_NONE) { + err = connection_get_proxy(conn, CONNECTION_ADDRESS_FAMILY_IPV4, &tmp); + connection_destroy(conn); + + //proxy = tmp? boost::str(boost::format("%s") % tmp) : ""; + proxy = tmp; + } + + return proxy; +} + +std::string N66asrWrapper::GetUniqueDeviceIdentifier() +{ + // Tizen specific implementation here. + /* need to check in Svoice application and import the source to get the + * Device ID from the PLM sync service, this is needed for ASR accuracy + */ + + return "gasrtizentest"; +} + +N66asrWrapper::N66asrWrapper(void) +{ + //epd = false; + RECORDING_DONE_IN_SDK = false; //--Modified for testing + SPEECH_DETECTION_DONE_IN_SDK = true; + ENCODING_DONE_IN_SDK = true; + + InitLocaleList(); + + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::N66asrWrapper()"); + + epdSpeechSessionEnd = false; + mSpRecognizer = NULL; + userData = NULL; + + server = NULL; + rampcode = NULL; + epd = asr_sdk_constant::EPD_THRESHOLD_MEDIUM; +} + +int N66asrWrapper::configureASR(const char* language, const char* type, void* user_data) +{ + userData = user_data; + strncpy(recogType, type, MAX_RECOG_TYPE_SIZE-1); + + string serverIP = asr_constants::QA2_HTTPS_SERVER_HOST_IP;// setting default + int serverportnum= asr_constants::QA2_HTTPS_SERVER_PORT;// setting default + + + string proxy="192.168.153.100";// setting default + string proxyportnum="8080";// setting default + int portnum_dec =8080; // setting default + + string asrMode = ""; + + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::configureASR() : %s - %s", language, type); + + //Config mconfig; + Config *mconfig = new Config(); + + if (type != NULL) + { + asrMode.assign(type); + } + + string locale(language); + string convertedLocale = toSVoiceLocale(locale); + cur_locale = toSVoiceLocale(locale); + if (convertedLocale.compare("") == 0) + { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::configureASR() Invalid language : %s ", language); + return STTE_ERROR_INVALID_LANGUAGE; + } + + mconfig->setLocale(convertedLocale); + mconfig->setIsRecordingRequired(RECORDING_DONE_IN_SDK); + mconfig->setIsNoiseSeparationRequired(true); + mconfig->setIsSpeechDetectionNotificationRequired(true); +// mconfig->setEPDThresholdDuration(asr_sdk_constant::EPD_THRESHOLD_LONG); +// mconfig->setEPDThresholdDuration(asr_sdk_constant::EPD_THRESHOLD_SHORT); + mconfig->setSamplingRate(asr_constants::SAMPLE_RATE); + mconfig->setIsEncodingRequired(ENCODING_DONE_IN_SDK); + mconfig->setIsSpeechDetectionRequired(SPEECH_DETECTION_DONE_IN_SDK); + mconfig->setIsEPDSessionEnd(epdSpeechSessionEnd); + mconfig->setUniqueDeviceIdentifier(GetUniqueDeviceIdentifier()); + mconfig->setASRMode(asrMode); + mconfig->setASRrampcode(asr_constants::HTTPS_SERVER_ASR_RAMPCODE_DASH_DICT); // alwaus dash_dict for ASR SDK .. since it doent depend on PLM + + string proxyURL =getProxyUrl(); + + if (proxyURL.length() != 0) { + std::size_t pos = proxyURL.find(":"); // position of "live" in str + proxyportnum = proxyURL.substr (pos +1); // get from "live" to the end + proxy = proxyURL.substr (0,pos); // get from "live" to the end + + std::string::size_type sz; // alias of size_t + //portnum_dec = std::stoi (proxyportnum,&sz); + portnum_dec = 8080; + + b_useproxy = true; + SHL_Log::shl_log_print(SHL_LOG_INFO, "N66asrWrapper", "HTTP Proxy is %s", proxyURL.c_str()); + SHL_Log::shl_log_print(SHL_LOG_INFO, "N66asrWrapper", "HTTP Proxy IP is %s", proxy.c_str()); + SHL_Log::shl_log_print(SHL_LOG_INFO, "N66asrWrapper", "HTTP Proxy Portnum is %d", portnum_dec); + } else { + b_useproxy = false; + SHL_Log::shl_log_print(SHL_LOG_INFO, "N66asrWrapper", "HTTP Proxy is NULL"); + } + + if ((convertedLocale.compare("en-US") == 0) || (convertedLocale.compare("es-US") == 0) || (convertedLocale.compare("fr-FR") == 0) + || (convertedLocale.compare("de-DE") == 0) || (convertedLocale.compare("ru-RU") == 0) || (convertedLocale.compare("pt-BR") == 0) + || (convertedLocale.compare("es-ES") == 0) || (convertedLocale.compare("en-GB") == 0) || (convertedLocale.compare("it-IT") == 0)) { + if (b_useproxy) { // http servers + serverIP = asr_constants::US_PROD2_HTTPS_SERVER_HOST_IP; + serverportnum = asr_constants::US_PROD2_HTTPS_SERVER_PORT; + } else { + serverIP = asr_constants::US_PROD2_TCP_SERVER_HOST_IP; + serverportnum = asr_constants::US_PROD2_TCP_SERVER_PORT; + } + } else if ((convertedLocale.compare("ko-KR") == 0) || (convertedLocale.compare("zh-CN") == 0) || (convertedLocale.compare("ja-JP") == 0) + || (convertedLocale.compare("zh-TW") == 0) || (convertedLocale.compare("zh-SG") == 0) || (convertedLocale.compare("zh-HK") == 0)) { + if (b_useproxy) { // http servers + serverIP = asr_constants::KR_PROD2_HTTPS_SERVER_HOST_IP; + serverportnum = asr_constants::KR_PROD2_HTTPS_SERVER_PORT; + } else { // tcp servers + serverIP = asr_constants::KR_PROD2_TCP_SERVER_HOST_IP; + serverportnum = asr_constants::KR_PROD2_TCP_SERVER_PORT; + } + } else { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::configureASR() Invalid language : %s ", language); + return STTE_ERROR_INVALID_LANGUAGE; + } + + mconfig->setServerDetails(serverIP,serverportnum, asr_constants::USE_TLS, asr_constants::CERT_PATH, + proxy, portnum_dec, b_useproxy); + + if (NULL != server) { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "Debug mode - Set Server"); + string debug_server; + int debug_port = 443; + + if (0 == strcmp(server, "qa")) { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "Debug mode - Set Server: QA"); + if (b_useproxy) { // http + debug_server = asr_constants::QA2_HTTPS_SERVER_HOST_IP; + debug_port = asr_constants::QA2_HTTPS_SERVER_PORT; + } else { // tcp + debug_server = asr_constants::QA2_TCP_SERVER_HOST_IP; + debug_port = asr_constants::QA2_TCP_SERVER_PORT; + } + + mconfig->setServerDetails(debug_server, debug_port, asr_constants::USE_TLS, asr_constants::CERT_PATH, + proxy, portnum_dec, b_useproxy); + } else if (0 == strcmp(server, "sbx")) { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "Debug mode - Set Server: SBX"); + debug_server = "sbx-n66.cloudpi.net"; + mconfig->setServerDetails(debug_server, debug_port, asr_constants::USE_TLS, asr_constants::CERT_PATH, + proxy, portnum_dec, b_useproxy); + } else { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "Product mode - Set Server: %s", server); + mconfig->setServerDetails(server, debug_port, asr_constants::USE_TLS, asr_constants::CERT_PATH, + proxy, portnum_dec, b_useproxy); + } + } + + if (NULL != rampcode) { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "Debug mode - Set Rampcode"); + + string debug_rampcode; + + if (0 == strcmp(rampcode, "dash_dict")) { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "Debug mode - Set Rampcode: dash_dict"); + debug_rampcode = rampcode; + mconfig->setASRrampcode(debug_rampcode); + } else if (0 == strcmp(rampcode, "dash_da")) { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "Debug mode - Set Rampcode: dash_da"); + debug_rampcode = rampcode; + mconfig->setASRrampcode(debug_rampcode); + } else { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "Debug mode - Set Rampcode: %s", rampcode); + debug_rampcode = rampcode; + mconfig->setASRrampcode(debug_rampcode); + } + } + + if (asr_sdk_constant::EPD_THRESHOLD_LONG != epd) { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "Debug mode: Set EPD(%d)", epd); + mconfig->setEPDThresholdDuration(epd); + } else { + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "Debug mode: Set Default EPD: EPD_THRESHOLD_LONG"); + mconfig->setEPDThresholdDuration(asr_sdk_constant::EPD_THRESHOLD_LONG); + } + + // TOS accepted API + mconfig->setTOSAccepted(true, true); // Full Accepted, Optional accepted as "OK" + mconfig->setUsePLM(false); + + mSpRecognizer = createSpeechRecognizerObject(*mconfig); + + delete mconfig; + mSpRecognizer->setListener(this); + + currentlang.assign(convertedLocale); // store the currently configure language + + return STTE_ERROR_NONE; + } + + +bool N66asrWrapper::isSpeechDetectionSupported() +{ + return true;//epdSpeechSessionEnd; +} + +bool N66asrWrapper::isNeededAppCredential() +{ + return false;//isNeededAppCredential; +} + +void N66asrWrapper::setSpeechDetectionSupported(bool silenceDetectionVal) +{ + epdSpeechSessionEnd = silenceDetectionVal; +} + +N66asrWrapper::~N66asrWrapper() +{ + tzLocaleMap.clear(); + + if (mSpRecognizer) + mSpRecognizer->destroy (); + + mSpRecognizer = NULL; + + if (NULL != server) { + free(server); + server = NULL; + } + + if (NULL != rampcode) { + free(rampcode); + rampcode = NULL; + } +} + +void N66asrWrapper::onReadyForSpeech(map params){ + +} + +void N66asrWrapper::onBeginningOfSpeech(){ + + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::onBeginningOfSpeech()"); + stte_send_speech_status(STTE_SPEECH_STATUS_BEGINNING_POINT_DETECTED, userData); +} + +void N66asrWrapper::onRmsChanged(float rmsdB){ + +} + +void N66asrWrapper::onEndOfSpeech(){ + + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::onEndOfSpeech()"); + + if (epdSpeechSessionEnd) + { + stte_send_speech_status(STTE_SPEECH_STATUS_END_POINT_DETECTED, userData); + } + +} + +void N66asrWrapper::onPartialResults(map results) { + map::iterator it; + const char** data = NULL; + int data_count = 1; + char* msg = NULL; //what is this? + char* time_info = NULL; //what is this? + + data = (const char **) malloc((sizeof(char *) * data_count)); + + int len_res_text = 0; + int len_itn_text = 0; + + bool ischinese_or_japanese = false; + char * time_info_temp = NULL; + char *data_text = NULL; + char *data_text1 = NULL; + for (it = results.begin(); it != results.end(); it++) { + if (it->first == "utterancetoken" && (cur_locale== "zh-CN" ||cur_locale=="ja-JP" || cur_locale=="zh-TW" || cur_locale=="zh-HK" || cur_locale == "zh-SG") ) + { + ischinese_or_japanese = true; + len_res_text = it->second.length(); + if (len_res_text) { + data_text1 = new char[len_res_text + 1]; + strcpy(data_text1, it->second.c_str()); + data[data_count - 1] = data_text1; + } + else { + data_count = 0; + data[data_count] =0; + } + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::onPartialResults() len_res_text of utterancetoken: %d", len_res_text); + } + else if (it->first == RECOGNIZER_RESULTS) + { + len_res_text = it->second.length(); + if (len_res_text) { + data_text = new char[len_res_text + 1]; + strcpy(data_text, it->second.c_str()); + if(!ischinese_or_japanese) + data[data_count - 1] = data_text; + }else { + data_count = 0; + data[data_count] =0; + } + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::onPartialResults() len_res_text: %d", len_res_text); + } + else if (it->first == ITN_TIMEFRAME_INFO) + { + len_itn_text = it->second.length(); + if ((len_itn_text > 0)) { //delimiter => st:res:txt + // For prevent + if(time_info_temp) { + delete []time_info_temp; + time_info_temp = NULL; + } + // End for prevent + time_info_temp = new char[len_itn_text + 1]; + strcpy(time_info_temp, it->second.c_str()); + } + } + //_add_asrresult_key_value(it->first.c_str(),it->second.c_str()); + } + + if (time_info_temp != NULL) + { //delimiter => st:res:txt + time_info = new char[len_res_text + 12 + len_itn_text + 1]; + strcpy(time_info, time_info_temp); + strcpy(time_info + len_itn_text, DELIM_STRING_RESULT_TEXT); + strcpy(time_info + len_itn_text + 12, data[data_count-1]); + delete []time_info_temp; + } + if(data_text != NULL) + data[data_count - 1] = data_text; + stte_send_result(STTE_RESULT_EVENT_PARTIAL_RESULT, + recogType, data, data_count, msg, time_info, userData); + + for(int i = 0; i < data_count; i++) + { + if (data[i]) + delete data[i]; + } + if (data) + { + free(data); + data = NULL; + } +} + +void N66asrWrapper::onResults(map results) { + map::iterator it; + const char ** data = NULL; + int data_count = 1; + char* msg = NULL; //what is this? + char* time_info = NULL; //what is this? + + data = (const char **) malloc((sizeof(char *) * data_count)); + + int len_res_text = 0; + int len_itn_text = 0; + + char * time_info_temp = NULL; + char *data_text = NULL; + char *data_text1 = NULL; + bool ischinese_or_japanese = false; + for (it = results.begin(); it != results.end(); it++) { + if (it->first == "utterancetoken" && (cur_locale== "zh-CN" ||cur_locale=="ja-JP" || cur_locale=="zh-TW" || cur_locale=="zh-HK" || cur_locale == "zh-SG") ) + { + ischinese_or_japanese = true; + len_res_text = it->second.length(); + if (len_res_text) { + data_text1 = new char[len_res_text + 1]; + strcpy(data_text1, it->second.c_str()); + data[data_count - 1] = data_text1; + } + else { + data_count = 0; + data[data_count] =0; + } + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::onResults() len_res_text of utterancetoken: %d", len_res_text); + } + else if (it->first == RECOGNIZER_RESULTS) + { + len_res_text = it->second.length(); + + if (len_res_text){ + data_text = new char[len_res_text + 1]; + strcpy(data_text, it->second.c_str()); + if(!ischinese_or_japanese) + data[data_count - 1] = data_text; + } + else { + data_count = 0; + data[data_count] =0; + } + + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::onResults() len_res_text: %d", len_res_text); + } + else if (it->first == ITN_TIMEFRAME_INFO) + { + len_itn_text = it->second.length(); + if ((len_itn_text > 0)) { //delimiter => st:res:txt + // For prevent + if(time_info_temp) { + delete []time_info_temp; + time_info_temp = NULL; + } + // End for prevent + time_info_temp = new char[len_itn_text + 1]; + strcpy(time_info_temp, it->second.c_str()); + } + } + //_add_asrresult_key_value(it->first.c_str(),it->second.c_str()); + } + if (time_info_temp != NULL) + { //delimiter => st:res:txt + time_info = new char[len_res_text + 12 + len_itn_text + 1]; + strcpy(time_info, time_info_temp); + strcpy(time_info + len_itn_text, DELIM_STRING_RESULT_TEXT); + strcpy(time_info + len_itn_text + 12, data[data_count-1]); + delete []time_info_temp; + } + + if(data_text != NULL) + data[data_count - 1] = data_text; + stte_send_result(STTE_RESULT_EVENT_FINAL_RESULT, + recogType, data, data_count, msg, time_info, userData); + + for(int i = 0; i < data_count; i++) + { + if (data[i]) + delete data[i]; + } + if (data) { + free(data); + data = NULL; + } +/* + if (time_info) + { + delete(time_info); + time_info = NULL; + } + + if (mSpRecognizer) { // clear the N66 lib instance to free resource + mSpRecognizer->destroy (); + mSpRecognizer = NULL; + } +*/ +} + +void N66asrWrapper::onError(string error){ + //uncomment to display error string on UI + //_add_asrSDKErrorString(error.c_str()); + + const char* msg = error.c_str(); + SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::onError() : %s", msg); + stte_send_error(STTE_ERROR_OPERATION_FAILED, msg); + +} + +void N66asrWrapper::onErrorString(string errorString){ + + //uncomment to display error string on UI + //_add_asrSDKErrorString(errorString.c_str()); + const char* msg = errorString.c_str(); + //SHL_Log::shl_log_print(SHL_LOG_INFO, "Plugin", "N66asrWrapper::onErrorString() : %s", msg); + stte_send_error(STTE_ERROR_OPERATION_FAILED, msg); +} + +void N66asrWrapper::onBufferReceived(unsigned char *buffer){ + +} diff --git a/src/multi_assistant_dbus.c b/src/multi_assistant_dbus.c new file mode 100644 index 0000000..89d7940 --- /dev/null +++ b/src/multi_assistant_dbus.c @@ -0,0 +1,665 @@ +/* +* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* http://www.apache.org/licenses/LICENSE-2.0 +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include +#include +#include +#include + +#include "multi_assistant_main.h" +#include "multi_assistant_dbus_server.h" +#include "multi_assistant_dbus.h" + +static DBusConnection* g_conn_sender = NULL; +static DBusConnection* g_conn_listener = NULL; + +static Ecore_Fd_Handler* g_dbus_fd_handler = NULL; + +static int g_waiting_time = 3000; + +int mas_dbus_reconnect() +{ + if (!g_conn_sender || !g_conn_listener) { + mas_dbus_close_connection(); + + if (0 != mas_dbus_open_connection()) { + MAS_LOGE("[ERROR] Fail to reconnect"); + return -1; + } + + MAS_LOGD("[DBUS] Reconnect"); + return 0; + } + + bool sender_connected = dbus_connection_get_is_connected(g_conn_sender); + bool listener_connected = dbus_connection_get_is_connected(g_conn_listener); + MAS_LOGW("[DBUS] Sender(%s) Listener(%s)", + sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected"); + + if (false == sender_connected || false == listener_connected) { + mas_dbus_close_connection(); + + if (0 != mas_dbus_open_connection()) { + MAS_LOGE("[ERROR] Fail to reconnect"); + return -1; + } + + MAS_LOGD("[DBUS] Reconnect"); + } + + return 0; +} + +static int __dbus_check() +{ + if (NULL == g_conn_sender || NULL == g_conn_listener) { + MAS_LOGE("[ERROR] NULL connection"); + return mas_dbus_reconnect(); + } + return 0; +} + +int mas_check_dbus_connection() +{ + if (NULL == g_conn_sender || NULL == g_conn_listener) { + MAS_LOGE("[ERROR] NULL connection sender(%p), listener(%p)", g_conn_sender, g_conn_listener); + return -1; + } + return 0; +} + +int masc_dbus_send_hello(int pid) +{ + if (0 != __dbus_check()) { + return -1; //MAS_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + DBusError err; + dbus_error_init(&err); + + msg = dbus_message_new_method_call( + MA_CLIENT_SERVICE_NAME, + MA_CLIENT_SERVICE_OBJECT_PATH, + MA_CLIENT_SERVICE_INTERFACE, + MAS_METHOD_HELLO); + + if (NULL == msg) { + MAS_LOGE("[DBus ERROR] Request masc hello : Fail to make message"); + return -1; + } + + int result = -1; + DBusMessage* result_msg = NULL; + result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 500, &err); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[Dbus ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + dbus_message_unref(msg); + + if (NULL != result_msg) { + dbus_message_unref(result_msg); + result = 0; + } else { + result = -1; //MAS_ERROR_TIMED_OUT; + } + + return result; +} + +int masc_dbus_send_error_message(int reason, const char* err_msg) +{ + if (0 != __dbus_check()) { + return -1; //MAS_ERROR_OPERATION_FAILED; + } + + if (NULL == g_conn_sender) { + MAS_LOGE("[Dbus ERROR] Dbus connection is not available"); + return -1; + } + + DBusMessage* msg = NULL; + + /* create a message */ + msg = dbus_message_new_signal( + MA_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */ + MA_CLIENT_SERVICE_INTERFACE, /* interface name of the signal */ + MAS_METHOD_ERROR); /* name of the signal */ + + if (NULL == msg) { + MAS_LOGE("[Dbus ERROR] Fail to create error message"); + return -1; + } + + if (!err_msg) + err_msg = strdup("#NULL"); + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &reason, + DBUS_TYPE_STRING, &err_msg, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + if (!dbus_connection_send(g_conn_sender, msg, NULL)) { + MAS_LOGE("[Dbus ERROR] <<<< error message : Out Of Memory !"); + } else { + MAS_LOGD("<<<< Send error message : reason(%d), err_msg(%s)", reason, err_msg); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + if (err_msg) + free(err_msg); + return 0; +} + +int masc_dbus_send_speech_data(int event, unsigned char* data, unsigned int data_size) +{ + if (0 != __dbus_check()) { + return -1; //MAS_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + DBusError err; + dbus_error_init(&err); + + msg = dbus_message_new_method_call( + MA_CLIENT_SERVICE_NAME, + MA_CLIENT_SERVICE_OBJECT_PATH, + MA_CLIENT_SERVICE_INTERFACE, + MAS_METHOD_SEND_SPEECH_DATA); + + if (NULL == msg) { + MAS_LOGE(">>>> Request mas send speech data : Fail to make message"); + return -1; // MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD(">>>> Request mas send speech data"); + } + + if (true != dbus_message_append_args(msg, + DBUS_TYPE_INT32, &event, + DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, + &data, data_size, + DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + MAS_LOGE("[ERROR] Fail to append args"); + return -1; + } + +#if 1 + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + MAS_LOGE("[Dbus ERROR] Fail to Send"); + return -1; // MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[Dbus DEBUG] Success to Send speech data"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + return 0; +#else + DBusMessage* result_msg; + int result = -1; + + result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + MAS_LOGE("[ERROR] Send error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("<<<< mas send speech data : Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = -1; + } + dbus_message_unref(result_msg); + + if (0 == result) { + MAS_LOGD("<<<< mas send speech data : result(%d)", result); + } else { + MAS_LOGE("<<<< mas send speech data : result(%d)", result); + } + } else { + MAS_LOGE("<<<< Result message is NULL "); + mas_dbus_reconnect(); + result = -1; + } + return result; +#endif +} + +int masc_ui_dbus_send_hello(void) +{ + if (0 != __dbus_check()) { + return -1; //MAS_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + DBusError err; + dbus_error_init(&err); + + msg = dbus_message_new_method_call( + MA_UI_CLIENT_SERVICE_NAME, + MA_UI_CLIENT_SERVICE_OBJECT_PATH, + MA_UI_CLIENT_SERVICE_INTERFACE, + MAS_METHOD_HELLO); + + if (NULL == msg) { + MAS_LOGE("[DBus ERROR] Request masc hello : Fail to make message"); + return -1; + } + + DBusMessage* result_msg = NULL; + int result = 0; + + result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 500, &err); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[Dbus ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + dbus_message_unref(msg); + + if (NULL != result_msg) { + dbus_message_unref(result_msg); + result = 0; + } else { + result = -1; //ERROR_TIMED_OUT; + } + + return result; +} + +int masc_ui_dbus_send_asr_result(int pid, int event, char* asr_result) +{ + if (0 != __dbus_check()) { + return -1; //MAS_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + MA_UI_CLIENT_SERVICE_NAME, + MA_UI_CLIENT_SERVICE_OBJECT_PATH, + MA_UI_CLIENT_SERVICE_INTERFACE, + MAS_UI_METHOD_SEND_ASR_RESULT); + + if (NULL == msg) { + MAS_LOGE("@@ Request multi-assistant send ASR result : Fail to make message"); + return -1; //MA_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[DEBUG] multi-assistant send ASR result, asr_result(%d)", asr_result); + } + + char* temp_asr_result = NULL; + if (!asr_result) + temp_asr_result = strdup("#NULL"); + else + temp_asr_result = strdup(asr_result); + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &event, + DBUS_TYPE_STRING, &temp_asr_result, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + MAS_LOGE("[Dbus ERROR] Fail to Send"); + return -1; // MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[Dbus DEBUG] Success to Send ASR result"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + if (temp_asr_result) + free(temp_asr_result); + return 0; +} + +int masc_ui_dbus_send_result(int pid, const char* display_text, const char* utterance_text, const char* result_json) +{ + if (0 != __dbus_check()) { + return -1; //MA_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + MA_UI_CLIENT_SERVICE_NAME, + MA_UI_CLIENT_SERVICE_OBJECT_PATH, + MA_UI_CLIENT_SERVICE_INTERFACE, + MAS_UI_METHOD_SEND_RESULT); + + if (NULL == msg) { + MAS_LOGE("@@ Request multi-assistant send result : Fail to make message"); + return -1; //MA_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[DEBUG] multi-assistant send result"); + } + char* temp_display_text = NULL; + char* temp_utterance_text = NULL; + char* temp_result_json = NULL; + +#if 0 + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &display_text, + DBUS_TYPE_STRING, &utterance_text, + DBUS_TYPE_STRING, &result_json, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + MAS_LOGE("[Dbus ERROR] Fail to Send"); + return -1; //MA_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[Dbus DEBUG] Success to Send result"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); +#else + if (!display_text) + temp_display_text = strdup("#NULL"); + else + temp_display_text = strdup(display_text); + if (!utterance_text) + temp_utterance_text = strdup("#NULL"); + else + temp_utterance_text = strdup(utterance_text); + if (!result_json) + temp_result_json = strdup("#NULL"); + else + temp_result_json = strdup(result_json); + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &temp_display_text, + DBUS_TYPE_STRING, &temp_utterance_text, + DBUS_TYPE_STRING, &temp_result_json, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + MAS_LOGE("[Dbus ERROR] Fail to Send"); + return -1; //MA_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[Dbus DEBUG] Success to Send result"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + if (temp_display_text) + free(temp_display_text); + if (temp_utterance_text) + free(temp_utterance_text); + if (temp_result_json) + free(temp_result_json); +#endif + return 0; +} + +int masc_ui_dbus_send_error_message(int reason, const char* err_msg) +{ + if (NULL == g_conn_sender) { + MAS_LOGE("[Dbus ERROR] Dbus connection is not available"); + return -1; + } + + DBusMessage* msg = NULL; + + /* create a message */ + msg = dbus_message_new_signal( + MA_UI_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */ + MA_UI_CLIENT_SERVICE_INTERFACE, /* interface name of the signal */ + MAS_UI_METHOD_ERROR); /* name of the signal */ + + if (NULL == msg) { + MAS_LOGE("[Dbus ERROR] Fail to create error message"); + return -1; + } + + if (!err_msg) + err_msg = strdup("#NULL"); + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &reason, + DBUS_TYPE_STRING, &err_msg, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + if (!dbus_connection_send(g_conn_sender, msg, NULL)) { + MAS_LOGE("[Dbus ERROR] <<<< error message : Out Of Memory !"); + } else { + MAS_LOGD("<<<< Send error message : reason(%d), err_msg(%s)", reason, err_msg); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + if (err_msg) + free(err_msg); + return 0; +} + +static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) +{ + if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW; + + dbus_connection_read_write_dispatch(g_conn_listener, 50); + + while (1) { + DBusMessage* msg = NULL; + msg = dbus_connection_pop_message(g_conn_listener); + + if (true != dbus_connection_get_is_connected(g_conn_listener)) { + MAS_LOGE("[ERROR] Connection is disconnected"); + return ECORE_CALLBACK_RENEW; + } + + /* loop again if we haven't read a message */ + if (NULL == msg) { + return ECORE_CALLBACK_RENEW; + } + + /* client event */ + if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_HELLO)) { + ma_service_dbus_hello(g_conn_listener, msg); + + } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_INITIALIZE)) { + ma_service_dbus_initialize(g_conn_listener, msg); + + } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_DEINITIALIZE)) { + ma_service_dbus_deinitialize(g_conn_listener, msg); + + } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_GET_RECORDING_AUDIO_FORMAT)) { + ma_service_dbus_get_audio_format(g_conn_listener, msg); + + } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_ASR_RESULT)) { + ma_service_dbus_send_asr_result(g_conn_listener, msg); + + } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_RESULT)) { + ma_service_dbus_send_result(g_conn_listener, msg); + + } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_UI_METHOD_INITIALIZE)) { + ma_service_ui_dbus_initialize(g_conn_listener, msg); + + } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_UI_METHOD_DEINITIALIZE)) { + ma_service_ui_dbus_deinitialize(g_conn_listener, msg); + + } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_UI_METHOD_CHANGE_ASSISTANT)) { + ma_service_ui_dbus_change_assistant(g_conn_listener, msg); + + } else { + MAS_LOGD("Message is NOT valid"); + /* Invalid method */ + } + /* free the message */ + dbus_message_unref(msg); + } + + return ECORE_CALLBACK_RENEW; +} + +static void __mas_dbus_connection_free() +{ + if (NULL != g_conn_listener) { + dbus_connection_close(g_conn_listener); + dbus_connection_unref(g_conn_listener); + g_conn_listener = NULL; + } + if (NULL != g_conn_sender) { + dbus_connection_close(g_conn_sender); + dbus_connection_unref(g_conn_sender); + g_conn_sender = NULL; + } +} + +int mas_dbus_open_connection() +{ + DBusError err; + dbus_error_init(&err); + + int ret; + + /* Create connection for sender */ + g_conn_sender = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[Dbus ERROR] Fail dbus_bus_get : %s", err.message); + dbus_error_free(&err); + } + + if (NULL == g_conn_sender) { + MAS_LOGE("[Dbus ERROR] Fail to get dbus connection"); + return -1; + } + + dbus_connection_set_exit_on_disconnect(g_conn_sender, false); + + /* connect to the bus and check for errors */ + g_conn_listener = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[Dbus ERROR] Fail dbus_bus_get : %s", err.message); + dbus_error_free(&err); + } + + if (NULL == g_conn_listener) { + MAS_LOGE("[Dbus ERROR] Fail to get dbus connection"); + __mas_dbus_connection_free(); + return -1; + } + + dbus_connection_set_exit_on_disconnect(g_conn_listener, false); + + /* request our name on the bus and check for errors */ + ret = dbus_bus_request_name(g_conn_listener, MA_SERVER_SERVICE_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING, &err); + + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { + printf("Fail to be primary owner in dbus request."); + MAS_LOGE("[Dbus ERROR] Fail to be primary owner"); + __mas_dbus_connection_free(); + return -1; + } + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[Dbus ERROR] dbus_bus_request_name() : %s", err.message); + dbus_error_free(&err); + __mas_dbus_connection_free(); + return -1; + } + + /* Flush messages which are received before fd event handler registration */ + while (DBUS_DISPATCH_DATA_REMAINS == dbus_connection_get_dispatch_status(g_conn_listener)) { + listener_event_callback(NULL, NULL); + } + + /* add a rule for getting signal */ + char rule[128]; + snprintf(rule, 128, "type='signal',interface='%s'", MA_SERVER_SERVICE_INTERFACE); + + /* add a rule for which messages we want to see */ + dbus_bus_add_match(g_conn_listener, rule, &err);/* see signals from the given interface */ + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[Dbus ERROR] dbus_bus_add_match() : %s", err.message); + dbus_error_free(&err); + __mas_dbus_connection_free(); + return -1; + } + + int fd = 0; + if (1 != dbus_connection_get_unix_fd(g_conn_listener, &fd)) { + MAS_LOGE("fail to get fd from dbus "); + __mas_dbus_connection_free(); + return -1; + } else { + MAS_LOGD("Get fd from dbus : %d", fd); + } + + + g_dbus_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL); + + if (NULL == g_dbus_fd_handler) { + MAS_LOGE("[Dbus ERROR] Fail to get fd handler"); + __mas_dbus_connection_free(); + return -1; + } + + return 0; +} + +int mas_dbus_close_connection() +{ + DBusError err; + dbus_error_init(&err); + + if (NULL != g_dbus_fd_handler) { + ecore_main_fd_handler_del(g_dbus_fd_handler); + g_dbus_fd_handler = NULL; + } + + dbus_bus_release_name(g_conn_listener, MA_SERVER_SERVICE_NAME, &err); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[Dbus ERROR] dbus_bus_release_name() : %s", err.message); + dbus_error_free(&err); + } + + __mas_dbus_connection_free(); + + return 0; +} diff --git a/src/multi_assistant_dbus.h b/src/multi_assistant_dbus.h new file mode 100644 index 0000000..a218865 --- /dev/null +++ b/src/multi_assistant_dbus.h @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* http://www.apache.org/licenses/LICENSE-2.0 +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#ifndef __MULTI_ASSISTANT_DBUS_h__ +#define __MULTI_ASSISTANT_DBUS_h__ + +#ifdef __cplusplus +extern "C" { +#endif + +int mas_dbus_open_connection(); + +int mas_dbus_close_connection(); + +int masc_dbus_send_hello(int pid); + +int masc_dbus_send_error_message(int reason, const char* err_msg); + +int masc_dbus_send_speech_data(int event, unsigned char* data, unsigned int data_size); + +int masc_ui_dbus_send_hello(void); + +int masc_ui_dbus_send_asr_result(int pid, int event, char* asr_result); + +int masc_ui_dbus_send_result(int pid, const char* display_text, const char* utterance_text, const char* result_json); + +int masc_ui_dbus_send_error_message(int reason, const char* err_msg); + + +#ifdef __cplusplus +} +#endif + +#endif /* __MULTI_ASSISTANT_DBUS_h__ */ diff --git a/src/multi_assistant_dbus_server.c b/src/multi_assistant_dbus_server.c new file mode 100644 index 0000000..9f485dd --- /dev/null +++ b/src/multi_assistant_dbus_server.c @@ -0,0 +1,469 @@ +/* +* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* http://www.apache.org/licenses/LICENSE-2.0 +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#include "multi_assistant_main.h" +#include "multi_assistant_dbus.h" +#include "multi_assistant_dbus_server.h" +#include "multi_assistant_service.h" + + +/* +* Dbus Client-Daemon Server +*/ +int ma_service_dbus_hello(DBusConnection* conn, DBusMessage* msg) +{ + MAS_LOGD("[DEBUG] MAS HELLO"); + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + if (!dbus_connection_send(conn, reply, NULL)) { + MAS_LOGE("[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + MAS_LOGE("[OUT ERROR] Fail to create reply message!!"); + } + + return 0; +} + +int ma_service_dbus_initialize(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = -1; + int ret = 0; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + MAS_LOGD("[DEBUG] MAS INITIALIZE"); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[IN ERROR] mas initialize : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = -1; //MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[IN] mas initialize : pid(%d)", pid); + ret = mas_client_initialize(pid); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + MAS_LOGD("[OUT] mas initialize : result(%d)", ret); + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INVALID); + + if (0 == ret) { + MAS_LOGD("[OUT] mas initialize : result(%d)", ret); + } else { + MAS_LOGE("[OUT ERROR] mas initialize : result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + MAS_LOGE("[OUT ERROR] mas initialize : Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + MAS_LOGE("[OUT ERROR] mas initialize : Fail to create reply message!!"); + } + + return 0; +} + +int ma_service_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = -1; + int ret = 0; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + MAS_LOGD("[DEBUG] MAS DEINITIALIZE"); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[IN ERROR] mas deinitialize : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = -1; //MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[IN] mas deinitialize : pid(%d)", pid); + ret = mas_client_deinitialize(pid); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + MAS_LOGD("[OUT] mas deinitialize : result(%d)", ret); + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INVALID); + + if (0 == ret) { + MAS_LOGD("[OUT] mas deinitialize : result(%d)", ret); + } else { + MAS_LOGE("[OUT ERROR] mas deinitialize : result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + MAS_LOGE("[OUT ERROR] mas deinitialize : Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + MAS_LOGE("[OUT ERROR] mas deinitialize : Fail to create reply message!!"); + } + + return 0; +} + +int ma_service_dbus_get_audio_format(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = -1; + int rate, channel, audio_type; + int ret; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + MAS_LOGD("[DEBUG] MAS GET AUDIO FORMAT"); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[IN ERROR] mas get audio format : Get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = -1; //MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[IN] mas get default voice"); + ret = mas_client_get_audio_format(pid, &rate, &channel, &audio_type); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + /* Append result and voice */ + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INT32, &rate, + DBUS_TYPE_INT32, &channel, + DBUS_TYPE_INT32, &audio_type, + DBUS_TYPE_INVALID); + if (0 == ret) { + MAS_LOGD("[OUT] mas get audio format : rate(%d), channel(%d), audio_type(%d)", rate, channel, audio_type); + } else { + MAS_LOGE("[OUT ERROR] mas get audio format : result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + MAS_LOGE("[OUT ERROR] mas get audio format : Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + MAS_LOGE("[OUT ERROR] tts default voice : Fail to create reply message!!"); + } + + return 0; +} + +int ma_service_dbus_send_asr_result(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid, event; + char *asr_result; + int ret = 0; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &event, + DBUS_TYPE_STRING, &asr_result, + DBUS_TYPE_INVALID); + + MAS_LOGD("[DEBUG] MAS SEND ASR RESULT"); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[IN ERROR] mas send asr result : Get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = -1; //MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[IN] mas send asr result : pid(%d), event(%d), asr_result(%s)", pid, event, asr_result); + ret = mas_client_send_asr_result(pid, event, asr_result); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INVALID); + + if (0 == ret) { + MAS_LOGD("[OUT] mas send asr result : result(%d)", ret); + } else { + MAS_LOGE("[OUT ERROR] mas send asr result : result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + MAS_LOGE("[OUT ERROR] mas send asr result : Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + MAS_LOGE("[OUT ERROR] mas send asr result : Fail to create reply message!!"); + } + + MAS_LOGD("<<<<<"); + MAS_LOGD(" "); + + return 0; +} + +int ma_service_dbus_send_result(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid; + char* display_text; + char* utterance_text; + char* result_json; + int ret = 0; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &display_text, + DBUS_TYPE_STRING, &utterance_text, + DBUS_TYPE_STRING, &result_json, + DBUS_TYPE_INVALID); + + MAS_LOGD("[DEBUG] MAS SEND RESULT"); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[IN ERROR] mas send result : Get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = -1; //MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[IN] mas send result : pid(%d), display_text(%s), utterance_text(%s), result_json(%s)", pid, display_text, utterance_text, result_json); + ret = mas_client_send_result(pid, display_text, utterance_text, result_json); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INVALID); + + if (0 == ret) { + MAS_LOGD("[OUT] mas send result : result(%d)", ret); + } else { + MAS_LOGE("[OUT ERROR] mas send result : result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + MAS_LOGE("[OUT ERROR] mas send result : Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + MAS_LOGE("[OUT ERROR] mas send result : Fail to create reply message!!"); + } + + MAS_LOGD("<<<<<"); + MAS_LOGD(" "); + + return 0; +} + +int ma_service_ui_dbus_initialize(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = -1; + int ret = 0; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + MAS_LOGD("[DEBUG] MAS UI INITIALIZE"); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[IN ERROR] mas ui initialize : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = -1; //MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[IN] mas ui initialize : pid(%d)", pid); + ret = mas_ui_client_initialize(pid); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + MAS_LOGD("[OUT] mas ui initialize : result(%d)", ret); + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INVALID); + + if (0 == ret) { + MAS_LOGD("[OUT] mas ui initialize : result(%d)", ret); + } else { + MAS_LOGE("[OUT ERROR] mas ui initialize : result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + MAS_LOGE("[OUT ERROR] mas ui initialize : Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + MAS_LOGE("[OUT ERROR] mas ui initialize : Fail to create reply message!!"); + } + + return 0; +} + +int ma_service_ui_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = -1; + int ret = 0; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + MAS_LOGD("[DEBUG] MAS UI DEINITIALIZE"); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[IN ERROR] mas ui deinitialize : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = -1; //MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[IN] mas ui deinitialize : pid(%d)", pid); + ret = mas_ui_client_deinitialize(pid); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + MAS_LOGD("[OUT] mas ui deinitialize : result(%d)", ret); + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INVALID); + + if (0 == ret) { + MAS_LOGD("[OUT] mas ui deinitialize : result(%d)", ret); + } else { + MAS_LOGE("[OUT ERROR] mas ui deinitialize : result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + MAS_LOGE("[OUT ERROR] mas ui deinitialize : Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + MAS_LOGE("[OUT ERROR] mas ui deinitialize : Fail to create reply message!!"); + } + + return 0; +} + +int ma_service_ui_dbus_change_assistant(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + char *app_id; + int ret = 0; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &app_id, + DBUS_TYPE_INVALID); + + MAS_LOGD("[DEBUG] MAS UI CHANGE ASSISTANT"); + + if (dbus_error_is_set(&err)) { + MAS_LOGE("[IN ERROR] mas ui change assisant : Get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = -1; //MAS_ERROR_OPERATION_FAILED; + } else { + MAS_LOGD("[IN] mas ui change assisant : app_id(%s)", app_id); + ret = mas_ui_client_change_assistant(app_id); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INVALID); + + if (0 == ret) { + MAS_LOGD("[OUT] mas ui change assisant : result(%d)", ret); + } else { + MAS_LOGE("[OUT ERROR] mas ui change assisant : result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + MAS_LOGE("[OUT ERROR] mas ui change assisant : Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + MAS_LOGE("[OUT ERROR] mas ui change assisant : Fail to create reply message!!"); + } + + MAS_LOGD("<<<<<"); + MAS_LOGD(" "); + + return 0; +} diff --git a/src/multi_assistant_dbus_server.h b/src/multi_assistant_dbus_server.h new file mode 100644 index 0000000..3d943c0 --- /dev/null +++ b/src/multi_assistant_dbus_server.h @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* http://www.apache.org/licenses/LICENSE-2.0 +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#ifndef __MULTI_ASSISTANT_DBUS_SERVER_H__ +#define __MULTI_ASSISTANT_DBUS_SERVER_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int ma_service_dbus_hello(DBusConnection* conn, DBusMessage* msg); + +int ma_service_dbus_initialize(DBusConnection* conn, DBusMessage* msg); + +int ma_service_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg); + +int ma_service_dbus_get_audio_format(DBusConnection* conn, DBusMessage* msg); + +int ma_service_dbus_send_asr_result(DBusConnection* conn, DBusMessage* msg); + +int ma_service_dbus_send_result(DBusConnection* conn, DBusMessage* msg); + +int ma_service_ui_dbus_initialize(DBusConnection* conn, DBusMessage* msg); + +int ma_service_ui_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg); + +int ma_service_ui_dbus_change_assistant(DBusConnection* conn, DBusMessage* msg); + +#ifdef __cplusplus +} +#endif + + +#endif /* __MULTI_ASSISTANT_DBUS_SERVER_H__ */ diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c new file mode 100644 index 0000000..7b20468 --- /dev/null +++ b/src/multi_assistant_service.c @@ -0,0 +1,243 @@ +/* + * Copyright 2018 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "multi_assistant_main.h" +#include "multi_assistant_service.h" +#include "multi_assistant_service_plugin.h" +#include "multi_assistant_dbus.h" + +static const char *g_current_lang = "en_US"; + + +int mas_client_initialize(int pid) +{ + MAS_LOGD("[Enter] pid(%d)", pid); + + return 0; +} + +int mas_client_deinitialize(int pid) +{ + MAS_LOGD("[Enter] pid(%d)", pid); + + return 0; +} + +int mas_client_get_audio_format(int pid, int* rate, int* channel, int* audio_type) +{ + MAS_LOGD("[Enter] pid(%d)", pid); + + int ret = multi_assistant_service_plugin_get_recording_audio_format(rate, channel, audio_type); + if (0 != ret){ + MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret); + } + + return ret; +} + +int mas_client_send_asr_result(int pid, int event, char* asr_result) +{ + MAS_LOGD("[Enter] pid(%d), event(%d), asr_result(%s)", pid, event, asr_result); + int ret = masc_ui_dbus_send_asr_result(pid, event, asr_result); + if (0 != ret){ + MAS_LOGE("[ERROR] Fail to send asr result, ret(%d)", ret); + } + + // if final event is , launch assistant app which is invoked with wakeup word. + /* TO_DO */ + return ret; +} + +int mas_client_send_result(int pid, char* display_text, char* utterance_text, char* result_json) +{ + MAS_LOGD("[Enter] pid(%d), display_text(%s), utterance_text(%s), result_json(%s)", pid, display_text, utterance_text, result_json); + int ret = masc_ui_dbus_send_result(pid, display_text, utterance_text, result_json); + if (0 != ret){ + MAS_LOGE("[ERROR] Fail to send result, ret(%d)", ret); + } + + return ret; +} + +int mas_ui_client_initialize(int pid) +{ + MAS_LOGD("[Enter] pid(%d)", pid); + + return 0; +} + +int mas_ui_client_deinitialize(int pid) +{ + MAS_LOGD("[Enter] pid(%d)", pid); + + return 0; +} + +int mas_ui_client_change_assistant(char* app_id) +{ + MAS_LOGD("[Enter] app_id(%s)", app_id); + + return 0; +} + +static int init_wakeup(void) +{ + MAS_LOGD("[Enter] init_wakeup "); + + int ret = mas_dbus_open_connection(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to open connection"); + } + + if (0 != multi_assistant_service_plugin_initialize()) { + MAS_LOGE("Fail to ws intialize"); + return -1; + } + + if (0 != multi_assistant_service_plugin_set_language(g_current_lang)) { + MAS_LOGE("Fail to ws set language"); + return -1; + } + + if (0 != multi_assistant_service_plugin_set_wakeup_word("en_US", "hi bixby")) { + MAS_LOGE("Fail to stt wakeup word"); + return -1; + } + + if (0 != multi_assistant_service_plugin_set_wakeup_word("en_US", "alexa")) { + MAS_LOGE("Fail to stt wakeup word"); + return -1; + } + + if (0 != multi_assistant_service_plugin_set_wakeup_word("en_US", "hi google")) { + MAS_LOGE("Fail to stt wakeup word"); + return -1; + } + + if (0 != multi_assistant_service_plugin_set_callbacks()) { + MAS_LOGE("Fail to set callbacks"); + return -1; + } + + if (0 != multi_assistant_service_plugin_start_recording()) { + MAS_LOGE("Fail to ws start recording"); + return -1; + } + + return 0; +} + +static void deinit_wakeup(void) +{ + MAS_LOGD("[Enter] deinit_wakeup "); + +/* if (NULL != g_current_lang) { + free(g_current_lang); + g_current_lang = NULL; + } +*/ + + int ret = mas_dbus_close_connection(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to close connection"); + } + + if (0 != multi_assistant_service_plugin_deinitialize()) { + MAS_LOGE("Fail to ws deinitialize"); + } +} + + +bool service_app_create(void *data) +{ + // Todo: add your code here. + + MAS_LOGD("[Enter] Service app create"); + + if (0 != init_wakeup()) { + MAS_LOGE("Fail to init wakeup service"); + return false; + } + + return true; +} + +void service_app_terminate(void *data) +{ + // Todo: add your code here. + deinit_wakeup(); + return; +} + +void service_app_control(app_control_h app_control, void *data) +{ + // Todo: add your code here. + return; +} + +static void +service_app_lang_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LANGUAGE_CHANGED*/ + return; +} + +static void +service_app_region_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_REGION_FORMAT_CHANGED*/ +} + +static void +service_app_low_battery(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_BATTERY*/ +} + +static void +service_app_low_memory(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_MEMORY*/ +} + +int main(int argc, char* argv[]) +{ + char ad[50] = {0,}; + service_app_lifecycle_callback_s event_callback; + app_event_handler_h handlers[5] = {NULL, }; + + event_callback.create = service_app_create; + event_callback.terminate = service_app_terminate; + event_callback.app_control = service_app_control; + + service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad); + + return service_app_main(argc, argv, &event_callback, ad); +} diff --git a/src/multi_assistant_service.cpp.org b/src/multi_assistant_service.cpp.org new file mode 100644 index 0000000..1cb9847 --- /dev/null +++ b/src/multi_assistant_service.cpp.org @@ -0,0 +1,169 @@ +/* + * Copyright 2018 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +#include "multi_assistant_service.h" +#include "multi_wakeup_recognizer.h" + + + +static const char *g_current_lang = "en_US"; + +static void __wakeup_event_cb(wakeup_service_wakeup_event_e event, void* user_data) +{ + dlog_print(DLOG_DEBUG, LOG_TAG, "[SUCCESS] __wakeup_event_cb is called"); +} + +static void __speech_streaming_cb(wakeup_service_speech_streaming_event_e event, char* buffer, int len, void *user_data) +{ + dlog_print(DLOG_DEBUG, LOG_TAG, "[SUCCESS] __speech_streaming_cb is called"); +} + +static void __speech_status_cb(wakeup_service_speech_status_e status, void *user_data) +{ + dlog_print(DLOG_DEBUG, LOG_TAG, "[SUCCESS] __speech_status_cb is called"); +} + +static int init_wakeup(void) +{ + if (0 != wakeup_service_initialize()) { + dlog_print(DLOG_ERROR, LOG_TAG, "Fail to ws intialize"); + return -1; + } + + if (0 != wakeup_service_set_language(g_current_lang)) { + dlog_print(DLOG_ERROR, LOG_TAG, "Fail to ws set language"); + return -1; + } + + if (0 != wakeup_service_set_wakeup_word("en_US", "hi bixby")) { + dlog_print(DLOG_ERROR, LOG_TAG, "Fail to stt wakeup word"); + return -1; + } + + if (0 != wakeup_service_set_wakeup_event_callback(__wakeup_event_cb, NULL)) { + dlog_print(DLOG_ERROR, LOG_TAG, "Fail to set wakeup event cb"); + return -1; + } + + if (0 != wakeup_service_set_speech_data_streaming_callback(__speech_streaming_cb, NULL)) { + dlog_print(DLOG_ERROR, LOG_TAG, "Fail to set speech data streaming cb"); + return -1; + } + + if (0 != wakeup_service_set_speech_status_callback(__speech_status_cb, NULL)) { + dlog_print(DLOG_ERROR, LOG_TAG, "Fail to set speech status changed cb"); + return -1; + } + + if (0 != wakeup_service_start_recording()) { + dlog_print(DLOG_ERROR, LOG_TAG, "Fail to ws start recording"); + return -1; + } + + return 0; +} + +static void deinit_wakeup(void) +{ +/* if (NULL != g_current_lang) { + free(g_current_lang); + g_current_lang = NULL; + } +*/ + + if (0 != wakeup_service_deinitialize()) { + dlog_print(DLOG_ERROR, LOG_TAG, "Fail to ws deinitialize"); + } +} + + +bool service_app_create(void *data) +{ + // Todo: add your code here. + if (0 != init_wakeup()) { + dlog_print(DLOG_ERROR, LOG_TAG, "Fail to init wakeup service"); + return false; + } + return true; +} + +void service_app_terminate(void *data) +{ + // Todo: add your code here. + deinit_wakeup(); + return; +} + +void service_app_control(app_control_h app_control, void *data) +{ + // Todo: add your code here. + return; +} + +static void +service_app_lang_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LANGUAGE_CHANGED*/ + return; +} + +static void +service_app_region_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_REGION_FORMAT_CHANGED*/ +} + +static void +service_app_low_battery(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_BATTERY*/ +} + +static void +service_app_low_memory(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_MEMORY*/ +} + +int main(int argc, char* argv[]) +{ + char ad[50] = {0,}; + service_app_lifecycle_callback_s event_callback; + app_event_handler_h handlers[5] = {NULL, }; + + event_callback.create = service_app_create; + event_callback.terminate = service_app_terminate; + event_callback.app_control = service_app_control; + + service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad); + + return service_app_main(argc, argv, &event_callback, ad); +} diff --git a/src/multi_assistant_service_plugin.c b/src/multi_assistant_service_plugin.c new file mode 100644 index 0000000..3e8c54c --- /dev/null +++ b/src/multi_assistant_service_plugin.c @@ -0,0 +1,386 @@ +/* + * Copyright 2018 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "multi_wakeup_recognizer.h" +#include "multi_assistant_main.h" +#include "multi_assistant_service.h" +#include "multi_assistant_service_plugin.h" +#include "multi_assistant_dbus.h" + +/* Sound buf save for test */ +#if 1 +#define BUF_SAVE_MODE +#endif + +#ifdef BUF_SAVE_MODE +static char g_temp_file_name[128] = {'\0',}; + +static FILE* g_pFile; + +static int g_count = 1; +#endif + + +/* + TEST_CODE */ +Eina_Bool __send_asr_result(void *data) +{ + MAS_LOGD("[ENTER]"); + + if (!strcmp((char*)data, "Today's")) { + masc_ui_dbus_send_asr_result(-1, 1, "Today's"); + } + if (!strcmp((char*)data, "weather.")) { + masc_ui_dbus_send_asr_result(-1, 0, "Today's weather."); + } + + MAS_LOGD("END"); + return EINA_FALSE; +} + +Eina_Bool __send_result(void *data) +{ + MAS_LOGD("[ENTER]"); + + int ret = masc_ui_dbus_send_result(-1, (const char*)data, (const char*)data, "test"); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to stop recording(%d)", ret); + return EINA_TRUE; + } + + MAS_LOGD("END"); + return EINA_FALSE; +} + +Eina_Bool __request_speech_data(void *data) +{ + MAS_LOGD("[ENTER]"); + + int ret = wakeup_service_request_speech_data(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to request speech data(%d)", ret); + } + + MAS_LOGD("END"); + return EINA_FALSE; +} +/* -TEST_CODE */ + +static void __wakeup_event_cb(wakeup_service_wakeup_event_e event, const char* wakeup_word, void* user_data) +{ + MAS_LOGD( "[SUCCESS] __wakeup_event_cb is called, event(%d), wakeup_word(%s)", event, wakeup_word); + int ret = -1; + int retry_cnt = 0; + while (0 != ret) { + ret = masc_ui_dbus_send_hello(); + retry_cnt++; + if (30 == retry_cnt) { + MAS_LOGE("[ERROR] Fail to receive reply for hello, ret(%d)", ret); + break; + } + } + +#ifdef BUF_SAVE_MODE + if (WAKEUP_EVENT_SUCCESS == event) { + if (g_pFile) { + fclose(g_pFile); + g_pFile = NULL; + } else { + MAS_LOGD("[Recorder Info] File not found!"); + } + + while (1) { + snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/ma_service_%d_%d", getpid(), g_count); + int ret = access(g_temp_file_name, 0); + + if (0 == ret) { + MAS_LOGD("[Recorder ERROR] File is already exist"); + if (0 == remove(g_temp_file_name)) { + MAS_LOGD("[Recorder] Remove file"); + break; + } else { + g_count++; + } + } else { + break; + } + } + + MAS_LOGD("[Recorder] Temp file name=[%s]", g_temp_file_name); + + /* open test file */ + g_pFile = fopen(g_temp_file_name, "wb+x"); + if (!g_pFile) { + MAS_LOGD("[Recorder ERROR] File not found!"); + return -1; + } + g_count++; + } +#endif + + // app control background launch + /* TO_DO */ + ret = -1; + retry_cnt = 0; + while (0 != ret) { + ret = masc_dbus_send_hello(getpid()); + retry_cnt++; + if (30 == retry_cnt) { + MAS_LOGE("[ERROR] Fail to receive reply for hello, ret(%d)", ret); + break; + } + } + + /* TEST_CODE */ + if (WAKEUP_EVENT_SUCCESS == event) { + ecore_thread_main_loop_begin(); + ecore_timer_add(1.0, __send_asr_result, "Today's"); + ecore_thread_main_loop_end(); + + ecore_thread_main_loop_begin(); + ecore_timer_add(2.0, __send_asr_result, "weather."); + ecore_thread_main_loop_end(); + + ecore_thread_main_loop_begin(); + ecore_timer_add(3.0, __send_result, "Partly cloudy with temperatures from 75 to 88"); + ecore_thread_main_loop_end(); + + ecore_thread_main_loop_begin(); + ecore_timer_add(4.0, __request_speech_data, NULL); + ecore_thread_main_loop_end(); + } +} + +static void __speech_streaming_cb(wakeup_service_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data) +{ + MAS_LOGD( "[SUCCESS] __speech_streaming_cb is called, event(%d), buffer(%p), len(%d)", event, buffer, len); + int ret = masc_dbus_send_speech_data(event, buffer, len); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to send speech data, ret(%d)", ret); + } + +#ifdef BUF_SAVE_MODE + /* write pcm buffer */ + if (g_pFile) + fwrite(buffer, 1, len, g_pFile); + + if (WAKEUP_SPEECH_STREAMING_EVENT_FINISH == event) { + if (g_pFile) { + MAS_LOGE("[Recorder SUCCESS] File Close"); + fclose(g_pFile); + g_pFile = NULL; + } else { + MAS_LOGE("[Recorder ERROR] File not found!"); + } + } +#endif +} + +static void __speech_status_cb(wakeup_service_speech_status_e status, void *user_data) +{ + MAS_LOGD( "[SUCCESS] __speech_status_cb is called, status(%d)", status); + + if (WAKEUP_SPEECH_STATUS_END_POINT_DETECTED == status) { + int ret = wakeup_service_stop_recording(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret); + } + } +} + +static void __error_cb(int error, const char* err_msg, void* user_data) +{ + MAS_LOGD( "[SUCCESS] __error_cb is called, error(%d), err_msg(%d)", error, err_msg); + int ret = wakeup_service_cancel_recording(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to cancel recording, ret(%d)", ret); + } + + ret = wakeup_service_start_recording(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret); + } + + ret = masc_ui_dbus_send_error_message(error, err_msg); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to send error message, ret(%d)", ret); + } +} + +int multi_assistant_service_plugin_initialize(void) +{ + int ret = wakeup_service_initialize(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret); + } + return ret; +} + +int multi_assistant_service_plugin_deinitialize(void) +{ +#ifdef BUF_SAVE_MODE + if (g_pFile) { + fclose(g_pFile); + g_pFile = NULL; + } else { + MAS_LOGD("[Recorder ERROR] File not found!"); + } +#endif + + int ret = wakeup_service_deinitialize(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret); + } + return ret; +} + +int multi_assistant_service_plugin_set_language(const char* language) +{ + int ret = wakeup_service_set_language(language); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to set langauge(%s), ret(%d)", language, ret); + } + return ret; +} + +int multi_assistant_service_plugin_set_wakeup_word(const char* language, const char* wakeup_word) +{ + int ret = wakeup_service_set_wakeup_word(language, wakeup_word); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", language, wakeup_word, ret); + } + return ret; +} + +int multi_assistant_service_plugin_start_recording(void) +{ + int ret = wakeup_service_start_recording(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret); + } + return ret; +} + +int multi_assistant_service_plugin_stop_recording(void) +{ + int ret = wakeup_service_stop_recording(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret); + } + return ret; +} + +int multi_assistant_service_plugin_cancel_recording(void) +{ + int ret = wakeup_service_cancel_recording(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to cancel recording, ret(%d)", ret); + } + return ret; +} + +int multi_assistant_service_plugin_request_speech_data(void) +{ + int ret = wakeup_service_cancel_recording(); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to cancel recording, ret(%d)", ret); + } + return ret; +} + +int multi_assistant_service_plugin_set_callbacks(void) +{ + int ret = multi_assistant_service_plugin_set_wakeup_event_callback(__wakeup_event_cb, NULL); + if (0 != ret) { + MAS_LOGE("Fail to set wakeup event cb"); + return ret; + } + + ret = multi_assistant_service_plugin_set_speech_streaming_callback(__speech_streaming_cb, NULL); + if (0 != ret) { + MAS_LOGE("Fail to set speech data streaming cb"); + return ret; + } + + ret = multi_assistant_service_plugin_set_speech_status_callback(__speech_status_cb, NULL); + if (0 != ret) { + MAS_LOGE("Fail to set speech status changed cb"); + return ret; + } + + ret = multi_assistant_service_plugin_set_error_callback(__error_cb, NULL); + if (0 != ret) { + MAS_LOGE("Fail to set error cb"); + return ret; + } + return 0; +} + +int multi_assistant_service_plugin_get_recording_audio_format(int *rate, int *channel, int *audio_type) +{ + int ret = wakeup_service_get_recording_audio_format(rate, channel, audio_type); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret); + } + return ret; +} + +int multi_assistant_service_plugin_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data) +{ + int ret = wakeup_service_set_wakeup_event_callback(callback, user_data); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to set wakeup event callback, ret(%d)", ret); + } + return ret; +} + +int multi_assistant_service_plugin_set_speech_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data) +{ + int ret = wakeup_service_set_speech_streaming_callback(callback, user_data); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to speech streaming callback, ret(%d)", ret); + } + return ret; +} + +int multi_assistant_service_plugin_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data) +{ + int ret = wakeup_service_set_speech_status_callback(callback, user_data); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to set speech status callback, ret(%d)", ret); + } + return ret; +} + +int multi_assistant_service_plugin_set_error_callback(wakeup_service_error_cb callback, void* user_data) +{ + int ret = wakeup_service_set_error_callback(callback, user_data); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret); + } + return ret; +}