Skip to content

Commit

Permalink
Bug 1154235: Share BluetoothUtils.{cpp,h} between Bluetooth v1 and v2…
Browse files Browse the repository at this point in the history
…, r=btian

With this patch, Bluetooth v1 and v2 share the same files for
BluetoothUtils.{cpp,h}. Some of the functions are still version specific
and cannot be shared. The v1 variants can be removed after switching to
v2.
  • Loading branch information
tdz committed Apr 16, 2015
1 parent f6510bb commit 87b1c57
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 227 deletions.
6 changes: 5 additions & 1 deletion CLOBBER
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
# changes to stick? As of bug 928195, this shouldn't be necessary! Please
# don't change CLOBBER for WebIDL changes any more.

Bug 1153796: Merge Bluetooth backend interfaces
Bug 1154235: Merge BluetoothUtils.{cpp,h} variants into single file

This patch set renames and removes source files. This requires updating
the build system's dependency information from scratch. The issue has
been reported in bug 1154232.
45 changes: 44 additions & 1 deletion dom/bluetooth/BluetoothUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ GeneratePathFromGattId(const BluetoothGattId& aId,
/**
* |SetJsObject| is an internal function used by |BroadcastSystemMessage| only
*/
bool
static bool
SetJsObject(JSContext* aContext,
const BluetoothValue& aValue,
JS::Handle<JSObject*> aObj)
Expand Down Expand Up @@ -219,6 +219,7 @@ BroadcastSystemMessage(const nsAString& aType,
return true;
}

#ifdef MOZ_B2G_BT_API_V2
void
DispatchReplySuccess(BluetoothReplyRunnable* aRunnable)
{
Expand Down Expand Up @@ -281,6 +282,48 @@ DispatchStatusChangedEvent(const nsAString& aType,
NS_ENSURE_TRUE_VOID(bs);
bs->DistributeSignal(aType, NS_LITERAL_STRING(KEY_ADAPTER), data);
}
#else
// TODO: remove with bluetooth1
void
DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,
const BluetoothValue& aValue,
const nsAString& aErrorStr)
{
// Reply will be deleted by the runnable after running on main thread
BluetoothReply* reply;
if (!aErrorStr.IsEmpty()) {
nsString err(aErrorStr);
reply = new BluetoothReply(BluetoothReplyError(err));
} else {
MOZ_ASSERT(aValue.type() != BluetoothValue::T__None);
reply = new BluetoothReply(BluetoothReplySuccess(aValue));
}

aRunnable->SetReply(reply);
if (NS_FAILED(NS_DispatchToMainThread(aRunnable))) {
BT_WARNING("Failed to dispatch to main thread!");
}
}

// TODO: remove with bluetooth1
void
DispatchStatusChangedEvent(const nsAString& aType,
const nsAString& aAddress,
bool aStatus)
{
MOZ_ASSERT(NS_IsMainThread());

InfallibleTArray<BluetoothNamedValue> data;
BT_APPEND_NAMED_VALUE(data, "address", nsString(aAddress));
BT_APPEND_NAMED_VALUE(data, "status", aStatus);

BluetoothSignal signal(nsString(aType), NS_LITERAL_STRING(KEY_ADAPTER), data);

BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
bs->DistributeSignal(signal);
}
#endif

bool
IsMainProcess()
Expand Down
14 changes: 14 additions & 0 deletions dom/bluetooth/BluetoothUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ BroadcastSystemMessage(const nsAString& aType,
// Dispatch bluetooth reply to main thread
//

#ifdef MOZ_B2G_BT_API_V2
/**
* Dispatch successful bluetooth reply with NO value to reply request.
*
Expand Down Expand Up @@ -142,6 +143,19 @@ DispatchReplyError(BluetoothReplyRunnable* aRunnable,
void
DispatchReplyError(BluetoothReplyRunnable* aRunnable,
const enum BluetoothStatus aStatus);
#else
// TODO: remove with bluetooth1
void
DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,
const BluetoothValue& aValue,
const nsAString& aErrorStr);

// TODO: remove with bluetooth1
void
DispatchStatusChangedEvent(const nsAString& aType,
const nsAString& aDeviceAddress,
bool aStatus);
#endif

void
DispatchStatusChangedEvent(const nsAString& aType,
Expand Down
178 changes: 0 additions & 178 deletions dom/bluetooth/bluetooth1/BluetoothUtils.cpp

This file was deleted.

44 changes: 0 additions & 44 deletions dom/bluetooth/bluetooth1/BluetoothUtils.h

This file was deleted.

5 changes: 2 additions & 3 deletions dom/bluetooth/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ if CONFIG['MOZ_B2G_BT']:

SOURCES += [
'BluetoothInterface.cpp',
'BluetoothInterfaceHelpers.cpp'
'BluetoothInterfaceHelpers.cpp',
'BluetoothUtils.cpp'
]

if CONFIG['MOZ_B2G_BT_API_V2']:
Expand All @@ -32,7 +33,6 @@ if CONFIG['MOZ_B2G_BT']:
'bluetooth2/BluetoothProfileController.cpp',
'bluetooth2/BluetoothReplyRunnable.cpp',
'bluetooth2/BluetoothService.cpp',
'bluetooth2/BluetoothUtils.cpp',
'bluetooth2/BluetoothUuid.cpp',
'bluetooth2/ipc/BluetoothChild.cpp',
'bluetooth2/ipc/BluetoothParent.cpp',
Expand All @@ -58,7 +58,6 @@ if CONFIG['MOZ_B2G_BT']:
'bluetooth1/BluetoothPropertyContainer.cpp',
'bluetooth1/BluetoothReplyRunnable.cpp',
'bluetooth1/BluetoothService.cpp',
'bluetooth1/BluetoothUtils.cpp',
'bluetooth1/BluetoothUuid.cpp',
'bluetooth1/ipc/BluetoothChild.cpp',
'bluetooth1/ipc/BluetoothParent.cpp',
Expand Down

0 comments on commit 87b1c57

Please sign in to comment.