Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
zones-manager.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Jan Olszak <j.olszak@samsung.com>
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
17  */
18 
26 #ifndef SERVER_ZONES_MANAGER_HPP
27 #define SERVER_ZONES_MANAGER_HPP
28 
29 #include "zone.hpp"
30 #include "zones-manager-config.hpp"
31 #include "api/messages.hpp"
32 #include "input-monitor.hpp"
33 #include "utils/worker.hpp"
35 
36 #include "host-ipc-connection.hpp"
38 #ifdef DBUS_CONNECTION
39 #include "host-dbus-connection.hpp"
40 #include "proxy-call-policy.hpp"
41 #endif //DBUS_CONNECTION
42 
43 #include <string>
44 #include <memory>
45 
46 
47 namespace vasum {
48 
49 const std::string INVALID_CONNECTION_ID = "invalid://";
50 
51 class ZonesManager final {
52 
53 public:
54  ZonesManager(cargo::ipc::epoll::EventPoll& eventPoll, const std::string& managerConfigPath);
55  ~ZonesManager();
56 
62  void stop(bool wait);
63 
67  void start();
68 
73  bool isRunning();
74 
81  void createZone(const std::string& zoneId, const std::string& templateName);
82 
88  void destroyZone(const std::string& zoneId);
89 
96  void focus(const std::string& zoneId);
97 
101  void restoreAll();
102 
106  void shutdownAll();
107 
111  bool isPaused(const std::string& zoneId);
112 
116  bool isRunning(const std::string& zoneId);
117 
121  bool isStopped(const std::string& zoneId);
122 
126  std::string getRunningForegroundZoneId();
127 
132  std::string getNextToForegroundZoneId();
133 
137  void setZonesDetachOnExit();
138 
142  void disconnectedCallback(const std::string& id);
143 
144  // Handlers --------------------------------------------------------
155  void handleGetNetdevListCall(const api::ZoneId& data,
167  void handleDeclareFileCall(const api::DeclareFileIn& data,
171  void handleDeclareLinkCall(const api::DeclareLinkIn& data,
173  void handleGetDeclarationsCall(const api::ZoneId& data,
177  void handleSetActiveZoneCall(const api::ZoneId& data,
179  void handleCreateZoneCall(const api::CreateZoneIn& data,
181  void handleDestroyZoneCall(const api::ZoneId& data,
183  void handleShutdownZoneCall(const api::ZoneId& data,
185  void handleStartZoneCall(const api::ZoneId& data,
187  void handleLockZoneCall(const api::ZoneId& data,
189  void handleUnlockZoneCall(const api::ZoneId& data,
191  void handleGrantDeviceCall(const api::GrantDeviceIn& data,
195  void handleCreateFileCall(const api::CreateFileIn& request,
197  void handleSwitchToDefaultCall(const std::string& caller,
200 
202 
203 private:
204  typedef std::recursive_mutex Mutex;
205  typedef std::unique_lock<Mutex> Lock;
206 
209  Mutex mMutex; // used to protect mZones
210  ZonesManagerConfig mConfig; //TODO make it const
212  // to hold InputMonitor pointer to monitor if zone switching sequence is recognized
213  std::unique_ptr<InputMonitor> mSwitchingSequenceMonitor;
214  // like set but keep insertion order
215  // smart pointer is needed because Zone is not moveable (because of mutex)
216  typedef std::vector<std::unique_ptr<Zone>> Zones;
218  std::string mActiveZoneId;
220  std::string mExclusiveIDLock;
221  Mutex mExclusiveIDMutex; // used to protect mExclusiveIDLock
222 
223  Zones::iterator findZone(const std::string& id);
224  Zone& getZone(const std::string& id);
225  Zones::iterator getRunningForegroundZoneIterator();
226  Zones::iterator getNextToForegroundZoneIterator();
227  void focusInternal(Zones::iterator iter);
228 
229  void saveDynamicConfig();
230  void updateDefaultId();
231  void refocus();
232  void generateNewConfig(const std::string& id,
233  const std::string& templatePath);
234  std::string getTemplatePathForExistingZone(const std::string& id);
235  int getVTForNewZone();
236  void insertZone(const std::string& zoneId, const std::string& templatePath);
237  void tryAddTask(const utils::Worker::Task& task, api::MethodResultBuilder::Pointer result, bool wait);
238 
240 #ifdef DBUS_CONNECTION
241  HostDbusConnection mHostDbusConnection;
242  std::unique_ptr<ProxyCallPolicy> mProxyCallPolicy;
243  void handleProxyCall(const std::string& caller,
244  const std::string& target,
245  const std::string& targetBusName,
246  const std::string& targetObjectPath,
247  const std::string& targetInterface,
248  const std::string& targetMethod,
249  GVariant* parameters,
251 #endif //DBUS_CONNECTION
252 };
253 
254 
255 } // namespace vasum
256 
257 
258 #endif // SERVER_ZONES_MANAGER_HPP
void handleGetNetdevListCall(const api::ZoneId &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:871
void setZonesDetachOnExit()
Set whether ZonesManager should detach zones on exit.
Definition: zones-manager.cpp:569
Definition: zone.hpp:49
void saveDynamicConfig()
Definition: zones-manager.cpp:281
C++ epoll wrapper.
Declaration of a class for communication with server.
void handleDeleteNetdevIpAddressCall(const api::DeleteNetdevIpAddressIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:985
bool mDetachOnExit
Definition: zones-manager.hpp:219
void handleSetNetdevAttrsCall(const api::SetNetDevAttrsIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:815
Mutex mExclusiveIDMutex
Definition: zones-manager.hpp:221
HostIPCConnection mHostIPCConnection
Definition: zones-manager.hpp:239
void handleCreateNetdevMacvlanCall(const api::CreateNetDevMacvlanIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:917
void insertZone(const std::string &zoneId, const std::string &templatePath)
Definition: zones-manager.cpp:316
std::unique_ptr< InputMonitor > mSwitchingSequenceMonitor
Definition: zones-manager.hpp:213
void handleLockQueueCall(api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:700
void createZone(const std::string &zoneId, const std::string &templateName)
Create new zone.
Definition: zones-manager.cpp:1211
void focus(const std::string &zoneId)
Focus this zone, put it to the foreground.
Definition: zones-manager.cpp:391
void handleDeclareMountCall(const api::DeclareMountIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1030
Declaration of the class for storing zone manager configuration.
void handleRevokeDeviceCall(const api::RevokeDeviceIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1512
std::string getTemplatePathForExistingZone(const std::string &id)
Definition: zones-manager.cpp:309
Definition: messages.hpp:179
void handleGetDeclarationsCall(const api::ZoneId &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1076
bool mIsRunning
Definition: zones-manager.hpp:207
void handleGetZoneInfoCall(const api::ZoneId &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:775
ZonesManagerConfig mConfig
Definition: zones-manager.hpp:210
Zone & getZone(const std::string &id)
Definition: zones-manager.cpp:272
Definition: messages.hpp:40
void shutdownAll()
Shutdown all managed zones without changing the saved state.
Definition: zones-manager.cpp:483
bool isPaused(const std::string &zoneId)
Definition: zones-manager.cpp:496
void switchingSequenceMonitorNotify()
Definition: zones-manager.cpp:555
void handleGetActiveZoneIdCall(api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:761
void handleUnlockQueueCall(api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:721
void start()
Starts the manager.
Definition: zones-manager.cpp:198
Zones mZones
Definition: zones-manager.hpp:217
Definition: zones-manager.hpp:51
~ZonesManager()
Definition: zones-manager.cpp:192
std::vector< std::unique_ptr< Zone > > Zones
Definition: zones-manager.hpp:216
std::string getNextToForegroundZoneId()
Definition: zones-manager.cpp:521
void handleGetZoneIdsCall(api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:742
void handleDestroyNetdevCall(const api::DestroyNetDevIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:962
void handleLockZoneCall(const api::ZoneId &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1393
void refocus()
Definition: zones-manager.cpp:447
char data[368]
Definition: initctl.cpp:41
void handleSwitchToDefaultCall(const std::string &caller, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:593
void handleGrantDeviceCall(const api::GrantDeviceIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1469
int getVTForNewZone()
Definition: zones-manager.cpp:1192
std::function< void()> Task
Definition: worker.hpp:40
std::unique_lock< Mutex > Lock
Definition: zones-manager.hpp:205
void stop(bool wait)
Request stopping the manager.
Definition: zones-manager.cpp:232
void handleCleanUpZonesRootCall(api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1553
Definition: messages.hpp:149
void restoreAll()
Restore all the configured zones to the saved state.
Definition: zones-manager.cpp:466
const std::string INVALID_CONNECTION_ID
Definition: zones-manager.hpp:49
Definition: messages.hpp:224
Declaration of the class for managing one zone.
void handleCreateFileCall(const api::CreateFileIn &request, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:617
std::recursive_mutex Mutex
Definition: zones-manager.hpp:204
Definition: messages.hpp:108
void handleDeclareFileCall(const api::DeclareFileIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1007
Definition: messages.hpp:49
void handleUnlockZoneCall(const api::ZoneId &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1432
void handleSetActiveZoneCall(const api::ZoneId &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1121
void handleDeclareLinkCall(const api::DeclareLinkIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1053
Declaration of a class for checking permissions of proxy calls.
Definition: zones-manager-config.hpp:107
std::string mExclusiveIDLock
Definition: zones-manager.hpp:220
A worker thread that executes tasks.
Definition: messages.hpp:121
Definition: messages.hpp:211
bool isRunning()
If ZoneManager is running it needs the external polling loop to operate.
Definition: zones-manager.cpp:259
Definition: messages.hpp:198
void handleStartZoneCall(const api::ZoneId &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1366
void focusInternal(Zones::iterator iter)
Definition: zones-manager.cpp:398
void handleGetNetdevAttrsCall(const api::GetNetDevAttrsIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:844
void updateDefaultId()
Definition: zones-manager.cpp:286
Definition: host-dbus-connection.hpp:44
void handleDestroyZoneCall(const api::ZoneId &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1316
void handleShutdownZoneCall(const api::ZoneId &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1337
ZonesManager(cargo::ipc::epoll::EventPoll &eventPoll, const std::string &managerConfigPath)
Definition: zones-manager.cpp:168
std::shared_ptr< MethodResultBuilder > Pointer
Definition: connection.hpp:47
Zones::iterator getNextToForegroundZoneIterator()
Definition: zones-manager.cpp:542
bool isStopped(const std::string &zoneId)
Definition: zones-manager.cpp:508
HostIPCConnection class.
This class waits on registered file descriptor for events.
Definition: event-poll.hpp:47
Mutex mMutex
Definition: zones-manager.hpp:209
utils::Worker::Pointer mWorker
Definition: zones-manager.hpp:208
void handleRemoveDeclarationCall(const api::RemoveDeclarationIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1099
void tryAddTask(const utils::Worker::Task &task, api::MethodResultBuilder::Pointer result, bool wait)
Definition: zones-manager.cpp:344
void handleCreateNetdevVethCall(const api::CreateNetDevVethIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:894
std::string getRunningForegroundZoneId()
Definition: zones-manager.cpp:514
void handleCreateNetdevPhysCall(const api::CreateNetDevPhysIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:939
Zones::iterator findZone(const std::string &id)
Definition: zones-manager.cpp:265
ZonesManagerDynamicConfig mDynamicConfig
Definition: zones-manager.hpp:211
std::shared_ptr< Worker > Pointer
Definition: worker.hpp:39
void generateNewConfig(const std::string &id, const std::string &templatePath)
Definition: zones-manager.cpp:1151
C++ wrapper for glib input monitor.
std::shared_ptr< MethodResultBuilder > Pointer
Definition: method-result-builder.hpp:41
void disconnectedCallback(const std::string &id)
Callback on a client (ipc/dbus) disconnect.
Definition: zones-manager.cpp:580
void handleCreateZoneCall(const api::CreateZoneIn &data, api::MethodResultBuilder::Pointer result)
Definition: zones-manager.cpp:1299
void destroyZone(const std::string &zoneId)
Destroy zone.
Definition: zones-manager.cpp:363
Definition: zones-manager-config.hpp:39
Definition: messages.hpp:162
Zones::iterator getRunningForegroundZoneIterator()
Definition: zones-manager.cpp:528
std::string mActiveZoneId
Definition: zones-manager.hpp:218
Definition: host-ipc-connection.hpp:38
Interface for result builders.
Definition: messages.hpp:134
Host's internal IPC messages declaration.