1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 #include "payload_logging.h"
25 bool g_foundResource = true;
27 #define DEFAULT_CONTEXT_VALUE (0x99)
29 OCStackApplicationResult foundResource(void* ctx,
31 OCClientResponse *clientResponse)
35 if (clientResponse == NULL)
37 std::cout << "foundResource received NULL clientResponse" << std::endl;
38 return OC_STACK_DELETE_TRANSACTION;
41 std::cout << "Found resource response." << std::endl;
42 OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
47 g_foundResource = false;
50 return OC_STACK_KEEP_TRANSACTION;
53 OCStackResult findResource(std::string str, OCClientResponseHandler cb)
55 OCCallbackData cbData;
56 cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
59 return OCDoResource(nullptr, OC_REST_DISCOVER,
60 str.c_str(), nullptr, nullptr, CT_DEFAULT,
61 static_cast<OCQualityOfService>(OC_LOW_QOS),
67 bool sendRequest = true;
68 std::cout << "Initializing IoTivity Platform" << std::endl;
69 OCStackResult result = OCInit(NULL, 0, OC_CLIENT_SERVER);
70 if (result != OC_STACK_OK)
72 std::cout << "OCInit Failed" << result << std::endl;
76 std::cout << "Created Platform..." << std::endl;
78 while (g_foundResource)
83 std::cout << "Finding Resource light" << std::endl;
84 if (OC_STACK_OK != findResource("/oic/res?rt=core.light", foundResource))
86 std::cout << "Exception finding resources : " << std::endl;
89 if (OC_STACK_OK != findResource("/oic/res?if=oic.if.baseline", foundResource))
91 std::cout << "Exception finding resources : " << std::endl;
94 if (OC_STACK_OK != findResource("/oic/res", foundResource))
96 std::cout << "Exception finding resources : " << std::endl;