Add ma_get_recording_audio_source_type API 11/210911/3
authorJi-hoon Lee <dalton.lee@samsung.com>
Fri, 26 Jul 2019 02:05:52 +0000 (11:05 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Mon, 5 Aug 2019 08:47:31 +0000 (17:47 +0900)
Change-Id: Id5a8b9bf388efe5f98c702a554cd1d4b5f683610

client/ma.c
client/ma_dbus.c
client/ma_dbus.h
common/ma_defs.h
include/multi_assistant.h

index b3f5c4116338bbb29faed4ab2db9466940aae8b7..4dda7af09f3f37ba134cf640c79bf369715ed9c6 100644 (file)
@@ -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
index 6a0026148ba482f428b00cd0c0030a03e766830e..abff3cb52ff3b4c62e869cd7855e49ce552a49e5 100644 (file)
@@ -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()) {
index a9ec69034e5235b9e991444720b844a8f42478c2..a9f07e71807ebd15442a0b20e92409a5a99ed9ab 100644 (file)
@@ -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
index 2c094126f651489f73af439f06f7d9cd07e8c18f..c51d54dfe85d7cefffa30408e7cd09c4c904eaaf 100644 (file)
@@ -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"
index 75f14a4513a12e3332d59b8d36d8b9643e4b096c..5e1571e9bb4af627033002718d4a7699723f72df 100644 (file)
@@ -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