|
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef mozilla_dom_bluetooth_bluetoothcommon_h__ |
|
8 #define mozilla_dom_bluetooth_bluetoothcommon_h__ |
|
9 |
|
10 #include "mozilla/Observer.h" |
|
11 #include "nsPrintfCString.h" |
|
12 #include "nsString.h" |
|
13 #include "nsTArray.h" |
|
14 |
|
15 extern bool gBluetoothDebugFlag; |
|
16 |
|
17 #define SWITCH_BT_DEBUG(V) (gBluetoothDebugFlag = V) |
|
18 |
|
19 #undef BT_LOG |
|
20 #if defined(MOZ_WIDGET_GONK) |
|
21 #include <android/log.h> |
|
22 |
|
23 /** |
|
24 * Prints 'D'EBUG build logs, which show in DEBUG build only when |
|
25 * developer setting 'Bluetooth output in adb' is enabled. |
|
26 */ |
|
27 #define BT_LOGD(msg, ...) \ |
|
28 do { \ |
|
29 if (gBluetoothDebugFlag) { \ |
|
30 __android_log_print(ANDROID_LOG_INFO, "GeckoBluetooth", \ |
|
31 "%s: " msg, __FUNCTION__, ##__VA_ARGS__); \ |
|
32 } \ |
|
33 } while(0) |
|
34 |
|
35 /** |
|
36 * Prints 'R'ELEASE build logs, which show in both RELEASE and DEBUG builds. |
|
37 */ |
|
38 #define BT_LOGR(msg, ...) \ |
|
39 __android_log_print(ANDROID_LOG_INFO, "GeckoBluetooth", \ |
|
40 "%s: " msg, __FUNCTION__, ##__VA_ARGS__) \ |
|
41 |
|
42 /** |
|
43 * Prints DEBUG build warnings, which show in DEBUG build only. |
|
44 */ |
|
45 #define BT_WARNING(args...) \ |
|
46 NS_WARNING(nsPrintfCString(args).get()) \ |
|
47 |
|
48 #else |
|
49 #define BT_LOGD(msg, ...) \ |
|
50 do { \ |
|
51 if (gBluetoothDebugFlag) { \ |
|
52 printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__); \ |
|
53 } \ |
|
54 } while(0) |
|
55 |
|
56 #define BT_LOGR(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__)) |
|
57 #define BT_WARNING(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__)) |
|
58 #endif |
|
59 |
|
60 /** |
|
61 * Wrap literal name and value into a BluetoothNamedValue |
|
62 * and append it to the array. |
|
63 */ |
|
64 #define BT_APPEND_NAMED_VALUE(array, name, value) \ |
|
65 array.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING(name), value)) |
|
66 |
|
67 /** |
|
68 * Ensure success of system message broadcast with void return. |
|
69 */ |
|
70 #define BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters) \ |
|
71 do { \ |
|
72 if (!BroadcastSystemMessage(type, parameters)) { \ |
|
73 BT_WARNING("Failed to broadcast [%s]", \ |
|
74 NS_ConvertUTF16toUTF8(type).get()); \ |
|
75 return; \ |
|
76 } \ |
|
77 } while(0) |
|
78 |
|
79 #define BEGIN_BLUETOOTH_NAMESPACE \ |
|
80 namespace mozilla { namespace dom { namespace bluetooth { |
|
81 #define END_BLUETOOTH_NAMESPACE \ |
|
82 } /* namespace bluetooth */ } /* namespace dom */ } /* namespace mozilla */ |
|
83 #define USING_BLUETOOTH_NAMESPACE \ |
|
84 using namespace mozilla::dom::bluetooth; |
|
85 |
|
86 #define KEY_LOCAL_AGENT "/B2G/bluetooth/agent" |
|
87 #define KEY_REMOTE_AGENT "/B2G/bluetooth/remote_device_agent" |
|
88 #define KEY_MANAGER "/B2G/bluetooth/manager" |
|
89 #define KEY_ADAPTER "/B2G/bluetooth/adapter" |
|
90 |
|
91 /** |
|
92 * When the connection status of a Bluetooth profile is changed, we'll notify |
|
93 * observers which register the following topics. |
|
94 */ |
|
95 #define BLUETOOTH_A2DP_STATUS_CHANGED_ID "bluetooth-a2dp-status-changed" |
|
96 #define BLUETOOTH_HFP_STATUS_CHANGED_ID "bluetooth-hfp-status-changed" |
|
97 #define BLUETOOTH_HID_STATUS_CHANGED_ID "bluetooth-hid-status-changed" |
|
98 #define BLUETOOTH_SCO_STATUS_CHANGED_ID "bluetooth-sco-status-changed" |
|
99 |
|
100 /** |
|
101 * When the connection status of a Bluetooth profile is changed, we'll |
|
102 * dispatch one of the following events. |
|
103 */ |
|
104 #define A2DP_STATUS_CHANGED_ID "a2dpstatuschanged" |
|
105 #define HFP_STATUS_CHANGED_ID "hfpstatuschanged" |
|
106 #define SCO_STATUS_CHANGED_ID "scostatuschanged" |
|
107 |
|
108 /** |
|
109 * When the pair status of a Bluetooth device is changed, we'll dispatch an |
|
110 * event. |
|
111 */ |
|
112 #define PAIRED_STATUS_CHANGED_ID "pairedstatuschanged" |
|
113 |
|
114 /** |
|
115 * When receiving a query about current play status from remote device, we'll |
|
116 * dispatch an event. |
|
117 */ |
|
118 #define REQUEST_MEDIA_PLAYSTATUS_ID "requestmediaplaystatus" |
|
119 |
|
120 // Bluetooth address format: xx:xx:xx:xx:xx:xx (or xx_xx_xx_xx_xx_xx) |
|
121 #define BLUETOOTH_ADDRESS_LENGTH 17 |
|
122 #define BLUETOOTH_ADDRESS_NONE "00:00:00:00:00:00" |
|
123 #define BLUETOOTH_ADDRESS_BYTES 6 |
|
124 |
|
125 // Bluetooth stack internal error, such as I/O error |
|
126 #define ERR_INTERNAL_ERROR "InternalError" |
|
127 |
|
128 BEGIN_BLUETOOTH_NAMESPACE |
|
129 |
|
130 enum BluetoothSocketType { |
|
131 RFCOMM = 1, |
|
132 SCO = 2, |
|
133 L2CAP = 3, |
|
134 EL2CAP = 4 |
|
135 }; |
|
136 |
|
137 class BluetoothSignal; |
|
138 typedef mozilla::Observer<BluetoothSignal> BluetoothSignalObserver; |
|
139 |
|
140 // Enums for object types, currently used for shared function lookups |
|
141 // (get/setproperty, etc...). Possibly discernable via dbus paths, but this |
|
142 // method is future-proofed for platform independence. |
|
143 enum BluetoothObjectType { |
|
144 TYPE_MANAGER = 0, |
|
145 TYPE_ADAPTER = 1, |
|
146 TYPE_DEVICE = 2, |
|
147 |
|
148 TYPE_INVALID |
|
149 }; |
|
150 |
|
151 enum ControlPlayStatus { |
|
152 PLAYSTATUS_STOPPED = 0x00, |
|
153 PLAYSTATUS_PLAYING = 0x01, |
|
154 PLAYSTATUS_PAUSED = 0x02, |
|
155 PLAYSTATUS_FWD_SEEK = 0x03, |
|
156 PLAYSTATUS_REV_SEEK = 0x04, |
|
157 PLAYSTATUS_UNKNOWN, |
|
158 PLAYSTATUS_ERROR = 0xFF, |
|
159 }; |
|
160 |
|
161 END_BLUETOOTH_NAMESPACE |
|
162 |
|
163 #endif // mozilla_dom_bluetooth_bluetoothcommon_h__ |