a55ca3098547f83f283f4a36f95aa90d0d053260
[platform/core/appfw/launchpad.git] / src / launchpad-process-pool / loader_executor.hh
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef LAUNCHPAD_PROCESS_POOL_LOADER_EXECUTOR_HH_
18 #define LAUNCHPAD_PROCESS_POOL_LOADER_EXECUTOR_HH_
19
20 #include <memory>
21 #include <string>
22 #include <vector>
23
24 #include "launchpad-process-pool/executor.hh"
25 #include "launchpad-process-pool/loader_context.hh"
26 #include "launchpad-process-pool/process_pool.hh"
27
28 namespace launchpad {
29
30 class LoaderExecutor : public Executor::Delegator,
31                        public Executor,
32                        public ProcessPool::IEvent {
33  public:
34   LoaderExecutor(const LoaderExecutor&) = delete;
35   LoaderExecutor& operator=(const LoaderExecutor&) = delete;
36   LoaderExecutor(LoaderExecutor&&) = delete;
37   LoaderExecutor& operator=(LoaderExecutor&&) = delete;
38
39   static LoaderExecutor& GetInst();
40
41   pid_t Execute(const LoaderContext* loader_context, int priority);
42   bool HasCandidateProcess() const;
43
44  private:
45   LoaderExecutor();
46   ~LoaderExecutor() = default;
47
48   void OnExecution() override;
49   void OnRequestReceived(std::shared_ptr<AppPacket> app_packet) override;
50   std::vector<std::string> CreateLoaderArgv(
51       const LoaderContext* loader_context);
52
53  private:
54   std::unique_ptr<ProcessPool> process_pool_;
55   std::vector<std::string> loader_argv_;
56 };
57
58 }  // namespace launchpad
59
60 #endif  // LAUNCHPAD_PROCESS_POOL_LOADER_EXECUTOR_HH_