1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 ///This sample demonstrates the device discovery feature
23 ///The client queries for the device related information
24 ///stored by the server.
28 #include <condition_variable>
30 #include "OCPlatform.h"
35 //Callback after device information is received
36 void receivedDeviceInfo(const OCRepresentation& rep)
38 std::cout << "\nDevice Information received ---->\n";
40 std::string contentType;
41 std::string dateOfManufacture;
42 std::string deviceName;
43 std::string deviceUUID;
44 std::string firmwareVersion;
46 std::string manufacturerName;
47 std::string manufacturerUrl;
48 std::string modelNumber;
49 std::string platformVersion;
50 std::string supportUrl;
53 if(rep.getValue("ct", contentType))
55 std::cout << "Content Type: " << contentType << std::endl;
58 if(rep.getValue("mndt", dateOfManufacture))
60 std::cout << "Date of manufacture: " << dateOfManufacture << std::endl;
63 if(rep.getValue("dn", deviceName))
65 std::cout << "Device Name: " << deviceName << std::endl;
68 if(rep.getValue("di", deviceUUID))
70 std::cout << "Device UUID: " << deviceUUID << std::endl;
73 if(rep.getValue("mnfv", firmwareVersion))
75 std::cout << "Firmware Version: " << firmwareVersion << std::endl;
78 if(rep.getValue("hn", hostName))
80 std::cout << "Host Name: " << hostName << std::endl;
83 if(rep.getValue("mnmn", manufacturerName))
85 std::cout << "Manufacturer Name: " << manufacturerName << std::endl;
88 if(rep.getValue("mnml", manufacturerUrl))
90 std::cout << "Manufacturer Url: " << manufacturerUrl << std::endl;
93 if(rep.getValue("mnmo", modelNumber))
95 std::cout << "Model No. : " << modelNumber << std::endl;
98 if(rep.getValue("mnpv", platformVersion))
100 std::cout << "Platform Version: " << platformVersion << std::endl;
103 if(rep.getValue("mnsl", supportUrl))
105 std::cout << "Support URL: " << supportUrl << std::endl;
108 if(rep.getValue("icv", version))
110 std::cout << "Version: " << version << std::endl;
116 // Create PlatformConfig object
118 OC::ServiceType::InProc,
119 OC::ModeType::Client,
122 OC::QualityOfService::LowQos
125 OCPlatform::Configure(cfg);
128 OCPlatform::getDeviceInfo("", "coap://224.0.1.187/oc/core/d", &receivedDeviceInfo);
129 std::cout<< "Querying for device information... " <<std::endl;
131 // A condition variable will free the mutex it is given, then do a non-
132 // intensive block until 'notify' is called on it. In this case, since we
133 // don't ever call cv.notify, this should be a non-processor intensive version
136 std::condition_variable cv;
137 std::unique_lock<std::mutex> lock(blocker);
140 }catch(OCException& e)