Add API : ma_send_preprocessing_result 26/214026/5
authorJi-hoon Lee <dalton.lee@samsung.com>
Tue, 17 Sep 2019 07:31:57 +0000 (16:31 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Wed, 18 Sep 2019 05:34:47 +0000 (14:34 +0900)
Change-Id: I89e4aaf610516355ceae56ffa091e3af3516ac2e

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

index 627cea948f6fa06184c47f1c59c1a01eb0468e01..6e4ff986b3976f356440652d772e5fbb064c7ed1 100644 (file)
@@ -1633,4 +1633,41 @@ int ma_unset_preprocessing_information_changed_cb(void)
        ma_client_set_preprocessing_information_changed_cb(g_ma, NULL, NULL);
 
        return MA_ERROR_NONE;
+}
+
+int ma_send_preprocessing_result(bool is_success)
+{
+       SLOG(LOG_DEBUG, TAG_MAC, "[Manager] Send preprocessing result");
+
+       if (0 != __ma_get_feature_enabled()) {
+               SLOG(LOG_DEBUG, TAG_MAC, "@@@ [Manager] not supported");
+               return MA_ERROR_NOT_SUPPORTED;
+       }
+
+       if (0 != __ma_check_privilege()) {
+               return MA_ERROR_PERMISSION_DENIED;
+       }
+
+       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");
+               SLOG(LOG_DEBUG, TAG_MAC, "@@@");
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       if (state != MA_STATE_READY) {
+               SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Invalid State: Current state is not 'READY', state(%d)", state);
+               SLOG(LOG_DEBUG, TAG_MAC, "@@@");
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       /* Send preprocessing result */
+       int pid = getpid();
+       int ret = ma_dbus_send_preprocessing_result(pid, is_success);
+       if (0 != ret) {
+               SLOG(LOG_WARN, TAG_MAC, "[WARNING] retry to send preprocessing result");
+       } else {
+               SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] Success to send");
+       }
+       return ret;
 }
\ No newline at end of file
index 278be1d31b8c081495659a5df84e184d4b54039a..69f268e0ff55c16c3234db9ed1bbd3e9e4231d6a 100644 (file)
@@ -1252,3 +1252,52 @@ int ma_dbus_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode_e
 
        return 0;
 }
+
+int ma_dbus_send_preprocessing_result(int pid, bool result)
+{
+       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_SEND_PREPROCESSING_RESULT);
+
+       if (NULL == msg) {
+               SLOG(LOG_ERROR, TAG_MAC, "@@ Request multi-assistant send preprocessing result : Fail to make message"); //LCOV_EXCL_LINE
+               return MA_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] multi-assistant send preprocessing result");
+       }
+
+       int tmp_result = (result ? 1 : 0);
+       dbus_message_append_args(msg,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_INT32, &tmp_result,
+               DBUS_TYPE_INVALID);
+
+       dbus_message_set_no_reply(msg, TRUE);
+
+       DBusError error;
+       dbus_error_init (&error);
+       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+               if (dbus_error_is_set (&error)) {
+                       SLOG(LOG_ERROR, TAG_MAC, "[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
+                       dbus_error_free (&error);
+               } else {
+                       SLOG(LOG_ERROR, TAG_MAC, "[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
+               }
+               return MA_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_MAC, "[Dbus DEBUG] Success to Send");
+               dbus_connection_flush(g_conn_sender);
+       }
+
+       dbus_message_unref(msg);
+
+       return 0;
+}
index 2dc4cf88eba1f8cee2955345537a4f5dbc71e8dd..73cb77bcdd90d49d7252f5bea3bc5c9bd4340110 100644 (file)
@@ -59,6 +59,8 @@ int ma_dbus_set_background_volume(int pid, double ratio);
 
 int ma_dbus_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode_e mode, const char *app_id);
 
+int ma_dbus_send_preprocessing_result(int pid, bool result);
+
 #ifdef __cplusplus
 }
 #endif
index c4cb5b4085455c22622dc5070894020ad4d43e64..f5d59aa99c619ef199bcfa9f0f973a7d2b07d794 100644 (file)
@@ -78,6 +78,7 @@ extern "C"
 #define MA_METHOD_SEND_ASSISTANT_SPECIFIC_COMMAND      "ma_method_send_assistant_specific_command"
 #define MA_METHOD_SET_BACKGROUND_VOLUME                                "ma_method_set_background_volume"
 #define MA_METHOD_SET_PREPROCESSING_ALLOW_MODE         "ma_method_set_preprocessing_allow_mode"
+#define MA_METHOD_SEND_PREPROCESSING_RESULT                    "ma_method_send_preprocessing_result"
 #define MA_METHOD_ERROR                                                                "ma_method_error"
 
 #define MA_UI_METHOD_INITIALIZE                                                "ma_ui_method_initialize"
index 09b2ffcf2e67d9e9854ed77acb7a64e9817dbea0..afe85872b404de7501ab1c0f3bab039cbaa60b18 100644 (file)
@@ -638,6 +638,25 @@ int ma_set_preprocessing_information_changed_cb(ma_preprocessing_information_cha
  */
 int ma_unset_preprocessing_information_changed_cb(void);
 
+/**
+ * @brief Sends the preprocessing result.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/recorder
+ *
+ * @param[in] is_success The result value to be sent, indicating whether the preprocessing succeeded or not
+ *
+ * @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_OPERATION_FAILED Operation failed
+ *
+ * @pre The state should be #MA_STATE_READY.
+ */
+int ma_send_preprocessing_result(bool is_success);
+
 #ifdef __cplusplus
 }
 #endif