1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "device/nfc/nfc_adapter.h" 6 7 #include "base/stl_util.h" 8 #include "device/nfc/nfc_peer.h" 9 #include "device/nfc/nfc_tag.h" 10 11 namespace device { 12 NfcAdapter()13NfcAdapter::NfcAdapter() { 14 } 15 ~NfcAdapter()16NfcAdapter::~NfcAdapter() { 17 STLDeleteValues(&peers_); 18 STLDeleteValues(&tags_); 19 } 20 GetPeers(PeerList * peer_list) const21void NfcAdapter::GetPeers(PeerList* peer_list) const { 22 peer_list->clear(); 23 for (PeersMap::const_iterator iter = peers_.begin(); 24 iter != peers_.end(); ++iter) { 25 peer_list->push_back(iter->second); 26 } 27 } 28 GetTags(TagList * tag_list) const29void NfcAdapter::GetTags(TagList* tag_list) const { 30 tag_list->clear(); 31 for (TagsMap::const_iterator iter = tags_.begin(); 32 iter != tags_.end(); ++iter) { 33 tag_list->push_back(iter->second); 34 } 35 } 36 GetPeer(const std::string & identifier) const37NfcPeer* NfcAdapter::GetPeer(const std::string& identifier) const { 38 PeersMap::const_iterator iter = peers_.find(identifier); 39 if (iter != peers_.end()) 40 return iter->second; 41 return NULL; 42 } 43 GetTag(const std::string & identifier) const44NfcTag* NfcAdapter::GetTag(const std::string& identifier) const { 45 TagsMap::const_iterator iter = tags_.find(identifier); 46 if (iter != tags_.end()) 47 return iter->second; 48 return NULL; 49 } 50 SetTag(const std::string & identifier,NfcTag * tag)51void NfcAdapter::SetTag(const std::string& identifier, NfcTag* tag) { 52 if (GetTag(identifier)) { 53 VLOG(1) << "Tag object for tag \"" << identifier << "\" already exists."; 54 return; 55 } 56 tags_[identifier] = tag; 57 } 58 SetPeer(const std::string & identifier,NfcPeer * peer)59void NfcAdapter::SetPeer(const std::string& identifier, NfcPeer* peer) { 60 if (GetPeer(identifier)) { 61 VLOG(1) << "Peer object for peer \"" << identifier << "\" already exists."; 62 return; 63 } 64 peers_[identifier] = peer; 65 } 66 RemoveTag(const std::string & identifier)67NfcTag* NfcAdapter::RemoveTag(const std::string& identifier) { 68 TagsMap::iterator iter = tags_.find(identifier); 69 if (iter == tags_.end()) { 70 VLOG(1) << "Tag with identifier \"" << identifier << "\" not found."; 71 return NULL; 72 } 73 NfcTag* tag = iter->second; 74 tags_.erase(iter); 75 return tag; 76 } 77 RemovePeer(const std::string & identifier)78NfcPeer* NfcAdapter::RemovePeer(const std::string& identifier) { 79 PeersMap::iterator iter = peers_.find(identifier); 80 if (iter == peers_.end()) { 81 VLOG(1) << "Peer object for peer \"" << identifier << "\" not found."; 82 return NULL; 83 } 84 NfcPeer* peer = iter->second; 85 peers_.erase(iter); 86 return peer; 87 } 88 ClearTags()89void NfcAdapter::ClearTags() { 90 tags_.clear(); 91 } 92 ClearPeers()93void NfcAdapter::ClearPeers() { 94 peers_.clear(); 95 } 96 97 } // namespace device 98