From 65119240511dd6609e9778fd9bbf7555d877f204 Mon Sep 17 00:00:00 2001 From: Joseph Morrow Date: Fri, 14 Nov 2014 19:53:10 -0500 Subject: [PATCH] Active Discovey Resource Type Filtering - C++ SDK & App Changes only. This change affects only the C++ API and it's sample app "presenceclient.cpp". Change-Id: I92cebe5045dfda5b506ab6c849a1ce13330c4391 Signed-off-by: Joseph Morrow --- resource/examples/presenceclient.cpp | 108 ++++++++++++++++++------------ resource/include/IClientWrapper.h | 2 +- resource/include/InProcClientWrapper.h | 2 +- resource/include/OCPlatform.h | 3 + resource/include/OCPlatform_impl.h | 3 + resource/include/OutOfProcClientWrapper.h | 3 +- resource/src/InProcClientWrapper.cpp | 9 ++- resource/src/OCPlatform.cpp | 9 +++ resource/src/OCPlatform_impl.cpp | 10 ++- 9 files changed, 100 insertions(+), 49 deletions(-) diff --git a/resource/examples/presenceclient.cpp b/resource/examples/presenceclient.cpp index 9c6204f..b279087 100644 --- a/resource/examples/presenceclient.cpp +++ b/resource/examples/presenceclient.cpp @@ -30,6 +30,30 @@ using namespace OC; std::shared_ptr curResource; +static int TEST_CASE = 0; + +/** + * List of methods that can be inititated from the client + */ +typedef enum { + TEST_UNICAST_PRESENCE_NORMAL = 1, + TEST_UNICAST_PRESENCE_WITH_FILTER, + TEST_MULTICAST_PRESENCE_NORMAL, + TEST_MULTICAST_PRESENCE_WITH_FILTER, + MAX_TESTS +} CLIENT_TEST; + +void printUsage() +{ + std::cout << "Usage : presenceclient -t <1|2>" << std::endl; + 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; + std::cout << "-t 3 : Discover Resources and Initiate Multicast Presence" << std::endl; + std::cout << "-t 4 : Discover Resources and Initiate Multicast Presence with Filter" + << std::endl; +} + // Callback to presence void presenceHandler(OCStackResult result, const unsigned int nonce) { @@ -92,8 +116,27 @@ void foundResource(std::shared_ptr resource) { curResource = resource; OCPlatform::OCPresenceHandle presenceHandle; - OCPlatform::subscribePresence(presenceHandle, hostAddress, &presenceHandler); - std::cout<< "subscribing for unicast presence... " < resource) } } -void PrintUsage() -{ - std::cout << std::endl; - std::cout << "Usage : presenceclient \n"; - std::cout << " 0 - unicast subcribe presence\n"; - std::cout << " 1 - multicast subscribe presence\n\n"; -} - -// 0 - unicast subcribe presence -// 1 - multicast subscribe presence -int isMulticastAddress = 0; +int main(int argc, char* argv[]) { + int opt; -int main(int argc, char* argv[1]) -{ - PrintUsage(); - - if (argc == 1) + while ((opt = getopt(argc, argv, "t:")) != -1) { - isMulticastAddress = 0; - } - else if (argc == 2) - { - int value = atoi(argv[1]); - if (value == 1) - isMulticastAddress = 1; - else - isMulticastAddress = 0; + switch(opt) + { + case 't': + TEST_CASE = atoi(optarg); + break; + default: + printUsage(); + return -1; + } } - else + if(TEST_CASE >= MAX_TESTS || TEST_CASE <= 0) { + printUsage(); return -1; } @@ -151,23 +182,14 @@ int main(int argc, char* argv[1]) OC::QualityOfService::LowQos }; + OCPlatform::Configure(cfg); + try { - OCPlatform::Configure(cfg); - - if(isMulticastAddress) - { - OCPlatform::OCPresenceHandle presenceHandle; - OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, presenceHandler); - std::cout<< "subscribing for multicast presence... " <