2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Lukasz Pawelczyk <l.pawelczyk@partner.samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
21 * @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
22 * @brief Declaration of the class for managing one zone
26 #ifndef SERVER_ZONE_HPP
27 #define SERVER_ZONE_HPP
29 #include "zone-config.hpp"
30 #include "zone-admin.hpp"
31 #include "zone-connection.hpp"
32 #include "zone-connection-transport.hpp"
33 #include "zone-provision.hpp"
34 #include "utils/worker.hpp"
39 #include <boost/regex.hpp>
50 * @param zonesPath directory where zones are defined (lxc configs, rootfs etc)
51 * @param zoneConfigPath path for zones config
52 * @param lxcTemplatePrefix directory where templates are stored
53 * @param baseRunMountPointPath base directory for run mount point
55 Zone(const utils::Worker::Pointer& worker,
56 const std::string& zonesPath,
57 const std::string& zoneConfigPath,
58 const std::string& lxcTemplatePrefix,
59 const std::string& baseRunMountPointPath);
60 Zone(Zone&&) = default;
63 typedef ZoneConnection::NotifyActiveZoneCallback NotifyActiveZoneCallback;
64 typedef ZoneConnection::DisplayOffCallback DisplayOffCallback;
65 typedef ZoneConnection::FileMoveRequestCallback FileMoveRequestCallback;
66 typedef ZoneConnection::ProxyCallCallback ProxyCallCallback;
68 typedef std::function<void(const std::string& address)> DbusStateChangedCallback;
69 typedef std::function<void(bool succeeded)> StartAsyncResultCallback;
72 * Returns a vector of regexps defining files permitted to be
73 * send to other zones using file move functionality
75 const std::vector<boost::regex>& getPermittedToSend() const;
78 * Returns a vector of regexps defining files permitted to be
79 * send to other zones using file move functionality
81 const std::vector<boost::regex>& getPermittedToRecv() const;
88 const std::string& getId() const;
91 * Get the zone privilege
93 int getPrivilege() const;
96 * Boot the zone to the background.
101 * Boot the zone to the background in separate thread. This function immediately exits
102 * after zone booting is started in another thread.
104 * @param callback Called after starting the zone. Passes bool with result of starting.
106 void startAsync(const StartAsyncResultCallback& callback);
109 * Try to shutdown the zone, if failed, destroy it.
114 * Activate this zone's VT
116 * @return Was activation successful?
121 * Setup this zone to be put in the foreground.
122 * I.e. set appropriate scheduler level.
127 * Setup this zone to be put in the background.
128 * I.e. set appropriate scheduler level.
133 * Set if zone should be detached on exit.
135 * This sends detach flag to ZoneAdmin object and disables unmounting tmpfs
136 * in ZoneConnectionTransport.
138 void setDetachOnExit();
141 * Set if zone should be destroyed on exit.
143 void setDestroyOnExit();
146 * @return Is the zone running?
151 * Check if the zone is stopped. It's NOT equivalent to !isRunning,
152 * because it checks different internal libvirt's states. There are other states,
153 * (e.g. paused) when the zone isn't running nor stopped.
155 * @return Is the zone stopped?
170 * @return Is the zone in a paused state?
174 // ZoneConnection API
177 * @return Is switching to default zone after timeout allowed?
179 bool isSwitchToDefaultAfterTimeoutAllowed() const;
182 * Register notification request callback
184 void setNotifyActiveZoneCallback(const NotifyActiveZoneCallback& callback);
187 * Register callback used when switching to default zone.
189 void setDisplayOffCallback(const DisplayOffCallback& callback);
192 * Register proxy call callback
194 void setProxyCallCallback(const ProxyCallCallback& callback);
197 * Send notification signal to this zone
199 * @param zone name of zone in which the notification occurred
200 * @param application name of application that cause notification
201 * @param message message to be send to zone
203 void sendNotification(const std::string& zone,
204 const std::string& application,
205 const std::string& message);
208 * Register file move request callback
210 void setFileMoveRequestCallback(const FileMoveRequestCallback& callback);
213 * Register dbus state changed callback
215 void setDbusStateChangedCallback(const DbusStateChangedCallback& callback);
220 void proxyCallAsync(const std::string& busName,
221 const std::string& objectPath,
222 const std::string& interface,
223 const std::string& method,
224 GVariant* parameters,
225 const dbus::DbusConnection::AsyncMethodCallCallback& callback);
230 std::string getDbusAddress() const;
238 * Declare file, directory or pipe that will be created while zone startup
240 void declareFile(const int32_t& type,
241 const std::string& path,
242 const int32_t& flags,
243 const int32_t& mode);
245 * Declare mount that will be created while zone startup
247 void declareMount(const std::string& source,
248 const std::string& target,
249 const std::string& type,
250 const int64_t& flags,
251 const std::string& data);
253 * Declare link that will be created while zone startup
255 void declareLink(const std::string& source,
256 const std::string& target);
261 std::string getRootPath() const;
264 utils::Worker::Pointer mWorker;
266 std::vector<boost::regex> mPermittedToSend;
267 std::vector<boost::regex> mPermittedToRecv;
268 std::unique_ptr<ZoneConnectionTransport> mConnectionTransport;
269 std::unique_ptr<ZoneAdmin> mAdmin;
270 std::unique_ptr<ZoneConnection> mConnection;
271 std::unique_ptr<ZoneProvision> mProvision;
272 mutable std::recursive_mutex mReconnectMutex;
273 NotifyActiveZoneCallback mNotifyCallback;
274 DisplayOffCallback mDisplayOffCallback;
275 FileMoveRequestCallback mFileMoveCallback;
276 ProxyCallCallback mProxyCallCallback;
277 DbusStateChangedCallback mDbusStateChangedCallback;
278 std::string mDbusAddress;
279 std::string mRunMountPoint;
281 void onNameLostCallback();
282 void reconnectHandler();
290 #endif // SERVER_ZONE_HPP