From 56860972bfbd0327bdbcc428f089ecf73b269dd7 Mon Sep 17 00:00:00 2001 From: Youngsoo Choi Date: Wed, 6 Dec 2017 05:17:35 +0000 Subject: [PATCH] [Tizen] Add preloader This implements initial preloader, using loader life-cycle of launchpad. Implementation for preloaded modules will be added later. Change-Id: I75b9b9efde060988066f49e8c07d709d771dc872 Signed-off-by: Youngsoo Choi --- atom/app/atom_main.cc | 29 +++++++-- efl/build/system.gyp | 42 +++++++++++++ electron.gyp | 2 + packaging/electron-efl.spec | 3 + tizen/loader/loader.gyp | 17 +++++ tizen/loader/prelauncher.cc | 150 ++++++++++++++++++++++++++++++++++++++++++++ tizen/loader/prelauncher.h | 50 +++++++++++++++ 7 files changed, 287 insertions(+), 6 deletions(-) create mode 100755 tizen/loader/prelauncher.cc create mode 100755 tizen/loader/prelauncher.h diff --git a/atom/app/atom_main.cc b/atom/app/atom_main.cc index 28959e5..2b33586 100644 --- a/atom/app/atom_main.cc +++ b/atom/app/atom_main.cc @@ -32,9 +32,11 @@ #endif #include "atom/app/node_main.h" +#include "tizen/loader/prelauncher.h" #include "atom/common/atom_command_line.h" #include "base/at_exit.h" #include "base/i18n/icu_util.h" +#include "base/logging.h" namespace { @@ -127,10 +129,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { #elif defined(OS_LINUX) // defined(OS_WIN) -#if defined(OS_TIZEN) -__attribute__((visibility("default"))) -#endif -int main(int argc, const char* argv[]) { +int real_main(int argc, char* argv[]) { if (IsEnvSet(kRunAsNode)) { base::i18n::InitializeICU(); base::AtExitManager atexit_manager; @@ -138,7 +137,7 @@ int main(int argc, const char* argv[]) { } #if defined(USE_EFL) - if (efl::Initialize(argc, argv)) + if (efl::Initialize(argc, const_cast(argv))) return 1; // Add params for EFL port @@ -153,11 +152,29 @@ int main(int argc, const char* argv[]) { atom::AtomMainDelegate delegate; content::ContentMainParams params(&delegate); params.argc = argc; - params.argv = argv; + params.argv = const_cast(argv); atom::AtomCommandLine::Init(argc, argv); return content::ContentMain(params); } +#if defined(OS_TIZEN) +__attribute__((visibility("default"))) +#endif +int main(int argc, const char* argv[]) { + if (strcmp(argv[0], "/usr/bin/wrt-loader") == 0) { + LOG(INFO) << "run with wrt-loader"; + auto preload = [argv](void) { + }; + auto did_launch = [](const std::string& app_path) { + }; + auto prelaunch = runtime::PreLauncher::Prelaunch; + return prelaunch(argc, const_cast(argv), preload, did_launch, real_main); + } else { + LOG(INFO) << "run without wrt-loader"; + return real_main(argc, const_cast(argv)); + } +} + #else // defined(OS_LINUX) int main(int argc, const char* argv[]) { diff --git a/efl/build/system.gyp b/efl/build/system.gyp index b35dd83..8934237 100644 --- a/efl/build/system.gyp +++ b/efl/build/system.gyp @@ -8,6 +8,27 @@ }, 'targets': [ { + 'target_name': 'ecore', + 'type': 'none', + 'conditions': [ + ['is_tizen==1', { + 'direct_dependent_settings': { + 'cflags': [ + ' +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace runtime { + +PreLauncher::PreLauncher() { + ecore_init(); +} + +PreLauncher::~PreLauncher() { + ecore_shutdown(); +} + +void PreLauncher::StartMainLoop() { + ecore_main_loop_begin(); +} + +void PreLauncher::StopMainLoop() { + ecore_main_loop_quit(); +} + +void PreLauncher::Watch(int fd, std::function readable) { + auto callback = [](void *user_data, Ecore_Fd_Handler *fd_handler) { + PreLauncher* launcher = static_cast(user_data); + if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { + int fd = ecore_main_fd_handler_fd_get(fd_handler); + auto handler = launcher->handlers_[fd_handler]; + if (handler) + handler(fd); + } + return ECORE_CALLBACK_RENEW; + }; + Ecore_Fd_Handler* handler = + ecore_main_fd_handler_add(fd, + static_cast(ECORE_FD_READ), + callback, this, NULL, NULL); + handlers_[handler] = readable; + fd_map_[fd] = handler; +} + +void PreLauncher::Unwatch(int fd) { + auto found = fd_map_.find(fd); + if (found == fd_map_.end()) + return; + auto handle = found->second; + ecore_main_fd_handler_del(handle); + fd_map_.erase(found); + handlers_.erase(handle); +} + +int PreLauncher::Prelaunch(int argc, char* argv[], + Preload preload, DidStart didstart, RealMain realmain) { + std::unique_ptr launcher(new PreLauncher()); + launcher->preload_ = preload; + launcher->didstart_ = didstart; + launcher->realmain_ = realmain; + + auto create = [](bundle* extra, int type, void *user_data) { + LOG(INFO) << "create"; + PreLauncher* launcher = static_cast(user_data); + launcher->preload_(); + }; + + auto launch = [](int argc, char **argv, const char *app_path, + const char *appid, const char *pkgid, + const char *pkg_type, void *user_data) { + LOG(INFO) << "launch"; + PreLauncher* launcher = static_cast(user_data); + launcher->didstart_(app_path); + return 0; + }; + + auto terminate = [](int argc, char **argv, void *user_data) { + LOG(INFO) << "terminate"; + PreLauncher* launcher = static_cast(user_data); + return launcher->realmain_(argc, argv); + }; + + auto start_loop = [](void *user_data) { + LOG(INFO) << "start_loop"; + PreLauncher* launcher = static_cast(user_data); + launcher->StartMainLoop(); + }; + + auto stop_loop = [](void *user_data) { + LOG(INFO) << "stop_loop"; + PreLauncher* launcher = static_cast(user_data); + launcher->StopMainLoop(); + }; + + auto add_fd = [](void *user_data, int fd, loader_receiver_cb receiver) { + LOG(INFO) << "add_fd"; + PreLauncher* launcher = static_cast(user_data); + launcher->Watch(fd, receiver); + }; + + auto remove_fd = [](void *user_data, int fd) { + LOG(INFO) << "remove_fd"; + PreLauncher* launcher = static_cast(user_data); + launcher->Unwatch(fd); + }; + + loader_lifecycle_callback_s callbacks = { + create, + launch, + terminate + }; + + loader_adapter_s loop_methods = { + start_loop, + stop_loop, + add_fd, + remove_fd + }; + + LOG(INFO) << "launchpad_loader_main is called !!"; + return launchpad_loader_main(argc, argv, + &callbacks, + &loop_methods, + launcher.get()); +} + +} // namespace runtime diff --git a/tizen/loader/prelauncher.h b/tizen/loader/prelauncher.h new file mode 100755 index 0000000..3051c97 --- /dev/null +++ b/tizen/loader/prelauncher.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +namespace runtime { + +class PreLauncher { + public: + using Preload = std::function; + using DidStart = std::function; + using RealMain = std::function; + static int Prelaunch(int argc, char* argv[], Preload, DidStart, RealMain); + + PreLauncher(); + ~PreLauncher(); + + private: + void StartMainLoop(); + void StopMainLoop(); + + void Watch(int fd, std::function readable); + void Unwatch(int fd); + + Preload preload_; + DidStart didstart_; + RealMain realmain_; + + std::map > handlers_; + std::map fd_map_; +}; + +} // namespace runtime -- 2.7.4