Mount gadget resource paths for NUIGadget
[platform/core/appfw/launchpad.git] / src / launchpad-process-pool / hydra_loader_context.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_HYDRA_LOADER_CONTEXT_HH_
18 #define LAUNCHPAD_PROCESS_POOL_HYDRA_LOADER_CONTEXT_HH_
19
20 #include <sys/types.h>
21
22 #include <memory>
23
24 #include "launchpad-process-pool/loader_context.hh"
25
26 namespace launchpad {
27
28 class HydraLoaderContext : public LoaderContext {
29  public:
30   class Builder : public LoaderContext::Builder {
31    public:
32     operator LoaderContext*() override;
33   };
34
35   HydraLoaderContext(std::shared_ptr<LoaderInfo> loader_info, int loader_id,
36                      pid_t caller_pid, bool activated,
37                      std::shared_ptr<LoaderMount> loader_mount);
38
39   void Listen() override;
40   void Dispose() override;
41   pid_t Prepare() override;
42
43   pid_t GetHydraPid() const;
44   void SetHydraPid(pid_t hydra_pid);
45
46  private:
47   void PrepareCandidateProcess();
48   void HandleHydraLoaderClientEvent(int condition);
49   void HandleHydraLoaderEvent();
50   void OnIOEventReceived(int fd, int condition) override;
51
52  private:
53   bool hydra_prepared_ = false;
54   pid_t hydra_pid_ = 0;
55   std::unique_ptr<ServerSocket> hydra_socket_;
56   std::unique_ptr<IOChannel> hydra_channel_;
57   std::unique_ptr<ClientSocket> client_socket_;
58   std::unique_ptr<IOChannel> client_channel_;
59 };
60
61 }  // namespace launchpad
62
63 #endif  // LAUNCHPAD_PROCESS_POOL_HYDRA_LOADER_CONTEXT_HH_