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"
37 #include <unordered_map>
44 class ZonesManager final {
47 ZonesManager(const std::string& managerConfigPath);
53 * @param zoneConfig config of new zone
55 void createZone(const std::string& zoneConfigPath);
60 * @param zoneId id of the zone
62 void destroyZone(const std::string& zoneId);
65 * Focus this zone, put it to the foreground.
66 * Method blocks until the focus is switched.
68 * @param zoneId id of the zone
70 void focus(const std::string& zoneId);
73 * Start up all the configured zones
78 * Stop all managed zones
83 * @return Is the zone in a paused state?
85 bool isPaused(const std::string& zoneId);
88 * @return Is the zone running?
90 bool isRunning(const std::string& zoneId);
93 * @return id of the currently focused/foreground zone
95 std::string getRunningForegroundZoneId() const;
98 * @return id of next to currently focused/foreground zone. If currently focused zone
99 * is last in zone map, id of fisrt zone from map is returned.
101 std::string getNextToForegroundZoneId();
104 * Set whether ZonesManager should detach zones on exit
106 void setZonesDetachOnExit();
109 typedef std::recursive_mutex Mutex;
110 typedef std::unique_lock<Mutex> Lock;
112 utils::Worker::Pointer mWorker;
113 mutable Mutex mMutex; // used to protect mZones
114 ZonesManagerConfig mConfig; //TODO make it const
115 ZonesManagerDynamicConfig mDynamicConfig;
116 HostConnection mHostConnection;
117 // to hold InputMonitor pointer to monitor if zone switching sequence is recognized
118 std::unique_ptr<InputMonitor> mSwitchingSequenceMonitor;
119 std::unique_ptr<ProxyCallPolicy> mProxyCallPolicy;
120 typedef std::unordered_map<std::string, std::shared_ptr<Zone>> ZoneMap;
121 ZoneMap mZones; // map of zones, id is the key
124 void saveDynamicConfig();
125 void switchingSequenceMonitorNotify();
126 void generateNewConfig(const std::string& id,
127 const std::string& templatePath,
128 const std::string& resultPath);
130 void notifyActiveZoneHandler(const std::string& caller,
131 const std::string& appliaction,
132 const std::string& message);
133 void displayOffHandler(const std::string& caller);
134 void handleZoneMoveFileRequest(const std::string& srcZoneId,
135 const std::string& dstZoneId,
136 const std::string& path,
137 dbus::MethodResultBuilder::Pointer result);
138 void handleProxyCall(const std::string& caller,
139 const std::string& target,
140 const std::string& targetBusName,
141 const std::string& targetObjectPath,
142 const std::string& targetInterface,
143 const std::string& targetMethod,
144 GVariant* parameters,
145 dbus::MethodResultBuilder::Pointer result);
146 void handleGetZoneDbuses(dbus::MethodResultBuilder::Pointer result) const;
147 void handleDbusStateChanged(const std::string& zoneId, const std::string& dbusAddress);
148 void handleGetZoneIdsCall(dbus::MethodResultBuilder::Pointer result) const;
149 void handleGetActiveZoneIdCall(dbus::MethodResultBuilder::Pointer result);
150 void handleGetZoneInfoCall(const std::string& id, dbus::MethodResultBuilder::Pointer result);
151 void handleDeclareFileCall(const std::string& zone,
153 const std::string& path,
154 const int32_t& flags,
156 dbus::MethodResultBuilder::Pointer result);
157 void handleDeclareMountCall(const std::string& source,
158 const std::string& zone,
159 const std::string& target,
160 const std::string& type,
161 const uint64_t& flags,
162 const std::string& data,
163 dbus::MethodResultBuilder::Pointer result);
164 void handleDeclareLinkCall(const std::string& source,
165 const std::string& zone,
166 const std::string& target,
167 dbus::MethodResultBuilder::Pointer result);
168 void handleSetActiveZoneCall(const std::string& id,
169 dbus::MethodResultBuilder::Pointer result);
170 void handleCreateZoneCall(const std::string& id,
171 dbus::MethodResultBuilder::Pointer result);
172 void handleDestroyZoneCall(const std::string& id,
173 dbus::MethodResultBuilder::Pointer result);
174 void handleShutdownZoneCall(const std::string& id,
175 dbus::MethodResultBuilder::Pointer result);
176 void handleStartZoneCall(const std::string& id,
177 dbus::MethodResultBuilder::Pointer result);
178 void handleLockZoneCall(const std::string& id,
179 dbus::MethodResultBuilder::Pointer result);
180 void handleUnlockZoneCall(const std::string& id,
181 dbus::MethodResultBuilder::Pointer result);
182 void handleGrantDeviceCall(const std::string& id,
183 const std::string& device,
185 dbus::MethodResultBuilder::Pointer result);
186 void handleRevokeDeviceCall(const std::string& id,
187 const std::string& device,
188 dbus::MethodResultBuilder::Pointer result);
195 #endif // SERVER_ZONES_MANAGER_HPP