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 * Try to shutdown the zone, if failed, destroy it.
106 * Activate this zone's VT
108 * @return Was activation successful?
113 * Setup this zone to be put in the foreground.
114 * I.e. set appropriate scheduler level.
119 * Setup this zone to be put in the background.
120 * I.e. set appropriate scheduler level.
125 * Set if zone should be detached on exit.
127 * This sends detach flag to ZoneAdmin object and disables unmounting tmpfs
128 * in ZoneConnectionTransport.
130 void setDetachOnExit();
133 * Set if zone should be destroyed on exit.
135 void setDestroyOnExit();
138 * @return Is the zone running?
143 * Check if the zone is stopped. It's NOT equivalent to !isRunning,
144 * because it checks different internal libvirt's states. There are other states,
145 * (e.g. paused) when the zone isn't running nor stopped.
147 * @return Is the zone stopped?
162 * @return Is the zone in a paused state?
166 // ZoneConnection API
169 * @return Is switching to default zone after timeout allowed?
171 bool isSwitchToDefaultAfterTimeoutAllowed() const;
174 * Register notification request callback
176 void setNotifyActiveZoneCallback(const NotifyActiveZoneCallback& callback);
179 * Register callback used when switching to default zone.
181 void setDisplayOffCallback(const DisplayOffCallback& callback);
184 * Register proxy call callback
186 void setProxyCallCallback(const ProxyCallCallback& callback);
189 * Send notification signal to this zone
191 * @param zone name of zone in which the notification occurred
192 * @param application name of application that cause notification
193 * @param message message to be send to zone
195 void sendNotification(const std::string& zone,
196 const std::string& application,
197 const std::string& message);
200 * Register file move request callback
202 void setFileMoveRequestCallback(const FileMoveRequestCallback& callback);
205 * Register dbus state changed callback
207 void setDbusStateChangedCallback(const DbusStateChangedCallback& callback);
212 void proxyCallAsync(const std::string& busName,
213 const std::string& objectPath,
214 const std::string& interface,
215 const std::string& method,
216 GVariant* parameters,
217 const dbus::DbusConnection::AsyncMethodCallCallback& callback);
222 std::string getDbusAddress() const;
230 * Declare file, directory or pipe that will be created while zone startup
232 void declareFile(const int32_t& type,
233 const std::string& path,
234 const int32_t& flags,
235 const int32_t& mode);
237 * Declare mount that will be created while zone startup
239 void declareMount(const std::string& source,
240 const std::string& target,
241 const std::string& type,
242 const int64_t& flags,
243 const std::string& data);
245 * Declare link that will be created while zone startup
247 void declareLink(const std::string& source,
248 const std::string& target);
253 std::string getRootPath() const;
256 utils::Worker::Pointer mWorker;
258 std::vector<boost::regex> mPermittedToSend;
259 std::vector<boost::regex> mPermittedToRecv;
260 std::unique_ptr<ZoneConnectionTransport> mConnectionTransport;
261 std::unique_ptr<ZoneAdmin> mAdmin;
262 std::unique_ptr<ZoneConnection> mConnection;
263 std::unique_ptr<ZoneProvision> mProvision;
264 mutable std::recursive_mutex mReconnectMutex;
265 NotifyActiveZoneCallback mNotifyCallback;
266 DisplayOffCallback mDisplayOffCallback;
267 FileMoveRequestCallback mFileMoveCallback;
268 ProxyCallCallback mProxyCallCallback;
269 DbusStateChangedCallback mDbusStateChangedCallback;
270 std::string mDbusAddress;
271 std::string mRunMountPoint;
273 void onNameLostCallback();
274 void reconnectHandler();
282 #endif // SERVER_ZONE_HPP