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