2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Jan Olszak <j.olszak@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 Jan Olszak (j.olszak@samsung.com)
22 * @brief Declaration of the class for managing many zones
26 #ifndef SERVER_ZONES_MANAGER_HPP
27 #define SERVER_ZONES_MANAGER_HPP
30 #include "zones-manager-config.hpp"
31 #include "host-connection.hpp"
32 #include "input-monitor.hpp"
33 #include "proxy-call-policy.hpp"
34 #include "utils/worker.hpp"
35 #include "api/method-result-builder.hpp"
44 class ZonesManager final {
47 ZonesManager(const std::string& managerConfigPath);
53 * @param zoneId id of new zone
54 * @param templateName a template name
56 void createZone(const std::string& zoneId, const std::string& templateName);
61 * @param zoneId id of the zone
63 void destroyZone(const std::string& zoneId);
66 * Focus this zone, put it to the foreground.
67 * Method blocks until the focus is switched.
69 * @param zoneId id of the zone
71 void focus(const std::string& zoneId);
74 * Restore all the configured zones to the saved state
79 * Shutdown all managed zones without changing the saved state
84 * @return Is the zone in a paused state?
86 bool isPaused(const std::string& zoneId);
89 * @return Is the zone running?
91 bool isRunning(const std::string& zoneId);
94 * @return Is the zone stopped?
96 bool isStopped(const std::string& zoneId);
99 * @return id of the currently focused/foreground zone
101 std::string getRunningForegroundZoneId();
104 * @return id of next to currently focused/foreground zone. If currently focused zone
105 * is last in zone map, id of fisrt zone from map is returned.
107 std::string getNextToForegroundZoneId();
110 * Set whether ZonesManager should detach zones on exit
112 void setZonesDetachOnExit();
115 typedef std::recursive_mutex Mutex;
116 typedef std::unique_lock<Mutex> Lock;
118 utils::Worker::Pointer mWorker;
119 Mutex mMutex; // used to protect mZones
120 ZonesManagerConfig mConfig; //TODO make it const
121 ZonesManagerDynamicConfig mDynamicConfig;
122 HostConnection mHostConnection;
123 // to hold InputMonitor pointer to monitor if zone switching sequence is recognized
124 std::unique_ptr<InputMonitor> mSwitchingSequenceMonitor;
125 std::unique_ptr<ProxyCallPolicy> mProxyCallPolicy;
126 // like set but keep insertion order
127 // smart pointer is needed because Zone is not moveable (because of mutex)
128 typedef std::vector<std::unique_ptr<Zone>> Zones;
130 std::string mActiveZoneId;
133 Zones::iterator findZone(const std::string& id);
134 Zone& getZone(const std::string& id);
135 Zones::iterator getRunningForegroundZoneIterator();
136 Zones::iterator getNextToForegroundZoneIterator();
137 void focusInternal(Zones::iterator iter);
139 void saveDynamicConfig();
140 void updateDefaultId();
142 void switchingSequenceMonitorNotify();
143 void generateNewConfig(const std::string& id,
144 const std::string& templatePath);
145 std::string getTemplatePathForExistingZone(const std::string& id);
146 int getVTForNewZone();
147 void insertZone(const std::string& zoneId, const std::string& templatePath);
149 // Zone's handlers---------------------------------------------------------
150 void handleNotifyActiveZoneCall(const std::string& caller,
151 const std::string& appliaction,
152 const std::string& message,
153 api::MethodResultBuilder::Pointer result);
154 void handleDisplayOffCall(const std::string& caller);
155 void handleFileMoveCall(const std::string& srcZoneId,
156 const std::string& dstZoneId,
157 const std::string& path,
158 api::MethodResultBuilder::Pointer result);
159 void handleProxyCall(const std::string& caller,
160 const std::string& target,
161 const std::string& targetBusName,
162 const std::string& targetObjectPath,
163 const std::string& targetInterface,
164 const std::string& targetMethod,
165 GVariant* parameters,
166 dbus::MethodResultBuilder::Pointer result);
167 void handleGetZoneDbusesCall(api::MethodResultBuilder::Pointer result);
169 void handleDbusStateChanged(const std::string& zoneId,
170 const std::string& dbusAddress);
171 // Host's handlers --------------------------------------------------------
172 void handleGetZoneIdsCall(api::MethodResultBuilder::Pointer result);
173 void handleGetActiveZoneIdCall(api::MethodResultBuilder::Pointer result);
174 void handleGetZoneInfoCall(const api::ZoneId& data,
175 api::MethodResultBuilder::Pointer result);
176 void handleSetNetdevAttrsCall(const api::SetNetDevAttrsIn& data,
177 api::MethodResultBuilder::Pointer result);
178 void handleGetNetdevAttrsCall(const api::GetNetDevAttrsIn& data,
179 api::MethodResultBuilder::Pointer result);
180 void handleGetNetdevListCall(const api::ZoneId& data,
181 api::MethodResultBuilder::Pointer result);
182 void handleCreateNetdevVethCall(const api::CreateNetDevVethIn& data,
183 api::MethodResultBuilder::Pointer result);
184 void handleCreateNetdevMacvlanCall(const api::CreateNetDevMacvlanIn& data,
185 api::MethodResultBuilder::Pointer result);
186 void handleCreateNetdevPhysCall(const api::CreateNetDevPhysIn& data,
187 api::MethodResultBuilder::Pointer result);
188 void handleDestroyNetdevCall(const api::DestroyNetDevIn& data,
189 api::MethodResultBuilder::Pointer result);
190 void handleDeclareFileCall(const api::DeclareFileIn& data,
191 api::MethodResultBuilder::Pointer result);
192 void handleDeclareMountCall(const api::DeclareMountIn& data,
193 api::MethodResultBuilder::Pointer result);
194 void handleDeclareLinkCall(const api::DeclareLinkIn& data,
195 api::MethodResultBuilder::Pointer result);
196 void handleGetDeclarationsCall(const api::ZoneId& data,
197 api::MethodResultBuilder::Pointer result);
198 void handleRemoveDeclarationCall(const api::RemoveDeclarationIn& data,
199 api::MethodResultBuilder::Pointer result);
200 void handleSetActiveZoneCall(const api::ZoneId& data,
201 api::MethodResultBuilder::Pointer result);
202 void handleCreateZoneCall(const api::CreateZoneIn& data,
203 api::MethodResultBuilder::Pointer result);
204 void handleDestroyZoneCall(const api::ZoneId& data,
205 api::MethodResultBuilder::Pointer result);
206 void handleShutdownZoneCall(const api::ZoneId& data,
207 api::MethodResultBuilder::Pointer result);
208 void handleStartZoneCall(const api::ZoneId& data,
209 api::MethodResultBuilder::Pointer result);
210 void handleLockZoneCall(const api::ZoneId& data,
211 api::MethodResultBuilder::Pointer result);
212 void handleUnlockZoneCall(const api::ZoneId& data,
213 api::MethodResultBuilder::Pointer result);
214 void handleGrantDeviceCall(const api::GrantDeviceIn& data,
215 api::MethodResultBuilder::Pointer result);
216 void handleRevokeDeviceCall(const api::RevokeDeviceIn& data,
217 api::MethodResultBuilder::Pointer result);
224 #endif // SERVER_ZONES_MANAGER_HPP