Using libConfig structures for input in server
[platform/core/security/vasum.git] / server / zones-manager.hpp
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
19 /**
20  * @file
21  * @author  Jan Olszak (j.olszak@samsung.com)
22  * @brief   Declaration of the class for managing many zones
23  */
24
25
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 "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"
36
37 #include <string>
38 #include <memory>
39
40
41 namespace vasum {
42
43
44 class ZonesManager final {
45
46 public:
47     ZonesManager(const std::string& managerConfigPath);
48     ~ZonesManager();
49
50     /**
51      * Create new zone.
52      *
53      * @param zoneId id of new zone
54      * @param templateName a template name
55      */
56     void createZone(const std::string& zoneId, const std::string& templateName);
57
58     /**
59      * Destroy zone.
60      *
61      * @param zoneId id of the zone
62      */
63     void destroyZone(const std::string& zoneId);
64
65     /**
66      * Focus this zone, put it to the foreground.
67      * Method blocks until the focus is switched.
68      *
69      * @param zoneId id of the zone
70      */
71     void focus(const std::string& zoneId);
72
73     /**
74      * Restore all the configured zones to the saved state
75      */
76     void restoreAll();
77
78     /**
79      * Shutdown all managed zones without changing the saved state
80      */
81     void shutdownAll();
82
83     /**
84      * @return Is the zone in a paused state?
85      */
86     bool isPaused(const std::string& zoneId);
87
88     /**
89      * @return Is the zone running?
90      */
91     bool isRunning(const std::string& zoneId);
92
93     /**
94      * @return Is the zone stopped?
95      */
96     bool isStopped(const std::string& zoneId);
97
98     /**
99      * @return id of the currently focused/foreground zone
100      */
101     std::string getRunningForegroundZoneId();
102
103     /**
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.
106      */
107     std::string getNextToForegroundZoneId();
108
109     /**
110      * Set whether ZonesManager should detach zones on exit
111      */
112     void setZonesDetachOnExit();
113
114 private:
115     typedef std::recursive_mutex Mutex;
116     typedef std::unique_lock<Mutex> Lock;
117
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;
129     Zones mZones;
130     std::string mActiveZoneId;
131     bool mDetachOnExit;
132
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);
138
139     void saveDynamicConfig();
140     void updateDefaultId();
141     void refocus();
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);
148
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);
168
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);
218 };
219
220
221 } // namespace vasum
222
223
224 #endif // SERVER_ZONES_MANAGER_HPP