#include "content/common/paths_efl.h"
#include "electron/shell/app/node_main.h"
#include "tizen_src/ewk/efl_integration/command_line_efl.h"
-#include "wrt/src/base/string_utils.h"
#include "wrt/src/common/application_data.h"
#include "wrt/src/service/wrt_service_manager.h"
-#if BUILDFLAG(IS_TIZEN_TV)
-#include "wrt/src/browser/tv/encrypted_file_handler.h"
-#include "wrt/src/common/constants.h"
-#endif
-
void _register_wrt();
void _register_wrt_xwalk_extension();
namespace wrt {
-namespace {
-
-uv_thread_t dbus_thread;
-
-void DbusStartService(const char*, const char* internal_id,
- const InterProcessCommunication::Message& message) {
- auto service_manager = WRTServiceManager::Get();
- if (service_manager->IsQuitting())
- return;
-
- auto service_id = ApplicationData::GetServiceID(internal_id);
- std::string pkg_path = ApplicationData::GetPackagePath(service_id);
- service_manager->StartService(internal_id, message.Sender(), pkg_path);
- message.Reply("Success");
-}
-
-void DbusStopService(const char*, const char* internal_id,
- const InterProcessCommunication::Message& message) {
- auto service_manager = WRTServiceManager::Get();
- if (service_manager->IsQuitting())
- return;
-
- if (service_manager->DidStartService(internal_id)) {
- service_manager->StopService(internal_id);
- message.Reply("Success");
- } else {
- LOG(WARNING) << internal_id << " isn't running";
- message.Reply("Failed");
- }
-}
-
-void DbusSetAppcontrolData(const char*, const char* argument,
- const InterProcessCommunication::Message& message) {
- auto service_manager = WRTServiceManager::Get();
- if (service_manager->IsQuitting())
- return;
-
- if (!argument) {
- LOG(ERROR) << "There is no argument of SetAppcontrolData";
- return;
- }
- auto appcontrol_argv = base::SplitString(std::string(argument), ":",
- base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- if (appcontrol_argv.size() != 2) {
- LOG(ERROR) << "Argument should be {app_id}:{app_control_data}";
- return;
- }
- service_manager->SetAppcontrolData(appcontrol_argv[0], appcontrol_argv[1]);
-}
-
-void DbusBuiltinService(const char*, const char* argument,
- const InterProcessCommunication::Message& message) {
- auto service_manager = WRTServiceManager::Get();
- if (service_manager->IsQuitting())
- return;
-
- if (!argument) {
- LOG(ERROR) << "There is no argument of BuiltinService";
- return;
- }
- auto service_argv = base::SplitString(std::string(argument), ":",
- base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- if (service_argv.size() != 3) {
- LOG(ERROR) << "Argument should be {service_name}:{app_id}:{app_path}";
- return;
- }
- auto& service_name = service_argv[0];
- auto& app_id = service_argv[1];
- auto& app_path = service_argv[2];
- LOG(INFO) << "Service Name: " << service_name << ", " << app_id << "("
- << app_path << ")";
- service_manager->RunBuiltinService(service_name, app_id, app_path);
-}
-
-void DbusDelayShutdown(const char*, const char* argument,
- const InterProcessCommunication::Message& message) {
- auto service_manager = WRTServiceManager::Get();
- if (service_manager->IsQuitting())
- return;
-
- service_manager->DelayShutdown(180);
- LOG(INFO) << "Delay shutdown count to 180";
- message.Reply("Success");
-}
-
-void DbusCloseConnection(const char*, const char*,
- const InterProcessCommunication::Message& message) {
- LOG(INFO) << "Closing connection on CloseDBusConnection";
- message.CloseDBusConnection();
-}
-
-void DbusKillLauncherProcess(const char*, const char* argument,
- const InterProcessCommunication::Message& message) {
- WRTServiceManager::Get()->KillLauncherProcess(argument);
-}
-
-#if BUILDFLAG(IS_TIZEN_TV)
-void DbusDecryptFile(const char*, const char* argument,
- const InterProcessCommunication::Message& message) {
- if (WRTServiceManager::Get()->IsQuitting())
- return;
-
- if (!argument) {
- message.Reply("");
- LOG(ERROR) << "There is no argument of DecryptFile";
- return;
- }
- auto service_argv =
- utils::SplitString(std::string(argument), kInternalIdAndFileDelim);
- auto& internal_id = service_argv[0];
- auto& file_path = service_argv[1];
-
- auto service_id = ApplicationData::GetServiceID(internal_id);
- auto pkg_path = WRTService::GetAppPkgPath(internal_id);
-
- auto decrypted_src = EncryptedFileHandler::DecryptFile(
- service_id, pkg_path, base::FilePath(file_path));
- if (!decrypted_src.GetLength()) {
- message.Reply("");
- return;
- }
- auto decryted_buffer =
- std::string(decrypted_src.GetBuffer(), decrypted_src.GetLength());
- message.Reply(decryted_buffer.c_str());
-}
-
-void DbusReleaseAppDrm(const char*, const char* service_id,
- const InterProcessCommunication::Message& message) {
- EncryptedFileHandler::ReleaseHandle(service_id);
-}
-#endif
-
-int RegisterDbusHandler() {
- uv_thread_create(&dbus_thread, [](void* data) {
- InterProcessCommunication ipc(true);
- ipc.SetExitOnDisconnect(false);
-
- // This daemon handler is called by ui app.
- ipc.AddMessageHandler("StartService", DbusStartService);
- ipc.AddMessageHandler("StopService", DbusStopService);
-
- // by wrt-service-launcher before StartService
- ipc.AddMessageHandler("SetAppcontrolData", DbusSetAppcontrolData);
-
- // by installer (wgt-backend)
- ipc.AddMessageHandler("BuiltinService", DbusBuiltinService);
-
- ipc.AddMessageHandler("DelayShutdown", DbusDelayShutdown);
- ipc.AddMessageHandler("CloseDBusConnection", DbusCloseConnection);
- ipc.AddMessageHandler("KillLauncherProcess", DbusKillLauncherProcess);
-
-#if BUILDFLAG(IS_TIZEN_TV)
- ipc.AddMessageHandler("DecryptFile", DbusDecryptFile);
- ipc.AddMessageHandler("ReleaseAppDrm", DbusReleaseAppDrm);
-#endif
-
- ipc.Listen();
- }, nullptr);
- return 0;
-}
-
-} // namespace
-
// static
WRTService::ServiceType WRTService::GetServiceModel() {
return WRTServiceManager::Get()->GetServiceModel();
service_manager->SetServiceModel(WRTService::GLOBAL);
if (prctl(PR_SET_PDEATHSIG, SIGKILL) == -1)
LOG(ERROR) << "prctl(PR_SET_PDEATHSIG, SIGKILL) has failed";
- RegisterDbusHandler();
#if BUILDFLAG(IS_TIZEN_TV)
} else if (std::string(argv[0]).find("wrt-node") != std::string::npos) {
uv_spawn_enable(1);
electron::NodeMain(sizeof(arguments) / sizeof(char*), arguments);
if (IsGlobalService()) {
service_manager->SendMessage("CloseDBusConnection", "");
- uv_thread_join(&dbus_thread);
+ service_manager->CloseDbusHandler();
LOG(INFO) << "DbusHandler thread is gone";
}
service_manager->Shutdown();
#include "base/strings/string_split.h"
#include "base/threading/platform_thread.h"
#include "tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.h"
+#include "wrt/src/base/string_utils.h"
#include "wrt/src/browser/api/wrt_api_web_runtime.h"
#include "wrt/src/service/wrt_service.h"
-#if BUILDFLAG(IS_TIZEN_TV) && TIZEN_VERSION_AT_LEAST(7, 0, 0)
+#if BUILDFLAG(IS_TIZEN_TV)
+#if TIZEN_VERSION_AT_LEAST(7, 0, 0)
#include <boost-api.h>
#endif
+#include "wrt/src/browser/tv/encrypted_file_handler.h"
+#include "wrt/src/common/constants.h"
+#endif
+
namespace wrt {
namespace {
boost_request_by_pid(getpid(), (const boost_info_t*)&app_info);
}
#endif
-} // namespace
-WRTServiceManager::WRTServiceManager() {
- uv_mutex_init(&mutex_);
- service_model_ = WRTService::GLOBAL;
- ecore_init();
- CreateUvHandlers();
- DelayShutdown();
- uv_init_threadpool();
+void DbusStartService(const char*,
+ const char* internal_id,
+ const InterProcessCommunication::Message& message) {
+ auto service_manager = WRTServiceManager::Get();
+ if (service_manager->IsQuitting())
+ return;
+
+ auto service_id = ApplicationData::GetServiceID(internal_id);
+ std::string pkg_path = ApplicationData::GetPackagePath(service_id);
+ service_manager->StartService(internal_id, message.Sender(), pkg_path);
+ message.Reply("Success");
+}
+
+void DbusStopService(const char*,
+ const char* internal_id,
+ const InterProcessCommunication::Message& message) {
+ auto service_manager = WRTServiceManager::Get();
+ if (service_manager->IsQuitting())
+ return;
+
+ if (service_manager->DidStartService(internal_id)) {
+ service_manager->StopService(internal_id);
+ message.Reply("Success");
+ } else {
+ LOG(WARNING) << internal_id << " isn't running";
+ message.Reply("Failed");
+ }
+}
+
+void DbusSetAppcontrolData(const char*,
+ const char* argument,
+ const InterProcessCommunication::Message& message) {
+ auto service_manager = WRTServiceManager::Get();
+ if (service_manager->IsQuitting())
+ return;
+
+ if (!argument) {
+ LOG(ERROR) << "There is no argument of SetAppcontrolData";
+ return;
+ }
+ auto appcontrol_argv = base::SplitString(
+ std::string(argument), ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ if (appcontrol_argv.size() != 2) {
+ LOG(ERROR) << "Argument should be {app_id}:{app_control_data}";
+ return;
+ }
+ service_manager->SetAppcontrolData(appcontrol_argv[0], appcontrol_argv[1]);
+}
+
+void DbusBuiltinService(const char*,
+ const char* argument,
+ const InterProcessCommunication::Message& message) {
+ auto service_manager = WRTServiceManager::Get();
+ if (service_manager->IsQuitting())
+ return;
+
+ if (!argument) {
+ LOG(ERROR) << "There is no argument of BuiltinService";
+ return;
+ }
+ auto service_argv = base::SplitString(
+ std::string(argument), ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ if (service_argv.size() != 3) {
+ LOG(ERROR) << "Argument should be {service_name}:{app_id}:{app_path}";
+ return;
+ }
+ auto& service_name = service_argv[0];
+ auto& app_id = service_argv[1];
+ auto& app_path = service_argv[2];
+ LOG(INFO) << "Service Name: " << service_name << ", " << app_id << "("
+ << app_path << ")";
+ service_manager->RunBuiltinService(service_name, app_id, app_path);
+}
+
+void DbusDelayShutdown(const char*,
+ const char* argument,
+ const InterProcessCommunication::Message& message) {
+ auto service_manager = WRTServiceManager::Get();
+ if (service_manager->IsQuitting())
+ return;
+
+ service_manager->DelayShutdown(180);
+ LOG(INFO) << "Delay shutdown count to 180";
+ message.Reply("Success");
}
+void DbusCloseConnection(const char*,
+ const char*,
+ const InterProcessCommunication::Message& message) {
+ LOG(INFO) << "Closing connection on CloseDBusConnection";
+ message.CloseDBusConnection();
+}
+
+void DbusKillLauncherProcess(
+ const char*,
+ const char* argument,
+ const InterProcessCommunication::Message& message) {
+ WRTServiceManager::Get()->KillLauncherProcess(argument);
+}
+
+#if BUILDFLAG(IS_TIZEN_TV)
+void DbusDecryptFile(const char*,
+ const char* argument,
+ const InterProcessCommunication::Message& message) {
+ if (WRTServiceManager::Get()->IsQuitting())
+ return;
+
+ if (!argument) {
+ message.Reply("");
+ LOG(ERROR) << "There is no argument of DecryptFile";
+ return;
+ }
+ auto service_argv =
+ utils::SplitString(std::string(argument), kInternalIdAndFileDelim);
+ auto& internal_id = service_argv[0];
+ auto& file_path = service_argv[1];
+
+ auto service_id = ApplicationData::GetServiceID(internal_id);
+ auto pkg_path = WRTService::GetAppPkgPath(internal_id);
+
+ auto decrypted_src = EncryptedFileHandler::DecryptFile(
+ service_id, pkg_path, base::FilePath(file_path));
+ if (!decrypted_src.GetLength()) {
+ message.Reply("");
+ return;
+ }
+ auto decryted_buffer =
+ std::string(decrypted_src.GetBuffer(), decrypted_src.GetLength());
+ message.Reply(decryted_buffer.c_str());
+}
+
+void DbusReleaseAppDrm(const char*,
+ const char* service_id,
+ const InterProcessCommunication::Message& message) {
+ EncryptedFileHandler::ReleaseHandle(service_id);
+}
+#endif
+
+} // namespace
+
+WRTServiceManager::WRTServiceManager() {}
+
WRTServiceManager::~WRTServiceManager() {}
WRTServiceManager* WRTServiceManager::Get(bool can_create) {
return manager;
}
+void WRTServiceManager::CloseDbusHandler() {
+ uv_thread_join(&dbus_thread_);
+}
+
+int WRTServiceManager::RegisterDbusHandler() {
+ uv_thread_create(
+ &dbus_thread_,
+ [](void* data) {
+ InterProcessCommunication ipc(true);
+ ipc.SetExitOnDisconnect(false);
+
+ // This daemon handler is called by ui app.
+ ipc.AddMessageHandler("StartService", DbusStartService);
+ ipc.AddMessageHandler("StopService", DbusStopService);
+
+ // by wrt-service-launcher before StartService
+ ipc.AddMessageHandler("SetAppcontrolData", DbusSetAppcontrolData);
+
+ // by installer (wgt-backend)
+ ipc.AddMessageHandler("BuiltinService", DbusBuiltinService);
+
+ ipc.AddMessageHandler("DelayShutdown", DbusDelayShutdown);
+ ipc.AddMessageHandler("CloseDBusConnection", DbusCloseConnection);
+ ipc.AddMessageHandler("KillLauncherProcess", DbusKillLauncherProcess);
+
+#if BUILDFLAG(IS_TIZEN_TV)
+ ipc.AddMessageHandler("DecryptFile", DbusDecryptFile);
+ ipc.AddMessageHandler("ReleaseAppDrm", DbusReleaseAppDrm);
+#endif
+
+ ipc.Listen();
+ },
+ nullptr);
+ return 0;
+}
+
void WRTServiceManager::Shutdown() {
LOG(INFO) << "WRTServiceManager is in shutdown!";
XWalkExtensionManager::GetInstance()->Shutdown();
}
void WRTServiceManager::InitServiceApp(int argc, char** argv) {
- uv_mutex_lock(&mutex_);
+ uv_mutex_init(&mutex_);
ppid_ = getppid();
if (!CheckParentProcessValid(ppid_))
ppid_ = -1;
- uv_mutex_unlock(&mutex_);
-
+ ecore_init();
+ CreateUvHandlers();
+ DelayShutdown();
+ uv_init_threadpool();
uv_timer_start(&timeout_handle_, OnTimeout, kEventTimeout, kEventTimeout);
InitAulHandler(argc, argv);
+ if (service_model_ == WRTService::GLOBAL)
+ RegisterDbusHandler();
}
WRTService::ServiceType WRTServiceManager::GetServiceModel() {
static WRTServiceManager* Get(bool can_create = true);
void CheckTimeout();
+ void CloseDbusHandler();
void DelayShutdown(int exit_count = 120);
void FinalizeService(const std::string& internal_id);
void InitServiceApp(int argc, char** argv);
void CreateUvHandlers();
bool CheckParentProcessValid(int pid);
bool HandleMessageQueue();
+ int RegisterDbusHandler();
uv_async_t handle_adder_;
uv_async_t handle_remover_;
std::string internal_id_;
std::string removed_internal_id;
+ uv_thread_t dbus_thread_;
uv_timer_t timeout_handle_ = {};
- WRTService::ServiceType service_model_;
+ WRTService::ServiceType service_model_ = WRTService::NONE;
unsigned int exit_count_;
bool quit_requested_ = false;
int ppid_ = 0;