From: Ji-hoon Lee Date: Fri, 26 Jul 2019 02:05:52 +0000 (+0900) Subject: Add ma_get_recording_audio_source_type API X-Git-Tag: submit/tizen/20190806.020345~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cd79feae96bdc9692d1482b51c2f5409b7e5b1d3;p=platform%2Fcore%2Fuifw%2Fmulti-assistant.git Add ma_get_recording_audio_source_type API Change-Id: Id5a8b9bf388efe5f98c702a554cd1d4b5f683610 --- diff --git a/client/ma.c b/client/ma.c index b3f5c41..4dda7af 100644 --- a/client/ma.c +++ b/client/ma.c @@ -1433,3 +1433,55 @@ int ma_assistant_info_get_name(ma_assistant_info_h handle, char** name) { *name = (char*)info->name; return MA_ERROR_NONE; } + +int ma_get_recording_audio_source_type(char** type) { + if (0 != __ma_get_feature_enabled()) { + return MA_ERROR_NOT_SUPPORTED; + } + + if (0 != __ma_check_privilege()) { + return MA_ERROR_PERMISSION_DENIED; + } + + if (NULL == type) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Invalid parameter"); + return MA_ERROR_INVALID_PARAMETER; + } + + ma_state_e state; + if (0 != ma_client_get_client_state(g_ma, &state)) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] A handle is not available"); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != MA_STATE_READY) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Invalid State: Current state is not 'READY'"); //LCOV_EXCL_LINE + return MA_ERROR_INVALID_STATE; + } + + SLOG(LOG_DEBUG, TAG_MAC, "[Client DEBUG] Get recording audio source type"); + + int count = 0; + int ret = -1; + int pid = getpid(); + do { + ret = ma_dbus_get_recording_audio_source_type(pid, type); + if (0 != ret) { + if (MA_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Fail to get audio source type"); + break; + } else { + SLOG(LOG_WARN, TAG_MAC, "[WARNING] Retry to get audio source type"); + usleep(10000); + count++; + if (MA_RETRY_COUNT == count) { + SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Fail to get audio source type"); + break; + } + } + } + } while (0 != ret); + + return ret; +} \ No newline at end of file diff --git a/client/ma_dbus.c b/client/ma_dbus.c index 6a00261..abff3cb 100644 --- a/client/ma_dbus.c +++ b/client/ma_dbus.c @@ -604,7 +604,6 @@ int ma_dbus_get_recording_audio_format(int pid, int *rate, ma_audio_channel_e *c DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - DBusError err; dbus_error_init(&err); @@ -655,6 +654,75 @@ int ma_dbus_get_recording_audio_format(int pid, int *rate, ma_audio_channel_e *c return result; } +int ma_dbus_get_recording_audio_source_type(int pid, char** type) +{ + if (0 != __dbus_check()) { + return MA_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + MA_SERVER_SERVICE_NAME, + MA_SERVER_SERVICE_OBJECT_PATH, + MA_SERVER_SERVICE_INTERFACE, + MA_METHOD_GET_RECORDING_AUDIO_SOURCE_TYPE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_MAC, "@@ Request multi-assistant recording audio source type : Fail to make message"); //LCOV_EXCL_LINE + return MA_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] multi-assistant recording audio source type"); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg = NULL; + int result = MA_ERROR_OPERATION_FAILED; + + 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)) { + SLOG(LOG_DEBUG, TAG_MAC, "[ERROR] Dbus Error (%s)", err.message); //LCOV_EXCL_LINE + dbus_error_free(&err); + } + + char* tmp_type = NULL; + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_STRING, &tmp_type, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_MAC, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = MA_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result && NULL != type) { + *type = strdup(tmp_type); + SLOG(LOG_DEBUG, TAG_MAC, "@@ multi-assistant get recording audio source type : result = %d, type = %s", result, *type); + } else { + SLOG(LOG_ERROR, TAG_MAC, "@@ multi-assistant get recording audio source type : result = %d, type(%p)", result, type); + } + } else { + SLOG(LOG_ERROR, TAG_MAC, "@@ Result message is NULL"); + ma_dbus_reconnect(); + result = MA_ERROR_TIMED_OUT; + } + + return result; +} + int ma_dbus_send_asr_result(int pid, ma_asr_result_event_e event, const char* asr_result) { if (0 != __dbus_check()) { diff --git a/client/ma_dbus.h b/client/ma_dbus.h index a9ec690..a9f07e7 100644 --- a/client/ma_dbus.h +++ b/client/ma_dbus.h @@ -54,6 +54,8 @@ int ma_dbus_update_voice_feedback_state(int pid, ma_voice_feedback_state_e state int ma_dbus_send_assistant_specific_command(int pid, const char* command); +int ma_dbus_get_recording_audio_source_type(int pid, char** type); + #ifdef __cplusplus } #endif diff --git a/common/ma_defs.h b/common/ma_defs.h index 2c09412..c51d54d 100644 --- a/common/ma_defs.h +++ b/common/ma_defs.h @@ -68,6 +68,7 @@ extern "C" #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_GET_RECORDING_AUDIO_SOURCE_TYPE "ma_method_get_recording_audio_source_type" #define MA_METHOD_SEND_ASR_RESULT "ma_method_send_asr_result" #define MA_METHOD_SEND_RESULT "ma_method_send_result" #define MA_METHOD_SEND_RECOGNITION_RESULT "ma_method_send_recognition_result" diff --git a/include/multi_assistant.h b/include/multi_assistant.h index 75f14a4..5e1571e 100644 --- a/include/multi_assistant.h +++ b/include/multi_assistant.h @@ -542,6 +542,28 @@ int ma_assistant_info_get_enabled_status(ma_assistant_info_h handle, bool* statu * @retval #MA_ERROR_INVALID_PARAMETER Invalid parameter */ int ma_assistant_info_get_name(ma_assistant_info_h handle, char** name); + +/** + * @brief Gets the type information of recording audio source. + * @since_tizen 5.5 + * @privlevel public + * @privilege %http://tizen.org/privilege/recorder + * + * @remarks You must release @a type using free(). + * @param[out] type The audio source type + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MA_ERROR_NONE Successful + * @retval #MA_ERROR_NOT_SUPPORTED Not supported + * @retval #MA_ERROR_PERMISSION_DENIED Permission denied + * @retval #MA_ERROR_INVALID_STATE Invalid state + * @retval #MA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MA_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state should be #MA_STATE_READY. + */ +int ma_get_recording_audio_source_type(char** type); + #ifdef __cplusplus } #endif