01611c1c0300a9b2ffb089a2f55b770e4fb30e5f
[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 #ifndef OCRESOURCE_H_
22 #define OCRESOURCE_H_
23
24 #define OC_OBSERVER_NOT_INTERESTED       (0)
25 #define OC_OBSERVER_STILL_INTERESTED     (1)
26 #define OC_OBSERVER_FAILED_COMM          (2)
27
28 //-----------------------------------------------------------------------------
29 // Virtual Resource Presence Attributes
30 //-----------------------------------------------------------------------------
31 #ifdef WITH_PRESENCE
32 typedef struct PRESENCERESOURCE{
33     OCResourceHandle handle;
34     uint32_t presenceTTL;
35 } PresenceResource;
36 #endif
37
38 //-----------------------------------------------------------------------------
39 // Forward declarations
40 //-----------------------------------------------------------------------------
41 struct rsrc_t;
42
43 //-----------------------------------------------------------------------------
44 // Typedefs
45 //-----------------------------------------------------------------------------
46
47 // IF here stands for Interface
48 typedef enum {
49     STACK_IF_DEFAULT = 0,
50     STACK_IF_LL,
51     STACK_IF_BATCH,
52     STACK_IF_GROUP,
53     STACK_IF_INVALID
54 } OCStackIfTypes;
55
56 // following structure will be create in occollection.
57 typedef struct occapability {
58     struct occapability* next;
59
60     char *capability;           // It is a name about resource capability.
61     char *status;               //
62 } OCCapability;
63
64
65 // following structure will be create in occollection.
66 typedef struct ocaction {
67     struct ocaction *next;
68
69     // Target Uri.
70     // It will be used to execute the action.
71     char *resourceUri;
72
73     OCCapability* head;
74     
75 } OCAction;
76
77 // following structure will be created in occollection.
78 typedef struct ocactionset {
79
80     struct ocactionset *next;
81
82     char *actionsetName;
83
84     OCAction* head;
85 } OCActionSet;
86
87
88
89 typedef struct resourcetype_t {
90     struct resourcetype_t *next; // linked list; for multiple types on resource
91
92     // Name of the type; this string is ‘.’ (dot) separate list of segments where each segment is a
93     // namespace and the final segment is the type; type and sub-types can be separate with
94     // ‘-‘ (dash) usually only two segments would be defined. Either way this string is meant to be
95     // human friendly and is used opaquely and not parsed by code. This name is used in the “rt=”
96     // parameter of a resource description when resources are introspected and is also use in the
97     // <base URI>/types list of available types.
98     char *resourcetypename;
99 } OCResourceType;
100
101 typedef struct attr_t {
102     struct attr_t *next; // Points to next resource in list
103
104     // The name of the attribute; used to look up the attribute in list;
105     // for a given attribute SHOULD not be changed once assigned
106     const char *attrName;
107     char *attrValue; // value of the attribute as string
108 } OCAttribute;
109
110 typedef struct resourceinterface_t {
111     struct resourceinterface_t *next; // linked list; for multiple interfaces on resource
112
113     // Name of the interface; this is ‘.’ (dot) separate list of segments where each segment is a
114     // namespace and the final segment is the interface; usually only two segments would be
115     // defined. Either way this string is opaque and not parsed by segment
116     char *name ;
117
118     // Supported content types to serialize request and response on this interface
119     // (REMOVE for V1 – only jSON for all but core.ll that uses Link Format)
120 #if 0
121     char *inputContentType ;
122     char *outputContentType ;
123 #endif
124     /*** Future placeholder for access control and policy ***/
125 } OCResourceInterface;
126
127 typedef struct rsrc_t {
128     struct rsrc_t *next; // Points to next resource in list
129     // Relative path on the device; will be combined with base url to create fully qualified path
130     char *host;
131     char *uri;
132     OCResourceType *rsrcType; // Resource type(s); linked list
133     OCResourceInterface *rsrcInterface; // Resource interface(s); linked list
134     OCAttribute *rsrcAttributes; // Resource interface(s); linked list
135     // Array of pointers to resources; can be used to represent a container of resources
136     // (i.e. hierarchies of resources) or for reference resources (i.e. for a resource collection)
137     struct rsrc_t *rsrcResources[MAX_CONTAINED_RESOURCES];
138     //struct rsrc_t *rsrcResources;
139     // Pointer to function that handles the entity bound to the resource.
140     // This handler has to be explicitly defined by the programmer
141     OCEntityHandler entityHandler;
142     // Properties on the resource – defines meta information on the resource
143     OCResourceProperty resourceProperties ; /* ACTIVE, DISCOVERABLE etc */
144     // Pointer to an opaque object where app/user specific data can be placed with the resource;
145     // this could be information for the entity handler between invocations
146     void *context;
147     // NOTE: Methods supported by this resource should be based on the interface targeted
148     // i.e. look into the interface structure based on the query request Can be removed here;
149     // place holder for the note above
150     /* method_t methods; */
151     // Sequence number for observable resources. Per the CoAP standard it is a 24 bit value.
152     uint32_t sequenceNum;
153
154         // Pointer of ActionSet which to support group action.
155     OCActionSet *actionsetHead;
156 } OCResource;
157
158
159
160 #endif /* OCRESOURCE_H_ */