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");
40 static std::string NativeOption("--native");
42 int main(int argc, char *argv[])
45 bool standalone = false;
46 const char* standalonePath = nullptr;
47 bool nativeOnly = false;
49 std::vector<char*> vargs;
51 // start index 1 to avoid passing executable name "dotnet-launcher" as a parameter
52 for (i=1; i<argc; i++)
54 if (VersionOption.compare(argv[i]) == 0)
56 printf("Dotnet launcher Version %s\n", LAUNCHER_VERSION_STR);
59 else if (StandaloneOption.compare(argv[i]) == 0)
65 fprintf(stderr, "Assembly path must be after \"--standalone\" option\n");
69 standalonePath = argv[i];
71 else if (NativeOption.compare(argv[i]) == 0)
77 vargs.push_back(argv[i]);
81 if (!standalone && nativeOnly)
83 fprintf(stderr, "\"--native\" option must be use with \"--standalone\"\n");
87 using tizen::runtime::LauncherInterface;
88 using tizen::runtime::Launchpad;
89 using tizen::runtime::AppInfo;
90 std::unique_ptr<LauncherInterface> runtime;
92 using tizen::runtime::dotnetcore::CoreRuntime;
93 std::unique_ptr<LauncherInterface> coreRuntime(new CoreRuntime());
94 runtime = std::move(coreRuntime);
98 _DBG("##### Run it standalone #########");
99 const char* appid = getenv("AUL_APPID");
100 _DBG("AUL_APPID : %s", appid);
102 if (appid != nullptr)
104 const char* approot_path = aul_get_app_root_path();
105 if (approot_path != nullptr)
107 approot = std::string(approot_path);
112 approot = Basename(standalonePath);
114 if (runtime->Initialize(true) != 0)
116 _ERR("Failed to initialize");
120 if (!nativeOnly && runtime->RunManagedLauncher() != 0)
122 _ERR("Failed to run managed launcher");
126 int args_len = vargs.size();
127 char** args = &vargs[0];
128 if (runtime->Launch(approot.c_str(), standalonePath, args_len, args))
130 _ERR("Failed to launch");
136 Launchpad.OnCreate = [&runtime]()
138 if (runtime->Initialize(false) != 0)
140 _ERR("Failed to initialized");
144 auto idle_task = [](void *data) -> Eina_Bool
146 LauncherInterface* runtime = static_cast<LauncherInterface*>(data);
147 if (runtime->RunManagedLauncher() != 0)
149 _ERR("Failed to run managed launcher");
151 return ECORE_CALLBACK_CANCEL;
153 ecore_idler_add(idle_task, runtime.get());
157 Launchpad.OnTerminate = [&runtime](const AppInfo& info, int argc, char** argv)
159 _DBG("terminated with app path : %s", info.path.c_str());
160 _DBG("appid : %s", info.id.c_str());
161 _DBG("pkg : %s", info.pkg.c_str());
162 _DBG("type : %s", info.type.c_str());
164 // The launchpad pass the name of exe file to the first argument.
165 // For the C# spec, we have to skip this first argument.
167 if (runtime->Launch(info.root.c_str(), info.path.c_str(), argc-1, argv+1))
169 _ERR("Failed to launch");
172 Launchpad.LoaderMain(argc, argv);