\r
#include "NSConsumer.h"\r
#include <cstring>\r
+#include "NSProviderService.h"\r
+#include "NSAcceptedConsumers.h"\r
#include "NSProviderInterface.h"\r
+#include "NSException.h"\r
#include "NSConstants.h"\r
-#include "NSUtils.h"\r
#include "oic_string.h"\r
+#include "oic_malloc.h"\r
\r
namespace OIC\r
{\r
{\r
if (consumer != nullptr)\r
{\r
- m_consumerId.assign(consumer->consumerId, NS_UTILS_UUID_STRING_SIZE);\r
+ m_consumerId.assign(consumer->consumerId, NS_UTILS_UUID_STRING_SIZE - 1);\r
}\r
}\r
\r
return m_consumerId;\r
}\r
\r
- int NSConsumer::acceptSubscription(NSConsumer *consumer, bool accepted)\r
+ NSResult NSConsumer::acceptSubscription(bool accepted)\r
{\r
NS_LOG(DEBUG, "acceptSubscription - IN");\r
- if (consumer != nullptr)\r
- return NSAcceptSubscription(consumer->getNSConsumer(), accepted);\r
+ if (!isValid())\r
+ {\r
+ throw NSException("Invalid Operation with stale reference of Consumer");\r
+ }\r
+ NSResult result = (NSResult) NSAcceptSubscription(getConsumerId().c_str(), accepted);\r
NS_LOG(DEBUG, "acceptSubscription - OUT");\r
- return NS_ERROR;\r
+ return result;\r
+ }\r
+\r
+ NSResult NSConsumer::setTopic(const std::string &topicName)\r
+ {\r
+ NS_LOG(DEBUG, "setTopic - IN");\r
+ if (!isValid())\r
+ {\r
+ throw NSException("Invalid Operation with stale reference of Consumer");\r
+ }\r
+ NSResult result = (NSResult) NSProviderSetConsumerTopic(getConsumerId().c_str(),\r
+ topicName.c_str());\r
+ NS_LOG(DEBUG, "setTopic - OUT");\r
+ return result;\r
+ }\r
+\r
+ NSResult NSConsumer::unsetTopic(const std::string &topicName)\r
+ {\r
+ NS_LOG(DEBUG, "unsetTopic - IN");\r
+ if (!isValid())\r
+ {\r
+ throw NSException("Invalid Operation with stale reference of Consumer");\r
+ }\r
+ NSResult result = (NSResult) NSProviderUnsetConsumerTopic(getConsumerId().c_str(),\r
+ topicName.c_str());\r
+ NS_LOG(DEBUG, "unsetTopic - OUT");\r
+ return result;\r
+ }\r
+\r
+ std::shared_ptr<NSTopicsList> NSConsumer::getConsumerTopicList()\r
+ {\r
+ NS_LOG(DEBUG, "getConsumerTopicList - IN");\r
+ if (!isValid())\r
+ {\r
+ throw NSException("Invalid Operation with stale reference of Consumer");\r
+ }\r
+ ::NSTopicLL *topics = NSProviderGetConsumerTopics(getConsumerId().c_str());\r
+\r
+ std::shared_ptr<NSTopicsList> nsTopics = std::make_shared<NSTopicsList>(topics, false);\r
+ NS_LOG(DEBUG, "getConsumerTopicList - OUT");\r
+ return nsTopics;\r
+ }\r
+\r
+ bool NSConsumer::isValid() const\r
+ {\r
+ if (!NSProviderService::getInstance()->getAcceptedConsumers()->isAccepted(getConsumerId()))\r
+ {\r
+ NS_LOG(DEBUG, "Invalid Operation with stale reference of Consumer. Consumer ID doesnot exist");\r
+ return false;\r
+ }\r
+ return true;\r
}\r
}\r
}\r