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