Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2554)

Unified Diff: device/nfc/nfc_peer.h

Issue 77563002: nfc: Add native NFC API definitions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed clang error. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/nfc/nfc_ndef_record_unittest.cc ('k') | device/nfc/nfc_peer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/nfc/nfc_peer.h
diff --git a/device/nfc/nfc_peer.h b/device/nfc/nfc_peer.h
new file mode 100644
index 0000000000000000000000000000000000000000..6799971539dfc141f883eb3a31d7c07d2250023c
--- /dev/null
+++ b/device/nfc/nfc_peer.h
@@ -0,0 +1,92 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_NFC_NFC_PEER_H_
+#define DEVICE_NFC_NFC_PEER_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/callback.h"
+#include "device/nfc/nfc_ndef_record.h"
+
+namespace device {
+
+// NfcPeer represents a remote NFC adapter that is available for P2P
+// communication with the local adapter. Instances of NfcPeer allow two
+// kinds of P2P interaction that is supported by NFC:
+//
+// - NDEF. Specifically, reading NDEF records found on the peer device and
+// pushing NDEF records to it (e.g. via SNEP or Android Beam), in the form
+// of an NDEF message as specified by the NFC forum.
+// - Initiating a handover. On platforms that support it, handover can be
+// used to quickly bootstrap a Bluetooth or WiFi based connection between
+// the two devices over NFC.
+class NfcPeer {
+ public:
+ // NFC handover types.
+ enum HandoverType {
+ kHandoverTypeBluetooth,
+ kHandoverTypeWiFi
+ };
+
+ // Interface for observing changes from NFC peer devices.
+ class Observer {
+ public:
+ virtual ~Observer() {}
+
+ // This method will be called when an NDEF message |message| from the peer
+ // device |peer| is received. Users can use this method to be notified of
+ // new records on the device and when the initial set of records are
+ // received from it, if any.
+ virtual void RecordsReceived(NfcPeer* peer,
+ const NfcNdefMessage& message) {}
+ };
+
+ // The ErrorCallback is used by methods to asynchronously report errors.
+ typedef base::Closure ErrorCallback;
+
+ virtual ~NfcPeer();
+
+ // Adds and removes observers for events on this NFC peer. If monitoring
+ // multiple peers, check the |peer| parameter of observer methods to
+ // determine which peer is issuing the event.
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
+
+ // Returns the unique identifier assigned to this peer.
+ virtual std::string GetIdentifier() const = 0;
+
+ // Returns all NDEF records that were received from the peer device in the
+ // form of a NDEF message. If the returned NDEF message contains no records,
+ // this only means that no records have yet been received from the device.
+ // Users should use this method in conjunction with the Observer methods
+ // to be notified when the records are ready.
+ virtual NfcNdefMessage GetNdefMessage() const = 0;
+
+ // Sends the NDEF records contained in |message| to the peer device. On
+ // success, |callback| will be invoked. On failure, |error_callback| will be
+ // invoked.
+ virtual void PushNdef(NfcNdefMessage* message,
+ const base::Closure& callback,
+ const ErrorCallback& error_callback) = 0;
+
+ // Initiates WiFi or Bluetooth pairing with the NFC peer device based on
+ // |handover_type|. On success, |callback| will be invoked. On failure,
+ // |error_callback| will be invoked.
+ virtual void StartHandover(HandoverType handover_type,
+ const base::Closure& callback,
+ const ErrorCallback& error_callback) = 0;
+
+ protected:
+ NfcPeer();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NfcPeer);
+};
+
+} // namespace device
+
+#endif // DEVICE_NFC_NFC_PEER_H_
« no previous file with comments | « device/nfc/nfc_ndef_record_unittest.cc ('k') | device/nfc/nfc_peer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698