Support hydra mode
authorGleb Balykov <g.balykov@samsung.com>
Thu, 2 Nov 2017 17:01:51 +0000 (20:01 +0300)
committer이형주/Common Platform Lab(SR)/Staff Engineer/삼성전자 <leee.lee@samsung.com>
Tue, 24 Sep 2019 22:07:13 +0000 (07:07 +0900)
NativeLauncher/dotnet.loader
NativeLauncher/launcher/dotnet/dotnet_launcher.cc
NativeLauncher/launcher/dotnet/dotnet_launcher.h
NativeLauncher/launcher/launcher.cc
NativeLauncher/launcher/launcher.h
NativeLauncher/launcher/main.cc

index eb17893..e04b914 100644 (file)
@@ -13,3 +13,4 @@ EXTRA_ARRAY_VAL        /usr/lib/ecore_imf/modules/wayland/v-1.16/libwltextinputm
 EXTRA_ARRAY_VAL        /usr/lib/libdali-toolkit.so
 EXTRA_ARRAY_VAL        /usr/lib/libcairo.so.2
 EXTRA_ARRAY_VAL        /usr/lib/libefl-assist.so.0
+HYDRA                  ON
index 713ff0c..c13c406 100644 (file)
@@ -296,7 +296,7 @@ CoreRuntime::~CoreRuntime()
        dispose();
 }
 
-int CoreRuntime::initialize(bool standalone)
+int CoreRuntime::preinitialize(bool standalone)
 {
        // checkInjection checks dotnet-launcher run mode
        // At the moment, this mechanism is used only when the Memory Profiler is started.
@@ -351,23 +351,6 @@ int CoreRuntime::initialize(bool standalone)
                return -1;
        }
 
-       if (__enableLogManager) {
-               if (initializeLogManager() < 0) {
-                       _ERR("Failed to initnialize LogManager");
-                       return -1;
-               }
-
-               if (redirectFD() < 0) {
-                       _ERR("Failed to redirect FD");
-                       return -1;
-               }
-
-               if (runLoggingThread() < 0) {
-                       _ERR("Failed to create and run logging thread to redicrect log");
-                       return -1;
-               }
-       }
-
        std::string libCoreclr(concatPath(getRuntimeDir(), "libcoreclr.so"));
 
        __coreclrLib = dlopen(libCoreclr.c_str(), RTLD_NOW | RTLD_LOCAL);
@@ -397,6 +380,38 @@ int CoreRuntime::initialize(bool standalone)
 
        _INFO("libcoreclr dlopen and dlsym success");
 
+       return 0;
+}
+
+int CoreRuntime::initialize(bool standalone)
+{
+#define __XSTR(x) #x
+#define __STR(x) __XSTR(x)
+
+#ifdef NATIVE_LIB_DIR
+       __nativeLibDirectory = __STR(NATIVE_LIB_DIR);
+#endif
+
+#undef __STR
+#undef __XSTR
+
+       if (__enableLogManager) {
+               if (initializeLogManager() < 0) {
+                       _ERR("Failed to initnialize LogManager");
+                       return -1;
+               }
+
+               if (redirectFD() < 0) {
+                       _ERR("Failed to redirect FD");
+                       return -1;
+               }
+
+               if (runLoggingThread() < 0) {
+                       _ERR("Failed to create and run logging thread to redicrect log");
+                       return -1;
+               }
+       }
+
        if (!standalone)
                pluginPreload();
 
index 704070b..88fb931 100644 (file)
@@ -30,6 +30,7 @@ class CoreRuntime
        public:
                CoreRuntime(const char* mode);
                ~CoreRuntime();
+               int preinitialize(bool standalone);
                int initialize(bool standalone);
                void dispose();
                int launch(const char* appId, const char* root, const char* path, int argc, char* argv[]);
index e5a1f14..14a7d18 100644 (file)
@@ -57,6 +57,7 @@ class LaunchpadAdapterImpl : public LaunchpadAdapter
        private:
                AppInfo appInfo;
                loader_lifecycle_callback_s callbacks;
+               hydra_lifecycle_callback_s hydraCallbacks;
                loader_adapter_s adapter;
                bool __isLaunched;
                std::string __launchPath;
@@ -90,7 +91,7 @@ static Eina_Bool fdHandler(void *data, Ecore_Fd_Handler* handler)
                }
        }
 
-       return ECORE_CALLBACK_CANCEL;
+       return ECORE_CALLBACK_RENEW;
 }
 
 static void fdAdd(void *data, int fd, loader_receiver_cb receiver)
@@ -214,6 +215,28 @@ int LaunchpadAdapterImpl::loaderMain(int argc, char* argv[])
                return 0;
        };
 
+       // Called before initial fork
+       hydraCallbacks.precreate = [](void* userData) {
+               WITH_SELF(userData) {
+                       if (self->onPreCreate != nullptr)
+                               self->onPreCreate();
+               }
+       };
+
+       hydraCallbacks.create = [](void* userData) {
+               ecore_init();
+       };
+
+       // Called after fork in candidate
+       hydraCallbacks.fork = [](void *userData) {
+               ecore_fork_reset();
+       };
+
+       hydraCallbacks.terminate = [](void* userData) {
+               ecore_shutdown();
+               return 0;
+       };
+
        adapter.loop_begin = [](void *data) {
                ecore_main_loop_begin();
        };
@@ -224,9 +247,10 @@ int LaunchpadAdapterImpl::loaderMain(int argc, char* argv[])
        adapter.add_fd = fdAdd;
        adapter.remove_fd = fdRemove;
 
-       _INFO("launchpad_loader_main is start");
-       int r = launchpad_loader_main(argc, argv, &(this->callbacks), &(this->adapter), this);
-       _INFO("launchpad_loader_main is finished with [%d]", r);
+       _INFO("launchpad_hydra_main is start");
+       int r = launchpad_hydra_main(argc, argv, &(this->hydraCallbacks),
+               &(this->callbacks), &(this->adapter), this);
+       _INFO("launchpad_hydra_main is finished with [%d]", r);
 
        return r;
 }
index e48f318..7e1125a 100644 (file)
@@ -35,6 +35,7 @@ class LaunchpadAdapter
 {
        public:
                virtual int loaderMain(int argc, char* argv[]) = 0;
+               std::function<void()> onPreCreate = nullptr;
                std::function<void()> onCreate = nullptr;
                std::function<void(const AppInfo&, int, char**)> onLaunch = nullptr;
                std::function<void(const AppInfo&, int, char**)> onTerminate = nullptr;
index d710225..cac7e39 100644 (file)
@@ -80,6 +80,11 @@ extern "C" int realMain(int argc, char *argv[], const char* mode)
                snprintf(appId, 16, "%s", "dotnet-launcher");
                appRoot = baseName(argv[1]);
 
+               if (runtime->preinitialize(true) != 0) {
+                       _ERR("Failed to preinitialized");
+                       return 1;
+               }
+
                if (runtime->initialize(true) != 0) {
                        _ERR("Failed to initialize");
                        return 1;
@@ -107,6 +112,11 @@ extern "C" int realMain(int argc, char *argv[], const char* mode)
                }
                _INFO("AUL_APPID : %s", appId);
 
+               if (runtime->preinitialize(true) != 0) {
+                       _ERR("Failed to preinitialized");
+                       return 1;
+               }
+
                if (runtime->initialize(true) != 0) {
                        _ERR("Failed to initialize");
                        return 1;
@@ -124,6 +134,13 @@ extern "C" int realMain(int argc, char *argv[], const char* mode)
                        return 1;
                }
        } else {
+               Launchpad.onPreCreate = [&runtime]() {
+                       if (runtime->preinitialize(false) != 0)
+                               _ERR("Failed to preinitialized");
+                       else
+                               _INFO("Success to preinitialized");
+               };
+
                Launchpad.onCreate = [&runtime]() {
                        if (runtime->initialize(false) != 0)
                                _ERR("Failed to initialized");