1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
9 // ============================================================================
11 // ============================================================================
18 #include "UUIDLess.hpp"
20 #include "SimpleLogger.h"
22 // ============================================================================
24 // ============================================================================
29 static const char DEVICE_TAG[] = "Device";
32 // ============================================================
34 // ============================================================
36 typedef std::shared_ptr<Device> SharedPtr;
37 typedef std::weak_ptr<Device> WeakPtr;
38 typedef std::list<Link::SharedPtr> LinkList;
41 Device(const UUID_t& deviceId) {
50 const UUID_t& getId() {
51 mutex_lock_guard lock(deviceMutex_);
55 const std::string& getName() {
56 mutex_lock_guard lock(deviceMutex_);
60 void setName(const std::string& name) {
61 mutex_lock_guard lock(deviceMutex_);
65 void addLink(const Link::SharedPtr& link) {
66 logDebug(DEVICE_TAG, "Entering Link::addLink");
68 mutex_lock_guard lock(deviceMutex_);
70 // If list is empty, go ahead and add
71 if (linkList_.empty())
73 logDebug(DEVICE_TAG, "Link::addLink, linkList empty, adding");
74 linkList_.push_back(link);
78 // Search list for the link. If already in list, return
79 for (auto iter = linkList_.begin(); iter != linkList_.end(); ++iter) {
81 logDebug(DEVICE_TAG, "Link::addLink, link already in linkList");
86 // Not already in list, so add
87 logDebug(DEVICE_TAG, "Link::addLink, adding link");
88 linkList_.push_back(link);
91 bool removeLink(const Link::SharedPtr& link) {
92 logDebug(DEVICE_TAG, "Entering Link::removeLink");
95 mutex_lock_guard lock(deviceMutex_);
96 // Return immediately if the list is empty
97 if (linkList_.empty()) {
98 logDebug(DEVICE_TAG, "Link::removeLink, linkList empty");
102 // Search list for the link. If in the list, return
103 for (auto iter = linkList_.begin(); iter != linkList_.end(); ++iter) {
105 linkList_.erase(iter);
106 logDebug(DEVICE_TAG, "Link::removeLink, removing link");
114 LinkList getLinks() {
115 mutex_lock_guard lock(deviceMutex_);
119 uint32_t getLinkCount() {
120 mutex_lock_guard lock(deviceMutex_);
121 return (uint32_t)linkList_.size();
137 #endif /* DEVICE_H_ */