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