2 * Copyright (c) 2023 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 #ifndef LAUNCHPAD_PROCESS_POOL_LOADER_MANAGER_HH_
18 #define LAUNCHPAD_PROCESS_POOL_LOADER_MANAGER_HH_
20 #include <bundle_cpp.h>
22 #include <sys/types.h>
26 #include <string_view>
29 #include <app_info.hh>
30 #include <hw_acceleration_config.hh>
32 #include "launchpad-process-pool/app_defined_loader_info_manager.hh"
33 #include "launchpad-process-pool/app_labels_monitor.hh"
34 #include "launchpad-process-pool/hydra_loader_context.hh"
35 #include "launchpad-process-pool/loader_context.hh"
36 #include "launchpad-process-pool/loader_info.hh"
37 #include "launchpad-process-pool/loader_mount.hh"
38 #include "launchpad-process-pool/memory_monitor.hh"
39 #include "launchpad-process-pool/sequencer.hh"
43 class LoaderManager : public AppDefinedLoaderInfoManager::IEvent,
44 public AppLabelsMonitor::IEvent,
45 public MemoryMonitor::IEvent,
46 public Sequencer::IEvent,
47 public LoaderContext::IEvent {
51 virtual ~IEvent() = default;
52 virtual void OnLoaderLaunched(LoaderContext* context) = 0;
53 virtual void OnLoaderPrepared(LoaderContext* context) = 0;
56 LoaderManager(const LoaderManager&) = delete;
57 LoaderManager& operator=(const LoaderManager&) = delete;
58 LoaderManager(LoaderManager&&) = delete;
59 LoaderManager& operator=(LoaderManager&&) = delete;
61 static LoaderManager& GetInst();
64 void PrepareApp(const std::shared_ptr<LoaderContext>& context,
65 const AppInfo* app_info);
66 void SetEventListener(IEvent* event_listener);
67 void HandleSigchld(pid_t pid);
68 void AddDefaultLoaderContexts();
69 void ActivateLoaderContexts(LoaderMethod method);
70 std::shared_ptr<LoaderContext> PrepareAppDefinedLoaderContext(
71 const std::string& name, pid_t caller_pid);
72 std::shared_ptr<LoaderContext> AddLoaderContext(tizen_base::Bundle b);
73 void UpdateAppInstallationStatus(const std::string& app_type,
75 void HandleDirectLaunch(std::shared_ptr<LoaderContext> context);
76 std::shared_ptr<LoaderContext> FindLoaderContext(LoaderType type,
78 std::shared_ptr<LoaderContext> FindAvailableLoaderContext(
79 const std::string& hwacc, const std::string& app_type,
80 const std::string& loader_name);
81 std::shared_ptr<LoaderContext> FindAlternativeLoaderContext(LoaderType type);
82 void RemoveLoaderContext(LoaderType type, int loader_id);
83 std::shared_ptr<LoaderContext> FindLoaderContextFromName(
84 const std::string& loader_name);
85 std::shared_ptr<LoaderContext> FindLoaderContextFromPid(pid_t pid);
92 std::shared_ptr<HydraLoaderContext> FindHydraLoaderContextFromPid(pid_t pid);
93 std::shared_ptr<LoaderContext> FindLoaderContextFromLoaderId(int loader_id);
94 std::shared_ptr<LoaderContext> FindLoaderContextFromType(LoaderType type);
95 void RemoveLoaderContextsByCallerPid(pid_t caller_pid);
96 bool IsHwAcceleration(const std::string& hwacc);
97 void UpdateLoaderContext(LoaderType type);
98 void RemoveLoaderContext(const std::string_view loader_name);
99 void UpdateLoaderContexts(bool low_memory);
100 void HandleMemoryStatusChangedEvent(bool low_memory);
101 void UpdatePssMemoryOfLoaderContexts();
102 void SortLoaderContexts();
103 void DeactivateLoaderContexts();
104 void ActivateLoaderContexts();
106 void OnAppLabelsChanged() override;
107 void OnMemoryStatusChanged(bool low_memory, bool should_check_pss) override;
108 void OnLoaderInfoAdded(const std::string_view name) override;
109 void OnLoaderInfoRemoved(const std::string_view name) override;
110 void OnTimeoutEvent(LoaderContext* context) override;
111 bool OnIdleCheck(LoaderContext* context) override;
112 void OnLoaderLaunch(LoaderContext* context) override;
113 void OnLoaderPrepared(LoaderContext* context) override;
114 void OnLoaderLaunched(LoaderContext* context) override;
117 bool disposed_ = true;
118 IEvent* event_listener_ = nullptr;
119 std::unique_ptr<Sequencer> sequencer_;
120 std::unique_ptr<LoaderInfoManager> loader_info_manager_;
121 std::unique_ptr<AppDefinedLoaderInfoManager> app_defined_loader_info_manager_;
122 std::vector<std::shared_ptr<LoaderContext>> loader_contexts_;
123 std::unique_ptr<HWAccelerationConfig> hwacc_config_;
124 std::shared_ptr<LoaderMount> loader_mount_;
127 } // namespace launchpad
129 #endif // LAUNCHPAD_PROCESS_POOL_LOADER_MANAGER_HH_