Support to get_module_index at muse_client 26/154526/1
authorYoungHun Kim <yh8004.kim@samsung.com>
Thu, 28 Sep 2017 23:46:22 +0000 (08:46 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Tue, 10 Oct 2017 11:06:38 +0000 (20:06 +0900)
Change-Id: I5750ee9f6a043026894b099ca829eedc816e3f8f

client/CMakeLists.txt
client/include/muse_client.h
client/src/muse_client.c
core/include/muse_core_internal.h
packaging/mused.spec
server/include/muse_server_config.h
server/include/muse_server_private.h
server/src/muse_server_config.c
server/src/muse_server_private.c

index c6883ae..1cc7111 100644 (file)
@@ -10,7 +10,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 
-SET(dependents "dlog glib-2.0 mm-common")
+SET(dependents "dlog glib-2.0 iniparser mm-common")
 SET(pc_dependents "muse-core")
 
 INCLUDE(FindPkgConfig)
index b078ffd..a0a0d5a 100644 (file)
@@ -34,6 +34,7 @@ int muse_client_close(int sock_fd);
 int muse_client_ipc_push_data(int sock_fd, const char *data, int size, uint64_t data_id);
 int muse_client_get_fd_id_value(int sock_fd);
 bool muse_client_check_fd_id_value(int sock_fd, int sock_id);
+int muse_client_get_module_index(char *module_name, int *module_index);
 
 #ifdef __cplusplus
 }
index af6d1ba..7272b9b 100644 (file)
@@ -281,3 +281,64 @@ bool muse_client_check_fd_id_value(int sock_fd, int sock_id)
        else
                return false;
 }
+
+int muse_client_get_module_index(char *module_name, int *module_index)
+{
+       int idx = 0;
+       char *str;
+       char *hosts;
+       char *host;
+       char *ptr = NULL;
+       bool module_name_matched = false;
+       dictionary *muse_client_dict;
+
+       g_return_val_if_fail(module_name, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(module_index, MM_ERROR_INVALID_ARGUMENT);
+
+       LOGD("Enter");
+
+       muse_client_dict = iniparser_load(CONFFILE);
+       g_return_val_if_fail(muse_client_dict, PARSE_ERROR);
+
+       str = iniparser_getstring(muse_client_dict, MUSE_HOST, NULL);
+       if (!str) {
+               LOGE("Error - iniparser_getstring (%s)", MUSE_HOST);
+               iniparser_freedict(muse_client_dict);
+               return PARSE_ERROR;
+       }
+
+       hosts = strdup(str);
+       if (!hosts) {
+               LOGE("Error - hosts allocation");
+               iniparser_freedict(muse_client_dict);
+               return PARSE_ERROR;
+       }
+
+       host = strtok_r(hosts, INI_PARSER_COMMA, &ptr);
+
+       while (host) {
+               g_strstrip(host);
+               if (strncmp(module_name, host, strlen(host)) == 0) {
+                       module_name_matched = true;
+                       *module_index = idx;
+                       break;
+               }
+
+               host = strtok_r(NULL, INI_PARSER_COMMA, &ptr);
+               idx++;
+       }
+
+       MUSE_FREE(hosts);
+
+       iniparser_freedict(muse_client_dict);
+
+       if (module_name_matched) {
+               LOGD("Leave");
+               return MM_ERROR_NONE;
+       } else {
+               LOGE("You have to check if [%s] is exact", module_name);
+               *module_index = MUSE_ERR;
+               LOGD("Leave");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+}
index aff8d08..1303409 100644 (file)
@@ -46,9 +46,15 @@ extern "C" {
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <iniparser.h>
 
 #undef LOG_TAG
 #define LOG_TAG "MUSED"
+
+#define CONFFILE SYSCONFDIR"/multimedia/mused.conf"
+#define MUSE_HOST "muse:hosts"
+#define INI_PARSER_COMMA ","
+
 #define MUSE_DATA_ROOT_PATH TZ_SYS_DATA_PATH"/mused/"
 #define MUSE_DEFAULT_PIDFILE "/tmp/.muse-server.pid"
 #define MUSE_SOCK_FILE0 "/tmp/.muse_server_socket"
@@ -63,6 +69,8 @@ extern "C" {
 #define MUSE_ERR -1
 #define MUSE_MAX_PARAM_NUM 10
 
+#define PARSE_ERROR -1
+
 /* message */
 #define MUSE_MSG_LEN 32
 #define MUSE_MAX_MSG_LEN 256
index fc5c9a5..21abbe0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A multimedia daemon
-Version:    0.3.9
+Version:    0.3.10
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 6a694a0..fd3e7b1 100644 (file)
@@ -30,19 +30,17 @@ extern "C" {
 #include <iniparser.h>
 
 #define CONFFILE SYSCONFDIR"/multimedia/mused.conf"
-#define MUSEHOST "muse:hosts"
-#define MUSELOG "muse:logfile"
-#define MUSELOCK "muse:lockfile"
-#define MUSEMINTIMEOUT "muse:min_timeout"
-#define MUSEMAXTIMEOUT "muse:max_timeout"
-#define MEMORYTHRESHOLD "muse:memory_threshold"
-#define MUSEGST "muse:gstparam"
-#define COLON ":"
-#define COMMA ","
+#define MUSE_LOG "muse:logfile"
+#define MUSE_LOCK "muse:lockfile"
+#define MUSE_MIN_TIMEOUT "muse:min_timeout"
+#define MUSE_MAX_TIMEOUT "muse:max_timeout"
+#define MEMORY_THRESHOLD "muse:memory_threshold"
+#define MUSE_GST "muse:gstparam"
+#define INI_PARSER_COLON ":"
 #define PATH "path"
 #define PRELOADED "preloaded"
 #define TIMEOUT "timeout"
-#define DIABLEWATCHDOGAPI "disable_watchdog_api"
+#define DIABLE_WATCHDOG_API "disable_watchdog_api"
 
 typedef struct host_info {
        char *path;
index 2566d3a..2d5b9a5 100644 (file)
@@ -62,7 +62,6 @@ void muse_server_cmd_dispatch(muse_module_h module, muse_module_command_e cmd);
 void muse_server_cmd_dispatch(muse_module_h module, muse_module_command_e cmd);
 void muse_server_worker_exit(muse_module_h module);
 void muse_server_respawn(int signo);
-int muse_server_get_api_module(char *module_name, int *api_module);
 int muse_server_get_pid(muse_module_h module);
 void muse_server_get_local_time(char *buf);
 void muse_server_main_thread_lock(void);
index e83d7c2..602730d 100644 (file)
@@ -22,8 +22,6 @@
 #include "muse_server_config.h"
 #include "muse_server_private.h"
 
-#define PARSE_ERROR -1
-
 static muse_server_config_t *g_muse_server_conf = NULL;
 
 static int _muse_server_config_parser(void);
@@ -49,9 +47,9 @@ static int _muse_server_config_parser(void)
        g_muse_server_conf->muse_dict = iniparser_load(CONFFILE);
        g_return_val_if_fail(g_muse_server_conf->muse_dict, PARSE_ERROR);
 
-       str = iniparser_getstring(g_muse_server_conf->muse_dict, MUSEHOST, NULL);
+       str = iniparser_getstring(g_muse_server_conf->muse_dict, MUSE_HOST, NULL);
        if (!str) {
-               LOGE("Error - iniparser_getstring (%s)", MUSEHOST);
+               LOGE("Error - iniparser_getstring (%s)", MUSE_HOST);
                goto out;
        }
 
@@ -61,9 +59,9 @@ static int _muse_server_config_parser(void)
                goto out;
        }
 
-       str = iniparser_getstring(g_muse_server_conf->muse_dict, MUSELOG, NULL);
+       str = iniparser_getstring(g_muse_server_conf->muse_dict, MUSE_LOG, NULL);
        if (!str) {
-               LOGE("Error - iniparser_getstring (%s)", MUSELOG);
+               LOGE("Error - iniparser_getstring (%s)", MUSE_LOG);
                goto out;
        }
 
@@ -72,9 +70,9 @@ static int _muse_server_config_parser(void)
        else
                g_muse_server_conf->log_enabled = FALSE;
 
-       str = iniparser_getstring(g_muse_server_conf->muse_dict, MUSELOCK, NULL);
+       str = iniparser_getstring(g_muse_server_conf->muse_dict, MUSE_LOCK, NULL);
        if (!str) {
-               LOGE("Error - iniparser_getstring (%s)", MUSELOCK);
+               LOGE("Error - iniparser_getstring (%s)", MUSE_LOCK);
                goto out;
        }
 
@@ -84,9 +82,9 @@ static int _muse_server_config_parser(void)
                goto out;
        }
 
-       str = iniparser_getstring(g_muse_server_conf->muse_dict, MUSEMINTIMEOUT, NULL);
+       str = iniparser_getstring(g_muse_server_conf->muse_dict, MUSE_MIN_TIMEOUT, NULL);
        if (!str) {
-               LOGE("Error - iniparser_getstring (%s)", MUSEMINTIMEOUT);
+               LOGE("Error - iniparser_getstring (%s)", MUSE_MIN_TIMEOUT);
                goto out;
        }
 
@@ -96,9 +94,9 @@ static int _muse_server_config_parser(void)
                goto out;
        }
 
-       str = iniparser_getstring(g_muse_server_conf->muse_dict, MUSEMAXTIMEOUT, NULL);
+       str = iniparser_getstring(g_muse_server_conf->muse_dict, MUSE_MAX_TIMEOUT, NULL);
        if (!str) {
-               LOGE("Error - iniparser_getstring (%s)", MUSEMAXTIMEOUT);
+               LOGE("Error - iniparser_getstring (%s)", MUSE_MAX_TIMEOUT);
                goto out;
        }
 
@@ -108,9 +106,9 @@ static int _muse_server_config_parser(void)
                goto out;
        }
 
-       str = iniparser_getstring(g_muse_server_conf->muse_dict, MEMORYTHRESHOLD, NULL);
+       str = iniparser_getstring(g_muse_server_conf->muse_dict, MEMORY_THRESHOLD, NULL);
        if (!str) {
-               LOGE("Error - iniparser_getstring (%s)", MEMORYTHRESHOLD);
+               LOGE("Error - iniparser_getstring (%s)", MEMORY_THRESHOLD);
                goto out;
        }
 
@@ -123,7 +121,7 @@ static int _muse_server_config_parser(void)
        g_muse_server_conf->gst_param_cnt = 0;
        for (; g_muse_server_conf->gst_param_cnt < MUSE_MAX_PARAM_NUM; g_muse_server_conf->gst_param_cnt++) {
                memset(gst_param_value, 0, MUSE_MAX_MSG_LEN);
-               snprintf(gst_param_value, strlen(MUSEGST) + 3, "%s%d", MUSEGST, g_muse_server_conf->gst_param_cnt + 1);
+               snprintf(gst_param_value, strlen(MUSE_GST) + 3, "%s%d", MUSE_GST, g_muse_server_conf->gst_param_cnt + 1);
 
                str = iniparser_getstring(g_muse_server_conf->muse_dict, gst_param_value, NULL);
                g_strstrip(str);
@@ -142,7 +140,7 @@ static int _muse_server_config_parser(void)
        }
 
        g_muse_server_conf->host_cnt = 0;
-       host = strtok_r(g_muse_server_conf->hosts, COMMA, &ptr);
+       host = strtok_r(g_muse_server_conf->hosts, INI_PARSER_COMMA, &ptr);
 
        while (host) {
                host_cnt = g_muse_server_conf->host_cnt;
@@ -156,7 +154,7 @@ static int _muse_server_config_parser(void)
                }
 
                /* path */
-               snprintf(host_name, MUSE_MAX_MSG_LEN, "%s%s%s", host, COLON, PATH);
+               snprintf(host_name, MUSE_MAX_MSG_LEN, "%s%s%s", host, INI_PARSER_COLON, PATH);
 
                g_muse_server_conf->host_infos[host_cnt] = (host_info_t *) calloc(1, sizeof(host_info_t));
                if (!g_muse_server_conf->host_infos[host_cnt]) {
@@ -174,7 +172,7 @@ static int _muse_server_config_parser(void)
                LOGD("[%d] %s", host_cnt, g_muse_server_conf->host_infos[host_cnt]->path);
 
                /* preloaded */
-               snprintf(host_name, MUSE_MAX_MSG_LEN, "%s%s%s", host, COLON, PRELOADED);
+               snprintf(host_name, MUSE_MAX_MSG_LEN, "%s%s%s", host, INI_PARSER_COLON, PRELOADED);
 
                g_muse_server_conf->host_infos[host_cnt]->preloaded =
                        strdup(iniparser_getstring(g_muse_server_conf->muse_dict, host_name, NULL));
@@ -184,7 +182,7 @@ static int _muse_server_config_parser(void)
                }
 
                /* timeout */
-               snprintf(host_name, MUSE_MAX_MSG_LEN, "%s%s%s", host, COLON, TIMEOUT);
+               snprintf(host_name, MUSE_MAX_MSG_LEN, "%s%s%s", host, INI_PARSER_COLON, TIMEOUT);
 
                g_muse_server_conf->host_infos[host_cnt]->timeout =
                        atoi(iniparser_getstring(g_muse_server_conf->muse_dict, host_name, NULL));
@@ -197,12 +195,12 @@ static int _muse_server_config_parser(void)
                }
 
                /* disable_watchdog_api */
-               snprintf(host_name, MUSE_MAX_MSG_LEN, "%s%s%s", host, COLON, DIABLEWATCHDOGAPI);
+               snprintf(host_name, MUSE_MAX_MSG_LEN, "%s%s%s", host, INI_PARSER_COLON, DIABLE_WATCHDOG_API);
 
                g_muse_server_conf->host_infos[host_cnt]->disable_watchdog_api =
                        atoi(iniparser_getstring(g_muse_server_conf->muse_dict, host_name, NULL));
 
-               host = strtok_r(NULL, COMMA, &ptr);
+               host = strtok_r(NULL, INI_PARSER_COMMA, &ptr);
                g_muse_server_conf->host_cnt++;
                MUSE_FREE(host_name);
        }
@@ -227,7 +225,7 @@ static void _muse_server_config_free(void)
                iniparser_freedict(g_muse_server_conf->muse_dict);
 
        if (g_muse_server_conf->hosts) {
-               host = strtok_r(g_muse_server_conf->hosts, COMMA, &ptr);
+               host = strtok_r(g_muse_server_conf->hosts, INI_PARSER_COMMA, &ptr);
                g_muse_server_conf->host_cnt = 0;
 
                while (host) {
@@ -235,7 +233,7 @@ static void _muse_server_config_free(void)
                        MUSE_FREE(g_muse_server_conf->host_infos[g_muse_server_conf->host_cnt]->path);
                        MUSE_FREE(g_muse_server_conf->host_infos[g_muse_server_conf->host_cnt]->preloaded);
                        MUSE_FREE(g_muse_server_conf->host_infos[g_muse_server_conf->host_cnt]);
-                       host = strtok_r(NULL, COMMA, &ptr);
+                       host = strtok_r(NULL, INI_PARSER_COMMA, &ptr);
                        g_muse_server_conf->host_cnt++;
                }
 
index afcf5d2..243ef06 100644 (file)
@@ -520,24 +520,6 @@ void muse_server_respawn(int signo)
        _muse_server_thread_kill(signo);
 }
 
-int muse_server_get_api_module(char *module_name, int *api_module)
-{
-       int idx;
-       g_return_val_if_fail(module_name, MM_ERROR_INVALID_ARGUMENT);
-       g_return_val_if_fail(api_module, MM_ERROR_INVALID_ARGUMENT);
-
-       for (idx = 0; idx < muse_server_config_get_instance()->host_cnt; idx++) {
-               if (strncmp(module_name, muse_server_config_get_instance()->host[idx], strlen(muse_server_config_get_instance()->host[idx])) == 0) {
-                       *api_module = idx;
-                       break;
-               }
-       }
-
-       g_return_val_if_fail(idx < muse_server_config_get_instance()->host_cnt, MM_ERROR_NOT_IMPLEMENTED);
-
-       return MM_ERROR_NONE;
-}
-
 int muse_server_get_pid(muse_module_h module)
 {
        g_return_val_if_fail(module, MUSE_ERR);