From 15434d897fbd4991a862e431e9b4bbf1b7cab726 Mon Sep 17 00:00:00 2001 From: "jyong2.kim" Date: Tue, 28 Apr 2015 17:12:19 +0900 Subject: [PATCH] Fix exception handling in Notification Manager Sample. 1. handle exception for resource bind. 2. update multicast-request address. 3. clean up code. Change-Id: I9cf87319cf360aaa8b483b45be34b2d520597abf Signed-off-by: jyong2.kim Reviewed-on: https://gerrit.iotivity.org/gerrit/852 Reviewed-by: Uze Choi Tested-by: Uze Choi --- .../linux/sampleConsumer/SampleConsumer.cpp | 30 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/service/notification-manager/SampleApp/linux/sampleConsumer/SampleConsumer.cpp b/service/notification-manager/SampleApp/linux/sampleConsumer/SampleConsumer.cpp index 758374a..7c2c8ef 100755 --- a/service/notification-manager/SampleApp/linux/sampleConsumer/SampleConsumer.cpp +++ b/service/notification-manager/SampleApp/linux/sampleConsumer/SampleConsumer.cpp @@ -18,8 +18,10 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -// OCClient.cpp : Defines the entry point for the console application. -// +/** + * @file SampleConsumer.cpp + * @brief Defines the entry point for the sample consumer application about Resource Hosting. + */ #include #include @@ -27,11 +29,12 @@ #include "OCPlatform.h" #include "OCApi.h" #include + using namespace OC; const int SUCCESS_RESPONSE = OC_STACK_OK; -#define OC_WELL_KNOWN_COORDINATING_QUERY "coap://224.0.1.187:5683/oc/core?rt=Resource.Hosting" +#define OC_WELL_KNOWN_COORDINATING_QUERY "224.0.1.187:5683/oc/core?rt=Resource.Hosting" #define OBSERVE 1 #define GET 2 @@ -39,7 +42,9 @@ const int SUCCESS_RESPONSE = OC_STACK_OK; #define DELETE 4 std::shared_ptr< OCResource > g_curResource; +std::shared_ptr< OCResource > g_curObserveResource; std::mutex curResourceLock; + OCStackResult nmfindResource(const std::string &host , const std::string &resourceName); void onObserve(const HeaderOptions &headerOption , const OCRepresentation &rep , const int &eCode, const int &sequenceNumber); @@ -59,6 +64,7 @@ void findResourceCandidate() } catch (OCException &e) { + std::cout << "Exception for find resource : " << e.reason() << std::endl; } } @@ -70,6 +76,23 @@ void startObserve(std::shared_ptr< OCResource > resource) return; } + if(g_curObserveResource == NULL) + { + g_curObserveResource = resource; + std::cout << "request for new observation" << std::endl; + } + else if(g_curObserveResource == g_curResource) + { + std::cout << "already registered same observation" << std::endl; + return; + } + else + { + std::cout << "change observed resource" << std::endl; + g_curObserveResource->cancelObserve(); + g_curObserveResource = resource; + } + QueryParamsMap test; if (OC_STACK_OK != resource->observe(ObserveType::Observe , test , &onObserve)) std::cout << "To Fail resource observe() process" << std::endl; @@ -321,6 +344,7 @@ int main(int argc , char *argv[]) std::cout << "Created Platform..." << std::endl; g_curResource = NULL; + g_curObserveResource = NULL; findResourceCandidate(); -- 2.7.4