2012-09-28 04:46:37 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_bluetooth_bluetoothoppmanager_h__
|
|
|
|
#define mozilla_dom_bluetooth_bluetoothoppmanager_h__
|
|
|
|
|
|
|
|
#include "BluetoothCommon.h"
|
2012-09-28 03:59:12 -07:00
|
|
|
#include "mozilla/dom/ipc/Blob.h"
|
2012-09-28 04:46:37 -07:00
|
|
|
#include "mozilla/ipc/UnixSocket.h"
|
|
|
|
|
2012-10-30 20:15:12 -07:00
|
|
|
class nsIOutputStream;
|
|
|
|
class nsIInputStream;
|
|
|
|
|
2012-09-28 04:46:37 -07:00
|
|
|
BEGIN_BLUETOOTH_NAMESPACE
|
|
|
|
|
|
|
|
class BluetoothReplyRunnable;
|
|
|
|
|
|
|
|
class BluetoothOppManager : public mozilla::ipc::UnixSocketConsumer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*
|
|
|
|
* Channel of reserved services are fixed values, please check
|
|
|
|
* function add_reserved_service_records() in
|
|
|
|
* external/bluetooth/bluez/src/adapter.c for more information.
|
|
|
|
*/
|
|
|
|
static const int DEFAULT_OPP_CHANNEL = 10;
|
2012-09-27 07:59:27 -07:00
|
|
|
static const int MAX_PACKET_LENGTH = 0xFFFE;
|
2012-09-28 04:46:37 -07:00
|
|
|
|
|
|
|
~BluetoothOppManager();
|
|
|
|
static BluetoothOppManager* Get();
|
2012-10-10 22:49:11 -07:00
|
|
|
void ReceiveSocketData(mozilla::ipc::UnixSocketRawData* aMessage)
|
|
|
|
MOZ_OVERRIDE;
|
2012-09-28 04:46:37 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a application wnats to send a file, first, it needs to
|
|
|
|
* call Connect() to create a valid RFCOMM connection. After
|
|
|
|
* that, call SendFile()/StopSendingFile() to control file-sharing
|
|
|
|
* process. During the file transfering process, the application
|
|
|
|
* will receive several system messages which contain the processed
|
|
|
|
* percentage of file. At the end, the application will get another
|
|
|
|
* system message indicating that te process is complete, then it can
|
|
|
|
* either call Disconnect() to close RFCOMM connection or start another
|
|
|
|
* file-sending thread via calling SendFile() again.
|
|
|
|
*/
|
|
|
|
bool Connect(const nsAString& aDeviceObjectPath,
|
|
|
|
BluetoothReplyRunnable* aRunnable);
|
|
|
|
void Disconnect();
|
2012-10-14 23:16:41 -07:00
|
|
|
bool Listen();
|
2012-09-28 04:46:37 -07:00
|
|
|
|
2012-11-02 18:36:43 -07:00
|
|
|
bool SendFile(BlobParent* aBlob);
|
|
|
|
bool StopSendingFile();
|
|
|
|
bool ConfirmReceivingFile(bool aConfirm);
|
2012-09-28 04:46:37 -07:00
|
|
|
|
2012-09-28 05:03:36 -07:00
|
|
|
void SendConnectRequest();
|
|
|
|
void SendPutHeaderRequest(const nsAString& aFileName, int aFileSize);
|
|
|
|
void SendPutRequest(uint8_t* aFileBody, int aFileBodyLength,
|
|
|
|
bool aFinal);
|
|
|
|
void SendDisconnectRequest();
|
2012-10-03 00:09:27 -07:00
|
|
|
void SendAbortRequest();
|
2012-09-28 05:03:36 -07:00
|
|
|
|
2012-10-25 18:25:46 -07:00
|
|
|
nsresult HandleShutdown();
|
2012-09-28 04:46:37 -07:00
|
|
|
private:
|
|
|
|
BluetoothOppManager();
|
2012-10-12 04:14:21 -07:00
|
|
|
void StartFileTransfer(const nsString& aDeviceAddress,
|
|
|
|
bool aReceived,
|
|
|
|
const nsString& aFileName,
|
|
|
|
uint32_t aFileLength,
|
|
|
|
const nsString& aContentType);
|
|
|
|
void FileTransferComplete(const nsString& aDeviceAddress,
|
|
|
|
bool aSuccess,
|
|
|
|
bool aReceived,
|
|
|
|
const nsString& aFileName,
|
|
|
|
uint32_t aFileLength,
|
|
|
|
const nsString& aContentType);
|
|
|
|
void UpdateProgress(const nsString& aDeviceAddress,
|
|
|
|
bool aReceived,
|
|
|
|
uint32_t aProcessedLength,
|
|
|
|
uint32_t aFileLength);
|
2012-10-16 23:46:53 -07:00
|
|
|
void ReceivingFileConfirmation(const nsString& aAddress,
|
|
|
|
const nsString& aFileName,
|
|
|
|
uint32_t aFileLength,
|
|
|
|
const nsString& aContentType);
|
2012-11-07 17:46:31 -08:00
|
|
|
bool CreateFile();
|
|
|
|
bool WriteToFile(const uint8_t* aData, int aDataLength);
|
2012-11-02 18:36:49 -07:00
|
|
|
void DeleteReceivedFile();
|
2012-10-08 22:56:17 -07:00
|
|
|
void ReplyToConnect();
|
|
|
|
void ReplyToDisconnect();
|
2012-10-18 23:16:13 -07:00
|
|
|
void ReplyToPut(bool aFinal, bool aContinue);
|
2012-10-30 20:15:12 -07:00
|
|
|
void AfterOppConnected();
|
|
|
|
void AfterOppDisconnected();
|
2012-10-10 22:49:11 -07:00
|
|
|
virtual void OnConnectSuccess() MOZ_OVERRIDE;
|
|
|
|
virtual void OnConnectError() MOZ_OVERRIDE;
|
2012-10-12 11:38:14 -07:00
|
|
|
virtual void OnDisconnect() MOZ_OVERRIDE;
|
2012-09-27 07:59:27 -07:00
|
|
|
|
|
|
|
bool mConnected;
|
|
|
|
int mConnectionId;
|
|
|
|
int mLastCommand;
|
2012-09-28 05:03:36 -07:00
|
|
|
uint8_t mRemoteObexVersion;
|
|
|
|
uint8_t mRemoteConnectionFlags;
|
|
|
|
int mRemoteMaxPacketLength;
|
2012-10-03 00:09:27 -07:00
|
|
|
bool mAbortFlag;
|
2012-10-08 22:56:17 -07:00
|
|
|
int mPacketLeftLength;
|
2012-11-07 17:46:31 -08:00
|
|
|
int mBodySegmentLength;
|
|
|
|
int mReceivedDataBufferOffset;
|
2012-10-12 04:14:21 -07:00
|
|
|
nsString mConnectedDeviceAddress;
|
2012-10-16 23:48:52 -07:00
|
|
|
bool mPutFinal;
|
2012-10-18 23:16:13 -07:00
|
|
|
bool mWaitingForConfirmationFlag;
|
2012-10-30 20:15:12 -07:00
|
|
|
int mUpdateProgressCounter;
|
2012-11-02 18:36:19 -07:00
|
|
|
enum mozilla::ipc::SocketConnectionStatus mSocketStatus;
|
2012-09-28 05:03:36 -07:00
|
|
|
|
2012-11-07 17:46:31 -08:00
|
|
|
nsAutoPtr<uint8_t> mBodySegment;
|
|
|
|
nsAutoPtr<uint8_t> mReceivedDataBuffer;
|
|
|
|
|
2012-09-28 05:03:36 -07:00
|
|
|
nsCOMPtr<nsIDOMBlob> mBlob;
|
2012-10-03 00:09:27 -07:00
|
|
|
nsCOMPtr<nsIThread> mReadFileThread;
|
2012-10-30 20:15:12 -07:00
|
|
|
nsCOMPtr<nsIOutputStream> mOutputStream;
|
|
|
|
nsCOMPtr<nsIInputStream> mInputStream;
|
2012-11-13 22:29:11 -08:00
|
|
|
|
|
|
|
nsRefPtr<BluetoothReplyRunnable> mRunnable;
|
2012-09-28 04:46:37 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_BLUETOOTH_NAMESPACE
|
|
|
|
|
|
|
|
#endif
|