IP address plumbing changes to support IPv6
[platform/upstream/iotivity.git] / resource / examples / simpleclientserver.cpp
index 04a9cb1..90b7682 100644 (file)
 #include "OCApi.h"
 using namespace OC;
 
-OCConnectivityType connectivityType = OC_WIFI;
 
 class ClientWorker
 {
 private:
-    bool m_isFoo;
-    int m_barCount;
     void putResourceInfo(const HeaderOptions& headerOptions,
             const OCRepresentation rep, const OCRepresentation rep2, const int eCode)
     {
@@ -144,15 +141,18 @@ private:
     }
 
 public:
+    ClientWorker(OCConnectivityType ct):m_connectivityType{ct}
+    {}
+
     void start()
     {
-        ostringstream requestURI;
-        requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.foo";
+        std::ostringstream requestURI;
+        requestURI << OC_MULTICAST_DISCOVERY_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;
@@ -167,6 +167,9 @@ private:
     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
@@ -275,11 +278,7 @@ 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;
                 }
@@ -297,46 +296,41 @@ struct FooResource
 
 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;
+                    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;
+        std::cout<< "Usage simpleclientserver 0>" << std::endl;
+        std::cout<< "    ConnectivityType: Default IP" << std::endl;
+        std::cout << "   ConnectivityType : 0 - IP" << std::endl;
     }
 
     PlatformConfig cfg {
@@ -358,7 +352,7 @@ int main(int argc, char* argv[])
             return -1;
         }
 
-        ClientWorker cw;
+        ClientWorker cw(connectivityType);
         cw.start();
     }
     catch(OCException& e)
@@ -368,3 +362,4 @@ int main(int argc, char* argv[])
 
     return 0;
 }
+