Modifying the C++ examples SConscript to build samples.
Modifying C++ samples to remove hard coded Connectivity Type.
Instead, accepting it as command line argument from the user.
Remove hard coded Multicast URl. Instead, added URLs for CA
in ocstack.h .
Change-Id: If7c16ae75ec9aa492f4d523cf382eb0f9930c417
Signed-off-by: omkar <omkar.m.hegde@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/148
Reviewed-by: Sashi Penta <sashi.kumar.penta@intel.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
//TODO: May want to refactor this in upcoming sprints.
//Don't want to expose to application layer that lower level stack is using CoAP.
+
+#ifdef CA_INT
+#define OC_WELL_KNOWN_QUERY "224.0.1.187:5298/oc/core"
+#define OC_EXPLICIT_DEVICE_DISCOVERY_URI "224.0.1.187:5298/oc/core/d?rt=core.led"
+#define OC_MULTICAST_PREFIX "224.0.1.187:5298"
+#define OC_MULTICAST_IP "224.0.1.187"
+
+#else
#define OC_WELL_KNOWN_QUERY "coap://224.0.1.187:5683/oc/core"
-#define OC_EXPLICIT_DEVICE_DISCOVERY_URI "coap://224.0.1.187:5683/oc/core?rt=core.led"
+#define OC_EXPLICIT_DEVICE_DISCOVERY_URI "coap://224.0.1.187:5683/oc/core/d?rt=core.led"
#define OC_MULTICAST_PREFIX "coap://224.0.1.187:5683"
#define OC_MULTICAST_IP "coap://224.0.1.187"
+#endif
#define USE_RANDOM_PORT (0)
#ifdef WITH_PRESENCE
######################################################################
simpleserver = examples_env.Program('simpleserver', 'simpleserver.cpp')
simpleclient = examples_env.Program('simpleclient', 'simpleclient.cpp')
-#simpleserverHQ = examples_env.Program('simpleserverHQ', 'simpleserverHQ.cpp')
-#simpleclientHQ = examples_env.Program('simpleclientHQ', 'simpleclientHQ.cpp')
-#fridgeserver = examples_env.Program('fridgeserver', 'fridgeserver.cpp')
-#fridgeclient = examples_env.Program('fridgeclient', 'fridgeclient.cpp')
+simpleserverHQ = examples_env.Program('simpleserverHQ', 'simpleserverHQ.cpp')
+simpleclientHQ = examples_env.Program('simpleclientHQ', 'simpleclientHQ.cpp')
+fridgeserver = examples_env.Program('fridgeserver', 'fridgeserver.cpp')
+fridgeclient = examples_env.Program('fridgeclient', 'fridgeclient.cpp')
presenceserver = examples_env.Program('presenceserver', 'presenceserver.cpp')
presenceclient = examples_env.Program('presenceclient', 'presenceclient.cpp')
-#simpleclientserver = examples_env.Program('simpleclientserver', 'simpleclientserver.cpp')
-#roomserver = examples_env.Program('roomserver', 'roomserver.cpp')
-#roomclient = examples_env.Program('roomclient', 'roomclient.cpp')
-#garageserver = examples_env.Program('garageserver', 'garageserver.cpp')
-#garageclient = examples_env.Program('garageclient', 'garageclient.cpp')
+simpleclientserver = examples_env.Program('simpleclientserver', 'simpleclientserver.cpp')
+roomserver = examples_env.Program('roomserver', 'roomserver.cpp')
+roomclient = examples_env.Program('roomclient', 'roomclient.cpp')
+garageserver = examples_env.Program('garageserver', 'garageserver.cpp')
+garageclient = examples_env.Program('garageclient', 'garageclient.cpp')
+groupserver = examples_env.Program('groupserver', 'groupserver.cpp')
+groupclient = examples_env.Program('groupclient', 'groupclient.cpp')
+lightserver = examples_env.Program('lightserver', 'lightserver.cpp')
+devicediscoveryserver = examples_env.Program('devicediscoveryserver', 'devicediscoveryserver.cpp')
+devicediscoveryclient = examples_env.Program('devicediscoveryclient', 'devicediscoveryclient.cpp')
+threadingsample = examples_env.Program('threadingsample', 'threadingsample.cpp')
Alias("examples", [simpleserver, simpleclient,
- #simpleserverHQ, simpleclientHQ,
- #fridgeserver, fridgeclient,
+ simpleserverHQ, simpleclientHQ,
+ fridgeserver, fridgeclient,
presenceserver, presenceclient,
- #simpleclientserver, roomserver, roomclient, garageserver,
- #garageclient
+ simpleclientserver, roomserver, roomclient, garageserver,
+ garageclient,
+ groupserver, groupclient,
+ lightserver,
+ devicediscoveryserver, devicediscoveryclient,
+ threadingsample
])
env.AppendTarget('examples')
}
}
-int main() {
+int main(int argc, char* argv[]) {
+ ostringstream requestURI;
+ std::string deviceDiscoveryURI = "/oc/core/d";
+
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+
+ if(argc == 2)
+ {
+ try
+ {
+ std::size_t inputValLen;
+ int optionSelected = stoi(argv[1], &inputValLen);
+
+ if(inputValLen == strlen(argv[1]))
+ {
+ if(optionSelected == 0)
+ {
+ connectivityType = OC_ETHERNET;
+ }
+ else if(optionSelected == 1)
+ {
+ connectivityType = OC_WIFI;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI" << std::endl;
+ }
+ }
+ catch(exception& e)
+ {
+ std::cout << "Invalid input argument. Using WIFI as connectivity type" << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Usage devicediscoveryclient <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;
+ }
+#endif
// Create PlatformConfig object
PlatformConfig cfg {
OC::ServiceType::InProc,
OCPlatform::Configure(cfg);
try
{
+ requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
+
#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
- OCPlatform::getDeviceInfo("", "coap://224.0.1.187/oc/core/d", connectivityType,
- &receivedDeviceInfo);
+ OCPlatform::getDeviceInfo("", requestURI.str(), connectivityType,
+ &receivedDeviceInfo);
#else
- OCPlatform::getDeviceInfo("", "coap://224.0.1.187/oc/core/d", &receivedDeviceInfo);
+ OCPlatform::getDeviceInfo("", requestURI.str(), &receivedDeviceInfo);
#endif
std::cout<< "Querying for device information... " <<std::endl;
const uint16_t API_VERSION = 2048;
const uint16_t TOKEN = 3000;
+#ifdef CA_INT
+static OCConnectivityType connectivityType = OC_WIFI;
+#endif
+
class ClientFridge
{
public:
ClientFridge()
{
+ ostringstream requestURI;
+ requestURI << OC_WELL_KNOWN_QUERY << "?rt=intel.fridge";
std::cout << "Fridge Client has started " <<std::endl;
FindCallback f (std::bind(&ClientFridge::foundDevice, this, PH::_1));
#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
OCStackResult result = OCPlatform::findResource(
- "", "coap://224.0.1.187/oc/core?rt=intel.fridge", connectivityType, f);
+ "", requestURI.str(), connectivityType, f);
#else
OCStackResult result = OCPlatform::findResource(
- "", "coap://224.0.1.187/oc/core?rt=intel.fridge", f);
+ "", requestURI.str(), f);
#endif
if(OC_STACK_OK != result)
std::vector<std::string> lightTypes = {"intel.fridge.light"};
std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
OCResource::Ptr light = constructResourceObject(resource->host(),
"/light", connectivityType, false, lightTypes, ifaces);
#else
std::condition_variable m_cv;
};
-int main()
+int main(int argc, char* argv[])
{
+
+#ifdef CA_INT
+ if(argc == 2)
+ {
+ try
+ {
+ std::size_t inputValLen;
+ int optionSelected = stoi(argv[1], &inputValLen);
+
+ if(inputValLen == strlen(argv[1]))
+ {
+ if(optionSelected == 0)
+ {
+ connectivityType = OC_ETHERNET;
+ }
+ else if(optionSelected == 1)
+ {
+ connectivityType = OC_WIFI;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI" << std::endl;
+ }
+ }
+ catch(exception& e)
+ {
+ std::cout << "Invalid input argument. Using WIFI as connectivity type" << std::endl;
+ }
+ }
+ else
+ {
+ std::cout<<"Usage: fridgeclient <ConnectivityType(0|1)>\n";
+ std::cout<<"ConnectivityType: Default WIFI\n";
+ std::cout<<"ConnectivityType 0: ETHERNET\n";
+ std::cout<<"ConnectivityType 1: WIFI\n";
+ }
+#endif
+
PlatformConfig cfg
{
ServiceType::InProc,
int main(int argc, char* argv[]) {
+ostringstream requestURI;
+
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+
+ if(argc == 2)
+ {
+ try
+ {
+ std::size_t inputValLen;
+ int optionSelected = stoi(argv[1], &inputValLen);
+
+ if(inputValLen == strlen(argv[1]))
+ {
+ if(optionSelected == 0)
+ {
+ connectivityType = OC_ETHERNET;
+ }
+ else if(optionSelected == 1)
+ {
+ connectivityType = OC_WIFI;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI" << std::endl;
+ }
+ }
+ catch(exception& e)
+ {
+ std::cout << "Invalid input argument. Using WIFI as connectivity type" << std::endl;
+ }
+ }
+ else
+ {
+ std::cout<<"Usage: garageclient <ConnectivityType(0|1)>\n";
+ std::cout<<"ConnectivityType: Default WIFI\n";
+ std::cout<<"ConnectivityType 0: ETHERNET\n";
+ std::cout<<"ConnectivityType 1: WIFI\n";
+ }
+#endif
+
// Create PlatformConfig object
PlatformConfig cfg {
OC::ServiceType::InProc,
try
{
// Find all resources
+ requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.garage";
+
#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.garage",
- connectivityType, &foundResource);
+ OCPlatform::findResource("", requestURI.str(),
+ connectivityType, &foundResource);
#else
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.garage",
+ OCPlatform::findResource("", requestURI.str(),
&foundResource);
#endif
std::cout<< "Finding Resource... " <<std::endl;
}
}
-int main()
+int main(int argc, char* argv[])
{
+ ostringstream requestURI;
+ requestURI << OC_WELL_KNOWN_QUERY << "?rt=a.collection";
+
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+
+ if(argc == 2)
+ {
+ try
+ {
+ std::size_t inputValLen;
+ int optionSelected = stoi(argv[1], &inputValLen);
+
+ if(inputValLen == strlen(argv[1]))
+ {
+ if(optionSelected == 0)
+ {
+ connectivityType = OC_ETHERNET;
+ }
+ else if(optionSelected == 1)
+ {
+ connectivityType = OC_WIFI;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI" << std::endl;
+ }
+ }
+ catch(exception& e)
+ {
+ std::cout << "Invalid input argument. Using WIFI as connectivity type" << std::endl;
+ }
+ }
+ else
+ {
+ std::cout<<"Usage: groupclient <ConnectivityType(0|1)>\n";
+ std::cout<<"ConnectivityType: Default WIFI\n";
+ std::cout<<"ConnectivityType 0: ETHERNET\n";
+ std::cout<<"ConnectivityType 1: WIFI\n";
+ }
+#endif
+
PlatformConfig config
{ OC::ServiceType::InProc, ModeType::Client, "0.0.0.0", 0, OC::QualityOfService::LowQos };
string resourceTypeName = "a.collection";
#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=a.collection",
+ OCPlatform::findResource("", requestURI.str(),
connectivityType, &foundResource);
#else
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=a.collection", &foundResource);
+ OCPlatform::findResource("", requestURI.str(), &foundResource);
#endif
isReady = false;
}
-int main()
+int main(int argc, char* argv[])
{
+ ostringstream requestURI;
+
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+
+ if(argc == 2)
+ {
+ try
+ {
+ std::size_t inputValLen;
+ int optionSelected = stoi(argv[1], &inputValLen);
+
+ if(inputValLen == strlen(argv[1]))
+ {
+ if(optionSelected == 0)
+ {
+ connectivityType = OC_ETHERNET;
+ }
+ else if(optionSelected == 1)
+ {
+ connectivityType = OC_WIFI;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI" << std::endl;
+ }
+ }
+ catch(exception& e)
+ {
+ std::cout << "Invalid input argument. Using WIFI as connectivity type" << std::endl;
+ }
+ }
+ else
+ {
+ std::cout<<"Usage: groupclient <ConnectivityType(0|1)>\n";
+ std::cout<<"ConnectivityType: Default WIFI\n";
+ std::cout<<"ConnectivityType 0: ETHERNET\n";
+ std::cout<<"ConnectivityType 1: WIFI\n";
+ }
+#endif
+
PlatformConfig config
{ OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
cout << "registerResource is called." << endl;
+ requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
+
#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light",
+ OCPlatform::findResource("", requestURI.str(),
connectivityType, &foundResource);
#else
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource);
+ OCPlatform::findResource("", requestURI.str(), &foundResource);
#endif
OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
static int TEST_CASE = 0;
+#ifdef CA_INT
+static OCConnectivityType connectivityType = OC_WIFI;
+#endif
+
/**
* List of methods that can be inititated from the client
*/
void printUsage()
{
+#ifdef CA_INT
+ std::cout << "Usage : presenceclient -t <1|2> -c <0|1>" << std::endl;
+#else
std::cout << "Usage : presenceclient -t <1|2>" << std::endl;
+#endif
std::cout << "-t 1 : Discover Resources and Initiate Unicast Presence" << std::endl;
std::cout << "-t 2 : Discover Resources and Initiate Unicast Presence with Filter"
<< std::endl;
<< std::endl;
std::cout << "-t 6 : Discover Resources and Initiate Multicast Presence with two Filters"
<< std::endl;
+#ifdef CA_INT
+ std::cout<<"ConnectivityType: Default WIFI" << std::endl;
+ std::cout << "-c 0 : Send message over ETHERNET interface" << std::endl;
+ std::cout << "-c 1 : Send message over WIFI interface" << std::endl;
+#endif
}
// Callback to presence
OCStackResult result = OC_STACK_OK;
curResource = resource;
OCPlatform::OCPresenceHandle presenceHandle = nullptr;
-#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
-#endif
if(TEST_CASE == TEST_UNICAST_PRESENCE_NORMAL)
{
}
int main(int argc, char* argv[]) {
+
+ ostringstream requestURI;
+
int opt;
- while ((opt = getopt(argc, argv, "t:")) != -1)
+#ifdef CA_INT
+ int optionSelected;
+#endif
+
+ try
{
- switch(opt)
+#ifdef CA_INT
+ while ((opt = getopt(argc, argv, "t:c:")) != -1)
+ #else
+ while ((opt = getopt(argc, argv, "t:")) != -1)
+ #endif
{
- case 't':
- TEST_CASE = atoi(optarg);
- break;
- default:
- printUsage();
- return -1;
+ switch(opt)
+ {
+ case 't':
+ TEST_CASE = stoi(optarg);
+ break;
+#ifdef CA_INT
+ case 'c':
+ std::size_t inputValLen;
+ optionSelected = stoi(optarg, &inputValLen);
+
+ if(inputValLen == strlen(optarg))
+ {
+ if(optionSelected == 0)
+ {
+ connectivityType = OC_ETHERNET;
+ }
+ else if(optionSelected == 1)
+ {
+ connectivityType = OC_WIFI;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ break;
+#endif
+ default:
+ printUsage();
+ return -1;
+ }
}
}
+ catch(exception& e)
+ {
+ std::cout << "Invalid input argument. Using WIFI as connectivity type"
+ << std::endl;
+ }
+
if(TEST_CASE >= MAX_TESTS || TEST_CASE <= 0)
{
printUsage();
OCPlatform::OCPresenceHandle presenceHandle = nullptr;
OCStackResult result = OC_STACK_OK;
-#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
-#endif
if(TEST_CASE == TEST_MULTICAST_PRESENCE_NORMAL)
{
else
{
// Find all resources
+ requestURI << OC_WELL_KNOWN_QUERY;
+
#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
- result = OCPlatform::findResource("", "coap://224.0.1.187:5298/oc/core",
- connectivityType, &foundResource);
+ result = OCPlatform::findResource("", requestURI.str(),
+ connectivityType, &foundResource);
#else
- result = OCPlatform::findResource("", "coap://224.0.1.187/oc/core", &foundResource);
+ result = OCPlatform::findResource("", requestURI.str(), &foundResource);
#endif
if(result == OC_STACK_OK)
{
int main(int argc, char* argv[]) {
+ ostringstream requestURI;
+
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+ if(argc == 2)
+ {
+ try
+ {
+ std::size_t inputValLen;
+ int optionSelected = stoi(argv[1], &inputValLen);
+
+ if(inputValLen == strlen(argv[1]))
+ {
+ if(optionSelected == 0)
+ {
+ connectivityType = OC_ETHERNET;
+ }
+ else if(optionSelected == 1)
+ {
+ connectivityType = OC_WIFI;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI" << std::endl;
+ }
+ }
+ catch(exception& e)
+ {
+ std::cout << "Invalid input argument. Using WIFI as connectivity type" << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Usage roomclient <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;
+ }
+#endif
+
// Create PlatformConfig object
PlatformConfig cfg {
OC::ServiceType::InProc,
try
{
// Find all resources
+ requestURI << OC_WELL_KNOWN_QUERY;
#ifdef CA_INT
- OCPlatform::findResource("", "coap://224.0.1.187:5298/oc/core", &foundResource);
+ OCPlatform::findResource("", requestURI.str(), connectivityType, &foundResource);
#else
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core", &foundResource);
+ OCPlatform::findResource("", requestURI.str(), &foundResource);
#endif
std::cout<< "Finding Resource... " <<std::endl;
void PrintUsage()
{
std::cout << std::endl;
+#ifdef CA_INT
+ std::cout << "Usage : simpleclient <ObserveType> <ConnectivityType>" << std::endl;
+#else
std::cout << "Usage : simpleclient <ObserveType>" << std::endl;
+#endif
std::cout << " ObserveType : 1 - Observe" << std::endl;
std::cout << " ObserveType : 2 - ObserveAll" << std::endl;
+#ifdef CA_INT
+ std::cout<<" connectivityType: Default WIFI" << std::endl;
+ std::cout << " ConnectivityType : 0 - ETHERNET"<< std::endl;
+ std::cout << " ConnectivityType : 1 - WIFI"<< std::endl;
+#endif
}
int main(int argc, char* argv[]) {
- if (argc == 1)
- {
- OBSERVE_TYPE_TO_USE = ObserveType::Observe;
- }
- else if (argc == 2)
+
+ ostringstream requestURI;
+
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+#endif
+ try
{
- int value = atoi(argv[1]);
- if (value == 1)
+ if (argc == 1)
+ {
OBSERVE_TYPE_TO_USE = ObserveType::Observe;
- else if (value == 2)
- OBSERVE_TYPE_TO_USE = ObserveType::ObserveAll;
+ }
+#ifdef CA_INT
+ else if (argc >= 2)
+#else
+ else if (argc == 2)
+#endif
+ {
+ int value = stoi(argv[1]);
+ if (value == 1)
+ OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+ else if (value == 2)
+ OBSERVE_TYPE_TO_USE = ObserveType::ObserveAll;
+ else
+ OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+
+#ifdef CA_INT
+ if(argc == 3)
+ {
+ std::size_t inputValLen;
+ int optionSelected = stoi(argv[2], &inputValLen);
+
+ if(inputValLen == strlen(argv[2]))
+ {
+ if(optionSelected == 0)
+ {
+ connectivityType = OC_ETHERNET;
+ }
+ else if(optionSelected == 1)
+ {
+ connectivityType = OC_WIFI;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ }
+#endif
else
- OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+ {
+ PrintUsage();
+ return -1;
+ }
}
- else
+ catch(exception& e)
{
- PrintUsage();
- return -1;
+ std::cout << "Invalid input argument. Using WIFI as connectivity type" << std::endl;
}
+
// Create PlatformConfig object
PlatformConfig cfg {
OC::ServiceType::InProc,
// makes it so that all boolean values are printed as 'true/false' in this stream
std::cout.setf(std::ios::boolalpha);
// Find all resources
+ requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
+
#ifdef CA_INT
- OCPlatform::findResource("", "coap://224.0.1.187:5298/oc/core?rt=core.light",
- OC_WIFI, &foundResource);
+ OCPlatform::findResource("", requestURI.str(),
+ connectivityType, &foundResource);
#else
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource);
+ OCPlatform::findResource("", requestURI.str(), &foundResource);
#endif
std::cout<< "Finding Resource... " <<std::endl;
// These resources will have the same uniqueidentifier (yet be different objects), so that
// we can verify/show the duplicate-checking code in foundResource(above);
#ifdef CA_INT
- OCPlatform::findResource("", "coap://224.0.1.187:5298/oc/core?rt=core.light",
- OC_ETHERNET, &foundResource);
+ OCPlatform::findResource("", requestURI.str(),
+ connectivityType, &foundResource);
#else
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource);
+ OCPlatform::findResource("", requestURI.str(), &foundResource);
#endif
std::cout<< "Finding Resource for second time... " <<std::endl;
while(true)
std::shared_ptr<OCResource> curResource;
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:
if(observe_count() > 30)
{
std::cout<<"Cancelling Observe..."<<std::endl;
- OCStackResult result = curResource->cancelObserve(OC::QualityOfService::HighQos);
+ OCStackResult result = curResource->cancelObserve(OC::QualityOfService::LowQos);
std::cout << "Cancel result: "<< result << " waiting for confirmation ..." <<std::endl;
}
std::cout << endl << "ObserveAll is used." << endl << endl;
sleep(1);
curResource->observe(OBSERVE_TYPE_TO_USE, QueryParamsMap(), &onObserve,
- OC::QualityOfService::HighQos);
+ OC::QualityOfService::LowQos);
}
else
rep2.setValue("state", mylight.m_state);
rep2.setValue("power", mylight.m_power);
sleep(1);
- curResource->post(rep2, QueryParamsMap(), &onPost2, OC::QualityOfService::HighQos);
+ curResource->post(rep2, QueryParamsMap(), &onPost2, OC::QualityOfService::LowQos);
}
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::HighQos);
+ resource->post(rep, QueryParamsMap(), &onPost, OC::QualityOfService::LowQos);
}
}
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::HighQos);
+ resource->put(rep, QueryParamsMap(), &onPut, OC::QualityOfService::LowQos);
}
}
// Invoke resource's get API with the callback parameter
QueryParamsMap test;
- resource->get(test, &onGet,OC::QualityOfService::HighQos);
+ resource->get(test, &onGet,OC::QualityOfService::LowQos);
}
}
void PrintUsage()
{
std::cout << std::endl;
- std::cout << "Usage : simpleclient <ObserveType>" << std::endl;
+#ifdef CA_INT
+ std::cout << "Usage : simpleclientHQ <ObserveType> <ConnectivityType>" << std::endl;
+#else
+ std::cout << "Usage : simpleclientHQ <ObserveType>" << std::endl;
+#endif
std::cout << " ObserveType : 1 - Observe" << std::endl;
std::cout << " ObserveType : 2 - ObserveAll" << std::endl;
+#ifdef CA_INT
+ std::cout<<" ConnectivityType: Default WIFI" << std::endl;
+ std::cout << " ConnectivityType : 0 - ETHERNET"<< std::endl;
+ std::cout << " ConnectivityType : 1 - WIFI"<< std::endl;
+#endif
}
int main(int argc, char* argv[]) {
- if (argc == 1)
- {
- OBSERVE_TYPE_TO_USE = ObserveType::Observe;
- }
- else if (argc == 2)
+
+ ostringstream requestURI;
+
+#ifdef CA_INT
+ OCConnectivityType connectivityType = OC_WIFI;
+#endif
+ try
{
- int value = atoi(argv[1]);
- if (value == 1)
+ if (argc == 1)
+ {
OBSERVE_TYPE_TO_USE = ObserveType::Observe;
- else if (value == 2)
- OBSERVE_TYPE_TO_USE = ObserveType::ObserveAll;
+ }
+#ifdef CA_INT
+ else if (argc >= 2)
+#else
+ else if (argc == 2)
+#endif
+ {
+ int value = stoi(argv[1]);
+ if (value == 1)
+ OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+ else if (value == 2)
+ OBSERVE_TYPE_TO_USE = ObserveType::ObserveAll;
+ else
+ OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+
+#ifdef CA_INT
+ if(argc == 3)
+ {
+ std::size_t inputValLen;
+ int optionSelected = stoi(argv[2], &inputValLen);
+
+ if(inputValLen == strlen(argv[2]))
+ {
+ if(optionSelected == 0)
+ {
+ connectivityType = OC_ETHERNET;
+ }
+ else if(optionSelected == 1)
+ {
+ connectivityType = OC_WIFI;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+#endif
+ }
else
- OBSERVE_TYPE_TO_USE = ObserveType::Observe;
+ {
+ PrintUsage();
+ return -1;
+ }
}
- else
+ catch(exception& e)
{
- PrintUsage();
- return -1;
+ std::cout << "Invalid input argument. Using WIFI as connectivity type" << std::endl;
}
+
// Create PlatformConfig object
PlatformConfig cfg {
OC::ServiceType::InProc,
try
{
// Find all resources
+ requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
+
#ifdef CA_INT
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light",
- OC_WIFI, &foundResource, OC::QualityOfService::LowQos);
+ OCPlatform::findResource("", requestURI.str(),
+ connectivityType, &foundResource, OC::QualityOfService::LowQos);
#else
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource,
+ OCPlatform::findResource("", requestURI.str(), &foundResource,
OC::QualityOfService::LowQos);
#endif
std::cout<< "Finding Resource... " <<std::endl;
// These resources will have the same uniqueidentifier (yet be different objects), so that
// we can verify/show the duplicate-checking code in foundResource(above);
#ifdef CA_INT
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light",
- OC_WIFI, &foundResource, OC::QualityOfService::LowQos);
+ OCPlatform::findResource("", requestURI.str(),
+ connectivityType, &foundResource, OC::QualityOfService::LowQos);
#else
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource,
+ OCPlatform::findResource("", requestURI.str(), &foundResource,
OC::QualityOfService::LowQos);
#endif
std::cout<< "Finding Resource for second time... " <<std::endl;
#include "OCApi.h"
using namespace OC;
+#ifdef CA_INT
+OCConnectivityType connectivityType = OC_WIFI;
+#endif
+
class ClientWorker
{
private:
public:
void start()
{
+ ostringstream requestURI;
+ requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.foo";
+
std::cout<<"Starting Client find:"<<std::endl;
FindCallback f (std::bind(&ClientWorker::foundResource, this, std::placeholders::_1));
#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
std::cout<<"result:" <<
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo", connectivityType, f)
+ OCPlatform::findResource("", requestURI.str(), connectivityType, f)
<< std::endl;
#else
std::cout<<"result:" <<
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo", f)
+ OCPlatform::findResource("", requestURI.str(), f)
<< std::endl;
#endif
};
-int main()
+int main(int argc, char* argv[])
{
+
+#ifdef CA_INT
+ if(argc == 2)
+ {
+ try
+ {
+ std::size_t inputValLen;
+ int optionSelected = stoi(argv[1], &inputValLen);
+
+ if(inputValLen == strlen(argv[1]))
+ {
+ if(optionSelected == 0)
+ {
+ connectivityType = OC_ETHERNET;
+ }
+ else if(optionSelected == 1)
+ {
+ connectivityType = OC_WIFI;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI" << std::endl;
+ }
+ }
+ catch(exception& e)
+ {
+ std::cout << "Invalid input argument. Using WIFI 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;
+ }
+#endif
+
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Both,
#include "OCApi.h"
using namespace OC;
+#ifdef CA_INT
+static OCConnectivityType connectivityType = OC_WIFI;
+#endif
+
+static std::ostringstream requestURI;
struct FooResource
{
{
std::cout << "in client1\n";
#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
- std::cout<<"result1:" << OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo",
+ std::cout<<"result1:" << OCPlatform::findResource("", requestURI.str(),
connectivityType, foundResource1)<< std::endl;
#else
- std::cout<<"result1:" << OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo",
+ std::cout<<"result1:" << OCPlatform::findResource("", requestURI.str(),
foundResource1)<< std::endl;
#endif
{
std::cout << "in client2\n";
#ifdef CA_INT
- OCConnectivityType connectivityType = OC_WIFI;
std::cout<<"result2:" << OCPlatform::findResource("",
- "coap://224.0.1.187/oc/core?rt=core.foo",
+ requestURI.str(),
connectivityType, foundResource2)<< std::endl;
#else
std::cout<<"result2:" << OCPlatform::findResource("",
- "coap://224.0.1.187/oc/core?rt=core.foo",
+ requestURI.str(),
foundResource2)<< std::endl;
#endif
cv.wait(lock);
}
-int main()
+int main(int argc, char* argv[])
{
+
+#ifdef CA_INT
+ if(argc == 2)
+ {
+ try
+ {
+ std::size_t inputValLen;
+ int optionSelected = stoi(argv[1], &inputValLen);
+
+ if(inputValLen == strlen(argv[1]))
+ {
+ if(optionSelected == 0)
+ {
+ connectivityType = OC_ETHERNET;
+ }
+ else if(optionSelected == 1)
+ {
+ connectivityType = OC_WIFI;
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI"
+ << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Invalid connectivity type selected. Using default WIFI" << std::endl;
+ }
+ }
+ catch(exception& e)
+ {
+ std::cout << "Invalid input argument. Using WIFI as connectivity type" << std::endl;
+ }
+ }
+ else
+ {
+ std::cout<< "Usage threadingsample <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;
+ }
+#endif
+
+ requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.foo";
+
PlatformConfig cfg {
OC::ServiceType::InProc,
OC::ModeType::Both,