Bug 780812 - [b2g-bluetooth] Implement function to get RFCOMM channel of specific Bluetooth service; r=qdot

This commit is contained in:
Eric Chou 2012-08-07 21:19:07 -07:00
parent b4c6de65bf
commit 20aa3fc5b1
5 changed files with 47 additions and 0 deletions

View File

@ -187,6 +187,11 @@ public:
const nsAString& aDeviceAddress,
nsAString& aDevicePath) = 0;
virtual int
GetDeviceServiceChannelInternal(const nsAString& aObjectPath,
const nsAString& aPattern,
int aAttributeId) = 0;
protected:
BluetoothService()
{

View File

@ -868,3 +868,24 @@ BluetoothDBusService::GetDevicePath(const nsAString& aAdapterPath,
aDevicePath = GetObjectPathFromAddress(aAdapterPath, aDeviceAddress);
return true;
}
int
BluetoothDBusService::GetDeviceServiceChannelInternal(const nsAString& aObjectPath,
const nsAString& aPattern,
int aAttributeId)
{
// This is a blocking call, should not be run on main thread.
MOZ_ASSERT(!NS_IsMainThread());
const char* deviceObjectPath = NS_ConvertUTF16toUTF8(aObjectPath).get();
const char* pattern = NS_ConvertUTF16toUTF8(aPattern).get();
DBusMessage *reply =
dbus_func_args(mConnection, deviceObjectPath,
DBUS_DEVICE_IFACE, "GetServiceAttributeValue",
DBUS_TYPE_STRING, &pattern,
DBUS_TYPE_UINT16, &aAttributeId,
DBUS_TYPE_INVALID);
return reply ? dbus_returns_int32(reply) : -1;
}

View File

@ -44,6 +44,10 @@ public:
GetDevicePath(const nsAString& aAdapterPath,
const nsAString& aDeviceAddress,
nsAString& aDevicePath);
virtual int
GetDeviceServiceChannelInternal(const nsAString& aObjectPath,
const nsAString& aPattern,
int aAttributeId);
private:
nsresult SendGetPropertyMessage(const nsAString& aPath,

View File

@ -260,5 +260,21 @@ DBusMessage * dbus_func_args_error(DBusConnection *conn,
return ret;
}
int dbus_returns_int32(DBusMessage *reply)
{
DBusError err;
int ret = -1;
dbus_error_init(&err);
if (!dbus_message_get_args(reply, &err,
DBUS_TYPE_INT32, &ret,
DBUS_TYPE_INVALID)) {
LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, reply);
}
dbus_message_unref(reply);
return ret;
}
}
}

View File

@ -105,6 +105,7 @@ DBusMessage* dbus_func_args_timeout_valist(DBusConnection* conn,
int first_arg_type,
va_list args);
int dbus_returns_int32(DBusMessage *reply);
}
}