From bf2e580e6786fbf35b87ad4074c8d477e97e1244 Mon Sep 17 00:00:00 2001 From: "jihwan.seo" Date: Wed, 10 Aug 2016 13:34:19 +0900 Subject: [PATCH] update simpleclient sample app to support test TCP. Change-Id: I23feba350fb80fb625161ae28077010767a172ba Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/10217 Reviewed-by: Jaehong Jo Tested-by: jenkins-iotivity Reviewed-by: Ziran Sun --- resource/examples/simpleclient.cpp | 41 ++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/resource/examples/simpleclient.cpp b/resource/examples/simpleclient.cpp index 6f7b91d..f9452af 100644 --- a/resource/examples/simpleclient.cpp +++ b/resource/examples/simpleclient.cpp @@ -47,6 +47,7 @@ typedef std::map> DiscoveredRe DiscoveredResourceMap discoveredResources; std::shared_ptr curResource; static ObserveType OBSERVE_TYPE_TO_USE = ObserveType::Observe; +static OCConnectivityType TRANSPORT_TYPE_TO_USE = OCConnectivityType::CT_ADAPTER_IP; std::mutex curResourceLock; class Light @@ -392,9 +393,15 @@ void foundResource(std::shared_ptr resource) if(resourceURI == "/a/light") { - curResource = resource; - // Call a local function which will internally invoke get API on the resource pointer - getLightRepresentation(resource); + if (resource->connectivityType() & TRANSPORT_TYPE_TO_USE) + { + curResource = resource; + // Get the resource host address + std::cout << "\tAddress of selected resource: " << resource->host() << std::endl; + + // Call a local function which will internally invoke get API on the resource pointer + getLightRepresentation(resource); + } } } else @@ -414,9 +421,11 @@ void printUsage() { std::cout << std::endl; std::cout << "---------------------------------------------------------------------\n"; - std::cout << "Usage : simpleclient " << std::endl; + std::cout << "Usage : simpleclient " << std::endl; std::cout << " ObserveType : 1 - Observe" << std::endl; std::cout << " ObserveType : 2 - ObserveAll" << std::endl; + std::cout << " TransportType : 1 - IP" << std::endl; + std::cout << " TransportType : 2 - TCP" << std::endl; std::cout << "---------------------------------------------------------------------\n\n"; } @@ -439,6 +448,25 @@ void checkObserverValue(int value) } } +void checkTransportValue(int value) +{ + if (1 == value) + { + TRANSPORT_TYPE_TO_USE = OCConnectivityType::CT_ADAPTER_IP; + std::cout << "<===Setting TransportType to IP===>\n\n"; + } + else if (2 == value) + { + TRANSPORT_TYPE_TO_USE = OCConnectivityType::CT_ADAPTER_TCP; + std::cout << "<===Setting TransportType to TCP===>\n\n"; + } + else + { + std::cout << "<===Invalid TransportType selected." + <<" Setting TransportType to IP===>\n\n"; + } +} + static FILE* client_open(const char* /*path*/, const char *mode) { return fopen(SVR_DB_FILE_NAME, mode); @@ -459,6 +487,11 @@ int main(int argc, char* argv[]) { { checkObserverValue(std::stoi(argv[1])); } + else if (argc == 3) + { + checkObserverValue(std::stoi(argv[1])); + checkTransportValue(std::stoi(argv[2])); + } else { std::cout << "<===Invalid number of command line arguments===>\n\n"; -- 2.7.4