mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
538b35a4ee
- Bug 1147951, part 2 - Remove unused JAVASCRIPT definition from nsJSEnvironment.cpp. r=baku (607909217) - Bug 1147951, part 1 - Remove uses of JAVASCRIPT2 from Console.cpp. r=baku (46cde7cfa) - pointer style (5504c22d4) - Bug 1165384 - Add a typedef for the statistics phase table; r=sfink (484a24237) - Bug 1165385 - Remove the rarely used !fullFormat mode of MOZ_GCTIMER; r=sfink (ab8b17eb1) - Bug 1165390 - Make the detailed statistics formatting methods have consistent names; r=sfink (55c5db543) - Bug 1165410 - Reimplement GC statistics JSON output formatter; r=sfink (04c13c874) - Bug 1166789 - Cleanup javascript.options.mem.log formatting; r=sfink, r=mccr8 (f23b455b4) - Bug 1171451 - Use the correct type for the argv argument to NS_CreateJSArgv and the nsJSArgArray constructor; r=jst (edfa21a59) - Bug 886459, part 1 - Remove unused includes of nsIJSRuntimeService.h. r=bholley (bbc277ac1) - Bug 886459, part 2 - Remove context callbacks from XPCJSRuntime. r=bholley (2c3c8515a) - Bug 886459, part 3 - Remove simple uses of nsIJSRuntimeService to get the JSRuntime. r=bholley (ff5bfe304) - pointer style (2ea264afd) - Bug 1169457 - Add null check in OnWrapperDestroy. r=jimm (741739513) - Bug 886459, part 4 - Remove nsIJSRuntimeService. r=bholley,aklotz (61563f53b) - Bug 1176642 - Use absolute_import in mach_commands.py files; r=glandium (a9fcb3b3f) - Bug 1176642 - Defer import of autotry and pprint; r=chmanchester (de40855cb) - Bug 1178772 - Add check_macroassembler_style.py: Verify that each MacroAssembler declaration maps to all its definitions. r=h4writer (fd406593a) - Bug 1152556 - Add moz.build bugzilla metadata in dom/media. r=kinetik (fa2ffa121) - Bug 1152556 - Add moz.build bugzilla metadata in dom/media webrtc. r=abr (d208b839a) - re-enable peerconnection (42e8c412b) - Bug 1152538 - Enable WebRTC identity, r=jesup (13a47adcb) - Bug 1231123 - Simplify LaunchApp on BSDs by dropping fork/exec version. r=jld (c35e6e36f) - bug 1171120 - Fix mtransport+signalling to build on iOS. r=ekr (7034b20ab) - Bug 1150609 Patch 1 WebRTC SDP - add tmmbr to offer. r=jesup (52ca72d09) - Bug 1150609 Patch 2 - WebRTC enable tmmbr r=jesup (d59c6adb9) - Bug 1150609 Patch 3 - WebRTC enable tmmbr unittest changes. r=jesup (eeffed826) - Bug 1087161 - Upgrading B2G toolchain to gcc-4.9 (851194ca0)
767 lines
18 KiB
C++
767 lines
18 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_bluetoothinterfacehelpers_h
|
|
#define mozilla_dom_bluetooth_bluetoothinterfacehelpers_h
|
|
|
|
#include "BluetoothCommon.h"
|
|
#include "nsThreadUtils.h"
|
|
|
|
BEGIN_BLUETOOTH_NAMESPACE
|
|
|
|
//
|
|
// Conversion
|
|
//
|
|
|
|
nsresult
|
|
Convert(nsresult aIn, BluetoothStatus& aOut);
|
|
|
|
//
|
|
// Result handling
|
|
//
|
|
// The classes of type |BluetoothResultRunnable[0..3]| transfer
|
|
// a result handler from the I/O thread to the main thread for
|
|
// execution. Call the methods |Create| and |Dispatch| to create or
|
|
// create-and-dispatch a result runnable.
|
|
//
|
|
// You need to specify the called method. The |Create| and |Dispatch|
|
|
// methods of |BluetoothResultRunnable[1..3]| receive an extra argument
|
|
// for initializing the result's arguments. During creation, the result
|
|
// runnable calls the supplied class's call operator with the result's
|
|
// argument. This is where initialization and conversion from backend-
|
|
// specific types is performed.
|
|
//
|
|
|
|
template <typename Obj, typename Res>
|
|
class BluetoothResultRunnable0 : public nsRunnable
|
|
{
|
|
public:
|
|
typedef BluetoothResultRunnable0<Obj, Res> SelfType;
|
|
|
|
template <typename InitOp>
|
|
static already_AddRefed<SelfType>
|
|
Create(Obj* aObj, Res (Obj::*aMethod)(), const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable(new SelfType(aObj, aMethod));
|
|
if (NS_FAILED(runnable->Init(aInitOp))) {
|
|
return nullptr;
|
|
}
|
|
return runnable.forget();
|
|
}
|
|
|
|
template <typename InitOp>
|
|
static void
|
|
Dispatch(Obj* aObj, Res (Obj::*aMethod)(), const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable = Create(aObj, aMethod, aInitOp);
|
|
if (!runnable) {
|
|
BT_LOGR("BluetoothResultRunnable0::Create failed");
|
|
return;
|
|
}
|
|
nsresult rv = NS_DispatchToMainThread(runnable);
|
|
if (NS_FAILED(rv)) {
|
|
BT_LOGR("NS_DispatchToMainThread failed: %X", unsigned(rv));
|
|
}
|
|
}
|
|
|
|
NS_METHOD
|
|
Run() override
|
|
{
|
|
((*mObj).*mMethod)();
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
BluetoothResultRunnable0(Obj* aObj, Res (Obj::*aMethod)())
|
|
: mObj(aObj)
|
|
, mMethod(aMethod)
|
|
{
|
|
MOZ_ASSERT(mObj);
|
|
MOZ_ASSERT(mMethod);
|
|
}
|
|
|
|
template<typename InitOp>
|
|
nsresult
|
|
Init(const InitOp& aInitOp)
|
|
{
|
|
return aInitOp();
|
|
}
|
|
|
|
nsRefPtr<Obj> mObj;
|
|
void (Obj::*mMethod)();
|
|
};
|
|
|
|
template <typename Obj, typename Res, typename Tin1, typename Arg1>
|
|
class BluetoothResultRunnable1 : public nsRunnable
|
|
{
|
|
public:
|
|
typedef BluetoothResultRunnable1<Obj, Res, Tin1, Arg1> SelfType;
|
|
|
|
template <typename InitOp>
|
|
static already_AddRefed<SelfType>
|
|
Create(Obj* aObj, Res (Obj::*aMethod)(Arg1), const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable(new SelfType(aObj, aMethod));
|
|
if (NS_FAILED(runnable->Init(aInitOp))) {
|
|
return nullptr;
|
|
}
|
|
return runnable.forget();
|
|
}
|
|
|
|
template <typename InitOp>
|
|
static void
|
|
Dispatch(Obj* aObj, Res (Obj::*aMethod)(Arg1), const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable = Create(aObj, aMethod, aInitOp);
|
|
if (!runnable) {
|
|
BT_LOGR("BluetoothResultRunnable1::Create failed");
|
|
return;
|
|
}
|
|
nsresult rv = NS_DispatchToMainThread(runnable);
|
|
if (NS_FAILED(rv)) {
|
|
BT_LOGR("NS_DispatchToMainThread failed: %X", unsigned(rv));
|
|
}
|
|
}
|
|
|
|
NS_METHOD
|
|
Run() override
|
|
{
|
|
((*mObj).*mMethod)(mArg1);
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
BluetoothResultRunnable1(Obj* aObj, Res (Obj::*aMethod)(Arg1))
|
|
: mObj(aObj)
|
|
, mMethod(aMethod)
|
|
{
|
|
MOZ_ASSERT(mObj);
|
|
MOZ_ASSERT(mMethod);
|
|
}
|
|
|
|
template<typename InitOp>
|
|
nsresult
|
|
Init(const InitOp& aInitOp)
|
|
{
|
|
return aInitOp(mArg1);
|
|
}
|
|
|
|
nsRefPtr<Obj> mObj;
|
|
Res (Obj::*mMethod)(Arg1);
|
|
Tin1 mArg1;
|
|
};
|
|
|
|
template <typename Obj, typename Res,
|
|
typename Tin1, typename Tin2, typename Tin3,
|
|
typename Arg1, typename Arg2, typename Arg3>
|
|
class BluetoothResultRunnable3 : public nsRunnable
|
|
{
|
|
public:
|
|
typedef BluetoothResultRunnable3<Obj, Res,
|
|
Tin1, Tin2, Tin3,
|
|
Arg1, Arg2, Arg3> SelfType;
|
|
|
|
template<typename InitOp>
|
|
static already_AddRefed<SelfType>
|
|
Create(Obj* aObj, Res (Obj::*aMethod)(Arg1, Arg2, Arg3),
|
|
const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable(new SelfType(aObj, aMethod));
|
|
if (NS_FAILED(runnable->Init(aInitOp))) {
|
|
return nullptr;
|
|
}
|
|
return runnable.forget();
|
|
}
|
|
|
|
template<typename InitOp>
|
|
static void
|
|
Dispatch(Obj* aObj, Res (Obj::*aMethod)(Arg1, Arg2, Arg3),
|
|
const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable = Create(aObj, aMethod, aInitOp);
|
|
if (!runnable) {
|
|
BT_LOGR("BluetoothResultRunnable3::Create failed");
|
|
return;
|
|
}
|
|
nsresult rv = NS_DispatchToMainThread(runnable);
|
|
if (NS_FAILED(rv)) {
|
|
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
|
}
|
|
}
|
|
|
|
NS_METHOD
|
|
Run() override
|
|
{
|
|
((*mObj).*mMethod)(mArg1, mArg2, mArg3);
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
BluetoothResultRunnable3(Obj* aObj, Res (Obj::*aMethod)(Arg1, Arg2, Arg3))
|
|
: mObj(aObj)
|
|
, mMethod(aMethod)
|
|
{
|
|
MOZ_ASSERT(mObj);
|
|
MOZ_ASSERT(mMethod);
|
|
}
|
|
|
|
template<typename InitOp>
|
|
nsresult
|
|
Init(const InitOp& aInitOp)
|
|
{
|
|
return aInitOp(mArg1, mArg2, mArg3);
|
|
}
|
|
|
|
nsRefPtr<Obj> mObj;
|
|
Res (Obj::*mMethod)(Arg1, Arg2, Arg3);
|
|
Tin1 mArg1;
|
|
Tin2 mArg2;
|
|
Tin3 mArg3;
|
|
};
|
|
|
|
//
|
|
// Notification handling
|
|
//
|
|
// The classes of type |BluetoothNotificationRunnable[0..5]| transfer
|
|
// a notification from the I/O thread to a notification handler on the
|
|
// main thread. Call the methods |Create| and |Dispatch| to create or
|
|
// create-and-dispatch a notification runnable.
|
|
//
|
|
// Like with result runnables, you need to specify the called method.
|
|
// And like with result runnables, the |Create| and |Dispatch| methods
|
|
// of |BluetoothNotificationRunnable[1..5]| receive an extra argument
|
|
// for initializing the notification's arguments. During creation, the
|
|
// notification runnable calls the class's call operator with the
|
|
// notification's argument. This is where initialization and conversion
|
|
// from backend-specific types is performed.
|
|
//
|
|
|
|
template <typename ObjectWrapper, typename Res>
|
|
class BluetoothNotificationRunnable0 : public nsRunnable
|
|
{
|
|
public:
|
|
typedef typename ObjectWrapper::ObjectType ObjectType;
|
|
typedef BluetoothNotificationRunnable0<ObjectWrapper, Res> SelfType;
|
|
|
|
template<typename InitOp>
|
|
static already_AddRefed<SelfType>
|
|
Create(Res (ObjectType::*aMethod)(), const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable(new SelfType(aMethod));
|
|
if (NS_FAILED(runnable->Init(aInitOp))) {
|
|
return nullptr;
|
|
}
|
|
return runnable.forget();
|
|
}
|
|
|
|
template<typename InitOp>
|
|
static void
|
|
Dispatch(Res (ObjectType::*aMethod)(), const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable = Create(aMethod, aInitOp);
|
|
if (!runnable) {
|
|
BT_WARNING("BluetoothNotificationRunnable0::Create failed");
|
|
return;
|
|
}
|
|
nsresult rv = NS_DispatchToMainThread(runnable);
|
|
if (NS_FAILED(rv)) {
|
|
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
|
}
|
|
}
|
|
|
|
NS_METHOD
|
|
Run() override
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ObjectType* obj = ObjectWrapper::GetInstance();
|
|
if (!obj) {
|
|
BT_WARNING("Notification handler not initialized");
|
|
} else {
|
|
((*obj).*mMethod)();
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
BluetoothNotificationRunnable0(Res (ObjectType::*aMethod)())
|
|
: mMethod(aMethod)
|
|
{
|
|
MOZ_ASSERT(mMethod);
|
|
}
|
|
|
|
template<typename InitOp>
|
|
nsresult
|
|
Init(const InitOp& aInitOp)
|
|
{
|
|
return aInitOp();
|
|
}
|
|
|
|
Res (ObjectType::*mMethod)();
|
|
};
|
|
|
|
template <typename ObjectWrapper, typename Res,
|
|
typename Tin1, typename Arg1=Tin1>
|
|
class BluetoothNotificationRunnable1 : public nsRunnable
|
|
{
|
|
public:
|
|
typedef typename ObjectWrapper::ObjectType ObjectType;
|
|
typedef BluetoothNotificationRunnable1<ObjectWrapper, Res,
|
|
Tin1, Arg1> SelfType;
|
|
|
|
template <typename InitOp>
|
|
static already_AddRefed<SelfType>
|
|
Create(Res (ObjectType::*aMethod)(Arg1), const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable(new SelfType(aMethod));
|
|
if (NS_FAILED(runnable->Init(aInitOp))) {
|
|
return nullptr;
|
|
}
|
|
return runnable.forget();
|
|
}
|
|
|
|
template <typename InitOp>
|
|
static void
|
|
Dispatch(Res (ObjectType::*aMethod)(Arg1), const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable = Create(aMethod, aInitOp);
|
|
|
|
if (!runnable) {
|
|
BT_WARNING("BluetoothNotificationRunnable1::Create failed");
|
|
return;
|
|
}
|
|
nsresult rv = NS_DispatchToMainThread(runnable);
|
|
if (NS_FAILED(rv)) {
|
|
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
|
}
|
|
}
|
|
|
|
NS_METHOD
|
|
Run() override
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ObjectType* obj = ObjectWrapper::GetInstance();
|
|
if (!obj) {
|
|
BT_WARNING("Notification handler not initialized");
|
|
} else {
|
|
((*obj).*mMethod)(mArg1);
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
BluetoothNotificationRunnable1(Res (ObjectType::*aMethod)(Arg1))
|
|
: mMethod(aMethod)
|
|
{
|
|
MOZ_ASSERT(mMethod);
|
|
}
|
|
|
|
template<typename InitOp>
|
|
nsresult
|
|
Init(const InitOp& aInitOp)
|
|
{
|
|
nsresult rv = aInitOp(mArg1);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
Res (ObjectType::*mMethod)(Arg1);
|
|
Tin1 mArg1;
|
|
};
|
|
|
|
template <typename ObjectWrapper, typename Res,
|
|
typename Tin1, typename Tin2,
|
|
typename Arg1=Tin1, typename Arg2=Tin2>
|
|
class BluetoothNotificationRunnable2 : public nsRunnable
|
|
{
|
|
public:
|
|
typedef typename ObjectWrapper::ObjectType ObjectType;
|
|
typedef BluetoothNotificationRunnable2<ObjectWrapper, Res,
|
|
Tin1, Tin2,
|
|
Arg1, Arg2> SelfType;
|
|
|
|
template <typename InitOp>
|
|
static already_AddRefed<SelfType>
|
|
Create(Res (ObjectType::*aMethod)(Arg1, Arg2), const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable(new SelfType(aMethod));
|
|
if (NS_FAILED(runnable->Init(aInitOp))) {
|
|
return nullptr;
|
|
}
|
|
return runnable.forget();
|
|
}
|
|
|
|
template <typename InitOp>
|
|
static void
|
|
Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2), const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable = Create(aMethod, aInitOp);
|
|
if (!runnable) {
|
|
BT_WARNING("BluetoothNotificationRunnable2::Create failed");
|
|
return;
|
|
}
|
|
nsresult rv = NS_DispatchToMainThread(runnable);
|
|
if (NS_FAILED(rv)) {
|
|
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
|
}
|
|
}
|
|
|
|
NS_METHOD
|
|
Run() override
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ObjectType* obj = ObjectWrapper::GetInstance();
|
|
if (!obj) {
|
|
BT_WARNING("Notification handler not initialized");
|
|
} else {
|
|
((*obj).*mMethod)(mArg1, mArg2);
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
BluetoothNotificationRunnable2(
|
|
Res (ObjectType::*aMethod)(Arg1, Arg2))
|
|
: mMethod(aMethod)
|
|
{
|
|
MOZ_ASSERT(mMethod);
|
|
}
|
|
|
|
template<typename InitOp>
|
|
nsresult
|
|
Init(const InitOp& aInitOp)
|
|
{
|
|
nsresult rv = aInitOp(mArg1, mArg2);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
Res (ObjectType::*mMethod)(Arg1, Arg2);
|
|
Tin1 mArg1;
|
|
Tin2 mArg2;
|
|
};
|
|
|
|
template <typename ObjectWrapper, typename Res,
|
|
typename Tin1, typename Tin2, typename Tin3,
|
|
typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3>
|
|
class BluetoothNotificationRunnable3 : public nsRunnable
|
|
{
|
|
public:
|
|
typedef typename ObjectWrapper::ObjectType ObjectType;
|
|
typedef BluetoothNotificationRunnable3<ObjectWrapper, Res,
|
|
Tin1, Tin2, Tin3,
|
|
Arg1, Arg2, Arg3> SelfType;
|
|
|
|
template <typename InitOp>
|
|
static already_AddRefed<SelfType>
|
|
Create(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3), const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable(new SelfType(aMethod));
|
|
if (NS_FAILED(runnable->Init(aInitOp))) {
|
|
return nullptr;
|
|
}
|
|
return runnable.forget();
|
|
}
|
|
|
|
template <typename InitOp>
|
|
static void
|
|
Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3),
|
|
const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable = Create(aMethod, aInitOp);
|
|
if (!runnable) {
|
|
BT_WARNING("BluetoothNotificationRunnable3::Create failed");
|
|
return;
|
|
}
|
|
nsresult rv = NS_DispatchToMainThread(runnable);
|
|
if (NS_FAILED(rv)) {
|
|
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
|
}
|
|
}
|
|
|
|
NS_METHOD
|
|
Run() override
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ObjectType* obj = ObjectWrapper::GetInstance();
|
|
if (!obj) {
|
|
BT_WARNING("Notification handler not initialized");
|
|
} else {
|
|
((*obj).*mMethod)(mArg1, mArg2, mArg3);
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
BluetoothNotificationRunnable3(
|
|
Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3))
|
|
: mMethod(aMethod)
|
|
{
|
|
MOZ_ASSERT(mMethod);
|
|
}
|
|
|
|
template<typename InitOp>
|
|
nsresult
|
|
Init(const InitOp& aInitOp)
|
|
{
|
|
nsresult rv = aInitOp(mArg1, mArg2, mArg3);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
Res (ObjectType::*mMethod)(Arg1, Arg2, Arg3);
|
|
Tin1 mArg1;
|
|
Tin2 mArg2;
|
|
Tin3 mArg3;
|
|
};
|
|
|
|
template <typename ObjectWrapper, typename Res,
|
|
typename Tin1, typename Tin2, typename Tin3, typename Tin4,
|
|
typename Arg1=Tin1, typename Arg2=Tin2,
|
|
typename Arg3=Tin3, typename Arg4=Tin4>
|
|
class BluetoothNotificationRunnable4 : public nsRunnable
|
|
{
|
|
public:
|
|
typedef typename ObjectWrapper::ObjectType ObjectType;
|
|
typedef BluetoothNotificationRunnable4<ObjectWrapper, Res,
|
|
Tin1, Tin2, Tin3, Tin4, Arg1, Arg2, Arg3, Arg4> SelfType;
|
|
|
|
template <typename InitOp>
|
|
static already_AddRefed<SelfType> Create(
|
|
Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4),
|
|
const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable(new SelfType(aMethod));
|
|
if (NS_FAILED(runnable->Init(aInitOp))) {
|
|
return nullptr;
|
|
}
|
|
return runnable.forget();
|
|
}
|
|
|
|
template <typename InitOp>
|
|
static void
|
|
Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4),
|
|
const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable = Create(aMethod, aInitOp);
|
|
if (!runnable) {
|
|
BT_WARNING("BluetoothNotificationRunnable4::Create failed");
|
|
return;
|
|
}
|
|
nsresult rv = NS_DispatchToMainThread(runnable);
|
|
if (NS_FAILED(rv)) {
|
|
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
|
}
|
|
}
|
|
|
|
NS_METHOD
|
|
Run() override
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ObjectType* obj = ObjectWrapper::GetInstance();
|
|
if (!obj) {
|
|
BT_WARNING("Notification handler not initialized");
|
|
} else {
|
|
((*obj).*mMethod)(mArg1, mArg2, mArg3, mArg4);
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
BluetoothNotificationRunnable4(
|
|
Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4))
|
|
: mMethod(aMethod)
|
|
{
|
|
MOZ_ASSERT(mMethod);
|
|
}
|
|
|
|
template<typename InitOp>
|
|
nsresult
|
|
Init(const InitOp& aInitOp)
|
|
{
|
|
nsresult rv = aInitOp(mArg1, mArg2, mArg3, mArg4);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
Res (ObjectType::*mMethod)(Arg1, Arg2, Arg3, Arg4);
|
|
Tin1 mArg1;
|
|
Tin2 mArg2;
|
|
Tin3 mArg3;
|
|
Tin4 mArg4;
|
|
};
|
|
|
|
template <typename ObjectWrapper, typename Res,
|
|
typename Tin1, typename Tin2, typename Tin3,
|
|
typename Tin4, typename Tin5,
|
|
typename Arg1=Tin1, typename Arg2=Tin2, typename Arg3=Tin3,
|
|
typename Arg4=Tin4, typename Arg5=Tin5>
|
|
class BluetoothNotificationRunnable5 : public nsRunnable
|
|
{
|
|
public:
|
|
typedef typename ObjectWrapper::ObjectType ObjectType;
|
|
typedef BluetoothNotificationRunnable5<ObjectWrapper, Res,
|
|
Tin1, Tin2, Tin3, Tin4, Tin5, Arg1, Arg2, Arg3, Arg4, Arg5> SelfType;
|
|
|
|
template <typename InitOp>
|
|
static already_AddRefed<SelfType> Create(
|
|
Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5),
|
|
const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable(new SelfType(aMethod));
|
|
if (NS_FAILED(runnable->Init(aInitOp))) {
|
|
return nullptr;
|
|
}
|
|
return runnable.forget();
|
|
}
|
|
|
|
template <typename InitOp>
|
|
static void
|
|
Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5),
|
|
const InitOp& aInitOp)
|
|
{
|
|
nsRefPtr<SelfType> runnable = Create(aMethod, aInitOp);
|
|
if (!runnable) {
|
|
BT_WARNING("BluetoothNotificationRunnable5::Create failed");
|
|
return;
|
|
}
|
|
nsresult rv = NS_DispatchToMainThread(runnable);
|
|
if (NS_FAILED(rv)) {
|
|
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
|
|
}
|
|
}
|
|
|
|
NS_METHOD
|
|
Run() override
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ObjectType* obj = ObjectWrapper::GetInstance();
|
|
if (!obj) {
|
|
BT_WARNING("Notification handler not initialized");
|
|
} else {
|
|
((*obj).*mMethod)(mArg1, mArg2, mArg3, mArg4, mArg5);
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
BluetoothNotificationRunnable5(
|
|
Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5))
|
|
: mMethod(aMethod)
|
|
{
|
|
MOZ_ASSERT(mMethod);
|
|
}
|
|
|
|
template<typename InitOp>
|
|
nsresult
|
|
Init(const InitOp& aInitOp)
|
|
{
|
|
nsresult rv = aInitOp(mArg1, mArg2, mArg3, mArg4, mArg5);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
Res (ObjectType::*mMethod)(Arg1, Arg2, Arg3, Arg4, Arg5);
|
|
Tin1 mArg1;
|
|
Tin2 mArg2;
|
|
Tin3 mArg3;
|
|
Tin4 mArg4;
|
|
Tin5 mArg5;
|
|
};
|
|
|
|
//
|
|
// Init operators
|
|
//
|
|
// Below are general-purpose init operators for Bluetooth. The classes
|
|
// of type |ConstantInitOp[1..3]| initialize results or notifications
|
|
// with constant values.
|
|
//
|
|
|
|
template <typename T1>
|
|
class ConstantInitOp1 final
|
|
{
|
|
public:
|
|
ConstantInitOp1(const T1& aArg1)
|
|
: mArg1(aArg1)
|
|
{ }
|
|
|
|
nsresult operator () (T1& aArg1) const
|
|
{
|
|
aArg1 = mArg1;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
const T1& mArg1;
|
|
};
|
|
|
|
template <typename T1, typename T2>
|
|
class ConstantInitOp2 final
|
|
{
|
|
public:
|
|
ConstantInitOp2(const T1& aArg1, const T2& aArg2)
|
|
: mArg1(aArg1)
|
|
, mArg2(aArg2)
|
|
{ }
|
|
|
|
nsresult operator () (T1& aArg1, T2& aArg2) const
|
|
{
|
|
aArg1 = mArg1;
|
|
aArg2 = mArg2;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
const T1& mArg1;
|
|
const T2& mArg2;
|
|
};
|
|
|
|
template <typename T1, typename T2, typename T3>
|
|
class ConstantInitOp3 final
|
|
{
|
|
public:
|
|
ConstantInitOp3(const T1& aArg1, const T2& aArg2, const T3& aArg3)
|
|
: mArg1(aArg1)
|
|
, mArg2(aArg2)
|
|
, mArg3(aArg3)
|
|
{ }
|
|
|
|
nsresult operator () (T1& aArg1, T2& aArg2, T3& aArg3) const
|
|
{
|
|
aArg1 = mArg1;
|
|
aArg2 = mArg2;
|
|
aArg3 = mArg3;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
const T1& mArg1;
|
|
const T2& mArg2;
|
|
const T3& mArg3;
|
|
};
|
|
|
|
END_BLUETOOTH_NAMESPACE
|
|
|
|
#endif
|