add skin server ready
authorSon Hyunjun <hj79.son@samsung.com>
Wed, 14 Mar 2012 03:10:20 +0000 (12:10 +0900)
committerSon Hyunjun <hj79.son@samsung.com>
Wed, 14 Mar 2012 03:10:20 +0000 (12:10 +0900)
tizen/src/emulator.c
tizen/src/skin/maruskin_client.c
tizen/src/skin/maruskin_server.c
tizen/src/skin/maruskin_server.h

index 7e3da36..7171174 100644 (file)
@@ -30,6 +30,7 @@
  */
 
 
+#include <stdlib.h>
 #include <SDL/SDL.h>
 #include "maru_common.h"
 #include "emulator.h"
@@ -73,8 +74,8 @@ static void construct_main_window(int skin_argc, char* skin_argv[])
     INFO("construct main window\n");
     start_skin_server(11111, 0, 0);
 #if 1
-    if (start_skin_client(skin_argc, skin_argv) == 0) {
-        //TODO:
+    if ( 0 > start_skin_client(skin_argc, skin_argv) ) {
+        exit( -1 );
     }
 #endif
 
index c2b2e5c..cb93d49 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <pthread.h>
-#include "maruskin_client.h"
 #include <string.h>
+#include <unistd.h>
+#include "maruskin_client.h"
+#include "maruskin_server.h"
+#include "debug_ch.h"
 
+#define SKIN_SERVER_READY_TIME 3 // second
+#define SKIN_SERVER_SLEEP_TIME 10 // milli second
 
 #define JAR_SKINFILE_PATH "EmulatorSkin.jar"
 #define JAVA_EXEFILE_PATH "java"
 #define JAVA_EXEOPTION "-jar"
 
+MULTI_DEBUG_CHANNEL( qemu, maruskin_client );
+
 // function modified by caramis
 // for delivery argv
 
@@ -68,14 +75,40 @@ static void* run_skin_client(void* arg)
 
 int start_skin_client(int argc, char* argv[])
 {
+
+    int count = 0;
+    int skin_server_ready = 0;
+
+    while( 1 ) {
+
+        if( 100 * SKIN_SERVER_READY_TIME < count ) {
+            break;
+        }
+
+        if( is_ready_skin_server() ) {
+            skin_server_ready = 1;
+            break;
+        }else {
+            count++;
+            INFO( "sleep for ready. count:%d\n", count );
+            usleep( 1000 * SKIN_SERVER_SLEEP_TIME );
+        }
+
+    }
+
+    if( !skin_server_ready ) {
+        ERR( "skin_server is not ready.\n" );
+        return -1;
+    }
+
     skin_argc = argc;
     skin_argv = argv;
 
     pthread_t thread_id = -1;
 
     if (0 != pthread_create(&thread_id, NULL, run_skin_client, NULL)) {
-        fprintf(stderr, "fail to create skin_client pthread.\n");
-        return 0;
+        ERR( "fail to create skin_client pthread.\n" );
+        return -1;
     }
 
     return 1;
index 5bfa1a9..6c9eedf 100644 (file)
@@ -73,6 +73,7 @@ static int server_sock = 0;
 static int client_sock = 0;
 static int stop_server = 0;
 static int is_sensord_initialized = 0;
+static int ready_server = 0;
 
 static int stop_heartbeat = 0;
 static int recv_heartbeat_count = 0;
@@ -128,11 +129,17 @@ void shutdown_skin_server( void ) {
 void notify_sensor_daemon_start( void ) {
     INFO( "notify_sensor_daemon_start\n" );
     is_sensord_initialized = 1;
-    if ( 0 > send_skin( client_sock, SEND_SENSOR_DAEMON_START ) ) {
-        ERR( "fail to send SEND_SENSOR_DAEMON_START to skin.\n" );
+    if( client_sock ) {
+        if ( 0 > send_skin( client_sock, SEND_SENSOR_DAEMON_START ) ) {
+            ERR( "fail to send SEND_SENSOR_DAEMON_START to skin.\n" );
+        }
     }
 }
 
+int is_ready_skin_server( void ) {
+    return ready_server;
+}
+
 static void* run_skin_server( void* args ) {
 
     uint16_t port;
@@ -194,6 +201,9 @@ static void* run_skin_server( void* args ) {
         INFO( "start accepting socket...\n" );
 
         client_len = sizeof( client_addr );
+
+        ready_server = 1;
+
         if ( 0 > ( client_sock = accept( server_sock, (struct sockaddr *) &client_addr, &client_len ) ) ) {
             ERR( "skin_servier accept error\n" );
             perror( "skin_servier accept error\n" );
index aa75ac9..c45c931 100644 (file)
@@ -34,7 +34,8 @@
 #include <stdint.h>
 
 pthread_t start_skin_server( uint16_t default_svr_port, int argc, char** argv );
-void shutdown_skin_server(void);
-void notify_sensor_daemon_start(void);
+void shutdown_skin_server( void );
+void notify_sensor_daemon_start( void );
+int is_ready_skin_server( void );
 
 #endif /* MARUSKIN_SERVER_H_ */