replace : iotivity -> iotivity-sec
[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  * following structure will be created in occollection.
65  */
66
67 typedef struct occapability {
68     /** Linked list; for multiple capabilities.*/
69     struct occapability* next;
70
71     /** It is a name about resource capability. */
72     char *capability;
73
74     /** It is mean status of capability. */
75     char *status;
76 } OCCapability;
77
78 /**
79  * following structure will be created in occollection.
80  */
81
82 typedef struct ocaction {
83     /** linked list; for multiple actions. */
84     struct ocaction *next;
85
86     /** Target Uri. It will be used to execute the action. */
87     char *resourceUri;
88
89     /** head pointer of a linked list of capability nodes.*/
90     OCCapability* head;
91 } OCAction;
92
93 /**
94  * following structure will be created in occollection.
95  */
96
97 typedef struct ocactionset
98 {
99     /** linked list; for list of action set. */
100     struct ocactionset *next;
101
102     /** Name of the action set.*/
103     char *actionsetName;
104
105     /** Time stamp.*/
106     long int timesteps;
107
108     /** Type of action.*/
109     unsigned int type;
110
111     /** head pointer of a linked list of Actions.*/
112     OCAction* head;
113 } OCActionSet;
114
115 /**
116  * Data structure for holding name and data types for each OIC resource.
117  */
118 typedef struct resourcetype_t {
119
120     /** linked list; for multiple types on resource. */
121     struct resourcetype_t *next;
122
123     /**
124      * Name of the type; this string is ‘.’ (dot) separate list of segments where each segment is a
125      * namespace and the final segment is the type; type and sub-types can be separate with
126      * ‘-‘ (dash) usually only two segments would be defined. Either way this string is meant to be
127      * human friendly and is used opaquely and not parsed by code. This name is used in the “rt=”
128      * parameter of a resource description when resources are introspected and is also use in the
129      * " <base URI>/types " list of available types.
130     */
131     char *resourcetypename;
132 } OCResourceType;
133
134 /**
135  * Data structure for data type and definition for attributes that the resource exposes.
136  */
137 typedef struct attr_t {
138
139     /** Points to next resource in list.*/
140     struct attr_t *next;
141
142     /** The name of the attribute; used to look up the attribute in list.
143      *  for a given attribute SHOULD not be changed once assigned.
144      */
145     char *attrName;
146
147     /** value of the attribute as void. To support both string and @OCStringLL value*/
148     void *attrValue;
149 } OCAttribute;
150
151 /**
152  * Data structure for holding a resource interface
153  */
154 typedef struct resourceinterface_t {
155
156     /** linked list; for multiple interfaces on resource.*/
157     struct resourceinterface_t *next;
158
159     /** Name of the interface; this is ‘.’ (dot) separate list of segments where each segment is a
160      * namespace and the final segment is the interface; usually only two segments would be
161      * defined. Either way this string is opaque and not parsed by segment.*/
162     char *name ;
163
164     /** Supported content types to serialize request and response on this interface
165      * (REMOVE for V1 – only jSON for all but core.ll that uses Link Format)*/
166 #if 0
167     char *inputContentType ;
168     char *outputContentType ;
169 #endif
170     /** Future placeholder for access control and policy.*/
171 } OCResourceInterface;
172
173 /**
174  * Data structure for holding child resources associated with a collection
175  */
176 typedef struct OCChildResource {
177     struct OCResource *rsrcResource;
178     struct OCChildResource *next;
179 } OCChildResource;
180
181 /**
182  * Data structure for holding data type and definition for OIC resource.
183  */
184 typedef struct OCResource {
185
186     /** Points to next resource in list.*/
187     struct OCResource *next;
188
189     /** Relative path on the device; will be combined with base url to create fully qualified path.*/
190     char *uri;
191
192     /** Resource type(s); linked list.*/
193     OCResourceType *rsrcType;
194
195     /** Resource interface(s); linked list.*/
196     OCResourceInterface *rsrcInterface;
197
198     /** Resource interface(s); linked list.*/
199     OCAttribute *rsrcAttributes;
200
201     /** Array of pointers to resources; can be used to represent a container of resources.
202      * (i.e. hierarchies of resources) or for reference resources (i.e. for a resource collection).*/
203
204     /** Child resource(s); linked list.*/
205     OCChildResource *rsrcChildResourcesHead;
206
207     /** Pointer to function that handles the entity bound to the resource.
208      *  This handler has to be explicitly defined by the programmer.*/
209     OCEntityHandler entityHandler;
210
211     /** Callback parameter.*/
212     void * entityHandlerCallbackParam;
213
214     /** Properties on the resource – defines meta information on the resource.
215      * (ACTIVE, DISCOVERABLE etc ). */
216
217     OCResourceProperty resourceProperties ;
218
219     /* @note: Methods supported by this resource should be based on the interface targeted
220      * i.e. look into the interface structure based on the query request Can be removed here;
221      * place holder for the note above.*/
222     /* method_t methods; */
223
224
225     /** Sequence number for observable resources. Per the CoAP standard it is a 24 bit value.*/
226     uint32_t sequenceNum;
227
228     /** Pointer of ActionSet which to support group action.*/
229     OCActionSet *actionsetHead;
230
231     /** The instance identifier for this web link in an array of web links - used in links. */
232     union
233     {
234         /** An ordinal number that is not repeated - must be unique in the collection context. */
235         int64_t ins;
236         /** Any unique string including a URI. */
237         char *uniqueStr;
238         /** Use UUID for universal uniqueness - used in /oic/res to identify the device. */
239         OCIdentity uniqueUUID;
240     };
241 } OCResource;
242
243
244
245 #endif /* OCRESOURCE_H_ */