Bump version to fix build issue
[profile/ivi/telephony-daemon.git] / src / main.c
index f26894e..bb905f9 100644 (file)
 #include <time.h>
 #include <dlfcn.h>
 #include <getopt.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sysinfo.h>
 
 #include <glib.h>
 #include <glib-object.h>
+#include <dlog.h>
 
 #include <tcore.h>
 #include <plugin.h>
 #include <server.h>
+#include <util.h>
+#include <log.h>
 
 #include "monitor.h"
 
+#ifndef DAEMON_VERSION
+#define DAEMON_VERSION "unknown"
+#endif
+
 static Server *_server;
 
+void tcore_log(enum tcore_log_type type, enum tcore_log_priority priority, const char *tag, const char *fmt, ...)
+{
+       va_list ap;
+       char buf[1024];
+
+       va_start(ap, fmt);
+       vsnprintf(buf, 1023, fmt, ap);
+       va_end(ap);
+
+       __dlog_print(type, priority, tag, buf);
+}
+
 static gboolean load_plugins(Server *s, const char *path, int flag_test_load)
 {
        const gchar *file;
@@ -45,16 +67,22 @@ static gboolean load_plugins(Server *s, const char *path, int flag_test_load)
        GDir *dir;
        void *handle;
        GSList *list;
+       struct stat stat_buf;
+       char file_date[27];
 
        TcorePlugin *p;
        struct tcore_plugin_define_desc *desc;
 
+       if (!path || !s)
+               return FALSE;
+
        dir = g_dir_open(path, 0, NULL);
        if (!dir)
                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)
+               if (g_str_has_prefix(file, "lib") == TRUE
+                               || g_str_has_suffix(file, ".so") == FALSE)
                        continue;
 
                filename = g_build_filename(path, file, NULL);
@@ -81,6 +109,21 @@ static gboolean load_plugins(Server *s, const char *path, int flag_test_load)
                        continue;
                }
 
+               dbg("%s plugin", desc->name);
+               dbg(" - path = %s", filename);
+               dbg(" - version = %d", desc->version);
+               dbg(" - priority = %d", desc->priority);
+
+               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';
+
+                               dbg(" - date = %s", file_date);
+                       }
+               }
+
                if (desc->load) {
                        if (desc->load() == FALSE) {
                                dbg("false return from load(). skip this plugin");
@@ -93,11 +136,13 @@ static gboolean load_plugins(Server *s, const char *path, int flag_test_load)
                p = tcore_plugin_new(s, desc, filename, handle);
                tcore_server_add_plugin(s, p);
 
-               dbg("plugin(%s) added", filename);
+               dbg("%s added", desc->name);
                g_free(filename);
        }
        g_dir_close(dir);
 
+       info("plugin load finished");
+
        list = tcore_server_ref_plugins(s);
        for (; list; list = list->next) {
                p = list->data;
@@ -116,6 +161,8 @@ static gboolean load_plugins(Server *s, const char *path, int flag_test_load)
                }
        }
 
+       info("plugin init finished");
+
        return TRUE;
 }
 
@@ -140,7 +187,7 @@ int main(int argc, char *argv[])
 {
        struct sigaction sigact_usr1;
        Server *s;
-       int flag_test_load=0;
+       int flag_test_load = 0;
        int opt;
        int opt_index;
        struct option options[] = {
@@ -149,6 +196,18 @@ int main(int argc, char *argv[])
                        { 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);
+       }
+
+       info("daemon version: %s", DAEMON_VERSION);
+
+       tcore_ver = tcore_util_get_version();
+       info("libtcore version: %s", tcore_ver);
+       free(tcore_ver);
 
        sigact_usr1.sa_handler = on_signal_usr1;
        sigemptyset(&sigact_usr1.sa_mask);
@@ -159,7 +218,6 @@ int main(int argc, char *argv[])
                warn("sigaction(SIGUSR1) failed.");
        }
 
-
        while (1) {
                opt = getopt_long(argc, argv, "hT", options, &opt_index);
 
@@ -187,12 +245,10 @@ int main(int argc, char *argv[])
                }
        }
 
-       if (optind < argc) {
+       if (optind < argc)
                plugin_path = argv[optind];
-       }
 
-       dbg("plugin_path: [%s]", plugin_path);
-       dbg("flag[test_load]: %d", flag_test_load);
+       info("plugin_path: [%s]", plugin_path);
 
        g_type_init();
 #if !GLIB_CHECK_VERSION (2, 31, 0)
@@ -206,16 +262,16 @@ int main(int argc, char *argv[])
        }
        _server = s;
 
-       if (!load_plugins(s, plugin_path, flag_test_load)) {
+       if (!load_plugins(s, plugin_path, flag_test_load))
                goto free_end;
-       }
 
        if (flag_test_load)
                goto free_end;
 
+       info("server mainloop start");
+
        if (tcore_server_run(s) == FALSE) {
                err("server_run failed.");
-               goto free_end;
        }
 
        /*
@@ -223,7 +279,7 @@ int main(int argc, char *argv[])
         */
 
 free_end:
-       dbg("exit!");
+       info("server end");
        tcore_server_free(s);
 
 end: