Closed Bug 1171866 Opened 9 years ago Closed 9 years ago

[bluetooth2] Remove ReversedUuidToString

Categories

(Firefox OS Graveyard :: Bluetooth, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(firefox41 fixed)

RESOLVED FIXED
2.2 S14 (12june)
Tracking Status
firefox41 --- fixed

People

(Reporter: brsun, Assigned: brsun)

References

Details

Attachments

(1 file, 5 obsolete files)

Suggest to do UUID reversion inside Bluetooth backend wrapper.
Blocks: 1171868
Blocks: 1161945
Attachment #8616522 - Flags: review?(joliu)
Attachment #8616523 - Flags: review?(tzimmermann)
Comment on attachment 8616523 [details] [review]
https://github.com/mozilla-b2g/platform_system_bluetoothd/pull/34

Belongs into Gecko, except BlueZ does it this way.
Attachment #8616523 - Flags: review?(tzimmermann) → review-
Address comment 3.
Attachment #8616522 - Attachment is obsolete: true
Attachment #8616523 - Attachment is obsolete: true
Attachment #8616522 - Flags: review?(joliu)
Attachment #8616620 - Flags: review?(joliu)
Attachment #8616620 - Flags: feedback?(tzimmermann)
Comment on attachment 8616620 [details] [diff] [review]
bug1171866_remove_reverse_uuid_to_string.v2.patch

Review of attachment 8616620 [details] [diff] [review]:
-----------------------------------------------------------------

The general patch seems good. ACK'ed with a fix of the copying overhead in the daemon backend.

::: dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
@@ +137,5 @@
>    uint8_t mName[256];
>  };
>  
> +// reversed GATT UUID, see bug 1171866
> +struct BluetoothReversedUuid {

That requires unnecessary copying of the UUID. Rather define structures similar to the existing |PackArray| and |PackConversion| structures.

  template<typename T>
  struct PackReversed<T> {

    PackReversed(const T& aValue)
      : mValue(aValue)
    { }

    const T& mValue;
  };

  template<typename T>
  struct UnpackReversed<T> {

    UnpackReversed(T& aValue)
      : mValue(&aValue)
    { }

    T* mValue;
  };

This will allow you to implement functions for packing and unpacking that don't require copying, but (de-)serialize directly into/from a PDU's buffer.

  nsresult
  PackPDU(const PackReversed<BluetoothUuid>& aIn, BluetoothDaemonPDU& aPDU)

  nsresult
  UnpackPDU(BluetoothDaemonPDU& aPDU, const UnpackReversed<BluetoothUuid>& aOut)
Attachment #8616620 - Flags: feedback?(tzimmermann) → feedback+
Comment on attachment 8616620 [details] [diff] [review]
bug1171866_remove_reverse_uuid_to_string.v2.patch

Review of attachment 8616620 [details] [diff] [review]:
-----------------------------------------------------------------

Cancel my review request for now, please request for review after Thomas's feedback being addressed.

Thanks,
Jocelyn
Attachment #8616620 - Flags: review?(joliu)
Address comment 5.
Attachment #8616620 - Attachment is obsolete: true
Attachment #8617783 - Flags: review?(joliu)
Comment on attachment 8617783 [details] [diff] [review]
bug1171866_remove_reverse_uuid_to_string.v3.patch

Hi Thomas,

May I have your feedback again to make sure my understanding of comment 5 is correct?
Attachment #8617783 - Flags: feedback?(tzimmermann)
Comment on attachment 8617783 [details] [diff] [review]
bug1171866_remove_reverse_uuid_to_string.v3.patch

Review of attachment 8617783 [details] [diff] [review]:
-----------------------------------------------------------------

This looks good. Thanks a lot!

::: dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
@@ +1164,5 @@
>   */
>  nsresult
>  UnpackPDU(BluetoothDaemonPDU& aPDU, const UnpackString0& aOut);
>  
> +/* |UnpackReversedArray| is a helper for unpacking arrays in a reversed order.

Maybe write

  'for unpacking array elements in reversed order'

because if an element is more than one byte in size, the order of elements will be reversed, but not the bytes within each element.

@@ +1169,5 @@
> + * Pass an instance of this structure as the second argument to |UnpackPDU| to
> + * unpack an array in a reversed order.
> + */
> +template <typename T>
> +struct UnpackReversedArray

Oh, you have a separate array struct. Nice! :)

If you want to get fancy, you could implement |UnpackReversedArray| with a combination of |UnpackArray| and |UnpackReversed|. But the current patch is also fine!

@@ +1211,5 @@
> +}
> +
> +template<typename T>
> +inline nsresult
> +UnpackPDU(BluetoothDaemonPDU& aPDU, UnpackReversedArray<T>& aOut)

A special variant for non-const structures?
Attachment #8617783 - Flags: feedback?(tzimmermann) → feedback+
Comment on attachment 8617783 [details] [diff] [review]
bug1171866_remove_reverse_uuid_to_string.v3.patch

Review of attachment 8617783 [details] [diff] [review]:
-----------------------------------------------------------------

Good job. :)
Attachment #8617783 - Flags: review?(joliu) → review+
This is the fancy one. :)
Attachment #8617783 - Attachment is obsolete: true
Attachment #8620786 - Flags: feedback?(tzimmermann)
Comment on attachment 8620786 [details] [diff] [review]
bug1171866_remove_reverse_uuid_to_string.v4.patch

Review of attachment 8620786 [details] [diff] [review]:
-----------------------------------------------------------------

Great! :)

::: dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
@@ +580,5 @@
>  }
>  
> +/* |PackReversed| is a helper for packing data in a reversed order. Pass an
> + * instance of this structure as the first argument to |PackPDU| to pack data
> + * in a reversed order.

Just a small nit: one says 'in reversed order' without 'a'. Here and everywhere else.

@@ +586,5 @@
> +template<typename T>
> +struct PackReversed
> +{
> +  PackReversed(const T& aValue)
> +  : mValue(aValue)

4-byte indention for the initializers as illustrated here: https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style#Classes
Attachment #8620786 - Flags: feedback?(tzimmermann) → feedback+
Attachment #8620786 - Attachment is obsolete: true
Attachment #8620885 - Flags: review+
Attachment #8620885 - Flags: feedback+
(In reply to Bruce Sun [:brsun] from comment #13)
> Created attachment 8620885 [details] [diff] [review]
> bug1171866_remove_reverse_uuid_to_string.commit.patch

Address comment 12.
|ReversedUuidToString| is used in Bluetooth API v2, which is not covered by try server currently.
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/4a91e5fda5e2
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → 2.2 S14 (12june)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: