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_PROCESS_POOL_HH_
18 #define LAUNCHPAD_PROCESS_POOL_PROCESS_POOL_HH_
21 #include <sys/types.h>
27 #include <app_packet.hh>
30 #include "launchpad-process-pool/executor.hh"
34 class ProcessPool : public Executor::Delegator,
39 virtual ~IEvent() = default;
40 virtual void OnRequestReceived(std::shared_ptr<AppPacket> app_packet) = 0;
43 explicit ProcessPool(int num_processes, IEvent* event_listener);
44 virtual ~ProcessPool();
46 bool IsPrepared() const;
47 pid_t Execute(std::shared_ptr<AppPacket> app_packet);
52 Process(pid_t pid, int fd);
55 int Send(std::shared_ptr<AppPacket> app_packet);
60 std::unique_ptr<Socket> socket_;
63 void OnExecution() override;
65 void PrepareProcess();
66 int WaitForRequest(std::unique_ptr<Socket> socket);
68 static gboolean OnTimeout(gpointer user_data);
72 IEvent* event_listener_;
73 int pipe_fd_[2] = { -1, -1 };
74 std::queue<std::shared_ptr<Process>> queue_;
78 } // namespace launchpad
80 #endif // LAUNCHPAD_PROCESS_POOL_PROCESS_POOL_HH_