Remove hard-coded IP address from the samples.
authorSashi Penta <sashi.kumar.penta@intel.com>
Wed, 24 Sep 2014 19:06:12 +0000 (12:06 -0700)
committerSashi Penta <sashi.kumar.penta@intel.com>
Thu, 25 Sep 2014 20:49:41 +0000 (13:49 -0700)
removed duplicate call to OCBuildIPv4Address OCInitCoAP.

Change-Id: I51ed3ff71997069e375043e37946180223a60141

16 files changed:
csdk/occoap/src/occoap.c
examples/fridgeclient.cpp
examples/fridgeserver.cpp
examples/garageclient.cpp
examples/garageserver.cpp
examples/ocicuc/client.cpp
examples/ocicuc/monoprocess.cpp
examples/ocicuc/server.cpp
examples/presenceclient.cpp
examples/presenceserver.cpp
examples/roomclient.cpp
examples/roomserver.cpp
examples/simpleclient.cpp
examples/simpleclientserver.cpp
examples/simpleserver.cpp
include/OCApi.h

index fd531d9..ac87186 100644 (file)
@@ -506,10 +506,9 @@ OCStackResult OCInitCoAP(const char *address, uint16_t port, OCMode mode) {
             ret = OC_STACK_ERROR;
             goto exit;
         }
-        OC_LOG_V(INFO, TAG, "Parsed IP Address %d.%d.%d.%d",ipAddr[0],ipAddr[1],ipAddr[2],ipAddr[3]);
 
-        OCBuildIPv4Address(ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3], port,
-                    &devAddr);
+        OC_LOG_V(INFO, TAG, "Parsed IP Address %d.%d.%d.%d",
+                               ipAddr[0],ipAddr[1],ipAddr[2],ipAddr[3]);
     }
 
     OCBuildIPv4Address(ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3], port,
index 81f360f..8c4c55b 100644 (file)
@@ -139,8 +139,8 @@ int main()
     {
         ServiceType::InProc,
         ModeType::Client,
-        "134.134.161.33",
-        56832,
+        "0.0.0.0",
+        0,
         QualityOfService::NonConfirmable
     };
 
index b249174..058e108 100644 (file)
@@ -292,8 +292,8 @@ int main ()
     {
         ServiceType::InProc,
         ModeType::Server,
-        "134.134.161.33",
-        56832,
+        "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+        0,         // Uses randomly available port
         QualityOfService::NonConfirmable
     };
 
index 60d6fa2..08b98f0 100644 (file)
@@ -228,8 +228,8 @@ int main(int argc, char* argv[]) {
     PlatformConfig cfg {
         OC::ServiceType::InProc,
         OC::ModeType::Client,
-        "192.168.1.10",
-        5683,
+        "0.0.0.0",
+        0,
         OC::QualityOfService::NonConfirmable
     };
 
index 637d054..4f15780 100644 (file)
@@ -222,8 +222,8 @@ int main(int argc, char* argv[1])
     PlatformConfig cfg {
         OC::ServiceType::InProc,
         OC::ModeType::Server,
-        "134.134.161.33",
-        56832,
+        "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+        0,         // Uses randomly available port
         OC::QualityOfService::NonConfirmable
     };
 
index b96be2d..9673a46 100644 (file)
@@ -40,7 +40,7 @@
 namespace Intel { namespace OCDemo {
 
 auto make_description()
-    -> boost::program_options::options_description 
+    -> boost::program_options::options_description
 {
  using std::string;
  using std::vector;
@@ -51,8 +51,8 @@ auto make_description()
 
  desc.add_options()
     ("nres",        po::value<unsigned long>()->default_value(1),           "number of resources to use for testing")
-    ("host_ip",     po::value<string>()->default_value("134.134.161.33"),   "IP of host")
-    ("host_port",   po::value<uint16_t>()->default_value(5683),             "port of host")
+    ("host_ip",     po::value<string>()->default_value("0.0.0.0"),   "IP of host")
+    ("host_port",   po::value<uint16_t>()->default_value(0),             "port of host")
     ("interface",   po::value<string>()->default_value("eth0"),             "network interface name")
     ("uri",         po::value<vector<string>>(),                            "remote resource URI")
     ;
@@ -64,12 +64,12 @@ int exec(const boost::program_options::variables_map& vm)
 {
  using namespace std;
 
- OC::OCPlatform platform({ 
+ OC::OCPlatform platform({
                           OC::ServiceType::InProc,              // in-process server
                           OC::ModeType::Client,                 // client mode
                           vm["host_ip"].as<string>(),           // host
                           vm["host_port"].as<uint16_t>(),       // port
-                          OC::QualityOfService::NonConfirmable 
+                          OC::QualityOfService::NonConfirmable
                         });
 
  vector<string> resource_URIs;
@@ -81,7 +81,7 @@ int exec(const boost::program_options::variables_map& vm)
     // Find all resources:
     resource_URIs.push_back("coap://224.0.1.187/oc/core");
 
-    /* Example of finding specific resources: 
+    /* Example of finding specific resources:
     const auto& nprops = vm["nres"].as<unsigned long>();
 
     for(unsigned long instance_number = 1;
index b101cf2..c6e50a6 100644 (file)
@@ -41,7 +41,7 @@
 namespace Intel { namespace OCDemo {
 
 auto make_description()
-    -> boost::program_options::options_description 
+    -> boost::program_options::options_description
 {
  using std::string;
 
@@ -52,9 +52,9 @@ auto make_description()
 std::cout << "JFW: TODO: separate IP/port/etc. for server and client!\n";
  desc.add_options()
     ("nres",        po::value<unsigned long>()->default_value(1),         "number of resources to use for testing")
-    ("host_ip",     po::value<string>()->default_value("134.134.161.33"), "IP of host")
-    ("host_port",   po::value<uint16_t>()->default_value(5683),           "port of host")
-    ("interface",   po::value<string>()->default_value("eth0"),           "network interface name") 
+    ("host_ip",     po::value<string>()->default_value("0.0.0.0"), "IP of host")
+    ("host_port",   po::value<uint16_t>()->default_value(0),           "port of host")
+    ("interface",   po::value<string>()->default_value("eth0"),           "network interface name")
     ("uri",         po::value<vector<string>>(),                          "resource URI")
     ;
 
@@ -149,7 +149,7 @@ struct server_t
  server_t(const boost::program_options::variables_map& vm,
           std::shared_ptr<OC::OCPlatform> platform,
           atomic<bool>& quit_flag_)
-  : m_vm(vm), 
+  : m_vm(vm),
     m_platform_ptr(platform),
     m_platform(*m_platform_ptr),
     quit_flag(quit_flag_)
@@ -200,7 +200,7 @@ int exec(const boost::program_options::variables_map& vm)
                           OC::ModeType::Both,                   // run in client/server mode
                           vm["host_ip"].as<string>(),           // host
                           vm["host_port"].as<uint16_t>(),       // port
-                          OC::QualityOfService::NonConfirmable 
+                          OC::QualityOfService::NonConfirmable
                         });
 
  std::cout << "Ok." << std::endl;
index 3b175e5..64b5028 100644 (file)
@@ -26,7 +26,7 @@
 namespace Intel { namespace OCDemo {
 
 auto make_description()
-    -> boost::program_options::options_description 
+    -> boost::program_options::options_description
 {
  using std::string;
 
@@ -36,9 +36,9 @@ auto make_description()
 
  desc.add_options()
     ("nres",        po::value<unsigned long>()->default_value(1),         "number of resources to use for testing")
-    ("host_ip",     po::value<string>()->default_value("134.134.161.33"), "IP of host")
-    ("host_port",   po::value<uint16_t>()->default_value(56832),          "port of host")
-    ("interface",   po::value<string>()->default_value("eth0"),           "network interface name") 
+    ("host_ip",     po::value<string>()->default_value("0.0.0.0"), "IP of host")
+    ("host_port",   po::value<uint16_t>()->default_value(0),          "port of host")
+    ("interface",   po::value<string>()->default_value("eth0"),           "network interface name")
     ("uri",     po::value<vector<string>>(),                              "resource URI")
     ("runtime", po::value<unsigned int>()->default_value(3600),             "time in seconds to keep the server alive")
     ;
@@ -52,12 +52,12 @@ int exec(const boost::program_options::variables_map& vm)
 
  std::cout << "Starting platform: " << std::flush;
 
- OC::OCPlatform platform({ 
+ OC::OCPlatform platform({
                           OC::ServiceType::InProc,              // in-process server
                           OC::ModeType::Server,                 // run in server mode
                           vm["host_ip"].as<string>(),           // host
                           vm["host_port"].as<uint16_t>(),       // port
-                          OC::QualityOfService::NonConfirmable      
+                          OC::QualityOfService::NonConfirmable
                         });
 
  std::cout << "Ok." << std::endl;
index 897c585..bd9cade 100644 (file)
@@ -76,19 +76,19 @@ void foundResource(std::shared_ptr<OCResource> resource)
             hostAddress = resource->host();
             std::cout << "\tHost address of the resource: " << hostAddress << std::endl;
 
-            // Get the resource types 
+            // Get the resource types
             std::cout << "\tList of resource types: " << std::endl;
             for(auto &resourceTypes : resource->getResourceTypes())
             {
                 std::cout << "\t\t" << resourceTypes << std::endl;
             }
-            
+
             // Get the resource interfaces
             std::cout << "\tList of resource interfaces: " << std::endl;
             for(auto &resourceInterfaces : resource->getResourceInterfaces())
             {
                 std::cout << "\t\t" << resourceInterfaces << std::endl;
-            } 
+            }
 
             if(resourceURI == "/a/light")
             {
@@ -116,8 +116,8 @@ int main(int argc, char* argv[]) {
     PlatformConfig cfg {
         OC::ServiceType::InProc,
         OC::ModeType::Client,
-        "192.168.1.10",
-        5683,
+        "0.0.0.0",
+        0,
         OC::QualityOfService::NonConfirmable
     };
 
index 4fd62aa..db2163c 100644 (file)
@@ -54,7 +54,7 @@ public:
 
 public:
     /// Constructor
-    LightResource(): m_state(false), m_power(0), m_lightUri("/a/light"), 
+    LightResource(): m_state(false), m_power(0), m_lightUri("/a/light"),
                      m_lightUri2("/a/light2"),m_lightUri3("/a/light3") {}
 
     /* Note that this does not need to be a member function: for classes you do not have
@@ -64,7 +64,7 @@ public:
     void createResource(OC::OCPlatform& platform)
     {
         std::string resourceURI = m_lightUri; // URI of the resource
-        std::string resourceTypeName = "core.light"; // resource type name. In this case, it is light
+        std::string resourceTypeName = "core.light"; // resource type name.
         std::string resourceInterface = DEFAULT_INTERFACE; // resource interface.
 
         // OCResourceProperty is defined ocstack.h
@@ -161,8 +161,8 @@ int main()
     PlatformConfig cfg {
         OC::ServiceType::InProc,
         OC::ModeType::Server,
-        "134.134.161.33",
-        56832,
+        "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+        0,         // Uses randomly available port
         OC::QualityOfService::NonConfirmable
     };
 
index 67ba8cb..735a630 100644 (file)
@@ -47,7 +47,7 @@ void onGet(const OCRepresentation& rep, const int eCode)
     if(eCode == SUCCESS_RESPONSE)
     {
         std::cout << "GET request was successful" << std::endl;
-        
+
         std::cout << "\tResource URI: " << rep.getUri() << std::endl;
 
         std::vector<OCRepresentation> children = rep.getChildren();
@@ -61,7 +61,7 @@ void onGet(const OCRepresentation& rep, const int eCode)
                 int  color = 0;
                 oit->getValue("state", state);
                 oit->getValue("color", color);
-    
+
                 std::cout << "\t\tstate:" << state << std::endl;
                 std::cout << "\t\tcolor:" << color << std::endl;
             }
@@ -71,7 +71,7 @@ void onGet(const OCRepresentation& rep, const int eCode)
                 int  speed = 0;
                 oit->getValue("state", state);
                 oit->getValue("speed", speed);
-    
+
                 std::cout << "\t\tstate:" << state << std::endl;
                 std::cout << "\t\tspeed:" << speed << std::endl;
             }
@@ -95,7 +95,7 @@ void putRoomRepresentation(std::shared_ptr<OCResource> resource)
         std::cout << "Putting room representation..."<<std::endl;
 
         bool state = true;
-        int speed = 10;   
+        int speed = 10;
         rep.setValue("state", state);
         rep.setValue("speed", speed);
 
@@ -124,7 +124,6 @@ void onPut(const OCRepresentation& rep, const int eCode)
                 int  color = 0;
                 oit->getValue("state", state);
                 oit->getValue("color", color);
-    
                 std::cout << "\t\tstate:" << state << std::endl;
                 std::cout << "\t\tcolor:" << color << std::endl;
             }
@@ -134,7 +133,6 @@ void onPut(const OCRepresentation& rep, const int eCode)
                 int  speed = 0;
                 oit->getValue("state", state);
                 oit->getValue("speed", speed);
-    
                 std::cout << "\t\tstate:" << state << std::endl;
                 std::cout << "\t\tspeed:" << speed << std::endl;
             }
@@ -187,19 +185,19 @@ void foundResource(std::shared_ptr<OCResource> resource)
             hostAddress = resource->host();
             std::cout << "\tHost address of the resource: " << hostAddress << std::endl;
 
-            // Get the resource types 
+            // Get the resource types
             std::cout << "\tList of resource types: " << std::endl;
             for(auto &resourceTypes : resource->getResourceTypes())
             {
                 std::cout << "\t\t" << resourceTypes << std::endl;
             }
-            
+
             // Get the resource interfaces
             std::cout << "\tList of resource interfaces: " << std::endl;
             for(auto &resourceInterfaces : resource->getResourceInterfaces())
             {
                 std::cout << "\t\t" << resourceInterfaces << std::endl;
-            } 
+            }
 
             if(resourceURI == "/a/room")
             {
@@ -227,8 +225,8 @@ int main(int argc, char* argv[]) {
     PlatformConfig cfg {
         OC::ServiceType::InProc,
         OC::ModeType::Client,
-        "192.168.1.10",
-        5683,
+        "0.0.0.0",
+        0,
         OC::QualityOfService::NonConfirmable
     };
 
index 035e6cc..5953544 100644 (file)
@@ -69,7 +69,7 @@ public:
 
 public:
     /// Constructor
-    RoomResource(): m_lightState(false), m_lightColor(0), m_fanState(false), m_fanSpeed(0) 
+    RoomResource(): m_lightState(false), m_lightColor(0), m_fanState(false), m_fanSpeed(0)
     {
         m_lightUri = "/a/light"; // URI of the resource
         m_lightTypes.push_back("core.light"); // resource type name. In this case, it is light
@@ -107,7 +107,7 @@ public:
         // This will internally create and register the resource.
         OCStackResult result = platform.registerResource(
                                     m_roomHandle, m_roomUri, m_roomTypes[0],
-                                    m_roomInterfaces[0], NULL, //entityHandlerRoom, 
+                                    m_roomInterfaces[0], NULL, //entityHandlerRoom,
                                     OC_DISCOVERABLE | OC_OBSERVABLE
                                   );
 
@@ -130,7 +130,7 @@ public:
 
         result = platform.registerResource(
                                     m_lightHandle, m_lightUri, m_lightTypes[0],
-                                    m_lightInterfaces[0], entityHandlerLight, 
+                                    m_lightInterfaces[0], entityHandlerLight,
                                     OC_DISCOVERABLE | OC_OBSERVABLE
                                    );
 
@@ -141,7 +141,7 @@ public:
 
         result = platform.registerResource(
                                     m_fanHandle, m_fanUri, m_fanTypes[0],
-                                    m_fanInterfaces[0], entityHandlerFan, 
+                                    m_fanInterfaces[0], entityHandlerFan,
                                     OC_DISCOVERABLE | OC_OBSERVABLE
                                    );
 
@@ -174,7 +174,7 @@ public:
         {
             m_lightState = tempState;
             m_lightColor= tempColor;
-       
+
             cout << "\t\t\t\t" << "state: " << m_lightState << endl;
             cout << "\t\t\t\t" << "color: " << m_lightColor << endl;
         }
@@ -197,7 +197,7 @@ public:
     }
 
 
-    OCRepresentation getLightRepresentation() 
+    OCRepresentation getLightRepresentation()
     {
         m_lightRep.setValue("state", m_lightState);
         m_lightRep.setValue("color", m_lightColor);
@@ -221,7 +221,7 @@ public:
 
         OCRepresentation fan = getFanRepresentation();
         children.push_back(fan);
-            
+
         m_roomRep.setChildren(children);
 
         return m_roomRep;
@@ -232,7 +232,8 @@ public:
 // Create the instance of the resource class (in this case instance of class 'RoomResource').
 RoomResource myRoomResource;
 
-void entityHandlerRoom(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response)
+void entityHandlerRoom(std::shared_ptr<OCResourceRequest> request,
+                       std::shared_ptr<OCResourceResponse> response)
 {
     cout << "\tIn Server CPP entity handler:\n";
 
@@ -465,8 +466,8 @@ int main()
     PlatformConfig cfg {
         OC::ServiceType::InProc,
         OC::ModeType::Server,
-        "192.168.1.10",
-        56832,
+        "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+        0,         // Uses randomly available port
         OC::QualityOfService::NonConfirmable
     };
 
index 886ea5c..83174c9 100644 (file)
@@ -268,8 +268,8 @@ int main(int argc, char* argv[]) {
     PlatformConfig cfg {
         OC::ServiceType::InProc,
         OC::ModeType::Client,
-        "192.168.1.10",
-        5683,
+        "0.0.0.0",
+        0,
         OC::QualityOfService::NonConfirmable
     };
 
index b824a55..7fea071 100644 (file)
@@ -97,7 +97,7 @@ private:
     }
 
     void foundResource(std::shared_ptr<OCResource> resource)
-    {    
+    {
         std::cout << "In foundResource" << std::endl;
         if(resource && resource->uri() == "/q/foo")
         {
@@ -114,25 +114,25 @@ private:
             std::cout << "Found Resource: "<<std::endl;
             std::cout << "\tHost: "<< resource->host()<<std::endl;
             std::cout << "\tURI:  "<< resource->uri()<<std::endl;
-            
-            // Get the resource types 
+
+            // Get the resource types
             std::cout << "\tList of resource types: " << std::endl;
             for(auto &resourceTypes : resource->getResourceTypes())
             {
                 std::cout << "\t\t" << resourceTypes << std::endl;
             }
-            
+
             // Get the resource interfaces
             std::cout << "\tList of resource interfaces: " << std::endl;
             for(auto &resourceInterfaces : resource->getResourceInterfaces())
             {
                 std::cout << "\t\t" << resourceInterfaces << std::endl;
-            } 
+            }
 
             std::cout<<"Doing a get on q/foo."<<std::endl;
 
             resource->get(QueryParamsMap(), GetCallback(std::bind(&ClientWorker::getResourceInfo, this, std::placeholders::_1, std::placeholders::_2)));
-        } 
+        }
     }
 
 public:
@@ -179,7 +179,7 @@ struct FooResource
 
         RegisterCallback eh(std::bind(&FooResource::entityHandler, this, std::placeholders::_1, std::placeholders::_2));
         OCStackResult result = platform.registerResource(m_resourceHandle, resourceURI, resourceTypeName,
-                                    resourceInterface, 
+                                    resourceInterface,
                                     eh, resourceProperty);
         if(OC_STACK_OK != result)
         {
@@ -247,7 +247,7 @@ struct FooResource
             else
             {
                 std::cout <<"\t\trequestFlag : UNSUPPORTED: ";
-                
+
                 if(request->getRequestHandlerFlag()==RequestHandlerFlag::InitFlag)
                 {
                     std::cout<<"InitFlag"<<std::endl;
@@ -270,8 +270,8 @@ int main()
     PlatformConfig cfg {
         OC::ServiceType::InProc,
         OC::ModeType::Both,
-        "134.134.161.33",
-        56833,
+        "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+        0,         // Uses randomly available port
         OC::QualityOfService::NonConfirmable
     };
 
@@ -280,7 +280,7 @@ int main()
     try
     {
         OCPlatform platform(cfg);
-        
+
         if(!fooRes.createResource(platform))
         {
             return -1;
index 2783183..5afc83a 100644 (file)
@@ -348,8 +348,8 @@ int main(int argc, char* argv[1])
     PlatformConfig cfg {
         OC::ServiceType::InProc,
         OC::ModeType::Server,
-        "134.134.161.33",
-        56832,
+        "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+        0,         // Uses randomly available port
         OC::QualityOfService::NonConfirmable
     };
 
index 981d421..34a57af 100644 (file)
@@ -75,12 +75,23 @@ namespace OC
         NonConfirmable  = OC_NON_CONFIRMABLE
     };
 
+    /**
+    *  Data structure to provide the configuration.
+    *  ServiceType: indicate InProc or OutOfProc
+    *  ModeType   : indicate whether we want to do server, client or both
+    *  ipAddress  : ip address of server.
+    *               if you speecifiy 0.0.0.0 : it listens on any interface.
+    *  port       : port of server.
+    *             : if you specifiy 0 : next available random port is used.
+    *             : if you specify 5683 : client discovery can work even if they don't specify port.
+    *  QoS        : Quality of Service : CONFIRMABLE or NON CONFIRMABLE.
+    */
     struct PlatformConfig
     {
-        ServiceType                serviceType;   // This will indicate whether it is InProc or OutOfProc
-        ModeType                   mode;          // This will indicate whether we want to do server, client or both
-        std::string                ipAddress;     // This is the ipAddress of the server to connect to
-        uint16_t                   port;          // Port of the server
+        ServiceType                serviceType;
+        ModeType                   mode;
+        std::string                ipAddress;
+        uint16_t                   port;
 
         QualityOfService           QoS;