Add: PUT/DELETE method for Resource Hosting.
[platform/upstream/iotivity.git] / service / notification-manager / NotificationManager / src / virtualResource.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 _VIRTUAL_RESOURCE_H_
22 #define _VIRTUAL_RESOURCE_H_
23
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27
28 #include "ocstack.h"
29 #include "ocsocket.h"
30 #include "logger.h"
31
32 #include "cJSON.h"
33 #define TAG  PCF("MirrorResource")
34 //-----------------------------------------------------------------------------
35 // Definition of Constant
36 //-----------------------------------------------------------------------------
37 #define VR_TAG "__NM__"
38 #define RH_TAG "__RM__"
39
40 //-----------------------------------------------------------------------------
41 // Typedefs
42 //-----------------------------------------------------------------------------
43
44 /**
45 * Resource Coordinating Parameter Type
46 */
47 typedef enum
48 {
49     /*
50      * for mirrorResourceHandle
51      */
52     OIC_SOURCE_ADDRESS  = 0,
53     OIC_MIRROR_ADDRESS  = 1,
54     OIC_REQUEST_HANDLE  = 0,
55     OIC_MIRROR_HANDLE       = 1,
56
57     /*
58      * for requestHandle
59      */
60     OIC_REQUEST_BY_CLIENT       = 0,
61     OIC_REQUEST_BY_COORDINATOR  = 1,
62
63     OIC_NONE                        = 255
64 } OICResourceCoordinatorParamType;
65
66 /**
67 * Property of Mirror Resource
68 */
69 typedef struct MirrorResourceProperty
70 {
71     int countResourceType;
72     int countInterface;
73     char **resourceType;
74     char **resourceInterfaceName;
75 } MirrorResourceProperty;
76
77 /**
78 * Mirror Resource Object
79 */
80 typedef struct MirrorResource
81 {
82     OCDoHandle resourceHandle[2];   // OIC_REQUEST_HANDLE = 0, OIC_VIRTUAL_HANDLE = 1
83     char *address[2];               // OIC_SOURCE_ADDRESS = 0, OIC_VIRTUAL_ADDRESS = 1
84     cJSON *rep;
85     char *uri;
86     MirrorResourceProperty prop;
87
88     struct MirrorResource *next;
89
90     /*
91      * for multiple resource
92      */
93 //  virtualRepresentation rep2;
94
95 } MirrorResource;
96
97 /**
98 * Mirror Resource List
99 */
100 typedef struct MirrorResourceList
101 {
102     struct MirrorResource *headerNode;
103     struct MirrorResource *tailNode;
104 } MirrorResourceList;
105
106 /**
107 * Request Object
108 */
109 typedef struct RequestHandle
110 {
111     void *requestHandle[2];         // OIC_REQUEST_BY_CLIENT = 0, OIC_REQUEST_BY_COORDINATOR = 1
112     OCResourceHandle resourceHandle;
113     OCRequestHandle entityRequestHandle;
114
115     OCMethod method;
116
117     unsigned char isAliveCheck;
118
119     struct RequestHandle *next;
120 } RequestHandle;
121
122 /**
123 * Request Object List
124 */
125 typedef struct RequestHandleList
126 {
127     struct RequestHandle *headerNode;
128     struct RequestHandle *tailNode;
129 } RequestHandleList;
130
131 //-----------------------------------------------------------------------------
132 // Function prototypes for mirrorResourceHandle
133 //-----------------------------------------------------------------------------
134
135 /**
136 * Create an empty mirror resource list
137 *
138 * @return
139 *     pointer to empty Mirror resource list
140 */
141 MirrorResourceList *createMirrorResourceList();
142
143 /**
144 * Create an empty mirror resource.
145 *
146 * @return
147 *     pointer to empty mirror resource
148 */
149 MirrorResource *createMirrorResource();
150
151 /**
152 * Insert the mirror resource in the mirror resource list
153 *
154 * @param mirrorResourceList - pointer to the target mirror resource list that mirror resource will be inserted
155 * @param mirrorResource - pointer to mirror resource list to be inserted
156 * @return
157 *     OIC_HOSTING_INVALID_PARAM - if list or vResource is null
158 *     OIC_HOSTING_OK - successfully inserted
159 */
160 OCStackResult insertMirrorResource(MirrorResourceList *mirrorResourceList,
161                                    MirrorResource *mirrorResource);
162
163 /**
164 * Delete the mirror resource from the mirror resource list
165 *
166 * @param mirrorResourceList - pointer to the target mirror resource list that mirror resource will be deleted
167 * @param mirrorResource - pointer to mirror resource list to be deleted
168 * @return
169 *     OIC_HOSTING_INVALID_PARAM - if mirrorResourceList or mirrorResource is null
170 *     OIC_HOSTING_ERROR - mirror resource delete process error
171 *     OIC_HOSTING_OK - successfully deleted
172 */
173 OCStackResult deleteMirrorResourceFromList(MirrorResourceList *mirrorResourceList,
174         MirrorResource *mirrorResource);
175
176 /**
177 * Destroy mirror resource
178 *
179 * @param mirrorResource - pointer to mirror resource to be destroyed
180 * @return
181 *     OIC_HOSTING_INVALID_PARAM - if mirrorResource is null
182 *     OIC_HOSTING_OK - successfully destroyed
183 */
184 OCStackResult destroyMirrorResource(MirrorResource *mirrorResource);
185
186 /**
187 * Destroy mirror resource list
188 *
189 * @param mirrorResourceList - pointer to mirror resource list to be destroyed
190 * @return
191 *     OIC_HOSTING_INVALID_PARAM - if mirrorResourceList is null
192 *     OIC_HOSTING_OK - successfully destroyed
193 */
194 OCStackResult destroyMirrorResourceList(MirrorResourceList *mirrorResourceList);
195
196 /**
197 * Find mirror resource using handle
198 *
199 * @param mirrorResourceList - pointer to the target mirror resource list that mirror resource will be found
200 * @param handle - handle value to be found
201 * @param paramType - handle type to be found
202 *
203 * NOTE: every parameter(handle and type) will be compared
204 *
205 * @return
206 *     pointer to the found mirror resource
207 *     NULL - mirror resource not found
208 */
209 MirrorResource *findMirrorResourceUsingHandle(MirrorResourceList *mirrorResourceList,
210         OCResourceHandle handle, OICResourceCoordinatorParamType paramType);
211
212 /*
213  * find virtual resource using address function 사용하는지 확인 필요.
214  */
215 //virtualResource *findvResourceUsingAddress(virtualResourceList *list,
216 //        const char *Address, OICResourceHostingParamType type, const char *subData);
217
218 /**
219 * Find mirror resource using Address and URI
220 *
221 * @param mirrorResourceList - pointer to the target mirror resource list that mirror resource will be found
222 * @param address - pointer to address to be found
223 * @param paramType - address type to be found
224 * @param uri - pointer to uri to be found
225 *
226 * NOTE: every parameter(address, type and uri) will be compared
227 *
228 * @return
229 *     pointer to the found mirror resource
230 *     NULL - invalid input parameter or mirror resource not found
231 */
232 MirrorResource *findMirrorResourceUsingAddressAndURI(MirrorResourceList *mirrorResourceList,
233         const char *address, OICResourceCoordinatorParamType paramType, const char *uri);
234
235 /**
236 * Find mirror resource list using Address and Hosting Parameter Type
237 *
238 * @param mirrorResourceList - pointer to the target mirror resource list that mirror resource will be found
239 * @param address - pointer to address to be found
240 * @param paramType - address type to be found
241 *
242 * NOTE: every parameter(address, type and uri) will be compared
243 *
244 * @return
245 *     pointer to the found mirror resource
246 *     NULL - invalid input parameter or mirror resource list not found
247 */
248 MirrorResourceList *findMirrorResourceListUsingAddress(MirrorResourceList *mirrorResourceList,
249         const char *address, OICResourceCoordinatorParamType paramType);
250
251 /**
252 * Copy mirror resource
253 *
254 * @param sourceMirrorResource - pointer to source mirror resource
255 *
256 * @return
257 *     pointer to the copied mirror resource
258 */
259 MirrorResource *cloneMirrorResource(MirrorResource *sourceMirrorResource);
260
261 /**
262 * Eject mirror resource from mirror resource list
263 *
264 * @param mirrorResourceList - pointer to the target mirror resource list that mirror resource will be found
265 * @param mirrorResource - pointer to mirror resource to be ejected
266 *
267 * @return
268 *     OIC_HOSTING_INVALID_PARAM - mirrorResourceList or mirrorResource is null
269 *     OIC_HOSTING_OK - ejected successfully
270 *     OIC_HOSTING_ERROR - cannot found mirror resource from mirrorResourceList same with mirrorResource
271 */
272 OCStackResult ejectMirrorResource(MirrorResourceList *mirrorResourceList,
273                                   MirrorResource *mirrorResource);
274
275 /**
276 * Print mirror resources from mirror resource list
277 *
278 * @param mirrorResourceList - pointer to the mirror resource list that mirror resource will be printed
279 *
280 * @return
281 *     OIC_HOSTING_INVALID_PARAM - mirrorResourceList is null or mirrorResourceList is empty
282 *     OIC_HOSTING_OK - print successfully
283 */
284 OCStackResult printMirrorResourceList(MirrorResourceList *mirrorResourceList);
285
286 //-----------------------------------------------------------------------------
287 // Function prototypes for RequestHandle
288 //-----------------------------------------------------------------------------
289 RequestHandleList *createRequestHandleList();
290 RequestHandle *createRequestHandle();
291 OCStackResult insertRequestHandle(RequestHandleList *requestHandleList,
292                                   RequestHandle *requestHandle);
293
294 OCStackResult deleteRequestHandleFromList(RequestHandleList *requestHandleList,
295         RequestHandle *requestHandle);
296 OCStackResult destroyRequestHandle(RequestHandle *requestHandle);
297
298 OCStackResult destroyRequestHandleList(RequestHandleList *requestHandleList);
299
300 RequestHandle *findRequestHandle(RequestHandleList *requestHandleList,
301                                  OCDoHandle handle, OICResourceCoordinatorParamType paramType);
302
303 #endif //_MIRROR_RESOURCE_H_