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{
39 OCResourceHandle handle;
44 /* Structure to represent the observers */
46 OCObservationId observationId;
48 OCResourceHandle resourceHandle;
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 /* call getResult in common.cpp to get the result in string format. */
56 const char *getResult(OCStackResult result);
58 /* Function that creates a new Light resource by calling the
59 * OCCreateResource() method.
61 int createLightResource (char *uri, LightResource *lightResource);
63 /* This method converts the payload to JSON format */
64 char* constructJsonResponse (OCEntityHandlerRequest *ehRequest);
66 /* This method changes the Light power using an independent thread
67 * and notifies the observers of new state of the resource.
69 void *ChangeLightRepresentation (void *param);
71 /* Following methods process the PUT, GET, POST, Delete,
72 * & Observe requests */
73 OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
75 uint16_t maxPayloadSize);
76 OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
78 uint16_t maxPayloadSize);
79 OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
80 OCEntityHandlerResponse *response,
82 uint16_t maxPayloadSize);
83 OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest,
85 uint16_t maxPayloadSize);
87 OCEntityHandlerResult ProcessNonExistingResourceRequest (OCEntityHandlerRequest *ehRequest,
89 uint16_t maxPayloadSize);
91 void ProcessObserveRegister (OCEntityHandlerRequest *ehRequest);
92 void ProcessObserveDeregister (OCEntityHandlerRequest *ehRequest);
94 void DeleteDeviceInfo();
96 OCStackResult SetDeviceInfo(const char *contentType, const char *dateOfManufacture,
97 const char *deviceName, const char *deviceUUID, const char *firmwareVersion,
98 const char *hostName, const char *manufacturerName, const char *manufacturerUrl,
99 const char *modelNumber, const char *platformVersion, const char *supportUrl,
100 const char *version);
103 //-----------------------------------------------------------------------------
104 // Callback functions
105 //-----------------------------------------------------------------------------
107 /* Entity Handler callback functions */
108 OCEntityHandlerResult
109 OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
110 OCEntityHandlerRequest *entityHandlerRequest, char* uri);
112 OCEntityHandlerResult
113 OCEntityHandlerCb (OCEntityHandlerFlag flag,
114 OCEntityHandlerRequest *entityHandlerRequest);