Updated Topic resource changes for C++ wrapper
authorabitha.s <abitha.s@samsung.com>
Fri, 12 Aug 2016 08:47:21 +0000 (14:17 +0530)
committerUze Choi <uzchoi@samsung.com>
Thu, 25 Aug 2016 03:32:44 +0000 (03:32 +0000)
1. Modified the Topic resource and Topic LL changes in Provider and Consumer
2. Updated the APIs for Topic resource in C++ wrapper
3. Updated the sample application for calling Topic APIs

patch 1 : initial commit
patch 2 : updated commit message
patch 3 : updated review comments
patch 4 : updated commit message
patch 5 : removed NSAccessPolicy struct

Change-Id: I737bef2eebb129c5f13034d990398d75dd13b3b7
Signed-off-by: abitha.s <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10623
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Chihyun Cho <ch79.cho@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
18 files changed:
service/notification/SConscript
service/notification/cpp-wrapper/common/NSMessage.cpp
service/notification/cpp-wrapper/common/NSMessage.h
service/notification/cpp-wrapper/common/NSTopic.cpp [new file with mode: 0755]
service/notification/cpp-wrapper/common/NSTopic.h [new file with mode: 0755]
service/notification/cpp-wrapper/common/NSTopicsList.cpp [new file with mode: 0755]
service/notification/cpp-wrapper/common/NSTopicsList.h [new file with mode: 0755]
service/notification/cpp-wrapper/common/NSUtils.h
service/notification/cpp-wrapper/consumer/inc/NSConsumerService.h
service/notification/cpp-wrapper/consumer/inc/NSProvider.h
service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp
service/notification/cpp-wrapper/consumer/src/NSProvider.cpp
service/notification/cpp-wrapper/examples/linux/notificationserviceconsumer.cpp
service/notification/cpp-wrapper/examples/linux/notificationserviceprovider.cpp
service/notification/cpp-wrapper/provider/inc/NSConsumer.h
service/notification/cpp-wrapper/provider/inc/NSProviderService.h
service/notification/cpp-wrapper/provider/src/NSConsumer.cpp
service/notification/cpp-wrapper/provider/src/NSProviderService.cpp

index 774e258..ba2db6c 100755 (executable)
@@ -124,4 +124,4 @@ SConscript('examples/SConscript')
 #    SConscript('android/SConscript')
 
 # Go to build c++ wrapper
-#SConscript('cpp-wrapper/SConscript')
+SConscript('cpp-wrapper/SConscript')
index 68f9e76..8556295 100755 (executable)
@@ -33,7 +33,7 @@ namespace OIC
             m_type = NSMessage::NSMessageType::NS_MESSAGE_ALERT;\r
             m_ttl = 0;\r
             m_mediaContents = new NSMediaContents();\r
-            \r
+\r
             if (msg != nullptr)\r
             {\r
                 m_messageId = msg->messageId;\r
@@ -59,12 +59,15 @@ namespace OIC
                     if ((msg->mediaContents->iconImage != nullptr) && strlen(msg->mediaContents->iconImage))\r
                         m_mediaContents->setIconImage(msg->mediaContents->iconImage);\r
 \r
+                if ((msg->topic != nullptr) && strlen(msg->topic))\r
+                    m_topic.assign(msg->topic, strlen(msg->topic));\r
+\r
             }\r
         }\r
 \r
         NSMessage::~NSMessage()\r
         {\r
-            if(m_mediaContents != nullptr)\r
+            if (m_mediaContents != nullptr)\r
                 delete m_mediaContents;\r
         }\r
 \r
@@ -113,6 +116,11 @@ namespace OIC
             return m_mediaContents;\r
         }\r
 \r
+        std::string NSMessage::getTopic() const\r
+        {\r
+            return m_topic;\r
+        }\r
+\r
         void NSMessage::setType(const NSMessageType &type)\r
         {\r
             m_type = type;\r
index 2e55e1c..f9dab49 100755 (executable)
@@ -54,7 +54,7 @@ namespace OIC
                         * Constructor of NSMessage.\r
                         */\r
                 NSMessage(): m_messageId(0), m_type(NSMessageType::NS_MESSAGE_ALERT), m_ttl(0),\r
-                                            m_mediaContents(new NSMediaContents) { }\r
+                    m_mediaContents(new NSMediaContents) { }\r
 \r
                 /**\r
                         * Constructor of NSMessage.\r
@@ -180,6 +180,12 @@ namespace OIC
                      */\r
                 void setMediaContents(NSMediaContents *mediaContents);\r
 \r
+                /**\r
+                     * This method is for getting Topic from the Notification service Message.\r
+                     *\r
+                     * @return Topic as string.\r
+                     */\r
+                std::string getTopic() const;\r
 \r
             private:\r
                 uint64_t m_messageId;\r
@@ -192,6 +198,7 @@ namespace OIC
                 std::string m_contentText;\r
                 std::string m_sourceName;\r
                 NSMediaContents *m_mediaContents;\r
+                std::string m_topic;\r
 \r
         };\r
     }\r
diff --git a/service/notification/cpp-wrapper/common/NSTopic.cpp b/service/notification/cpp-wrapper/common/NSTopic.cpp
new file mode 100755 (executable)
index 0000000..ce099d9
--- /dev/null
@@ -0,0 +1,47 @@
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "NSTopic.h"
+
+namespace OIC
+{
+    namespace Service
+    {
+        std::string NSTopic::getTopicName() const
+        {
+            return m_topicName;
+        }
+
+        void NSTopic::setTopicName(const std::string &topicName)
+        {
+            m_topicName = topicName;
+        }
+
+        NSTopic::NSTopicState NSTopic::getState() const
+        {
+            return m_state;
+        }
+
+        void NSTopic::setState(const NSTopic::NSTopicState state)
+        {
+            m_state = state;
+        }
+    }
+}
diff --git a/service/notification/cpp-wrapper/common/NSTopic.h b/service/notification/cpp-wrapper/common/NSTopic.h
new file mode 100755 (executable)
index 0000000..36a3747
--- /dev/null
@@ -0,0 +1,109 @@
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file
+ *
+ * This file contains Notification service topic representation.
+ */
+
+#ifndef _NS_TOPIC_H_
+#define _NS_TOPIC_H_
+
+
+#include <string>
+#include "NSCommon.h"
+
+namespace OIC
+{
+    namespace Service
+    {
+        /**
+         * @class   NSTopic
+         * @brief   This class provides a set of APIs for Notification service Topic.
+         */
+        class NSTopic
+        {
+            public:
+                /**
+                     *  Notification topic State
+                     */
+                enum class NSTopicState
+                {
+                    UNSUBSCRIBED = 0,
+                    SUBSCRIBED = 1,
+                };
+
+                /**
+                     * Constructor of NSTopic.
+                     */
+                NSTopic(): m_state(NSTopicState::UNSUBSCRIBED) { }
+
+                /**
+                     * Constructor of NSTopic.
+                     *
+                     * @param topicName - topicName of the Notification service Topic.
+                     * @param state - as NSTopicState.
+                     */
+                NSTopic(const std::string &topicName, const NSTopicState state)
+                    : m_topicName(topicName) , m_state(state) {}
+
+
+                /**
+                     * Destructor of NSTopic.
+                     */
+                ~NSTopic() = default;
+
+                /**
+                      * This method is for getting topicName from the Notification service Topic.
+                      *
+                      * @return topicName as string.
+                      */
+                std::string getTopicName() const;
+
+                /**
+                      * This method is for setting topicName for the Notification service Topic.
+                      *
+                      * @param topicName - as string.
+                      */
+                void setTopicName(const std::string &topicName);
+
+                /**
+                      * This method is for getting state from the Notification service Topic.
+                      *
+                      * @return state as NSTopicState.
+                      */
+                NSTopicState getState() const;
+
+                /**
+                      * This method is for setting state for the Notification service Topic.
+                      *
+                      * @param state - as NSTopicState.
+                      */
+                void setState(const NSTopicState state);
+
+            private:
+                std::string m_topicName;
+                NSTopicState m_state;
+
+        };
+    }
+}
+#endif /* _NS_TOPIC_H_ */
diff --git a/service/notification/cpp-wrapper/common/NSTopicsList.cpp b/service/notification/cpp-wrapper/common/NSTopicsList.cpp
new file mode 100755 (executable)
index 0000000..35d2365
--- /dev/null
@@ -0,0 +1,78 @@
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "NSTopicsList.h"
+#include "oic_malloc.h"
+
+namespace OIC
+{
+    namespace Service
+    {
+        NSTopicsList::NSTopicsList(::NSTopicLL *topics)
+        {
+            ::NSTopicLL *topicsNode = nullptr;
+            topicsNode = topics;
+
+            while (topicsNode != nullptr)
+            {
+                addTopic(topicsNode->topicName, (NSTopic::NSTopicState)topicsNode->state);
+                topicsNode = topicsNode->next;
+            }
+
+            topicsNode = topics;
+            while (topicsNode != nullptr)
+            {
+                topics = topics->next;
+                if (topicsNode->topicName)
+                    OICFree(topicsNode->topicName);
+                OICFree(topicsNode);
+                topicsNode = topics;
+            }
+        }
+
+        NSTopicsList::~NSTopicsList()
+        {
+            for (auto it : getTopicsList())
+            {
+                delete it;
+            }
+            getTopicsList().clear();
+        }
+
+        void NSTopicsList::addTopic(const std::string &topicName, NSTopic::NSTopicState state)
+        {
+            m_topicsList.push_back(new NSTopic(topicName, state));
+        }
+
+        void NSTopicsList::removeTopic(const std::string &topicName)
+        {
+            for (auto it : getTopicsList())
+            {
+                if (it->getTopicName().compare(topicName) == 0)
+                    m_topicsList.remove(it);
+            }
+        }
+
+        std::list<NSTopic *> NSTopicsList::getTopicsList()
+        {
+            return m_topicsList;
+        }
+    }
+}
diff --git a/service/notification/cpp-wrapper/common/NSTopicsList.h b/service/notification/cpp-wrapper/common/NSTopicsList.h
new file mode 100755 (executable)
index 0000000..9274826
--- /dev/null
@@ -0,0 +1,91 @@
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file
+ *
+ * This file contains Notification service topics linked list representation.
+ */
+
+#ifndef _NS_TOPICS_LIST_H_
+#define _NS_TOPICS_LIST_H_
+
+
+#include <string>
+#include <list>
+#include "NSTopic.h"
+
+namespace OIC
+{
+    namespace Service
+    {
+        /**
+         * @class   NSTopicsList
+         * @brief   This class provides a set of APIs for Notification service Topics Linked list.
+         */
+        class NSTopicsList
+        {
+            public:
+                /**
+                     * Constructor of NSTopicsList.
+                     */
+                NSTopicsList() = default;
+
+                /**
+                     * Constructor of NSTopicsList.
+                     *
+                     * @param topics - pointer to NSTopicLL struct to initialize.
+                     */
+                NSTopicsList(::NSTopicLL *topics);
+
+                /**
+                     * Destructor of NSTopicsList.
+                     */
+                ~NSTopicsList();
+
+                /**
+                     * This method is for adding topic for the Notification service Topics Linked list.
+                     *
+                     * @param topicName as string.
+                     * @param state - as NSTopicState.
+                     */
+                void addTopic(const std::string &topicName, NSTopic::NSTopicState state);
+
+                /**
+                     * This method is for removing topic from the Notification service Topics Linked list.
+                     *
+                     * @param topicName as string.
+                     */
+                void removeTopic(const std::string &topicName);
+
+                /**
+                     * This method is for getting topic LL from the Notification service Topics Linked list.
+                     *
+                     * @return topic as NSTopics Linked list.
+                     */
+                std::list<NSTopic *> getTopicsList();
+
+            private:
+                std::list<NSTopic *> m_topicsList;
+
+        };
+    }
+}
+#endif /* _NS_TOPICS_LIST_H_ */
index 00c00a5..99c0c3d 100755 (executable)
@@ -41,7 +41,7 @@ namespace OIC
             SUCCESS = 300,
             FAIL = 400,
         };
-        
+
         /**
              * NSResponse code of notification service
              */
index 2f6aa89..36e2781 100755 (executable)
@@ -111,6 +111,14 @@ namespace OIC
                       */\r
                 NSProvider *getProvider(const std::string &id);\r
 \r
+\r
+                /**\r
+                     * Request NSMessage that is matched by message id\r
+                     * @param[in]  messageId  the id of message that user wants to get\r
+                     * @return NSMessage\r
+                     */\r
+                NSMessage *getMessage(uint64_t messageId);\r
+\r
                 /**\r
                       *  get consumer config values\r
                       * @return ConsumerConfig callbaks set\r
index 5ace980..a556ae2 100755 (executable)
@@ -31,6 +31,8 @@
 #include <string>\r
 #include "NSSyncInfo.h"\r
 #include "NSMessage.h"\r
+#include "NSUtils.h"\r
+#include "NSTopicsList.h"\r
 \r
 namespace OIC\r
 {\r
@@ -60,7 +62,7 @@ namespace OIC
                 /**\r
                       * Constructor of NSProvider.\r
                       */\r
-                NSProvider(): m_messageCb(NULL), m_syncInfoCb(NULL) {}\r
+                NSProvider(): m_topicList(new NSTopicsList()), m_messageCb(NULL), m_syncInfoCb(NULL) {}\r
 \r
                 /**\r
                       * Constructor of NSProvider.\r
@@ -68,7 +70,16 @@ namespace OIC
                       * @param providerId - providerId of the Notification.\r
                       */\r
                 NSProvider(const std::string &providerId) : m_providerId(providerId),\r
-                    m_messageCb(NULL), m_syncInfoCb(NULL) {}\r
+                    m_topicList(new NSTopicsList()), m_messageCb(NULL), m_syncInfoCb(NULL) {}\r
+\r
+                /**\r
+                      * Constructor of NSProvider.\r
+                      *\r
+                      * @param providerId - providerId of the Notification.\r
+                      * @param topicList - NSTopicsList of interested Topics.\r
+                      */\r
+                NSProvider(const std::string &providerId, NSTopicsList *topicList) : m_providerId(\r
+                        providerId), m_topicList(topicList), m_messageCb(NULL), m_syncInfoCb(NULL) {}\r
 \r
                 /**\r
                       * Constructor of NSProvider.\r
@@ -81,7 +92,7 @@ namespace OIC
                 /**\r
                       * Destructor of NSProvider.\r
                       */\r
-                ~NSProvider() = default;\r
+                ~NSProvider();\r
 \r
                 /**\r
                       * This method is for getting ProviderId from the Notification service provider.\r
@@ -91,6 +102,13 @@ namespace OIC
                 std::string getProviderId() const;\r
 \r
                 /**\r
+                      * This method is for getting NSTopic List from the Notification service provider.\r
+                      *\r
+                      * @return NSTopicsList  as pointer.\r
+                      */\r
+                NSTopicsList *getTopicList() const;\r
+\r
+                /**\r
                       * This method is for requesting subscription of Notification service.\r
                       *\r
                       */\r
@@ -120,6 +138,14 @@ namespace OIC
                                  SyncInfoReceivedCallback syncHandle);\r
 \r
                 /**\r
+                     * Select Topic list that is wanted to subscribe from provider\r
+                     *\r
+                     * @param topicList - NSTopicsList of interested Topics.\r
+                     * @return NSResult\r
+                     */\r
+                NSResult selectInterestTopics(NSTopicsList *topicList);\r
+\r
+                /**\r
                       * This method is for getting the registered cb of Notification message received.\r
                       *\r
                       * @return messageCb - MessageReceivedCallback .\r
@@ -138,6 +164,7 @@ namespace OIC
 \r
             private:\r
                 std::string m_providerId;\r
+                NSTopicsList *m_topicList;\r
                 MessageReceivedCallback m_messageCb;\r
                 SyncInfoReceivedCallback m_syncInfoCb;\r
 \r
index d4eb618..18ebf51 100755 (executable)
@@ -43,24 +43,35 @@ namespace OIC
         void onNSProviderChanged(::NSProvider *provider, ::NSResponse response)\r
         {\r
             NS_LOG(DEBUG, "onNSProviderChanged - IN");\r
-            NS_LOG_V(DEBUG, "provider Id : %s",provider->providerId);\r
-            NS_LOG_V(DEBUG, "response : %d",(int)response);\r
-            \r
+            NS_LOG_V(DEBUG, "provider Id : %s", provider->providerId);\r
+            NS_LOG_V(DEBUG, "response : %d", (int)response);\r
+\r
             NSProvider *nsProvider = new NSProvider(provider);\r
             auto changeCallback = NSConsumerService::getInstance()->getConsumerConfig().m_changedCb;\r
-            if(response == NS_ALLOW)\r
+            if (response == NS_ALLOW)\r
             {\r
                 NSConsumerService::getInstance()->getAcceptedProviders().push_back(nsProvider);\r
                 if (changeCallback != NULL)\r
                     changeCallback(nsProvider, (NSResponse) response);\r
             }\r
-            else if(response == NS_DENY)\r
+            else if (response == NS_DENY)\r
             {\r
                 NSConsumerService::getInstance()->getAcceptedProviders().remove(nsProvider);\r
                 if (changeCallback != NULL)\r
                     changeCallback(nsProvider, (NSResponse) response);\r
                 delete nsProvider;\r
             }\r
+            else if (response == NS_TOPIC)\r
+            {\r
+                NSProvider *oldProvider = NSConsumerService::getInstance()->getProvider(\r
+                                              nsProvider->getProviderId());\r
+                if (oldProvider != nullptr)\r
+                {\r
+                    NSConsumerService::getInstance()->getAcceptedProviders().remove(oldProvider);\r
+                    NSConsumerService::getInstance()->getAcceptedProviders().push_back(nsProvider);\r
+                    delete oldProvider;\r
+                }\r
+            }\r
             NS_LOG(DEBUG, "onNSProviderChanged - OUT");\r
         }\r
 \r
@@ -130,7 +141,7 @@ namespace OIC
             m_config = config;\r
             NSConsumerConfig nsConfig;\r
             nsConfig.discoverCb = onNSProviderDiscovered;\r
-            nsConfig.changedCb= onNSProviderChanged;\r
+            nsConfig.changedCb = onNSProviderChanged;\r
             nsConfig.messageCb = onNSMessageReceived;\r
             nsConfig.syncInfoCb = onNSSyncInfoReceived;\r
 \r
@@ -178,6 +189,18 @@ namespace OIC
             return NULL;\r
         }\r
 \r
+        NSMessage *getMessage(uint64_t messageId)\r
+        {\r
+            NS_LOG(DEBUG, "getMessage - IN");\r
+            ::NSMessage *message = NSConsumerGetMessage(messageId);\r
+            NSMessage *nsMessage = new NSMessage(message);\r
+\r
+            delete message->mediaContents;\r
+            delete message;\r
+            NS_LOG(DEBUG, "getMessage - OUT");\r
+            return nsMessage;\r
+        }\r
+\r
         NSConsumerService::ConsumerConfig NSConsumerService::getConsumerConfig()\r
         {\r
             return m_config;\r
index 7aa94be..c65e552 100755 (executable)
@@ -23,7 +23,6 @@
 #include "NSConsumerInterface.h"\r
 #include "NSConstants.h"\r
 #include "NSCommon.h"\r
-#include "NSUtils.h"\r
 #include "oic_string.h"\r
 \r
 namespace OIC\r
@@ -34,6 +33,27 @@ namespace OIC
         {\r
             ::NSProvider *provider = new ::NSProvider;\r
             OICStrcpy(provider->providerId, NS_UTILS_UUID_STRING_SIZE, m_providerId.c_str());\r
+\r
+            provider->topicLL = NULL;\r
+\r
+            if (m_topicList != nullptr)\r
+            {\r
+                for (auto it : m_topicList->getTopicsList())\r
+                {\r
+                    ::NSTopicLL *topic = new ::NSTopicLL;\r
+                    OICStrcpy(topic->topicName, it->getTopicName().length(),\r
+                              it->getTopicName().c_str());\r
+                    topic->state = (::NSTopicState)it->getState();\r
+                    topic->next = NULL;\r
+                    if (provider->topicLL == NULL)\r
+                        provider->topicLL = topic;\r
+                    else\r
+                    {\r
+                        topic->next = provider->topicLL;\r
+                        provider->topicLL = topic;\r
+                    }\r
+                }\r
+            }\r
             return provider;\r
         }\r
 \r
@@ -44,14 +64,29 @@ namespace OIC
             if (provider != nullptr)\r
             {\r
                 m_providerId.assign(provider->providerId, NS_UTILS_UUID_STRING_SIZE);\r
+                if (provider->topicLL != nullptr)\r
+                    m_topicList = new NSTopicsList(provider->topicLL);\r
+                else\r
+                    m_topicList = new NSTopicsList();\r
             }\r
         }\r
 \r
+        NSProvider::~NSProvider()\r
+        {\r
+            if (m_topicList != nullptr)\r
+                delete m_topicList;\r
+        }\r
+\r
         std::string NSProvider::getProviderId() const\r
         {\r
             return m_providerId;\r
         }\r
 \r
+        NSTopicsList *NSProvider::getTopicList() const\r
+        {\r
+            return m_topicList;\r
+        }\r
+\r
         void NSProvider::subscribe()\r
         {\r
             NS_LOG(DEBUG, "subscribe - IN");\r
@@ -81,6 +116,17 @@ namespace OIC
             m_syncInfoCb = syncHandle;\r
         }\r
 \r
+        NSResult NSProvider::selectInterestTopics(NSTopicsList *topicList)\r
+        {\r
+            NS_LOG(DEBUG, "selectInterestTopics - IN");\r
+            NSProvider *provider = new NSProvider(getProviderId(), topicList);\r
+            NSResult result = (NSResult) NSConsumerSelectInterestTopics(\r
+                                  provider->getNSProvider());\r
+            delete provider;\r
+            NS_LOG(DEBUG, "selectInterestTopics - OUT");\r
+            return result;\r
+        }\r
+\r
         NSProvider::MessageReceivedCallback NSProvider::getMessageReceivedCb()\r
         {\r
             return m_messageCb;\r
index fe2af59..effe625 100755 (executable)
@@ -24,6 +24,7 @@
 #include "NSConsumerService.h"\r
 #include "NSMessage.h"\r
 #include "NSProvider.h"\r
+#include "NSTopicsList.h"\r
 #include "ocstack.h"\r
 \r
 #define TAG "NotiConsumerWrapperExample"\r
@@ -32,6 +33,7 @@ using namespace OIC::Service;
 \r
 bool isExit = false;\r
 std::string REMOTE_SERVER_ADDRESS;\r
+std::string mainProvider;\r
 \r
 void onNotificationPostedCb(OIC::Service::NSMessage *notification)\r
 {\r
@@ -39,6 +41,7 @@ void onNotificationPostedCb(OIC::Service::NSMessage *notification)
     std::cout << "title : " << notification->getTitle() << std::endl;\r
     std::cout << "content : " <<  notification->getContentText() << std::endl;\r
     std::cout << "source : " <<  notification->getSourceName() << std::endl;\r
+    std::cout << "topic : " <<  notification->getTopic() << std::endl;\r
 }\r
 \r
 void onNotificationSyncCb(OIC::Service::NSSyncInfo *sync)\r
@@ -54,12 +57,68 @@ void onDiscoverNotificationCb(OIC::Service::NSProvider *provider)
     std::cout << "startSubscribing" << std::endl;\r
 }\r
 \r
-void onProviderChangedCb(OIC::Service::NSProvider *provider,OIC::Service::NSResponse response)\r
+void onProviderChangedCb(OIC::Service::NSProvider *provider, OIC::Service::NSResponse response)\r
 {\r
     std::cout << "Subscription accepted" << std::endl;\r
     std::cout << "subscribed provider Id : " << provider->getProviderId() << std::endl;\r
-    if(response == OIC::Service::NSResponse::ALLOW)\r
+    if (response == OIC::Service::NSResponse::ALLOW)\r
+    {\r
         provider->setListener(onNotificationPostedCb, onNotificationSyncCb);\r
+        if (mainProvider.empty())\r
+            mainProvider = provider->getProviderId();\r
+    }\r
+    else if (response == OIC::Service::NSResponse::TOPIC)\r
+    {\r
+        std::cout << "Provider Topic Updated" << std::endl;\r
+        for (auto it : provider->getTopicList()->getTopicsList())\r
+        {\r
+            std::cout << "Topic Name: " << it->getTopicName() << std::endl;\r
+            std::cout << "Topic state: " << (int) it->getState() << std::endl;\r
+        }\r
+\r
+        std::cout << "7. Get Topics" << std::endl;\r
+        std::cout << "8. Select Topics" << std::endl;\r
+        std::cout << "0. Exit" << std::endl;\r
+        std::cout << "input: " << std::endl;\r
+\r
+        int num = 0;\r
+        std::cin >> num;\r
+        switch (num)\r
+        {\r
+            case 7:\r
+                {\r
+                    std::cout <<  "getInterestTopics" << std::endl;\r
+                    if (provider != nullptr)\r
+                    {\r
+                        auto topicList = provider->getTopicList();\r
+                        if (topicList != nullptr)\r
+                            for (auto it : topicList->getTopicsList())\r
+                            {\r
+                                std::cout << "Topic Name: " << it->getTopicName() << std::endl;\r
+                                std::cout << "Topic state: " << (int) it->getState() << std::endl;\r
+                            }\r
+                    }\r
+                }\r
+                break;\r
+            case 8:\r
+                {\r
+                    std::cout <<  "selectInterestTopics" << std::endl;\r
+                    if (provider != nullptr)\r
+                    {\r
+                        NSTopicsList *topicList = new NSTopicsList();\r
+                        topicList->addTopic("OCF_TOPIC1", NSTopic::NSTopicState::UNSUBSCRIBED);\r
+                        topicList->addTopic("OCF_TOPIC2", NSTopic::NSTopicState::UNSUBSCRIBED);\r
+                        topicList->addTopic("OCF_TOPIC3", NSTopic::NSTopicState::UNSUBSCRIBED);\r
+\r
+                        provider->selectInterestTopics(topicList);\r
+                    }\r
+                }\r
+                break;\r
+            case 0:\r
+            default:\r
+                break;\r
+        }\r
+    }\r
 }\r
 \r
 void *OCProcessThread(void *ptr)\r
@@ -103,10 +162,12 @@ int main(void)
 \r
         std::cout << "1. Start Consumer" << std::endl;\r
         std::cout << "2. Stop Consumer" << std::endl;\r
+        std::cout << "3. getInterestTopics" << std::endl;\r
+        std::cout << "4. selectInterestTopics" << std::endl;\r
 #ifdef WITH_CLOUD\r
-        std::cout << "3. Enable  NS Consumer RemoteService" << std::endl;\r
+        std::cout << "5. Enable  NS Consumer RemoteService" << std::endl;\r
 #endif\r
-        std::cout << "5. Exit" << std::endl;\r
+        std::cout << "6. Exit" << std::endl;\r
 \r
         std::cout << "Input: " << std::endl;\r
         std::cin >> num;\r
@@ -120,18 +181,49 @@ int main(void)
                 std::cout << "2. Stop the Notification Consumer" << std::endl;\r
                 NSConsumerService::getInstance()->Stop();\r
                 break;\r
-#ifdef WITH_CLOUD\r
             case 3:\r
                 {\r
-                    std::cout << "3. Enable NS Consumer RemoteService" << std::endl;\r
+                    std::cout <<  "getInterestTopics" << std::endl;\r
+                    OIC::Service::NSProvider *provider = NSConsumerService::getInstance()->getProvider(mainProvider);\r
+                    if (provider != nullptr)\r
+                    {\r
+                        auto topicList = provider->getTopicList();\r
+                        if (topicList != nullptr)\r
+                            for (auto it : topicList->getTopicsList())\r
+                            {\r
+                                std::cout << "Topic Name: " << it->getTopicName() << std::endl;\r
+                                std::cout << "Topic state: " << (int) it->getState() << std::endl;\r
+                            }\r
+                    }\r
+                }\r
+                break;\r
+            case 4:\r
+                {\r
+                    std::cout <<  "selectInterestTopics" << std::endl;\r
+                    OIC::Service::NSProvider *provider = NSConsumerService::getInstance()->getProvider(mainProvider);\r
+                    if (provider != nullptr)\r
+                    {\r
+                        NSTopicsList *topicList = new NSTopicsList();\r
+                        topicList->addTopic("OCF_TOPIC1", NSTopic::NSTopicState::UNSUBSCRIBED);\r
+                        topicList->addTopic("OCF_TOPIC2", NSTopic::NSTopicState::UNSUBSCRIBED);\r
+                        topicList->addTopic("OCF_TOPIC3", NSTopic::NSTopicState::UNSUBSCRIBED);\r
+\r
+                        provider->selectInterestTopics(topicList);\r
+                    }\r
+                }\r
+                break;\r
+#ifdef WITH_CLOUD\r
+            case 5:\r
+                {\r
+                    std::cout << "5. Enable NS Consumer RemoteService" << std::endl;\r
                     std::cout << "Input the Server Address :";\r
                     std::cin >> REMOTE_SERVER_ADDRESS;\r
                     NSConsumerService::getInstance()->EnableRemoteService(REMOTE_SERVER_ADDRESS);\r
                     break;\r
                 }\r
 #endif\r
-            case 5:\r
-                std::cout << "5. Exit" << std::endl;\r
+            case 6:\r
+                std::cout << "6. Exit" << std::endl;\r
                 isExit = true;\r
                 break;\r
             default:\r
index 339d1f0..ca2a37d 100755 (executable)
@@ -22,6 +22,8 @@
 #include <stdlib.h>\r
 #include "NSCommon.h"\r
 #include "NSProviderService.h"\r
+#include "NSUtils.h"\r
+#include "NSTopicsList.h"\r
 #include "logger.h"\r
 #include "octypes.h"\r
 #include "pthread.h"\r
@@ -32,6 +34,7 @@
 #define TAG "NotiProviderWrapperExample"\r
 using namespace std;\r
 using namespace OIC::Service;\r
+std::string mainConsumer;\r
 \r
 extern char *strdup(const char *s);\r
 \r
@@ -60,6 +63,8 @@ void subscribeRequestCallback(OIC::Service::NSConsumer *consumer)
     std::cout << "consumer requested to subscribe" << std::endl;\r
 \r
     std::cout << "Consumer Device ID: " << consumer->getConsumerId() << std::endl;\r
+    if (mainConsumer.empty())\r
+        mainConsumer = consumer->getConsumerId();\r
     consumer->acceptSubscription(consumer, true);\r
 }\r
 \r
@@ -92,11 +97,18 @@ int main()
         std::cout << "2. Start the Notification Provider(Accepter: Consumer)" << std::endl;\r
         std::cout << "3. SendMessage " << std::endl;\r
         std::cout << "4. SendSyncInfo" << std::endl;\r
+\r
+        std::cout << "5. AddTopic" << std::endl;\r
+        std::cout << "6. DeleteTopic" << std::endl;\r
+        std::cout << "7. SelectTopic" << std::endl;\r
+        std::cout << "8. UnselectTopic" << std::endl;\r
+        std::cout << "9. GetConsumerTopics" << std::endl;\r
+        std::cout << "10. GetTopics" << std::endl;\r
 #ifdef WITH_CLOUD\r
-        std::cout << "5. Enable NS Provider RemoteService" << std::endl;\r
-        std::cout << "6. Disable NS Provider RemoteService" << std::endl;\r
+        std::cout << "11. Enable NS Provider RemoteService" << std::endl;\r
+        std::cout << "12. Disable NS Provider RemoteService" << std::endl;\r
 #endif\r
-        std::cout << "9. Stop the Notification Provider" << std::endl;\r
+        std::cout << "13. Stop the Notification Provider" << std::endl;\r
         std::cout << "0. Exit()" << std::endl;\r
 \r
         std::cout << "input : ";\r
@@ -111,7 +123,7 @@ int main()
                     NSProviderService::ProviderConfig cfg;\r
                     cfg.m_subscribeRequestCb = subscribeRequestCallback;\r
                     cfg.m_syncInfoCb = syncCallback;\r
-                    cfg.policy = (bool) NSProviderService::NSAccessPolicy::NS_ACCESS_ALLOW;\r
+                    cfg.policy = true;\r
 \r
                     NSProviderService::getInstance()->Start(cfg);\r
                     break;\r
@@ -122,7 +134,7 @@ int main()
                     NSProviderService::ProviderConfig cfg;\r
                     cfg.m_subscribeRequestCb = subscribeRequestCallback;\r
                     cfg.m_syncInfoCb = syncCallback;\r
-                    cfg.policy = (bool) NSProviderService::NSAccessPolicy::NS_ACCESS_DENY;\r
+                    cfg.policy = false;\r
 \r
                     NSProviderService::getInstance()->Start(cfg);\r
                     break;\r
@@ -133,6 +145,7 @@ int main()
 \r
                     std::string title;\r
                     std::string body;\r
+                    std::string topic;\r
 \r
                     std::cout << "id : " << ++id << std::endl;\r
                     std::cout << "title : ";\r
@@ -142,8 +155,12 @@ int main()
                     std::cout << "body : ";\r
                     std::cin >> body;\r
 \r
+                    std::cout << "topic : ";\r
+                    std::cin >> topic;\r
+\r
                     std::cout << "app - mTitle : " << title << std::endl;\r
                     std::cout << "app - mContentText : " << body << std::endl;\r
+                    std::cout << "app - mTopic : " << topic << std::endl;\r
 \r
                     OIC::Service::NSMessage *msg = NSProviderService::getInstance()->CreateMessage();\r
 \r
@@ -163,24 +180,100 @@ int main()
                             OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);\r
                     break;\r
                 }\r
-#ifdef WITH_CLOUD\r
+\r
             case 5:\r
+                std::cout <<  "AddTopic" << std::endl;\r
+                NSProviderService::getInstance()->AddTopic("OCF_TOPIC1");\r
+                NSProviderService::getInstance()->AddTopic("OCF_TOPIC2");\r
+                NSProviderService::getInstance()->AddTopic("OCF_TOPIC3");\r
+                NSProviderService::getInstance()->AddTopic("OCF_TOPIC4");\r
+                break;\r
+\r
+            case 6:\r
+                std::cout <<  "DeleteTopic" << std::endl;\r
+                NSProviderService::getInstance()->DeleteTopic("OCF_TOPIC2");\r
+                break;\r
+\r
+            case 7:\r
+                {\r
+                    std::cout <<  "SelectTopic" << std::endl;\r
+                    OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(mainConsumer);\r
+                    if (consumer != nullptr)\r
+                    {\r
+                        consumer->selectTopic("OCF_TOPIC1");\r
+                        consumer->selectTopic("OCF_TOPIC2");\r
+                        consumer->selectTopic("OCF_TOPIC3");\r
+                        consumer->selectTopic("OCF_TOPIC4");\r
+                        std::cout <<  "SelectTopic completed" << std::endl;\r
+                    }\r
+                    break;\r
+                }\r
+            case 8:\r
+                {\r
+                    std::cout <<  "UnSelectTopic" << std::endl;\r
+                    OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(mainConsumer);\r
+                    if (consumer != nullptr)\r
+                    {\r
+                        consumer->unselectTopic("OCF_TOPIC1");\r
+                        std::cout <<  "UnSelectTopic completed" << std::endl;\r
+                    }\r
+                    break;\r
+                }\r
+                break;\r
+\r
+            case 9:\r
+                {\r
+                    std::cout <<  "GetConsumerTopics" << std::endl;\r
+                    OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(mainConsumer);\r
+                    if (consumer != nullptr)\r
+                    {\r
+                        auto nsTopics = consumer->getConsumerTopics();\r
+                        if (nsTopics != nullptr)\r
+                        {\r
+                            for (auto it : nsTopics->getTopicsList())\r
+                            {\r
+\r
+                                std::cout << it->getTopicName() << std::endl;\r
+                                std::cout << (int) it->getState() << std::endl;\r
+                            }\r
+                            delete nsTopics;\r
+                        }\r
+                        std::cout <<  "GetConsumerTopics completed" << std::endl;\r
+                    }\r
+                }\r
+                break;\r
+\r
+            case 10:\r
                 {\r
-                    std::cout << "3. Enable NS Provider RemoteService" << std::endl;\r
+                    std::cout <<  "GetTopics" << std::endl;\r
+                    auto nsTopics = NSProviderService::getInstance()->GetTopics();\r
+                    for (auto it : nsTopics->getTopicsList())\r
+                    {\r
+\r
+                        std::cout << it->getTopicName() << std::endl;\r
+                        std::cout << (int) it->getState() << std::endl;\r
+                    }\r
+                    delete nsTopics;\r
+                }\r
+                break;\r
+#ifdef WITH_CLOUD\r
+            case 11:\r
+                {\r
+                    std::cout << "11. Enable NS Provider RemoteService" << std::endl;\r
                     std::cout << "Input the Server Address :";\r
                     std::cin >> REMOTE_SERVER_ADDRESS;\r
                     NSProviderService::getInstance()->EnableRemoteService(REMOTE_SERVER_ADDRESS);\r
                     break;\r
                 }\r
-            case 6:\r
+            case 12:\r
                 {\r
-                    std::cout << "3. Disable NS Provider RemoteService" << std::endl;\r
+                    std::cout << "12. Disable NS Provider RemoteService" << std::endl;\r
                     std::cout << "Input the Server Address :";\r
                     NSProviderService::getInstance()->DisableRemoteService(REMOTE_SERVER_ADDRESS);\r
                     break;\r
                 }\r
 #endif\r
-            case 9:\r
+            case 13:\r
                 NSProviderService::getInstance()->Stop();\r
                 break;\r
             case 0:\r
index ed2bc56..c71c666 100755 (executable)
@@ -30,6 +30,8 @@
 \r
 #include <string>\r
 #include "NSCommon.h"\r
+#include "NSUtils.h"\r
+#include "NSTopicsList.h"\r
 \r
 namespace OIC\r
 {\r
@@ -50,7 +52,7 @@ namespace OIC
                 /**\r
                       * Constructor of NSConsumer.\r
                       *\r
-                      * @param consumerId - consumerId of the Notification service Consumer.\r
+                      * @param consumerId -consumerId of the Notification service Consumer.\r
                       */\r
                 NSConsumer(const std::string &consumerId)\r
                     : m_consumerId(consumerId) {}\r
@@ -82,6 +84,26 @@ namespace OIC
                       */\r
                 int acceptSubscription(NSConsumer *consumer, bool accepted);\r
 \r
+                /**\r
+                     * Select a topic name for a consumer\r
+                     * @param[in]  topicName Topic name to select\r
+                     * @return :: OK or result code of NSResult\r
+                     */\r
+                NSResult selectTopic(const std::string &topicName);\r
+\r
+                /**\r
+                     * Unselect a topic from the topic list for consumer\r
+                     * @param[in]  topicName Topic name to unselect\r
+                     * @return :: OK or result code of NSResult\r
+                     */\r
+                NSResult unselectTopic(const std::string &topicName);\r
+\r
+                /**\r
+                     * Request topic list with selection state for the consumer\r
+                     * @return :: Topic list\r
+                     */\r
+                NSTopicsList *getConsumerTopics();\r
+\r
             private:\r
                 ::NSConsumer *getNSConsumer();\r
 \r
index deed41f..75ca9a2 100755 (executable)
@@ -32,6 +32,7 @@
 #include "NSSyncInfo.h"\r
 #include "NSMessage.h"\r
 #include "NSUtils.h"\r
+#include "NSTopicsList.h"\r
 \r
 namespace OIC\r
 {\r
@@ -81,15 +82,6 @@ namespace OIC
                 } ProviderConfig;\r
 \r
                 /**\r
-                     * Access policy exchanged between provider and consumer during subscription process\r
-                     */\r
-                enum class NSAccessPolicy\r
-                {\r
-                    NS_ACCESS_ALLOW = 0,\r
-                    NS_ACCESS_DENY = 1,\r
-                };\r
-\r
-                /**\r
                       * API for starting the NS Provider\r
                       *\r
                       * @return NSProviderService Pointer to singleton instance created\r
@@ -147,13 +139,48 @@ namespace OIC
                 NSMessage *CreateMessage();\r
 \r
                 /**\r
+                      *  request to get NSConsumer pointer\r
+                      * @param id -id as string\r
+                      *\r
+                      * @return pointer to NSConsumer\r
+                      */\r
+                NSConsumer *getConsumer(const std::string &id);\r
+\r
+                /**\r
+                     * Add topic to topic list which is located in provider service storage\r
+                     * @param[in]  topicName Topic name to add\r
+                     * @return :: OK or result code of NSResult\r
+                     */\r
+                NSResult AddTopic(const std::string &topicName);\r
+\r
+                /**\r
+                     * Delete topic from topic list\r
+                     * @param[in]  topicName Topic name to delete\r
+                     * @return :: OK or result code of NSResult\r
+                     */\r
+                NSResult DeleteTopic(const std::string &topicName);\r
+\r
+                /**\r
+                     * Request topics list already registered by provider user\r
+                     * @return :: Topic list\r
+                     */\r
+                NSTopicsList *GetTopics();\r
+\r
+                /**\r
                       *  get Provider config values\r
                       * @return ProviderConfig callbaks set\r
                       */\r
                 ProviderConfig getProviderConfig();\r
 \r
+                /**\r
+                      *  get list of Consumers accepted.\r
+                      * @return m_acceptedConsumers -list of accepted Consumers\r
+                      */\r
+                std::list<NSConsumer *> getAcceptedConsumers();\r
+\r
             private :\r
                 ProviderConfig m_config;\r
+                std::list<NSConsumer *> m_acceptedConsumers;\r
 \r
             private:\r
                 NSProviderService()\r
@@ -161,7 +188,7 @@ namespace OIC
                     m_config.m_subscribeRequestCb = NULL;\r
                     m_config.m_syncInfoCb = NULL;\r
                 }\r
-                ~NSProviderService() = default;\r
+                ~NSProviderService();\r
                 NSProviderService(const NSProviderService &) = delete;\r
                 NSProviderService &operator=(const NSProviderService &) = delete;\r
                 NSProviderService(const NSProviderService &&) = delete;\r
index e4d35bf..7c99f3d 100755 (executable)
@@ -22,8 +22,8 @@
 #include <cstring>\r
 #include "NSProviderInterface.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
@@ -57,5 +57,33 @@ namespace OIC
             NS_LOG(DEBUG, "acceptSubscription - OUT");\r
             return NS_ERROR;\r
         }\r
+\r
+        NSResult NSConsumer::selectTopic(const std::string &topicName)\r
+        {\r
+            NS_LOG(DEBUG, "selectTopic - IN");\r
+            NSResult result = (NSResult) NSProviderSelectTopic(OICStrdup(getConsumerId().c_str()),\r
+                              OICStrdup(topicName.c_str()));\r
+            NS_LOG(DEBUG, "selectTopic - OUT");\r
+            return result;\r
+        }\r
+\r
+        NSResult NSConsumer::unselectTopic(const std::string &topicName)\r
+        {\r
+            NS_LOG(DEBUG, "unselectTopic - IN");\r
+            NSResult result = (NSResult) NSProviderUnselectTopic(OICStrdup(getConsumerId().c_str()),\r
+                              OICStrdup(topicName.c_str()));\r
+            NS_LOG(DEBUG, "unselectTopic - OUT");\r
+            return result;\r
+        }\r
+\r
+        NSTopicsList *NSConsumer::getConsumerTopics()\r
+        {\r
+            NS_LOG(DEBUG, "getConsumerTopics - IN");\r
+            ::NSTopicLL *topics = NSProviderGetConsumerTopics(OICStrdup(getConsumerId().c_str()));\r
+\r
+            NSTopicsList *nsTopics = new NSTopicsList(topics);\r
+            NS_LOG(DEBUG, "getConsumerTopics - OUT");\r
+            return nsTopics;\r
+        }\r
     }\r
 }\r
index af34fa6..0df46f7 100755 (executable)
 #include <cstring>\r
 #include "NSCommon.h"\r
 #include "NSProviderInterface.h"\r
-#include "oic_string.h"\r
 #include "NSConsumer.h"\r
 #include "NSSyncInfo.h"\r
 #include "NSConstants.h"\r
+#include "oic_string.h"\r
+#include "oic_malloc.h"\r
 \r
 namespace OIC\r
 {\r
@@ -38,7 +39,7 @@ namespace OIC
             NSConsumer *nsConsumer = new NSConsumer(consumer);\r
             if (NSProviderService::getInstance()->getProviderConfig().m_subscribeRequestCb != NULL)\r
                 NSProviderService::getInstance()->getProviderConfig().m_subscribeRequestCb(nsConsumer);\r
-            delete nsConsumer;\r
+            NSProviderService::getInstance()->getAcceptedConsumers().push_back(nsConsumer);\r
             NS_LOG(DEBUG, "onConsumerSubscribedCallback - OUT");\r
         }\r
 \r
@@ -72,6 +73,15 @@ namespace OIC
             return nsMsg;\r
         }\r
 \r
+        NSProviderService::~NSProviderService()\r
+        {\r
+            for (auto it : getAcceptedConsumers())\r
+            {\r
+                delete it;\r
+            }\r
+            getAcceptedConsumers().clear();\r
+        }\r
+\r
         NSProviderService *NSProviderService::getInstance()\r
         {\r
             static NSProviderService s_instance;\r
@@ -134,7 +144,7 @@ namespace OIC
             NSResult result = NSResult::ERROR;\r
             if (msg != nullptr)\r
             {\r
-                ::NSMessage * nsMsg = getNSMessage(msg);\r
+                ::NSMessage *nsMsg = getNSMessage(msg);\r
                 result = (NSResult) NSSendMessage(nsMsg);\r
                 delete nsMsg->mediaContents;\r
                 delete nsMsg;\r
@@ -168,9 +178,50 @@ namespace OIC
             return nsMessage;\r
         }\r
 \r
+        NSConsumer *NSProviderService::getConsumer(const std::string &id)\r
+        {\r
+            for (auto it : getAcceptedConsumers())\r
+            {\r
+                if (it->getConsumerId() == id)\r
+                    return it;\r
+            }\r
+            return NULL;\r
+        }\r
+\r
+        NSResult NSProviderService::AddTopic(const std::string &topicName)\r
+        {\r
+            NS_LOG(DEBUG, "AddTopic - IN");\r
+            NSResult result = (NSResult) NSProviderAddTopic(OICStrdup(topicName.c_str()));\r
+            NS_LOG(DEBUG, "AddTopic - OUT");\r
+            return result;\r
+        }\r
+\r
+        NSResult NSProviderService::DeleteTopic(const std::string &topicName)\r
+        {\r
+            NS_LOG(DEBUG, "DeleteTopic - IN");\r
+            NSResult result = (NSResult) NSProviderDeleteTopic(OICStrdup(topicName.c_str()));\r
+            NS_LOG(DEBUG, "DeleteTopic - OUT");\r
+            return result;\r
+        }\r
+\r
+        NSTopicsList *NSProviderService::GetTopics()\r
+        {\r
+            NS_LOG(DEBUG, "GetTopics - IN");\r
+            ::NSTopicLL *topics = NSProviderGetTopics();\r
+\r
+            NSTopicsList *nsTopics = new NSTopicsList(topics);\r
+            NS_LOG(DEBUG, "GetTopics - OUT");\r
+            return nsTopics;\r
+        }\r
+\r
         NSProviderService::ProviderConfig NSProviderService::getProviderConfig()\r
         {\r
             return m_config;\r
         }\r
+\r
+        std::list<NSConsumer *> NSProviderService::getAcceptedConsumers()\r
+        {\r
+            return m_acceptedConsumers;\r
+        }\r
     }\r
 }\r