Instead of using a "GMainLoop" element in the main thread, we now 38/23438/1
authorManuel Bachmann <manuel.bachmann@open.eurogiciel.org>
Wed, 25 Jun 2014 14:23:39 +0000 (16:23 +0200)
committerManuel Bachmann <manuel.bachmann@open.eurogiciel.org>
Wed, 25 Jun 2014 14:23:39 +0000 (16:23 +0200)
create a separate thread which will initiate the loop and do the
socket listening logic.

This avoids conflicting with the "GMainLoop" created by Ecore_Evas,
which produces lots of warnings and errors.

Bug-Tizen: TC-21

Change-Id: I453a21df649b256b63c96d4f274122c692aaf2f0
Signed-off-by: Manuel Bachmann <manuel.bachmann@open.eurogiciel.org>
CMakeLists.txt
server/thumb-server.c

index c6a2780..39c3a15 100644 (file)
@@ -44,7 +44,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src/include
 INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED
 glib-2.0 gthread-2.0 dlog mm-fileinfo drm-client aul
-libexif ecore-evas evas mmutil-imgp mmutil-jpeg heynoti libmedia-utils vconf libtzplatform-config)
+libexif ecore ecore-evas evas mmutil-imgp mmutil-jpeg heynoti libmedia-utils vconf libtzplatform-config)
 
 
 FOREACH(flag ${pkgs_CFLAGS})
index 2e9cda4..db17571 100755 (executable)
@@ -30,6 +30,9 @@
 #include <vconf.h>
 //#include <signal.h>
 //#include <glib-unix.h>
+#include <Ecore.h>
+#include <Ecore_Evas.h>
+
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -54,18 +57,34 @@ static void _media_thumb_signal_handler(void *user_data)
 }
 
 
-int main()
+void* gmainloop_thread(void *data)
 {
-       int sockfd = -1;
-
-    GSource *source = NULL;
-       GIOChannel *channel = NULL;
+       GSource *source = NULL;
+       GIOChannel *channel = (GIOChannel *)data;
        GMainContext *context = NULL;
 
+        g_thumb_server_mainloop = g_main_loop_new(context, FALSE);
+        context = g_main_loop_get_context(g_thumb_server_mainloop);
+
+        source = g_io_create_watch(channel, G_IO_IN);
+
+        /* Set callback to be called when socket is readable */
+        g_source_set_callback(source, (GSourceFunc)_thumb_server_read_socket, NULL, NULL);
+        g_source_attach(source, context);
+
+       g_main_loop_run(g_thumb_server_mainloop);
+
+       pthread_exit(NULL);
+}
+
+int main()
+{
        /*heynoti for power off*/
        int err = 0;
        int heynoti_id = heynoti_init();
 
+        int sockfd = -1;
+
        if (heynoti_id < 0) {
                thumb_err("heynoti_init failed");
        } else {
@@ -79,6 +98,12 @@ int main()
                }
        }
 
+       /* Create and bind new UDP socket */
+       if (!_thumb_server_prepare_socket(&sockfd)) {
+               thumb_err("Failed to create socket\n");
+               return -1;
+       }
+
        /* Set VCONFKEY_SYSMAN_MMC_FORMAT callback to get noti for SD card format */
        err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_FORMAT, (vconf_callback_fn) _thumb_daemon_vconf_cb, NULL);
        if (err == -1)
@@ -89,41 +114,29 @@ int main()
        if (err == -1)
                thumb_err("vconf_notify_key_changed : %s fails", VCONFKEY_SYSMAN_MMC_STATUS);
 
-       /* Create and bind new UDP socket */
-       if (!_thumb_server_prepare_socket(&sockfd)) {
-               thumb_err("Failed to create socket\n");
-               return -1;
-       }
-
-       g_thumb_server_mainloop = g_main_loop_new(context, FALSE);
-       context = g_main_loop_get_context(g_thumb_server_mainloop);
-
-       /* Create new channel to watch udp socket */
-       channel = g_io_channel_unix_new(sockfd);
-       source = g_io_create_watch(channel, G_IO_IN);
-
-       /* Set callback to be called when socket is readable */
-       g_source_set_callback(source, (GSourceFunc)_thumb_server_read_socket, NULL, NULL);
-       g_source_attach(source, context);
-
-       GSource *source_evas_init = NULL;
-       source_evas_init = g_idle_source_new ();
-       g_source_set_callback (source_evas_init, _thumb_daemon_start_jobs, NULL, NULL);
-       g_source_attach (source_evas_init, context);
-
 /*     Would be used when glib 2.32 is installed
        GSource *sig_handler_src = NULL;
        sig_handler_src = g_unix_signal_source_new (SIGTERM);
        g_source_set_callback(sig_handler_src, (GSourceFunc)_media_thumb_signal_handler, NULL, NULL);
        g_source_attach(sig_handler_src, context);
 */
+       ecore_evas_init();
+
+       GIOChannel *channel = NULL;
+        /* Create new channel to watch udp socket */
+        channel = g_io_channel_unix_new(sockfd);
+
+       static pthread_t thread;
+       pthread_create(&thread, NULL, gmainloop_thread, channel);
+
        thumb_dbg("************************************");
        thumb_dbg("*** Thumbnail server is running ***");
        thumb_dbg("************************************");
 
-       g_main_loop_run(g_thumb_server_mainloop);
+       ecore_main_loop_begin();
 
        thumb_dbg("Thumbnail server is shutting down...");
+
        g_io_channel_shutdown(channel,  FALSE, NULL);
        g_io_channel_unref(channel);
        _thumb_daemon_finish_jobs();