1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef OC_RESOURCEHANDLER_H
22 #define OC_RESOURCEHANDLER_H
25 #include "ocstackinternal.h"
26 #include "ocserverrequest.h"
33 * Common JSON string components used by the stack to build JSON strings.
34 * These details are exposed in ocstackconfig.h file in the form of documentation.
35 * Remember to update the documentation there if these are changed.
37 #define OC_JSON_PREFIX "{\"oic\":["
38 #define OC_JSON_PREFIX_LEN (sizeof(OC_JSON_PREFIX) - 1)
39 #define OC_JSON_SUFFIX "]}"
40 #define OC_JSON_SUFFIX_LEN (sizeof(OC_JSON_SUFFIX) - 1)
41 #define OC_JSON_SEPARATOR ','
42 #define OC_JSON_SEPARATOR_STR ","
43 #define OC_KEY_VALUE_DELIMITER "="
46 * Static values for various JSON attributes.
48 #define OC_RESOURCE_OBSERVABLE 1
49 #define OC_RESOURCE_SECURE 1
52 * OIC Virtual resources supported by every OIC device.
68 /** "/oic/res/d/type" .*/
69 OC_RESOURCE_TYPES_URI,
70 #ifdef ROUTING_GATEWAY
71 /** "/oic/gateway" .*/
84 /** Max items in the list */
85 OC_MAX_VIRTUAL_RESOURCES //<s Max items in the list
90 * The type of query a request/response message is.
94 STACK_RES_DISCOVERY_NOFILTER = 0,
95 STACK_RES_DISCOVERY_IF_FILTER,
96 STACK_RES_DISCOVERY_RT_FILTER,
97 STACK_DEVICE_DISCOVERY_DI_FILTER,
98 STACK_DEVICE_DISCOVERY_DN_FILTER
102 * The type of handling required to handle a request.
106 OC_RESOURCE_VIRTUAL = 0,
107 OC_RESOURCE_NOT_COLLECTION_WITH_ENTITYHANDLER,
108 OC_RESOURCE_NOT_COLLECTION_DEFAULT_ENTITYHANDLER,
109 OC_RESOURCE_COLLECTION_WITH_ENTITYHANDLER,
110 OC_RESOURCE_COLLECTION_DEFAULT_ENTITYHANDLER,
111 OC_RESOURCE_DEFAULT_DEVICE_ENTITYHANDLER,
112 OC_RESOURCE_NOT_SPECIFIED
116 * Default entity handler (ie. callback) to be used for resources with
119 OCEntityHandlerResult defaultResourceEHandler(OCEntityHandlerFlag flag,
120 OCEntityHandlerRequest * request, void* callbackParam);
123 * Find and retrieve pointer to a resource associated with a specific resource
125 * @return pointer to found resource
127 OCResource *FindResourceByUri(const char* resourceUri);
130 * This function checks whether the specified resource URI aligns with a pre-existing
131 * virtual resource; returns false otherwise.
132 * @return true or false.
134 bool IsVirtualResource(const char* resourceUri);
137 * Parameter @ref handling returns by-reference the type of resource handling
138 * required by the internal stack based on the specified @ref request.
139 * @return ::OC_STACK_OK for Success, otherwise some error value
141 OCStackResult DetermineResourceHandling (const OCServerRequest *request,
142 ResourceHandling *handling,
143 OCResource **resource);
146 * Processes the specified @ref request based on the type of resource handling
148 * @return ::OC_STACK_OK for Success, otherwise some error value.
150 OCStackResult ProcessRequest(ResourceHandling resHandling,
151 OCResource *resource,
152 OCServerRequest *request);
155 * Internal API used to save all of the platform's information for use in platform
156 * discovery requests.
157 * @return ::OC_STACK_OK for Success, otherwise some error value.
159 OCStackResult SavePlatformInfo(OCPlatformInfo info);
162 * Internal API used to save all of the device's information for use in platform
163 * discovery requests.
164 * @param info Device name is received from the application.
165 * DeviceID, spec version and data model version are initialized by the stack.
166 * @return ::OC_STACK_OK for Success, otherwise some error value.
168 OCStackResult SaveDeviceInfo(OCDeviceInfo info);
171 * Internal API used to clear the platform information.
173 void DeletePlatformInfo();
176 * Internal API used to clear the device information.
178 void DeleteDeviceInfo();
181 * Prepare payload for resource representation.
183 OCStackResult BuildResponseRepresentation(const OCResource *resourcePtr,
184 OCRepPayload** payload);
187 * A helper function that Maps an @ref OCEntityHandlerResult type to an
188 * @ref OCStackResult type.
190 OCStackResult EntityHandlerCodeToOCStackCode(OCEntityHandlerResult ehResult);
194 #endif // __cplusplus
195 #endif //OC_RESOURCEHANDLER_H