OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 COMPONENTS_COPRESENCE_SOCKETS_COPRESENCE_PEER_H_ |
| 6 #define COMPONENTS_COPRESENCE_SOCKETS_COPRESENCE_PEER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 15 #include "device/bluetooth/bluetooth_device.h" |
| 16 #include "device/bluetooth/bluetooth_uuid.h" |
| 17 |
| 18 namespace device { |
| 19 class BluetoothAdapter; |
| 20 class BluetoothDevice; |
| 21 class BluetoothSocket; |
| 22 } |
| 23 |
| 24 namespace copresence_sockets { |
| 25 |
| 26 class CopresenceSocket; |
| 27 |
| 28 // A CopresencePeer is an object that can be connected to. Creating a peer |
| 29 // will create a server that will listen on a medium (currently only Bluetooth) |
| 30 // and accept connections. |
| 31 class CopresencePeer { |
| 32 public: |
| 33 // Callback with the locator data for the created peer. On a failed create, |
| 34 // the locator string will be empty. |
| 35 typedef base::Callback<void(const std::string&)> CreatePeerCallback; |
| 36 |
| 37 // Callback that accepts connections. The callback takes ownership of the |
| 38 // Copresence socket passed in the parameter. |
| 39 typedef base::Callback<void(scoped_ptr<CopresenceSocket> socket)> |
| 40 AcceptCallback; |
| 41 |
| 42 // Create a CopresencePeer and start listening for connections. Once the peer |
| 43 // object is created, the locator data for the object is returned via |
| 44 // create_callback. This locator data can be used to connect to this peer by |
| 45 // remote CopresenceSockets. Any connections accepted by this peer are |
| 46 // delivered as CopresenceSocket objects to accept_callback. |
| 47 CopresencePeer(const CreatePeerCallback& create_callback, |
| 48 const AcceptCallback& accept_callback); |
| 49 |
| 50 virtual ~CopresencePeer(); |
| 51 |
| 52 // This will return a string containing the data needed for a remote |
| 53 // CopresenceSocket to connect to this peer. |
| 54 std::string GetLocatorData(); |
| 55 |
| 56 private: |
| 57 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); |
| 58 void OnCreateService(scoped_refptr<device::BluetoothSocket> socket); |
| 59 void OnCreateServiceError(const std::string& message); |
| 60 |
| 61 void OnAccept(const device::BluetoothDevice* device, |
| 62 scoped_refptr<device::BluetoothSocket> socket); |
| 63 void OnAcceptError(const std::string& message); |
| 64 |
| 65 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 66 scoped_refptr<device::BluetoothSocket> server_socket_; |
| 67 device::BluetoothUUID service_uuid_; |
| 68 |
| 69 CreatePeerCallback create_callback_; |
| 70 AcceptCallback accept_callback_; |
| 71 |
| 72 scoped_ptr<device::BluetoothDevice::PairingDelegate> delegate_; |
| 73 |
| 74 base::WeakPtrFactory<CopresencePeer> weak_ptr_factory_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(CopresencePeer); |
| 77 }; |
| 78 |
| 79 } // namespace copresence_sockets |
| 80 |
| 81 #endif // COMPONENTS_COPRESENCE_SOCKETS_COPRESENCE_PEER_H_ |
OLD | NEW |