mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1029386: Add result handler for Bluetooth Core profile, r=shuang
The result-handler class contains a method for each interface in the Core profile and a method for failed calls. The patch also adds runnable classes that execute a result handler's method on the main thread.
This commit is contained in:
parent
81cc059b6d
commit
e2ec3ca124
@ -5,6 +5,8 @@
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "BluetoothInterface.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
@ -12,6 +14,61 @@ template<class T>
|
||||
struct interface_traits
|
||||
{ };
|
||||
|
||||
//
|
||||
// Result handling
|
||||
//
|
||||
|
||||
template <typename Obj, typename Res>
|
||||
class BluetoothInterfaceRunnable0 : public nsRunnable
|
||||
{
|
||||
public:
|
||||
BluetoothInterfaceRunnable0(Obj* aObj, Res (Obj::*aMethod)())
|
||||
: mObj(aObj)
|
||||
, mMethod(aMethod)
|
||||
{
|
||||
MOZ_ASSERT(mObj);
|
||||
MOZ_ASSERT(mMethod);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
Run() MOZ_OVERRIDE
|
||||
{
|
||||
((*mObj).*mMethod)();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
nsRefPtr<Obj> mObj;
|
||||
void (Obj::*mMethod)();
|
||||
};
|
||||
|
||||
template <typename Obj, typename Res, typename Arg1>
|
||||
class BluetoothInterfaceRunnable1 : public nsRunnable
|
||||
{
|
||||
public:
|
||||
BluetoothInterfaceRunnable1(Obj* aObj, Res (Obj::*aMethod)(Arg1),
|
||||
const Arg1& aArg1)
|
||||
: mObj(aObj)
|
||||
, mMethod(aMethod)
|
||||
, mArg1(aArg1)
|
||||
{
|
||||
MOZ_ASSERT(mObj);
|
||||
MOZ_ASSERT(mMethod);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
Run() MOZ_OVERRIDE
|
||||
{
|
||||
((*mObj).*mMethod)(mArg1);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
nsRefPtr<Obj> mObj;
|
||||
void (Obj::*mMethod)(Arg1);
|
||||
Arg1 mArg1;
|
||||
};
|
||||
|
||||
//
|
||||
// Socket Interface
|
||||
//
|
||||
@ -371,6 +428,32 @@ BluetoothAvrcpInterface::SetVolume(uint8_t aVolume)
|
||||
// Bluetooth Core Interface
|
||||
//
|
||||
|
||||
typedef
|
||||
BluetoothInterfaceRunnable0<BluetoothResultHandler, void>
|
||||
BluetoothResultRunnable;
|
||||
|
||||
typedef
|
||||
BluetoothInterfaceRunnable1<BluetoothResultHandler, void, int>
|
||||
BluetoothErrorRunnable;
|
||||
|
||||
static nsresult
|
||||
DispatchBluetoothResult(BluetoothResultHandler* aRes,
|
||||
void (BluetoothResultHandler::*aMethod)(),
|
||||
int aStatus)
|
||||
{
|
||||
MOZ_ASSERT(aRes);
|
||||
|
||||
nsRunnable* runnable;
|
||||
|
||||
if (aStatus == BT_STATUS_SUCCESS) {
|
||||
runnable = new BluetoothResultRunnable(aRes, aMethod);
|
||||
} else {
|
||||
runnable = new
|
||||
BluetoothErrorRunnable(aRes, &BluetoothResultHandler::OnError, aStatus);
|
||||
}
|
||||
NS_DispatchToMainThread(runnable);
|
||||
}
|
||||
|
||||
/* returns the container structure of a variable; _t is the container's
|
||||
* type, _v the name of the variable, and _m is _v's field within _t
|
||||
*/
|
||||
|
@ -181,6 +181,50 @@ private:
|
||||
// Bluetooth Core Interface
|
||||
//
|
||||
|
||||
class BluetoothResultHandler
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BluetoothResultHandler)
|
||||
|
||||
virtual ~BluetoothResultHandler() { }
|
||||
|
||||
virtual void OnError(int aStatus)
|
||||
{
|
||||
BT_LOGR("received error code %d", aStatus);
|
||||
}
|
||||
|
||||
virtual void Init() { }
|
||||
virtual void Cleanup() { }
|
||||
virtual void Enable() { }
|
||||
virtual void Disable() { }
|
||||
|
||||
virtual void GetAdapterProperties() { }
|
||||
virtual void GetAdapterProperty() { }
|
||||
virtual void SetAdapterProperty() { }
|
||||
|
||||
virtual void GetRemoteDeviceProperties() { }
|
||||
virtual void GetRemoteDeviceProperty() { }
|
||||
virtual void SetRemoteDeviceProperty() { }
|
||||
|
||||
virtual void GetRemoteServiceRecord() { }
|
||||
virtual void GetRemoteServices() { }
|
||||
|
||||
virtual void StartDiscovery() { }
|
||||
virtual void CancelDiscovery() { }
|
||||
|
||||
virtual void CreateBond() { }
|
||||
virtual void RemoveBond() { }
|
||||
virtual void CancelBond() { }
|
||||
|
||||
virtual void PinReply() { }
|
||||
virtual void SspReply() { }
|
||||
|
||||
virtual void DutModeConfigure() { }
|
||||
virtual void DutModeSend() { }
|
||||
|
||||
virtual void LeTestMode() { }
|
||||
};
|
||||
|
||||
class BluetoothInterface
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user