bootstrap: use thread for grpc server 18/295518/2 accepted/tizen/unified/20230713.014419
authorHosang Kim <hosang12.kim@samsung.com>
Mon, 10 Jul 2023 07:04:09 +0000 (16:04 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Tue, 11 Jul 2023 05:50:20 +0000 (14:50 +0900)
Revert "bootstrap: remove unnecessary mainloop and thread."

This reverts commit 0ff9860541bb67fc3372d1261a047c1d29e24412.

Change-Id: I3cd4511e3da32443c373377be1d15582f61451f8

org.tizen.aurum-bootstrap/src/BootstrapServer.cc

index 22b397c4b17aa5b9fc15dd099ca3611e2aa17e29..93902f5ea33310c9d1f87d444c8bf635d102e3bc 100644 (file)
@@ -31,6 +31,7 @@
 using namespace grpc;
 
 typedef struct _ServiceContext {
+    GThread *thread;
     std::unique_ptr<Server> server;
     bool forceTouchEnabled;
 } ServiceContext;
@@ -51,7 +52,8 @@ static void _vconf_force_enable_touch_set(void *data, bool enable)
     ctx->forceTouchEnabled = enable;
 }
 
-static bool _service_app_create(void *data)
+static gpointer
+_grpc_thread_func (gpointer data)
 {
     ServiceContext *ctx = (ServiceContext *)data;
     std::string binding("0.0.0.0:50051");
@@ -76,6 +78,20 @@ static bool _service_app_create(void *data)
     ctx->server = std::move(builder.BuildAndStart());
     ctx->server->Wait();
 
+    return NULL;
+}
+
+static bool _service_app_create(void *data)
+{
+    ServiceContext *ctx = (ServiceContext *)data;
+
+    ctx->thread = g_thread_new("grpc_thread", _grpc_thread_func, ctx);
+
+    if (!ctx->thread) {
+        LOGE("Thread is empty!");
+        return false;
+    }
+
     return true;
 }
 
@@ -86,6 +102,7 @@ static void _service_app_terminate(void *data)
     if (ctx->forceTouchEnabled)
         _vconf_force_enable_touch_set(ctx, false);
     ctx->server->Shutdown();
+    g_thread_join(ctx->thread);
 }
 
 static void _service_app_control(app_control_h app_control, void *data)