1 // Copyright 2020 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BROWSER_WRT_SERVICE_MANAGER_H_
6 #define BROWSER_WRT_SERVICE_MANAGER_H_
11 #include <unordered_map>
15 #include "wrt/src/browser/wrt_ipc.h"
16 #include "wrt/src/common/application_data.h"
17 #include "wrt/src/service/wrt_service.h"
21 class WRTServiceManager {
23 static WRTServiceManager* Get(bool can_create = true);
26 void CloseDbusHandler();
27 void DelayShutdown(int exit_count = 120);
28 void FinalizeService(const std::string& internal_id);
29 void InitServiceApp(int argc, char** argv);
30 void KillLauncherProcess(const std::string& internal_id);
31 void StartService(const std::string& internal_id,
32 const std::string& source_name,
33 const std::string& pkg_path);
34 void StopService(const std::string& internal_id);
36 void RunBuiltinService(const std::string& service_name,
37 const std::string& internal_id,
38 const std::string& pkg_path);
40 void SetServiceModel(WRTService::ServiceType service_model);
43 bool CheckLauncherAlive(const std::string& internal_id);
44 bool FinishStartingService(const std::string& internal_id);
45 bool IsStandaloneService();
46 bool IsQuitting() { return quit_requested_; }
47 bool SendMessage(const char* type, const char* argument);
48 bool SendMessage(const char* receiver, const char* type, const char* argument);
49 bool DidStartService(const std::string& internal_id);
51 WRTService::ServiceType GetServiceModel();
53 std::string GetAppControlData(std::string& app_id);
54 std::string GetRuntimeVariable(const std::string& runtime_key);
55 std::string SendMessageAndWaitReply(const char* type, const char* argument);
57 ApplicationData* GetApplicationData(const std::string& internal_id);
63 static void OnBuiltinService(uv_async_t* handle);
64 static void OnServiceStarted(uv_async_t* handle);
65 static void OnServiceStopped(uv_async_t* handle);
67 void InitAulHandler(int argc, char** argv);
68 void CloseUvHandlers();
69 void CreateUvHandlers();
70 bool CheckParentProcessValid(int pid);
71 bool HandleMessageQueue();
72 int RegisterDbusHandler();
74 uv_async_t handle_adder_ = {};
75 uv_async_t handle_remover_ = {};
76 uv_async_t handle_builtin_ = {};
79 std::vector<std::string> prepared_to_start_services_;
80 std::vector<std::string> prepared_to_stop_services_;
81 std::unordered_map<std::string, std::string> ui_source_names_;
83 wrt::InterProcessCommunication ipc_;
84 std::string internal_id_;
85 std::string removed_internal_id;
87 uv_thread_t dbus_thread_ = {};
88 uv_timer_t timeout_handle_ = {};
89 WRTService::ServiceType service_model_ = WRTService::NONE;
90 unsigned int exit_count_ = 120;
91 bool quit_requested_ = false;
97 #endif // BROWSER_WRT_SERVICE_MANAGER_H_