Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
guard.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License version 2.1 as published by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  */
17 
24 #ifndef LXCPP_GUARD_GUARD_HPP
25 #define LXCPP_GUARD_GUARD_HPP
26 
27 
29 #include "lxcpp/guard/api.hpp"
30 
31 #include "utils/channel.hpp"
32 #include "utils/signalfd.hpp"
33 
34 #include "cargo-ipc/service.hpp"
36 
37 
38 namespace lxcpp {
39 
48 class Guard {
49 public:
50  Guard(const std::string& socketPath);
51  ~Guard();
52 
53  int execute();
54 
55 private:
56  struct ContainerData {
59 
61  : mConfig(config), mChannel(channel) {}
62  };
63 
67  std::unique_ptr<cargo::ipc::Service> mService;
68 
69  std::shared_ptr<ContainerConfig> mConfig;
70 
74  static int startContainer(void *data);
75 
83 
91 
98  void onInitExit(struct ::signalfd_siginfo& sigInfo);
99 
105  bool onSetConfig(const cargo::ipc::PeerID, std::shared_ptr<ContainerConfig>& data, cargo::ipc::MethodResult::Pointer result);
106 
112  bool onGetConfig(const cargo::ipc::PeerID, std::shared_ptr<api::Void>&, cargo::ipc::MethodResult::Pointer result);
113 
117  bool onStart(const cargo::ipc::PeerID, std::shared_ptr<api::Void>&, cargo::ipc::MethodResult::Pointer result);
118 
123  bool onStop(const cargo::ipc::PeerID, std::shared_ptr<api::Void>&, cargo::ipc::MethodResult::Pointer result);
124 
125 };
126 
127 } // namespace lxcpp
128 
129 #endif // LXCPP_GUARD_HPP
C++ epoll wrapper.
utils::Channel & mChannel
Definition: guard.hpp:58
void onDisconnection(const cargo::ipc::PeerID &peerID, const cargo::ipc::FileDescriptor)
Called each time a connection to host is lost.
Definition: guard.cpp:115
cargo::ipc::PeerID mPeerID
Definition: guard.hpp:65
std::shared_ptr< MethodResult > Pointer
Definition: method-result.hpp:47
Declaration of the cargo IPC handling class.
std::string PeerID
Definition: types.hpp:45
bool onStart(const cargo::ipc::PeerID, std::shared_ptr< api::Void > &, cargo::ipc::MethodResult::Pointer result)
Host -> Guard: Start init in a container described by the configuration.
Definition: guard.cpp:168
cargo::ipc::epoll::EventPoll mEventPoll
Definition: guard.hpp:64
ContainerData(ContainerConfig &config, utils::Channel &channel)
Definition: guard.hpp:60
utils::SignalFD mSignalFD
Definition: guard.hpp:66
int execute()
Definition: guard.cpp:223
IPC implementation for related processes.
Signalfd wrapper.
bool onSetConfig(const cargo::ipc::PeerID, std::shared_ptr< ContainerConfig > &data, cargo::ipc::MethodResult::Pointer result)
Called when synchronizing configuration with the host.
Definition: guard.cpp:137
IPC messages declaration.
~Guard()
Definition: guard.cpp:101
char data[368]
Definition: initctl.cpp:41
Definition: container-config.hpp:51
Guard(const std::string &socketPath)
Definition: guard.cpp:77
Guard process used for container's init configuration and control.
Definition: guard.hpp:48
SignalFD takes control over handling signals sent to the thread.
Definition: signalfd.hpp:47
void onInitExit(struct::signalfd_siginfo &sigInfo)
Called when the init process exits.
Definition: guard.cpp:123
std::shared_ptr< ContainerConfig > mConfig
Definition: guard.hpp:69
std::unique_ptr< cargo::ipc::Service > mService
Definition: guard.hpp:67
static int startContainer(void *data)
Setups the init process and executes the init.
Definition: guard.cpp:42
void onConnection(const cargo::ipc::PeerID &peerID, const cargo::ipc::FileDescriptor)
Called each time a new connection is opened to the Guard's socket.
Definition: guard.cpp:105
This class waits on registered file descriptor for events.
Definition: event-poll.hpp:47
int FileDescriptor
Definition: types.hpp:42
Channel is implemented with a pair of anonymous sockets.
Definition: channel.hpp:38
bool onGetConfig(const cargo::ipc::PeerID, std::shared_ptr< api::Void > &, cargo::ipc::MethodResult::Pointer result)
Called when synchronizing configuration with the host.
Definition: guard.cpp:161
ContainerConfig & mConfig
Definition: guard.hpp:57
A definition of a ContainerConfig struct.
Definition: guard.hpp:56
bool onStop(const cargo::ipc::PeerID, std::shared_ptr< api::Void > &, cargo::ipc::MethodResult::Pointer result)
Host -> Guard: Stop the init process and return its exit status.
Definition: guard.cpp:213