Merge test folder of test branch
[iotivity.git] / test / src / common / commonutil / c_cpp / UnsupportiveResource.cpp
1 /******************************************************************\r
2  *\r
3  * Copyright 2016 Samsung Electronics All Rights Reserved.\r
4  *\r
5  *\r
6  *\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  * http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  *\r
19  ******************************************************************/\r
20 \r
21 /**\r
22  * UnsupportiveResource.cpp\r
23  *\r
24  *  Created on: Nov 25, 2014\r
25  *\r
26  */\r
27 \r
28 #include "UnsupportiveResource.h"\r
29 \r
30 #define PRESENCE_INTERVAL 10000\r
31 \r
32 UnsupportiveResource::UnsupportiveResource(void)\r
33 {\r
34     //child constructor\r
35 \r
36     string value = DEFAULT_DUMMY_VALUE;\r
37     m_representation.setValue("dummy", value);\r
38 \r
39     printf("Current resource info: %s", m_representation.getPayload()->values->str);\r
40 }\r
41 \r
42 UnsupportiveResource::~UnsupportiveResource(void)\r
43 {\r
44     // child destructor\r
45 }\r
46 \r
47 void UnsupportiveResource::handleObserveRequest(QueryParamsMap& queryParamsMap,\r
48 std::shared_ptr< OCResourceRequest > request,\r
49 std::shared_ptr< OCResourceResponse > response)\r
50 {\r
51     printf("Inside handleObserveRequest... ");\r
52     // handle observe request\r
53     response->setErrorCode(200);\r
54     OCStackResult result = OCPlatform::sendResponse(response);\r
55     if (result != OC_STACK_OK)\r
56     {\r
57         printf("Unable to send response for Observe Request");\r
58     }\r
59 }\r
60 \r
61 void UnsupportiveResource::handleDeleteRequest(QueryParamsMap &queryParamsMap,\r
62         OCRepresentation incomingRepresentation, std::shared_ptr< OCResourceRequest > request,\r
63         std::shared_ptr< OCResourceResponse > response)\r
64 {\r
65     printf("Inside handleDeleteRequest... ");\r
66     // handle delete request\r
67     response->setErrorCode(200);\r
68     OCStackResult result = OCPlatform::sendResponse(response);\r
69     if (result != OC_STACK_OK)\r
70     {\r
71         printf("Unable to send response for Delete Request");\r
72     }\r
73 }\r
74 \r
75 void UnsupportiveResource::handlePostRequest(QueryParamsMap &queryParamsMap,\r
76         OCRepresentation incomingRepresentation, std::shared_ptr< OCResourceRequest > request,\r
77         std::shared_ptr< OCResourceResponse > response)\r
78 {\r
79     printf("Inside handlePostRequest... ");\r
80     // handle POST request\r
81     response->setErrorCode(200);\r
82     OCStackResult result = OCPlatform::sendResponse(response);\r
83     if (result != OC_STACK_OK)\r
84     {\r
85         printf("Unable to send response for POST Request");\r
86     }\r
87 }\r
88 \r
89 void UnsupportiveResource::handleGetRequest(QueryParamsMap &queryParamsMap,\r
90 std::shared_ptr< OCResourceRequest > request,\r
91 std::shared_ptr< OCResourceResponse > response)\r
92 {\r
93     printf("Inside handleGetRequest... ");\r
94     //handle GET request\r
95     response->setErrorCode(200);\r
96     OCRepresentation rep = getRepresentation();\r
97     printf("Found representation is: %s", rep.getPayload()->values->str);\r
98 \r
99     response->setResourceRepresentation(rep, DEFAULT_INTERFACE);\r
100     OCStackResult result = OCPlatform::sendResponse(response);\r
101     if (result != OC_STACK_OK)\r
102     {\r
103         printf("Unable to send response for GET Request");\r
104     }\r
105 }\r
106 \r
107 void UnsupportiveResource::handlePutRequest(QueryParamsMap &queryParamsMap,\r
108         OCRepresentation incomingRepresentation, std::shared_ptr< OCResourceRequest > request,\r
109         std::shared_ptr< OCResourceResponse > response)\r
110 {\r
111     OCRepresentation rep = getRepresentation();\r
112 \r
113     printf("Inside handlePutRequest... ");\r
114     printf("Incoming JSON Representation is: %s", incomingRepresentation.getPayload()->values->str);\r
115     // handle PUT request\r
116     response->setErrorCode(200);\r
117     response->setResourceRepresentation(rep, DEFAULT_INTERFACE);\r
118 \r
119     OCStackResult result = OCPlatform::sendResponse(response);\r
120     if (result != OC_STACK_OK)\r
121     {\r
122         printf("Unable to send response for PUT Request");\r
123     }\r
124 }\r
125 \r
126 void UnsupportiveResource::onResourceServerStarted(bool& isRegisteredForPresence,\r
127         int& presenceInterval)\r
128 {\r
129     printf("Inside onResourceServerStarted... ");\r
130     isRegisteredForPresence = true;\r
131     presenceInterval = PRESENCE_INTERVAL;\r
132 \r
133     // perform additional task\r
134 }\r
135 \r
136 void UnsupportiveResource::handleInitRequest(QueryParamsMap &queryParamsMap,\r
137 std::shared_ptr< OCResourceRequest > request,\r
138 std::shared_ptr< OCResourceResponse > response)\r
139 {\r
140     printf("Inside handleInitRequest... ");\r
141     // handle initialization\r
142     response->setErrorCode(200);\r
143 \r
144     OCStackResult result = OCPlatform::sendResponse(response);\r
145     if (result != OC_STACK_OK)\r
146     {\r
147         printf("Unable to send response for Init Request");\r
148     }\r
149 }\r
150 \r
151 OCRepresentation UnsupportiveResource::getResourceRepresentation(OCRepresentation& resourceRep)\r
152 {\r
153     return resourceRep;\r
154 }\r
155 \r