1 //******************************************************************
3 // Copyright 2017 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #include "NSProviderService.h"
25 #include "NSConstants.h"
26 #include "NSAcceptedConsumers.h"
32 std::shared_ptr<NSConsumer> NSAcceptedConsumers::getConsumer(const std::string &id)
34 std::lock_guard<std::mutex> lock(m_mutex);
35 NS_LOG_V(DEBUG, "AcceptedConsumers::getConsumer size : %d", (int) m_consumers.size());
36 auto it = m_consumers.find(id);
37 if (it != m_consumers.end() )
39 NS_LOG(DEBUG, "getConsumer : Found Consumer with given ID");
42 NS_LOG(DEBUG, "getConsumer : Not Found Consumer with given ID");
45 void NSAcceptedConsumers::addConsumer(std::shared_ptr<NSConsumer> consumer)
47 std::lock_guard<std::mutex> lock(m_mutex);
48 NS_LOG_V(INFO_PRIVATE, "AcceptedConsumers::addConsumer Id : %s", consumer->getConsumerId().c_str());
49 m_consumers[consumer->getConsumerId()] = consumer;
53 void NSAcceptedConsumers::removeConsumer(const std::string &id)
55 std::lock_guard<std::mutex> lock(m_mutex);
56 NS_LOG_V(INFO_PRIVATE, "AcceptedConsumers::removeConsumer Id : %s", id.c_str());
57 m_consumers.erase(id);
61 bool NSAcceptedConsumers::isAccepted(const std::string &id)
63 std::lock_guard<std::mutex> lock(m_mutex);
64 NS_LOG_V(INFO_PRIVATE, "AcceptedConsumers::isAccepted Id : %s", id.c_str());
65 if ( m_consumers.find(id) == m_consumers.end() )
67 NS_LOG(DEBUG, "isAccepted : Not Found Consumer with given ID");
72 NS_LOG(DEBUG, "isAccepted : Found Consumer with given ID");
77 int NSAcceptedConsumers::size()
79 std::lock_guard<std::mutex> lock(m_mutex);
80 NS_LOG_V(DEBUG, "AcceptedConsumers::size : %d", (int) m_consumers.size());
81 return m_consumers.size();
84 void NSAcceptedConsumers::removeConsumers()
86 std::lock_guard<std::mutex> lock(m_mutex);
87 NS_LOG(DEBUG, "AcceptedConsumers::removeConsumers ");
92 std::map<std::string, std::shared_ptr<NSConsumer> > NSAcceptedConsumers::getConsumers()
94 std::lock_guard<std::mutex> lock(m_mutex);