Add an internal API for setting server 38/104138/4
authorsooyeon.kim <sooyeon.kim@samsung.com>
Mon, 12 Dec 2016 11:09:30 +0000 (20:09 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Thu, 15 Dec 2016 02:20:47 +0000 (11:20 +0900)
Change-Id: I17e62da3ac2acf73969fc10d3f75ce23ba206b5c
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
client/stt.c
client/stt_client.c
client/stt_client.h
include/stt_internal.h

index 4595139..2fdd82f 100644 (file)
@@ -674,6 +674,11 @@ int stt_set_private_data(stt_h stt, const char* key, const char* data)
                return STT_ERROR_INVALID_STATE;
        }
 
+       if (true != client->internal && (0 == strcmp(key, "server") || 0 == strcmp(key, "rampcode") || 0 == strcmp(key, "epd"))) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This is not an internal app");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
        int ret = -1;
        int count = 0;
        while (0 != ret) {
@@ -756,6 +761,69 @@ int stt_get_private_data(stt_h stt, const char* key, char** data)
 
        return STT_ERROR_NONE;
 }
+
+int stt_set_server_stt(stt_h stt, const char* key, char* user_data)
+{
+       int ret = -1;
+       stt_client_s* client = NULL;
+
+       if (0 != __stt_get_feature_enabled()) {
+               return STT_ERROR_NOT_SUPPORTED;
+       }
+       if (0 != __stt_check_privilege()) {
+               return STT_ERROR_PERMISSION_DENIED;
+       }
+       if (0 != __stt_check_handle(stt, &client)) {
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "===== Set STT server");
+
+       if (NULL == key || NULL == user_data) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       if (STT_STATE_CREATED != client->current_state && STT_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] The current state is invalid (%d).", client->current_state);
+               return STT_ERROR_INVALID_STATE;
+       }
+
+
+       client->internal = true;
+
+       char* private_key = NULL;
+       private_key = strdup(key);
+       if (NULL == private_key) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(private_key)");
+               return STT_ERROR_OUT_OF_MEMORY;
+       }
+
+       char* data = NULL;
+       data = strdup(user_data);
+       if (NULL == data) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(data)");
+               free(private_key);
+               private_key = NULL;
+               return STT_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = stt_set_private_data(stt, private_key, data);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data, ret(%d), key(%s)", ret, private_key);
+       }
+
+       free(data);
+       data = NULL;
+       free(private_key);
+       private_key = NULL;
+
+       SLOG(LOG_DEBUG, TAG_STTC, "======");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
 static Eina_Bool __stt_connect_daemon(void *data)
 {
        stt_client_s* client = (stt_client_s*)data;
@@ -2281,4 +2349,4 @@ int stt_unset_speech_status_cb(stt_h stt)
        client->speech_status_user_data = NULL;
 
        return 0;
-}
\ No newline at end of file
+}
index 793bfd7..d2d04cf 100644 (file)
@@ -94,6 +94,8 @@ int stt_client_new(stt_h* stt)
 
        client->cb_ref_count = 0;
 
+       client->internal = false;
+
        g_client_list = g_list_append(g_client_list, client);
 
        *stt = temp;
index 20c35d8..b11e164 100644 (file)
@@ -88,6 +88,9 @@ typedef struct {
        /* error data */
        int     reason;
        char*   err_msg;
+
+       /* is this internal? */
+       bool    internal;
 } stt_client_s;
 
 
index d0b0e70..5b0cc70 100644 (file)
@@ -18,6 +18,7 @@
 #define __STT_INTERNAL_H__
 
 #include <tizen.h>
+#include <stt.h>
 
 /**
  * @file stt_internal.h
@@ -88,6 +89,41 @@ int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* use
 */
 int stt_unset_speech_status_cb(stt_h stt);
 
+/**
+ * @brief Sets server STT.
+ * @details Using this API, the application can set server STT with a @a key as a @a user_data
+ *     The key is a private data to set STT server.
+ *     There are 3 types of keys; "server", "rampcode" and "epd".
+ *             "server": STT server address
+ *             "rampcode": ASR ramp code
+ *             "epd": A threshold for end-point detection
+ *
+ *     The application can input the @a user_data corresponding to the @a key.
+ *             "server": "qa", "sbx"
+ *             "rampcode": "dash_dict", "dash_da"
+ *             "epd": "100", "750", etc
+ *
+ *  If the application sets those keys, it will be able to use corresponding STT engines and options.
+ *
+ * @since_tizen 3.0
+ * @privilege %http://tizen.org/privilege/recorder
+ *
+ * @param[in] stt The STT handle
+ * @param[in] key The key
+ * @param[in] user_data The user data corresponding to the key
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #STT_ERROR_NONE Successful
+ * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #STT_ERROR_INVALID_STATE Invalid state
+ * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
+ * @retval #STT_ERROR_OUT_OF_MEMORY STT Out of memory
+ * @retval #STT_ERROR_PERMISSION_DENIED Permission denied
+ *
+ * @pre The state should be #STT_STATE_READY.
+ */
+int stt_set_server_stt(stt_h stt, const char* key, char* user_data);
+
 #ifdef __cplusplus
 }
 #endif