// OCClient.cpp : Defines the entry point for the console application.
//
+#include "iotivity_config.h"
+
#include <set>
#include <string>
#include <cstdlib>
-#include <pthread.h>
#include <mutex>
#include <condition_variable>
#include "OCPlatform.h"
#include "OCApi.h"
+#if defined(HAVE_PTHREAD_H)
+#include <pthread.h>
+#endif
+#if defined(HAVE_WINDOWS_H)
+#include <windows.h>
+#endif
+
using namespace OC;
struct dereference_compare
std::mutex resourceLock;
static ObserveType OBSERVE_TYPE_TO_USE = ObserveType::Observe;
-//TODO-CA: Since CA CON message support is still in progress, this client uses
-// LowQos messages. This needs to change once Confirmable messages are supported in CA.
-
class Light
{
public:
return ++oc;
}
-void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
+void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& rep,
const int& eCode, const int& sequenceNumber)
{
if(eCode == SUCCESS_RESPONSE)
std::cout << "\tpower: " << mylight.m_power << std::endl;
std::cout << "\tname: " << mylight.m_name << std::endl;
- if(observe_count() > 30)
+ if(observe_count() == 11)
{
std::cout<<"Cancelling Observe..."<<std::endl;
- OCStackResult result = curResource->cancelObserve(OC::QualityOfService::LowQos);
+ OCStackResult result = curResource->cancelObserve(OC::QualityOfService::HighQos);
std::cout << "Cancel result: "<< result << " waiting for confirmation ..." <<std::endl;
}
}
}
-void onPost2(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+void onPost2(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode)
{
- if(eCode == SUCCESS_RESPONSE)
+ if(eCode == SUCCESS_RESPONSE || eCode == OC_STACK_RESOURCE_CHANGED)
{
std::cout << "POST request was successful" << std::endl;
std::cout << std::endl << "ObserveAll is used." << std::endl << std::endl;
sleep(1);
curResource->observe(OBSERVE_TYPE_TO_USE, QueryParamsMap(), &onObserve,
- OC::QualityOfService::LowQos);
+ OC::QualityOfService::HighQos);
}
else
}
}
-void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+void onPost(const HeaderOptions& /*headerOptions*/,
+ const OCRepresentation& rep, const int eCode)
{
- if(eCode == SUCCESS_RESPONSE)
+ if(eCode == SUCCESS_RESPONSE || eCode == OC_STACK_RESOURCE_CHANGED)
{
std::cout << "POST request was successful" << std::endl;
rep2.setValue("state", mylight.m_state);
rep2.setValue("power", mylight.m_power);
sleep(1);
- curResource->post(rep2, QueryParamsMap(), &onPost2, OC::QualityOfService::LowQos);
+ curResource->post(rep2, QueryParamsMap(), &onPost2, OC::QualityOfService::HighQos);
}
else
{
rep.setValue("power", mylight.m_power);
// Invoke resource's post API with rep, query map and the callback parameter
- resource->post(rep, QueryParamsMap(), &onPost, OC::QualityOfService::LowQos);
+ resource->post(rep, QueryParamsMap(), &onPost, OC::QualityOfService::HighQos);
}
}
// callback handler on PUT request
-void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+void onPut(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode)
{
- if(eCode == SUCCESS_RESPONSE)
+ if(eCode == SUCCESS_RESPONSE || eCode == OC_STACK_RESOURCE_CHANGED)
{
std::cout << "PUT request was successful" << std::endl;
rep.setValue("power", mylight.m_power);
// Invoke resource's put API with rep, query map and the callback parameter
- resource->put(rep, QueryParamsMap(), &onPut, OC::QualityOfService::LowQos);
+ resource->put(rep, QueryParamsMap(), &onPut, OC::QualityOfService::HighQos);
}
}
// Callback handler on GET request
-void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+void onGet(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode)
{
if(eCode == SUCCESS_RESPONSE)
{
// Invoke resource's get API with the callback parameter
QueryParamsMap test;
- resource->get(test, &onGet,OC::QualityOfService::LowQos);
+ resource->get(test, &onGet,OC::QualityOfService::HighQos);
}
}
}
catch(std::exception& e)
{
- //log(e.what());
+ std::cerr << "Exception in foundResource: "<< e.what() <<std::endl;
}
}
std::cout << "Usage : simpleclientHQ <ObserveType> <ConnectivityType>" << std::endl;
std::cout << " ObserveType : 1 - Observe" << std::endl;
std::cout << " ObserveType : 2 - ObserveAll" << std::endl;
- std::cout<<" ConnectivityType: Default WIFI" << std::endl;
- std::cout << " ConnectivityType : 0 - ETHERNET"<< std::endl;
- std::cout << " ConnectivityType : 1 - WIFI"<< std::endl;
+ std::cout << " ConnectivityType: Default IP" << std::endl;
+ std::cout << " ConnectivityType : 0 - IP"<< std::endl;
}
int main(int argc, char* argv[]) {
std::ostringstream requestURI;
- OCConnectivityType connectivityType = OC_WIFI;
+ OCConnectivityType connectivityType = CT_ADAPTER_IP;
try
{
if (argc == 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::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;
}
}
}
return -1;
}
}
- catch(std::exception& e)
+ catch(std::exception&)
{
- std::cout << "Invalid input argument. Using WIFI as connectivity type" << std::endl;
+ std::cout << "Invalid input argument." << std::endl;
+ PrintUsage();
+ return -1;
}
OC::ModeType::Client,
"0.0.0.0",
0,
- OC::QualityOfService::LowQos
+ OC::QualityOfService::HighQos
};
OCPlatform::Configure(cfg);
try
{
// Find all resources
- requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
+ requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.light";
OCPlatform::findResource("", requestURI.str(),
connectivityType, &foundResource, OC::QualityOfService::LowQos);