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_TECHNOLOGY_H_ |
| 6 #define DEVICE_NFC_NFC_TAG_TECHNOLOGY_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "device/nfc/nfc_ndef_record.h" |
| 10 |
| 11 namespace device { |
| 12 |
| 13 class NfcTag; |
| 14 |
| 15 // NfcTagTechnology represents an NFC technology that allows a certain type of |
| 16 // I/O operation on an NFC tag. NFC tags can support a wide array of protocols. |
| 17 // The NfcTagTechnology hierarchy allows both raw and high-level I/O operations |
| 18 // on NFC tags. |
| 19 class NfcTagTechnology { |
| 20 public: |
| 21 // The various I/O technologies that an NFC tag can support. |
| 22 enum TechnologyType { |
| 23 kTechnologyTypeNfcA = 1 << 0, |
| 24 kTechnologyTypeNfcB = 1 << 1, |
| 25 kTechnologyTypeNfcF = 1 << 2, |
| 26 kTechnologyTypeNfcV = 1 << 3, |
| 27 kTechnologyTypeIsoDep = 1 << 4, |
| 28 kTechnologyTypeNdef = 1 << 5 |
| 29 }; |
| 30 typedef uint32 TechnologyTypeMask; |
| 31 |
| 32 virtual ~NfcTagTechnology(); |
| 33 |
| 34 // Returns true, if the underlying tag supports the NFC tag technology that |
| 35 // this instance represents. |
| 36 virtual bool IsSupportedByTag() const = 0; |
| 37 |
| 38 // Returns a pointer to the associated NfcTag instance. |
| 39 NfcTag* tag() const { return tag_; } |
| 40 |
| 41 protected: |
| 42 // Constructs a technology instance, where |tag| is the NFC tag that this |
| 43 // instance will operate on. Clients aren't allowed to instantiate classes |
| 44 // directly. They should use the static "Create" methods defined in each |
| 45 // subclass to obtain the platform specific implementation. |
| 46 explicit NfcTagTechnology(NfcTag* tag); |
| 47 |
| 48 private: |
| 49 NfcTagTechnology(); |
| 50 |
| 51 // The underlying NfcTag instance that data exchange operations through this |
| 52 // instance are performed on. |
| 53 NfcTag* tag_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(NfcTagTechnology); |
| 56 }; |
| 57 |
| 58 // NfcNdefTagTechnology allows reading and writing NDEF messages to a tag. This |
| 59 // is the most commonly used data exchange format in NFC. |
| 60 class NfcNdefTagTechnology : public NfcTagTechnology { |
| 61 public: |
| 62 // The ErrorCallback is used by methods to asynchronously report errors. |
| 63 typedef base::Closure ErrorCallback; |
| 64 |
| 65 virtual ~NfcNdefTagTechnology(); |
| 66 |
| 67 // NfcTagTechnology override. |
| 68 virtual bool IsSupportedByTag() const OVERRIDE; |
| 69 |
| 70 // Returns all NDEF records that were received from the tag in the form of an |
| 71 // NDEF message. If the returned NDEF message contains no records, this only |
| 72 // means that no records have yet been received from the tag. Users should |
| 73 // use this method in conjunction with the NfcTag::Observer::RecordsReceived |
| 74 // method to be notified when the records are ready. |
| 75 virtual NfcNdefMessage GetNdefMessage() const = 0; |
| 76 |
| 77 // Writes the given NDEF message to the underlying tag, overwriting any |
| 78 // existing NDEF message on it. On success, |callback| will be invoked. On |
| 79 // failure, |error_callback| will be invoked. This method can fail, if the |
| 80 // underlying tag does not support NDEF as a technology. |
| 81 virtual void WriteNdefMessage(const NfcNdefMessage& message, |
| 82 const base::Closure& callback, |
| 83 const ErrorCallback& error_callback) = 0; |
| 84 |
| 85 // Static factory method for constructing an instance. The ownership of the |
| 86 // returned instance belongs to the caller. Returns NULL, if NFC is not |
| 87 // supported on the current platform. |
| 88 static NfcNdefTagTechnology* Create(NfcTag* tag); |
| 89 |
| 90 private: |
| 91 // Constructs a technology instance, where |tag| is the NFC tag that this |
| 92 // instance will operate on. |
| 93 explicit NfcNdefTagTechnology(NfcTag* tag); |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(NfcNdefTagTechnology); |
| 96 }; |
| 97 |
| 98 } // namespace device |
| 99 |
| 100 #endif // DEVICE_NFC_NFC_TAG_TECHNOLOGY_H_ |
OLD | NEW |