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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "NSAcceptedProviders.h"
24 #include "NSConstants.h"
30 std::shared_ptr<NSProvider> NSAcceptedProviders::getProvider(const std::string &id)
32 std::lock_guard<std::mutex> lock(m_mutex);
33 NS_LOG_V(DEBUG, "AcceptedProviders::getProvider size : %d", (int) m_providers.size());
34 auto it = m_providers.find(id);
35 if (it != m_providers.end() )
37 NS_LOG(DEBUG, "getProvider : Found Provider with given ID");
40 NS_LOG(DEBUG, "getProvider : Not Found Provider with given ID");
43 void NSAcceptedProviders::addProvider(std::shared_ptr<NSProvider> provider)
45 std::lock_guard<std::mutex> lock(m_mutex);
46 NS_LOG_V(INFO_PRIVATE, "AcceptedProviders::addProvider Id : %s", provider->getProviderId().c_str());
47 m_providers[provider->getProviderId()] = provider;
51 void NSAcceptedProviders::removeProvider(const std::string &id)
53 std::lock_guard<std::mutex> lock(m_mutex);
54 NS_LOG_V(INFO_PRIVATE, "AcceptedProviders::removeProvider Id : %s", id.c_str());
55 m_providers.erase(id);
59 bool NSAcceptedProviders::isAccepted(const std::string &id)
61 std::lock_guard<std::mutex> lock(m_mutex);
62 NS_LOG_V(INFO_PRIVATE, "AcceptedProviders::isAccepted Id : %s", id.c_str());
63 if ( m_providers.find(id) == m_providers.end() )
65 NS_LOG(DEBUG, "isAccepted : Not Found Provider with given ID");
70 NS_LOG(DEBUG, "isAccepted : Found Provider with given ID");
75 int NSAcceptedProviders::size()
77 std::lock_guard<std::mutex> lock(m_mutex);
78 NS_LOG_V(DEBUG, "AcceptedProviders::size : %d", (int) m_providers.size());
79 return m_providers.size();
82 void NSAcceptedProviders::removeProviders()
84 std::lock_guard<std::mutex> lock(m_mutex);
85 NS_LOG(DEBUG, "AcceptedProviders::removeProviders ");
90 std::map<std::string, std::shared_ptr<NSProvider> > NSAcceptedProviders::getProviders()
92 std::lock_guard<std::mutex> lock(m_mutex);