Merge "Merge branch 'master' into resource-manipulation" into resource-manipulation
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / linux / SimpleClientServer / ocserver.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef OCSERVER_H_
22 #define OCSERVER_H_
23
24 #include "ocstack.h"
25
26 //-----------------------------------------------------------------------------
27 // Defines
28 //-----------------------------------------------------------------------------
29 #define TAG "ocserver"
30 #define SAMPLE_MAX_NUM_OBSERVATIONS     8
31 #define SAMPLE_MAX_NUM_POST_INSTANCE  2
32
33 //-----------------------------------------------------------------------------
34 // Typedefs
35 //-----------------------------------------------------------------------------
36
37 /* Structure to represent a Light resource */
38 typedef struct LIGHTRESOURCE
39 {
40     OCResourceHandle handle;
41     bool state;
42     int power;
43 } LightResource;
44
45 /* Structure to represent the observers */
46 typedef struct
47 {
48     OCObservationId observationId;
49     bool valid;
50     OCResourceHandle resourceHandle;
51 } Observers;
52
53 //-----------------------------------------------------------------------------
54 // Function prototype
55 //-----------------------------------------------------------------------------
56
57 /* call getResult in common.cpp to get the result in string format. */
58 const char *getResult(OCStackResult result);
59
60 /* Function that creates a new Light resource by calling the
61  * OCCreateResource() method.
62  */
63 int createLightResource (char *uri, LightResource *lightResource);
64
65 /* This method converts the payload to JSON format */
66 char* constructJsonResponse (OCEntityHandlerRequest *ehRequest);
67
68 /* This method changes the Light power using an independent thread
69  * and notifies the observers of new state of the resource.
70  */
71 void *ChangeLightRepresentation (void *param);
72
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
75  */
76 OCEntityHandlerResult ValidateQueryParams (OCEntityHandlerRequest *entityHandlerRequest);
77
78 /* Following methods process the PUT, GET, POST, Delete,
79  * & Observe requests */
80 OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
81                                          char *payload,
82                                          uint16_t maxPayloadSize);
83 OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
84                                          char *payload,
85                                          uint16_t maxPayloadSize);
86 OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
87                                           OCEntityHandlerResponse *response,
88                                           char *payload,
89                                           uint16_t maxPayloadSize);
90 OCEntityHandlerResult ProcessDeleteRequest (OCEntityHandlerRequest *ehRequest,
91                                             char *payload,
92                                             uint16_t maxPayloadSize);
93
94 OCEntityHandlerResult ProcessNonExistingResourceRequest (OCEntityHandlerRequest *ehRequest,
95                                                          char *payload,
96                                                          uint16_t maxPayloadSize);
97
98 void ProcessObserveRegister (OCEntityHandlerRequest *ehRequest);
99 void ProcessObserveDeregister (OCEntityHandlerRequest *ehRequest);
100
101 void DeleteDeviceInfo();
102
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);
108
109
110 //-----------------------------------------------------------------------------
111 // Callback functions
112 //-----------------------------------------------------------------------------
113
114 /* Entity Handler callback functions */
115 OCEntityHandlerResult
116 OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
117         OCEntityHandlerRequest *entityHandlerRequest, char* uri);
118
119 OCEntityHandlerResult
120 OCEntityHandlerCb (OCEntityHandlerFlag flag,
121         OCEntityHandlerRequest *entityHandlerRequest);
122
123
124 #endif
125