mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 922617: Don't inherit BluetoothDBusService from RawDBusConnection, r=echou
BluetoothDBusService uses RawDBusConnection, but isn't one. With this patch, the connection is instead maintained as a field of the class. This change also allows to delete the class instance when the connection gets closed, which will allow for further cleanups of the DBus connection handling within Bluetooth.
This commit is contained in:
parent
d334af791c
commit
750ccd808d
@ -1626,7 +1626,9 @@ BluetoothDBusService::StartInternal()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (NS_FAILED(EstablishDBusConnection())) {
|
||||
mConnection = new RawDBusConnection();
|
||||
|
||||
if (NS_FAILED(mConnection->EstablishDBusConnection())) {
|
||||
BT_WARNING("Cannot start Main Thread DBus connection!");
|
||||
StopDBus();
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -1648,7 +1650,7 @@ BluetoothDBusService::StartInternal()
|
||||
// signals we want, register all of them in this thread at startup.
|
||||
// The event handler will sort the destinations out as needed.
|
||||
for (uint32_t i = 0; i < ArrayLength(sBluetoothDBusSignals); ++i) {
|
||||
dbus_bus_add_match(mConnection,
|
||||
dbus_bus_add_match(mConnection->GetConnection(),
|
||||
sBluetoothDBusSignals[i],
|
||||
&err);
|
||||
if (dbus_error_is_set(&err)) {
|
||||
@ -1657,8 +1659,8 @@ BluetoothDBusService::StartInternal()
|
||||
}
|
||||
|
||||
// Add a filter for all incoming messages_base
|
||||
if (!dbus_connection_add_filter(mConnection, EventFilter,
|
||||
NULL, NULL)) {
|
||||
if (!dbus_connection_add_filter(mConnection->GetConnection(),
|
||||
EventFilter, NULL, NULL)) {
|
||||
BT_WARNING("Cannot create DBus Event Filter for DBus Thread!");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@ -1712,7 +1714,7 @@ BluetoothDBusService::StopInternal()
|
||||
DBusError err;
|
||||
dbus_error_init(&err);
|
||||
for (uint32_t i = 0; i < ArrayLength(sBluetoothDBusSignals); ++i) {
|
||||
dbus_bus_remove_match(mConnection,
|
||||
dbus_bus_remove_match(mConnection->GetConnection(),
|
||||
sBluetoothDBusSignals[i],
|
||||
&err);
|
||||
if (dbus_error_is_set(&err)) {
|
||||
@ -1720,7 +1722,8 @@ BluetoothDBusService::StopInternal()
|
||||
}
|
||||
}
|
||||
|
||||
dbus_connection_remove_filter(mConnection, EventFilter, nullptr);
|
||||
dbus_connection_remove_filter(mConnection->GetConnection(),
|
||||
EventFilter, nullptr);
|
||||
|
||||
if (!dbus_connection_unregister_object_path(gThreadConnection->GetConnection(),
|
||||
KEY_LOCAL_AGENT)) {
|
||||
@ -1885,7 +1888,8 @@ BluetoothDBusService::GetDefaultAdapterPathInternal(
|
||||
nsRefPtr<DefaultAdapterPathReplyHandler> handler =
|
||||
new DefaultAdapterPathReplyHandler(aRunnable);
|
||||
|
||||
bool success = SendWithReply(DefaultAdapterPathReplyHandler::Callback,
|
||||
bool success = mConnection->SendWithReply(
|
||||
DefaultAdapterPathReplyHandler::Callback,
|
||||
handler.get(), 1000,
|
||||
"/", DBUS_MANAGER_IFACE, "DefaultAdapter",
|
||||
DBUS_TYPE_INVALID);
|
||||
@ -1928,7 +1932,8 @@ BluetoothDBusService::SendDiscoveryMessage(const char* aMessageName,
|
||||
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable(aRunnable);
|
||||
|
||||
bool success = SendWithReply(OnSendDiscoveryMessageReply,
|
||||
bool success = mConnection->SendWithReply(
|
||||
OnSendDiscoveryMessageReply,
|
||||
static_cast<void*>(aRunnable), -1,
|
||||
NS_ConvertUTF16toUTF8(sAdapterPath).get(),
|
||||
DBUS_ADAPTER_IFACE, aMessageName,
|
||||
@ -1982,8 +1987,8 @@ BluetoothDBusService::SendAsyncDBusMessage(const nsAString& aObjectPath,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
bool ret = SendWithReply(aCallback,
|
||||
static_cast<void*>(serviceClass.forget()), -1,
|
||||
bool ret = mConnection->SendWithReply(
|
||||
aCallback, static_cast<void*>(serviceClass.forget()), -1,
|
||||
NS_ConvertUTF16toUTF8(aObjectPath).get(),
|
||||
aInterface, NS_ConvertUTF16toUTF8(aMessage).get(),
|
||||
DBUS_TYPE_INVALID);
|
||||
@ -2294,7 +2299,10 @@ BluetoothDBusService::SetProperty(BluetoothObjectType aType,
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
|
||||
|
||||
// msg is unref'd as part of SendWithReply
|
||||
if (!SendWithReply(GetVoidCallback, (void*)aRunnable, 1000, msg)) {
|
||||
bool success = mConnection->SendWithReply(GetVoidCallback,
|
||||
(void*)aRunnable,
|
||||
1000, msg);
|
||||
if (!success) {
|
||||
BT_WARNING("SendWithReply failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@ -2341,7 +2349,8 @@ BluetoothDBusService::CreatePairedDeviceInternal(
|
||||
|
||||
// Then send CreatePairedDevice, it will register a temp device agent then
|
||||
// unregister it after pairing process is over
|
||||
bool ret = SendWithReply(GetObjectPathCallback, (void*)runnable, aTimeout,
|
||||
bool ret = mConnection->SendWithReply(
|
||||
GetObjectPathCallback, (void*)runnable, aTimeout,
|
||||
NS_ConvertUTF16toUTF8(sAdapterPath).get(),
|
||||
DBUS_ADAPTER_IFACE,
|
||||
"CreatePairedDevice",
|
||||
@ -2392,8 +2401,8 @@ BluetoothDBusService::RemoveDeviceInternal(const nsAString& aDeviceAddress,
|
||||
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable(aRunnable);
|
||||
|
||||
bool success = SendWithReply(OnRemoveDeviceReply,
|
||||
static_cast<void*>(runnable.get()), -1,
|
||||
bool success = mConnection->SendWithReply(
|
||||
OnRemoveDeviceReply, static_cast<void*>(runnable.get()), -1,
|
||||
NS_ConvertUTF16toUTF8(sAdapterPath).get(),
|
||||
DBUS_ADAPTER_IFACE, "RemoveDevice",
|
||||
DBUS_TYPE_OBJECT_PATH, &cstrDeviceObjectPath,
|
||||
@ -2443,7 +2452,7 @@ BluetoothDBusService::SetPinCodeInternal(const nsAString& aDeviceAddress,
|
||||
errorStr.AssignLiteral("Couldn't append arguments to dbus message.");
|
||||
result = false;
|
||||
} else {
|
||||
result = Send(reply);
|
||||
result = mConnection->Send(reply);
|
||||
}
|
||||
|
||||
dbus_message_unref(msg);
|
||||
@ -2489,7 +2498,7 @@ BluetoothDBusService::SetPasskeyInternal(const nsAString& aDeviceAddress,
|
||||
errorStr.AssignLiteral("Couldn't append arguments to dbus message.");
|
||||
result = false;
|
||||
} else {
|
||||
result = Send(reply);
|
||||
result = mConnection->Send(reply);
|
||||
}
|
||||
|
||||
dbus_message_unref(msg);
|
||||
@ -2533,7 +2542,7 @@ BluetoothDBusService::SetPairingConfirmationInternal(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = Send(reply);
|
||||
bool result = mConnection->Send(reply);
|
||||
if (!result) {
|
||||
errorStr.AssignLiteral("Can't send message!");
|
||||
}
|
||||
@ -2746,8 +2755,8 @@ BluetoothDBusService::GetServiceChannel(const nsAString& aDeviceAddress,
|
||||
nsRefPtr<OnGetServiceChannelReplyHandler> handler =
|
||||
new OnGetServiceChannelReplyHandler(objectPath, aServiceUUID, aManager);
|
||||
|
||||
bool success = SendWithReply(OnGetServiceChannelReplyHandler::Callback,
|
||||
handler, -1,
|
||||
bool success = mConnection->SendWithReply(
|
||||
OnGetServiceChannelReplyHandler::Callback, handler, -1,
|
||||
NS_ConvertUTF16toUTF8(objectPath).get(),
|
||||
DBUS_DEVICE_IFACE, "GetServiceAttributeValue",
|
||||
DBUS_TYPE_STRING, &cstrServiceUUID,
|
||||
@ -2799,7 +2808,7 @@ BluetoothDBusService::UpdateSdpRecords(const nsAString& aDeviceAddress,
|
||||
OnUpdateSdpRecordsRunnable* callbackRunnable =
|
||||
new OnUpdateSdpRecordsRunnable(objectPath, aManager);
|
||||
|
||||
return SendWithReply(DiscoverServicesCallback,
|
||||
return mConnection->SendWithReply(DiscoverServicesCallback,
|
||||
(void*)callbackRunnable, -1,
|
||||
NS_ConvertUTF16toUTF8(objectPath).get(),
|
||||
DBUS_DEVICE_IFACE,
|
||||
@ -3014,7 +3023,8 @@ BluetoothDBusService::SendMetaData(const nsAString& aTitle,
|
||||
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable(aRunnable);
|
||||
|
||||
bool ret = SendWithReply(GetVoidCallback, (void*)runnable.get(), -1,
|
||||
bool ret = mConnection->SendWithReply(
|
||||
GetVoidCallback, (void*)runnable.get(), -1,
|
||||
NS_ConvertUTF16toUTF8(objectPath).get(),
|
||||
DBUS_CTL_IFACE, "UpdateMetaData",
|
||||
DBUS_TYPE_STRING, &title,
|
||||
@ -3111,7 +3121,8 @@ BluetoothDBusService::SendPlayStatus(int64_t aDuration,
|
||||
|
||||
nsRefPtr<BluetoothReplyRunnable> runnable(aRunnable);
|
||||
|
||||
bool ret = SendWithReply(GetVoidCallback, (void*)runnable.get(), -1,
|
||||
bool ret = mConnection->SendWithReply(
|
||||
GetVoidCallback, (void*)runnable.get(), -1,
|
||||
NS_ConvertUTF16toUTF8(objectPath).get(),
|
||||
DBUS_CTL_IFACE, "UpdatePlayStatus",
|
||||
DBUS_TYPE_UINT32, &aDuration,
|
||||
@ -3158,7 +3169,8 @@ BluetoothDBusService::UpdatePlayStatus(uint32_t aDuration,
|
||||
|
||||
uint32_t tempPlayStatus = aPlayStatus;
|
||||
|
||||
bool ret = SendWithReply(ControlCallback, nullptr, -1,
|
||||
bool ret = mConnection->SendWithReply(
|
||||
ControlCallback, nullptr, -1,
|
||||
NS_ConvertUTF16toUTF8(objectPath).get(),
|
||||
DBUS_CTL_IFACE, "UpdatePlayStatus",
|
||||
DBUS_TYPE_UINT32, &aDuration,
|
||||
@ -3186,10 +3198,10 @@ BluetoothDBusService::UpdateNotification(ControlEventId aEventId,
|
||||
GetObjectPathFromAddress(sAdapterPath, address);
|
||||
uint16_t eventId = aEventId;
|
||||
|
||||
bool ret = SendWithReply(ControlCallback, nullptr, -1,
|
||||
bool ret = mConnection->SendWithReply(
|
||||
ControlCallback, nullptr, -1,
|
||||
NS_ConvertUTF16toUTF8(objectPath).get(),
|
||||
DBUS_CTL_IFACE,
|
||||
"UpdateNotification",
|
||||
DBUS_CTL_IFACE, "UpdateNotification",
|
||||
DBUS_TYPE_UINT16, &eventId,
|
||||
DBUS_TYPE_UINT64, &aData,
|
||||
DBUS_TYPE_INVALID);
|
||||
|
@ -22,7 +22,6 @@ BEGIN_BLUETOOTH_NAMESPACE
|
||||
*/
|
||||
|
||||
class BluetoothDBusService : public BluetoothService
|
||||
, private mozilla::ipc::RawDBusConnection
|
||||
{
|
||||
public:
|
||||
bool IsReady();
|
||||
@ -201,6 +200,8 @@ private:
|
||||
const char* aInterface,
|
||||
const nsAString& aMessage,
|
||||
mozilla::ipc::DBusReplyCallback aCallback);
|
||||
|
||||
nsRefPtr<mozilla::ipc::RawDBusConnection> mConnection;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user