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.
5 #include "device/nfc/nfc_adapter.h"
7 #include "base/stl_util.h"
8 #include "device/nfc/nfc_peer.h"
9 #include "device/nfc/nfc_tag.h"
13 NfcAdapter::NfcAdapter() {
16 NfcAdapter::~NfcAdapter() {
17 STLDeleteValues(&peers_
);
18 STLDeleteValues(&tags_
);
21 void NfcAdapter::GetPeers(PeerList
* peer_list
) const {
23 for (PeersMap::const_iterator iter
= peers_
.begin();
24 iter
!= peers_
.end(); ++iter
) {
25 peer_list
->push_back(iter
->second
);
29 void NfcAdapter::GetTags(TagList
* tag_list
) const {
31 for (TagsMap::const_iterator iter
= tags_
.begin();
32 iter
!= tags_
.end(); ++iter
) {
33 tag_list
->push_back(iter
->second
);
37 NfcPeer
* NfcAdapter::GetPeer(const std::string
& identifier
) const {
38 PeersMap::const_iterator iter
= peers_
.find(identifier
);
39 if (iter
!= peers_
.end())
44 NfcTag
* NfcAdapter::GetTag(const std::string
& identifier
) const {
45 TagsMap::const_iterator iter
= tags_
.find(identifier
);
46 if (iter
!= tags_
.end())
51 void NfcAdapter::SetTag(const std::string
& identifier
, NfcTag
* tag
) {
52 if (GetTag(identifier
)) {
53 VLOG(1) << "Tag object for tag \"" << identifier
<< "\" already exists.";
56 tags_
[identifier
] = tag
;
59 void NfcAdapter::SetPeer(const std::string
& identifier
, NfcPeer
* peer
) {
60 if (GetPeer(identifier
)) {
61 VLOG(1) << "Peer object for peer \"" << identifier
<< "\" already exists.";
64 peers_
[identifier
] = peer
;
67 NfcTag
* 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.";
73 NfcTag
* tag
= iter
->second
;
78 NfcPeer
* 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.";
84 NfcPeer
* peer
= iter
->second
;
89 void NfcAdapter::ClearTags() {
93 void NfcAdapter::ClearPeers() {