e0dc2b0f3b3c229ae214992a1e4f770d90704a20
[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 provisioning manager to get owned devices' Device IDs.
118  *
119  * @param[out] uuidList information about the list of owned devices' uuids.
120  * @param[out] numOfDevices total number of owned devices.
121  *
122  * @return OC_STACK_OK in case of success and other value otherwise.
123  */
124 OCStackResult PDMGetOwnedDevices(OCUuidList_t** uuidList, size_t* numOfDevices);
125
126 /**
127  * This method is used by provisioning manager to get linked devices' IDs.
128  *
129  * @param[in] uuidOfDevice a target device's uuid.
130  * @param[out] uuidList information about the list of linked devices' uuids.
131  * @param[out] numOfDevices total number of linked devices.
132  *
133  * @return OC_STACK_OK in case of success and other value otherwise.
134  */
135 OCStackResult PDMGetLinkedDevices(const OicUuid_t* uuidOfDevice, OCUuidList_t** uuidList,
136                                     size_t* numOfDevices);
137
138 /**
139  * This method is used by provisioning manager to update linked status as stale.
140  *
141  * @param[in] uuidOfDevice1 first id of stale link.
142  * @param[in] uuidOfDevice2 other id for stale link.
143  *
144  * @return OC_STACK_OK in case of success and other value otherwise.
145  */
146 OCStackResult PDMSetLinkStale(const OicUuid_t* uuidOfDevice1, const OicUuid_t* uuidOfDevice2);
147
148 /**
149  * This method is used by provisioning manager to get stale devices.
150  *
151  * @note in case of sqllite, the caller should set NULL for parameters.
152  *
153  * @param[out] staleDevices information about the list of "To be Removed" devices' uuid.
154  * @param[out] numOfDevices total number of devices to be removed.
155  *
156  * @return OC_STACK_OK in case of success and other value otherwise.
157  */
158 OCStackResult PDMGetToBeUnlinkedDevices(OCPairList_t** staleDevList, size_t* numOfDevices);
159
160 /**
161  * This method is used by provisioning manager to close provisioning database.
162  *
163  * @return  OC_STACK_OK in case of success and other value otherwise.
164  */
165 OCStackResult PDMClose();
166
167 /**
168  * This method is used by provisioning manager free memory allocated to OCUuidList_t lists.
169  *
170  * @param[in] ptr start pointer of link list.
171  */
172 void PDMDestoryOicUuidLinkList(OCUuidList_t* ptr);
173
174 /**
175  * This method is used by provisioning manager free memory allocated to Stalelist.
176  *
177  * @param[in] ptr start pointer of link list.
178  *
179  */
180 void PDMDestoryStaleLinkList(OCPairList_t* ptr);
181
182 /**
183  * This method is used by provisioning manager to check does the link exists between
184  * two devices or not.
185  *
186  * @param[in] uuidOfDevice1 UUID of device1.
187  * @param[in] uuidOfDevice2 UUID of device2.
188  * @param[out] result true when link exists otherwise false.
189  *
190  * @return OC_STACK_OK in case of success and other value otherwise.
191  */
192 OCStackResult PDMIsLinkExists(const OicUuid_t* uuidOfDevice1, const OicUuid_t* uuidOfDevice2,
193                                 bool *result);
194
195
196 #ifdef __cplusplus
197 }
198 #endif
199 #endif //PROVISIONING_DATABASE_MANAGER_H