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"
29 * Attributes used to form a proper OIC conforming JSON message.
31 #define OC_RSRVD_OC "oc"
32 #define OC_RSRVD_PAYLOAD "payload"
33 #define OC_RSRVD_HREF "href"
34 #define OC_RSRVD_REPRESENTATION "rep"
35 #define OC_RSRVD_CONTENT_TYPE "ct"
36 #define OC_RSRVD_RESOURCE_TYPE "rt"
37 #define OC_RSRVD_RESOURCE_TYPE_PRESENCE "core.presence"
38 #define OC_RSRVD_INTERFACE "if"
39 #define OC_RSRVD_DEVICE_ID "di"
40 #define OC_RSRVD_DEVICE_NAME "dn"
41 #define OC_RSRVD_INTERFACE_DEFAULT "oc.mi.def"
42 #define OC_RSRVD_INTERFACE_LL "oc.mi.ll"
43 #define OC_RSRVD_INTERFACE_BATCH "oc.mi.b"
44 #define OC_RSRVD_INTERFACE_GROUP "oc.mi.grp"
45 #define OC_RSRVD_MFG_DATE "mndt"
46 #define OC_RSRVD_FW_VERSION "mnfv"
47 #define OC_RSRVD_HOST_NAME "hn"
48 #define OC_RSRVD_MFG_NAME "mnmn"
49 #define OC_RSRVD_MFG_URL "mnml"
50 #define OC_RSRVD_MODEL_NUM "mnmo"
51 #define OC_RSRVD_PLATFORM_VERSION "mnpv"
52 #define OC_RSRVD_SUPPORT_URL "mnsl"
53 #define OC_RSRVD_VERSION "icv"
54 #define OC_RSRVD_OBSERVABLE "obs"
55 #define OC_RSRVD_SECURE "sec"
56 #define OC_RSRVD_HOSTING_PORT "port"
57 #define OC_RSRVD_SERVER_INSTANCE_ID "sid"
60 * Common JSON string components used by the stack to build JSON strings.
62 #define OC_JSON_PREFIX "{\"oc\":["
63 #define OC_JSON_PREFIX_LEN (sizeof(OC_JSON_PREFIX) - 1)
64 #define OC_JSON_SUFFIX "]}"
65 #define OC_JSON_SUFFIX_LEN (sizeof(OC_JSON_SUFFIX) - 1)
66 #define OC_JSON_SEPARATOR ','
67 #define OC_JSON_SEPARATOR_STR ","
70 * Static values for various JSON attributes.
72 #define OC_RESOURCE_OBSERVABLE 1
73 #define OC_RESOURCE_SECURE 1
76 * The type of query a request/response message is.
80 STACK_RES_DISCOVERY_NOFILTER = 0,
81 STACK_RES_DISCOVERY_IF_FILTER,
82 STACK_RES_DISCOVERY_RT_FILTER,
83 STACK_DEVICE_DISCOVERY_DI_FILTER,
84 STACK_DEVICE_DISCOVERY_DN_FILTER
88 * The type of handling required to handle a request.
92 OC_RESOURCE_VIRTUAL = 0,
93 OC_RESOURCE_NOT_COLLECTION_WITH_ENTITYHANDLER,
94 OC_RESOURCE_NOT_COLLECTION_DEFAULT_ENTITYHANDLER,
95 OC_RESOURCE_COLLECTION_WITH_ENTITYHANDLER,
96 OC_RESOURCE_COLLECTION_DEFAULT_ENTITYHANDLER,
97 OC_RESOURCE_DEFAULT_DEVICE_ENTITYHANDLER,
98 OC_RESOURCE_NOT_SPECIFIED
102 * Default entity handler (ie. callback) to be used for resources with
105 OCEntityHandlerResult defaultResourceEHandler(OCEntityHandlerFlag flag,
106 OCEntityHandlerRequest * request);
109 * Get string value associated with a virtual resource type.
111 const char * GetVirtualResourceUri(OCVirtualResources resource);
114 * Find and retrieve pointer to a resource associated with a specific resource
117 OCResource *FindResourceByUri(const char* resourceUri);
120 * Returns true if the specificed resource URI aligns with a pre-existing
121 * virtual resource; returns false otherwise.
123 bool IsVirtualResource(const char* resourceUri);
126 * Parameter @ref handling returns by-reference the type of resource handling
127 * required by the internal stack based on the specified @ref request.
129 OCStackResult DetermineResourceHandling (OCServerRequest *request,
130 ResourceHandling *handling,
131 OCResource **resource);
134 * Processes the specified @ref request based on the type of resource handling
137 OCStackResult ProcessRequest(ResourceHandling resHandling,
138 OCResource *resource,
139 OCServerRequest *request);
142 * Internal API used to save all of the device's information for use in device
143 * discovery requests.
145 OCStackResult SaveDeviceInfo(OCDeviceInfo deviceInfo);
148 * Internal API used to clear the device information.
150 void DeleteDeviceInfo();
153 * Prepares a JSON string for response.
155 OCStackResult BuildVirtualResourceResponse(OCResource *resourcePtr,
160 CAConnectivityType_t connType);
163 * A helper function that Maps an @ref OCEntityHandlerResult type to an
164 * @ref OCStackResult type.
166 OCStackResult EntityHandlerCodeToOCStackCode(OCEntityHandlerResult ehResult);
168 #endif //OC_RESOURCEHANDLER_H