Updated NS sample App to allow/deny consumer subscription.
Change-Id: I6f3609895cbfe2d4d8b18247b7e7dd4c7a438161
Signed-off-by: abitha.s <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14369
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
#include "NSCommon.h"\r
#include "NSConstants.h"\r
#include "oic_string.h"\r
+#include "oic_malloc.h"\r
\r
namespace OIC\r
{\r
NS_LOG(DEBUG, "initiating the callback for Response : NS_TOPIC");\r
changeCallback((NSProviderState)state);\r
}\r
+ if (topicLL)\r
+ {\r
+ NSTopicLL *iter = topicLL;\r
+ NSTopicLL *following = NULL;\r
+\r
+ while (iter)\r
+ {\r
+ following = iter->next;\r
+ if (iter)\r
+ {\r
+ NSOICFree(iter->topicName);\r
+ iter->next = NULL;\r
+ NSOICFree(iter);\r
+ }\r
+ iter = following;\r
+ }\r
+ }\r
}\r
else if (state == NS_STOPPED)\r
{\r
getProviderId().c_str());\r
NSResult result = (NSResult) NSConsumerUpdateTopicList(getProviderId().c_str(), topicLL);\r
\r
- if(topicLL)\r
+ if (topicLL)\r
{\r
- NSTopicLL * iter = topicLL;\r
- NSTopicLL * following = NULL;\r
+ NSTopicLL *iter = topicLL;\r
+ NSTopicLL *following = NULL;\r
\r
while (iter)\r
{\r
following = iter->next;\r
- if(iter)\r
+ if (iter)\r
{\r
NSOICFree(iter->topicName);\r
iter->next = NULL;\r
std::string mainProvider;\r
uint64_t mainMessageId = 0;\r
\r
-FILE* server_fopen(const char *path, const char *mode)\r
+FILE *server_fopen(const char *path, const char *mode)\r
{\r
(void)path;\r
return fopen("oic_ns_provider_db.dat", mode);\r
std::cout << "type : " << (int) notification->getType() << std::endl;\r
std::cout << "TTL : " << notification->getTTL() << std::endl;\r
std::cout << "time : " << notification->getTime() << std::endl;\r
- if(notification->getMediaContents() != nullptr)\r
+ if (notification->getMediaContents() != nullptr)\r
{\r
std::cout << "MediaContents IconImage : " << notification->getMediaContents()->getIconImage()\r
- << std::endl;\r
+ << std::endl;\r
}\r
std::cout << "ExtraInfo " << std::endl;\r
OC::OCRepresentation rep = notification->getExtraInfo();\r
- for(auto it : rep.getResourceTypes())\r
+ for (auto it : rep.getResourceTypes())\r
{\r
std::cout << "resourceType : " << it << std::endl;\r
}\r
- for(auto it : rep.getResourceInterfaces())\r
+ for (auto it : rep.getResourceInterfaces())\r
{\r
std::cout << "Interface : " << it << std::endl;\r
}\r
- for(auto it : rep.getValues())\r
+ for (auto it : rep.getValues())\r
{\r
std::cout << "Key : " << it.first << std::endl;\r
}\r
switch (num)\r
{\r
case 1:\r
- std::cout << "Start the Notification Consumer" << std::endl;\r
- NSConsumerService::getInstance()->start(onDiscoverNotificationCb);\r
- break;\r
+ {\r
+ std::cout << "Start the Notification Consumer" << std::endl;\r
+ NSConsumerService::getInstance()->start(onDiscoverNotificationCb);\r
+ break;\r
+ }\r
case 2:\r
- std::cout << "Stop the Notification Consumer" << std::endl;\r
- NSConsumerService::getInstance()->stop();\r
- break;\r
+ {\r
+ std::cout << "Stop the Notification Consumer" << std::endl;\r
+ NSConsumerService::getInstance()->stop();\r
+ break;\r
+ }\r
case 3:\r
{\r
std::cout << "SendSyncInfo" << std::endl;\r
- if(!mainMessageId)\r
+ if (!mainMessageId)\r
{\r
std::cout << "Message ID is empty" << std::endl;\r
break;\r
std::cout << "1. Send Read Sync" << std::endl;\r
std::cout << "2. Send Delete Sync" << std::endl;\r
int syn = 0;\r
- while(!(std::cin >> syn)){\r
- std::cout << "Bad value!" <<std::endl;;\r
+ while (!(std::cin >> syn))\r
+ {\r
+ std::cout << "Bad value!" << std::endl;;\r
std::cin.clear();\r
std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
}\r
switch (syn)\r
{\r
case 1:\r
- {\r
- std::cout << "Sending Read Sync" << std::endl;\r
- auto provider = NSConsumerService::getInstance()->getProvider(\r
- mainProvider);\r
- if (provider != nullptr)\r
{\r
- provider->sendSyncInfo(mainMessageId,\r
- OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);\r
+ std::cout << "Sending Read Sync" << std::endl;\r
+ auto provider = NSConsumerService::getInstance()->getProvider(\r
+ mainProvider);\r
+ if (provider != nullptr)\r
+ {\r
+ provider->sendSyncInfo(mainMessageId,\r
+ OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);\r
+ }\r
}\r
- }\r
- break;\r
+ break;\r
case 2:\r
- {\r
- std::cout << "Sending Delete Sync" << std::endl;\r
- auto provider = NSConsumerService::getInstance()->getProvider(\r
- mainProvider);\r
- if (provider != nullptr)\r
{\r
- provider->sendSyncInfo(mainMessageId,\r
- OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED);\r
+ std::cout << "Sending Delete Sync" << std::endl;\r
+ auto provider = NSConsumerService::getInstance()->getProvider(\r
+ mainProvider);\r
+ if (provider != nullptr)\r
+ {\r
+ provider->sendSyncInfo(mainMessageId,\r
+ OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED);\r
+ }\r
}\r
- }\r
- break;\r
+ break;\r
default:\r
- {\r
- cout << "Invalid Input!. sending default Read Sync";\r
- auto provider = NSConsumerService::getInstance()->getProvider(\r
- mainProvider);\r
- if (provider != nullptr)\r
{\r
- provider->sendSyncInfo(mainMessageId,\r
- OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);\r
+ cout << "Invalid Input!. sending default Read Sync";\r
+ auto provider = NSConsumerService::getInstance()->getProvider(\r
+ mainProvider);\r
+ if (provider != nullptr)\r
+ {\r
+ provider->sendSyncInfo(mainMessageId,\r
+ OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);\r
+ }\r
+ std::cin.clear();\r
+ std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
+ break;\r
}\r
- std::cin.clear();\r
- std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
- break;\r
- }\r
}\r
break;\r
}\r
}\r
#endif\r
case 7:\r
- std::cout << "Exit" << std::endl;\r
- NSConsumerService::getInstance()->stop();\r
- isExit = true;\r
- break;\r
+ {\r
+ std::cout << "Exit" << std::endl;\r
+ NSConsumerService::getInstance()->stop();\r
+ isExit = true;\r
+ break;\r
+ }\r
default:\r
- std::cout << "Under Construction" << std::endl;\r
- std::cin.clear();\r
- std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
- break;\r
+ {\r
+ std::cout << "Under Construction" << std::endl;\r
+ std::cin.clear();\r
+ std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
+ break;\r
+ }\r
}\r
}\r
\r
(void) ptr;\r
while (!isExit)\r
{\r
+ usleep(2000);\r
if (OCProcess() != OC_STACK_OK)\r
{\r
std::cout << "OCStack process error" << std::endl;\r
std::cout << "Choose the Consumer ID for operation" << std::endl;\r
int pos = 1;\r
unsigned int option = 0;\r
- for(auto it: discoveredConsumers)\r
+ for (auto it : discoveredConsumers)\r
{\r
- std::cout << pos << ". " << it <<std::endl;\r
+ std::cout << pos << ". " << it << std::endl;\r
pos++;\r
}\r
- while(!(std::cin >> option)){\r
- std::cout << "Bad value!" <<std::endl;;\r
+ while (!(std::cin >> option))\r
+ {\r
+ std::cout << "Bad value!" << std::endl;;\r
std::cin.clear();\r
std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
}\r
option--;\r
if (option > discoveredConsumers.size())\r
+ {\r
return NULL;\r
+ }\r
std::string consumerId = discoveredConsumers[option];\r
OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(\r
- consumerId);\r
+ consumerId);\r
return consumer;\r
}\r
\r
msg->setTopic(topic);\r
msg->setTTL(40);\r
msg->setTime("12:30");\r
- OIC::Service::NSMediaContents *mediaContents = \r
- new OIC::Service::NSMediaContents("iconImage");\r
+ OIC::Service::NSMediaContents *mediaContents =\r
+ new OIC::Service::NSMediaContents("iconImage");\r
msg->setMediaContents(mediaContents);\r
\r
OC::OCRepresentation rep;\r
- rep.setValue("Key1","Value1");\r
- rep.setValue("Key2","Value2");\r
+ rep.setValue("Key1", "Value1");\r
+ rep.setValue("Key2", "Value2");\r
msg->setExtraInfo(rep);\r
\r
mainMessageId = msg->getMessageId();\r
std::cout << "MessageID for Message : " << msg->getMessageId() << std::endl;\r
\r
NSProviderService::getInstance()->sendMessage(msg);\r
- delete mediaContents;\r
+ delete msg;\r
break;\r
}\r
case 6:\r
std::cout << "------------------------------------" << std::endl;\r
std::cout << "SendSyncInfo" << std::endl;\r
std::cout << "------------------------------------" << std::endl;\r
- if(!mainMessageId)\r
+ if (!mainMessageId)\r
{\r
std::cout << "Message ID is empty" << std::endl;\r
break;\r
std::cout << "1. Send Read Sync" << std::endl;\r
std::cout << "2. Send Delete Sync" << std::endl;\r
int syn = 0;\r
- while(!(std::cin >> syn)){\r
- std::cout << "Bad value!" <<std::endl;;\r
+ while (!(std::cin >> syn))\r
+ {\r
+ std::cout << "Bad value!" << std::endl;;\r
std::cin.clear();\r
std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
}\r
switch (syn)\r
{\r
case 1:\r
- {\r
- std::cout << "Sending Read Sync" << std::endl;\r
- NSProviderService::getInstance()->sendSyncInfo(mainMessageId,\r
- OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);\r
- }\r
- break;\r
+ {\r
+ std::cout << "Sending Read Sync" << std::endl;\r
+ NSProviderService::getInstance()->sendSyncInfo(mainMessageId,\r
+ OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);\r
+ }\r
+ break;\r
case 2:\r
- {\r
- std::cout << "Sending Delete Sync" << std::endl;\r
- NSProviderService::getInstance()->sendSyncInfo(mainMessageId,\r
- OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED);\r
- }\r
- break;\r
- default:\r
- {\r
- cout << "Invalid Input!. sending default Read Sync";\r
- NSProviderService::getInstance()->sendSyncInfo(mainMessageId,\r
- OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);\r
- std::cin.clear();\r
- std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
+ {\r
+ std::cout << "Sending Delete Sync" << std::endl;\r
+ NSProviderService::getInstance()->sendSyncInfo(mainMessageId,\r
+ OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED);\r
+ }\r
break;\r
- }\r
+ default:\r
+ {\r
+ cout << "Invalid Input!. sending default Read Sync";\r
+ NSProviderService::getInstance()->sendSyncInfo(mainMessageId,\r
+ OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);\r
+ std::cin.clear();\r
+ std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
+ break;\r
+ }\r
}\r
break;\r
}\r
\r
case 7:\r
- std::cout << "RegisterTopic" << std::endl;\r
- NSProviderService::getInstance()->registerTopic("OCF_TOPIC1");\r
- NSProviderService::getInstance()->registerTopic("OCF_TOPIC2");\r
- NSProviderService::getInstance()->registerTopic("OCF_TOPIC3");\r
- NSProviderService::getInstance()->registerTopic("OCF_TOPIC4");\r
- break;\r
-\r
+ {\r
+ std::cout << "RegisterTopic" << std::endl;\r
+ NSProviderService::getInstance()->registerTopic("OCF_TOPIC1");\r
+ NSProviderService::getInstance()->registerTopic("OCF_TOPIC2");\r
+ NSProviderService::getInstance()->registerTopic("OCF_TOPIC3");\r
+ NSProviderService::getInstance()->registerTopic("OCF_TOPIC4");\r
+ break;\r
+ }\r
case 8:\r
- std::cout << "UnregisterTopic" << std::endl;\r
- NSProviderService::getInstance()->unregisterTopic("OCF_TOPIC2");\r
- break;\r
-\r
+ {\r
+ std::cout << "UnregisterTopic" << std::endl;\r
+ NSProviderService::getInstance()->unregisterTopic("OCF_TOPIC2");\r
+ break;\r
+ }\r
case 9:\r
{\r
std::cout << "SetTopic" << std::endl;\r
}\r
#endif\r
case 15:\r
- std::cout << "Stop the Notification Provider" << std::endl;\r
- NSProviderService::getInstance()->stop();\r
- break;\r
+ {\r
+ std::cout << "Stop the Notification Provider" << std::endl;\r
+ NSProviderService::getInstance()->stop();\r
+ break;\r
+ }\r
case 16:\r
- std::cout << "Exit()" << std::endl;\r
- NSProviderService::getInstance()->stop();\r
- isExit = true;\r
- break;\r
+ {\r
+ std::cout << "Exit()" << std::endl;\r
+ NSProviderService::getInstance()->stop();\r
+ isExit = true;\r
+ break;\r
+ }\r
default:\r
- std::cout << "Under Construction" << std::endl;\r
- std::cin.clear();\r
- std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
- break;\r
+ {\r
+ std::cout << "Under Construction" << std::endl;\r
+ std::cin.clear();\r
+ std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
+ break;\r
+ }\r
}\r
\r
std::cout << std::endl;\r
notification_env.PrependUnique(LIBS = [
'oc_logger',
'oc',
+ 'octbstack',
'notification_provider'
])
notification_env.AppendUnique(CXXFLAGS = ['-std=c++0x','-frtti'])
#include "NSSyncInfo.h"\r
#include "NSConstants.h"\r
#include "OCRepresentation.h"\r
+#include "ocpayload.h"\r
#include "oic_string.h"\r
#include "oic_malloc.h"\r
\r
OICFree(nsMsg->contentText);\r
OICFree(nsMsg->sourceName);\r
OICFree(nsMsg->topic);\r
- OICFree(nsMsg->extraInfo);\r
- delete nsMsg->mediaContents;\r
+ if (nsMsg->mediaContents != NULL)\r
+ {\r
+ if (nsMsg->mediaContents->iconImage != NULL)\r
+ {\r
+ OICFree(nsMsg->mediaContents->iconImage);\r
+ }\r
+ delete nsMsg->mediaContents;\r
+ }\r
+ OCPayloadDestroy((OCPayload *) nsMsg->extraInfo);\r
delete nsMsg;\r
}\r
else\r
class NSConsumerSimulator
{
-private:
- std::function<void(const int&, const std::string&, const std::string&,
- const std::string&)> m_messageFunc;
- std::function<void(const int&, const int&)> m_syncFunc;
-
- std::shared_ptr<OC::OCResource> m_syncResource;
- std::shared_ptr<OC::OCResource> m_msgResource;
- std::shared_ptr<OC::OCResource> m_topicResource;
-
-public:
- NSConsumerSimulator()
- : m_messageFunc(), m_syncFunc(),
- m_syncResource()
- {
- }
- ~NSConsumerSimulator() = default;
-
- NSConsumerSimulator(const NSConsumerSimulator &) = delete;
- NSConsumerSimulator & operator = (const NSConsumerSimulator &) = delete;
-
- NSConsumerSimulator(NSConsumerSimulator &&) = delete;
- NSConsumerSimulator & operator = (NSConsumerSimulator &&) = delete;
-
- void findProvider()
- {
- OC::OCPlatform::findResource("", std::string("/oic/res?rt=oic.wk.notification"),
- OCConnectivityType::CT_DEFAULT,
- std::bind(&NSConsumerSimulator::findResultCallback, this, std::placeholders::_1),
- OC::QualityOfService::LowQos);
- }
-
- void syncToProvider(int & type, const int & id, const std::string & providerID)
- {
- if (m_syncResource == nullptr)
+ private:
+ std::function<void(const int &, const std::string &, const std::string &,
+ const std::string &)> m_messageFunc;
+ std::function<void(const int &, const int &)> m_syncFunc;
+
+ std::shared_ptr<OC::OCResource> m_syncResource;
+ std::shared_ptr<OC::OCResource> m_msgResource;
+ std::shared_ptr<OC::OCResource> m_topicResource;
+
+ public:
+ NSConsumerSimulator()
+ : m_messageFunc(), m_syncFunc(),
+ m_syncResource()
{
- return;
}
+ ~NSConsumerSimulator() = default;
- OC::OCRepresentation rep;
- rep.setValue("providerId", providerID);
- rep.setValue("messageId", id);
- rep.setValue("state", type);
+ NSConsumerSimulator(const NSConsumerSimulator &) = delete;
+ NSConsumerSimulator &operator = (const NSConsumerSimulator &) = delete;
- m_syncResource->post(rep, OC::QueryParamsMap(), &onPost, OC::QualityOfService::LowQos);
- }
+ NSConsumerSimulator(NSConsumerSimulator &&) = delete;
+ NSConsumerSimulator &operator = (NSConsumerSimulator &&) = delete;
- bool cancelObserves()
- {
- if((msgResourceCancelObserve(OC::QualityOfService::HighQos) == OC_STACK_OK) &&
- (syncResourceCancelObserve(OC::QualityOfService::HighQos) == OC_STACK_OK))
+ void findProvider()
{
- return true;
+ OC::OCPlatform::findResource("", std::string("/oic/res?rt=oic.wk.notification"),
+ OCConnectivityType::CT_DEFAULT,
+ std::bind(&NSConsumerSimulator::findResultCallback, this, std::placeholders::_1),
+ OC::QualityOfService::LowQos);
}
- return false;
- }
-
- void setCallback(std::function<void(const int&, const std::string&,
- const std::string&, const std::string&)> messageFunc,
- const std::function<void(const int&, const int&)> & syncFunc)
- {
- m_messageFunc = messageFunc;
- m_syncFunc = syncFunc;
- }
-
-private:
- static void onPost(const OC::HeaderOptions &/*headerOption*/,
- const OC::OCRepresentation & /*rep*/ , const int /*eCode*/)
- {
- }
- void findResultCallback(std::shared_ptr<OC::OCResource> resource)
- {
-
-
- if(resource->uri() == "/notification")
+
+ void syncToProvider(int &type, const int &id, const std::string &providerID)
{
- resource->get(OC::QueryParamsMap(),
- std::bind(&NSConsumerSimulator::onGet, this,
- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
- resource), OC::QualityOfService::LowQos);
+ if (m_syncResource == nullptr)
+ {
+ return;
+ }
+
+ OC::OCRepresentation rep;
+ rep.setValue("providerId", providerID);
+ rep.setValue("messageId", id);
+ rep.setValue("state", type);
+
+ m_syncResource->post(rep, OC::QueryParamsMap(), &onPost, OC::QualityOfService::LowQos);
}
- }
- void onGet(const OC::HeaderOptions &/*headerOption*/,
- const OC::OCRepresentation & /*rep*/ , const int /*eCode*/,
- std::shared_ptr<OC::OCResource> resource)
- {
- OC::QueryParamsMap map;
- map.insert(std::pair<std::string,std::string>(std::string("consumerId"),
- std::string("123456789012345678901234567890123456")));
+ bool cancelObserves()
+ {
+ if ((msgResourceCancelObserve(OC::QualityOfService::HighQos) == OC_STACK_OK) &&
+ (syncResourceCancelObserve(OC::QualityOfService::HighQos) == OC_STACK_OK))
+ {
+ return true;
+ }
+ return false;
+ }
- try
+ void setCallback(std::function<void(const int &, const std::string &,
+ const std::string &, const std::string &)> messageFunc,
+ const std::function<void(const int &, const int &)> &syncFunc)
{
+ m_messageFunc = messageFunc;
+ m_syncFunc = syncFunc;
+ }
- std::vector<std::string> rts{"oic.wk.notification"};
+ private:
+ static void onPost(const OC::HeaderOptions &/*headerOption*/,
+ const OC::OCRepresentation & /*rep*/ , const int /*eCode*/)
+ {
+ }
+ void findResultCallback(std::shared_ptr<OC::OCResource> resource)
+ {
- m_msgResource
- = OC::OCPlatform::constructResourceObject(
- std::string(resource->host()), std::string(resource->uri() + "/message"),
- OCConnectivityType(resource->connectivityType()), true, rts,
- std::vector<std::string>(resource->getResourceInterfaces()));
- m_msgResource->observe(OC::ObserveType::Observe, map,
- std::bind(&NSConsumerSimulator::onObserve, this,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, std::placeholders::_4, resource),
- OC::QualityOfService::LowQos);
+ if (resource->uri() == "/notification")
+ {
+ resource->get(OC::QueryParamsMap(),
+ std::bind(&NSConsumerSimulator::onGet, this,
+ std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+ resource), OC::QualityOfService::LowQos);
+ }
}
- catch(std::exception & e)
+ void onGet(const OC::HeaderOptions &/*headerOption*/,
+ const OC::OCRepresentation & /*rep*/ , const int /*eCode*/,
+ std::shared_ptr<OC::OCResource> resource)
{
- std::cout << "OC::ResoureInitException : " << e.what() << std::endl;
+
+ OC::QueryParamsMap map;
+ map.insert(std::pair<std::string, std::string>(std::string("consumerId"),
+ std::string("123456789012345678901234567890123456")));
+
+ try
+ {
+
+ std::vector<std::string> rts{"oic.wk.notification"};
+
+ m_msgResource
+ = OC::OCPlatform::constructResourceObject(
+ std::string(resource->host()), std::string(resource->uri() + "/message"),
+ OCConnectivityType(resource->connectivityType()), true, rts,
+ std::vector<std::string>(resource->getResourceInterfaces()));
+
+ m_msgResource->observe(OC::ObserveType::Observe, map,
+ std::bind(&NSConsumerSimulator::onObserve, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, std::placeholders::_4, resource),
+ OC::QualityOfService::LowQos);
+ }
+ catch (std::exception &e)
+ {
+ std::cout << "OC::ResoureInitException : " << e.what() << std::endl;
+ }
+ m_syncResource
+ = OC::OCPlatform::constructResourceObject(resource->host(), resource->uri() + "/sync",
+ resource->connectivityType(), true, resource->getResourceTypes(),
+ resource->getResourceInterfaces());
+
+ m_syncResource->observe(OC::ObserveType::Observe, map,
+ std::bind(&NSConsumerSimulator::onObserve, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, std::placeholders::_4, resource),
+ OC::QualityOfService::LowQos);
+
+ m_topicResource
+ = OC::OCPlatform::constructResourceObject(resource->host(), resource->uri() + "/topic",
+ resource->connectivityType(), true, resource->getResourceTypes(),
+ resource->getResourceInterfaces());
}
- m_syncResource
- = OC::OCPlatform::constructResourceObject(resource->host(), resource->uri() + "/sync",
- resource->connectivityType(), true, resource->getResourceTypes(),
- resource->getResourceInterfaces());
-
- m_syncResource->observe(OC::ObserveType::Observe, map,
- std::bind(&NSConsumerSimulator::onObserve, this,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, std::placeholders::_4, resource),
- OC::QualityOfService::LowQos);
-
- m_topicResource
- = OC::OCPlatform::constructResourceObject(resource->host(), resource->uri() + "/topic",
- resource->connectivityType(), true, resource->getResourceTypes(),
- resource->getResourceInterfaces());
- }
- void onObserve(const OC::HeaderOptions &/*headerOption*/,
- const OC::OCRepresentation &rep , const int & /*eCode*/, const int &,
- std::shared_ptr<OC::OCResource> )
- {
-
- if (rep.getUri() == "/notification/message" && rep.hasAttribute("messageId")
- && rep.getValue<int>("messageId") != 1)
+ void onObserve(const OC::HeaderOptions &/*headerOption*/,
+ const OC::OCRepresentation &rep , const int & /*eCode*/, const int &,
+ std::shared_ptr<OC::OCResource> )
{
- m_messageFunc(int(rep.getValue<int>("messageId")),
- std::string(rep.getValueToString("title")),
- std::string(rep.getValueToString("contentText")),
- std::string(rep.getValueToString("source")));
- if(rep.getValue<int>("messageId") == 3)
+
+ if (rep.getUri() == "/notification/message" && rep.hasAttribute("messageId")
+ && rep.getValue<int>("messageId") != 1)
+ {
+ m_messageFunc(int(rep.getValue<int>("messageId")),
+ std::string(rep.getValueToString("title")),
+ std::string(rep.getValueToString("contentText")),
+ std::string(rep.getValueToString("source")));
+ if (rep.getValue<int>("messageId") == 3)
+ {
+ m_topicResource->get(OC::QueryParamsMap(),
+ std::bind(&NSConsumerSimulator::onTopicGet, this, std::placeholders::_1,
+ std::placeholders::_2, std::placeholders::_3, m_topicResource),
+ OC::QualityOfService::LowQos);
+ }
+ }
+ else if (rep.getUri() == "/notification/sync")
{
- m_topicResource->get(OC::QueryParamsMap(),
- std::bind(&NSConsumerSimulator::onTopicGet, this, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3, m_topicResource),
- OC::QualityOfService::LowQos);
+ m_syncFunc(int(rep.getValue<int>("state")), int(rep.getValue<int>("messageId")));
}
}
- else if (rep.getUri() == "/notification/sync")
+ void onTopicGet(const OC::HeaderOptions &/*headerOption*/,
+ const OC::OCRepresentation & /*rep*/ , const int /*eCode*/,
+ std::shared_ptr<OC::OCResource> /*resource*/)
+ {
+ }
+
+ OCStackResult msgResourceCancelObserve(OC::QualityOfService qos)
+ {
+ return m_msgResource->cancelObserve(qos);
+ }
+
+ OCStackResult syncResourceCancelObserve(OC::QualityOfService qos)
{
- m_syncFunc(int(rep.getValue<int>("state")), int(rep.getValue<int>("messageId")));
+ return m_syncResource->cancelObserve(qos);
}
- }
- void onTopicGet(const OC::HeaderOptions &/*headerOption*/,
- const OC::OCRepresentation & /*rep*/ , const int /*eCode*/,
- std::shared_ptr<OC::OCResource> /*resource*/)
- {
- }
-
- OCStackResult msgResourceCancelObserve(OC::QualityOfService qos)
- {
- return m_msgResource->cancelObserve(qos);
- }
-
- OCStackResult syncResourceCancelObserve(OC::QualityOfService qos)
- {
- return m_syncResource->cancelObserve(qos);
- }
};
TEST_F(NotificationServiceConsumerTest, ExpectGetProviderSuccessWithValidProviderId)
{
- OIC::Service::NSProvider * provider =
- OIC::Service::NSConsumerService::getInstance()->getProvider(g_provider->getProviderId());
+ OIC::Service::NSProvider *provider =
+ OIC::Service::NSConsumerService::getInstance()->getProvider(g_provider->getProviderId());
int ret = strcmp(provider->getProviderId().c_str(), g_provider->getProviderId().c_str());
EXPECT_EQ(0, ret);
}
TEST_F(NotificationServiceConsumerTest, ExpectGetProviderSuccessWithInvalidProviderId)
{
- OIC::Service::NSProvider * provider =
- OIC::Service::NSConsumerService::getInstance()->getProvider("123456789012345678901234567890123457");
- EXPECT_EQ(provider, (void*)NULL);
+ OIC::Service::NSProvider *provider =
+ OIC::Service::NSConsumerService::getInstance()->getProvider("123456789012345678901234567890123457");
+ EXPECT_EQ(provider, (void *)NULL);
}
TEST_F(NotificationServiceConsumerTest, ExpectCallbackTopicUpdated)
OIC::Service::NSProviderState revState = OIC::Service::NSProviderState::STOPPED;
mocks.OnCallFunc(ProviderChangedCallbackEmpty).Do(
[this, & revState](OIC::Service::NSProviderState state)
- {
- std::cout << "Income Changed Callback : " << (int)state << std::endl;
- revState = state;
- responseCon.notify_all();
- });
+ {
+ std::cout << "Income Changed Callback : " << (int)state << std::endl;
+ revState = state;
+ responseCon.notify_all();
+ });
NSProviderSimulator::NS_TopicList topics;
topics.push_back("1");
topics.push_back("3");
std::list<OIC::Service::NSTopic *> retTopic = g_provider->getTopicList()->getTopicsList();
- auto it1=retTopic.begin();
- auto it2=topics.begin();
- while( it1 != retTopic.end() || it2 != topics.end() )
+ auto it1 = retTopic.begin();
+ auto it2 = topics.begin();
+ while ( it1 != retTopic.end() || it2 != topics.end() )
{
- if((*it1)->getTopicName() != *it2)
+ if ((*it1)->getTopicName() != *it2)
{
isSame = false; break;
}
- it1++;it2++;
+ it1++; it2++;
}
TEST_F(NotificationServiceConsumerTest, ExpectFailUpdateTopicOnConsumer)
{
- OIC::Service::NSTopicsList * retTopic = g_provider->getTopicList();
+ OIC::Service::NSTopicsList *retTopic = g_provider->getTopicList();
for (auto it : retTopic->getTopicsList())
{
it->setState(OIC::Service::NSTopic::NSTopicState::SUBSCRIBED);
class NSProviderSimulator
{
-public:
- enum class TopicAllowState
- {
- DENY,
- ALLOW
- };
- typedef std::pair<std::string, TopicAllowState> NS_TopicState;
- typedef std::map<std::string, TopicAllowState> NS_TopicStateList;
-
- typedef std::list<std::string> NS_TopicList;
-private:
- OCResourceHandle m_notificationHandle;
- OCResourceHandle m_messageHandle;
- OCResourceHandle m_syncHandle;
- OCResourceHandle m_topicHandle;
- OC::OCRepresentation m_syncRep;
- OC::OCRepresentation m_messageRep;
- int m_accepter;
-
- std::string m_notificationUri;
- std::string m_messageUri;
- std::string m_syncUri;
- std::string m_topicUri;
- NS_TopicList m_topicList;
- NS_TopicStateList m_allowedTopicList;
-
- OC::ObservationIds m_syncObservers;
-
-public:
- NSProviderSimulator()
- : m_notificationHandle(), m_messageHandle(), m_syncHandle(), m_topicHandle(),
- m_syncRep(), m_messageRep(), m_accepter(0),
- m_notificationUri(std::string("/notification")),
- m_messageUri(std::string("/message")),
- m_syncUri(std::string("/sync")),
- m_topicUri(std::string("/topic")),
- m_topicList(),
- m_allowedTopicList(),
- m_syncObservers()
- {
+ public:
+ enum class TopicAllowState
+ {
+ DENY,
+ ALLOW
+ };
+ typedef std::pair<std::string, TopicAllowState> NS_TopicState;
+ typedef std::map<std::string, TopicAllowState> NS_TopicStateList;
+
+ typedef std::list<std::string> NS_TopicList;
+ private:
+ OCResourceHandle m_notificationHandle;
+ OCResourceHandle m_messageHandle;
+ OCResourceHandle m_syncHandle;
+ OCResourceHandle m_topicHandle;
+ OC::OCRepresentation m_syncRep;
+ OC::OCRepresentation m_messageRep;
+ int m_accepter;
+
+ std::string m_notificationUri;
+ std::string m_messageUri;
+ std::string m_syncUri;
+ std::string m_topicUri;
+ NS_TopicList m_topicList;
+ NS_TopicStateList m_allowedTopicList;
+
+ OC::ObservationIds m_syncObservers;
+
+ public:
+ NSProviderSimulator()
+ : m_notificationHandle(), m_messageHandle(), m_syncHandle(), m_topicHandle(),
+ m_syncRep(), m_messageRep(), m_accepter(0),
+ m_notificationUri(std::string("/notification")),
+ m_messageUri(std::string("/message")),
+ m_syncUri(std::string("/sync")),
+ m_topicUri(std::string("/topic")),
+ m_topicList(),
+ m_allowedTopicList(),
+ m_syncObservers()
+ {
- };
+ };
- ~NSProviderSimulator() = default;
+ ~NSProviderSimulator() = default;
- NSProviderSimulator(const NSProviderSimulator &) = delete;
- NSProviderSimulator & operator = (const NSProviderSimulator &) = delete;
+ NSProviderSimulator(const NSProviderSimulator &) = delete;
+ NSProviderSimulator &operator = (const NSProviderSimulator &) = delete;
- NSProviderSimulator(NSProviderSimulator &&) = delete;
- NSProviderSimulator & operator = (NSProviderSimulator &&) = delete;
+ NSProviderSimulator(NSProviderSimulator &&) = delete;
+ NSProviderSimulator &operator = (NSProviderSimulator &&) = delete;
-private:
- std::shared_ptr<OC::OCResourceResponse> getResponse(
+ private:
+ std::shared_ptr<OC::OCResourceResponse> getResponse(
std::shared_ptr< OC::OCResourceRequest > requests, requestType type)
- {
- auto response = std::make_shared<OC::OCResourceResponse>();
- response->setRequestHandle(requests->getRequestHandle());
- response->setResourceHandle(requests->getResourceHandle());
-
- int requestFlag = requests->getRequestHandlerFlag();
- if (requestFlag == OC::RequestHandlerFlag::RequestFlag)
{
- std::string request = requests->getRequestType();
-
- response->setErrorCode(200);
- response->setResponseResult(OC_EH_OK);
+ auto response = std::make_shared<OC::OCResourceResponse>();
+ response->setRequestHandle(requests->getRequestHandle());
+ response->setResourceHandle(requests->getResourceHandle());
- if (request == "GET")
+ int requestFlag = requests->getRequestHandlerFlag();
+ if (requestFlag == OC::RequestHandlerFlag::RequestFlag)
{
- OC::OCRepresentation rep;
+ std::string request = requests->getRequestType();
- if (type == requestType::NS_NOTIFICATION)
- {
- std::string msgUri = m_notificationUri + m_messageUri;
- std::string syncUri = m_notificationUri + m_syncUri;
- std::string topicUri = m_notificationUri + m_topicUri;
- std::string providerId = "123456789012345678901234567890123456";
- rep.setValue("subControllability", m_accepter);
- rep.setValue("messageUri", msgUri);
- rep.setValue("syncUri", syncUri);
- rep.setValue("topicUri", topicUri);
- rep.setValue("providerId", providerId);
- }
- else if (type == requestType::NS_SYNC)
- {
- rep = m_syncRep;
- }
- else if (type == requestType::NS_MESSAGE)
- {
- rep = m_messageRep;
- }
- else if (type == requestType::NS_TOPIC)
+ response->setErrorCode(200);
+ response->setResponseResult(OC_EH_OK);
+
+ if (request == "GET")
{
- if (m_allowedTopicList.empty())
+ OC::OCRepresentation rep;
+
+ if (type == requestType::NS_NOTIFICATION)
+ {
+ std::string msgUri = m_notificationUri + m_messageUri;
+ std::string syncUri = m_notificationUri + m_syncUri;
+ std::string topicUri = m_notificationUri + m_topicUri;
+ std::string providerId = "123456789012345678901234567890123456";
+ rep.setValue("subControllability", m_accepter);
+ rep.setValue("messageUri", msgUri);
+ rep.setValue("syncUri", syncUri);
+ rep.setValue("topicUri", topicUri);
+ rep.setValue("providerId", providerId);
+ }
+ else if (type == requestType::NS_SYNC)
{
- std::for_each (m_topicList.begin(), m_topicList.end(),
- [this](const std::string & topic)
+ rep = m_syncRep;
+ }
+ else if (type == requestType::NS_MESSAGE)
+ {
+ rep = m_messageRep;
+ }
+ else if (type == requestType::NS_TOPIC)
+ {
+ if (m_allowedTopicList.empty())
+ {
+ std::for_each (m_topicList.begin(), m_topicList.end(),
+ [this](const std::string & topic)
{
m_allowedTopicList.insert(
- std::make_pair<std::string, TopicAllowState>(
- std::string(topic), TopicAllowState::DENY));
+ std::make_pair<std::string, TopicAllowState>(
+ std::string(topic), TopicAllowState::DENY));
}
- );
- }
+ );
+ }
- std::vector<OC::OCRepresentation> topicArr;
+ std::vector<OC::OCRepresentation> topicArr;
- std::for_each (m_allowedTopicList.begin(), m_allowedTopicList.end(),
- [& topicArr](const NS_TopicState & topicState)
+ std::for_each (m_allowedTopicList.begin(), m_allowedTopicList.end(),
+ [& topicArr](const NS_TopicState & topicState)
{
OC::OCRepresentation topic;
topic.setValue("topicName", topicState.first);
topic.setValue("topicState", (int) topicState.second);
topicArr.push_back(topic);
}
- );
+ );
- rep.setValue<std::vector<OC::OCRepresentation>>
- ("topicList", topicArr);
- }
- else
- {
- return NULL;
- }
+ rep.setValue<std::vector<OC::OCRepresentation>>
+ ("topicList", topicArr);
+ }
+ else
+ {
+ return NULL;
+ }
- response->setResourceRepresentation(rep);
- return response;
- }
+ response->setResourceRepresentation(rep);
+ return response;
+ }
- else if (request == "POST")
- {
- if (type == requestType::NS_SYNC)
+ else if (request == "POST")
{
- m_syncRep = requests->getResourceRepresentation();
+ if (type == requestType::NS_SYNC)
+ {
+ m_syncRep = requests->getResourceRepresentation();
- std::cout << "Receive POST for Sync" << std::endl;
- std::cout << "provider Id : " << m_syncRep.getValueToString("providerId") << std::endl;
- std::cout << "Sync State : " << m_syncRep.getValueToString("state") << std::endl;
+ std::cout << "Receive POST for Sync" << std::endl;
+ std::cout << "provider Id : " << m_syncRep.getValueToString("providerId") << std::endl;
+ std::cout << "Sync State : " << m_syncRep.getValueToString("state") << std::endl;
- response->setResourceRepresentation(m_syncRep);
+ response->setResourceRepresentation(m_syncRep);
- OC::OCPlatform::notifyAllObservers(m_syncHandle);
+ OC::OCPlatform::notifyAllObservers(m_syncHandle);
- return response;
- }
- else if (type == requestType::NS_TOPIC)
- {
- auto receivePayload =
+ return response;
+ }
+ else if (type == requestType::NS_TOPIC)
+ {
+ auto receivePayload =
requests->getResourceRepresentation()
.getValue<std::vector<OC::OCRepresentation>>("topicList");
- std::for_each (receivePayload.begin(), receivePayload.end(),
- [this](const OC::OCRepresentation & rep)
- {
- auto tmp = m_allowedTopicList.find(rep.getValueToString("topicName"));
- if (tmp != m_allowedTopicList.end())
- {
- tmp->second = (TopicAllowState) rep.getValue<int>("topicState");
- }
- }
- );
+ std::for_each (receivePayload.begin(), receivePayload.end(),
+ [this](const OC::OCRepresentation & rep)
+ {
+ auto tmp = m_allowedTopicList.find(rep.getValueToString("topicName"));
+ if (tmp != m_allowedTopicList.end())
+ {
+ tmp->second = (TopicAllowState) rep.getValue<int>("topicState");
+ }
+ }
+ );
+ }
}
}
- }
- return NULL;
- }
+ return NULL;
+ }
- void setObserver(std::shared_ptr< OC::OCResourceRequest > requests, requestType type)
- {
- if (type == requestType::NS_SYNC)
+ void setObserver(std::shared_ptr< OC::OCResourceRequest > requests, requestType type)
{
- OC::ObservationInfo observationInfo = requests->getObservationInfo();
- if (OC::ObserveAction::ObserveRegister == observationInfo.action)
+ if (type == requestType::NS_SYNC)
{
- m_syncObservers.push_back(observationInfo.obsId);
+ OC::ObservationInfo observationInfo = requests->getObservationInfo();
+ if (OC::ObserveAction::ObserveRegister == observationInfo.action)
+ {
+ m_syncObservers.push_back(observationInfo.obsId);
+ }
+ else if (OC::ObserveAction::ObserveUnregister == observationInfo.action)
+ {
+ m_syncObservers.erase(std::remove(
+ m_syncObservers.begin(), m_syncObservers.end(),
+ observationInfo.obsId), m_syncObservers.end());
+ }
}
- else if (OC::ObserveAction::ObserveUnregister == observationInfo.action)
+ else if (type == requestType::NS_MESSAGE)
{
- m_syncObservers.erase(std::remove(
- m_syncObservers.begin(), m_syncObservers.end(),
- observationInfo.obsId), m_syncObservers.end());
+ OC::OCRepresentation rep;
+ std::string providerId = "123456789012345678901234567890123456";
+ rep.setValue<int>("messageId", (int)messageType::NS_ALLOW);
+ rep.setValue("providerId", providerId);
+
+ auto response = std::make_shared<OC::OCResourceResponse>();
+ response->setRequestHandle(requests->getRequestHandle());
+ response->setResourceHandle(requests->getResourceHandle());
+ response->setErrorCode(200);
+ response->setResponseResult(OC_EH_OK);
+ response->setResourceRepresentation(rep);
+
+ OC::ObservationIds ids;
+ ids.push_back(requests->getObservationInfo().obsId);
+
+ OC::OCPlatform::notifyListOfObservers(m_messageHandle, ids, response);
}
}
- else if (type == requestType::NS_MESSAGE)
+
+ OCEntityHandlerResult entityHandler(
+ std::shared_ptr< OC::OCResourceRequest > request, requestType type)
{
- OC::OCRepresentation rep;
- std::string providerId = "123456789012345678901234567890123456";
- rep.setValue<int>("messageId", (int)messageType::NS_ALLOW);
- rep.setValue("providerId", providerId);
+ if (!request)
+ {
+ return OC_EH_ERROR;
+ }
- auto response = std::make_shared<OC::OCResourceResponse>();
- response->setRequestHandle(requests->getRequestHandle());
- response->setResourceHandle(requests->getResourceHandle());
- response->setErrorCode(200);
- response->setResponseResult(OC_EH_OK);
- response->setResourceRepresentation(rep);
+ std::cout << "Provider : Income request : " << request->getRequestHandlerFlag() << std::endl;
+ if ((request->getRequestHandlerFlag() & OC::RequestHandlerFlag::ObserverFlag))
+ {
+ std::cout << "Provider : Income Observe : " << std::endl;
+ setObserver(request, type);
+ return OC_EH_OK;
+ }
- OC::ObservationIds ids;
- ids.push_back(requests->getObservationInfo().obsId);
+ auto pResponse = getResponse(request, type);
+ if (pResponse == nullptr)
+ {
+ return OC_EH_ERROR;
+ }
- OC::OCPlatform::notifyListOfObservers(m_messageHandle, ids, response);
+ try
+ {
+ OC::OCPlatform::sendResponse(pResponse);
+ }
+ catch (std::exception &e)
+ {
+ return OC_EH_ERROR;
+ }
+
+ return OC_EH_OK;
}
- }
- OCEntityHandlerResult entityHandler(
- std::shared_ptr< OC::OCResourceRequest > request, requestType type)
- {
- if (!request)
+ public:
+
+ void setAccepter(int accepter)
{
- return OC_EH_ERROR;
+ m_accepter = accepter;
}
- std::cout << "Provider : Income request : " << request->getRequestHandlerFlag() << std::endl;
- if ((request->getRequestHandlerFlag() & OC::RequestHandlerFlag::ObserverFlag))
+ void notifyMessage()
{
- std::cout << "Provider : Income Observe : " << std::endl;
- setObserver(request, type);
- return OC_EH_OK;
+ std::cout << "Provider : notify~" << std::endl;
+ OC::OCPlatform::notifyAllObservers(m_messageHandle);
}
- auto pResponse = getResponse(request, type);
- if (pResponse == nullptr)
+ void notifyMessage(const uint64_t &id, const std::string &title, const std::string &content)
{
- return OC_EH_ERROR;
+ setMessage(id, title, content);
+ notifyMessage();
}
- try
+ void sendRead(const uint64_t &id)
{
- OC::OCPlatform::sendResponse(pResponse);
+ std::string providerId = "123456789012345678901234567890123456";
+ m_syncRep.setValue<int>("messageId", id);
+ m_syncRep.setValue("state", (int)1);
+ m_syncRep.setValue("providerId", providerId);
+ OC::OCPlatform::notifyAllObservers(m_syncHandle);
}
- catch (std::exception & e)
+ void sendDismiss(const uint64_t &id)
{
- return OC_EH_ERROR;
+ std::string providerId = "123456789012345678901234567890123456";
+ m_syncRep.setValue<int>("messageId", id);
+ m_syncRep.setValue("state", (int)2);
+ m_syncRep.setValue("providerId", providerId);
+ OC::OCPlatform::notifyAllObservers(m_syncHandle);
}
- return OC_EH_OK;
- }
-
-public:
-
- void setAccepter(int accepter)
- {
- m_accepter = accepter;
- }
-
- void notifyMessage()
- {
- std::cout << "Provider : notify~" << std::endl;
- OC::OCPlatform::notifyAllObservers(m_messageHandle);
- }
-
- void notifyMessage(const uint64_t & id, const std::string & title, const std::string & content)
- {
- setMessage(id, title, content);
- notifyMessage();
- }
+ void setMessage(const uint64_t &id, const std::string &title, const std::string &content)
+ {
+ std::string providerId = "123456789012345678901234567890123456";
+ m_messageRep.setValue<int>("messageId", id);
+ m_messageRep.setValue("title", title);
+ m_messageRep.setValue("contentText", content);
+ m_messageRep.setValue("providerId", providerId);
+ }
- void sendRead(const uint64_t & id)
- {
- std::string providerId = "123456789012345678901234567890123456";
- m_syncRep.setValue<int>("messageId", id);
- m_syncRep.setValue("state", (int)1);
- m_syncRep.setValue("providerId", providerId);
- OC::OCPlatform::notifyAllObservers(m_syncHandle);
- }
- void sendDismiss(const uint64_t & id)
- {
- std::string providerId = "123456789012345678901234567890123456";
- m_syncRep.setValue<int>("messageId", id);
- m_syncRep.setValue("state", (int)2);
- m_syncRep.setValue("providerId", providerId);
- OC::OCPlatform::notifyAllObservers(m_syncHandle);
- }
-
- void setMessage(const uint64_t & id, const std::string & title, const std::string & content)
- {
- std::string providerId = "123456789012345678901234567890123456";
- m_messageRep.setValue<int>("messageId", id);
- m_messageRep.setValue("title", title);
- m_messageRep.setValue("contentText", content);
- m_messageRep.setValue("providerId", providerId);
- }
-
- void setTopics(const NS_TopicList & topics)
- {
- bool isChanged = false;
- std::for_each (topics.begin(), topics.end(),
- [this, & isChanged](const std::string & topic)
+ void setTopics(const NS_TopicList &topics)
+ {
+ bool isChanged = false;
+ std::for_each (topics.begin(), topics.end(),
+ [this, & isChanged](const std::string & topic)
{
auto found = std::find(
- this->m_topicList.begin(), this->m_topicList.end(), topic);
+ this->m_topicList.begin(), this->m_topicList.end(), topic);
if (found == this->m_topicList.end())
{
this->m_topicList.push_back(topic);
}
});
- if (isChanged)
- {
- this->notifyMessage((uint64_t)messageType::NS_TOPIC, "", "");
+ if (isChanged)
+ {
+ this->notifyMessage((uint64_t)messageType::NS_TOPIC, "", "");
+ }
}
- }
- NS_TopicList getTopics() const
- {
- return m_topicList;
- }
+ NS_TopicList getTopics() const
+ {
+ return m_topicList;
+ }
- void updateTopicState(const NS_TopicStateList & allowedTopics)
- {
- std::for_each (allowedTopics.begin(), allowedTopics.end(),
- [this](const NS_TopicState & allowedTopic)
+ void updateTopicState(const NS_TopicStateList &allowedTopics)
+ {
+ std::for_each (allowedTopics.begin(), allowedTopics.end(),
+ [this](const NS_TopicState & allowedTopic)
{
auto found = this->m_allowedTopicList.find(allowedTopic.first);
if (found != this->m_allowedTopicList.end())
found->second = allowedTopic.second;
}
});
- }
+ }
- NS_TopicStateList getTopicAllowState() const
- {
- return m_allowedTopicList;
- }
+ NS_TopicStateList getTopicAllowState() const
+ {
+ return m_allowedTopicList;
+ }
- void deleteNotificationResource()
- {
- OC::OCPlatform::unregisterResource(m_notificationHandle);
- OC::OCPlatform::unregisterResource(m_messageHandle);
- OC::OCPlatform::unregisterResource(m_syncHandle);
- OC::OCPlatform::unregisterResource(m_topicHandle);
- m_allowedTopicList.clear();
- m_topicList.clear();
- }
-
- void createNotificationResource()
- {
- createNotificationResource(m_notificationUri);
- }
+ void deleteNotificationResource()
+ {
+ OC::OCPlatform::unregisterResource(m_notificationHandle);
+ OC::OCPlatform::unregisterResource(m_messageHandle);
+ OC::OCPlatform::unregisterResource(m_syncHandle);
+ OC::OCPlatform::unregisterResource(m_topicHandle);
+ m_allowedTopicList.clear();
+ m_topicList.clear();
+ }
- void createNotificationResource(const std::string & uri)
- {
- if (m_notificationUri != uri)
+ void createNotificationResource()
{
- m_notificationUri = uri;
+ createNotificationResource(m_notificationUri);
}
- OC::OCPlatform::startPresence(30);
+ void createNotificationResource(const std::string &uri)
+ {
+ if (m_notificationUri != uri)
+ {
+ m_notificationUri = uri;
+ }
+
+ OC::OCPlatform::startPresence(30);
- std::string notificationUri = m_notificationUri;
- std::string resourceTypeName = "oic.wk.notification.topic";
- std::string resourceInterface = OC::DEFAULT_INTERFACE;
+ std::string notificationUri = m_notificationUri;
+ std::string resourceTypeName = "oic.wk.notification.topic";
+ std::string resourceInterface = OC::DEFAULT_INTERFACE;
- uint8_t resourceProperty = OC_OBSERVABLE;
- std::string childUri = uri + m_topicUri;
- try
- {
- OC::OCPlatform::registerResource(
+ uint8_t resourceProperty = OC_OBSERVABLE;
+ std::string childUri = uri + m_topicUri;
+ try
+ {
+ OC::OCPlatform::registerResource(
m_topicHandle, childUri,
resourceTypeName, resourceInterface,
std::bind(& NSProviderSimulator::entityHandler, this,
- std::placeholders::_1, requestType::NS_TOPIC),
- resourceProperty);
- }
- catch(std::exception & e)
- {
- std::cout << e.what() << std::endl;
- }
+ std::placeholders::_1, requestType::NS_TOPIC),
+ resourceProperty);
+ }
+ catch (std::exception &e)
+ {
+ std::cout << e.what() << std::endl;
+ }
- //resourceProperty |= OC_OBSERVABLE;
- resourceTypeName = "oic.wk.notification.message";
- childUri = uri + m_messageUri;
- try
- {
- OC::OCPlatform::registerResource(
+ //resourceProperty |= OC_OBSERVABLE;
+ resourceTypeName = "oic.wk.notification.message";
+ childUri = uri + m_messageUri;
+ try
+ {
+ OC::OCPlatform::registerResource(
m_messageHandle, childUri,
resourceTypeName, resourceInterface,
std::bind(& NSProviderSimulator::entityHandler, this,
- std::placeholders::_1, requestType::NS_MESSAGE),
- resourceProperty);
- }
- catch (std::exception & e)
- {
- std::cout << e.what() << std::endl;
- }
+ std::placeholders::_1, requestType::NS_MESSAGE),
+ resourceProperty);
+ }
+ catch (std::exception &e)
+ {
+ std::cout << e.what() << std::endl;
+ }
- resourceTypeName = "oic.wk.notification.sync";
- childUri = uri + m_syncUri;
- try
- {
- OC::OCPlatform::registerResource(
+ resourceTypeName = "oic.wk.notification.sync";
+ childUri = uri + m_syncUri;
+ try
+ {
+ OC::OCPlatform::registerResource(
m_syncHandle, childUri,
resourceTypeName, resourceInterface,
std::bind(& NSProviderSimulator::entityHandler, this,
- std::placeholders::_1, requestType::NS_SYNC),
- resourceProperty);
- }
- catch (std::exception & e)
- {
- std::cout << e.what() << std::endl;
- }
+ std::placeholders::_1, requestType::NS_SYNC),
+ resourceProperty);
+ }
+ catch (std::exception &e)
+ {
+ std::cout << e.what() << std::endl;
+ }
- resourceProperty |= OC_DISCOVERABLE;
- resourceTypeName = "oic.wk.notification";
- try
- {
- OC::OCPlatform::registerResource(
+ resourceProperty |= OC_DISCOVERABLE;
+ resourceTypeName = "oic.wk.notification";
+ try
+ {
+ OC::OCPlatform::registerResource(
m_notificationHandle, notificationUri,
resourceTypeName, resourceInterface,
std::bind(& NSProviderSimulator::entityHandler, this,
- std::placeholders::_1, requestType::NS_NOTIFICATION),
- resourceProperty);
- }
- catch (std::exception & e)
- {
- std::cout << e.what() << std::endl;
+ std::placeholders::_1, requestType::NS_NOTIFICATION),
+ resourceProperty);
+ }
+ catch (std::exception &e)
+ {
+ std::cout << e.what() << std::endl;
+ }
}
- }
};
#endif /* _NS_PROVIDER_SERVICE_SIMULATOR_H_ */
std::unique_lock< std::mutex > lock { mutexForCondition };
responseCon.wait_for(lock, g_waitForResponse);
- EXPECT_NE((void*)g_consumer, (void*)NULL);
+ EXPECT_NE((void *)g_consumer, (void *)NULL);
}
TEST_F(NotificationProviderServiceTest, NeverCallNotifyOnConsumerByAcceptIsFalse)
int msgID = 0;
mocks.OnCallFunc(MessageCallbackFromConsumerEmpty).Do(
- [& expectTrue, &msgID](const int & id, const std::string &, const std::string &,
+ [& expectTrue, &msgID](const int &id, const std::string &, const std::string &,
const std::string &)
{
if (id == msgID)
int msgID = 0;
mocks.ExpectCallFunc(MessageCallbackFromConsumerEmpty).Do(
- [&msgID](const int & id, const std::string &, const std::string &, const std::string &)
+ [&msgID](const int &id, const std::string &, const std::string &, const std::string &)
{
if (id == msgID)
{
int id = 0;
mocks.ExpectCallFunc(SyncCallbackFromConsumerEmpty).Do(
- [& id](int & type, int & syncId)
+ [& id](int &type, int &syncId)
{
std::cout << "MessageSynchronizedCallbackEmpty" << std::endl;
if (syncId == id &&
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
- if(topicList != nullptr)
+ if (topicList != nullptr)
{
delete topicList;
}
EXPECT_EQ(isSame, true);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
- if(topicList != nullptr)
+ if (topicList != nullptr)
{
delete topicList;
}
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
- if(topicList != nullptr)
+ if (topicList != nullptr)
{
delete topicList;
}
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str1);
OIC::Service::NSProviderService::getInstance()->unregisterTopic(str2);
-
- if(topicList != nullptr)
+
+ if (topicList != nullptr)
{
delete topicList;
}