Add debug compilation mode
[platform/core/security/nice-lad.git] / src / SecurityManager / DataProvider.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file        src/SecurityManager/DataProvider.cpp
18  * @author      Aleksander Zdyb <a.zdyb@samsung.com>
19  * @version     1.0
20  */
21
22 #include <functional>
23 #include <memory>
24
25 #include <Log/log.h>
26
27 #include <SecurityManager/ErrorException.h>
28
29 #include "DataProvider.h"
30
31 namespace SecurityManager {
32
33 DataProvider::DataProvider(BaseSecurityManagerWrapper &smApi) : m_smApi(smApi) {}
34
35 Lad::DataProvider::GroupsList DataProvider::getResourceGroups(void) {
36     Lad::DataProvider::GroupsList retGroups;
37
38     char **groups = nullptr;
39     size_t groupsLen = 0;
40
41     auto getRet = m_smApi.security_manager_groups_get(&groups, &groupsLen);
42
43     if (getRet != m_smApi.SECURITY_MANAGER_SUCCESS_CONST()) {
44         throw ErrorException("Could not get groups from Security Manager");
45     }
46
47     auto groupsDeleter = std::bind(&BaseSecurityManagerWrapper::security_manager_groups_free,
48                                    &m_smApi, std::placeholders::_1, groupsLen);
49     std::unique_ptr<char *, std::function<void(char **)>> groupsPtr(groups, groupsDeleter);
50
51     for (size_t i = 0; i < groupsLen; ++i) {
52         retGroups.push_back(groups[i]);
53     }
54
55     return retGroups;
56 }
57
58 } /* namespace SecurityManager */