RD client features in base layer
[platform/upstream/iotivity.git] / resource / csdk / stack / include / internal / ocresource.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH 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 /**
22  * @file
23  *
24  * This file contains the definition, types and interfaces for resource and attributes
25  *
26  */
27
28
29 #ifndef OCRESOURCE_H_
30 #define OCRESOURCE_H_
31
32 #include "ocstackconfig.h"
33 #include "occlientcb.h"
34
35 /** Macro Definitions for observers */
36
37 /** Observer not interested. */
38 #define OC_OBSERVER_NOT_INTERESTED       (0)
39
40 /** Observer still interested. */
41 #define OC_OBSERVER_STILL_INTERESTED     (1)
42
43 /** Failed communication. */
44 #define OC_OBSERVER_FAILED_COMM          (2)
45
46 /**
47  *Virtual Resource Presence Attributes
48  */
49
50 #ifdef WITH_PRESENCE
51 typedef struct PRESENCERESOURCE{
52     OCResourceHandle handle;
53     uint32_t presenceTTL;
54 } PresenceResource;
55 #endif
56
57 /**
58  * Forward declarations
59  */
60
61 struct rsrc_t;
62
63 /**
64  * Typedefs for stack interface
65  * IF here stands for Interface
66  */
67
68 typedef enum {
69     STACK_IF_DEFAULT = 0,
70     STACK_IF_LL,
71     STACK_IF_BATCH,
72     STACK_IF_GROUP,
73     STACK_IF_INVALID
74 } OCStackIfTypes;
75
76 /**
77  * following structure will be created in occollection.
78  */
79
80 typedef struct occapability {
81     /** Linked list; for multiple capabilities.*/
82     struct occapability* next;
83
84     /** It is a name about resource capability. */
85     char *capability;
86
87     /** It is mean status of capability. */
88     char *status;
89 } OCCapability;
90
91 /**
92  * following structure will be created in occollection.
93  */
94
95 typedef struct ocaction {
96     /** linked list; for multiple actions. */
97     struct ocaction *next;
98
99     /** Target Uri. It will be used to execute the action. */
100     char *resourceUri;
101
102     /** head pointer of a linked list of capability nodes.*/
103     OCCapability* head;
104 } OCAction;
105
106 /**
107  * following structure will be created in occollection.
108  */
109
110 typedef struct ocactionset
111 {
112     /** linked list; for list of action set. */
113     struct ocactionset *next;
114
115     /** Name of the action set.*/
116     char *actionsetName;
117
118     /** Time stamp.*/
119     long int timesteps;
120
121     /** Type of action.*/
122     unsigned int type;
123
124     /** head pointer of a linked list of Actions.*/
125     OCAction* head;
126 } OCActionSet;
127
128 /**
129  * Data structure for holding name and data types for each OIC resource.
130  */
131 typedef struct resourcetype_t {
132
133     /** linked list; for multiple types on resource. */
134     struct resourcetype_t *next;
135
136     /**
137      * Name of the type; this string is ‘.’ (dot) separate list of segments where each segment is a
138      * namespace and the final segment is the type; type and sub-types can be separate with
139      * ‘-‘ (dash) usually only two segments would be defined. Either way this string is meant to be
140      * human friendly and is used opaquely and not parsed by code. This name is used in the “rt=”
141      * parameter of a resource description when resources are introspected and is also use in the
142      * " <base URI>/types " list of available types.
143     */
144     char *resourcetypename;
145 } OCResourceType;
146
147 /**
148  * Data structure for data type and definition for attributes that the resource exposes.
149  */
150 typedef struct attr_t {
151
152     /** Points to next resource in list.*/
153     struct attr_t *next;
154
155     /** The name of the attribute; used to look up the attribute in list.
156      *  for a given attribute SHOULD not be changed once assigned.
157      */
158     const char *attrName;
159
160     /** value of the attribute as string.*/
161     char *attrValue;
162 } OCAttribute;
163
164 /**
165  * Data structure for holding a resource interface
166  */
167 typedef struct resourceinterface_t {
168
169     /** linked list; for multiple interfaces on resource.*/
170     struct resourceinterface_t *next;
171
172     /** Name of the interface; this is ‘.’ (dot) separate list of segments where each segment is a
173      * namespace and the final segment is the interface; usually only two segments would be
174      * defined. Either way this string is opaque and not parsed by segment.*/
175     char *name ;
176
177     /** Supported content types to serialize request and response on this interface
178      * (REMOVE for V1 – only jSON for all but core.ll that uses Link Format)*/
179 #if 0
180     char *inputContentType ;
181     char *outputContentType ;
182 #endif
183     /** Future placeholder for access control and policy.*/
184 } OCResourceInterface;
185
186 /**
187  * Data structure for holding child resources associated with a collection
188  */
189 typedef struct OCChildResource {
190     struct OCResource *rsrcResource;
191     struct OCChildResource *next;
192 } OCChildResource;
193
194 /**
195  * Data structure for holding data type and definition for OIC resource.
196  */
197 typedef struct OCResource {
198
199     /** Points to next resource in list.*/
200     struct OCResource *next;
201
202     /** Relative path on the device; will be combined with base url to create fully qualified path.*/
203     char *uri;
204
205     /** Resource type(s); linked list.*/
206     OCResourceType *rsrcType;
207
208     /** Resource interface(s); linked list.*/
209     OCResourceInterface *rsrcInterface;
210
211     /** Resource interface(s); linked list.*/
212     OCAttribute *rsrcAttributes;
213
214     /** Array of pointers to resources; can be used to represent a container of resources.
215      * (i.e. hierarchies of resources) or for reference resources (i.e. for a resource collection).*/
216
217     /** Child resource(s); linked list.*/
218     OCChildResource *rsrcChildResourcesHead;
219
220     /** Pointer to function that handles the entity bound to the resource.
221      *  This handler has to be explicitly defined by the programmer.*/
222     OCEntityHandler entityHandler;
223
224     /** Callback parameter.*/
225     void * entityHandlerCallbackParam;
226
227     /** Properties on the resource – defines meta information on the resource.
228      * (ACTIVE, DISCOVERABLE etc ). */
229
230     OCResourceProperty resourceProperties ;
231
232     /* @note: Methods supported by this resource should be based on the interface targeted
233      * i.e. look into the interface structure based on the query request Can be removed here;
234      * place holder for the note above.*/
235     /* method_t methods; */
236
237
238     /** Sequence number for observable resources. Per the CoAP standard it is a 24 bit value.*/
239     uint32_t sequenceNum;
240
241     /** Pointer of ActionSet which to support group action.*/
242     OCActionSet *actionsetHead;
243
244     /** The instance identifier for this web link in an array of web links - used in links. */
245     union
246     {
247         /** An ordinal number that is not repeated - must be unique in the collection context. */
248         uint8_t ins;
249         /** Any unique string including a URI. */
250         char *uniqueStr;
251         /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
252         OCIdentity uniqueUUID;
253     };
254 } OCResource;
255
256
257
258 #endif /* OCRESOURCE_H_ */