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 constructs a response from the request */
67 OCRepPayload* constructResponse (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,
82 OCRepPayload **payload);
83 OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
84 OCRepPayload **payload);
85 OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
86 OCEntityHandlerResponse *response,
87 OCRepPayload **payload);
88 OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest);
90 OCEntityHandlerResult ProcessNonExistingResourceRequest (OCEntityHandlerRequest *ehRequest);
92 void ProcessObserveRegister (OCEntityHandlerRequest *ehRequest);
93 void ProcessObserveDeregister (OCEntityHandlerRequest *ehRequest);
95 void DeleteDeviceInfo();
97 OCStackResult SetDeviceInfo(const char *contentType, const char *dateOfManufacture,
98 const char *deviceName, const char *deviceUUID, const char *firmwareVersion,
99 const char *hostName, const char *manufacturerName, const char *manufacturerUrl,
100 const char *modelNumber, const char *platformVersion, const char *supportUrl,
101 const char *version);
104 //-----------------------------------------------------------------------------
105 // Callback functions
106 //-----------------------------------------------------------------------------
108 /* Entity Handler callback functions */
109 OCEntityHandlerResult
110 OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
111 OCEntityHandlerRequest *entityHandlerRequest, char* uri);
113 OCEntityHandlerResult
114 OCEntityHandlerCb (OCEntityHandlerFlag flag,
115 OCEntityHandlerRequest *entityHandlerRequest);