OCResourceHandle resourceHandle;
std::vector< OCResourceHandle > resourceHandleVector;
+static void printUsage()
+{
+ std::cout<<"Usage: groupclient <0|1>\n";
+ std::cout<<"ConnectivityType: Default \n";
+ std::cout<<"ConnectivityType 0: IP\n";
+}
void foundResource(std::shared_ptr< OCResource > resource)
{
cout << "\tResource Type : " << resource->getResourceTypes().front() << endl;
if (resourceURI == "/a/light" || resourceURI == "/a/fan")
{
- OCResourceHandle foundResourceHandle;
+ OCResourceHandle foundResourceHandle = nullptr;
OCStackResult result = OCPlatform::registerResource(foundResourceHandle, resource);
cout << "\tresource registed!" << endl;
if (result == OC_STACK_OK)
cout << "\tresource Error!" << endl;
}
}
-
- // p_platform.bindResource(resourceHandle, foundResourceHandle);
-
}
}
catch (std::exception& e)
{
- std::cout << "" << std::endl;
+ std::cout << "Exception in foundResource:"<< e.what() << std::endl;
}
}
-int main()
+int main(int argc, char* argv[])
{
+ ostringstream requestURI;
+
+ OCConnectivityType connectivityType = CT_ADAPTER_IP;
+
+ if(argc == 2)
+ {
+ try
+ {
+ std::size_t inputValLen;
+ int optionSelected = stoi(argv[1], &inputValLen);
+
+ if(inputValLen == strlen(argv[1]))
+ {
+ if(optionSelected == 0)
+ {
+ std::cout << "Using IP."<< std::endl;
+ connectivityType = CT_ADAPTER_IP;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
+ }
+ }
+ catch(exception&)
+ {
+ std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
+ }
+ }
+ else
+ {
+ printUsage();
+
+ }
+
PlatformConfig config
{ OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
cout << "registerResource is called." << endl;
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource);
+ requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
+
+ OCPlatform::findResource("", requestURI.str(),
+ connectivityType, &foundResource);
+
OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
int selectedMenu;
- while (true)
+ bool isRun = true;
+ while (isRun)
{
+ cout << endl << "0 :: Quit 1 :: UNREGISTER RESOURCES\n" << endl;
std::cin >> selectedMenu;
- if (selectedMenu == 1)
+ switch(selectedMenu)
{
+ case 0:
+ isRun = false;
+ break;
+ case 1:
+ std::cout << "Unregistering resources" << std::endl;
for (unsigned int i = 0; i < resourceHandleVector.size(); ++i)
{
OCPlatform::unregisterResource(resourceHandleVector.at(i));
}
+ break;
+ default:
+ cout << "Invalid option" << endl;
}
}
}
catch (OCException& e)
{
-
+ oclog() << "Exception in main: "<< e.what();
}
return 0;
}
+