replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / examples / presenceclient.cpp
index ef52004..72b672a 100644 (file)
@@ -25,7 +25,7 @@
 #include <pthread.h>
 #include <mutex>
 #include <condition_variable>
-
+#include <getopt.h>
 #include "OCPlatform.h"
 #include "OCApi.h"
 
@@ -33,10 +33,9 @@ using namespace OC;
 
 std::shared_ptr<OCResource> curResource;
 std::mutex resourceLock;
-
 static int TEST_CASE = 0;
 
-static OCConnectivityType connectivityType = OC_WIFI;
+static OCConnectivityType connectivityType = CT_ADAPTER_IP;
 
 /**
  * List of methods that can be inititated from the client
@@ -58,15 +57,14 @@ void printUsage()
     std::cout << "-t 2 : Discover Resources and Initiate Unicast Presence with Filter"
               << std::endl;
     std::cout << "-t 3 : Discover Resources and Initiate Unicast Presence with Two Filters"
-            << std::endl;
+              << std::endl;
     std::cout << "-t 4 : Discover Resources and Initiate Multicast Presence" << std::endl;
     std::cout << "-t 5 : Discover Resources and Initiate Multicast Presence with Filter"
               << std::endl;
     std::cout << "-t 6 : Discover Resources and Initiate Multicast Presence with two Filters"
-                  << std::endl;
-    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;
+            << std::endl;
+    std::cout<<"ConnectivityType: Default IP" << std::endl;
+    std::cout << "-c 0 : Send message with IP" << std::endl;
 }
 
 // Callback to presence
@@ -192,6 +190,7 @@ void foundResource(std::shared_ptr<OCResource> resource)
     }
     catch(std::exception& e)
     {
+        std::cerr << "Exception in foundResource: "<< e.what() << std::endl;
         //log(e.what());
     }
 }
@@ -221,21 +220,18 @@ int main(int argc, char* argv[]) {
                     {
                         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::cout << "Invalid connectivity type selected. Using default IP"
                             << std::endl;
                     }
                     break;
@@ -245,9 +241,9 @@ int main(int argc, char* argv[]) {
             }
         }
     }
-    catch(std::exception& e)
+    catch(std::exception& )
     {
-        std::cout << "Invalid input argument. Using WIFI as connectivity type"
+        std::cout << "Invalid input argument. Using IP as connectivity type"
             << std::endl;
     }
 
@@ -278,7 +274,9 @@ int main(int argc, char* argv[]) {
         if(TEST_CASE == TEST_MULTICAST_PRESENCE_NORMAL)
         {
             result = OCPlatform::subscribePresence(presenceHandle,
-                    OC_MULTICAST_IP, connectivityType, presenceHandler);
+                                                   "",
+                                                   connectivityType,
+                                                   presenceHandler);
 
             if(result == OC_STACK_OK)
             {
@@ -291,8 +289,10 @@ int main(int argc, char* argv[]) {
         }
         else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTER)
         {
-            result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
-                    connectivityType, &presenceHandler);
+            result = OCPlatform::subscribePresence(presenceHandle,
+                                                   "", "core.light",
+                                                   connectivityType,
+                                                   &presenceHandler);
             if(result == OC_STACK_OK)
             {
                 std::cout << "Subscribed to multicast presence with resource type";
@@ -305,8 +305,10 @@ int main(int argc, char* argv[]) {
         }
         else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTERS)
         {
-            result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
-                    connectivityType, &presenceHandler);
+            result = OCPlatform::subscribePresence(presenceHandle,
+                                                   "", "core.light",
+                                                   connectivityType,
+                                                   &presenceHandler);
             if(result == OC_STACK_OK)
             {
                 std::cout << "Subscribed to multicast presence with resource type";
@@ -317,8 +319,10 @@ int main(int argc, char* argv[]) {
             }
             std::cout << "\"core.light\"." << std::endl;
 
-            result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.fan",
-                    connectivityType, &presenceHandler);
+            result = OCPlatform::subscribePresence(presenceHandle,
+                                                   "", "core.fan",
+                                                   connectivityType,
+                                                   &presenceHandler);
             if(result == OC_STACK_OK)
             {
                 std::cout<< "Subscribed to multicast presence with resource type";
@@ -332,10 +336,10 @@ int main(int argc, char* argv[]) {
         else
         {
             // Find all resources
-            requestURI << OC_WELL_KNOWN_QUERY;
+            requestURI << OC_RSRVD_WELL_KNOWN_URI;
 
             result = OCPlatform::findResource("", requestURI.str(),
-                    connectivityType, &foundResource);
+                    CT_DEFAULT, &foundResource);
             if(result == OC_STACK_OK)
             {
                 std::cout << "Finding Resource... " << std::endl;