2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "dotnet/dotnet_launcher.h"
30 #define __STR(x) __XSTR(x)
33 #define LAUNCHER_VERSION_STR "-Unknown-"
35 #define LAUNCHER_VERSION_STR __STR(VERSION)
38 static std::string VersionOption("--version");
39 static std::string StandaloneOption("--standalone");
41 int main(int argc, char *argv[])
44 bool standalone = false;
45 const char* standalonePath = nullptr;
47 std::vector<char*> vargs;
49 // start index 1 to avoid passing executable name "dotnet-launcher" as a parameter
50 for (i = 1; i <argc; i++) {
51 if (VersionOption.compare(argv[i]) == 0) {
52 printf("Dotnet launcher Version %s\n", LAUNCHER_VERSION_STR);
54 } else if (StandaloneOption.compare(argv[i]) == 0) {
58 fprintf(stderr, "Assembly path must be after \"--standalone\" option\n");
62 standalonePath = argv[i];
64 vargs.push_back(argv[i]);
68 using tizen::runtime::LauncherInterface;
69 using tizen::runtime::Launchpad;
70 using tizen::runtime::AppInfo;
71 std::unique_ptr<LauncherInterface> runtime;
73 using tizen::runtime::dotnetcore::CoreRuntime;
74 std::unique_ptr<LauncherInterface> coreRuntime(new CoreRuntime());
75 runtime = std::move(coreRuntime);
78 _DBG("##### Run it standalone #########");
79 const char* appId = getenv("AUL_APPID");
80 _DBG("AUL_APPID : %s", appId);
82 if (appId != nullptr) {
83 const char* appRootPath = aul_get_app_root_path();
84 if (appRootPath != nullptr)
85 appRoot = std::string(appRootPath);
87 appId = "dotnet-launcher";
91 appRoot = baseName(baseName(standalonePath));
92 if (runtime->initialize(true) != 0) {
93 _ERR("Failed to initialize");
97 int argsLen = vargs.size();
98 char** args = &vargs[0];
99 if (runtime->launch(appId, appRoot.c_str(), standalonePath, argsLen, args)) {
100 _ERR("Failed to launch");
104 Launchpad.onCreate = [&runtime]() {
105 if (runtime->initialize(false) != 0)
106 _ERR("Failed to initialized");
108 _DBG("Success to initialized");
111 Launchpad.onTerminate = [&runtime](const AppInfo& appInfo, int argc, char** argv) {
112 _DBG("terminated with app path : %s", appInfo.path.c_str());
113 _DBG("appId : %s", appInfo.id.c_str());
114 _DBG("pkg : %s", appInfo.pkg.c_str());
115 _DBG("type : %s", appInfo.type.c_str());
117 // The launchpad pass the name of exe file to the first argument.
118 // For the C# spec, we have to skip this first argument.
120 if (runtime->launch(appInfo.id.c_str(), appInfo.root.c_str(), appInfo.path.c_str(), argc-1, argv+1))
121 _ERR("Failed to launch");
123 Launchpad.loaderMain(argc, argv);