lxcpp: provisioning implementation (part 2)
[platform/core/security/vasum.git] / server / zone-provision.hpp
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Mateusz Malicki <m.malicki2@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  Mateusz Malicki (m.malicki2@samsung.com)
22  * @brief   Declaration of the class for managing zone provision
23  */
24
25
26 #ifndef SERVER_ZONE_PROVISION_HPP
27 #define SERVER_ZONE_PROVISION_HPP
28
29 #include "zone-provision-config.hpp"
30
31 #include <string>
32 #include <vector>
33 #include <list>
34
35 namespace vasum {
36
37
38 /**
39  * Class is responsible for prepare filesystem for zone
40  * It allows to create directories, files, mount points and copying files from host
41  */
42 class ZoneProvision {
43
44 public:
45     /**
46      * ZoneProvision constructor
47      * @param rootPath zone root path
48      * @param configPath path to config with defaults
49      * @param dbPath path to database
50      * @param dbPrefix database prefix
51      * @param validLinkPrefixes valid link prefixes
52      */
53     ZoneProvision(const std::string& rootPath,
54                   const std::string& configPath,
55                   const std::string& dbPath,
56                   const std::string& dbPrefix,
57                   const std::vector<std::string>& validLinkPrefixes);
58     ~ZoneProvision();
59
60     ZoneProvision(const ZoneProvision&) = delete;
61     ZoneProvision& operator=(const ZoneProvision&) = delete;
62     ZoneProvision(ZoneProvision&&) = default;
63
64     /**
65      * Declare file, directory or pipe that will be created while zone startup
66      */
67     std::string declareFile(const int32_t& type,
68                             const std::string& path,
69                             const int32_t& flags,
70                             const int32_t& mode);
71     /**
72      * Declare mount that will be created while zone startup
73      */
74     std::string declareMount(const std::string& source,
75                              const std::string& target,
76                              const std::string& type,
77                              const int64_t& flags,
78                              const std::string& data);
79     /**
80      * Declare link that will be created while zone startup
81      */
82     std::string declareLink(const std::string& source,
83                             const std::string& target);
84
85     void start() noexcept;
86     void stop() noexcept;
87
88     /**
89      * List all provisioned resources
90      */
91     std::vector<std::string> list() const;
92
93     /**
94      * Remove resource
95      *
96      * @param item resource to be removed (as in list())
97      */
98     void remove(const std::string& item);
99
100 private:
101     ZoneProvisioningConfig mProvisioningConfig;
102     std::string mRootPath;
103     std::string mDbPath;
104     std::string mDbPrefix;
105     std::vector<std::string> mValidLinkPrefixes;
106     std::list<ZoneProvisioningConfig::Provision> mProvisioned;
107
108     void saveProvisioningConfig();
109     std::string declareProvision(ZoneProvisioningConfig::Provision&& provision);
110
111     void mount(const ZoneProvisioningConfig::Mount& config);
112     void umount(const ZoneProvisioningConfig::Mount& config);
113     void file(const ZoneProvisioningConfig::File& config);
114     void link(const ZoneProvisioningConfig::Link& config);
115
116     static std::string getId(const ZoneProvisioningConfig::File& file);
117     static std::string getId(const ZoneProvisioningConfig::Mount& mount);
118     static std::string getId(const ZoneProvisioningConfig::Link& link);
119     static std::string getId(const ZoneProvisioningConfig::Provision& provision);
120 };
121
122 } // namespace vasum
123
124 #endif // SERVER_ZONE_PROVISION_HPP