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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
29 #define TAG "ocserver"
30 #define SAMPLE_MAX_NUM_OBSERVATIONS 8
31 #define SAMPLE_MAX_NUM_POST_INSTANCE 2
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 /* Structure to represent a Light resource */
38 typedef struct LIGHTRESOURCE
40 OCResourceHandle handle;
45 /* Structure to represent the observers */
48 OCObservationId observationId;
50 OCResourceHandle resourceHandle;
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
57 /* call getResult in common.cpp to get the result in string format. */
58 const char *getResult(OCStackResult result);
60 /* Function that creates a new Light resource by calling the
61 * OCCreateResource() method.
63 int createLightResource (char *uri, LightResource *lightResource);
65 /* This method converts the payload to JSON format */
66 char* constructJsonResponse (OCEntityHandlerRequest *ehRequest);
68 /* This method changes the Light power using an independent thread
69 * and notifies the observers of new state of the resource.
71 void *ChangeLightRepresentation (void *param);
73 /* This method check the validity of resourceTypeName and resource interfaces
74 * Entity Handler has to parse the query string in order to process it
76 OCEntityHandlerResult ValidateQueryParams (OCEntityHandlerRequest *entityHandlerRequest);
78 /* Following methods process the PUT, GET, POST, Delete,
79 * & Observe requests */
80 OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
82 uint16_t maxPayloadSize);
83 OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
85 uint16_t maxPayloadSize);
86 OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
87 OCEntityHandlerResponse *response,
89 uint16_t maxPayloadSize);
90 OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest,
92 uint16_t maxPayloadSize);
94 OCEntityHandlerResult ProcessNonExistingResourceRequest (OCEntityHandlerRequest *ehRequest,
96 uint16_t maxPayloadSize);
98 void ProcessObserveRegister (OCEntityHandlerRequest *ehRequest);
99 void ProcessObserveDeregister (OCEntityHandlerRequest *ehRequest);
101 void DeleteDeviceInfo();
103 OCStackResult SetDeviceInfo(const char *contentType, const char *dateOfManufacture,
104 const char *deviceName, const char *deviceUUID, const char *firmwareVersion,
105 const char *hostName, const char *manufacturerName, const char *manufacturerUrl,
106 const char *modelNumber, const char *platformVersion, const char *supportUrl,
107 const char *version);
110 //-----------------------------------------------------------------------------
111 // Callback functions
112 //-----------------------------------------------------------------------------
114 /* Entity Handler callback functions */
115 OCEntityHandlerResult
116 OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
117 OCEntityHandlerRequest *entityHandlerRequest, char* uri);
119 OCEntityHandlerResult
120 OCEntityHandlerCb (OCEntityHandlerFlag flag,
121 OCEntityHandlerRequest *entityHandlerRequest);