replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / cpp-wrapper / consumer / src / NSAcceptedProviders.cpp
1 //******************************************************************
2 //
3 // Copyright 2017 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include "NSAcceptedProviders.h"
22 #include <cstring>
23 #include "NSCommon.h"
24 #include "NSConstants.h"
25
26 namespace OIC
27 {
28     namespace Service
29     {
30         std::shared_ptr<NSProvider> NSAcceptedProviders::getProvider(const std::string &id)
31         {
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() )
36             {
37                 NS_LOG(DEBUG, "getProvider : Found Provider with given ID");
38                 return it->second;
39             }
40             NS_LOG(DEBUG, "getProvider : Not Found Provider with given ID");
41             return NULL;
42         }
43         void NSAcceptedProviders::addProvider(std::shared_ptr<NSProvider> provider)
44         {
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;
48             return;
49         }
50
51         void NSAcceptedProviders::removeProvider(const std::string &id)
52         {
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);
56             return;
57         }
58
59         bool NSAcceptedProviders::isAccepted(const std::string &id)
60         {
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() )
64             {
65                 NS_LOG(DEBUG, "isAccepted : Not Found Provider with given ID");
66                 return false;
67             }
68             else
69             {
70                 NS_LOG(DEBUG, "isAccepted : Found Provider with given ID");
71                 return true;
72             }
73         }
74
75         int NSAcceptedProviders::size()
76         {
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();
80         }
81
82         void NSAcceptedProviders::removeProviders()
83         {
84             std::lock_guard<std::mutex> lock(m_mutex);
85             NS_LOG(DEBUG, "AcceptedProviders::removeProviders ");
86             m_providers.clear();
87             return;
88         }
89
90         std::map<std::string, std::shared_ptr<NSProvider> > NSAcceptedProviders::getProviders()
91         {
92             std::lock_guard<std::mutex> lock(m_mutex);
93             return m_providers;
94         }
95     }
96 }