1 //******************************************************************
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
4 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
6 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
20 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
30 #define TAG "ocserver"
31 #define SAMPLE_MAX_NUM_OBSERVATIONS 8
32 #define SAMPLE_MAX_NUM_POST_INSTANCE 2
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 /* Structure to represent a Light resource */
39 typedef struct LIGHTRESOURCE
41 OCResourceHandle handle;
46 /* Structure to represent the observers */
49 OCObservationId observationId;
51 OCResourceHandle resourceHandle;
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 /* call getResult in common.cpp to get the result in string format. */
59 const char *getResult(OCStackResult result);
61 /* Function that creates a new Light resource by calling the
62 * OCCreateResource() method.
64 int createLightResource (char *uri, LightResource *lightResource);
66 /* This method converts the payload to JSON format */
67 char* constructJsonResponse (OCEntityHandlerRequest *ehRequest);
69 /* This method changes the Light power using an independent thread
70 * and notifies the observers of new state of the resource.
72 void *ChangeLightRepresentation (void *param);
74 /* This method check the validity of resourceTypeName and resource interfaces
75 * Entity Handler has to parse the query string in order to process it
77 OCEntityHandlerResult ValidateQueryParams (OCEntityHandlerRequest *entityHandlerRequest);
79 /* Following methods process the PUT, GET, POST, Delete,
80 * & Observe requests */
81 OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
83 uint16_t maxPayloadSize);
84 OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
86 uint16_t maxPayloadSize);
87 OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
88 OCEntityHandlerResponse *response,
90 uint16_t maxPayloadSize);
91 OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest,
93 uint16_t maxPayloadSize);
95 OCEntityHandlerResult ProcessNonExistingResourceRequest (OCEntityHandlerRequest *ehRequest,
97 uint16_t maxPayloadSize);
99 void ProcessObserveRegister (OCEntityHandlerRequest *ehRequest);
100 void ProcessObserveDeregister (OCEntityHandlerRequest *ehRequest);
102 void DeleteDeviceInfo();
104 OCStackResult SetDeviceInfo(const char *contentType, const char *dateOfManufacture,
105 const char *deviceName, const char *deviceUUID, const char *firmwareVersion,
106 const char *hostName, const char *manufacturerName, const char *manufacturerUrl,
107 const char *modelNumber, const char *platformVersion, const char *supportUrl,
108 const char *version);
111 //-----------------------------------------------------------------------------
112 // Callback functions
113 //-----------------------------------------------------------------------------
115 /* Entity Handler callback functions */
116 OCEntityHandlerResult
117 OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
118 OCEntityHandlerRequest *entityHandlerRequest, char* uri);
120 OCEntityHandlerResult
121 OCEntityHandlerCb (OCEntityHandlerFlag flag,
122 OCEntityHandlerRequest *entityHandlerRequest);