Imported Upstream version 0.9.2
[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 constructs a response from the request */
66 OCRepPayload* constructResponse (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                                          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);
88
89 OCEntityHandlerResult ProcessNonExistingResourceRequest (OCEntityHandlerRequest *ehRequest);
90
91 void ProcessObserveRegister (OCEntityHandlerRequest *ehRequest);
92 void ProcessObserveDeregister (OCEntityHandlerRequest *ehRequest);
93
94 void DeleteDeviceInfo();
95
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);
101
102
103 //-----------------------------------------------------------------------------
104 // Callback functions
105 //-----------------------------------------------------------------------------
106
107 /* Entity Handler callback functions */
108 OCEntityHandlerResult
109 OCDeviceEntityHandlerCb (OCEntityHandlerFlag flag,
110         OCEntityHandlerRequest *entityHandlerRequest, char* uri);
111
112 OCEntityHandlerResult
113 OCEntityHandlerCb (OCEntityHandlerFlag flag,
114         OCEntityHandlerRequest *entityHandlerRequest);
115
116
117 #endif
118