| OLD | NEW |
| (Empty) |
| 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 #ifndef DEVICE_NFC_NFC_PEER_H_ | |
| 6 #define DEVICE_NFC_NFC_PEER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "device/nfc/nfc_ndef_record.h" | |
| 15 | |
| 16 namespace device { | |
| 17 | |
| 18 // NfcPeer represents a remote NFC adapter that is available for P2P | |
| 19 // communication with the local adapter. Instances of NfcPeer allow two | |
| 20 // kinds of P2P interaction that is supported by NFC: | |
| 21 // | |
| 22 // - NDEF. Specifically, reading NDEF records found on the peer device and | |
| 23 // pushing NDEF records to it (e.g. via SNEP or Android Beam), in the form | |
| 24 // of an NDEF message as specified by the NFC forum. | |
| 25 // - Initiating a handover. On platforms that support it, handover can be | |
| 26 // used to quickly bootstrap a Bluetooth or WiFi based connection between | |
| 27 // the two devices over NFC. | |
| 28 class NfcPeer { | |
| 29 public: | |
| 30 // NFC handover types. | |
| 31 enum HandoverType { | |
| 32 kHandoverTypeBluetooth, | |
| 33 kHandoverTypeWiFi | |
| 34 }; | |
| 35 | |
| 36 // Interface for observing changes from NFC peer devices. | |
| 37 class Observer { | |
| 38 public: | |
| 39 virtual ~Observer() {} | |
| 40 | |
| 41 // This method will be called when an NDEF record |record| from the peer | |
| 42 // device |peer| is received. Users can use this method to be notified of | |
| 43 // new records on the device and when the initial set of records are | |
| 44 // received from it, if any. All records received from |peer| can be | |
| 45 // accessed by calling |peer->GetNdefMessage()|. | |
| 46 virtual void RecordReceived(NfcPeer* peer, const NfcNdefRecord* record) {} | |
| 47 }; | |
| 48 | |
| 49 // The ErrorCallback is used by methods to asynchronously report errors. | |
| 50 typedef base::Closure ErrorCallback; | |
| 51 | |
| 52 virtual ~NfcPeer(); | |
| 53 | |
| 54 // Adds and removes observers for events on this NFC peer. If monitoring | |
| 55 // multiple peers, check the |peer| parameter of observer methods to | |
| 56 // determine which peer is issuing the event. | |
| 57 virtual void AddObserver(Observer* observer) = 0; | |
| 58 virtual void RemoveObserver(Observer* observer) = 0; | |
| 59 | |
| 60 // Returns the unique identifier assigned to this peer. | |
| 61 virtual std::string GetIdentifier() const = 0; | |
| 62 | |
| 63 // Returns all NDEF records that were received from the peer device in the | |
| 64 // form of a NDEF message. If the returned NDEF message contains no records, | |
| 65 // this only means that no records have yet been received from the device. | |
| 66 // Users should use this method in conjunction with the Observer methods | |
| 67 // to be notified when the records are ready. | |
| 68 virtual const NfcNdefMessage& GetNdefMessage() const = 0; | |
| 69 | |
| 70 // Sends the NDEF records contained in |message| to the peer device. On | |
| 71 // success, |callback| will be invoked. On failure, |error_callback| will be | |
| 72 // invoked. | |
| 73 virtual void PushNdef(const NfcNdefMessage& message, | |
| 74 const base::Closure& callback, | |
| 75 const ErrorCallback& error_callback) = 0; | |
| 76 | |
| 77 // Initiates WiFi or Bluetooth pairing with the NFC peer device based on | |
| 78 // |handover_type|. On success, |callback| will be invoked. On failure, | |
| 79 // |error_callback| will be invoked. | |
| 80 virtual void StartHandover(HandoverType handover_type, | |
| 81 const base::Closure& callback, | |
| 82 const ErrorCallback& error_callback) = 0; | |
| 83 | |
| 84 protected: | |
| 85 NfcPeer(); | |
| 86 | |
| 87 private: | |
| 88 DISALLOW_COPY_AND_ASSIGN(NfcPeer); | |
| 89 }; | |
| 90 | |
| 91 } // namespace device | |
| 92 | |
| 93 #endif // DEVICE_NFC_NFC_PEER_H_ | |
| OLD | NEW |