X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fnotification%2Fcpp-wrapper%2Fprovider%2Fsrc%2FNSConsumer.cpp;h=5d3c472fdbb6732698351d4bfe5042aea15f0a3e;hb=refs%2Ftags%2Faccepted%2Ftizen%2Funified%2F20171010.063815;hp=a81f87542c18e2bcd997397e0c79204b5e3a03f3;hpb=edcfc3d2329da7b914771c0dcff5f42c9b74fd93;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/notification/cpp-wrapper/provider/src/NSConsumer.cpp b/service/notification/cpp-wrapper/provider/src/NSConsumer.cpp index a81f875..5d3c472 100755 --- a/service/notification/cpp-wrapper/provider/src/NSConsumer.cpp +++ b/service/notification/cpp-wrapper/provider/src/NSConsumer.cpp @@ -20,7 +20,10 @@ #include "NSConsumer.h" #include +#include "NSProviderService.h" +#include "NSAcceptedConsumers.h" #include "NSProviderInterface.h" +#include "NSException.h" #include "NSConstants.h" #include "oic_string.h" #include "oic_malloc.h" @@ -49,17 +52,25 @@ namespace OIC return m_consumerId; } - int NSConsumer::acceptSubscription(bool accepted) + NSResult NSConsumer::acceptSubscription(bool accepted) { NS_LOG(DEBUG, "acceptSubscription - IN"); + if (!isValid()) + { + throw NSException("Invalid Operation with stale reference of Consumer"); + } NSResult result = (NSResult) NSAcceptSubscription(getConsumerId().c_str(), accepted); NS_LOG(DEBUG, "acceptSubscription - OUT"); - return (int) result; + return result; } NSResult NSConsumer::setTopic(const std::string &topicName) { NS_LOG(DEBUG, "setTopic - IN"); + if (!isValid()) + { + throw NSException("Invalid Operation with stale reference of Consumer"); + } NSResult result = (NSResult) NSProviderSetConsumerTopic(getConsumerId().c_str(), topicName.c_str()); NS_LOG(DEBUG, "setTopic - OUT"); @@ -69,20 +80,38 @@ namespace OIC NSResult NSConsumer::unsetTopic(const std::string &topicName) { NS_LOG(DEBUG, "unsetTopic - IN"); + if (!isValid()) + { + throw NSException("Invalid Operation with stale reference of Consumer"); + } NSResult result = (NSResult) NSProviderUnsetConsumerTopic(getConsumerId().c_str(), topicName.c_str()); NS_LOG(DEBUG, "unsetTopic - OUT"); return result; } - NSTopicsList *NSConsumer::getConsumerTopicList() + std::shared_ptr NSConsumer::getConsumerTopicList() { NS_LOG(DEBUG, "getConsumerTopicList - IN"); + if (!isValid()) + { + throw NSException("Invalid Operation with stale reference of Consumer"); + } ::NSTopicLL *topics = NSProviderGetConsumerTopics(getConsumerId().c_str()); - NSTopicsList *nsTopics = new NSTopicsList(topics); + std::shared_ptr nsTopics = std::make_shared(topics, false); NS_LOG(DEBUG, "getConsumerTopicList - OUT"); return nsTopics; } + + bool NSConsumer::isValid() const + { + if (!NSProviderService::getInstance()->getAcceptedConsumers()->isAccepted(getConsumerId())) + { + NS_LOG(DEBUG, "Invalid Operation with stale reference of Consumer. Consumer ID doesnot exist"); + return false; + } + return true; + } } }