#include "OCApi.h"
using namespace OC;
-OCConnectivityType connectivityType = OC_WIFI;
+static void printUsage()
+{
+ std::cout<< " Usage simpleclientserver <0|1>" << std::endl;
+ std::cout<< " ConnectivityType: Default IP" << std::endl;
+ std::cout << " ConnectivityType : 0 - IP" << std::endl;
+}
class ClientWorker
{
private:
- bool m_isFoo;
- int m_barCount;
- void putResourceInfo(const HeaderOptions& headerOptions,
- const OCRepresentation rep, const OCRepresentation rep2, const int eCode)
+ void putResourceInfo(const HeaderOptions& /*headerOptions*/,
+ const OCRepresentation rep, const OCRepresentation /*rep2*/, const int eCode)
{
std::cout << "In PutResourceInfo" << std::endl;
std::cout <<"Clientside Put response to get was: "<<std::endl;
std::cout <<"ErrorCode: "<<eCode <<std::endl;
- if(eCode == 0)
+ if(eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
{
std::cout<<"Successful Put. Attributes sent were: "<<std::endl;
}
}
- void getResourceInfo(const HeaderOptions& headerOptions, const OCRepresentation rep,
+ void getResourceInfo(const HeaderOptions& /*headerOptions*/, const OCRepresentation rep,
const int eCode)
{
std::cout << "In getResourceInfo" << std::endl;
}
public:
+ ClientWorker(OCConnectivityType ct):m_connectivityType{ct}
+ {}
+
void start()
{
- ostringstream requestURI;
- requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.foo";
+ std::ostringstream requestURI;
+ requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.foo";
std::cout<<"Starting Client find:"<<std::endl;
FindCallback f (std::bind(&ClientWorker::foundResource, this, std::placeholders::_1));
std::cout<<"result:" <<
- OCPlatform::findResource("", requestURI.str(), connectivityType, f)
+ OCPlatform::findResource("", requestURI.str(), CT_DEFAULT, f)
<< std::endl;
std::cout<<"Finding Resource..."<<std::endl;
std::mutex m_resourceLock;
std::condition_variable m_cv;
std::shared_ptr<OCResource> m_resource;
+ OCConnectivityType m_connectivityType;
+ bool m_isFoo;
+ int m_barCount;
};
struct FooResource
{
std::cout <<"\t\trequestFlag : UNSUPPORTED: ";
- if(request->getRequestHandlerFlag()==RequestHandlerFlag::InitFlag)
- {
- std::cout<<"InitFlag"<<std::endl;
- }
- else if(request->getRequestHandlerFlag()== RequestHandlerFlag::ObserverFlag)
+ if(request->getRequestHandlerFlag()== RequestHandlerFlag::ObserverFlag)
{
std::cout<<"ObserverFlag"<<std::endl;
}
int main(int argc, char* argv[])
{
+ OCConnectivityType connectivityType = CT_ADAPTER_IP;
if(argc == 2)
{
try
{
std::size_t inputValLen;
- int optionSelected = stoi(argv[1], &inputValLen);
+ int optionSelected = std::stoi(argv[1], &inputValLen);
if(inputValLen == strlen(argv[1]))
{
if(optionSelected == 0)
{
- connectivityType = OC_ETHERNET;
- }
- else if(optionSelected == 1)
- {
- connectivityType = OC_WIFI;
+ std::cout << "Using IP."<< std::endl;
+ connectivityType = CT_ADAPTER_IP;
}
else
{
- std::cout << "Invalid connectivity type selected. Using default WIFI"
- << std::endl;
+ std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
}
}
else
{
- std::cout << "Invalid connectivity type selected. Using default WIFI" << std::endl;
+ std::cout << "Invalid connectivity type selected. Using default IP" << std::endl;
}
}
- catch(exception& e)
+ catch(std::exception& )
{
- std::cout << "Invalid input argument. Using WIFI as connectivity type" << std::endl;
+ std::cout << "Invalid input argument. Using IP as connectivity type" << std::endl;
}
}
else
{
- std::cout<< "Usage simpleclientserver <ConnectivityType(0|1)>" << std::endl;
- std::cout<<" ConnectivityType: Default WIFI" << std::endl;
- std::cout << " ConnectivityType : 0 - ETHERNET" << std::endl;
- std::cout << " ConnectivityType : 1 - WIFI" << std::endl;
+ printUsage();
}
PlatformConfig cfg {
return -1;
}
- ClientWorker cw;
+ ClientWorker cw(connectivityType);
cw.start();
}
catch(OCException& e)
return 0;
}
+