Bug 711601 - Bluetooth Implementation on B2G - patch 1: Boilerplate code for creating navigator.mozBluetooth object. r=bent

This commit is contained in:
Kyle Machulis 2012-02-14 17:51:52 -08:00
parent 68b5985a34
commit 55bf17714a
19 changed files with 260 additions and 0 deletions

View File

@ -151,6 +151,9 @@
@BINPATH@/components/dom_system_b2g.xpt
#endif
@BINPATH@/components/dom_battery.xpt
#ifdef MOZ_B2G_BT
@BINPATH@/components/dom_bluetooth.xpt
#endif
@BINPATH@/components/dom_canvas.xpt
@BINPATH@/components/dom_core.xpt
@BINPATH@/components/dom_css.xpt

View File

@ -150,6 +150,9 @@
@BINPATH@/components/dom_system_b2g.xpt
#endif
@BINPATH@/components/dom_battery.xpt
#ifdef MOZ_B2G_BT
@BINPATH@/components/dom_bluetooth.xpt
#endif
@BINPATH@/components/dom_canvas.xpt
@BINPATH@/components/dom_core.xpt
@BINPATH@/components/dom_css.xpt

View File

@ -293,6 +293,7 @@ MOZ_NATIVE_NSPR = @MOZ_NATIVE_NSPR@
MOZ_NATIVE_NSS = @MOZ_NATIVE_NSS@
MOZ_B2G_RIL = @MOZ_B2G_RIL@
MOZ_B2G_BT = @MOZ_B2G_BT@
BUILD_CTYPES = @BUILD_CTYPES@

View File

@ -4920,6 +4920,7 @@ cairo-gonk)
MOZ_PDF_PRINTING=1
MOZ_B2G_RIL=1
MOZ_TOUCH=1
MOZ_B2G_BT=1
;;
esac
@ -7590,6 +7591,18 @@ if test -n "$MOZ_B2G_RIL"; then
fi
AC_SUBST(MOZ_B2G_RIL)
dnl ========================================================
dnl = Enable Bluetooth Interface for B2G (Gonk usually)
dnl ========================================================
MOZ_ARG_ENABLE_BOOL(b2g-bt,
[ --enable-b2g-bt Set compile flags necessary for compiling Bluetooth API for B2G ],
MOZ_B2G_BT=1,
MOZ_B2G_BT= )
if test -n "$MOZ_B2G_BT"; then
AC_DEFINE(MOZ_B2G_BT)
fi
AC_SUBST(MOZ_B2G_BT)
dnl ========================================================
dnl = Support for demangling undefined symbols
dnl ========================================================

View File

@ -97,6 +97,11 @@ DIRS += \
$(NULL)
endif
ifdef MOZ_B2G_BT
DIRS += \
bluetooth \
$(NULL)
endif
TEST_DIRS += tests
ifneq (,$(filter gtk2 cocoa windows android qt os2,$(MOZ_WIDGET_TOOLKIT)))
TEST_DIRS += plugins/test

View File

@ -80,6 +80,10 @@
#ifdef MOZ_B2G_RIL
#include "TelephonyFactory.h"
#endif
#ifdef MOZ_B2G_BT
#include "nsIDOMBluetoothAdapter.h"
#include "BluetoothAdapter.h"
#endif
// This should not be in the namespace.
DOMCI_DATA(Navigator, mozilla::dom::Navigator)
@ -133,6 +137,9 @@ NS_INTERFACE_MAP_BEGIN(Navigator)
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorTelephony)
#endif
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorNetwork)
#ifdef MOZ_B2G_BT
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorBluetooth)
#endif
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Navigator)
NS_INTERFACE_MAP_END
@ -182,6 +189,12 @@ Navigator::Invalidate()
mConnection->Shutdown();
mConnection = nsnull;
}
#ifdef MOZ_B2G_BT
if (mBluetooth) {
mBluetooth = nsnull;
}
#endif
}
nsPIDOMWindow *
@ -1112,6 +1125,30 @@ Navigator::GetMozConnection(nsIDOMMozConnection** aConnection)
return NS_OK;
}
#ifdef MOZ_B2G_BT
//*****************************************************************************
// nsNavigator::nsIDOMNavigatorBluetooth
//*****************************************************************************
NS_IMETHODIMP
Navigator::GetMozBluetooth(nsIDOMBluetoothAdapter** aBluetooth)
{
nsCOMPtr<nsIDOMBluetoothAdapter> bluetooth = mBluetooth;
if (!bluetooth) {
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
mBluetooth = new bluetooth::BluetoothAdapter();
bluetooth = mBluetooth;
}
bluetooth.forget(aBluetooth);
return NS_OK;
}
#endif //MOZ_B2G_BT
PRInt64
Navigator::SizeOf() const
{

View File

@ -65,6 +65,11 @@ class nsIDOMMozConnection;
class nsIDOMTelephony;
#endif
#ifdef MOZ_B2G_BT
#include "nsIDOMNavigatorBluetooth.h"
#endif
class nsIDOMAdapter;
//*****************************************************************************
// Navigator: Script "navigator" object
//*****************************************************************************
@ -98,6 +103,9 @@ class Navigator : public nsIDOMNavigator
, public nsIDOMNavigatorTelephony
#endif
, public nsIDOMMozNavigatorNetwork
#ifdef MOZ_B2G_BT
, public nsIDOMNavigatorBluetooth
#endif
{
public:
Navigator(nsPIDOMWindow *aInnerWindow);
@ -115,6 +123,10 @@ public:
#endif
NS_DECL_NSIDOMMOZNAVIGATORNETWORK
#ifdef MOZ_B2G_BT
NS_DECL_NSIDOMNAVIGATORBLUETOOTH
#endif
static void Init();
void Invalidate();
@ -146,6 +158,9 @@ private:
nsCOMPtr<nsIDOMTelephony> mTelephony;
#endif
nsRefPtr<network::Connection> mConnection;
#ifdef MOZ_B2G_BT
nsCOMPtr<nsIDOMBluetoothAdapter> mBluetooth;
#endif
nsWeakPtr mWindow;
};

View File

@ -532,6 +532,10 @@ using mozilla::dom::indexedDB::IDBWrapperCache;
#include "CallEvent.h"
#endif
#ifdef MOZ_B2G_BT
#include "BluetoothAdapter.h"
#endif
#include "DOMError.h"
using namespace mozilla;
@ -1627,6 +1631,11 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#endif
#ifdef MOZ_B2G_BT
NS_DEFINE_CLASSINFO_DATA(BluetoothAdapter, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#endif
NS_DEFINE_CLASSINFO_DATA(DOMError, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
};
@ -2423,6 +2432,9 @@ nsDOMClassInfo::Init()
#endif
DOM_CLASSINFO_MAP_CONDITIONAL_ENTRY(nsIDOMMozNavigatorNetwork,
network::IsAPIEnabled())
#ifdef MOZ_B2G_BT
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorBluetooth)
#endif
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(Plugin, nsIDOMPlugin)
@ -4365,6 +4377,12 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_END
#endif
#ifdef MOZ_B2G_BT
DOM_CLASSINFO_MAP_BEGIN(BluetoothAdapter, nsIDOMBluetoothAdapter)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothAdapter)
DOM_CLASSINFO_MAP_END
#endif
DOM_CLASSINFO_MAP_BEGIN(DOMError, nsIDOMDOMError)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMError)
DOM_CLASSINFO_MAP_END

View File

@ -540,4 +540,8 @@ DOMCI_CLASS(TelephonyCall)
DOMCI_CLASS(CallEvent)
#endif
#ifdef MOZ_B2G_BT
DOMCI_CLASS(BluetoothAdapter)
#endif
DOMCI_CLASS(DOMError)

View File

@ -0,0 +1,39 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* 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/. */
#include "BluetoothAdapter.h"
#include "nsDOMClassInfo.h"
USING_BLUETOOTH_NAMESPACE
BluetoothAdapter::BluetoothAdapter() : mPower(false)
{
}
NS_INTERFACE_MAP_BEGIN(BluetoothAdapter)
NS_INTERFACE_MAP_ENTRY(nsIDOMBluetoothAdapter)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BluetoothAdapter)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(BluetoothAdapter)
NS_IMPL_RELEASE(BluetoothAdapter)
DOMCI_DATA(BluetoothAdapter, BluetoothAdapter)
NS_IMETHODIMP
BluetoothAdapter::GetPower(bool* aPower)
{
*aPower = mPower;
return NS_OK;
}
NS_IMETHODIMP
BluetoothAdapter::SetPower(bool aPower)
{
mPower = aPower;
return NS_OK;
}

View File

@ -0,0 +1,28 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* 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_bluetoothadapter_h__
#define mozilla_dom_bluetooth_bluetoothadapter_h__
#include "BluetoothCommon.h"
#include "nsIDOMBluetoothAdapter.h"
BEGIN_BLUETOOTH_NAMESPACE
class BluetoothAdapter : public nsIDOMBluetoothAdapter
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMBLUETOOTHADAPTER
BluetoothAdapter();
protected:
bool mPower;
};
END_BLUETOOTH_NAMESPACE
#endif

View File

@ -0,0 +1,19 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* 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_bluetoothcommon_h__
#define mozilla_dom_bluetooth_bluetoothcommon_h__
#define BEGIN_BLUETOOTH_NAMESPACE \
namespace mozilla { namespace dom { namespace bluetooth {
#define END_BLUETOOTH_NAMESPACE \
} /* namespace bluetooth */ } /* namespace dom */ } /* namespace mozilla */
#define USING_BLUETOOTH_NAMESPACE \
using namespace mozilla::dom::bluetooth;
class nsIDOMBluetooth;
#endif // mozilla_dom_bluetooth_bluetoothcommon_h__

30
dom/bluetooth/Makefile.in Normal file
View File

@ -0,0 +1,30 @@
# 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/.
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = dom
LIBRARY_NAME = dombluetooth_s
XPIDL_MODULE = dom_bluetooth
LIBXUL_LIBRARY = 1
FORCE_STATIC_LIB = 1
include $(topsrcdir)/dom/dom-config.mk
CPPSRCS = \
BluetoothAdapter.cpp \
$(NULL)
XPIDLSRCS = \
nsIDOMNavigatorBluetooth.idl \
nsIDOMBluetoothAdapter.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,13 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* 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/. */
#include "nsISupports.idl"
[scriptable, builtinclass, uuid(29689a22-45ff-4ccf-b552-5364ce3a3642)]
interface nsIDOMBluetoothAdapter : nsISupports
{
attribute boolean power;
};

View File

@ -0,0 +1,15 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* 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/. */
#include "nsISupports.idl"
interface nsIDOMBluetoothAdapter;
[scriptable, uuid(677f2c2d-c4d1-41ea-addc-21d30d0d3858)]
interface nsIDOMNavigatorBluetooth : nsISupports
{
readonly attribute nsIDOMBluetoothAdapter mozBluetooth;
};

View File

@ -31,5 +31,9 @@ DOM_SRCDIRS += \
$(NULL)
endif
ifdef MOZ_B2G_BT
DOM_SRCDIRS += dom/bluetooth
endif
LOCAL_INCLUDES += $(DOM_SRCDIRS:%=-I$(topsrcdir)/%)
DEFINES += -D_IMPL_NS_LAYOUT

View File

@ -148,6 +148,10 @@ LOCAL_INCLUDES += \
$(NULL)
endif
ifdef MOZ_B2G_BT #{
SHARED_LIBRARY_LIBS += $(DEPTH)/dom/bluetooth/$(LIB_PREFIX)dombluetooth_s.$(LIB_SUFFIX)
endif #}
ifdef MOZ_B2G_RIL #{
SHARED_LIBRARY_LIBS += $(DEPTH)/dom/system/b2g/$(LIB_PREFIX)domsystemb2g_s.$(LIB_SUFFIX)
endif #}
@ -272,5 +276,8 @@ ifdef MOZ_B2G_RIL #{
LOCAL_INCLUDES += -I$(topsrcdir)/dom/system/b2g
endif #}
ifdef MOZ_B2G_BT #{
LOCAL_INCLUDES += -I$(topsrcdir)/dom/bluetooth
endif #}
DEFINES += -D_IMPL_NS_LAYOUT

View File

@ -157,6 +157,9 @@
@BINPATH@/components/dom_system_b2g.xpt
#endif
@BINPATH@/components/dom_battery.xpt
#ifdef MOZ_B2G_BT
@BINPATH@/components/dom_bluetooth.xpt
#endif
@BINPATH@/components/dom_canvas.xpt
@BINPATH@/components/dom_core.xpt
@BINPATH@/components/dom_css.xpt

View File

@ -398,6 +398,9 @@ OS_LIBS += \
-lbinder \
-lsensorservice \
$(NULL)
ifdef MOZ_B2G_BT
OS_LIBS += -lbluedroid
endif
endif
EXTRA_DEPS += \