1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bluetooth/bluedroid/BluetoothSocket.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_bluetooth_BluetoothSocket_h 1.11 +#define mozilla_dom_bluetooth_BluetoothSocket_h 1.12 + 1.13 +#include "BluetoothCommon.h" 1.14 +#include "mozilla/ipc/UnixSocket.h" 1.15 + 1.16 +BEGIN_BLUETOOTH_NAMESPACE 1.17 + 1.18 +class BluetoothSocketObserver; 1.19 +class DroidSocketImpl; 1.20 + 1.21 +class BluetoothSocket : public mozilla::ipc::UnixSocketConsumer 1.22 +{ 1.23 +public: 1.24 + BluetoothSocket(BluetoothSocketObserver* aObserver, 1.25 + BluetoothSocketType aType, 1.26 + bool aAuth, 1.27 + bool aEncrypt); 1.28 + 1.29 + /** 1.30 + * Connect to remote server as a client. 1.31 + * 1.32 + * The steps are as following: 1.33 + * 1) BluetoothSocket acquires fd from bluedroid, and creates 1.34 + * a DroidSocketImpl to watch read/write of the fd. 1.35 + * 2) DroidSocketImpl receives first 2 messages to get socket info. 1.36 + * 3) Obex client session starts. 1.37 + */ 1.38 + bool Connect(const nsAString& aDeviceAddress, int aChannel); 1.39 + 1.40 + /** 1.41 + * Listen to incoming connection as a server. 1.42 + * 1.43 + * The steps are as following: 1.44 + * 1) BluetoothSocket acquires fd from bluedroid, and creates 1.45 + * a DroidSocketImpl to watch read of the fd. DroidSocketImpl 1.46 + * receives the 1st message immediately. 1.47 + * 2) When there's incoming connection, DroidSocketImpl receives 1.48 + * 2nd message to get socket info and client fd. 1.49 + * 3) DroidSocketImpl stops watching read of original fd and 1.50 + * starts to watch read/write of client fd. 1.51 + * 4) Obex server session starts. 1.52 + */ 1.53 + bool Listen(int aChannel); 1.54 + 1.55 + inline void Disconnect() 1.56 + { 1.57 + CloseDroidSocket(); 1.58 + } 1.59 + 1.60 + virtual void OnConnectSuccess() MOZ_OVERRIDE; 1.61 + virtual void OnConnectError() MOZ_OVERRIDE; 1.62 + virtual void OnDisconnect() MOZ_OVERRIDE; 1.63 + virtual void ReceiveSocketData( 1.64 + nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE; 1.65 + 1.66 + inline void GetAddress(nsAString& aDeviceAddress) 1.67 + { 1.68 + aDeviceAddress = mDeviceAddress; 1.69 + } 1.70 + 1.71 + void CloseDroidSocket(); 1.72 + bool SendDroidSocketData(mozilla::ipc::UnixSocketRawData* aData); 1.73 + 1.74 +private: 1.75 + BluetoothSocketObserver* mObserver; 1.76 + DroidSocketImpl* mImpl; 1.77 + nsString mDeviceAddress; 1.78 + bool mAuth; 1.79 + bool mEncrypt; 1.80 + bool mIsServer; 1.81 + int mReceivedSocketInfoLength; 1.82 + 1.83 + bool ReceiveSocketInfo(nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage); 1.84 +}; 1.85 + 1.86 +END_BLUETOOTH_NAMESPACE 1.87 + 1.88 +#endif