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 : public base::SupportsWeakPtr<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; | |
armansito
2014/09/30 20:37:58
nit: Add newline after the typedefs.
rkc
2014/10/01 19:08:24
Done.
| |
36 // Callback that accepts connections. The callback takes ownership of the | |
37 // Copresence socket passed in the parameter. | |
38 typedef base::Callback<void(CopresenceSocket* socket)> AcceptCallback; | |
Cait (Slow)
2014/09/30 17:56:01
Pass a scoped_ptr instead?
rkc
2014/10/01 19:08:24
Done.
| |
39 // Create a CopresencePeer and start listening for connections. Once the peer | |
40 // object is created, the locator data for the object is returned via | |
41 // create_callback. This locator data can be used to connect to this peer by | |
42 // remote CopresenceSockets. Any connections accepted by this peer are | |
43 // delivered as CopresenceSocket objects to accept_callback. | |
44 CopresencePeer(CreatePeerCallback create_callback, | |
45 AcceptCallback accept_callback); | |
46 | |
47 // This will return a string containing the data needed for a remote | |
48 // CopresenceSocket to connect to this peer. | |
49 std::string GetLocatorData(); | |
50 | |
51 virtual ~CopresencePeer(); | |
armansito
2014/09/30 20:37:58
nit: Move destructor below the constructor.
rkc
2014/10/01 19:08:24
Done.
| |
52 | |
53 private: | |
54 void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); | |
55 void OnCreateService(scoped_refptr<device::BluetoothSocket> socket); | |
56 void OnCreateServiceError(const std::string& message); | |
57 | |
58 void OnAccept(const device::BluetoothDevice* device, | |
59 scoped_refptr<device::BluetoothSocket> socket); | |
60 void OnAcceptError(const std::string& message); | |
61 | |
62 scoped_refptr<device::BluetoothAdapter> adapter_; | |
63 scoped_refptr<device::BluetoothSocket> server_socket_; | |
64 device::BluetoothUUID service_uuid_; | |
65 | |
66 CreatePeerCallback create_callback_; | |
67 AcceptCallback accept_callback_; | |
68 | |
69 device::BluetoothDevice::PairingDelegate* delegate_; | |
Cait (Slow)
2014/09/30 17:56:01
scoped_ptr<device::BluetoothDevice::PairingDelegat
rkc
2014/10/01 19:08:24
Done.
| |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(CopresencePeer); | |
72 }; | |
73 | |
74 } // namespace copresence_sockets | |
75 | |
76 #endif // COMPONENTS_COPRESENCE_SOCKETS_COPRESENCE_PEER_H_ | |
OLD | NEW |