dom/bluetooth/bluedroid/BluetoothSocket.h

branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
equal deleted inserted replaced
-1:000000000000 0:12ff00c646c0
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef mozilla_dom_bluetooth_BluetoothSocket_h
8 #define mozilla_dom_bluetooth_BluetoothSocket_h
9
10 #include "BluetoothCommon.h"
11 #include "mozilla/ipc/UnixSocket.h"
12
13 BEGIN_BLUETOOTH_NAMESPACE
14
15 class BluetoothSocketObserver;
16 class DroidSocketImpl;
17
18 class BluetoothSocket : public mozilla::ipc::UnixSocketConsumer
19 {
20 public:
21 BluetoothSocket(BluetoothSocketObserver* aObserver,
22 BluetoothSocketType aType,
23 bool aAuth,
24 bool aEncrypt);
25
26 /**
27 * Connect to remote server as a client.
28 *
29 * The steps are as following:
30 * 1) BluetoothSocket acquires fd from bluedroid, and creates
31 * a DroidSocketImpl to watch read/write of the fd.
32 * 2) DroidSocketImpl receives first 2 messages to get socket info.
33 * 3) Obex client session starts.
34 */
35 bool Connect(const nsAString& aDeviceAddress, int aChannel);
36
37 /**
38 * Listen to incoming connection as a server.
39 *
40 * The steps are as following:
41 * 1) BluetoothSocket acquires fd from bluedroid, and creates
42 * a DroidSocketImpl to watch read of the fd. DroidSocketImpl
43 * receives the 1st message immediately.
44 * 2) When there's incoming connection, DroidSocketImpl receives
45 * 2nd message to get socket info and client fd.
46 * 3) DroidSocketImpl stops watching read of original fd and
47 * starts to watch read/write of client fd.
48 * 4) Obex server session starts.
49 */
50 bool Listen(int aChannel);
51
52 inline void Disconnect()
53 {
54 CloseDroidSocket();
55 }
56
57 virtual void OnConnectSuccess() MOZ_OVERRIDE;
58 virtual void OnConnectError() MOZ_OVERRIDE;
59 virtual void OnDisconnect() MOZ_OVERRIDE;
60 virtual void ReceiveSocketData(
61 nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE;
62
63 inline void GetAddress(nsAString& aDeviceAddress)
64 {
65 aDeviceAddress = mDeviceAddress;
66 }
67
68 void CloseDroidSocket();
69 bool SendDroidSocketData(mozilla::ipc::UnixSocketRawData* aData);
70
71 private:
72 BluetoothSocketObserver* mObserver;
73 DroidSocketImpl* mImpl;
74 nsString mDeviceAddress;
75 bool mAuth;
76 bool mEncrypt;
77 bool mIsServer;
78 int mReceivedSocketInfoLength;
79
80 bool ReceiveSocketInfo(nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage);
81 };
82
83 END_BLUETOOTH_NAMESPACE
84
85 #endif

mercurial