gmain_loop: made single main loop at main function 25/41925/1
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Wed, 17 Jun 2015 06:33:52 +0000 (15:33 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Fri, 19 Jun 2015 07:01:27 +0000 (16:01 +0900)
- network: removed unused requirement packages

Change-Id: I6768538ac0dfa4bf1cbdc8ffd3973115437b5303
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
CMakeLists.txt
emuld.service
include/emuld.h
packaging/emuld.spec
src/common.cpp
src/emuld.cpp
src/net.cpp

index f257d98bf7b8a1e533f818626ae61c2281472ca4..5605ce255e292bde703c3971b4a91e7c9f1b62b1 100644 (file)
@@ -62,7 +62,6 @@ SET(PKG_MODULE
     ecore
     edbus
     capi-network-connection
-    glib-2.0
 )
 
 pkg_check_modules(PKGS REQUIRED ${PKG_MODULE})
index 46367b47dac90000b520744b976b030ed8c5cc4c..7266b979af77b59b00f3677910531aac2fd41e44 100644 (file)
@@ -8,7 +8,6 @@ After=connman.service
 [Service]
 Type=simple
 ExecStart=/usr/bin/emuld
-KillSignal=SIGUSR1
 
 [Install]
 WantedBy=emulator.target
index 9d7aebc5136a1b8cd0f948c0782a0f38e942cb09..e5e6b84de1997b9b03ab24f323ec0f58d37538c4 100644 (file)
@@ -62,7 +62,7 @@ enum
 #define HEADER_SIZE         4
 #define STATUS              15
 
-#define TID_BOOT            1
+#define TID_NETWORK         1
 #define TID_SDCARD          2
 #define TID_LOCATION        3
 #define TID_HDS_ATTACH      4
@@ -85,9 +85,23 @@ void writelog(const char* fmt, ...);
 #  define LOGERR LOGE
 #  define LOGDEBUG LOGD
 #else
-#  define LOGINFO(fmt, ...) { writelog(fmt, ##__VA_ARGS__); }
-#  define LOGERR LOGINFO
-#  define LOGDEBUG LOGINFO
+#  define LOG_TAG           "EMULD"
+#  include <dlog/dlog.h>
+#  define LOGINFO(fmt, ...)     \
+        do {    \
+            writelog(fmt, ##__VA_ARGS__);   \
+            LOGI(fmt, ##__VA_ARGS__);   \
+        } while (0)
+#  define LOGERR(fmt, ...)  \
+        do {    \
+            writelog(fmt, ##__VA_ARGS__);   \
+            LOGE(fmt, ##__VA_ARGS__);   \
+        } while (0)
+#  define LOGDEBUG(fmt, ...)    \
+        do {    \
+            writelog(fmt, ##__VA_ARGS__);   \
+            LOGD(fmt, ##__VA_ARGS__);   \
+        } while (0)
 #endif
 
 typedef unsigned short  CliSN;
@@ -188,7 +202,7 @@ int recv_data(int event_fd, char** r_databuf, int size);
 void recv_from_evdi(evdi_fd fd);
 bool accept_proc(const int server_fd);
 void get_guest_addr(void);
-int register_connection(void);
+void register_connection(void);
 void destroy_connection(void);
 
 void set_vconf_cb(void);
@@ -196,7 +210,6 @@ void send_to_ecs(const char* cat, int group, int action, char* data);
 void send_emuld_connection(void);
 void send_default_suspend_req(void);
 void send_default_mount_req(void);
-void* dbus_booting_done_check(void* data);
 void systemcall(const char* param);
 int parse_val(char *buff, unsigned char data, char *parsbuf);
 
index f007c3698ac6e29c67b6ea5296b8d5fec9c57537..9671b72c6c8073e882110595f8f2bd492f3d9c2b 100644 (file)
@@ -1,5 +1,5 @@
 Name: emuld
-Version: 0.9.10
+Version: 0.9.11
 Release: 0
 Summary: Emulator daemon
 License: Apache-2.0
@@ -12,12 +12,7 @@ BuildRequires: pkgconfig(deviced)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(edbus)
 BuildRequires: pkgconfig(ecore)
-BuildRequires: pkgconfig(dbus-glib-1)
-BuildRequires: pkgconfig(capi-appfw-app-manager)
-BuildRequires: pkgconfig(capi-base-common)
 BuildRequires: pkgconfig(capi-network-connection)
-BuildRequires: pkgconfig(network)
-BuildRequires: pkgconfig(glib-2.0)
 
 %description
 A emulator daemon is used for communication between guest and host
index 7576c29661b233d1196edf58a100aa38ef61c938..44d5a34d29d23226e8d51cfd34429c22685bc9a6 100644 (file)
 
 #include <sys/time.h>
 #include <sys/reboot.h>
-#include <sys/ioctl.h>
 #include <sys/mount.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <errno.h>
 #include <utility>
 
-#include <E_DBus.h>
-#include <Ecore.h>
-
 #include <dirent.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -423,97 +419,6 @@ void msgproc_package(ijcommand* ijcmd)
     }
 }
 
-enum ioctl_cmd {
-    IOCTL_CMD_BOOT_DONE,
-};
-
-void send_to_kernel(void)
-{
-    if(ioctl(g_fd[fdtype_device], IOCTL_CMD_BOOT_DONE, NULL) == -1) {
-        LOGERR("Failed to send ioctl to kernel");
-        return;
-    }
-    LOGINFO("[DBUS] sent booting done to kernel");
-}
-
-#define DBUS_PATH_BOOT_DONE  "/Org/Tizen/System/DeviceD/Core"
-#define DBUS_IFACE_BOOT_DONE "org.tizen.system.deviced.core"
-#define BOOT_DONE_SIGNAL     "BootingDone"
-
-static void boot_done(void *data, DBusMessage *msg)
-{
-    if (dbus_message_is_signal(msg,
-                DBUS_IFACE_BOOT_DONE,
-                BOOT_DONE_SIGNAL) != 0) {
-        LOGINFO("[DBUS] sending booting done to ecs.");
-        send_to_ecs(IJTYPE_BOOT, 0, 0, NULL);
-        LOGINFO("[DBUS] sending booting done to kernel for log.");
-        send_to_kernel();
-    }
-}
-
-static void sig_handler(int signo)
-{
-    LOGINFO("received signal: %d. EXIT!", signo);
-    _exit(0);
-}
-
-static void add_sig_handler(int signo)
-{
-    sighandler_t sig;
-
-    sig = signal(signo, sig_handler);
-    if (sig == SIG_ERR) {
-        LOGERR("adding %d signal failed : %d", signo, errno);
-    }
-}
-
-void* dbus_booting_done_check(void* data)
-{
-    E_DBus_Connection *connection;
-    E_DBus_Signal_Handler *boot_handler = NULL;
-
-    ecore_init();
-    e_dbus_init();
-
-    connection = e_dbus_bus_get(DBUS_BUS_SYSTEM);
-    if (!connection) {
-        LOGERR("[DBUS] Failed to get dbus bus.");
-        e_dbus_shutdown();
-        ecore_shutdown();
-        return NULL;
-    }
-
-    boot_handler = e_dbus_signal_handler_add(
-            connection,
-            NULL,
-            DBUS_PATH_BOOT_DONE,
-            DBUS_IFACE_BOOT_DONE,
-            BOOT_DONE_SIGNAL,
-            boot_done,
-            NULL);
-    if (!boot_handler) {
-        LOGERR("[DBUS] Failed to register handler");
-        e_dbus_signal_handler_del(connection, boot_handler);
-        e_dbus_shutdown();
-        ecore_shutdown();
-        return NULL;
-    }
-    LOGINFO("[DBUS] signal handler is added.");
-
-    add_sig_handler(SIGINT);
-    add_sig_handler(SIGTERM);
-    add_sig_handler(SIGUSR1);
-
-    ecore_main_loop_begin();
-
-    e_dbus_signal_handler_del(connection, boot_handler);
-    e_dbus_shutdown();
-    ecore_shutdown();
-
-    return NULL;
-}
-
 char SDpath[256];
 
 // Location
index 54eaa562323f29630f8484184e303b702bb7350f..8d3cc5f05390db971a8fba298a3838f7fcc933c0 100644 (file)
 #include <stdarg.h>
 #include <stdio.h>
 #include <arpa/inet.h>
+#include <sys/ioctl.h>
 #include <unistd.h>
 
 #include "emuld.h"
 #include "synbuf.h"
 
+#include <E_DBus.h>
+#include <Ecore.h>
+
 #include <queue>
 
 /* global definition */
@@ -339,7 +343,52 @@ static bool server_process(void)
     return false;
 }
 
-int main( int argc , char *argv[])
+enum ioctl_cmd {
+    IOCTL_CMD_BOOT_DONE,
+};
+
+void send_to_kernel(void)
+{
+    if(ioctl(g_fd[fdtype_device], IOCTL_CMD_BOOT_DONE, NULL) == -1) {
+        LOGERR("Failed to send ioctl to kernel");
+        return;
+    }
+    LOGINFO("[DBUS] sent booting done to kernel");
+}
+
+#define DBUS_PATH_BOOT_DONE  "/Org/Tizen/System/DeviceD/Core"
+#define DBUS_IFACE_BOOT_DONE "org.tizen.system.deviced.core"
+#define BOOT_DONE_SIGNAL     "BootingDone"
+
+static void boot_done(void *data, DBusMessage *msg)
+{
+    if (dbus_message_is_signal(msg,
+                DBUS_IFACE_BOOT_DONE,
+                BOOT_DONE_SIGNAL) != 0) {
+        LOGINFO("[DBUS] sending booting done to ecs.");
+        send_to_ecs(IJTYPE_BOOT, 0, 0, NULL);
+        LOGINFO("[DBUS] sending booting done to kernel for log.");
+        send_to_kernel();
+    }
+}
+
+static void sig_handler(int signo)
+{
+    LOGINFO("received signal: %d. EXIT!", signo);
+    _exit(0);
+}
+
+static void add_sig_handler(int signo)
+{
+    sighandler_t sig;
+
+    sig = signal(signo, sig_handler);
+    if (sig == SIG_ERR) {
+        LOGERR("adding %d signal failed : %d", signo, errno);
+    }
+}
+
+void* handling_network(void* data)
 {
     int ret = -1;
 
@@ -356,16 +405,8 @@ int main( int argc , char *argv[])
         exit(0);
     }
 
-    ret = register_connection();
-
     send_default_suspend_req();
 
-    if (pthread_create(&tid[TID_BOOT], NULL, dbus_booting_done_check, NULL) != 0)
-    {
-        LOGERR("boot noti pthread create fail!");
-        return -1;
-    }
-
     LOGINFO("[START] epoll & device init success");
 
     send_default_mount_req();
@@ -382,21 +423,87 @@ int main( int argc , char *argv[])
     add_vconf_map_profile();
     set_vconf_cb();
 
+    send_emuld_connection();
+
     while(!exit_flag)
     {
         exit_flag = server_process();
     }
 
     stop_listen();
-    if (ret == 1)
+
+    exit(0);
+}
+
+int main( int argc , char *argv[])
+{
+    int ret;
+    void* retval = NULL;
+
+    E_DBus_Connection *dbus_conn;
+    E_DBus_Signal_Handler *boot_handler = NULL;
+
+    ecore_init();
+
+    dbus_threads_init_default();
+
+    ret = e_dbus_init();
+    if (ret == 0) {
+        LOGERR("[DBUS] init value : %d", ret);
+        exit(-1);
+    }
+
+    dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
+    if (!dbus_conn) {
+        LOGERR("[DBUS] Failed to get dbus bus.");
+        e_dbus_shutdown();
+        ecore_shutdown();
+        exit(-1);
+    }
+
+    boot_handler = e_dbus_signal_handler_add(
+            dbus_conn,
+            NULL,
+            DBUS_PATH_BOOT_DONE,
+            DBUS_IFACE_BOOT_DONE,
+            BOOT_DONE_SIGNAL,
+            boot_done,
+            NULL);
+    if (!boot_handler) {
+        LOGERR("[DBUS] Failed to register handler");
+        e_dbus_signal_handler_del(dbus_conn, boot_handler);
+        e_dbus_shutdown();
+        ecore_shutdown();
+        exit(-1);
+    }
+    LOGINFO("[DBUS] signal handler is added.");
+
+    add_sig_handler(SIGINT);
+    add_sig_handler(SIGTERM);
+
+    register_connection();
+
+    if (pthread_create(&tid[TID_NETWORK], NULL, handling_network, NULL) != 0)
     {
-        LOGINFO("destroy connection");
-        destroy_connection();
+        LOGERR("boot noti pthread create fail!");
+        return -1;
     }
 
+    ecore_main_loop_begin();
+
+    e_dbus_signal_handler_del(dbus_conn, boot_handler);
+    e_dbus_shutdown();
+    ecore_shutdown();
+
+    destroy_connection();
 
     LOGINFO("emuld exit");
 
+    ret = pthread_join(tid[TID_NETWORK], &retval);
+    if (ret < 0) {
+        LOGERR("validate package pthread join is failed.");
+    }
+
     return 0;
 }
 
index 7e18ba4ac3d66c2a7c50721a93313585a5052f1f..76a0ae1237e17c7d3c37244a698c3428bc28b316 100644 (file)
@@ -39,7 +39,6 @@
 #include <fcntl.h>
 #include "emuld.h"
 #include <net_connection.h>
-
 #define PROC_CMDLINE_PATH "/proc/cmdline"
 #define IP_SUFFIX " ip="
 #define IJTYPE_GUESTIP "guest_ip"
@@ -239,42 +238,25 @@ static void send_guest_ip_req(void)
         free(packet);
 }
 
-void *g_main_thread_cb(void *arg)
+void register_connection(void)
 {
-    mainloop = g_main_loop_new(NULL, FALSE);
-
-    int err = connection_create(&connection);
-    if (CONNECTION_ERROR_NONE == err) {
+    int ret = connection_create(&connection);
+    if (CONNECTION_ERROR_NONE == ret) {
         LOGINFO("connection_create() success!: [%p]", connection);
         connection_set_ip_address_changed_cb(connection, ip_changed_cb, NULL);
     } else {
-        LOGERR("Client registration failed %d", err);
-        return NULL;
+        LOGERR("Client registration failed %d", ret);
+        return;
     }
     get_guest_addr();
-    g_main_loop_run(mainloop);
-    return NULL;
 }
 
-int register_connection()
-{
-    LOGINFO("register_connection");
-
-    if(pthread_create(&g_main_thread, NULL, g_main_thread_cb, NULL) != 0) {
-        LOGERR("fail to create g_main_thread!");
-        return -1;
-    }
-    return 1;
-}
-
-void destroy_connection()
+void destroy_connection(void)
 {
     if (connection != NULL) {
         connection_destroy(connection);
     }
     connection_profile_destroy(profile);
-    g_main_loop_quit(mainloop);
-    pthread_detach(g_main_thread);
 }
 
 static char *s_strncpy(char *dest, const char *source, size_t n)
@@ -396,7 +378,5 @@ void get_guest_addr()
     } else {
         LOGINFO("use dynamic IP. do not need update network information.");
     }
-
-    send_emuld_connection();
 }