#define EPOLL_ERR -1
-static void _ms_connection_destroy_async_queue(gpointer data);
static void _ms_connection_module_instance_info(muse_module_h m, ms_connection_t *connection, GQueue *queue, int cmd);
-static void _ms_connection_destroy_async_queue(gpointer data)
-{
- ms_diag_msg_t *dm = (ms_diag_msg_t *)data;
-
- LOGI("diag msg (%p) free", dm);
- g_free(dm);
-}
-
static void _ms_connection_module_instance_info(muse_module_h m, ms_connection_t *connection, GQueue *queue, int cmd)
{
muse_module_h connecting_m;
char pid[MUSE_PARAM_MAX] = {'\0',};
int idx, len;
ms_diag_msg_t *dm;
+ muse_server_h ms;
muse_return_if_fail(m);
muse_return_if_fail(connection);
muse_return_if_fail(queue);
- muse_return_if_fail(ms_get_instance());
+
+ ms = ms_get_instance();
+ muse_return_if_fail(ms);
len = g_queue_get_length(queue);
strncat(pids, pid, MUSE_MSG_LEN_MAX - strlen(pids) - 1);
}
- strncpy(ms_get_instance()->instance_pid_info, pids, MUSE_MSG_LEN_MAX);
+ strncpy(ms->instance_pid_info, pids, MUSE_MSG_LEN_MAX);
dm = g_new0(ms_diag_msg_t, 1);
-
dm->cmd = cmd;
-
- g_async_queue_push(connection->msg_aq, (gpointer)dm);
+ g_async_queue_push(ms->diag.msg_aq, (gpointer)dm);
LOGW("total number of modules = %d ( %s) - %s %p from pid %d %s client (count %d)",
- len, ms_get_instance()->instance_pid_info, ms_get_command_string(cmd), m, m->pid,
+ len, ms->instance_pid_info, ms_get_command_string(cmd), m, m->pid,
ms_config_get_host_name(m->idx), connection->instance_count[m->idx]);
}
g_queue_free(connection->instance_q);
connection->instance_q = NULL;
- g_async_queue_unref(connection->msg_aq);
- connection->msg_aq = NULL;
-
g_mutex_clear(&connection->lock);
g_free(connection);
connection->instance_q = g_queue_new();
muse_return_if_fail(connection->instance_q);
- connection->msg_aq = g_async_queue_new_full(_ms_connection_destroy_async_queue);
- muse_return_if_fail(connection->msg_aq);
-
g_mutex_init(&connection->lock);
}
static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition condition, gpointer data);
#ifdef MUSE_USE_LWIPC
static void _ms_wait_event(void);
+static void _ms_diag_init(void);
+static void _ms_diag_deinit(void);
static gboolean _ms_idle_cb(gpointer user_data);
+static int _ms_open_lockfile(void);
static void _ms_wait_event(void)
{
static gpointer _ms_diag_check_connection_event_thread(gpointer data)
{
+ ms_diag_t *d;
ms_diag_msg_t *dm = NULL;
muse_return_val_if_fail(muse_server, NULL);
+ d = &muse_server->diag;
+
while (ms_is_server_ready()) {
- dm = (ms_diag_msg_t *)g_async_queue_pop(ms_get_instance()->connection->msg_aq);
+ dm = (ms_diag_msg_t *)g_async_queue_pop(d->msg_aq);
if (!dm)
continue;
g_mutex_unlock(&muse_server->state_lock);
}
+static void _ms_diag_init(void)
+{
+ ms_diag_t *d;
+ char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
+ GError *error = NULL;
+
+ muse_return_if_fail(muse_server);
+
+ d = &muse_server->diag;
+
+ d->idle_state_thread = g_thread_try_new("diag_idle_state",
+ _ms_diag_check_idle_state_thread, muse_server->main_loop, &error);
+ if (!d->idle_state_thread) {
+ snprintf(err_msg, sizeof(err_msg), "diag_idle_state_thread creation failed : %s", error->message);
+ LOGE("%s", err_msg);
+ g_error_free(error);
+ ms_log_process_info(muse_server->pid);
+ }
+
+ d->msg_aq = g_async_queue_new_full(g_free);
+ muse_return_if_fail(d->msg_aq);
+
+ d->conn_event_thread = g_thread_try_new("diag_connection_event",
+ _ms_diag_check_connection_event_thread, muse_server->main_loop, &error);
+ if (!d->conn_event_thread) {
+ snprintf(err_msg, sizeof(err_msg), "diag_connection_event_thread creation failed : %s", error->message);
+ LOGE("%s", err_msg);
+ g_error_free(error);
+ ms_log_process_info(muse_server->pid);
+ }
+}
+
+static void _ms_diag_deinit(void)
+{
+ ms_diag_t *d;
+ ms_diag_msg_t *dm;
+
+ LOGD("Enter");
+
+ muse_return_if_fail(muse_server);
+
+ d = &muse_server->diag;
+
+ dm = g_new0(ms_diag_msg_t, 1);
+
+ dm->thread_stop = TRUE;
+ LOGI("[%p] g_async_queue_push", dm);
+ g_async_queue_push_front(d->msg_aq, (gpointer)dm);
+
+ if (d->idle_state_thread) {
+ g_thread_join(d->idle_state_thread);
+ d->idle_state_thread = NULL;
+ }
+
+ if (d->conn_event_thread) {
+ g_thread_join(d->conn_event_thread);
+ d->conn_event_thread = NULL;
+ }
+
+ g_async_queue_unref(d->msg_aq);
+ d->msg_aq = NULL;
+}
+
static gboolean _ms_idle_cb(gpointer user_data)
{
if (!ms_create_ready_file())
LOGE("%s file creation is failed", MUSE_SERVER_READY);
- ms_diag_thread_create();
+ _ms_diag_init();
return G_SOURCE_REMOVE;
}
LOGD("Leave");
}
-int ms_open_lockfile(void)
+static int _ms_open_lockfile(void)
{
int fd, already_running;
char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
return MM_ERROR_NONE;
}
-void ms_diag_thread_create(void)
-{
- char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
- GError *error = NULL;
-
- muse_return_if_fail(muse_server);
-
- muse_server->diag_idle_state_thread = g_thread_try_new("diag_idle_state",
- _ms_diag_check_idle_state_thread, muse_server->main_loop, &error);
- if (!muse_server->diag_idle_state_thread && error) {
- snprintf(err_msg, sizeof(err_msg), "diag_idle_state_thread creation failed : %s", error->message);
- LOGE("%s", err_msg);
- g_error_free(error);
- ms_log_process_info(muse_server->pid);
- }
-
- muse_server->diag_connection_event_thread = g_thread_try_new("diag_connection_event",
- _ms_diag_check_connection_event_thread, muse_server->main_loop, &error);
- if (!muse_server->diag_connection_event_thread && error) {
- snprintf(err_msg, sizeof(err_msg), "diag_connection_event_thread creation failed : %s", error->message);
- LOGE("%s", err_msg);
- g_error_free(error);
- ms_log_process_info(muse_server->pid);
- }
-}
-
-void ms_diag_thread_destroy(void)
-{
- ms_diag_msg_t *dm;
-
- muse_return_if_fail(muse_server);
-
- LOGD("Enter");
-
- dm = g_new0(ms_diag_msg_t, 1);
-
- dm->thread_stop = TRUE;
- LOGI("[%p] g_async_queue_push", dm);
- g_async_queue_push_front(muse_server->connection->msg_aq, (gpointer)dm);
-
- if (muse_server->diag_idle_state_thread) {
- g_thread_join(muse_server->diag_idle_state_thread);
- muse_server->diag_idle_state_thread = NULL;
- }
-
- if (muse_server->diag_connection_event_thread) {
- g_thread_join(muse_server->diag_connection_event_thread);
- muse_server->diag_connection_event_thread = NULL;
- }
-
- LOGD("Leave");
-}
-
void ms_setup_syslog(void)
{
int flags = LOG_CONS|LOG_NDELAY|LOG_PID;
_ms_init();
- muse_return_if_fail(ms_get_instance());
-
- muse_return_if_fail(ms_open_lockfile() == MM_ERROR_NONE);
+ muse_return_if_fail(_ms_open_lockfile() == MM_ERROR_NONE);
ms_new();
trace_end();
#endif
- ms_system_subscribe_external_event(ms_get_instance()->system);
+ ms_system_subscribe_external_event(muse_server->system);
#ifdef MUSE_USE_WATCHDOG
- if (!ms_watchdog_attach(ms_get_instance()->watchdog)) {
+ if (!ms_watchdog_attach(muse_server->watchdog)) {
LOGE("watchdog thread failed");
ms_log_process_info(muse_server->pid);
return;
muse_return_val_if_fail(muse_server->log, retval);
muse_return_val_if_fail(muse_server->security, retval);
muse_return_val_if_fail(muse_server->watchdog, retval);
- muse_return_val_if_fail(muse_server->diag_idle_state_thread, retval);
- muse_return_val_if_fail(muse_server->diag_connection_event_thread, retval);
ms_recursive_rmdir(MUSE_DATA_ROOT_PATH);
ms_set_state(MUSE_SERVER_STATE_IDLE);
- ms_diag_thread_destroy();
+ _ms_diag_deinit();
#ifdef MUSE_USE_WATCHDOG
ms_watchdog_detach(muse_server->watchdog);