OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 class IOBuffer; | 14 class IOBuffer; |
15 } // namespace net | 15 } // namespace net |
16 | 16 |
17 namespace device { | 17 namespace device { |
18 | 18 |
| 19 class BluetoothDevice; |
| 20 class BluetoothUUID; |
| 21 |
19 // BluetoothSocket represents a socket to a specific service on a | 22 // BluetoothSocket represents a socket to a specific service on a |
20 // BluetoothDevice. BluetoothSocket objects are ref counted and may outlive | 23 // BluetoothDevice. BluetoothSocket objects are ref counted and may outlive |
21 // both the BluetoothDevice and BluetoothAdapter that were involved in their | 24 // both the BluetoothDevice and BluetoothAdapter that were involved in their |
22 // creation. In terms of threading, platform specific implementations may | 25 // creation. In terms of threading, platform specific implementations may |
23 // differ slightly, but platform independent consumers must guarantee calling | 26 // differ slightly, but platform independent consumers must guarantee calling |
24 // various instance methods on the same thread as the thread used at | 27 // various instance methods on the same thread as the thread used at |
25 // construction time -- platform specific implementation are resonsible for | 28 // construction time -- platform specific implementation are resonsible for |
26 // marshalling calls to a different thread if required. | 29 // marshalling calls to a different thread if required. |
27 class BluetoothSocket : public base::RefCountedThreadSafe<BluetoothSocket> { | 30 class BluetoothSocket : public base::RefCountedThreadSafe<BluetoothSocket> { |
28 public: | 31 public: |
29 enum ErrorReason { kSystemError, kIOPending, kDisconnected }; | 32 enum ErrorReason { kSystemError, kIOPending, kDisconnected }; |
30 | 33 |
31 typedef base::Callback<void(int)> SendCompletionCallback; | 34 typedef base::Callback<void(int)> SendCompletionCallback; |
32 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> | 35 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> |
33 ReceiveCompletionCallback; | 36 ReceiveCompletionCallback; |
| 37 typedef base::Callback<void(const BluetoothDevice* device, |
| 38 scoped_refptr<BluetoothSocket> socket)> |
| 39 AcceptCompletionCallback; |
34 typedef base::Callback<void(const std::string& error_message)> | 40 typedef base::Callback<void(const std::string& error_message)> |
35 ErrorCompletionCallback; | 41 ErrorCompletionCallback; |
36 typedef base::Callback<void(ErrorReason, const std::string& error_message)> | 42 typedef base::Callback<void(ErrorReason, const std::string& error_message)> |
37 ReceiveErrorCompletionCallback; | 43 ReceiveErrorCompletionCallback; |
38 | 44 |
39 // Destroys resources associated with the socket. After calling this method, | 45 // Destroys resources associated with the socket. After calling this method, |
40 // it is illegal to call any method on this socket instance (except for the | 46 // it is illegal to call any method on this socket instance (except for the |
41 // desctrutor via Release). | 47 // desctrutor via Release). |
42 virtual void Close() = 0; | 48 virtual void Close() = 0; |
43 | 49 |
(...skipping 11 matching lines...) Expand all Loading... |
55 const ReceiveErrorCompletionCallback& error_callback) = 0; | 61 const ReceiveErrorCompletionCallback& error_callback) = 0; |
56 | 62 |
57 // Sends |buffer| to the socket and calls |success_callback| when data has | 63 // Sends |buffer| to the socket and calls |success_callback| when data has |
58 // been successfully sent. |buffer_size| is the number of bytes contained in | 64 // been successfully sent. |buffer_size| is the number of bytes contained in |
59 // |buffer|. If an error occurs, calls |error_callback| with an error message. | 65 // |buffer|. If an error occurs, calls |error_callback| with an error message. |
60 virtual void Send(scoped_refptr<net::IOBuffer> buffer, | 66 virtual void Send(scoped_refptr<net::IOBuffer> buffer, |
61 int buffer_size, | 67 int buffer_size, |
62 const SendCompletionCallback& success_callback, | 68 const SendCompletionCallback& success_callback, |
63 const ErrorCompletionCallback& error_callback) = 0; | 69 const ErrorCompletionCallback& error_callback) = 0; |
64 | 70 |
| 71 // Accepts a pending client connection from the socket and calls |
| 72 // |success_callback| on completion, passing a new BluetoothSocket instance |
| 73 // for the new client. If an error occurs, calls |error_callback| with a |
| 74 // reason and an error message. |
| 75 virtual void Accept(const AcceptCompletionCallback& success_callback, |
| 76 const ErrorCompletionCallback& error_callback) = 0; |
| 77 |
65 protected: | 78 protected: |
66 friend class base::RefCountedThreadSafe<BluetoothSocket>; | 79 friend class base::RefCountedThreadSafe<BluetoothSocket>; |
67 virtual ~BluetoothSocket(); | 80 virtual ~BluetoothSocket(); |
68 }; | 81 }; |
69 | 82 |
70 } // namespace device | 83 } // namespace device |
71 | 84 |
72 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ | 85 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ |
OLD | NEW |