lxcpp: provisioning implementation (part 1)
[platform/core/security/vasum.git] / libs / lxcpp / provision-config.hpp
1 /*
2  *  Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License version 2.1 as published by the Free Software Foundation.
7  *
8  *  This library is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  *  Lesser General Public License for more details.
12  *
13  *  You should have received a copy of the GNU Lesser General Public
14  *  License along with this library; if not, write to the Free Software
15  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16  */
17
18 /**
19  * @file
20  * @author  Maciej Karpiuk (m.karpiuk2@samsung.com)
21  * @brief   Provisioning configuration
22  */
23
24 #ifndef LXCPP_PROVISION_CONFIG_HPP
25 #define LXCPP_PROVISION_CONFIG_HPP
26
27 #include "config/config.hpp"
28 #include "config/fields.hpp"
29 #include "config/fields-union.hpp"
30
31 #include <vector>
32 #include <string>
33 #include <string.h>
34
35 namespace lxcpp {
36 namespace provision {
37
38 typedef std::string ProvisionID;
39
40 /**
41  * Provision configuration items
42  */
43 struct File
44 {
45     enum class Type : int
46     {
47         DIRECTORY,
48         FIFO,
49         REGULAR
50     };
51
52     ProvisionID getId() const
53     {
54         return "file " +
55                path + " " +
56                std::to_string(static_cast<int>(type)) + " " +
57                std::to_string(flags) + " " +
58                std::to_string(mode);
59     }
60
61     Type type;
62     std::string path;
63     std::int32_t flags;
64     std::int32_t mode;
65
66     CONFIG_REGISTER
67     (
68         type,
69         path,
70         flags,
71         mode
72     )
73
74     bool operator==(const File& m) const
75     {
76         return ((m.type == type) && (m.path == path) &&
77                 (m.flags == flags) && (m.mode == mode));
78     }
79 };
80
81 struct Mount
82 {
83     ProvisionID getId() const
84     {
85         return "mount " +
86                source + " " +
87                target + " " +
88                type + " " +
89                std::to_string(flags) + " " +
90                data;
91     }
92
93     std::string source;
94     std::string target;
95     std::string type;
96     std::int64_t flags;
97     std::string data;
98
99     CONFIG_REGISTER
100     (
101         source,
102         target,
103         type,
104         flags,
105         data
106     )
107
108     bool operator==(const Mount& m) const
109     {
110         return ((m.source == source) && (m.target == target) && (m.type == type) &&
111                 (m.flags == flags) && (m.data == data));
112     }
113 };
114
115 struct Link
116 {
117     ProvisionID getId() const
118     {
119         return "link " + source + " " + target;
120     }
121
122     std::string source;
123     std::string target;
124
125     CONFIG_REGISTER
126     (
127         source,
128         target
129     )
130
131     bool operator==(const Link& m) const
132     {
133         return ((m.source == source) && (m.target == target));
134     }
135 };
136 } // namespace provision
137
138 typedef std::vector<provision::File>   FileVector;
139 typedef std::vector<provision::Mount>  MountVector;
140 typedef std::vector<provision::Link>   LinkVector;
141
142 struct ProvisionConfig
143 {
144     FileVector files;
145     MountVector mounts;
146     LinkVector links;
147
148     void addFile(const provision::File& newFile);
149     const FileVector& getFiles() const;
150     void removeFile(const provision::File& item);
151
152     void addMount(const provision::Mount& newMount);
153     const MountVector& getMounts() const;
154     void removeMount(const provision::Mount& item);
155
156     void addLink(const provision::Link& newLink);
157     const LinkVector& getLinks() const;
158     void removeLink(const provision::Link& item);
159
160     CONFIG_REGISTER
161     (
162         files,
163         mounts,
164         links
165     )
166 };
167
168 } // namespace lxcpp
169
170 #endif // LXCPP_PROVISION_CONFIG_HPP