1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_bluetooth_bluetoothutils_h
#define mozilla_dom_bluetooth_bluetoothutils_h
#include "BluetoothCommon.h"
#include "js/TypeDecls.h"
BEGIN_BLUETOOTH_NAMESPACE
class BluetoothNamedValue;
class BluetoothValue;
class BluetoothReplyRunnable;
void
UuidToString(const BluetoothUuid& aUuid, nsAString& aString);
/**
* Convert xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx uuid string to BluetoothUuid object.
* This utility function is used by goanna internal only to convert uuid string
* created by goanna back to BluetoothUuid representation.
*/
void
StringToUuid(const char* aString, BluetoothUuid& aUuid);
bool
SetJsObject(JSContext* aContext,
const BluetoothValue& aValue,
JS::Handle<JSObject*> aObj);
bool
BroadcastSystemMessage(const nsAString& aType,
const BluetoothValue& aData);
bool
BroadcastSystemMessage(const nsAString& aType,
const InfallibleTArray<BluetoothNamedValue>& aData);
/**
* Dispatch BluetoothReply to main thread. The reply contains an error string
* if the request fails.
*
* This function is for methods returning DOMRequest. If |aErrorStr| is not
* empty, the DOMRequest property 'error.name' would be updated to |aErrorStr|
* before callback function 'onerror' is fired.
*
* @param aRunnable the runnable to reply bluetooth request.
* @param aValue the BluetoothValue used to reply successful request.
* @param aErrorStr the error string used to reply failed request.
*/
void
DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,
const BluetoothValue& aValue,
const nsAString& aErrorStr);
/**
* Dispatch BluetoothReply to main thread. The reply contains an error string
* if the request fails.
*
* This function is for methods returning Promise. If |aStatusCode| is not
* STATUS_SUCCESS, the Promise would reject with an Exception object with
* nsError associated with |aStatusCode|. The name and messege of Exception
* (defined in dom/base/domerr.msg) are filled automatically during promise
* rejection.
*
* @param aRunnable the runnable to reply bluetooth request.
* @param aValue the BluetoothValue to reply successful request.
* @param aStatusCode the error status to reply failed request.
*/
void
DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,
const BluetoothValue& aValue,
const enum BluetoothStatus aStatusCode);
void
DispatchStatusChangedEvent(const nsAString& aType,
const nsAString& aDeviceAddress,
bool aStatus);
/**
* Check whether the caller runs at B2G process.
*
* @return true if the caller runs at B2G process, false otherwise.
*/
bool
IsMainProcess();
END_BLUETOOTH_NAMESPACE
#endif
|