OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 #ifndef DEVICE_NFC_NFC_TAG_H_ |
| 6 #define DEVICE_NFC_NFC_TAG_H_ |
| 7 |
| 8 #include "device/nfc/nfc_tag_technology.h" |
| 9 |
| 10 namespace device { |
| 11 |
| 12 // NfcTag represents a remote NFC tag. An NFC tag is a passive NFC device, |
| 13 // powered by the NFC field of the local adapter while it is in range. Tags |
| 14 // can come in many forms, such as stickers, key fobs, or even embedded in a |
| 15 // more sofisticated device. |
| 16 // |
| 17 // Tags can have a wide range of capabilities. Simple tags just offer |
| 18 // read/write semantics, and contain some one time programmable areas to make |
| 19 // read-only. More complex tags offer math operations and per-sector access |
| 20 // control and authentication. The most sophisticated tags contain operating |
| 21 // environments allowing complex interactions with the code executing on the |
| 22 // tag. |
| 23 // |
| 24 // The NfcTag class facilitates possible interactions with a tag. The most |
| 25 // common usage of a tag is to exchange NDEF messages, but different kinds of |
| 26 // I/O can be performed using the NfcTagTechnology classes. |
| 27 class NfcTag { |
| 28 public: |
| 29 // NFC tag types. |
| 30 enum TagType { |
| 31 kTagType1, |
| 32 kTagType2, |
| 33 kTagType3, |
| 34 kTagType4 |
| 35 }; |
| 36 |
| 37 // NFC protocols that a tag can support. A tag will usually support only one |
| 38 // of these. |
| 39 enum Protocol { |
| 40 kProtocolFelica, |
| 41 kProtocolIsoDep, |
| 42 kProtocolJewel, |
| 43 kProtocolMifare, |
| 44 kProtocolNfcDep |
| 45 }; |
| 46 |
| 47 // Interface for observing changes from NFC tags. |
| 48 class Observer { |
| 49 public: |
| 50 virtual ~Observer() {} |
| 51 |
| 52 // This method will be called when an NDEF message |message|, stored on the |
| 53 // NFC tag |tag| has been read. Although NDEF is the most common record |
| 54 // storage format for NFC tags, not all tags support it. This method won't |
| 55 // be called if there are no records on an NDEF compliant tag or if the tag |
| 56 // doesn't support NDEF. |
| 57 virtual void RecordsReceived(NfcTag* tag, const NfcNdefMessage& message) {} |
| 58 }; |
| 59 |
| 60 virtual ~NfcTag(); |
| 61 |
| 62 // Adds and removes observers for events on this NFC tag. If monitoring |
| 63 // multiple tags, check the |tag| parameter of observer methods to determine |
| 64 // which tag is issuing the event. |
| 65 virtual void AddObserver(Observer* observer) = 0; |
| 66 virtual void RemoveObserver(Observer* observer) = 0; |
| 67 |
| 68 // Returns the unique identifier assigned to this tag. |
| 69 virtual std::string GetIdentifier() const = 0; |
| 70 |
| 71 // Returns the current tag's NFC forum specified "type". |
| 72 virtual TagType GetType() const = 0; |
| 73 |
| 74 // Returns true, if this tag is read-only and cannot be written to. |
| 75 virtual bool IsReadOnly() const = 0; |
| 76 |
| 77 // Returns the current tag's supported NFC protocol. |
| 78 virtual Protocol GetSupportedProtocol() const = 0; |
| 79 |
| 80 // Returns a bitmask of the tag I/O technologies supported by this tag. |
| 81 virtual NfcTagTechnology::TechnologyTypeMask |
| 82 GetSupportedTechnologies() const = 0; |
| 83 |
| 84 protected: |
| 85 NfcTag(); |
| 86 |
| 87 private: |
| 88 DISALLOW_COPY_AND_ASSIGN(NfcTag); |
| 89 }; |
| 90 |
| 91 } // namespace device |
| 92 |
| 93 #endif // DEVICE_NFC_NFC_TAG_H_ |
OLD | NEW |