diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h b/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h index 26f2de6ab9c3..e3e896019b4d 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h +++ b/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h @@ -565,303 +565,6 @@ UnpackPDU(BluetoothDaemonPDU& aPDU, nsTArray& aOut) return NS_OK; } -template -inline nsresult -UnpackPDU(BluetoothDaemonPDU& aPDU, T1& aArg1) -{ - return UnpackPDU(aPDU, aArg1); -} - -template<> -inline nsresult -UnpackPDU( - BluetoothDaemonPDU& aPDU, int& aArg1) -{ - aArg1 = aPDU.AcquireFd(); - - if (NS_WARN_IF(aArg1 < 0)) { - return NS_ERROR_ILLEGAL_VALUE; - } - - return NS_OK; -} - - -template -inline nsresult -UnpackPDU(BluetoothDaemonPDU& aPDU, T1& aArg1, T2& aArg2) -{ - nsresult rv = UnpackPDU(aPDU, aArg1); - if (NS_FAILED(rv)) { - return rv; - } - return UnpackPDU(aPDU, aArg2); -} - -template<> -inline nsresult -UnpackPDU, 0x01, 0x84>( - BluetoothDaemonPDU& aPDU, - int& aArg1, nsAutoArrayPtr& aArg2) -{ - /* Read number of properties */ - uint8_t numProperties; - nsresult rv = UnpackPDU(aPDU, numProperties); - if (NS_FAILED(rv)) { - return rv; - } - aArg1 = numProperties; - - /* Read properties array */ - UnpackArray properties(aArg2, aArg1); - return UnpackPDU(aPDU, properties); -} - -template -inline nsresult -UnpackPDU(BluetoothDaemonPDU& aPDU, T1& aArg1, T2& aArg2, T3& aArg3) -{ - nsresult rv = UnpackPDU(aPDU, aArg1); - if (NS_FAILED(rv)) { - return rv; - } - rv = UnpackPDU(aPDU, aArg2); - if (NS_FAILED(rv)) { - return rv; - } - return UnpackPDU(aPDU, aArg3); -} - -template<> -inline nsresult -UnpackPDU, 0x01, 0x82>( - BluetoothDaemonPDU& aPDU, - BluetoothStatus& aArg1, int& aArg2, nsAutoArrayPtr& aArg3) -{ - /* Read status */ - nsresult rv = UnpackPDU(aPDU, aArg1); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read number of properties */ - uint8_t numProperties; - rv = UnpackPDU(aPDU, numProperties); - if (NS_FAILED(rv)) { - return rv; - } - aArg2 = numProperties; - - /* Read properties array */ - UnpackArray properties(aArg3, aArg2); - return UnpackPDU(aPDU, properties); -} - -template<> -inline nsresult -UnpackPDU( - BluetoothDaemonPDU& aPDU, - nsString& aArg1, nsString& aArg2, uint32_t& aArg3) -{ - /* Read remote address */ - nsresult rv = UnpackPDU( - aPDU, UnpackConversion(aArg1)); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read remote name */ - rv = UnpackPDU(aPDU, UnpackConversion(aArg2)); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read CoD */ - return UnpackPDU(aPDU, aArg3); -} - -template<> -inline nsresult -UnpackPDU( - BluetoothDaemonPDU& aPDU, - BluetoothStatus& aArg1, nsString& aArg2, BluetoothBondState& aArg3) -{ - /* Read status */ - nsresult rv = UnpackPDU(aPDU, aArg1); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read remote address */ - rv = UnpackPDU(aPDU, UnpackConversion(aArg2)); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read bond state */ - return UnpackPDU(aPDU, aArg3); -} - -template<> -inline nsresult -UnpackPDU( - BluetoothDaemonPDU& aPDU, - BluetoothStatus& aArg1, nsString& aArg2, bool& aArg3) -{ - /* Read status */ - nsresult rv = UnpackPDU(aPDU, aArg1); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read remote address */ - rv = UnpackPDU(aPDU, UnpackConversion(aArg2)); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read ACL state */ - return UnpackPDU(aPDU, UnpackConversion(aArg3)); -} - -template<> -inline nsresult -UnpackPDU, uint8_t, 0x01, 0x8a>( - BluetoothDaemonPDU& aPDU, - uint16_t& aArg1, nsAutoArrayPtr& aArg2, uint8_t& aArg3) -{ - /* Read opcode */ - nsresult rv = UnpackPDU(aPDU, aArg1); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read length */ - rv = UnpackPDU(aPDU, aArg3); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read data */ - return UnpackPDU(aPDU, UnpackArray(aArg2, aArg3)); -} - -template -inline nsresult -UnpackPDU(BluetoothDaemonPDU& aPDU, T1& aArg1, T2& aArg2, T3& aArg3, T4& aArg4) -{ - nsresult rv = UnpackPDU(aPDU, aArg1); - if (NS_FAILED(rv)) { - return rv; - } - rv = UnpackPDU(aPDU, aArg2); - if (NS_FAILED(rv)) { - return rv; - } - rv = UnpackPDU(aPDU, aArg3); - if (NS_FAILED(rv)) { - return rv; - } - return UnpackPDU(aPDU, aArg4); -} - -template<> -inline nsresult -UnpackPDU, - 0x01, 0x83>( - BluetoothDaemonPDU& aPDU, - BluetoothStatus& aArg1, nsString& aArg2, int& aArg3, - nsAutoArrayPtr& aArg4) -{ - /* Read status */ - nsresult rv = UnpackPDU(aPDU, aArg1); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read address */ - rv = UnpackPDU(aPDU, UnpackConversion(aArg2)); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read number of properties */ - uint8_t numProperties; - rv = UnpackPDU(aPDU, numProperties); - if (NS_FAILED(rv)) { - return rv; - } - aArg3 = numProperties; - - /* Read properties array */ - UnpackArray properties(aArg4, aArg3); - return UnpackPDU(aPDU, properties); -} - -template -inline nsresult -UnpackPDU(BluetoothDaemonPDU& aPDU, - T1& aArg1, T2& aArg2, T3& aArg3, T4& aArg4, T5& aArg5) -{ - nsresult rv = UnpackPDU(aPDU, aArg1); - if (NS_FAILED(rv)) { - return rv; - } - rv = UnpackPDU(aPDU, aArg2); - if (NS_FAILED(rv)) { - return rv; - } - rv = UnpackPDU(aPDU, aArg3); - if (NS_FAILED(rv)) { - return rv; - } - rv = UnpackPDU(aPDU, aArg4); - if (NS_FAILED(rv)) { - return rv; - } - return UnpackPDU(aPDU, aArg5); -} - -template<> -inline nsresult -UnpackPDU( - BluetoothDaemonPDU& aPDU, - nsString& aArg1, nsString& aArg2, uint32_t& aArg3, - nsString& aArg4, uint32_t& aArg5) -{ - /* Read remote address */ - nsresult rv = UnpackPDU( - aPDU, UnpackConversion(aArg1)); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read remote name */ - rv = UnpackPDU(aPDU, UnpackConversion(aArg2)); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read CoD */ - rv = UnpackPDU(aPDU, aArg3); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read pairing variant */ - rv = UnpackPDU( - aPDU, UnpackConversion(aArg4)); - if (NS_FAILED(rv)) { - return rv; - } - - /* Read passkey */ - return UnpackPDU(aPDU, aArg5); -} - // // Init operators // @@ -1021,704 +724,6 @@ public: } }; -// -// Result handling -// - -template -class BluetoothDaemonInterfaceRunnable0 : public nsRunnable -{ -public: - typedef BluetoothDaemonInterfaceRunnable0 SelfType; - - static already_AddRefed Create( - Obj* aObj, Res (Obj::*aMethod)()) - { - nsRefPtr runnable(new SelfType(aObj, aMethod)); - - return runnable.forget(); - } - - static void - Dispatch(Obj* aObj, Res (Obj::*aMethod)()) - { - nsRefPtr runnable = Create(aObj, aMethod); - if (!runnable) { - BT_WARNING("BluetoothDaemonInterfaceRunnable0::Create failed"); - return; - } - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) { - BT_WARNING("NS_DispatchToMainThread failed: %X", rv); - } - } - - NS_METHOD - Run() MOZ_OVERRIDE - { - ((*mObj).*mMethod)(); - return NS_OK; - } - -private: - BluetoothDaemonInterfaceRunnable0(Obj* aObj, Res (Obj::*aMethod)()) - : mObj(aObj) - , mMethod(aMethod) - { - MOZ_ASSERT(mObj); - MOZ_ASSERT(mMethod); - } - - nsRefPtr mObj; - void (Obj::*mMethod)(); -}; - -template -class BluetoothDaemonInterfaceRunnable1 : public nsRunnable -{ -public: - typedef BluetoothDaemonInterfaceRunnable1 SelfType; - - template - static already_AddRefed Create( - Obj* aObj, Res (Obj::*aMethod)(Arg1), BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable(new SelfType(aObj, aMethod)); - - if (NS_FAILED((runnable->UnpackAndSet(aPDU)))) { - return nullptr; - } - return runnable.forget(); - } - - static already_AddRefed Create( - Obj* aObj, Res (Obj::*aMethod)(Arg1), const Arg1& aArg1) - { - nsRefPtr runnable(new SelfType(aObj, aMethod, aArg1)); - return runnable.forget(); - } - - template - static void - Dispatch(Obj* aObj, Res (Obj::*aMethod)(Arg1), - BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable = Create(aObj, aMethod, aPDU); - if (!runnable) { - BT_WARNING("BluetoothDaemonInterfaceRunnable1::Create failed"); - return; - } - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) { - BT_WARNING("NS_DispatchToMainThread failed: %X", rv); - } - } - - static void - Dispatch(Obj* aObj, Res (Obj::*aMethod)(Arg1), const Tin1& aArg1) - { - nsRefPtr runnable = Create(aObj, aMethod, aArg1); - if (!runnable) { - BT_WARNING("BluetoothDaemonInterfaceRunnable1::Create failed"); - return; - } - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) { - BT_WARNING("NS_DispatchToMainThread failed: %X", rv); - } - } - - NS_METHOD - Run() MOZ_OVERRIDE - { - ((*mObj).*mMethod)(mArg1); - return NS_OK; - } - -private: - BluetoothDaemonInterfaceRunnable1(Obj* aObj, Res (Obj::*aMethod)(Arg1)) - : mObj(aObj) - , mMethod(aMethod) - { - MOZ_ASSERT(mObj); - MOZ_ASSERT(mMethod); - } - - BluetoothDaemonInterfaceRunnable1(Obj* aObj, Res (Obj::*aMethod)(Arg1), - const Tin1& aArg1) - : mObj(aObj) - , mMethod(aMethod) - , mArg1(aArg1) - { - MOZ_ASSERT(mObj); - MOZ_ASSERT(mMethod); - } - - template - nsresult - UnpackAndSet(BluetoothDaemonPDU& aPDU) - { - return UnpackPDU(aPDU, mArg1); - } - - nsRefPtr mObj; - Res (Obj::*mMethod)(Arg1); - Tin1 mArg1; -}; - -template -class BluetoothDaemonInterfaceRunnable3 : public nsRunnable -{ -public: - typedef BluetoothDaemonInterfaceRunnable3 SelfType; - - template - static already_AddRefed Create( - Obj* aObj, Res (Obj::*aMethod)(Arg1, Arg2, Arg3), BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable(new SelfType(aObj, aMethod)); - - if (NS_FAILED((runnable->UnpackAndSet(aPDU)))) { - return nullptr; - } - return runnable.forget(); - } - - static already_AddRefed Create( - Obj* aObj, Res (Obj::*aMethod)(Arg1, Arg2, Arg3), - const Tin1& aArg1, const Tin2& aArg2, const Tin3& aArg3) - { - nsRefPtr runnable(new SelfType(aObj, aMethod, - aArg1, aArg2, aArg3)); - return runnable.forget(); - } - - template - static void - Dispatch(Obj* aObj, Res (Obj::*aMethod)(Arg1, Arg2, Arg3), - BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable = Create(aObj, aMethod, aPDU); - if (!runnable) { - BT_WARNING("BluetoothDaemonInterfaceRunnable3::Create failed"); - return; - } - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) { - BT_WARNING("NS_DispatchToMainThread failed: %X", rv); - } - } - - static void - Dispatch(Obj* aObj, Res (Obj::*aMethod)(Arg1, Arg2, Arg3), - const Tin1& aArg1, const Tin2& aArg2, const Tin3& aArg3) - { - nsRefPtr runnable = Create(aObj, aMethod, aArg1, aArg2, aArg3); - if (!runnable) { - BT_WARNING("BluetoothDaemonInterfaceRunnable3::Create failed"); - return; - } - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) { - BT_WARNING("NS_DispatchToMainThread failed: %X", rv); - } - } - - NS_METHOD - Run() MOZ_OVERRIDE - { - ((*mObj).*mMethod)(mArg1, mArg2, mArg3); - return NS_OK; - } - -private: - BluetoothDaemonInterfaceRunnable3(Obj* aObj, - Res (Obj::*aMethod)(Arg1, Arg2, Arg3)) - : mObj(aObj) - , mMethod(aMethod) - { - MOZ_ASSERT(mObj); - MOZ_ASSERT(mMethod); - } - - BluetoothDaemonInterfaceRunnable3(Obj* aObj, - Res (Obj::*aMethod)(Arg1, Arg2, Arg3), - const Tin1& aArg1, const Tin2& aArg2, - const Tin3& aArg3) - : mObj(aObj) - , mMethod(aMethod) - , mArg1(aArg1) - , mArg2(aArg2) - , mArg3(aArg3) - { - MOZ_ASSERT(mObj); - MOZ_ASSERT(mMethod); - } - - template - nsresult - UnpackAndSet(BluetoothDaemonPDU& aPDU) - { - return UnpackPDU(aPDU, - mArg1, mArg2, - mArg3); - } - - nsRefPtr mObj; - Res (Obj::*mMethod)(Arg1, Arg2, Arg3); - Tin1 mArg1; - Tin2 mArg2; - Tin3 mArg3; -}; - -// -// Notification handling -// - -template -class BluetoothDaemonNotificationRunnable0 : public nsRunnable -{ -public: - typedef typename ObjectWrapper::ObjectType ObjectType; - typedef BluetoothDaemonNotificationRunnable0 SelfType; - - static already_AddRefed Create(Res (ObjectType::*aMethod)()) - { - nsRefPtr runnable(new SelfType(aMethod)); - - return runnable.forget(); - } - - static void - Dispatch(Res (ObjectType::*aMethod)()) - { - nsRefPtr runnable = Create(aMethod); - - if (!runnable) { - BT_WARNING("BluetoothDaemonNotificationRunnable0::Create failed"); - return; - } - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) { - BT_WARNING("NS_DispatchToMainThread failed: %X", rv); - } - } - - NS_METHOD - Run() MOZ_OVERRIDE - { - MOZ_ASSERT(NS_IsMainThread()); - - ObjectType* obj = ObjectWrapper::GetInstance(); - - if (!obj) { - BT_WARNING("Notification handler not initialized"); - } else { - ((*obj).*mMethod)(); - } - return NS_OK; - } - -private: - BluetoothDaemonNotificationRunnable0(Res (ObjectType::*aMethod)()) - : mMethod(aMethod) - { - MOZ_ASSERT(mMethod); - } - - Res (ObjectType::*mMethod)(); -}; - -template -class BluetoothDaemonNotificationRunnable1 : public nsRunnable -{ -public: - typedef typename ObjectWrapper::ObjectType ObjectType; - typedef BluetoothDaemonNotificationRunnable1 SelfType; - - template - static already_AddRefed Create( - Res (ObjectType::*aMethod)(Arg1), BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable(new SelfType(aMethod)); - - if (NS_FAILED((runnable->UnpackAndSet(aPDU)))) { - return nullptr; - } - return runnable.forget(); - } - - template - static void - Dispatch(Res (ObjectType::*aMethod)(Arg1), BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable = Create(aMethod, aPDU); - - if (!runnable) { - BT_WARNING("BluetoothDaemonNotificationRunnable1::Create failed"); - return; - } - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) { - BT_WARNING("NS_DispatchToMainThread failed: %X", rv); - } - } - - NS_METHOD - Run() MOZ_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: - BluetoothDaemonNotificationRunnable1(Res (ObjectType::*aMethod)(Arg1)) - : mMethod(aMethod) - { - MOZ_ASSERT(mMethod); - } - - template - nsresult - UnpackAndSet(BluetoothDaemonPDU& aPDU) - { - return UnpackPDU(aPDU, mArg1); - } - - Res (ObjectType::*mMethod)(Arg1); - Tin1 mArg1; -}; - -template -class BluetoothDaemonNotificationRunnable2 : public nsRunnable -{ -public: - typedef typename ObjectWrapper::ObjectType ObjectType; - typedef BluetoothDaemonNotificationRunnable2 SelfType; - - template - static already_AddRefed Create( - Res (ObjectType::*aMethod)(Arg1, Arg2), BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable(new SelfType(aMethod)); - - if (NS_FAILED((runnable->UnpackAndSet(aPDU)))) { - return nullptr; - } - return runnable.forget(); - } - - template - static void - Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2), - BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable = Create(aMethod, aPDU); - - if (!runnable) { - BT_WARNING("BluetoothDaemonNotificationRunnable2::Create failed"); - return; - } - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) { - BT_WARNING("NS_DispatchToMainThread failed: %X", rv); - } - } - - NS_METHOD - Run() MOZ_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: - BluetoothDaemonNotificationRunnable2( - Res (ObjectType::*aMethod)(Arg1, Arg2)) - : mMethod(aMethod) - { - MOZ_ASSERT(mMethod); - } - - template - nsresult - UnpackAndSet(BluetoothDaemonPDU& aPDU) - { - return UnpackPDU(aPDU, mArg1, mArg2); - } - - Res (ObjectType::*mMethod)(Arg1, Arg2); - Tin1 mArg1; - Tin2 mArg2; -}; - -template -class BluetoothDaemonNotificationRunnable3 : public nsRunnable -{ -public: - typedef typename ObjectWrapper::ObjectType ObjectType; - typedef BluetoothDaemonNotificationRunnable3 SelfType; - - template - static already_AddRefed Create( - Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3), - BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable(new SelfType(aMethod)); - - if (NS_FAILED((runnable->UnpackAndSet(aPDU)))) { - return nullptr; - } - return runnable.forget(); - } - - template - static void - Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3), - BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable = Create(aMethod, aPDU); - if (!runnable) { - BT_WARNING("BluetoothDaemonNotificationRunnable3::Create failed"); - return; - } - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) { - BT_WARNING("NS_DispatchToMainThread failed: %X", rv); - } - } - - NS_METHOD - Run() MOZ_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: - BluetoothDaemonNotificationRunnable3( - Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3)) - : mMethod(aMethod) - { - MOZ_ASSERT(mMethod); - } - - template - nsresult - UnpackAndSet(BluetoothDaemonPDU& aPDU) - { - return UnpackPDU(aPDU, - mArg1, mArg2, - mArg3); - } - - Res (ObjectType::*mMethod)(Arg1, Arg2, Arg3); - Tin1 mArg1; - Tin2 mArg2; - Tin3 mArg3; -}; - -template -class BluetoothDaemonNotificationRunnable4 : public nsRunnable -{ -public: - typedef typename ObjectWrapper::ObjectType ObjectType; - typedef BluetoothDaemonNotificationRunnable4 SelfType; - - template - static already_AddRefed Create( - Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4), - BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable(new SelfType(aMethod)); - - if (NS_FAILED((runnable->UnpackAndSet(aPDU)))) { - return nullptr; - } - return runnable.forget(); - } - - template - static void - Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4), - BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable = Create(aMethod, aPDU); - if (!runnable) { - BT_WARNING("BluetoothDaemonNotificationRunnable4::Create failed"); - return; - } - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) { - BT_WARNING("NS_DispatchToMainThread failed: %X", rv); - } - } - - NS_METHOD - Run() MOZ_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: - BluetoothDaemonNotificationRunnable4( - Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4)) - : mMethod(aMethod) - { - MOZ_ASSERT(mMethod); - } - - template - nsresult - UnpackAndSet(BluetoothDaemonPDU& aPDU) - { - return UnpackPDU(aPDU, - mArg1, mArg2, - mArg3, mArg4); - } - - Res (ObjectType::*mMethod)(Arg1, Arg2, Arg3, Arg4); - Tin1 mArg1; - Tin2 mArg2; - Tin3 mArg3; - Tin4 mArg4; -}; - -template -class BluetoothDaemonNotificationRunnable5 : public nsRunnable -{ -public: - typedef typename ObjectWrapper::ObjectType ObjectType; - typedef BluetoothDaemonNotificationRunnable5 SelfType; - - template - static already_AddRefed Create( - Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5), - BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable(new SelfType(aMethod)); - - if (NS_FAILED((runnable->UnpackAndSet(aPDU)))) { - return nullptr; - } - return runnable.forget(); - } - - template - static void - Dispatch(Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5), - BluetoothDaemonPDU& aPDU) - { - nsRefPtr runnable = Create(aMethod, aPDU); - if (!runnable) { - BT_WARNING("BluetoothDaemonNotificationRunnable5::Create failed"); - return; - } - nsresult rv = NS_DispatchToMainThread(runnable); - if (NS_FAILED(rv)) { - BT_WARNING("NS_DispatchToMainThread failed: %X", rv); - } - } - - NS_METHOD - Run() MOZ_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: - BluetoothDaemonNotificationRunnable5( - Res (ObjectType::*aMethod)(Arg1, Arg2, Arg3, Arg4, Arg5)) - : mMethod(aMethod) - { - MOZ_ASSERT(mMethod); - } - - template - nsresult - UnpackAndSet(BluetoothDaemonPDU& aPDU) - { - return UnpackPDU(aPDU, - mArg1, - mArg2, - mArg3, - mArg4, - mArg5); - } - - Res (ObjectType::*mMethod)(Arg1, Arg2, Arg3, Arg4, Arg5); - Tin1 mArg1; - Tin2 mArg2; - Tin3 mArg3; - Tin4 mArg4; - Tin5 mArg5; -}; - END_BLUETOOTH_NAMESPACE #endif