1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 // ============================================================================
26 // ============================================================================
33 #include "UUIDLess.hpp"
35 #include "SimpleLogger.h"
37 // ============================================================================
39 // ============================================================================
44 static const char DEVICE_TAG[] = "Device";
47 // ============================================================
49 // ============================================================
51 typedef std::shared_ptr<Device> SharedPtr;
52 typedef std::weak_ptr<Device> WeakPtr;
53 typedef std::list<Link::SharedPtr> LinkList;
56 Device(const UUID_t& deviceId) {
65 const UUID_t& getId() {
66 mutex_lock_guard lock(deviceMutex_);
70 const std::string& getName() {
71 mutex_lock_guard lock(deviceMutex_);
75 void setName(const std::string& name) {
76 mutex_lock_guard lock(deviceMutex_);
80 void addLink(const Link::SharedPtr& link) {
81 logDebug(DEVICE_TAG, "Entering Link::addLink");
83 mutex_lock_guard lock(deviceMutex_);
85 // If list is empty, go ahead and add
86 if (linkList_.empty())
88 logDebug(DEVICE_TAG, "Link::addLink, linkList empty, adding");
89 linkList_.push_back(link);
93 // Search list for the link. If already in list, return
94 for (auto iter = linkList_.begin(); iter != linkList_.end(); ++iter) {
96 logDebug(DEVICE_TAG, "Link::addLink, link already in linkList");
101 // Not already in list, so add
102 logDebug(DEVICE_TAG, "Link::addLink, adding link");
103 linkList_.push_back(link);
106 bool removeLink(const Link::SharedPtr& link) {
107 logDebug(DEVICE_TAG, "Entering Link::removeLink");
110 mutex_lock_guard lock(deviceMutex_);
111 // Return immediately if the list is empty
112 if (linkList_.empty()) {
113 logDebug(DEVICE_TAG, "Link::removeLink, linkList empty");
117 // Search list for the link. If in the list, return
118 for (auto iter = linkList_.begin(); iter != linkList_.end(); ++iter) {
120 linkList_.erase(iter);
121 logDebug(DEVICE_TAG, "Link::removeLink, removing link");
129 LinkList getLinks() {
130 mutex_lock_guard lock(deviceMutex_);
134 uint32_t getLinkCount() {
135 mutex_lock_guard lock(deviceMutex_);
136 return (uint32_t)linkList_.size();
152 #endif /* DEVICE_H_ */