mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-08 12:37:37 +00:00
01583602a9
The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
115 lines
3.3 KiB
C++
115 lines
3.3 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=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_bluedroid_BluetoothSocketMessageWatcher_h
|
|
#define mozilla_dom_bluetooth_bluedroid_BluetoothSocketMessageWatcher_h
|
|
|
|
#include "base/message_loop.h"
|
|
#include "BluetoothCommon.h"
|
|
|
|
BEGIN_BLUETOOTH_NAMESPACE
|
|
|
|
class BluetoothSocketResultHandler;
|
|
|
|
/* |SocketMessageWatcher| receives Bluedroid's socket setup
|
|
* messages on the I/O thread. You need to inherit from this
|
|
* class to make use of it.
|
|
*
|
|
* Bluedroid sends two socket info messages (20 bytes) at
|
|
* the beginning of a connection to both peers.
|
|
*
|
|
* - 1st message: [channel:4]
|
|
* - 2nd message: [size:2][bd address:6][channel:4][connection status:4]
|
|
*
|
|
* On the server side, the second message will contain a
|
|
* socket file descriptor for the connection. The client
|
|
* uses the original file descriptor.
|
|
*/
|
|
class SocketMessageWatcher : public MessageLoopForIO::Watcher
|
|
{
|
|
public:
|
|
static const unsigned char MSG1_SIZE = 4;
|
|
static const unsigned char MSG2_SIZE = 16;
|
|
|
|
static const unsigned char OFF_CHANNEL1 = 0;
|
|
static const unsigned char OFF_SIZE = 4;
|
|
static const unsigned char OFF_BDADDRESS = 6;
|
|
static const unsigned char OFF_CHANNEL2 = 12;
|
|
static const unsigned char OFF_STATUS = 16;
|
|
|
|
virtual ~SocketMessageWatcher();
|
|
|
|
virtual void Proceed(BluetoothStatus aStatus) = 0;
|
|
|
|
void OnFileCanReadWithoutBlocking(int aFd) override;
|
|
void OnFileCanWriteWithoutBlocking(int aFd) override;
|
|
|
|
void Watch();
|
|
void StopWatching();
|
|
|
|
bool IsComplete() const;
|
|
|
|
int GetFd() const;
|
|
int32_t GetChannel1() const;
|
|
int32_t GetSize() const;
|
|
BluetoothAddress GetBdAddress() const;
|
|
int32_t GetChannel2() const;
|
|
int32_t GetConnectionStatus() const;
|
|
int GetClientFd() const;
|
|
|
|
BluetoothSocketResultHandler* GetResultHandler() const;
|
|
|
|
protected:
|
|
SocketMessageWatcher(int aFd, BluetoothSocketResultHandler* aRes);
|
|
|
|
private:
|
|
BluetoothStatus RecvMsg1();
|
|
BluetoothStatus RecvMsg2();
|
|
|
|
int16_t ReadInt16(unsigned long aOffset) const;
|
|
int32_t ReadInt32(unsigned long aOffset) const;
|
|
void ReadBdAddress(unsigned long aOffset, BluetoothAddress& aBdAddress) const;
|
|
|
|
MessageLoopForIO::FileDescriptorWatcher mWatcher;
|
|
int mFd;
|
|
int mClientFd;
|
|
unsigned char mLen;
|
|
uint8_t mBuf[MSG1_SIZE + MSG2_SIZE];
|
|
RefPtr<BluetoothSocketResultHandler> mRes;
|
|
};
|
|
|
|
/* |SocketMessageWatcherTask| starts a SocketMessageWatcher
|
|
* on the I/O task
|
|
*/
|
|
class SocketMessageWatcherTask final : public Task
|
|
{
|
|
public:
|
|
SocketMessageWatcherTask(SocketMessageWatcher* aWatcher);
|
|
|
|
void Run() override;
|
|
|
|
private:
|
|
SocketMessageWatcher* mWatcher;
|
|
};
|
|
|
|
/* |DeleteSocketMessageWatcherTask| deletes a watching SocketMessageWatcher
|
|
* on the I/O task
|
|
*/
|
|
class DeleteSocketMessageWatcherTask final : public Task
|
|
{
|
|
public:
|
|
DeleteSocketMessageWatcherTask(BluetoothSocketResultHandler* aRes);
|
|
|
|
void Run() override;
|
|
|
|
private:
|
|
BluetoothSocketResultHandler* mRes;
|
|
};
|
|
|
|
END_BLUETOOTH_NAMESPACE
|
|
|
|
#endif // mozilla_dom_bluetooth_bluedroid_BluetoothSocketMessageWatcher_h
|