X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=NativeLauncher%2Flauncher%2Fmain.cc;h=f09705ba4d2559d499277fff95636808d7b2193c;hb=2158324e388cdf7226410609d98bd9d95c0281c8;hp=f56432aa1630782316dfbada2fb7d820d079e196;hpb=7e7177ce4e44a3ed21248b459236ae9764bac927;p=platform%2Fcore%2Fdotnet%2Flauncher.git diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index f56432a..f09705b 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -15,7 +15,6 @@ */ #include "dotnet/dotnet_launcher.h" -#include "mono/mono_launcher.h" #include "utils.h" #include "log.h" @@ -26,164 +25,149 @@ #include #include #include +#include +#include -#define __XSTR(x) #x -#define __STR(x) __XSTR(x) +// By the specification, application id must be shorter than 50 characters. +// Current length of argv[0] is 25 with a space. ("/usr/bin/dotnet-launcher ") +// To be able to change argv[0] when standalone mode padding for executable path is added. +#define APPID_MAX_LENGTH (25 + 105) -#ifndef VERSION -#define LAUNCHER_VERSION_STR "-Unknown-" -#else -#define LAUNCHER_VERSION_STR __STR(VERSION) -#endif - -static std::string VersionOption("--version"); static std::string StandaloneOption("--standalone"); -static std::string NativeOption("--native"); +static std::string PaddingOption("--PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE_PADDING_TO_CHANGE_CMDLINE"); + +extern "C" int realMain(int argc, char *argv[], const char* mode) +{ + int i; + bool standaloneMode = false; + char* standalonePath = nullptr; + bool corerunMode = false; + bool paddingExist = false; + + std::vector vargs; + + // start index 1 to avoid passing executable name "dotnet-launcher" as a parameter + for (i = 1; i < argc; i++) { + if (StandaloneOption.compare(argv[i]) == 0) { + standaloneMode = true; + + if (i > argc - 1) { + fprintf(stderr, "Assembly path must be after \"--standalone\" option\n"); + return 1; + } + i++; + standalonePath = argv[i]; + } else if (PaddingOption.compare(argv[i]) == 0) { + paddingExist = true; + } else { + vargs.push_back(argv[i]); + } + } + + if (isManagedAssembly(argv[1]) || isNativeImage(argv[1])) { + corerunMode = true; + } + + using tizen::runtime::Launchpad; + using tizen::runtime::AppInfo; + using tizen::runtime::dotnetcore::CoreRuntime; + + std::unique_ptr runtime(new CoreRuntime(mode)); + + // Intiailize ecore first (signal handlers, etc.) before runtime init. + ecore_init(); + + if (corerunMode) { + _INFO("##### Run in corerun mode #####"); + char appId[APPID_MAX_LENGTH] = {0,}; + std::string appRoot; + snprintf(appId, 16, "%s", "dotnet-launcher"); + appRoot = baseName(argv[1]); + + if (runtime->initialize(true) != 0) { + _ERR("Failed to initialize"); + return 1; + } + + int argsLen = vargs.size() - 1; + char** args = &vargs[1]; + if (runtime->launch(appId, appRoot.c_str(), argv[1], argsLen, args)) { + _ERR("Failed to launch"); + return 1; + } + } else if (standaloneMode) { + _INFO("##### Run in standalone mode #####"); + char appId[APPID_MAX_LENGTH] = {0,}; + std::string appRoot; + if (AUL_R_OK == aul_app_get_appid_bypid(getpid(), appId, sizeof(appId))) { + const char* appRootPath = aul_get_app_root_path(); + if (appRootPath != nullptr) + appRoot = std::string(appRootPath); + } else { + // If appId is not set, it is executed directly by cmdline. + // In this case, appRoot is passed as an argument. + snprintf(appId, 16, "%s", "dotnet-launcher"); + appRoot = baseName(baseName(standalonePath)); + } + _INFO("AUL_APPID : %s", appId); + + if (runtime->initialize(true) != 0) { + _ERR("Failed to initialize"); + return 1; + } + + // change cmdline from dotnet-launcher to executable path + int cmdlineSize = paddingExist ? APPID_MAX_LENGTH : APPID_MAX_LENGTH - PaddingOption.length(); + memset(argv[0], '\0', cmdlineSize); + snprintf(argv[0], cmdlineSize, "%s", standalonePath); + + int argsLen = vargs.size(); + char** args = &vargs[0]; + if (runtime->launch(appId, appRoot.c_str(), standalonePath, argsLen, args)) { + _ERR("Failed to launch"); + return 1; + } + } else { + // change cmdline from dotnet-hydra-launcher to dotnet-launcher + if (strcmp(argv[0], "/usr/bin/dotnet-hydra-launcher") == 0) { + memset(argv[0], '\0', strlen("/usr/bin/dotnet-hydra-launcher")); + snprintf(argv[0], strlen("/usr/bin/dotnet-launcher") + 1, "/usr/bin/dotnet-launcher"); + } + + Launchpad.onCreate = [&runtime]() { + if (runtime->initialize(false) != 0) { + _ERR("Failed to initialized"); + } else { + _INFO("Success to initialized"); + } + }; + + Launchpad.onTerminate = [&runtime](const AppInfo& appInfo, int argc, char** argv) { + _INFO("launch request with app path : %s", appInfo.path.c_str()); + _INFO("appId : %s", appInfo.id.c_str()); + _INFO("pkg : %s", appInfo.pkg.c_str()); + + // aul_get_app_root_path() can return NULL for error case. + if (appInfo.root.empty()) { + _ERR("Failed to launch. root path is set to NULL"); + } else { + // The launchpad pass the name of exe file to the first argument. + // For the C# spec, we have to skip this first argument. + if (runtime->launch(appInfo.id.c_str(), appInfo.root.c_str(), appInfo.path.c_str(), argc-1, argv+1)) + _ERR("Failed to launch"); + } + }; + int ret = Launchpad.loaderMain(argc, argv); + if (ret < 0) { + _ERR("fail to start loaderMain. candidate process is not created."); + return 1; + } + } + + return 0; +} int main(int argc, char *argv[]) { - int i; - bool standalone = false; - const char* standalonePath = nullptr; - bool nativeOnly = false; - - std::vector vargs; - - // start index 1 to avoid passing executable name "dotnet-launcher" as a parameter - for (i=1; i argc-1) - { - fprintf(stderr, "Assembly path must be after \"--standalone\" option\n"); - return 1; - } - i++; - standalonePath = argv[i]; - } - else if (NativeOption.compare(argv[i]) == 0) - { - nativeOnly = true; - } - else - { - vargs.push_back(argv[i]); - } - } - - if (!standalone && nativeOnly) - { - fprintf(stderr, "\"--native\" option must be use with \"--standalone\"\n"); - return 1; - } - - using tizen::runtime::LauncherInterface; - using tizen::runtime::Launchpad; - using tizen::runtime::AppInfo; - std::unique_ptr runtime; - - bool useMono = !FileNotExist("/etc/.use_mono"); - - if (!useMono) - { - using tizen::runtime::dotnetcore::CoreRuntime; - std::unique_ptr coreRuntime(new CoreRuntime()); - runtime = std::move(coreRuntime); - - _DBG("##### CoreCLR Launcher ######"); - } - else - { - using tizen::runtime::mono::MonoRuntime; - std::unique_ptr monoRuntime(new MonoRuntime()); - runtime = std::move(monoRuntime); - - _DBG("##### Mono Launcher ######"); - } - - if (standalone) - { - _DBG("##### Run it standalone #########"); - const char* appid = getenv("AUL_APPID"); - _DBG("AUL_APPID : %s", appid); - std::string approot; - if (appid != nullptr) - { - const char* approot_path = aul_get_app_root_path(); - if (approot_path != nullptr) - { - approot = std::string(approot_path); - } - } - if (approot.empty()) - { - approot = Basename(standalonePath); - } - if (runtime->Initialize(true) != 0) - { - _ERR("Failed to initialize"); - return 1; - } - - if (!nativeOnly && runtime->RunManagedLauncher() != 0) - { - _ERR("Failed to run managed launcher"); - return 1; - } - - int args_len = vargs.size(); - char** args = &vargs[0]; - if (runtime->Launch(approot.c_str(), standalonePath, args_len, args)) - { - _ERR("Failed to launch"); - return 0; - } - } - else - { - Launchpad.OnCreate = [&runtime]() - { - if (runtime->Initialize(false) != 0) - { - _ERR("Failed to initialized"); - } - else - { - auto idle_task = [](void *data) -> Eina_Bool - { - LauncherInterface* runtime = static_cast(data); - if (runtime->RunManagedLauncher() != 0) - { - _ERR("Failed to run managed launcher"); - } - return ECORE_CALLBACK_CANCEL; - }; - ecore_idler_add(idle_task, runtime.get()); - } - }; - - Launchpad.OnTerminate = [&runtime](const AppInfo& info, int argc, char** argv) - { - _DBG("terminated with app path : %s", info.path.c_str()); - _DBG("appid : %s", info.id.c_str()); - _DBG("pkg : %s", info.pkg.c_str()); - _DBG("type : %s", info.type.c_str()); - - if (runtime->Launch(info.root.c_str(), info.path.c_str(), argc, argv)) - { - _ERR("Failed to launch"); - } - }; - Launchpad.LoaderMain(argc, argv); - } - - return 0; + return realMain(argc, argv, "default"); }