dom/bluetooth/bluedroid/BluetoothSocket.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial