michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_bluetooth_bluetoothcommon_h__ michael@0: #define mozilla_dom_bluetooth_bluetoothcommon_h__ michael@0: michael@0: #include "mozilla/Observer.h" michael@0: #include "nsPrintfCString.h" michael@0: #include "nsString.h" michael@0: #include "nsTArray.h" michael@0: michael@0: extern bool gBluetoothDebugFlag; michael@0: michael@0: #define SWITCH_BT_DEBUG(V) (gBluetoothDebugFlag = V) michael@0: michael@0: #undef BT_LOG michael@0: #if defined(MOZ_WIDGET_GONK) michael@0: #include michael@0: michael@0: /** michael@0: * Prints 'D'EBUG build logs, which show in DEBUG build only when michael@0: * developer setting 'Bluetooth output in adb' is enabled. michael@0: */ michael@0: #define BT_LOGD(msg, ...) \ michael@0: do { \ michael@0: if (gBluetoothDebugFlag) { \ michael@0: __android_log_print(ANDROID_LOG_INFO, "GeckoBluetooth", \ michael@0: "%s: " msg, __FUNCTION__, ##__VA_ARGS__); \ michael@0: } \ michael@0: } while(0) michael@0: michael@0: /** michael@0: * Prints 'R'ELEASE build logs, which show in both RELEASE and DEBUG builds. michael@0: */ michael@0: #define BT_LOGR(msg, ...) \ michael@0: __android_log_print(ANDROID_LOG_INFO, "GeckoBluetooth", \ michael@0: "%s: " msg, __FUNCTION__, ##__VA_ARGS__) \ michael@0: michael@0: /** michael@0: * Prints DEBUG build warnings, which show in DEBUG build only. michael@0: */ michael@0: #define BT_WARNING(args...) \ michael@0: NS_WARNING(nsPrintfCString(args).get()) \ michael@0: michael@0: #else michael@0: #define BT_LOGD(msg, ...) \ michael@0: do { \ michael@0: if (gBluetoothDebugFlag) { \ michael@0: printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__); \ michael@0: } \ michael@0: } while(0) michael@0: michael@0: #define BT_LOGR(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__)) michael@0: #define BT_WARNING(msg, ...) printf("%s: " msg, __FUNCTION__, ##__VA_ARGS__)) michael@0: #endif michael@0: michael@0: /** michael@0: * Wrap literal name and value into a BluetoothNamedValue michael@0: * and append it to the array. michael@0: */ michael@0: #define BT_APPEND_NAMED_VALUE(array, name, value) \ michael@0: array.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING(name), value)) michael@0: michael@0: /** michael@0: * Ensure success of system message broadcast with void return. michael@0: */ michael@0: #define BT_ENSURE_TRUE_VOID_BROADCAST_SYSMSG(type, parameters) \ michael@0: do { \ michael@0: if (!BroadcastSystemMessage(type, parameters)) { \ michael@0: BT_WARNING("Failed to broadcast [%s]", \ michael@0: NS_ConvertUTF16toUTF8(type).get()); \ michael@0: return; \ michael@0: } \ michael@0: } while(0) michael@0: michael@0: #define BEGIN_BLUETOOTH_NAMESPACE \ michael@0: namespace mozilla { namespace dom { namespace bluetooth { michael@0: #define END_BLUETOOTH_NAMESPACE \ michael@0: } /* namespace bluetooth */ } /* namespace dom */ } /* namespace mozilla */ michael@0: #define USING_BLUETOOTH_NAMESPACE \ michael@0: using namespace mozilla::dom::bluetooth; michael@0: michael@0: #define KEY_LOCAL_AGENT "/B2G/bluetooth/agent" michael@0: #define KEY_REMOTE_AGENT "/B2G/bluetooth/remote_device_agent" michael@0: #define KEY_MANAGER "/B2G/bluetooth/manager" michael@0: #define KEY_ADAPTER "/B2G/bluetooth/adapter" michael@0: michael@0: /** michael@0: * When the connection status of a Bluetooth profile is changed, we'll notify michael@0: * observers which register the following topics. michael@0: */ michael@0: #define BLUETOOTH_A2DP_STATUS_CHANGED_ID "bluetooth-a2dp-status-changed" michael@0: #define BLUETOOTH_HFP_STATUS_CHANGED_ID "bluetooth-hfp-status-changed" michael@0: #define BLUETOOTH_HID_STATUS_CHANGED_ID "bluetooth-hid-status-changed" michael@0: #define BLUETOOTH_SCO_STATUS_CHANGED_ID "bluetooth-sco-status-changed" michael@0: michael@0: /** michael@0: * When the connection status of a Bluetooth profile is changed, we'll michael@0: * dispatch one of the following events. michael@0: */ michael@0: #define A2DP_STATUS_CHANGED_ID "a2dpstatuschanged" michael@0: #define HFP_STATUS_CHANGED_ID "hfpstatuschanged" michael@0: #define SCO_STATUS_CHANGED_ID "scostatuschanged" michael@0: michael@0: /** michael@0: * When the pair status of a Bluetooth device is changed, we'll dispatch an michael@0: * event. michael@0: */ michael@0: #define PAIRED_STATUS_CHANGED_ID "pairedstatuschanged" michael@0: michael@0: /** michael@0: * When receiving a query about current play status from remote device, we'll michael@0: * dispatch an event. michael@0: */ michael@0: #define REQUEST_MEDIA_PLAYSTATUS_ID "requestmediaplaystatus" michael@0: michael@0: // Bluetooth address format: xx:xx:xx:xx:xx:xx (or xx_xx_xx_xx_xx_xx) michael@0: #define BLUETOOTH_ADDRESS_LENGTH 17 michael@0: #define BLUETOOTH_ADDRESS_NONE "00:00:00:00:00:00" michael@0: #define BLUETOOTH_ADDRESS_BYTES 6 michael@0: michael@0: // Bluetooth stack internal error, such as I/O error michael@0: #define ERR_INTERNAL_ERROR "InternalError" michael@0: michael@0: BEGIN_BLUETOOTH_NAMESPACE michael@0: michael@0: enum BluetoothSocketType { michael@0: RFCOMM = 1, michael@0: SCO = 2, michael@0: L2CAP = 3, michael@0: EL2CAP = 4 michael@0: }; michael@0: michael@0: class BluetoothSignal; michael@0: typedef mozilla::Observer BluetoothSignalObserver; michael@0: michael@0: // Enums for object types, currently used for shared function lookups michael@0: // (get/setproperty, etc...). Possibly discernable via dbus paths, but this michael@0: // method is future-proofed for platform independence. michael@0: enum BluetoothObjectType { michael@0: TYPE_MANAGER = 0, michael@0: TYPE_ADAPTER = 1, michael@0: TYPE_DEVICE = 2, michael@0: michael@0: TYPE_INVALID michael@0: }; michael@0: michael@0: enum ControlPlayStatus { michael@0: PLAYSTATUS_STOPPED = 0x00, michael@0: PLAYSTATUS_PLAYING = 0x01, michael@0: PLAYSTATUS_PAUSED = 0x02, michael@0: PLAYSTATUS_FWD_SEEK = 0x03, michael@0: PLAYSTATUS_REV_SEEK = 0x04, michael@0: PLAYSTATUS_UNKNOWN, michael@0: PLAYSTATUS_ERROR = 0xFF, michael@0: }; michael@0: michael@0: END_BLUETOOTH_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_bluetooth_bluetoothcommon_h__