1 //******************************************************************
3 // Copyright 2015 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 "DeviceAssociation.h"
22 #include "DevicePresence.h"
29 DeviceAssociation * DeviceAssociation::s_instance = nullptr;
30 std::mutex DeviceAssociation::s_mutexForCreation;
31 std::list< DevicePresencePtr > DeviceAssociation::s_deviceList;
33 DeviceAssociation::DeviceAssociation()
35 // TODO Auto-generated constructor stub
38 DeviceAssociation::~DeviceAssociation()
40 // TODO Auto-generated destructor stub
43 DeviceAssociation * DeviceAssociation::getInstance()
47 s_mutexForCreation.lock();
50 s_instance = new DeviceAssociation();
52 s_mutexForCreation.unlock();
57 DevicePresencePtr DeviceAssociation::findDevice(const std::string & address)
59 OC_LOG_V(DEBUG,BROKER_TAG,"findDevice()");
60 DevicePresencePtr retDevice = nullptr;
61 for(auto it : s_deviceList)
63 if(address == it->getAddress())
65 OC_LOG_V(DEBUG,BROKER_TAG,"find device in deviceList");
74 void DeviceAssociation::addDevice(DevicePresencePtr dPresence)
76 OC_LOG_V(DEBUG,BROKER_TAG,"addDevice()");
77 DevicePresencePtr foundDevice = findDevice(dPresence->getAddress());
78 if(foundDevice == nullptr)
80 OC_LOG_V(DEBUG,BROKER_TAG,"add device in deviceList");
81 s_deviceList.push_back(dPresence);
85 void DeviceAssociation::removeDevice(DevicePresencePtr dPresence)
87 OC_LOG_V(DEBUG,BROKER_TAG,"removeDevice()");
88 DevicePresencePtr foundDevice = findDevice(dPresence->getAddress());
89 if(foundDevice != nullptr)
91 OC_LOG_V(DEBUG,BROKER_TAG,"remove device in deviceList");
92 s_deviceList.remove(foundDevice);
97 bool DeviceAssociation::isEmptyDeviceList()
99 OC_LOG_V(DEBUG,BROKER_TAG,"isEmptyDeviceList()");
100 return s_deviceList.empty();
102 } // namespace Service