Bug 1036977: Add result handler for Bluetooth Socket interface (under bluetooth2/), r=btian

This commit is contained in:
Thomas Zimmermann 2014-07-16 10:23:35 +02:00
parent 45a8eef1a9
commit 970da4830d
2 changed files with 46 additions and 0 deletions

View File

@ -84,6 +84,36 @@ struct interface_traits<BluetoothSocketInterface>
}
};
typedef
BluetoothInterfaceRunnable1<BluetoothSocketResultHandler, void, int>
BluetoothSocketIntResultRunnable;
typedef
BluetoothInterfaceRunnable1<BluetoothSocketResultHandler, void, bt_status_t>
BluetoothSocketErrorRunnable;
static nsresult
DispatchBluetoothSocketResult(BluetoothSocketResultHandler* aRes,
void (BluetoothSocketResultHandler::*aMethod)(int),
int aArg, bt_status_t aStatus)
{
MOZ_ASSERT(aRes);
nsRunnable* runnable;
if (aStatus == BT_STATUS_SUCCESS) {
runnable = new BluetoothSocketIntResultRunnable(aRes, aMethod, aArg);
} else {
runnable = new BluetoothSocketErrorRunnable(aRes,
&BluetoothSocketResultHandler::OnError, aStatus);
}
nsresult rv = NS_DispatchToMainThread(runnable);
if (NS_FAILED(rv)) {
BT_WARNING("NS_DispatchToMainThread failed: %X", rv);
}
return rv;
}
bt_status_t
BluetoothSocketInterface::Listen(btsock_type_t aType,
const char* aServiceName,

View File

@ -24,6 +24,22 @@ class BluetoothInterface;
// Socket Interface
//
class BluetoothSocketResultHandler
{
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BluetoothSocketResultHandler)
virtual ~BluetoothSocketResultHandler() { }
virtual void OnError(bt_status_t aStatus)
{
BT_WARNING("Received error code %d", (int)aStatus);
}
virtual void Listen(int aSockFd) { }
virtual void Connect(int aSockFd) { }
};
class BluetoothSocketInterface
{
public: