replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / include / internal / provisioningdatabasemanager.h
1 /* *****************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * *****************************************************************/
20
21 #ifndef PROVISIONING_DATABASE_MANAGER_H
22 #define PROVISIONING_DATABASE_MANAGER_H
23 #include "securevirtualresourcetypes.h"
24 #include "ocstack.h"
25 #include "pmtypes.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 typedef enum PdmDeviceState {
32     PDM_DEVICE_ACTIVE = 0,
33     PDM_DEVICE_STALE = 1,
34     PDM_DEVICE_INIT = 2,
35     PDM_DEVICE_UNKNOWN = 99
36 }PdmDeviceState_t;
37
38 /**
39  * This method is used by provisioning manager to open provisioning database.
40  *
41  * @param[in] dbPath file path of the sqlite3 db
42  *
43  * @return OC_STACK_OK in case of success and other value otherwise.
44  */
45 OCStackResult PDMInit(const char* dbPath);
46
47 /**
48  * This method is used by provisioning manager to check device status.
49  *
50  * @param[in] uuid information about the target device's uuid.
51  * @param[out] result device status.
52  *
53  * @return OC_STACK_OK in case of success and other value otherwise.
54  */
55 OCStackResult PDMGetDeviceState(const OicUuid_t* uuid, PdmDeviceState_t* result);
56
57 /**
58  * This method is used by provisioning manager to update device status.
59  *
60  * @param[in] uuid id of device.
61  * @param[in] state device state. (ref. PdmDeviceState_t)
62  *
63  * @return OC_STACK_OK in case of success and other value otherwise.
64  */
65 OCStackResult PDMSetDeviceState(const OicUuid_t* uuid, PdmDeviceState_t state);
66
67 /**
68  * This method is used by provisioning manager to check duplication of device's Device ID with
69  * provisioning database.
70  *
71  * @param[in] uuidOfDevice information about the target device's uuid.
72  * @param[out] result true in case device UUID already exist otherwise false.
73  *
74  * @return OC_STACK_OK in case of success and other value otherwise.
75  */
76 OCStackResult PDMIsDuplicateDevice(const OicUuid_t* uuidOfDevice, bool* result);
77
78 /**
79  * This method is used by provisioning manager to add owned device's Device ID.
80  *
81  * @param[in] uuidOfDevice information about the owned device's uuid.
82  *
83  * @return OC_STACK_OK in case of success and other value otherwise.
84  */
85 OCStackResult PDMAddDevice(const OicUuid_t* uuidOfDevice);
86
87 /**
88  * This method is used by provisioning manager to update linked status of owned devices.
89  *
90  * @param[in] uuidOfDevice1 DeviceID which is going to be linked with uuid of device 2.
91  * @param[in] uuidOfDevice2 DeviceID which is going to be linked with uuid of device 1.
92  *
93  * @return OC_STACK_OK in case of success and other value otherwise.
94  */
95 OCStackResult PDMLinkDevices(const OicUuid_t *uuidOfDevice1, const OicUuid_t *uuidOfDevice2);
96
97 /**
98  * This method is used by provisioning manager to unlink pairwise devices.
99  *
100  * @param[in] uuidOfDevice1 DeviceID which is going to be unlinked with uuid of device 2.
101  * @param[in] uuidOfDevice2 DeviceID which is going to be unlinked with uuid of device 1.
102  *
103  * @return OC_STACK_OK in case of success and other value otherwise.
104  */
105 OCStackResult PDMUnlinkDevices(const OicUuid_t *uuidOfDevice1, const OicUuid_t *uuidOfDevice2);
106
107 /**
108  * This method is used by provisioning manager to delete owned device's Device ID.
109  *
110  * @param[in] uuidOfDevice information about the owned device's uuid to be deleted.
111  *
112  * @return OC_STACK_OK in case of success and other value otherwise.
113  */
114 OCStackResult PDMDeleteDevice(const OicUuid_t *uuidOfDevice);
115
116 /**
117  * This method is used by OTM & PDM to remove device information with device state.
118  *
119  * @param[in] state device state to be removed.
120  *
121  * @return OC_STACK_OK in case of success and other value otherwise.
122  */
123 OCStackResult PDMDeleteDeviceWithState(const PdmDeviceState_t state);
124
125 /**
126  * This method is used by provisioning manager to get owned devices' Device IDs.
127  *
128  * @param[out] uuidList information about the list of owned devices' uuids.
129  * @param[out] numOfDevices total number of owned devices.
130  *
131  * @return OC_STACK_OK in case of success and other value otherwise.
132  */
133 OCStackResult PDMGetOwnedDevices(OCUuidList_t** uuidList, size_t* numOfDevices);
134
135 /**
136  * This method is used by provisioning manager to get linked devices' IDs.
137  *
138  * @param[in] uuidOfDevice a target device's uuid.
139  * @param[out] uuidList information about the list of linked devices' uuids.
140  * @param[out] numOfDevices total number of linked devices.
141  *
142  * @return OC_STACK_OK in case of success and other value otherwise.
143  */
144 OCStackResult PDMGetLinkedDevices(const OicUuid_t* uuidOfDevice, OCUuidList_t** uuidList,
145                                     size_t* numOfDevices);
146
147 /**
148  * This method is used by provisioning manager to update linked status as stale.
149  *
150  * @param[in] uuidOfDevice1 first id of stale link.
151  * @param[in] uuidOfDevice2 other id for stale link.
152  *
153  * @return OC_STACK_OK in case of success and other value otherwise.
154  */
155 OCStackResult PDMSetLinkStale(const OicUuid_t* uuidOfDevice1, const OicUuid_t* uuidOfDevice2);
156
157 /**
158  * This method is used by provisioning manager to get stale devices.
159  *
160  * @note in case of sqllite, the caller should set NULL for parameters.
161  *
162  * @param[out] staleDevices information about the list of "To be Removed" devices' uuid.
163  * @param[out] numOfDevices total number of devices to be removed.
164  *
165  * @return OC_STACK_OK in case of success and other value otherwise.
166  */
167 OCStackResult PDMGetToBeUnlinkedDevices(OCPairList_t** staleDevList, size_t* numOfDevices);
168
169 /**
170  * This method is used by provisioning manager to close provisioning database.
171  *
172  * @return  OC_STACK_OK in case of success and other value otherwise.
173  */
174 OCStackResult PDMClose();
175
176 /**
177  * This method is used by provisioning manager free memory allocated to OCUuidList_t lists.
178  *
179  * @param[in] ptr start pointer of link list.
180  */
181 void PDMDestoryOicUuidLinkList(OCUuidList_t* ptr);
182
183 /**
184  * This method is used by provisioning manager free memory allocated to Stalelist.
185  *
186  * @param[in] ptr start pointer of link list.
187  *
188  */
189 void PDMDestoryStaleLinkList(OCPairList_t* ptr);
190
191 /**
192  * This method is used by provisioning manager to check does the link exists between
193  * two devices or not.
194  *
195  * @param[in] uuidOfDevice1 UUID of device1.
196  * @param[in] uuidOfDevice2 UUID of device2.
197  * @param[out] result true when link exists otherwise false.
198  *
199  * @return OC_STACK_OK in case of success and other value otherwise.
200  */
201 OCStackResult PDMIsLinkExists(const OicUuid_t* uuidOfDevice1, const OicUuid_t* uuidOfDevice2,
202                                 bool *result);
203
204
205 #ifdef __cplusplus
206 }
207 #endif
208 #endif //PROVISIONING_DATABASE_MANAGER_H