Initial refactoring merge 00/19100/1 accepted/tizen_3.0.2014.q3_common accepted/tizen_3.0.m14.3_ivi accepted/tizen_generic accepted/tizen_ivi_panda tizen_3.0.2014.q3_common tizen_3.0.2014.q4_common tizen_3.0.2015.q1_common tizen_3.0.m14.2_ivi tizen_3.0.m14.3_ivi tizen_3.0_ivi accepted/tizen/generic/20140408.094943 accepted/tizen/ivi/20140410.192408 accepted/tizen/ivi/panda/20140408.203143 accepted/tizen/mobile/20140409.082553 submit/tizen/20140408.080722 submit/tizen_mobile/20141120.000000 tizen_3.0.2014.q3_common_release tizen_3.0.m14.2_ivi_release tizen_3.0.m14.3_ivi_release tizen_3.0_ivi_release
authorDongchul Lim <dc7.lim@samsung.com>
Mon, 7 Apr 2014 10:55:20 +0000 (19:55 +0900)
committerDongchul Lim <dc7.lim@samsung.com>
Mon, 7 Apr 2014 10:55:39 +0000 (19:55 +0900)
Change-Id: I9aa6a52f9291ddca0fdb14fde41642ef9eae9772

AUTHORS [deleted file]
CMakeLists.txt
packaging/telephony-daemon.spec
src/main.c
src/monitor.c
src/monitor.h

diff --git a/AUTHORS b/AUTHORS
deleted file mode 100644 (file)
index 0e9faa9..0000000
--- a/AUTHORS
+++ /dev/null
@@ -1,6 +0,0 @@
-Jongman Park <jman.park@samsung.com>
-Ja-young Gu <jygu@samsung.com>
-Kyeongchul Kim <kyeongchul.kim@samsung.com>
-DongHoo Park <donghoo.park@samsung.>
-Youngman Park <youngman.park@samsung.com>
-Inho Oh <inho48.oh@samsung.com>
index 4098ad7..b5f66fe 100644 (file)
@@ -16,29 +16,38 @@ ENDFOREACH(flag)
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/)
 
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Werror -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align")
 
 ADD_DEFINITIONS("-DFEATURE_TLOG_DEBUG")
-ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"TELEPHONY_DAEMON\"")
+ADD_DEFINITIONS("-DTCORE_LOG_TAG=\"DAEMON\"")
 ADD_DEFINITIONS("-DDAEMON_VERSION=\"${VERSION}\"")
+ADD_DEFINITIONS("-DDEFAULT_PLUGINS_PATH=\"/usr/lib/telephony/plugins/\"")
+
+IF (ENABLE_MONITOR)
+       ADD_DEFINITIONS("-DENABLE_MONITOR")
+ENDIF (ENABLE_MONITOR)
 
 MESSAGE(${CMAKE_C_FLAGS})
 MESSAGE(${pkgs_LDFLAGS})
 
+IF (ENABLE_MONITOR)
 SET(SRCS
-               src/main.c
-               src/monitor.c
+        src/main.c
+        src/monitor.c
 )
-
+ELSE (ENABLE_MONITOR)
+SET(SRCS
+        src/main.c
+)
+ENDIF (ENABLE_MONITOR)
 
 # binary build
-ADD_EXECUTABLE(telephony-daemon ${SRCS})
-TARGET_LINK_LIBRARIES(telephony-daemon ${pkgs_LDFLAGS} "-ldl")
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl")
 
 
 # install
-INSTALL(TARGETS telephony-daemon
-               RUNTIME DESTINATION bin)
+INSTALL(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
 
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME telephony-daemon)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/telephony.service DESTINATION /usr/lib/systemd/system)
index 8455561..e81c809 100644 (file)
@@ -1,9 +1,13 @@
+%define major 3
+%define minor 0
+%define patchlevel 1
+
 Name:       telephony-daemon
+Version:        %{major}.%{minor}.%{patchlevel}
+Release:        1
+License:        Apache-2.0
 Summary:    Telephony daemon
-Version:    0.1.13
-Release:    2
 Group:      System/Telephony
-License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source1001:    telephony-daemon.manifest
 BuildRequires:  cmake
index efd2959..90c4961 100644 (file)
@@ -1,15 +1,14 @@
 /*
  * telephony-daemon
  *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Ja-young Gu <jygu@samsung.com>
+ * Copyright 2013 Samsung Electronics Co. Ltd.
+ * Copyright 2013 Intel Corporation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://www.apache.org/licenses/LICENSE-2.0
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * limitations under the License.
  */
 
-#include <systemd/sd-daemon.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <pthread.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <time.h>
+
 #include <dlfcn.h>
 #include <getopt.h>
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/sysinfo.h>
+#include <systemd/sd-daemon.h>
 
 #include <glib.h>
-#include <glib-object.h>
 #include <dlog.h>
 
+#ifdef ENABLE_MONITOR
+#include "monitor.h"
+#endif
+
 #include <tcore.h>
-#include <plugin.h>
 #include <server.h>
-#include <util.h>
-#include <log.h>
-
-#include "monitor.h"
+#include <plugin.h>
 
 #ifndef DAEMON_VERSION
 #define DAEMON_VERSION "unknown"
 #endif
 
-static Server *_server;
+#ifndef DEFAULT_PLUGINS_PATH
+#define DEFAULT_PLUGINS_PATH "/usr/lib/telephony/plugins/"
+#endif
 
-void tcore_log(enum tcore_log_type type, enum tcore_log_priority priority, const char *tag, const char *fmt, ...)
+#define NOTUSED(var) (var = var)
+
+static Server *_server = NULL;
+
+static void __usage_info(const gchar *exec)
+{
+       printf("Usage: %s [OPTION]... [PLUGIN_PATH]\n", exec);
+       printf("\n");
+       printf("  -T, --testload\t run with plugin load test mode and exit\n");
+       printf("  -h, --help\t\t display this help and exit\n");
+       printf("\n");
+}
+
+void tcore_log(enum tcore_log_type type, enum tcore_log_priority priority, const gchar *tag, const gchar *fmt, ...)
 {
        va_list ap;
-       char buf[1024];
+       gchar buf[1024];
 
        va_start(ap, fmt);
        vsnprintf(buf, 1023, fmt, ap);
@@ -61,189 +71,275 @@ void tcore_log(enum tcore_log_type type, enum tcore_log_priority priority, const
        __dlog_print(type, priority, tag, buf);
 }
 
-static gboolean load_plugins(Server *s, const char *path, int flag_test_load)
+static void glib_log(const gchar *log_domain, GLogLevelFlags log_level,
+               const gchar *msg, gpointer user_data)
 {
-       const gchar *file;
-       char *filename;
-       GDir *dir;
-       void *handle;
-       GSList *list;
-       struct stat stat_buf;
-       char file_date[27];
+       NOTUSED(log_domain);
+       NOTUSED(log_level);
+       NOTUSED(user_data);
 
-       TcorePlugin *p;
-       struct tcore_plugin_define_desc *desc;
+       __dlog_print (LOG_ID_RADIO, DLOG_ERROR, "GLIB", msg);
+}
 
-       if ((path == NULL) || (s == NULL))
+#ifdef ENABLE_MONITOR
+static void telephony_signal_handler(gint signo)
+{
+       if (_server == NULL) {
+               err("Server is NULL");
+               return;
+       }
+
+       switch (signo) {
+       case SIGUSR1: {
+               monitor_server_state(_server);
+       } break;
+
+       case SIGTERM: {
+               tcore_server_free(_server);
+       } break;
+
+       default: {
+               warn("*~*~*~* Unhandled Signal: [%d] *~*~*~*", signo);
+       } break;
+       } /* end switch */
+}
+#endif
+
+static void __log_uptime()
+{
+       float a = 0.00, b = 0.00;
+       FILE *fp = fopen("/proc/uptime", "r");
+       g_return_if_fail(NULL != fp);
+
+       info("Scanned %d items", fscanf(fp, "%f %f", &a, &b));
+       info("proc uptime = %f idletime = %f\n", a, b);
+
+       fclose(fp);
+}
+
+static gboolean __init_plugin(TcorePlugin *plugin)
+{
+       const struct tcore_plugin_define_desc *desc = tcore_plugin_get_description(plugin);
+
+       if ((desc == NULL) || (desc->init == NULL)) {
+               err("desc: [%p] desc->init: [%p]", desc, (desc ? desc->init : NULL));
                return FALSE;
+       }
 
-       dir = g_dir_open(path, 0, NULL);
-       if (dir == NULL)
+       if (desc->init(plugin) == FALSE) {              /* TODO: Remove plugin from server */
+               gchar *plugin_name = tcore_plugin_get_filename(plugin);
+               if (plugin_name != NULL) {
+                       err("Plug-in '%s' init failed!!!", plugin_name);
+                       tcore_free(plugin_name);
+               }
                return FALSE;
+       }
 
-       while ((file = g_dir_read_name(dir)) != NULL) {
-               if (g_str_has_prefix(file, "lib") == TRUE
-                               || g_str_has_suffix(file, ".so") == FALSE)
-                       continue;
+       return TRUE;
+}
 
-               filename = g_build_filename(path, file, NULL);
+static gboolean init_plugins(Server *s)
+{
+       GSList *list = tcore_server_ref_plugins(s);
 
-               handle = dlopen(filename, RTLD_NOW);
-               if (handle == NULL) {
-                       dbg("fail to load '%s': %s", filename, dlerror());
-                       g_free(filename);
+       while (list != NULL) {
+               if (G_UNLIKELY(FALSE == __init_plugin(list->data))) {
+                       list = g_slist_next(list);
                        continue;
                }
+               list = g_slist_next(list);
+       }
 
-               if (flag_test_load) {
-                       dbg("success to load '%s'", filename);
-                       dlclose(handle);
-                       g_free(filename);
-                       continue;
-               }
+       info("[TIME_CHECK] plugin init finished");
+       return TRUE;
+}
 
-               desc = dlsym(handle, "plugin_define_desc");
-               if (desc == NULL) {
-                       dbg("fail to load symbol: %s", dlerror());
-                       dlclose(handle);
-                       g_free(filename);
-                       continue;
-               }
+static void *__load_plugin(const gchar *filename, struct tcore_plugin_define_desc **desc_out)
+{
+       void *handle;
+       struct tcore_plugin_define_desc *desc;
+       struct stat stat_buf;
+       gchar file_date[27];
+
+       handle = dlopen(filename, RTLD_NOW);
+       if (G_UNLIKELY(NULL == handle)) {
+               err("Failed to open '%s': %s", filename, dlerror());
+               return NULL;
+       }
+
+       desc = dlsym(handle, "plugin_define_desc");
+       if (G_UNLIKELY(NULL == desc)) {
+               err("Failed to load symbol: %s", dlerror());
+
+               dlclose(handle);
+               return NULL;
+       }
+
+       dbg("'%s' plugin", desc->name);
+       dbg(" - path = %s", filename);
+       dbg(" - version = %d", desc->version);
+       dbg(" - priority = %d", desc->priority);
 
-               dbg("%s plugin", desc->name);
-               dbg(" - path = %s", filename);
-               dbg(" - version = %d", desc->version);
-               dbg(" - priority = %d", desc->priority);
+       memset(&stat_buf, 0x00, sizeof(stat_buf));
+       memset(&file_date, '\0', sizeof(file_date));
 
-               memset(&stat_buf, 0, sizeof(struct stat));
-               if (stat(filename, &stat_buf) == 0) {
-                       if (ctime_r(&stat_buf.st_mtime, file_date) != NULL) {
-                               if (strlen(file_date) > 1)
-                                       file_date[strlen(file_date)-1] = '\0';
+       if (stat(filename, &stat_buf) == 0) {
+               if (ctime_r(&stat_buf.st_mtime, file_date) != NULL) {
+                       if (strlen(file_date) > 1)
+                               file_date[strlen(file_date)-1] = '\0';
 
-                               dbg(" - date = %s", file_date);
-                       }
+                       dbg(" - date = %s", file_date);
                }
+       }
+
+       if (G_LIKELY(desc->load)) {
+               if (G_UNLIKELY(desc->load() == FALSE)) {
+                       warn("Failed to load Plug-in");
 
-               if (desc->load) {
-                       if (desc->load() == FALSE) {
-                               dbg("false return from load(). skip this plugin");
-                               dlclose(handle);
-                               g_free(filename);
-                               continue;
-                       }
+                       dlclose(handle);
+                       return NULL;
                }
+       }
 
-               p = tcore_plugin_new(s, desc, filename, handle);
-               tcore_server_add_plugin(s, p);
+       if (desc_out != NULL)
+               *desc_out = desc;
 
-               dbg("%s added", desc->name);
-               g_free(filename);
+       return handle;
+}
+
+static gboolean load_plugins(Server *s, const gchar *path, gboolean flag_test_load)
+{
+       const gchar *file = NULL;
+       gchar *filename = NULL;
+       GDir *dir = NULL;
+       void *handle = NULL;
+       struct tcore_plugin_define_desc *desc = NULL;
+
+       if ((path == NULL) || (s == NULL)) {
+               err("path: [%p] s: [%p]", path, s);
+               return FALSE;
        }
-       g_dir_close(dir);
 
-       info("plugin load finished");
+       dir = g_dir_open(path, 0, NULL);
+       if (dir == NULL) {
+               err("Failed to open directory '%s'", path);
+               return FALSE;
+       }
 
-       list = tcore_server_ref_plugins(s);
-       for (; list; list = list->next) {
-               p = list->data;
-               if (p == NULL)
+       while ((file = g_dir_read_name(dir)) != NULL) {
+               if (g_str_has_prefix(file, "lib") == TRUE
+                               || g_str_has_suffix(file, ".so") == FALSE)
                        continue;
 
-               desc = (struct tcore_plugin_define_desc *)tcore_plugin_get_description(p);
-               if (desc == NULL)
-                       continue;
+               filename = g_build_filename(path, file, NULL);
 
-               if (desc->init == NULL)
+               /* Load a plugin */
+               if (G_UNLIKELY((handle = __load_plugin(filename, &desc)) == NULL)) {
+                       g_free(filename);
                        continue;
-
-               if (desc->init(p) == FALSE) {
-                       dbg("plugin(%s) init failed.", tcore_plugin_get_filename(p));
                }
-       }
 
-       info("plugin init finished");
+               /* Don't add to server if flag_test_load */
+               if (flag_test_load) {
+                       dbg("Loading '%s' - Successful", filename);
 
-       return TRUE;
-}
+                       dlclose(handle);
+                       g_free(filename);
+                       continue;
+               }
 
-static void usage(const char *name)
-{
-       printf("Usage: %s [OPTION]... [PLUGIN_PATH]\n", name);
-       printf("\n");
-       printf("  -T, --testload\t run with plugin load test mode and exit\n");
-       printf("  -h, --help\t\t display this help and exit\n");
-       printf("\n");
-}
+               /* Add Plug-in to Server Plug-in list */
+               tcore_server_add_plugin(s, tcore_plugin_new(s, desc, filename, handle));
+               dbg("'%s' added", desc->name);
 
-static void on_signal_usr1(int signo)
-{
-       if (_server == NULL)
-               return;
+               g_free(filename);
+       }
+
+       g_dir_close(dir);
+       info("[TIME_CHECK] Plug-in load finished");
 
-       monitor_server_state(_server);
+       return TRUE;
 }
 
-int main(int argc, char *argv[])
+gint main(gint argc, gchar *argv[])
 {
-       struct sigaction sigact_usr1;
+#ifdef ENABLE_MONITOR
+       struct sigaction sigact;
+#endif
        Server *s;
-       int flag_test_load = 0;
-       int opt;
-       int opt_index;
+       gboolean flag_test_load = FALSE;
+       gint opt = 0, opt_index = 0, ret_code = EXIT_SUCCESS;
        struct option options[] = {
-                       { "help", 0, 0, 0 },
-                       { "testload", 0, &flag_test_load, 1 },
-                       { 0, 0, 0, 0 }
+               { "help", 0, 0, 0 },
+               { "testload", 0, &flag_test_load, 1 },
+               { 0, 0, 0, 0 }
        };
-       char *plugin_path = "/usr/lib/telephony/plugins/";
-       char *tcore_ver;
-       struct sysinfo info;
-
-       if (sysinfo(&info) == 0) {
-               info("uptime: %ld secs", info.uptime);
-       }
+       gchar *plugin_path = DEFAULT_PLUGINS_PATH;
+       gchar *tcore_ver = NULL;
+       struct sysinfo sys_info;
 
-       info("daemon version: %s", DAEMON_VERSION);
+       /* System Uptime */
+       if (sysinfo(&sys_info) == 0)
+               info("uptime: %ld secs", sys_info.uptime);
+       __log_uptime();
 
+       /* Version Info */
        tcore_ver = tcore_util_get_version();
+       info("daemon version: %s", DAEMON_VERSION);
        info("libtcore version: %s", tcore_ver);
-       free(tcore_ver);
-
-       sigact_usr1.sa_handler = on_signal_usr1;
-       sigemptyset(&sigact_usr1.sa_mask);
-       sigaddset(&sigact_usr1.sa_mask, SIGUSR1);
-       sigact_usr1.sa_flags = 0;
-
-       if (sigaction(SIGUSR1, &sigact_usr1, NULL) < 0) {
+       tcore_free(tcore_ver);
+       info("glib version: %u.%u.%u", glib_major_version, glib_minor_version, glib_micro_version);
+
+#ifdef ENABLE_MONITOR
+       /* Signal Registration */
+       sigact.sa_handler = telephony_signal_handler;
+       sigemptyset(&sigact.sa_mask);
+       sigact.sa_flags = 0;
+       if (sigaction(SIGTERM, &sigact, NULL) < 0)
+               warn("sigaction(SIGTERM) failed.");
+       if (sigaction(SIGUSR1, &sigact, NULL) < 0)
                warn("sigaction(SIGUSR1) failed.");
-       }
 
-       while (1) {
-               opt = getopt_long(argc, argv, "hT", options, &opt_index);
+       /* Additional signals for dedugging the cause of Telephony crash */
+       if (sigaction(SIGINT, &sigact, NULL) < 0)
+               warn("sigaction(SIGINT) failed.");
+       if (sigaction(SIGABRT, &sigact, NULL) < 0)
+               warn("sigaction(SIGABRT) failed.");
+       if (sigaction(SIGHUP, &sigact, NULL) < 0)
+               warn("sigaction(SIGHUP) failed.");
+       if (sigaction(SIGSEGV, &sigact, NULL) < 0)
+               warn("sigaction(SIGSEGV) failed.");
+       if (sigaction(SIGXCPU, &sigact, NULL) < 0)
+               warn("sigaction(SIGXCPU) failed.");
+       if (sigaction(SIGQUIT, &sigact, NULL) < 0)
+               warn("sigaction(SIGQUIT) failed.");
+#endif
 
+       /* Commandline option parser TODO: Replace with GOptionContext */
+       while (TRUE) {
+               opt = getopt_long(argc, argv, "hT", options, &opt_index);
                if (opt == -1)
                        break;
 
                switch (opt) {
-                       case 0:
-                               switch (opt_index) {
-                                       case 0: // help
-                                               usage(argv[0]);
-                                               return 0;
-                                               break;
-                               }
-                               break;
-
-                       case 'h':
-                               usage(argv[0]);
+               case 0: {
+                       switch (opt_index) {
+                       case 0: {
+                               __usage_info(argv[0]);
                                return 0;
-                               break;
-
-                       case 'T':
-                               flag_test_load = 1;
-                               break;
-               }
+                       } break;
+                       } /* end switch */
+               } break;
+
+               case 'h': {
+                       __usage_info(argv[0]);
+                       return 0;
+               } break;
+
+               case 'T': {
+                       flag_test_load = TRUE;
+               } break;
+               } /* end switch */
        }
 
        if (optind < argc)
@@ -251,43 +347,54 @@ int main(int argc, char *argv[])
 
        info("plugin_path: [%s]", plugin_path);
 
-#if !GLIB_CHECK_VERSION(2,35,0)
+#if !GLIB_CHECK_VERSION(2, 35, 0)
        g_type_init();
 #endif
-#if !GLIB_CHECK_VERSION (2, 31, 0)
+#if !GLIB_CHECK_VERSION(2, 31, 0)
        g_thread_init(NULL);
 #endif
 
        s = tcore_server_new();
-       if (s == NULL) {
+       if (G_UNLIKELY(NULL == s)) {
                err("server_new failed.");
-               goto end;
+               return EXIT_FAILURE;
        }
        _server = s;
 
-       if (load_plugins(s, plugin_path, flag_test_load) == FALSE)
-               goto free_end;
+       g_log_set_default_handler(glib_log, s);
+
+       /* Load Plugins */
+       if (G_UNLIKELY(FALSE == load_plugins(s, (const gchar *)plugin_path, flag_test_load))) {
+               err("load_plugins failed.");
+               ret_code = EXIT_FAILURE;
+               goto END;
+       }
+
+       if (flag_test_load) {
+               ret_code = EXIT_SUCCESS;
+               goto END;
+       }
 
-       if (flag_test_load)
-               goto free_end;
+       /* Initialize Plugins */
+       if (G_UNLIKELY(FALSE == init_plugins(s))) {
+               err("init_plugins failed.");
+               ret_code = EXIT_FAILURE;
+               goto END;
+       }
 
-       info("server mainloop start");
+       info("Server mainloop start");
 
        /* Notification to systemd */
        sd_notify(0, "READY=1");
 
-       if (tcore_server_run(s) == FALSE) {
-               err("server_run failed.");
+       /* Server Run */
+       if (G_UNLIKELY(FALSE == tcore_server_run(s))) {
+               err("Server_run - Failed!!!");
+               ret_code = EXIT_FAILURE;
        }
 
-       /*
-        * RUNNING
-        */
-
-free_end:
-       info("server end");
+END:
        tcore_server_free(s);
 
-end:
-       return EXIT_SUCCESS;
+       return ret_code;
 }
index c0bf9da..8643b85 100644 (file)
@@ -1,15 +1,14 @@
 /*
  * telephony-daemon
  *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Ja-young Gu <jygu@samsung.com>
+ * Copyright 2013 Samsung Electronics Co. Ltd.
+ * Copyright 2013 Intel Corporation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://www.apache.org/licenses/LICENSE-2.0
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * limitations under the License.
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <pthread.h>
-#include <unistd.h>
 #include <stdlib.h>
-#include <time.h>
-#include <dlfcn.h>
-#include <getopt.h>
 
 #include <glib.h>
-#include <glib-object.h>
 
-#include <tcore.h>
-#include <plugin.h>
+#include "monitor.h"
+
 #include <server.h>
-#include <hal.h>
+#include <communicator.h>
+#include <plugin.h>
+//#include <hal.h>
+#include <core_object.h>
 #include <queue.h>
 #include <storage.h>
-#include <communicator.h>
-#include <user_request.h>
 
-#include "monitor.h"
+#define NOTUSED(var) (var = var)
 
-/* Hacking TcoreQueue */
+/* hacking TcoreQueue */
 struct tcore_queue_type {
        TcorePlugin *plugin;
        GQueue *gq;
 };
 
+static void _hash_dump(gpointer key, gpointer value, gpointer user_data)
+{
+       NOTUSED(user_data);
+
+       msg("         - %s: [%s]", key, value);
+}
+
+static void _monitor_core_objects(GSList *list)
+{
+       CoreObject *co;
+       GHashTable *prop = NULL;
+
+       while (list) {
+               co = list->data;
+
+               msg("       Type: 0x%x", tcore_object_get_type(co));
+               msg("       - addr: %p", co);
+               //msg("       - hal: %p", tcore_object_get_hal(co));
+
+               //prop = tcore_object_ref_property_hash(co);
+               if (prop) {
+                       msg("       - Properties: %d", g_hash_table_size(prop));
+                       g_hash_table_foreach(prop, _hash_dump, NULL);
+               }
+
+               list = g_slist_next(list);
+       }
+}
+
 static void _monitor_plugin(Server *s)
 {
        GSList *list;
-       TcorePlugin *p;
+       GSList *co_list = NULL;
+       TcorePlugin *plugin;
        char *str;
 
        msg("-- Plugins --");
 
        list = tcore_server_ref_plugins(s);
-       if (list == NULL)
-               return;
+       while (list) {
+               plugin = list->data;
+               if (plugin != NULL) {
+                       msg("Name: [%s]", tcore_plugin_get_description(plugin)->name);
 
-       do {
-               p = list->data;
+                       str = tcore_plugin_get_filename(plugin);
+                       if (str) {
+                               msg(" - file: %s", str);
+                               tcore_free(str);
+                       }
 
-               msg("Name: [%s]", tcore_plugin_get_description(p)->name);
+                       msg(" - addr: %p", plugin);
+                       msg(" - userdata: %p", tcore_plugin_ref_user_data(plugin));
 
-               str = tcore_plugin_get_filename(p);
-               msg(" - file: %s", str);
-               if (str)
-                       free(str);
+                       co_list = tcore_plugin_ref_core_objects(plugin);
+                       if (co_list) {
+                               msg(" - core_object list: %d", g_slist_length(co_list));
 
-               msg(" - addr: %p", p);
-               msg(" - userdata: %p", tcore_plugin_ref_user_data(p));
-               msg("");
+                               _monitor_core_objects(co_list);
+                               g_slist_free(co_list);
+                       }
 
+                       msg("");
+               }
 
-               list = list->next;
-       } while (list);
+               list = g_slist_next(list);
+       }
 }
 
 static void _monitor_storage(Server *s)
 {
        GSList *list;
-       Storage *strg;
+       TcoreStorage *strg;
 
        msg("-- Storages --");
 
        list = tcore_server_ref_storages(s);
-       if (list == NULL)
-               return;
-
-       do {
+       while (list) {
                strg = list->data;
+               if (strg != NULL) {
+                       msg("Name: [%s]", tcore_storage_ref_name(strg));
+                       msg(" - addr: %p", strg);
+                       msg("");
+               }
 
-               msg("Name: [%s]", tcore_storage_ref_name(strg));
-               msg(" - addr: %p", strg);
-               msg("");
-
-               list = list->next;
-       } while (list);
+               list = g_slist_next(list);
+       }
 }
 
 static void _monitor_communicator(Server *s)
@@ -108,39 +135,34 @@ static void _monitor_communicator(Server *s)
        msg("-- Communicators --");
 
        list = tcore_server_ref_communicators(s);
-       if (list == NULL)
-               return;
-
-       do {
+       while (list) {
                comm = list->data;
-
-               msg("Name: [%s]", tcore_communicator_ref_name(comm));
-               msg(" - addr: %p", comm);
-               msg(" - parent_plugin: %p", tcore_communicator_ref_plugin(comm));
-               msg(" - userdata: %p", tcore_communicator_ref_user_data(comm));
-               msg("");
-
-               list = list->next;
-       } while (list);
+               if (comm != NULL) {
+                       msg("Name: [%s]", tcore_communicator_ref_name(comm));
+                       msg(" - addr: %p", comm);
+                       msg(" - parent_plugin: %p", tcore_communicator_ref_plugin(comm));
+                       msg(" - userdata: %p", tcore_communicator_ref_user_data(comm));
+                       msg("");
+               }
+
+               list = g_slist_next(list);
+       }
 }
 
 static void _monitor_modems(Server *s)
 {
        GSList *list;
-       TcorePlugin *p;
+       TcorePlugin *plugin;
 
        msg("-- Modems --");
 
        list = tcore_server_ref_plugins(s);
-       if (list == NULL)
-               return;
-
-       for (; list != NULL; list = g_slist_next(list)) {
-               p = list->data;
-               if (p == NULL)
-                       continue;
+       while (list) {
+               plugin = list->data;
+               if (plugin != NULL)
+                       tcore_server_print_modems(plugin);
 
-               tcore_server_print_modems(p);
+               list = g_slist_next(list);
        }
 }
 
index ac76bdf..6e3b08a 100644 (file)
@@ -1,15 +1,14 @@
 /*
  * telephony-daemon
  *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Ja-young Gu <jygu@samsung.com>
+ * Copyright 2013 Samsung Electronics Co. Ltd.
+ * Copyright 2013 Intel Corporation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://www.apache.org/licenses/LICENSE-2.0
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * limitations under the License.
  */
 
-#ifndef __MONITIR_H__
-#define __MONITOR_H__
+#pragma once
 
+#include <tcore.h>
 
 void monitor_server_state(Server *s);
-
-#endif