1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bluetooth/BluetoothCommon.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,163 @@ 1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_bluetooth_bluetoothcommon_h__ 1.11 +#define mozilla_dom_bluetooth_bluetoothcommon_h__ 1.12 + 1.13 +#include "mozilla/Observer.h" 1.14 +#include "nsPrintfCString.h" 1.15 +#include "nsString.h" 1.16 +#include "nsTArray.h" 1.17 + 1.18 +extern bool gBluetoothDebugFlag; 1.19 + 1.20 +#define SWITCH_BT_DEBUG(V) (gBluetoothDebugFlag = V) 1.21 + 1.22 +#undef BT_LOG 1.23 +#if defined(MOZ_WIDGET_GONK) 1.24 +#include <android/log.h> 1.25 + 1.26 +/** 1.27 + * Prints 'D'EBUG build logs, which show in DEBUG build only when 1.28 + * developer setting 'Bluetooth output in adb' is enabled. 1.29 + */ 1.30 +#define BT_LOGD(msg, ...) \ 1.31 + do { \ 1.32 + if (gBluetoothDebugFlag) { \ 1.33 + __android_log_print(ANDROID_LOG_INFO, "GeckoBluetooth", \ 1.34 + "%s: " msg, __FUNCTION__, ##__VA_ARGS__); \ 1.35 + } \ 1.36 + } while(0) 1.37 + 1.38 +/** 1.39 + * Prints 'R'ELEASE build logs, which show in both RELEASE and DEBUG builds. 1.40 + */ 1.41 +#define BT_LOGR(msg, ...) \ 1.42 + __android_log_print(ANDROID_LOG_INFO, "GeckoBluetooth", \ 1.43 + "%s: " msg, __FUNCTION__, ##__VA_ARGS__) \ 1.44 + 1.45 +/** 1.46 + * Prints DEBUG build warnings, which show in DEBUG build only. 1.47 + */ 1.48 +#define BT_WARNING(args...) \ 1.49 + NS_WARNING(nsPrintfCString(args).get()) \ 1.50 + 1.51 +#else 1.52 +#define BT_LOGD(msg, ...) \ 1.53 + do { \ 1.54 + if (gBluetoothDebugFlag) { \ 1.55 + printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__); \ 1.56 + } \ 1.57 + } while(0) 1.58 + 1.59 +#define BT_LOGR(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__)) 1.60 +#define BT_WARNING(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__)) 1.61 +#endif 1.62 + 1.63 +/** 1.64 + * Wrap literal name and value into a BluetoothNamedValue 1.65 + * and append it to the array. 1.66 + */ 1.67 +#define BT_APPEND_NAMED_VALUE(array, name, value) \ 1.68 + array.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING(name), value)) 1.69 + 1.70 +/** 1.71 + * Ensure success of system message broadcast with void return. 1.72 + */ 1.73 +#define BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters) \ 1.74 + do { \ 1.75 + if (!BroadcastSystemMessage(type, parameters)) { \ 1.76 + BT_WARNING("Failed to broadcast [%s]", \ 1.77 + NS_ConvertUTF16toUTF8(type).get()); \ 1.78 + return; \ 1.79 + } \ 1.80 + } while(0) 1.81 + 1.82 +#define BEGIN_BLUETOOTH_NAMESPACE \ 1.83 + namespace mozilla { namespace dom { namespace bluetooth { 1.84 +#define END_BLUETOOTH_NAMESPACE \ 1.85 + } /* namespace bluetooth */ } /* namespace dom */ } /* namespace mozilla */ 1.86 +#define USING_BLUETOOTH_NAMESPACE \ 1.87 + using namespace mozilla::dom::bluetooth; 1.88 + 1.89 +#define KEY_LOCAL_AGENT "/B2G/bluetooth/agent" 1.90 +#define KEY_REMOTE_AGENT "/B2G/bluetooth/remote_device_agent" 1.91 +#define KEY_MANAGER "/B2G/bluetooth/manager" 1.92 +#define KEY_ADAPTER "/B2G/bluetooth/adapter" 1.93 + 1.94 +/** 1.95 + * When the connection status of a Bluetooth profile is changed, we'll notify 1.96 + * observers which register the following topics. 1.97 + */ 1.98 +#define BLUETOOTH_A2DP_STATUS_CHANGED_ID "bluetooth-a2dp-status-changed" 1.99 +#define BLUETOOTH_HFP_STATUS_CHANGED_ID "bluetooth-hfp-status-changed" 1.100 +#define BLUETOOTH_HID_STATUS_CHANGED_ID "bluetooth-hid-status-changed" 1.101 +#define BLUETOOTH_SCO_STATUS_CHANGED_ID "bluetooth-sco-status-changed" 1.102 + 1.103 +/** 1.104 + * When the connection status of a Bluetooth profile is changed, we'll 1.105 + * dispatch one of the following events. 1.106 + */ 1.107 +#define A2DP_STATUS_CHANGED_ID "a2dpstatuschanged" 1.108 +#define HFP_STATUS_CHANGED_ID "hfpstatuschanged" 1.109 +#define SCO_STATUS_CHANGED_ID "scostatuschanged" 1.110 + 1.111 +/** 1.112 + * When the pair status of a Bluetooth device is changed, we'll dispatch an 1.113 + * event. 1.114 + */ 1.115 +#define PAIRED_STATUS_CHANGED_ID "pairedstatuschanged" 1.116 + 1.117 +/** 1.118 + * When receiving a query about current play status from remote device, we'll 1.119 + * dispatch an event. 1.120 + */ 1.121 +#define REQUEST_MEDIA_PLAYSTATUS_ID "requestmediaplaystatus" 1.122 + 1.123 +// Bluetooth address format: xx:xx:xx:xx:xx:xx (or xx_xx_xx_xx_xx_xx) 1.124 +#define BLUETOOTH_ADDRESS_LENGTH 17 1.125 +#define BLUETOOTH_ADDRESS_NONE "00:00:00:00:00:00" 1.126 +#define BLUETOOTH_ADDRESS_BYTES 6 1.127 + 1.128 +// Bluetooth stack internal error, such as I/O error 1.129 +#define ERR_INTERNAL_ERROR "InternalError" 1.130 + 1.131 +BEGIN_BLUETOOTH_NAMESPACE 1.132 + 1.133 +enum BluetoothSocketType { 1.134 + RFCOMM = 1, 1.135 + SCO = 2, 1.136 + L2CAP = 3, 1.137 + EL2CAP = 4 1.138 +}; 1.139 + 1.140 +class BluetoothSignal; 1.141 +typedef mozilla::Observer<BluetoothSignal> BluetoothSignalObserver; 1.142 + 1.143 +// Enums for object types, currently used for shared function lookups 1.144 +// (get/setproperty, etc...). Possibly discernable via dbus paths, but this 1.145 +// method is future-proofed for platform independence. 1.146 +enum BluetoothObjectType { 1.147 + TYPE_MANAGER = 0, 1.148 + TYPE_ADAPTER = 1, 1.149 + TYPE_DEVICE = 2, 1.150 + 1.151 + TYPE_INVALID 1.152 +}; 1.153 + 1.154 +enum ControlPlayStatus { 1.155 + PLAYSTATUS_STOPPED = 0x00, 1.156 + PLAYSTATUS_PLAYING = 0x01, 1.157 + PLAYSTATUS_PAUSED = 0x02, 1.158 + PLAYSTATUS_FWD_SEEK = 0x03, 1.159 + PLAYSTATUS_REV_SEEK = 0x04, 1.160 + PLAYSTATUS_UNKNOWN, 1.161 + PLAYSTATUS_ERROR = 0xFF, 1.162 +}; 1.163 + 1.164 +END_BLUETOOTH_NAMESPACE 1.165 + 1.166 +#endif // mozilla_dom_bluetooth_bluetoothcommon_h__