Commit 4c1c94f6 authored by abitha.s's avatar abitha.s Committed by Uze Choi

Updated NS sample App to allow/deny consumer subscription.

Change-Id: Icdcc0b71fb865fbbb5dd472045e71cef2689d2c6
Signed-off-by: default avatarabitha.s <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13455Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
parent 33033ada
......@@ -214,7 +214,7 @@ int main(void)
std::cout << "2. Send Delete Sync" << std::endl;
int syn = 0;
while(!(std::cin >> syn)){
cout << "Bad value!";
std::cout << "Bad value!" <<std::endl;;
std::cin.clear();
std::cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
......
......@@ -35,7 +35,7 @@
#define TAG "NotiProviderWrapperExample"
using namespace std;
using namespace OIC::Service;
std::string mainConsumer;
std::vector<std::string> discoveredConsumers;
uint64_t mainMessageId = 0;
extern char *strdup(const char *s);
......@@ -65,10 +65,7 @@ void subscribeRequestCallback(OIC::Service::NSConsumer *consumer)
std::cout << "consumer requested to subscribe" << std::endl;
std::cout << "Consumer Device ID: " << consumer->getConsumerId() << std::endl;
if (mainConsumer.empty())
{
mainConsumer = consumer->getConsumerId();
}
discoveredConsumers.push_back(consumer->getConsumerId());
consumer->acceptSubscription(true);
}
......@@ -80,6 +77,30 @@ void syncCallback(OIC::Service::NSSyncInfo *sync)
std::cout << "Sync State: " << (int) sync->getState() << std::endl;
}
OIC::Service::NSConsumer *printAvailableConsumers()
{
std::cout << "Choose the Consumer ID for operation" << std::endl;
int pos = 1;
unsigned int option = 0;
for(auto it: discoveredConsumers)
{
std::cout << pos << ". " << it <<std::endl;
pos++;
}
while(!(std::cin >> option)){
std::cout << "Bad value!" <<std::endl;;
std::cin.clear();
std::cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
option--;
if (option > discoveredConsumers.size())
return NULL;
std::string consumerId = discoveredConsumers[option];
OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(
consumerId);
return consumer;
}
int main()
{
int num = 0;
......@@ -149,8 +170,7 @@ int main()
case 3:
{
std::cout << "Allow Subscription" << std::endl;
OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(
mainConsumer);
OIC::Service::NSConsumer *consumer = printAvailableConsumers();
if (consumer != nullptr)
{
std::cout << "ALLOW" << std::endl;
......@@ -161,8 +181,7 @@ int main()
case 4:
{
std::cout << "Deny Subscription" << std::endl;
OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(
mainConsumer);
OIC::Service::NSConsumer *consumer = printAvailableConsumers();
if (consumer != nullptr)
{
std::cout << "DENY" << std::endl;
......@@ -237,7 +256,7 @@ int main()
std::cout << "2. Send Delete Sync" << std::endl;
int syn = 0;
while(!(std::cin >> syn)){
cout << "Bad value!";
std::cout << "Bad value!" <<std::endl;;
std::cin.clear();
std::cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
......@@ -286,7 +305,7 @@ int main()
case 9:
{
std::cout << "SetTopic" << std::endl;
OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(mainConsumer);
OIC::Service::NSConsumer *consumer = printAvailableConsumers();
if (consumer != nullptr)
{
consumer->setTopic("OCF_TOPIC1");
......@@ -299,7 +318,7 @@ int main()
case 10:
{
std::cout << "UnsetTopic" << std::endl;
OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(mainConsumer);
OIC::Service::NSConsumer *consumer = printAvailableConsumers();
if (consumer != nullptr)
{
consumer->unsetTopic("OCF_TOPIC1");
......@@ -312,7 +331,7 @@ int main()
case 11:
{
std::cout << "GetConsumerTopicList" << std::endl;
OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(mainConsumer);
OIC::Service::NSConsumer *consumer = printAvailableConsumers();
if (consumer != nullptr)
{
auto nsTopics = consumer->getConsumerTopicList();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment