1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "NSTopicsList.h"
22 #include "NSException.h"
23 #include "oic_malloc.h"
29 NSTopicsList::NSTopicsList(::NSTopicLL *topics, bool modify)
31 ::NSTopicLL *topicsNode = nullptr;
33 m_modifiable = modify;
35 while (topicsNode != nullptr)
37 m_topicsList.push_back(new NSTopic(
38 topicsNode->topicName, (NSTopic::NSTopicState)topicsNode->state));
39 topicsNode = topicsNode->next;
43 NSTopicsList::NSTopicsList(const NSTopicsList &topicsList)
45 for (auto it : topicsList.getTopicsList())
47 m_topicsList.push_back(new NSTopic(it.getTopicName(), it.getState()));
52 NSTopicsList &NSTopicsList::operator=(const NSTopicsList &topicsList)
54 for (auto it : topicsList.getTopicsList())
56 this->m_topicsList.push_back(new NSTopic(it.getTopicName(), it.getState()));
62 NSTopicsList::~NSTopicsList()
64 for (auto it : m_topicsList)
71 void NSTopicsList::addTopic(const std::string &topicName, NSTopic::NSTopicState state)
75 m_topicsList.push_back(new NSTopic(topicName, state));
79 throw NSException("Invalid Operation. Method not supported as the object state is invalid");
83 void NSTopicsList::removeTopic(const std::string &topicName)
87 for (auto it : m_topicsList)
89 if (it->getTopicName().compare(topicName) == 0)
91 m_topicsList.remove(it);
98 throw NSException("Invalid Operation. Method not supported as the object state is invalid");
102 std::list<NSTopic> NSTopicsList::getTopicsList() const
104 std::list<NSTopic> topicList;
105 for (auto it : m_topicsList)
107 NSTopic topic(it->getTopicName(), it->getState());
108 topicList.push_back(topic);
113 //Below method restricts the application from illegally modifying Topics when
114 //Provider is in Invalid state. By calling the API, the service prevents and protects
115 //the integrity of TopicsList updation when the associated object is Invalid
116 //The default value of the variable is 'false' in the provider side. Also, the state is irreversible.
117 void NSTopicsList::unsetModifiability()
119 m_modifiable = false;