lxcpp: provisioning implementation (part 1)
[platform/core/security/vasum.git] / libs / lxcpp / provision-config.cpp
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 #include <vector>
25 #include <string>
26 #include "lxcpp/container-config.hpp"
27
28 using namespace lxcpp;
29 using namespace provision;
30
31 void ProvisionConfig::addFile(const File& newFile)
32 {
33     auto it = std::find(files.begin(), files.end(), newFile);
34     if (it != files.end()) {
35         const std::string msg =
36             "Can't add file. Provision already exists: " + newFile.getId();
37         LOGE(msg);
38         throw ProvisionException(msg);
39     }
40     files.push_back(newFile);
41 }
42
43 const FileVector& ProvisionConfig::getFiles() const
44 {
45     return files;
46 }
47
48 void ProvisionConfig::removeFile(const File& item)
49 {
50     const auto it = std::find(files.begin(), files.end(), item);
51     if (it == files.end()) {
52         const std::string msg = "Can't find provision: " + item.getId();
53         LOGE(msg);
54         throw ProvisionException(msg);
55     }
56     files.erase(it);
57 }
58
59
60 void ProvisionConfig::addMount(const Mount& newMount)
61 {
62     auto it = std::find(mounts.begin(), mounts.end(), newMount);
63     if (it != mounts.end()) {
64         const std::string msg =
65             "Can't add mount. Provision already exists: " + newMount.getId();
66         LOGE(msg);
67         throw ProvisionException(msg);
68     }
69     mounts.push_back(newMount);
70 }
71
72 const MountVector& ProvisionConfig::getMounts() const
73 {
74     return mounts;
75 }
76
77 void ProvisionConfig::removeMount(const Mount& item)
78 {
79     const auto it = std::find(mounts.begin(), mounts.end(), item);
80     if (it == mounts.end()) {
81         const std::string msg = "Can't find provision: " + item.getId();
82         LOGE(msg);
83         throw ProvisionException(msg);
84     }
85     mounts.erase(it);
86 }
87
88
89 void ProvisionConfig::addLink(const Link& newLink)
90 {
91     auto it = std::find(links.begin(), links.end(), newLink);
92     if (it != links.end()) {
93         const std::string msg =
94             "Can't add link. Provision already exists: " + newLink.getId();
95         LOGE(msg);
96         throw ProvisionException(msg);
97     }
98     links.push_back(newLink);
99 }
100
101 const LinkVector& ProvisionConfig::getLinks() const
102 {
103     return links;
104 }
105
106 void ProvisionConfig::removeLink(const Link& item)
107 {
108     const auto it = std::find(links.begin(), links.end(), item);
109     if (it == links.end()) {
110         const std::string msg = "Can't find provision: " + item.getId();
111         LOGE(msg);
112         throw ProvisionException(msg);
113     }
114     links.erase(it);
115 }