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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 // This contains the Boost MPL defines required for the boost_variant
22 // serialization, so it must go before the boost/program_options
33 #include <boost/program_options.hpp>
35 #include "OCResource.h"
36 #include "OCPlatform.h"
39 #include "utility.hpp"
41 #include "demo_client.hpp"
43 namespace Intel { namespace OCDemo {
45 auto make_description()
46 -> boost::program_options::options_description
51 namespace po = boost::program_options;
53 po::options_description desc("Client options");
56 ("nres", po::value<unsigned long>()->default_value(1), "number of resources to use for testing")
57 ("host_ip", po::value<string>()->default_value("0.0.0.0"), "IP of host")
58 ("host_port", po::value<uint16_t>()->default_value(0), "port of host")
59 ("interface", po::value<string>()->default_value("eth0"), "network interface name")
60 ("uri", po::value<vector<string>>(), "remote resource URI")
66 int exec(const boost::program_options::variables_map& vm)
70 OC::OCPlatform::Configure({
71 OC::ServiceType::InProc, // in-process server
72 OC::ModeType::Client, // client mode
73 vm["host_ip"].as<string>(), // host
74 vm["host_port"].as<uint16_t>(), // port
75 OC::QualityOfService::LowQos
78 vector<string> resource_URIs;
80 if(0 == vm.count("uri"))
82 std::cout << "No URI specified, looking for everything in \"core\".\n";
84 // Find all resources:
85 resource_URIs.push_back("coap://224.0.1.187/oc/core");
87 /* Example of finding specific resources:
88 const auto& nprops = vm["nres"].as<unsigned long>();
90 for(unsigned long instance_number = 1;
91 instance_number <= nprops;
97 uri << "coap://" << vm["host_ip"].as<string>() << "/oc/core?rt=core.light" << '_' << instance_number;
98 resource_URIs.push_back(uri.str()); // ie. "coap://224.0.1.187/oc/core?rt=core.light_1");
104 const vector<string>& input_URIs = vm["uri"].as< vector<string> >();
105 copy(begin(input_URIs), end(input_URIs), back_inserter(resource_URIs));
108 std::cout << "Requesting " << resource_URIs.size() << " URIs:\n";
110 for(const auto& resource_URI : resource_URIs)
111 cout << resource_URI << '\n';
113 Intel::OCDemo::client::resource_handler resources(resource_URIs);
115 // Register callbacks and wait for resources:
116 resources.find_resources();
118 // Allow the client to receive events from the server:
125 }} // namespace Intel::OCDemo