Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
7 #ifndef mozilla_dom_bluetooth_BluetoothSocket_h
8 #define mozilla_dom_bluetooth_BluetoothSocket_h
10 #include "BluetoothCommon.h"
11 #include "mozilla/ipc/UnixSocket.h"
13 BEGIN_BLUETOOTH_NAMESPACE
15 class BluetoothSocketObserver;
16 class DroidSocketImpl;
18 class BluetoothSocket : public mozilla::ipc::UnixSocketConsumer
19 {
20 public:
21 BluetoothSocket(BluetoothSocketObserver* aObserver,
22 BluetoothSocketType aType,
23 bool aAuth,
24 bool aEncrypt);
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);
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);
52 inline void Disconnect()
53 {
54 CloseDroidSocket();
55 }
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;
63 inline void GetAddress(nsAString& aDeviceAddress)
64 {
65 aDeviceAddress = mDeviceAddress;
66 }
68 void CloseDroidSocket();
69 bool SendDroidSocketData(mozilla::ipc::UnixSocketRawData* aData);
71 private:
72 BluetoothSocketObserver* mObserver;
73 DroidSocketImpl* mImpl;
74 nsString mDeviceAddress;
75 bool mAuth;
76 bool mEncrypt;
77 bool mIsServer;
78 int mReceivedSocketInfoLength;
80 bool ReceiveSocketInfo(nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage);
81 };
83 END_BLUETOOTH_NAMESPACE
85 #endif