# SConscript('android/SConscript')
# Go to build c++ wrapper
-#SConscript('cpp-wrapper/SConscript')
+SConscript('cpp-wrapper/SConscript')
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
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
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
* 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
*/\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
std::string m_contentText;\r
std::string m_sourceName;\r
NSMediaContents *m_mediaContents;\r
+ std::string m_topic;\r
\r
};\r
}\r
--- /dev/null
+//******************************************************************
+//
+// 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;
+ }
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// 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_ */
--- /dev/null
+//******************************************************************
+//
+// 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;
+ }
+ }
+}
--- /dev/null
+//******************************************************************
+//
+// 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_ */
SUCCESS = 300,
FAIL = 400,
};
-
+
/**
* NSResponse code of notification service
*/
*/\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
#include <string>\r
#include "NSSyncInfo.h"\r
#include "NSMessage.h"\r
+#include "NSUtils.h"\r
+#include "NSTopicsList.h"\r
\r
namespace OIC\r
{\r
/**\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
* @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
/**\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
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
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
\r
private:\r
std::string m_providerId;\r
+ NSTopicsList *m_topicList;\r
MessageReceivedCallback m_messageCb;\r
SyncInfoReceivedCallback m_syncInfoCb;\r
\r
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
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
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
#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
{\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
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
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
#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
\r
bool isExit = false;\r
std::string REMOTE_SERVER_ADDRESS;\r
+std::string mainProvider;\r
\r
void onNotificationPostedCb(OIC::Service::NSMessage *notification)\r
{\r
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
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
\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
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
#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
#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
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
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
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
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
\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
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
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
\r
#include <string>\r
#include "NSCommon.h"\r
+#include "NSUtils.h"\r
+#include "NSTopicsList.h"\r
\r
namespace OIC\r
{\r
/**\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
*/\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
#include "NSSyncInfo.h"\r
#include "NSMessage.h"\r
#include "NSUtils.h"\r
+#include "NSTopicsList.h"\r
\r
namespace OIC\r
{\r
} 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
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
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
#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
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
#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
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
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
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
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