dom/bluetooth/BluetoothCommon.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial