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 void foundResource(std::shared_ptr< OCResource > resource)
39 std::string resourceURI;
40 std::string hostAddress;
44 cout << "FOUND RESOURCE" << endl;
48 resourceURI = resource->uri();
49 hostAddress = resource->host();
51 cout << "\tResource URI : " << resourceURI << endl;
52 cout << "\tResource Host : " << hostAddress << endl;
53 cout << "\tResource Interfaces : " << resource->getResourceInterfaces().front() << endl;
54 cout << "\tResource Type : " << resource->getResourceTypes().front() << endl;
55 if (resourceURI == "/a/light" || resourceURI == "/a/fan")
57 OCResourceHandle foundResourceHandle;
58 OCStackResult result = OCPlatform::registerResource(foundResourceHandle, resource);
59 cout << "\tresource registed!" << endl;
60 if (result == OC_STACK_OK)
62 OCPlatform::bindResource(resourceHandle, foundResourceHandle);
63 resourceHandleVector.push_back(foundResourceHandle);
67 cout << "\tresource Error!" << endl;
72 catch (std::exception& e)
74 std::cout << "Exception in foundResource:"<< e.what() << std::endl;
79 int main(int argc, char* argv[])
81 ostringstream requestURI;
83 OCConnectivityType connectivityType = CT_DEFAULT;
89 std::size_t inputValLen;
90 int optionSelected = stoi(argv[1], &inputValLen);
92 if(inputValLen == strlen(argv[1]))
94 if(optionSelected == 0)
96 connectivityType = CT_ADAPTER_IP;
100 std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
105 std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
110 std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
115 std::cout<<"Usage: groupclient 0\n";
116 std::cout<<"ConnectivityType: Default \n";
117 std::cout<<"ConnectivityType 0: IP\n";
120 PlatformConfig config
121 { OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
125 string resourceURI = "/core/a/collection";
126 string resourceTypeName = "a.collection";
127 string resourceInterface = BATCH_INTERFACE;
128 OCPlatform::Configure(config);
130 // EntityHandler cb = std::bind(, PH::_1, PH::_2);
132 OCPlatform::registerResource(resourceHandle, resourceURI, resourceTypeName,
135 //&entityHandler, // entityHandler
138 cout << "registerResource is called." << endl;
140 requestURI << OC_MULTICAST_DISCOVERY_URI << "?rt=core.light";
142 OCPlatform::findResource("", requestURI.str(),
143 connectivityType, &foundResource);
145 OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
146 OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
152 cout << endl << "0 :: Quit 1 :: UNREGISTER RESOURCES\n" << endl;
153 std::cin >> selectedMenu;
161 std::cout << "Unregistering resources" << std::endl;
162 for (unsigned int i = 0; i < resourceHandleVector.size(); ++i)
164 OCPlatform::unregisterResource(resourceHandleVector.at(i));
168 cout << "Invalid option" << endl;
173 catch (OCException& e)
175 oclog() << "Exception in main: "<< e.what();