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 constructs a response from the request */
66 OCRepPayload* constructResponse (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,
81 OCRepPayload **payload);
82 OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
83 OCRepPayload **payload);
84 OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
85 OCEntityHandlerResponse *response,
86 OCRepPayload **payload);
87 OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest);
89 OCEntityHandlerResult ProcessNonExistingResourceRequest (OCEntityHandlerRequest *ehRequest);
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);