1 //******************************************************************
3 // Copyright 2014 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "OCPlatform.h"
31 namespace PH = std::placeholders;
33 OCResourceHandle resourceHandle;
34 std::vector< OCResourceHandle > resourceHandleVector;
36 static void printUsage()
38 std::cout<<"Usage: groupclient <0|1>\n";
39 std::cout<<"ConnectivityType: Default \n";
40 std::cout<<"ConnectivityType 0: IPv4\n";
41 std::cout<<"ConnectivityType 1: IPv6\n";
43 void foundResource(std::shared_ptr< OCResource > resource)
46 std::string resourceURI;
47 std::string hostAddress;
51 cout << "FOUND RESOURCE" << endl;
55 resourceURI = resource->uri();
56 hostAddress = resource->host();
58 cout << "\tResource URI : " << resourceURI << endl;
59 cout << "\tResource Host : " << hostAddress << endl;
60 cout << "\tResource Interfaces : " << resource->getResourceInterfaces().front() << endl;
61 cout << "\tResource Type : " << resource->getResourceTypes().front() << endl;
62 if (resourceURI == "/a/light" || resourceURI == "/a/fan")
64 OCResourceHandle foundResourceHandle;
65 OCStackResult result = OCPlatform::registerResource(foundResourceHandle, resource);
66 cout << "\tresource registed!" << endl;
67 if (result == OC_STACK_OK)
69 OCPlatform::bindResource(resourceHandle, foundResourceHandle);
70 resourceHandleVector.push_back(foundResourceHandle);
74 cout << "\tresource Error!" << endl;
79 catch (std::exception& e)
81 std::cout << "Exception in foundResource:"<< e.what() << std::endl;
86 int main(int argc, char* argv[])
88 ostringstream requestURI;
90 OCConnectivityType connectivityType = CT_ADAPTER_IP;
96 std::size_t inputValLen;
97 int optionSelected = stoi(argv[1], &inputValLen);
99 if(inputValLen == strlen(argv[1]))
101 if(optionSelected == 0)
103 std::cout << "Using IPv4."<< std::endl;
104 connectivityType = CT_IP_USE_V4;
106 else if(optionSelected == 1)
108 std::cout << "IPv6 is currently not supported."<< std::endl;
111 //TODO: printUsage to be removed when IPv6 is available.
112 //connectivityType = CT_IP_USE_V6;
116 std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
121 std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
126 std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
135 PlatformConfig config
136 { OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
140 string resourceURI = "/core/a/collection";
141 string resourceTypeName = "a.collection";
142 string resourceInterface = BATCH_INTERFACE;
143 OCPlatform::Configure(config);
145 // EntityHandler cb = std::bind(, PH::_1, PH::_2);
147 OCPlatform::registerResource(resourceHandle, resourceURI, resourceTypeName,
150 //&entityHandler, // entityHandler
153 cout << "registerResource is called." << endl;
155 requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.light";
157 OCPlatform::findResource("", requestURI.str(),
158 connectivityType, &foundResource);
160 OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
161 OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
167 cout << endl << "0 :: Quit 1 :: UNREGISTER RESOURCES\n" << endl;
168 std::cin >> selectedMenu;
176 std::cout << "Unregistering resources" << std::endl;
177 for (unsigned int i = 0; i < resourceHandleVector.size(); ++i)
179 OCPlatform::unregisterResource(resourceHandleVector.at(i));
183 cout << "Invalid option" << endl;
188 catch (OCException& e)
190 oclog() << "Exception in main: "<< e.what();