CA: Enable Building C++ Samples, remove hardcoded connectivity type
authoromkar <omkar.m.hegde@intel.com>
Fri, 16 Jan 2015 00:31:15 +0000 (16:31 -0800)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Tue, 20 Jan 2015 22:42:52 +0000 (22:42 +0000)
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>
13 files changed:
resource/csdk/stack/include/ocstack.h
resource/examples/SConscript
resource/examples/devicediscoveryclient.cpp
resource/examples/fridgeclient.cpp
resource/examples/garageclient.cpp
resource/examples/groupclient.cpp
resource/examples/groupserver.cpp
resource/examples/presenceclient.cpp
resource/examples/roomclient.cpp
resource/examples/simpleclient.cpp
resource/examples/simpleclientHQ.cpp
resource/examples/simpleclientserver.cpp
resource/examples/threadingsample.cpp

index 6fdfe57..c2c45e8 100644 (file)
@@ -34,10 +34,19 @@ extern "C" {
 
 //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
index 6afdb15..2f0fbfa 100644 (file)
@@ -53,24 +53,34 @@ examples_env.AppendUnique(CPPDEFINES = ['CA_INT'])
 ######################################################################
 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')
 
index 4bc412c..b75eaa3 100644 (file)
@@ -111,8 +111,55 @@ void receivedDeviceInfo(const OCRepresentation& rep)
     }
 }
 
-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,
@@ -125,12 +172,13 @@ int main() {
     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;
 
index 30420b3..7b6bc5e 100644 (file)
@@ -37,20 +37,25 @@ namespace PH = std::placeholders;
 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)
@@ -85,7 +90,6 @@ class ClientFridge
         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
@@ -266,8 +270,52 @@ class ClientFridge
     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,
index 392a501..c9997e6 100644 (file)
@@ -269,6 +269,53 @@ void foundResource(std::shared_ptr<OCResource> resource)
 
 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,
@@ -282,12 +329,13 @@ int main(int argc, char* argv[]) {
     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;
index 4e5e654..b0f743e 100755 (executable)
@@ -121,8 +121,56 @@ void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, con
     }
 }
 
-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 };
 
@@ -134,11 +182,10 @@ int main()
 
         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;
index 4ebb2d6..c6fcb3e 100755 (executable)
@@ -79,8 +79,55 @@ void foundResource(std::shared_ptr< OCResource > resource)
 
 }
 
-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 };
 
@@ -101,12 +148,13 @@ int main()
 
         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);
index aae788c..9390788 100644 (file)
@@ -35,6 +35,10 @@ std::shared_ptr<OCResource> curResource;
 
 static int TEST_CASE = 0;
 
+#ifdef CA_INT
+static OCConnectivityType connectivityType = OC_WIFI;
+#endif
+
 /**
  * List of methods that can be inititated from the client
  */
@@ -50,7 +54,11 @@ typedef enum {
 
 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;
@@ -61,6 +69,11 @@ void printUsage()
               << 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
@@ -132,9 +145,6 @@ void foundResource(std::shared_ptr<OCResource> resource)
                 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)
                 {
@@ -210,20 +220,68 @@ void foundResource(std::shared_ptr<OCResource> resource)
 }
 
 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();
@@ -247,9 +305,6 @@ int main(int argc, char* argv[]) {
 
         OCPlatform::OCPresenceHandle presenceHandle = nullptr;
         OCStackResult result = OC_STACK_OK;
-#ifdef CA_INT
-        OCConnectivityType connectivityType = OC_WIFI;
-#endif
 
         if(TEST_CASE == TEST_MULTICAST_PRESENCE_NORMAL)
         {
@@ -328,12 +383,13 @@ int main(int argc, char* argv[]) {
         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)
             {
index 9c6dd74..596832f 100644 (file)
@@ -219,6 +219,52 @@ void foundResource(std::shared_ptr<OCResource> resource)
 
 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,
@@ -233,11 +279,12 @@ int main(int argc, char* argv[]) {
     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;
 
index 652d5dc..7e95eaa 100644 (file)
@@ -345,32 +345,89 @@ void foundResource(std::shared_ptr<OCResource> resource)
 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,
@@ -386,11 +443,13 @@ int main(int argc, char* argv[]) {
         // 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;
 
@@ -398,10 +457,10 @@ int main(int argc, char* argv[]) {
         // 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)
index 5a3d9e2..f26a919 100644 (file)
@@ -45,6 +45,9 @@ const int SUCCESS_RESPONSE = 0;
 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:
@@ -99,7 +102,7 @@ void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
         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;
         }
@@ -139,7 +142,7 @@ void onPost2(const HeaderOptions& headerOptions, const OCRepresentation& rep, co
             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
@@ -181,7 +184,7 @@ void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, con
         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
     {
@@ -206,7 +209,7 @@ void postLightRepresentation(std::shared_ptr<OCResource> resource)
         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);
     }
 }
 
@@ -250,7 +253,7 @@ void putLightRepresentation(std::shared_ptr<OCResource> resource)
         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);
     }
 }
 
@@ -288,7 +291,7 @@ void getLightRepresentation(std::shared_ptr<OCResource> resource)
         // 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);
     }
 }
 
@@ -366,32 +369,89 @@ void foundResource(std::shared_ptr<OCResource> resource)
 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,
@@ -406,11 +466,13 @@ int main(int argc, char* argv[]) {
     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;
@@ -419,10 +481,10 @@ int main(int argc, char* argv[]) {
         // 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;
index 763af03..22a0dcd 100644 (file)
 #include "OCApi.h"
 using namespace OC;
 
+#ifdef CA_INT
+OCConnectivityType connectivityType = OC_WIFI;
+#endif
+
 class ClientWorker
 {
 private:
@@ -144,16 +148,18 @@ 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
 
@@ -297,8 +303,52 @@ struct FooResource
 
 };
 
-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,
index b092c1a..24e7200 100644 (file)
 #include "OCApi.h"
 using namespace OC;
 
+#ifdef CA_INT
+static OCConnectivityType connectivityType = OC_WIFI;
+#endif
+
+static std::ostringstream requestURI;
 
 struct FooResource
 {
@@ -281,11 +286,10 @@ void client1()
 {
     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
 
@@ -303,13 +307,12 @@ void client2()
 {
     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
 
@@ -342,8 +345,54 @@ void server()
     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,