#define TAG "NotiProviderWrapperExample"\r
using namespace std;\r
using namespace OIC::Service;\r
-std::string mainConsumer;\r
+std::vector<std::string> discoveredConsumers;\r
uint64_t mainMessageId = 0;\r
\r
extern char *strdup(const char *s);\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
- {\r
- mainConsumer = consumer->getConsumerId();\r
- }\r
+ discoveredConsumers.push_back(consumer->getConsumerId());\r
consumer->acceptSubscription(true);\r
}\r
\r
std::cout << "Sync State: " << (int) sync->getState() << std::endl;\r
}\r
\r
+OIC::Service::NSConsumer *printAvailableConsumers()\r
+{\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
+ {\r
+ std::cout << pos << ". " << it <<std::endl;\r
+ pos++;\r
+ }\r
+ while(!(std::cin >> option)){\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
+ return NULL;\r
+ std::string consumerId = discoveredConsumers[option];\r
+ OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(\r
+ consumerId);\r
+ return consumer;\r
+}\r
+\r
int main()\r
{\r
int num = 0;\r
case 3:\r
{\r
std::cout << "Allow Subscription" << std::endl;\r
- OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(\r
- mainConsumer);\r
+ OIC::Service::NSConsumer *consumer = printAvailableConsumers();\r
if (consumer != nullptr)\r
{\r
std::cout << "ALLOW" << std::endl;\r
case 4:\r
{\r
std::cout << "Deny Subscription" << std::endl;\r
- OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(\r
- mainConsumer);\r
+ OIC::Service::NSConsumer *consumer = printAvailableConsumers();\r
if (consumer != nullptr)\r
{\r
std::cout << "DENY" << std::endl;\r
std::cout << "2. Send Delete Sync" << std::endl;\r
int syn = 0;\r
while(!(std::cin >> syn)){\r
- cout << "Bad value!";\r
+ std::cout << "Bad value!" <<std::endl;;\r
std::cin.clear();\r
std::cin.ignore(numeric_limits<streamsize>::max(), '\n');\r
}\r
case 9:\r
{\r
std::cout << "SetTopic" << std::endl;\r
- OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(mainConsumer);\r
+ OIC::Service::NSConsumer *consumer = printAvailableConsumers();\r
if (consumer != nullptr)\r
{\r
consumer->setTopic("OCF_TOPIC1");\r
case 10:\r
{\r
std::cout << "UnsetTopic" << std::endl;\r
- OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(mainConsumer);\r
+ OIC::Service::NSConsumer *consumer = printAvailableConsumers();\r
if (consumer != nullptr)\r
{\r
consumer->unsetTopic("OCF_TOPIC1");\r
case 11:\r
{\r
std::cout << "GetConsumerTopicList" << std::endl;\r
- OIC::Service::NSConsumer *consumer = NSProviderService::getInstance()->getConsumer(mainConsumer);\r
+ OIC::Service::NSConsumer *consumer = printAvailableConsumers();\r
if (consumer != nullptr)\r
{\r
auto nsTopics = consumer->getConsumerTopicList();\r