X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fnotification%2Fcpp-wrapper%2Fcommon%2FNSTopicsList.cpp;h=33862536d2c90a1749de367dab364b3e4ab45b19;hb=c315c87e07c4080ecd0ef488e7a1047bc3c509b2;hp=915547bb6d6e0aafaa76ce0df45689be5ba90f45;hpb=edcfc3d2329da7b914771c0dcff5f42c9b74fd93;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/notification/cpp-wrapper/common/NSTopicsList.cpp b/service/notification/cpp-wrapper/common/NSTopicsList.cpp index 915547b..3386253 100755 --- a/service/notification/cpp-wrapper/common/NSTopicsList.cpp +++ b/service/notification/cpp-wrapper/common/NSTopicsList.cpp @@ -19,20 +19,23 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "NSTopicsList.h" +#include "NSException.h" #include "oic_malloc.h" namespace OIC { namespace Service { - NSTopicsList::NSTopicsList(::NSTopicLL *topics) + NSTopicsList::NSTopicsList(::NSTopicLL *topics, bool modify) { ::NSTopicLL *topicsNode = nullptr; topicsNode = topics; + m_modifiable = modify; while (topicsNode != nullptr) { - addTopic(topicsNode->topicName, (NSTopic::NSTopicState)topicsNode->state); + m_topicsList.push_back(new NSTopic( + topicsNode->topicName, (NSTopic::NSTopicState)topicsNode->state)); topicsNode = topicsNode->next; } @@ -41,47 +44,79 @@ namespace OIC { for (auto it : topicsList.getTopicsList()) { - addTopic(it->getTopicName(), it->getState()); + m_topicsList.push_back(new NSTopic(it.getTopicName(), it.getState())); } + m_modifiable = false; } NSTopicsList &NSTopicsList::operator=(const NSTopicsList &topicsList) { for (auto it : topicsList.getTopicsList()) { - this->addTopic(it->getTopicName(), it->getState()); + this->m_topicsList.push_back(new NSTopic(it.getTopicName(), it.getState())); } return *this; + m_modifiable = false; } NSTopicsList::~NSTopicsList() { - for (auto it : getTopicsList()) + for (auto it : m_topicsList) { delete it; } - getTopicsList().clear(); + m_topicsList.clear(); } void NSTopicsList::addTopic(const std::string &topicName, NSTopic::NSTopicState state) { - m_topicsList.push_back(new NSTopic(topicName, state)); + if(m_modifiable) + { + m_topicsList.push_back(new NSTopic(topicName, state)); + } + else + { + throw NSException("Invalid Operation. Method not supported as the object state is invalid"); + } } void NSTopicsList::removeTopic(const std::string &topicName) { - for (auto it : getTopicsList()) + if(m_modifiable) { - if (it->getTopicName().compare(topicName) == 0) + for (auto it : m_topicsList) { - m_topicsList.remove(it); + if (it->getTopicName().compare(topicName) == 0) + { + m_topicsList.remove(it); + break; + } } } + else + { + throw NSException("Invalid Operation. Method not supported as the object state is invalid"); + } } - std::list NSTopicsList::getTopicsList() const + std::list NSTopicsList::getTopicsList() const + { + std::list topicList; + for (auto it : m_topicsList) + { + NSTopic topic(it->getTopicName(), it->getState()); + topicList.push_back(topic); + } + return topicList; + } + + //Below method restricts the application from illegally modifying Topics when + //Provider is in Invalid state. By calling the API, the service prevents and protects + //the integrity of TopicsList updation when the associated object is Invalid + //The default value of the variable is 'false' in the provider side. Also, the state is irreversible. + void NSTopicsList::unsetModifiability() { - return m_topicsList; + m_modifiable = false; } } }