# HG changeset patch # User hgs # Date 1272886567 -10800 # Node ID 48ae3789ce0023ca5e8d79b527c3eadc8cdfdb6d # Parent 7e2761e776bd66e0664291ed5b3c30e53ff829e0 201017_2 diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/bteng/btengconnman/inc/btengpairinghandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/bteng/btengconnman/inc/btengpairinghandler.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,155 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Bluetooth Engine API for connection management functionality. +* +*/ + +#ifndef BTENGPAIRINGHANDLER_H +#define BTENGPAIRINGHANDLER_H + +#include +#include + +#include "btengactive.h" + +class CBTEngConnMan; +class MBTEngConnObserver; + + +/** + * ?one_line_short_description + * + * ?more_complete_description + * + * @lib ?library + * @since S60 v3.2 + */ +NONSHARABLE_CLASS( CBTEngPairingHandler ) : public CBase, public MBTEngActiveObserver + { + +public: + + /** + * Two-phase constructor + */ + static CBTEngPairingHandler* NewL( MBTEngConnObserver* aObserver, + CBTEngConnMan* aParent ); + + /** + * Destructor + */ + virtual ~CBTEngPairingHandler(); + + /** + * ?description + * + * @since S60 v3.2 + * @param ?arg1 ?description + * @param ?arg2 ?description + * @return ?description + */ + void StartPairingL( const TBTDevAddr& aAddr, TBTDeviceClass& aDeviceClass ); + + /** + * ?description + * + * @since S60 v3.2 + * @param ?arg1 ?description + * @param ?arg2 ?description + * @return ?description + */ + void CancelPairing(); + +// from base class MBTEngActiveObserver + + /** + * From MBTEngActiveObserver. + * ?description + * + * @since S60 v3.2 + * @param ?arg1 ?description + */ + virtual void RequestCompletedL( CBTEngActive* aActive, + TInt aStatus ); + + /** + * Callback for handling cancelation of an outstanding request. + * + * @param aId The ID that identifies the outstanding request. + */ + virtual void CancelRequest( TInt aRequestId ); + + /** + * From MBTEngActiveObserver. + * ?description + * + * @since S60 v3.2 + * @param ?arg1 ?description + */ + virtual void HandleError( CBTEngActive* aActive, + TInt aError ); + +private: + + /** + * C++ default constructor + */ + CBTEngPairingHandler( MBTEngConnObserver* aObserver, + CBTEngConnMan* aParent ); + + /** + * Symbian 2nd-phase constructor + */ + void ConstructL(); + +private: // data + + /** + * the address of the remote device to be paired. + */ + TBTDevAddrPckgBuf iAddr; + + /** + * the class of device value of the remote device to be paired. + */ + TBTDeviceClass iCod; + + /** + * the session to notifier which handles the actual pairing operation. + * Own. + */ + RBTNotifier iBtNotifier; + + /** + * Active object for pairing request + * Own. + */ + CBTEngActive* iActive; + + /** + * the observer that receives the result of pairing operation. + * Not own. + */ + MBTEngConnObserver* iObserver; + + /** + * ?description_of_pointer_member + * Not own. + */ + CBTEngConnMan* iParent; + + }; + + +#endif // BTENGPAIRINGHANDLER_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/bteng/btengconnman/src/btengpairinghandler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/bteng/btengconnman/src/btengpairinghandler.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,152 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Implementation of pairing a Bluetooth device. +* +*/ +#include "btengpairinghandler.h" +#include "btengconnman.h" +#include "btengactive.h" +#include "debug.h" + +const TInt KPairingRequestId = 60; + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTEngPairingHandler::CBTEngPairingHandler( MBTEngConnObserver* aObserver, + CBTEngConnMan* aParent ) +: iObserver( aObserver ), + iParent( aParent ) + { + } + + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTEngPairingHandler::ConstructL() + { + ASSERT( iObserver ); + iActive = CBTEngActive::NewL( *this, KPairingRequestId, + CActive::EPriorityStandard ); + } + + +// --------------------------------------------------------------------------- +// NewL +// --------------------------------------------------------------------------- +// +CBTEngPairingHandler* CBTEngPairingHandler::NewL( MBTEngConnObserver* aObserver, + CBTEngConnMan* aParent ) + { + CBTEngPairingHandler* self = new( ELeave ) CBTEngPairingHandler( aObserver, + aParent ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTEngPairingHandler::~CBTEngPairingHandler() + { + delete iActive; + iBtNotifier.Close(); + } + +// --------------------------------------------------------------------------- +// ?implementation_description +// --------------------------------------------------------------------------- +// +void CBTEngPairingHandler::StartPairingL( const TBTDevAddr& aAddr, + TBTDeviceClass& aDeviceClass ) + { + TRACE_FUNC_ENTRY + if ( !iBtNotifier.Handle() ) + { + User::LeaveIfError( iBtNotifier.Connect() ); + } + iAddr() = aAddr; + iCod = aDeviceClass; + iBtNotifier.PairDevice( iAddr, iCod.DeviceClass(), iActive->RequestStatus() ); + iActive->GoActive(); + TRACE_FUNC_EXIT + } + +// --------------------------------------------------------------------------- +// Cancel a pairing request. +// --------------------------------------------------------------------------- +// +void CBTEngPairingHandler::CancelPairing() + { + TRACE_FUNC_ENTRY + if( iActive->IsActive() ) + { + iBtNotifier.CancelPairDevice(); + iActive->Cancel(); + } + } + +// --------------------------------------------------------------------------- +// From class MBTEngActiveObserver. +// ?implementation_description +// --------------------------------------------------------------------------- +// +void CBTEngPairingHandler::RequestCompletedL( CBTEngActive* aActive, + TInt aStatus ) + { + TRACE_FUNC_ARG( ( _L( "status: %d" ), aStatus ) ) + ASSERT( aActive->RequestId() != 0 ); + (void) aActive; + // Pairing completes, inform client. + iObserver->PairingComplete( iAddr(), aStatus ); + TRACE_FUNC_EXIT + } + +// --------------------------------------------------------------------------- +// From class MBTEngActiveObserver. +// Handles cancelation of an outstanding request +// --------------------------------------------------------------------------- +// +void CBTEngPairingHandler::CancelRequest( TInt aRequestId ) + { + TRACE_FUNC_ARG( ( _L( "reqID %d" ), aRequestId ) ); + if ( aRequestId == KPairingRequestId ) + { + iBtNotifier.CancelPairDevice(); + } + TRACE_FUNC_EXIT + } + +// --------------------------------------------------------------------------- +// From class MBTEngActiveObserver. +// ?implementation_description +// --------------------------------------------------------------------------- +// +void CBTEngPairingHandler::HandleError( CBTEngActive* aActive, + TInt aError ) + { + // Our RunL can actually not leave, so we should never reach here. + (void) aActive; + (void) aError; + } + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.pro Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,64 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: Global confirmation query notification plugin +# + +TEMPLATE = lib +TARGET = btdevicedialogplugin +CONFIG += hb plugin +INCLUDEPATH += . ../inc +DEPENDPATH += . +DESTDIR = $${HB_BUILD_DIR}/plugins/devicedialogs + +MOC_DIR = moc +OBJECTS_DIR = obj + +# dependencies +HEADERS += inc/btdevicedialoginputwidget.h \ + inc/btdevicedialogquerywidget.h \ + inc/btdevicedialognotifwidget.h \ + inc/btdevicedialogpluginerrors.h \ + inc/btdevicedialogplugin.h \ + inc/btdevicesearchdialogwidget.h \ + inc/btdevicedialogplugintrace.h + +SOURCES += src/btdevicedialogplugin.cpp \ + src/btdevicedialoginputwidget.cpp \ + src/btdevicedialogquerywidget.cpp \ + src/btdevicedialognotifwidget.cpp \ + src/btdevicesearchdialogwidget.cpp + +RESOURCES += btdevicedialogplugin.qrc + +symbian: { + SYMBIAN_PLATFORMS = WINSCW ARMV5 + TARGET.EPOCALLOWDLLDATA = 1 + TARGET.CAPABILITY = CAP_GENERAL_DLL + TARGET.UID3 = 0x2002E6DF + hblib.sources = Hb.dll + hblib.path = \sys\bin + hblib.depends = "(0xEEF9EA38), 1, 0, 0, {\"Hb\"}" + pluginstub.sources = btdevicedialogplugin.dll + pluginstub.path = /resource/plugins/devicedialogs + DEPLOYMENT += pluginstub +} +!local { + target.path = $${HB_PLUGINS_DIR}/devicedialogs + INSTALLS += target +} + +BLD_INF_RULES.prj_exports += \ + "$${LITERAL_HASH}include " \ + "rom/btdevicedialogplugin.iby CORE_MW_LAYER_IBY_EXPORT_PATH(btdevicedialogplugin.iby)" \ + "qmakepluginstubs/btdevicedialogplugin.qtplugin /epoc32/data/z/pluginstub/btdevicedialogplugin.qtplugin" diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.qrc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/btdevicedialogplugin.qrc Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,6 @@ + + + docml/bt-device-search-dialog.docml + icons/qgn_prop_sml_bt.svg + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-device-search-dialog.docml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/docml/bt-device-search-dialog.docml Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/icons/qgn_prop_sml_bt.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/icons/qgn_prop_sml_bt.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialoginputwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialoginputwidget.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: BtDeviceDialogWidget class declaration. +* +*/ + + +#ifndef BTDEVICEDIALOGINPUTWIDGET_H +#define BTDEVICEDIALOGINPUTWIDGET_H + +#include + +#include +#include +#include + +/*! + \class BtDeviceDialogInputWidget + \brief Widget class with properties setting. + + BtDeviceDialogInputWidget, inherited from HbInputDialog, + implements interface HbDeviceDialogInterface. The Q_Properties + here are interfaces for caller of HbDeviceDialog to configue + what to be shown in the widget. + + */ +class BtDeviceDialogInputWidget : + public QObject, public HbDeviceDialogInterface +{ + Q_OBJECT + +public: + BtDeviceDialogInputWidget(const QVariantMap ¶meters); + + // From base class HbDeviceDialogInterface + virtual bool setDeviceDialogParameters(const QVariantMap ¶meters); + virtual int deviceDialogError() const; + virtual void closeDeviceDialog(bool byClient); + virtual HbDialog *deviceDialogWidget() const; + virtual QObject *signalSender() const; + +signals: + // Required by the framework + void deviceDialogClosed(); + void deviceDialogData(QVariantMap data); + +public slots: + void inputClosed(HbAction *action); + +private: + void processParam(const QVariantMap ¶meters); + bool constructInputDialog(const QVariantMap ¶meters); + void resetProperties(); + +private: + Q_DISABLE_COPY(BtDeviceDialogInputWidget) + + int mLastError; + int mSendAction; + bool mShowEventReceived; + HbInputDialog *mInputDialog; +}; + +#endif // BTDEVICEDIALOGINPUTWIDGET_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialognotifwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialognotifwidget.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: BtDeviceDialogWidget class declaration. +* +*/ + + +#ifndef BTDEVICEDIALOGNOTIFWIDGET_H +#define BTDEVICEDIALOGNOTIFWIDGET_H + +#include + +#include +#include +#include + +/*! + \class BtDeviceDialogQueryWidget + \brief Widget class with properties setting. + + BtDeviceDialogQueryWidget, inherited from HbNotificationDialog, + implements interface HbDeviceDialogInterface. The Q_Properties + here are interfaces for caller of HbDeviceDialog to configue + what to be shown in the widget. + + */ +class BtDeviceDialogNotifWidget : + public HbNotificationDialog, public HbDeviceDialogInterface +{ + Q_OBJECT + +public: + BtDeviceDialogNotifWidget(const QVariantMap ¶meters); + + // From base class HbDeviceDialogInterface + virtual bool setDeviceDialogParameters(const QVariantMap ¶meters); + virtual int deviceDialogError() const; + virtual void closeDeviceDialog(bool byClient); + virtual HbDialog *deviceDialogWidget() const; + +signals: + // Required by the framework + void deviceDialogClosed(); + +private: + void processParam(const QVariantMap ¶meters); + bool constructQueryDialog(const QVariantMap ¶meters); + void resetProperties(); + + // From base HbInputDialog, reimplement and emit signals. + void hideEvent(QHideEvent *event); + void showEvent(QShowEvent *event); + +private: + Q_DISABLE_COPY(BtDeviceDialogNotifWidget) + + int mLastError; + int mSendAction; + bool mShowEventReceived; +}; + +#endif // BTDEVICEDIALOGNOTIFWIDGET_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogplugin.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogplugin.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: BtDeviceDialogPlugin class declaration. +* +*/ + + +#ifndef BTDEVICEDIALOGPLUGIN_P_H +#define BTDEVICEDIALOGPLUGIN_P_H + +#include +#include + +#include + +// Forward declarations +class BtDeviceDialogPluginPrivate; + +/*! + \class BtDeviceDialogPlugin + \brief Device dialog widget plugin providing generic input dialog. + + BtDeviceDialogPlugin implements interface HbDeviceDialogPlugin and + creates device dialog widget, which allows user's input. + Currently this plugin implements only one dialog type, identified by + "com.nokia.hb.btdevicedialog/1.0". + + ToDo: create widget base on dialog types when multiple dialog types available. + */ +class BtDeviceDialogPlugin : public HbDeviceDialogPlugin +{ + Q_OBJECT + +public: + friend class BtDeviceDialogPluginPrivate; + + BtDeviceDialogPlugin(); + ~BtDeviceDialogPlugin(); + + // from base HbDeviceDialogPluginInterface + virtual HbDeviceDialogInterface *createDeviceDialog(const QString &deviceDialogType, + const QVariantMap ¶meters); + + // from base HbDeviceDialogPlugin + virtual bool accessAllowed(const QString &deviceDialogType, + const QVariantMap ¶meters, const QVariantMap &securityInfo) const; + virtual bool deviceDialogInfo(const QString &deviceDialogType, + const QVariantMap ¶meters, DeviceDialogInfo *info) const; + virtual QStringList deviceDialogTypes() const; + virtual PluginFlags pluginFlags() const; + virtual int error() const; + +private: + HbDeviceDialogInterface *checkDialogType( const QVariantMap ¶meters ); + +private: + Q_DISABLE_COPY(BtDeviceDialogPlugin) + BtDeviceDialogPluginPrivate *d; +}; + +#endif // BTDEVICEDIALOGPLUGIN_P_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogpluginerrors.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogpluginerrors.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Plugin error constants +* +*/ + +#ifndef BTDEVICEDIALOGPLUGINERRORS_H +#define BTDEVICEDIALOGPLUGINERRORS_H + +#include + +// No error +const int NoError = 0; +// Illegal parameter error +const int ParameterError = HbDeviceDialog::PluginErrors + 1; +// Unknown device dialog error +const int UnknownDeviceDialogError = HbDeviceDialog::PluginErrors + 2; + +#endif // BTDEVICEDIALOGPLUGINERRORS_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogplugintrace.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogplugintrace.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Tracing macros +* +*/ + +#ifndef BTDEVICEDIALOGPLUGINTRACE_H +#define BTDEVICEDIALOGPLUGINTRACE_H + +#include // QDebug +#include // qDebug() + + +#ifdef ENABLE_TRACE_OUTPUT + #define INSTALL_MESSAGE_HANDLER HbDeviceDialogMessageHandler::installMessageHandler(QString(TRACE_OUTPUT_FILE), TRACE_OUTPUT_FILE_REQUIRED); + #define UNINSTALL_MESSAGE_HANDLER HbDeviceDialogMessageHandler::uninstallMessageHandler(); + #define TRACE_UNUSED(name) + #define TRACE_STATIC_ENTRY qDebug() << __PRETTY_FUNCTION__ << "entry"; + #define TRACE_STATIC_ENTRY_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "entry," << args; + #define TRACE_ENTRY qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this << "entry"; + #define TRACE_ENTRY_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this << "entry," << args; + #define TRACE_EXIT qDebug() << __PRETTY_FUNCTION__ << "exit"; + #define TRACE_EXIT_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "exit," << args; + #define TRACE(args) qDebug() << __PRETTY_FUNCTION__ << args; +#else + #define INSTALL_MESSAGE_HANDLER + #define UNINSTALL_MESSAGE_HANDLER + #define TRACE_UNUSED(name) Q_UNUSED(name) + #define TRACE_STATIC_ENTRY + #define TRACE_STATIC_ENTRY_ARGS(args) + #define TRACE_ENTRY + #define TRACE_ENTRY_ARGS(args) + #define TRACE_EXIT + #define TRACE_EXIT_ARGS(args) + #define TRACE(args) +#endif // ENABLE_TRACE_OUTPUT + +#endif // BTDEVICEDIALOGPLUGINTRACE_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogquerywidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicedialogquerywidget.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: BtDeviceDialogWidget class declaration. +* +*/ + + +#ifndef BTDEVICEDIALOGQUERYWIDGET_H +#define BTDEVICEDIALOGQUERYWIDGET_H + +#include + +#include +#include +#include + +/*! + \class BtDeviceDialogQueryWidget + \brief Widget class with properties setting. + + BtDeviceDialogQueryWidget, inherited from HbMessageBox, + implements interface HbDeviceDialogInterface. The Q_Properties + here are interfaces for caller of HbDeviceDialog to configue + what to be shown in the widget. + + */ +class BtDeviceDialogQueryWidget : + public QObject, public HbDeviceDialogInterface +{ + Q_OBJECT + +public: + BtDeviceDialogQueryWidget(HbMessageBox::MessageBoxType type, const QVariantMap ¶meters); + + // From base class HbDeviceDialogInterface + virtual bool setDeviceDialogParameters(const QVariantMap ¶meters); + virtual int deviceDialogError() const; + virtual void closeDeviceDialog(bool byClient); + virtual HbDialog *deviceDialogWidget() const; + virtual QObject *signalSender() const; + +signals: + // Required by the framework + void deviceDialogClosed(); + void deviceDialogData(QVariantMap data); + +public slots: + void messageBoxClosed(HbAction*); + +private: + void processParam(const QVariantMap ¶meters); + bool constructQueryDialog(const QVariantMap ¶meters); + void resetProperties(); + +private: + Q_DISABLE_COPY(BtDeviceDialogQueryWidget) + + int mLastError; + int mSendAction; + bool mShowEventReceived; + + HbMessageBox *mMessageBox; +}; + +#endif // BTDEVICEDIALOGQUERYWIDGET_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicesearchdialogwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/inc/btdevicesearchdialogwidget.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + + +#ifndef BTDEVICESEARCHDIALOGWIDGET_H +#define BTDEVICESEARCHDIALOGWIDGET_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +struct device + { + QString mDeviceName; + QString mDeviceType; + int mDeviceIdx; + }; + +class BTDeviceSearchDialogWidget : public HbDialog, + public HbDeviceDialogInterface + { + Q_OBJECT + +public: + BTDeviceSearchDialogWidget(const QVariantMap ¶meters); + ~BTDeviceSearchDialogWidget(); + +public: // from HbDeviceDialogInterface + bool setDeviceDialogParameters(const QVariantMap ¶meters); + int deviceDialogError() const; + void closeDeviceDialog(bool byClient); + HbPopup *deviceDialogWidget() const; + +public slots: + void stopClicked(); + void retryClicked(); +// void viewByClicked(); + void deviceSelected(const QModelIndex& modelIndex); +// void viewByItemSelected(int index); + +private: + bool constructDialog(const QVariantMap ¶meters); + void hideEvent(QHideEvent *event); + void showEvent(QShowEvent *event); + void appendToDeviceList(const QString deviceName); + bool appendToDeviceTypeList(const QString deviceType); + QIcon icon(); + +signals: + void deviceDialogClosed(); + void deviceDialogData(QVariantMap data); + +private: + HbDocumentLoader *mLoader; + + /** + * + * item model for content list view. + */ + + QStandardItemModel* mContentItemModel; + HbDialog* mViewByDialog; + HbRadioButtonList* mRbl; + QList mDeviceTypeList; + QList mDeviceList; + HbListView* mListView; + bool mViewByChosen; + QList mDeviceLstOfType; + int mDeviceLstIdx; + int mSelectedType; + int mDeviceDialogData; + + Q_DISABLE_COPY(BTDeviceSearchDialogWidget) + }; + +#endif /* BTDEVICESEARCHDIALOGWIDGET_H */ diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/rom/btdevicedialogplugin.iby --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/rom/btdevicedialogplugin.iby Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Image description file for project btdevicedialogplugin +* +*/ + + +#ifndef BTDEVICEDIALOGPLUGIN_IBY +#define BTDEVICEDIALOGPLUGIN_IBY + +#include + +#ifdef __BT +file=ABI_DIR/BUILD_DIR/btdevicedialogplugin.dll SHARED_LIB_DIR/btdevicedialogplugin.dll +data=/epoc32/data/z/pluginstub/btdevicedialogplugin.qtplugin resource/plugins/devicedialogs/btdevicedialogplugin.qtplugin +#endif // __BT + +#endif // BTDEVICEDIALOGPLUGIN_IBY \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialoginputwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialoginputwidget.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,201 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: BtDeviceDialogWidget class implementation. +* +*/ + + +#include "btdevicedialoginputwidget.h" +#include "btdevicedialogplugintrace.h" +#include +#include +#include +#include "btdevicedialogpluginerrors.h" + +/*! + class Constructor + */ +BtDeviceDialogInputWidget::BtDeviceDialogInputWidget( + const QVariantMap ¶meters) +{ + TRACE_ENTRY + // set properties + mLastError = NoError; + mShowEventReceived = false; + mInputDialog = new HbInputDialog(); + + resetProperties(); + constructInputDialog(parameters); + TRACE_EXIT +} + +/*! + Set parameters, implementation of interface + Invoked when HbDeviceDialog::update calls. + */ +bool BtDeviceDialogInputWidget::setDeviceDialogParameters( + const QVariantMap ¶meters) +{ + TRACE_ENTRY + mLastError = NoError; + processParam(parameters); + TRACE_EXIT + return true; +} + +/*! + Get error, implementation of interface + */ +int BtDeviceDialogInputWidget::deviceDialogError() const +{ + TRACE_ENTRY + TRACE_EXIT + return mLastError; +} + +/*! + Close notification, implementation of interface + */ +void BtDeviceDialogInputWidget::closeDeviceDialog(bool byClient) +{ + TRACE_ENTRY + Q_UNUSED(byClient); + // Closed by client or internally by server -> no action to be transmitted. + mSendAction = false; + mInputDialog->close(); + // If show event has been received, close is signalled from hide event. If not, + // hide event does not come and close is signalled from here. + if (!mShowEventReceived) { + emit deviceDialogClosed(); + } + TRACE_EXIT +} + +/*! + Return display widget, implementation of interface + */ +HbDialog *BtDeviceDialogInputWidget::deviceDialogWidget() const +{ + TRACE_ENTRY + TRACE_EXIT + return mInputDialog; +} + +QObject *BtDeviceDialogInputWidget::signalSender() const +{ + return const_cast(this); +} + +/*! + Construct display widget + */ +bool BtDeviceDialogInputWidget::constructInputDialog(const QVariantMap ¶meters) +{ + TRACE_ENTRY + // analyze the parameters to compose the properties of the widget + processParam(parameters); + connect(mInputDialog, SIGNAL(finished(HbAction*)), this, SLOT(inputClosed(HbAction*))); + + TRACE_EXIT + return true; +} + +/*! + Take parameter values and generate relevant property of this widget + */ +void BtDeviceDialogInputWidget::processParam(const QVariantMap ¶meters) +{ + TRACE_ENTRY + + QString keyStr, prompt; + keyStr.setNum( TBluetoothDialogParams::EResource ); + // Validate if the resource item exists. + QVariantMap::const_iterator i = parameters.constFind( keyStr ); + // item of ResourceId is not found, can't continue. + if ( i == parameters.constEnd() ) { + mLastError = UnknownDeviceDialogError; + return; + } + + QVariant param = parameters.value( keyStr ); + if ( param.toInt() == EPinInput ) { + prompt = QString( tr( "Passcode for device %1:" ) ); + } + else { + mLastError = ParameterError; + return; + } + + // check if minLength of passcode required + keyStr.setNum( TBluetoothDeviceDialog::EAdditionalDesc ); + i = parameters.constFind( keyStr ); + // Mini Length required, update prompt + // ToDo: use Validator to check input length. + if ( i != parameters.constEnd() ) { + prompt = QString( tr( "Enter %1 digit passcode for device %2:" ) ); + param = parameters.value( keyStr ); + } + + // replace % with the miniLength and device name + int repls = prompt.count( QString( "%" ) ); + if ( repls > 1 ) { + prompt = prompt.arg( param.toString() ); + } + if ( repls > 0 ) { + QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) ); + prompt = prompt.arg( name.toString() ); + } + // set property value to this dialog widget + mInputDialog->setPromptText( prompt ); + TRACE_EXIT +} + +/*! + Reset properties to default values + */ +void BtDeviceDialogInputWidget::resetProperties() +{ + TRACE_ENTRY + // set to default values + mInputDialog->setModal(true); + mInputDialog->setTimeout(HbDialog::NoTimeout); + mInputDialog->setDismissPolicy(HbDialog::NoDismiss); + mSendAction = true; + // Todo: clean the Validator + TRACE_EXIT + return; +} + +void BtDeviceDialogInputWidget::inputClosed(HbAction *action) +{ + QVariantMap data; + + HbInputDialog *dlg=static_cast(sender()); + if(dlg->actions().first() == action) { + //Ok + QVariant result( dlg->value().toString().toUtf8() ); + data.insert( QString( "result" ), QVariant(true)); + data.insert( QString( "input" ), result ); + } + else if(dlg->actions().at(1) == action) { + //Cancel + data.insert( QString( "result" ), QVariant(false)); + } + + emit deviceDialogData(data); + emit deviceDialogClosed(); + mSendAction = false; +} + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialognotifwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialognotifwidget.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,176 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: BtDeviceDialogWidget class implementation. +* +*/ + + +#include "btdevicedialognotifwidget.h" +#include "btdevicedialogplugintrace.h" +#include +#include +#include +#include "btdevicedialogpluginerrors.h" + +/*! + class Constructor + */ +BtDeviceDialogNotifWidget::BtDeviceDialogNotifWidget( const QVariantMap ¶meters ) +{ + TRACE_ENTRY + // set properties + mLastError = NoError; + mShowEventReceived = false; + resetProperties(); + constructQueryDialog(parameters); + TRACE_EXIT +} + +/*! + Set parameters, implementation of interface + Invoked when HbDeviceDialog::update calls. + */ +bool BtDeviceDialogNotifWidget::setDeviceDialogParameters( + const QVariantMap ¶meters) +{ + TRACE_ENTRY + mLastError = NoError; + processParam(parameters); + TRACE_EXIT + return true; +} + +/*! + Get error, implementation of interface + */ +int BtDeviceDialogNotifWidget::deviceDialogError() const +{ + TRACE_ENTRY + TRACE_EXIT + return mLastError; +} + +/*! + Close notification, implementation of interface + */ +void BtDeviceDialogNotifWidget::closeDeviceDialog(bool byClient) +{ + TRACE_ENTRY + Q_UNUSED(byClient); + // Closed by client or internally by server -> no action to be transmitted. + mSendAction = false; + close(); + // If show event has been received, close is signalled from hide event. If not, + // hide event does not come and close is signalled from here. + if (!mShowEventReceived) { + emit deviceDialogClosed(); + } + TRACE_EXIT +} + +/*! + Return display widget, implementation of interface + */ +HbDialog *BtDeviceDialogNotifWidget::deviceDialogWidget() const +{ + TRACE_ENTRY + TRACE_EXIT + return const_cast(this); +} + +/*! + Construct display widget + */ +bool BtDeviceDialogNotifWidget::constructQueryDialog(const QVariantMap ¶meters) +{ + TRACE_ENTRY + // analyze the parameters to compose the properties of the message box widget + processParam(parameters); + + TRACE_EXIT + return true; +} + +/*! + Take parameter values and generate relevant property of this widget + */ +void BtDeviceDialogNotifWidget::processParam(const QVariantMap ¶meters) +{ + TRACE_ENTRY + QString keyStr, prompt; + keyStr.setNum( TBluetoothDialogParams::EResource ); + // Validate if the resource item exists. + QVariantMap::const_iterator i = parameters.constFind( keyStr ); + // item of ResourceId is not found, can't continue. + if ( i == parameters.constEnd() ) { + mLastError = UnknownDeviceDialogError; + return; + } + + QVariant param = parameters.value( keyStr ); + int key = param.toInt(); + switch ( key ) { + // Note dialogs + case EPairingSuccess: + prompt = QString( tr( "Pairing with %1 complete" ) ); + break; + case EPairingFailure: + prompt = QString( tr( "Unable to pair with %1" ) ); + break; + case EVisibilityTimeout: + prompt = QString( tr( "Phone is not detectable in searches made by other devices" ) ); + break; + default: + mLastError = ParameterError; + break; + } + // Could use QChar with ReplacementCharacter? + int repls = prompt.count( QString( "%" ) ); + if ( repls > 0 ) { + QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) ); + prompt = prompt.arg( name.toString() ); + } + // set property value to this dialog widget + HbNotificationDialog::setTitle( prompt ); + TRACE_EXIT +} + +/*! + Reset properties to default values + */ +void BtDeviceDialogNotifWidget::resetProperties() +{ + TRACE_ENTRY + mSendAction = true; + TRACE_EXIT + return; +} + +/*! + Widget is about to hide. Closing effect has ended. + */ +void BtDeviceDialogNotifWidget::hideEvent(QHideEvent *event) +{ + HbNotificationDialog::hideEvent(event); + emit deviceDialogClosed(); +} + +/*! + Widget is about to show + */ +void BtDeviceDialogNotifWidget::showEvent(QShowEvent *event) +{ + HbNotificationDialog::showEvent(event); + mShowEventReceived = true; +} diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogplugin.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogplugin.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,217 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: BtDeviceDialogPlugin class implementation. +* +*/ + + +#include "btdevicedialogplugin.h" +#include "btdevicedialogplugintrace.h" +#include +#include +#include +#include "btdevicedialoginputwidget.h" +#include "btdevicedialogquerywidget.h" +#include "btdevicedialognotifwidget.h" + +#include "btdevicedialogpluginerrors.h" +#include "btdevicesearchdialogwidget.h" + +Q_EXPORT_PLUGIN2(btdevicedialogplugin, BtDeviceDialogPlugin) + +// This plugin implements one device dialog type +static const struct { + const char *mTypeString; +} noteInfos[] = { + {"com.nokia.hb.btdevicedialog/1.0"} +}; + +class BtDeviceDialogPluginPrivate +{ +public: + BtDeviceDialogPluginPrivate(); +public: + int mError; +}; +/*! + BtDeviceDialogPluginPrivate Constructor + */ +BtDeviceDialogPluginPrivate::BtDeviceDialogPluginPrivate() +{ + mError = NoError; +} + +/*! + BtDeviceDialogPlugin Constructor + */ +BtDeviceDialogPlugin::BtDeviceDialogPlugin() +{ + d = new BtDeviceDialogPluginPrivate; +} + +/*! + Destructor + */ +BtDeviceDialogPlugin::~BtDeviceDialogPlugin() +{ + delete d; +} + +/*! + Check if client is allowed to use device dialog widget + */ +bool BtDeviceDialogPlugin::accessAllowed(const QString &deviceDialogType, + const QVariantMap ¶meters, const QVariantMap &securityInfo) const +{ + Q_UNUSED(deviceDialogType) + Q_UNUSED(parameters) + Q_UNUSED(securityInfo) + + // This plugin doesn't perform operations that may compromise security. + // All clients are allowed to use. + return true; +} + +/*! + From interface class. + Use the dialog type in the parameter to create widget. + */ +HbDeviceDialogInterface *BtDeviceDialogPlugin::createDeviceDialog( + const QString &deviceDialogType, const QVariantMap ¶meters) +{ + d->mError = NoError; + + int i; + // verify that requested dialog type is supported + const int numTypes = sizeof(noteInfos) / sizeof(noteInfos[0]); + for(i = 0; i < numTypes; i++) { + if (noteInfos[i].mTypeString == deviceDialogType) { + break; + } + } + // dialog type was found + if (i < numTypes) { + return checkDialogType( parameters ); + } + else { + // unknown dialog type, return error + d->mError = UnknownDeviceDialogError; + return 0; + } +} + +/*! + Return information of device dialog the plugin creates + Currently only supporting 1 device dialog type, so no need to check the type. + */ +bool BtDeviceDialogPlugin::deviceDialogInfo(const QString &deviceDialogType, + const QVariantMap ¶meters, DeviceDialogInfo *info) const +{ + Q_UNUSED(parameters) + Q_UNUSED(deviceDialogType) + // set return values + info->group = GenericDeviceDialogGroup; + info->flags = NoDeviceDialogFlags; + info->priority = DefaultPriority; + return true; +} + +/*! + Return device dialog types this plugin implements + Function will work fine (unchanged) when new dialogs are added. + */ +QStringList BtDeviceDialogPlugin::deviceDialogTypes() const +{ + QStringList types; + // read supported types from noteInfos + const int numTypes = sizeof(noteInfos) / sizeof(noteInfos[0]); + for(int i = 0; i < numTypes; i++) { + types.append(noteInfos[i].mTypeString); + } + return types; +} + +/*! + Return plugin flags + */ +HbDeviceDialogPlugin::PluginFlags BtDeviceDialogPlugin::pluginFlags() const +{ + return NoPluginFlags; +} + +/*! + Return last error + */ +int BtDeviceDialogPlugin::error() const +{ + return d->mError; +} + +/*! + Check the device dialog type to decide which widget to be used. + And create the specified widget. + */ +HbDeviceDialogInterface *BtDeviceDialogPlugin::checkDialogType( const QVariantMap ¶meters ) +{ + // Construct the key of EDialogType + QString keyStr; + keyStr.setNum( TBluetoothDialogParams::EDialogType ); + // Find the const iterator with key EDialogType + QVariantMap::const_iterator i = parameters.constFind( keyStr ); + + // item with key EDialogType is not found + if ( i == parameters.constEnd() ) { + d->mError = UnknownDeviceDialogError; + return NULL; + } + + // item with key EDialogType is found + // generate specified widget based on the dialog type value. + HbDeviceDialogInterface *deviceDialog = NULL; + switch ( i.value().toInt() ) { + case TBluetoothDialogParams::ENote: + deviceDialog = + new BtDeviceDialogQueryWidget(HbMessageBox::MessageTypeInformation, parameters); + break; + case TBluetoothDialogParams::EQuery: + deviceDialog = + new BtDeviceDialogQueryWidget(HbMessageBox::MessageTypeQuestion, parameters); + break; + case TBluetoothDialogParams::EInput: + deviceDialog = new BtDeviceDialogInputWidget(parameters); + break; + case TBluetoothDialogParams::EDeviceSearch: + deviceDialog = new BTDeviceSearchDialogWidget(parameters); + break; + case TBluetoothDialogParams::EGlobalNotif: + deviceDialog = new BtDeviceDialogNotifWidget(parameters); + break; + default: + d->mError = UnknownDeviceDialogError; + break; + } + if ( deviceDialog ) { + // verify no error has occurred + d->mError = deviceDialog->deviceDialogError(); + if ( d->mError ) { + // Do not continue if an error occurred + delete deviceDialog; + deviceDialog = NULL; + } + else { + d->mError = UnknownDeviceDialogError; + } + } + return deviceDialog; +} diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogquerywidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogquerywidget.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,215 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: BtDeviceDialogWidget class implementation. +* +*/ + + +#include "btdevicedialogquerywidget.h" +#include "btdevicedialogplugintrace.h" +#include +#include +#include +#include "btdevicedialogpluginerrors.h" + +/*! + class Constructor + */ +BtDeviceDialogQueryWidget::BtDeviceDialogQueryWidget( + HbMessageBox::MessageBoxType type, const QVariantMap ¶meters) +{ + TRACE_ENTRY + // set properties + mLastError = NoError; + mShowEventReceived = false; + mMessageBox = new HbMessageBox(type); + + resetProperties(); + constructQueryDialog(parameters); + TRACE_EXIT +} + +/*! + Set parameters, implementation of interface + Invoked when HbDeviceDialog::update calls. + */ +bool BtDeviceDialogQueryWidget::setDeviceDialogParameters( + const QVariantMap ¶meters) +{ + TRACE_ENTRY + mLastError = NoError; + processParam(parameters); + TRACE_EXIT + return true; +} + +/*! + Get error, implementation of interface + */ +int BtDeviceDialogQueryWidget::deviceDialogError() const +{ + TRACE_ENTRY + TRACE_EXIT + return mLastError; +} + +/*! + Close notification, implementation of interface + */ +void BtDeviceDialogQueryWidget::closeDeviceDialog(bool byClient) +{ + TRACE_ENTRY + Q_UNUSED(byClient); + // Closed by client or internally by server -> no action to be transmitted. + mSendAction = false; + mMessageBox->close(); + // If show event has been received, close is signalled from hide event. If not, + // hide event does not come and close is signalled from here. + if (!mShowEventReceived) { + emit deviceDialogClosed(); + } + TRACE_EXIT +} + +/*! + Return display widget, implementation of interface + */ +HbDialog *BtDeviceDialogQueryWidget::deviceDialogWidget() const +{ + TRACE_ENTRY + TRACE_EXIT + return mMessageBox; +} + +QObject *BtDeviceDialogQueryWidget::signalSender() const +{ + return const_cast(this); +} + +/*! + Construct display widget + */ +bool BtDeviceDialogQueryWidget::constructQueryDialog(const QVariantMap ¶meters) +{ + TRACE_ENTRY + // analyze the parameters to compose the properties of the message box widget + processParam(parameters); + + connect(mMessageBox, SIGNAL(finished(HbAction*)), this, SLOT(messageBoxClosed(HbAction*))); + + TRACE_EXIT + return true; +} + +/*! + Take parameter values and generate relevant property of this widget + */ +void BtDeviceDialogQueryWidget::processParam(const QVariantMap ¶meters) +{ + TRACE_ENTRY + QString keyStr, prompt; + keyStr.setNum( TBluetoothDialogParams::EResource ); + // Validate if the resource item exists. + QVariantMap::const_iterator i = parameters.constFind( keyStr ); + // item of ResourceId is not found, can't continue. + if ( i == parameters.constEnd() ) { + mLastError = UnknownDeviceDialogError; + return; + } + + QVariant param = parameters.value( keyStr ); + int key = param.toInt(); + switch ( key ) { + // Query dialogs: + case EAuthorization: + prompt = QString( tr( "Accept connection request from:\n%1" ) ); + break; + case EIncomingPairing: + prompt = QString( tr( "Device '%1' is trying to pair with you. Allow pairing?" ) ); + break; + case ENumericComparison: + prompt = QString( tr( "Does this code match the one on %1?\n\n%2" ) ); + break; + case EPasskeyDisplay: + prompt = QString( tr( "Enter on %1:\n\n%2" ) ); + break; + case ESetTrusted: + prompt = QString( tr( "Authorise this device to make connections automatically?" ) ); + break; + case EBlockUnpairedDevice: + prompt = QString( tr( "Do you want to block all future connection attempts from device %1?" ) ); + break; + case EBlockPairedDevice: + prompt = QString( tr( "Do you want to block all future connection attempts from paired device %1? \nThis will delete your pairing with the device." ) ); + break; + // Note dialogs, but not Notification dialogs + // Input dialogs + case EPinInput: + case EObexPasskeyInput: + // NULL parameters + case ENoResource: + case EUnusedResource: + default: + mLastError = ParameterError; + break; + } + // Could use QChar with ReplacementCharacter? + int repls = prompt.count( QString( "%" ) ); + if ( repls > 0 ) { + QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) ); + prompt = prompt.arg( name.toString() ); + if ( repls > 1 ) { + QVariant addval = parameters.value( QString::number( TBluetoothDeviceDialog::EAdditionalDesc ) ); + prompt = prompt.arg( addval.toString() ); + } + } + // set property value to this dialog widget + mMessageBox->setText( prompt ); + TRACE_EXIT +} + +/*! + Reset properties to default values + */ +void BtDeviceDialogQueryWidget::resetProperties() +{ + TRACE_ENTRY + // set to default values + mMessageBox->setModal(true); + mMessageBox->setTimeout(HbDialog::NoTimeout); + mMessageBox->setDismissPolicy(HbDialog::NoDismiss); + mSendAction = true; + TRACE_EXIT + return; +} + + +void BtDeviceDialogQueryWidget::messageBoxClosed(HbAction* action) +{ + QVariantMap data; + + HbMessageBox *dlg=static_cast(sender()); + if(dlg->actions().first() == action) { + //Yes + data.insert( QString( "result" ), QVariant(true)); + } + else if(dlg->actions().at(1) == action) { + //No + data.insert( QString( "result" ), QVariant(false)); + } + + emit deviceDialogData(data); + emit deviceDialogClosed(); + mSendAction = false; +} diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicesearchdialogwidget.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,359 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + + +#include "btdevicesearchdialogwidget.h" +#include +#include +#include +#include +#include + +const char* DOCML_BTDEV_SEARCH_DIALOG = ":/docml/bt-device-search-dialog.docml"; + + +BTDeviceSearchDialogWidget::BTDeviceSearchDialogWidget(const QVariantMap ¶meters) +:HbDialog() + { + mDeviceLstIdx = 0; + mViewByChosen = false; + mSelectedType = 0; + mDeviceDialogData = 0; + constructDialog(parameters); + } + +BTDeviceSearchDialogWidget::~BTDeviceSearchDialogWidget() + { + delete mLoader; + mLoader = NULL; + delete mContentItemModel; + mContentItemModel = NULL; + // delete mRbl; + // delete mViewByDialog; + } + +bool BTDeviceSearchDialogWidget::setDeviceDialogParameters(const QVariantMap ¶meters) + { + device newDevice; + + // newDevice.mDeviceName = parameters.value("deviceName").toString(); + newDevice.mDeviceName = parameters.value(parameters.keys().at(0)).toString(); + + // newDevice.mDeviceType = parameters.value("deviceType").toString(); + newDevice.mDeviceIdx = mDeviceLstIdx; + + mDeviceList.append(newDevice); + mDeviceLstIdx++; + + + QStringList info; + // if(!mViewByChosen) + { + info.append(newDevice.mDeviceName); + // info.append(newDevice.mDeviceType); + QStandardItem* listitem = new QStandardItem(); + listitem->setData(info, Qt::DisplayRole); + + listitem->setIcon(icon()); + + mContentItemModel->appendRow(listitem); + } + /* else + { + if(mDeviceTypeList[mSelectedType] == newDevice.mDeviceType) + { + info.append(newDevice.mDeviceName); + info.append(newDevice.mDeviceType); + QStandardItem* listitem = new QStandardItem(); + listitem->setData(info, Qt::DisplayRole); + + listitem->setIcon(icon(newDevice.mDeviceType)); + + mContentItemModel->appendRow(listitem); + } + }*/ + + return true; + } + +int BTDeviceSearchDialogWidget::deviceDialogError() const + { + return 0; + } + +void BTDeviceSearchDialogWidget::closeDeviceDialog(bool byClient) + { + Q_UNUSED(byClient); + this->close(); + } + +HbPopup* BTDeviceSearchDialogWidget::deviceDialogWidget() const + { + return const_cast(this); + } + +bool BTDeviceSearchDialogWidget::constructDialog(const QVariantMap ¶meters) + { + (void) parameters; + mLoader = new HbDocumentLoader(); + bool ok = false; + + mLoader->load(DOCML_BTDEV_SEARCH_DIALOG, &ok); + if(ok) + { + HbLabel* label = qobject_cast(mLoader->findWidget("heading")); + if(label) + { + label->setTextWrapping(Hb::TextWordWrap); + label->setAlignment(Qt::AlignHCenter); + label->setPlainText("Bluetooth - Found devices"); + } + this->setHeadingWidget(label); + this->setFrameType(HbDialog::Strong); + this->setBackgroundFaded(false); + + HbPushButton* viewBy = qobject_cast(mLoader->findWidget("viewBy")); + HbPushButton* stop = qobject_cast(mLoader->findWidget("stop")); + HbPushButton* retry = qobject_cast(mLoader->findWidget("retry")); + + mListView = qobject_cast(mLoader->findWidget("listView")); + mListView->setSelectionMode(HbAbstractItemView::SingleSelection); + + mContentItemModel = new QStandardItemModel(this); + mListView->setModel(mContentItemModel);//, prototype); + + connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); + connect(stop, SIGNAL(clicked()), this, SLOT(stopClicked())); + connect(retry, SIGNAL(clicked()), this, SLOT(retryClicked())); + connect(viewBy, SIGNAL(clicked()), this, SLOT(viewByClicked())); + + QGraphicsWidget *widget = mLoader->findWidget(QString("container")); + this->setContentWidget(widget); + } + else + { + + } + + this->setBackgroundFaded(false); + setDismissPolicy(HbPopup::TapOutside); + setTimeout(HbPopup::NoTimeout); + + /* mViewByDialog = new HbDialog(); + mRbl = new HbRadioButtonList(mViewByDialog); + connect(mRbl, SIGNAL(itemSelected(int)), this, SLOT(viewByItemSelected(int)));*/ + + return true; + } + +void BTDeviceSearchDialogWidget::hideEvent(QHideEvent *event) + { + HbDialog::hideEvent(event); + if(mDeviceDialogData == 0) + { + QVariantMap val; + QVariant index(-1); + val.insert("selectedindex",index); + emit deviceDialogData(val); + } + emit deviceDialogClosed(); + } + +void BTDeviceSearchDialogWidget::showEvent(QShowEvent *event) + { + HbDialog::showEvent(event); + } + +void BTDeviceSearchDialogWidget::stopClicked() + { + QVariantMap val; + QVariant index("Stop"); + val.insert("Stop",index); + emit deviceDialogData(val); + } + +void BTDeviceSearchDialogWidget::retryClicked() + { + QVariantMap val; + QVariant index("Retry"); + val.insert("Retry",index); + emit deviceDialogData(val); + delete mContentItemModel; + mContentItemModel = new QStandardItemModel(this); + mListView->setModel(mContentItemModel); + } + +//void BTDeviceSearchDialogWidget::viewByClicked() +// { +/* mViewByDialog->setDismissPolicy(HbPopup::NoDismiss); + mViewByDialog->setTimeout(HbPopup::NoTimeout); + + bool foundEntry = false; + QStringList st; + st << "All"; + mDeviceTypeList.clear(); + for(int i = 0; i < mDeviceList.count(); i++) + { + for(int j = 0; j < mDeviceTypeList.count(); j++) + { + if(mDeviceTypeList[j] == mDeviceList[i].mDeviceType) + { + foundEntry = true; + break; + } + } + if(!foundEntry) + { + mDeviceTypeList.append(mDeviceList[i].mDeviceType); + } + foundEntry = false; + } + + for(int k = 0; k < mDeviceTypeList.count(); k++) + { + st << mDeviceTypeList[k]; + } + + mRbl->setItems(st); + mViewByDialog->setContentWidget(mRbl); + mViewByDialog->setMaximumHeight(300); + mViewByDialog->setMaximumWidth(500); + + mViewByDialog->show();*/ + // } + +void BTDeviceSearchDialogWidget::deviceSelected(const QModelIndex& modelIndex) + { + int row = 0; + + /* if(mViewByChosen) + { + row = mDeviceLstOfType[modelIndex.row()].mDeviceIdx; + } + + else*/ + { + row = modelIndex.row(); + } + + QVariantMap val; + QVariant index(row); + val.insert("selectedindex",index); + emit deviceDialogData(val); + mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog + //emit deviceDialogClosed(); + this->close(); + } + +//void BTDeviceSearchDialogWidget::viewByItemSelected(int index) + // { + // (void) index; + /* if(index == 0) + { + //Option 'All' selected + mViewByDialog->close(); + delete mContentItemModel; + mContentItemModel = new QStandardItemModel(this); + mListView->setModel(mContentItemModel); + mViewByChosen = false; + + for(int i = 0; i < mDeviceList.count(); i++) + { + QStandardItem* listitem = new QStandardItem(); + + QStringList info; + info << mDeviceList[i].mDeviceName << mDeviceList[i].mDeviceType ; + listitem->setData(info, Qt::DisplayRole); + + //listitem->setIcon(icon(mDeviceList[i].mDeviceType)); + + mContentItemModel->appendRow(listitem); + } + } + else + { + index--; + mSelectedType = index; + mViewByDialog->close(); + + delete mContentItemModel; + mContentItemModel = new QStandardItemModel(this); + mListView->setModel(mContentItemModel); + + mDeviceLstOfType.clear(); + for(int i = 0; i < mDeviceList.count(); i++) + { + if(mDeviceList[i].mDeviceType == mDeviceTypeList[index]) + { + mDeviceLstOfType.append(mDeviceList[i]); + + QStandardItem* listitem = new QStandardItem(); + + QStringList info; + info << mDeviceList[i].mDeviceName << mDeviceTypeList[index]; + listitem->setData(info, Qt::DisplayRole); + + //listitem->setIcon(icon(mDeviceTypeList[index])); + + mContentItemModel->appendRow(listitem); + } + } + mViewByChosen = true; + }*/ + // } + +QIcon BTDeviceSearchDialogWidget::icon() + { + /* if(deviceType == "Audio") + { + return (QIcon(QString(":/icons/qgn_prop_bt_audio.svg"))); + } + else if(deviceType == "Car-kit") + { + return (QIcon(QString(":/icons/qgn_prop_bt_car_kit.svg"))); + } + else if(deviceType == "Computer") + { + return (QIcon(QString(":/icons/qgn_prop_bt_computer.svg"))); + } + else if(deviceType == "Headset") + { + return (QIcon(QString(":/icons/qgn_prop_bt_headset.svg"))); + } + else if(deviceType == "Keyboard") + { + return (QIcon(QString(":/icons/qgn_prop_bt_keyboard.svg"))); + } + else if(deviceType == "Mouse") + { + return (QIcon(QString(":/icons/qgn_prop_bt_mouse.svg"))); + } + else if(deviceType == "Phone") + { + return (QIcon(QString(":/icons/qgn_prop_bt_phone.svg"))); + } + else if(deviceType == "Printer") + { + return (QIcon(QString(":/icons/qgn_prop_bt_printer.svg"))); + } + else + { + return (QIcon(QString(":/icons/qgn_prop_bt_unknown.svg"))); + }*/ + return QIcon(QString(":/icons/qgn_prop_sml_bt.svg")); + } + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifclient/bwins/btnotifclientu.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifclient/bwins/btnotifclientu.def Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,11 @@ +EXPORTS + ??0RBTNotifier@@QAE@XZ @ 1 NONAME ; RBTNotifier::RBTNotifier(void) + ?CancelNotifier@RBTNotifier@@QAEHVTUid@@@Z @ 2 NONAME ; int RBTNotifier::CancelNotifier(class TUid) + ?Connect@RBTNotifier@@QAEHXZ @ 3 NONAME ; int RBTNotifier::Connect(void) + ?StartNotifier@RBTNotifier@@QAEHVTUid@@ABVTDesC8@@@Z @ 4 NONAME ; int RBTNotifier::StartNotifier(class TUid, class TDesC8 const &) + ?StartNotifierAndGetResponse@RBTNotifier@@QAEXAAVTRequestStatus@@VTUid@@ABVTDesC8@@AAVTDes8@@@Z @ 5 NONAME ; void RBTNotifier::StartNotifierAndGetResponse(class TRequestStatus &, class TUid, class TDesC8 const &, class TDes8 &) + ?UpdateNotifier@RBTNotifier@@QAEHVTUid@@ABVTDesC8@@AAVTDes8@@@Z @ 6 NONAME ; int RBTNotifier::UpdateNotifier(class TUid, class TDesC8 const &, class TDes8 &) + ?Version@RBTNotifier@@QAE?AVTVersion@@XZ @ 7 NONAME ; class TVersion RBTNotifier::Version(void) + ?CancelPairDevice@RBTNotifier@@QAEXXZ @ 8 NONAME ; void RBTNotifier::CancelPairDevice(void) + ?PairDevice@RBTNotifier@@QAEXABV?$TPckgBuf@VTBTDevAddr@@@@JAAVTRequestStatus@@@Z @ 9 NONAME ; void RBTNotifier::PairDevice(class TPckgBuf const &, long, class TRequestStatus &) + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifclient/eabi/btnotifclientu.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifclient/eabi/btnotifclientu.def Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,12 @@ +EXPORTS + _ZN11RBTNotifier13StartNotifierE4TUidRK6TDesC8 @ 1 NONAME + _ZN11RBTNotifier14CancelNotifierE4TUid @ 2 NONAME + _ZN11RBTNotifier14UpdateNotifierE4TUidRK6TDesC8R5TDes8 @ 3 NONAME + _ZN11RBTNotifier27StartNotifierAndGetResponseER14TRequestStatus4TUidRK6TDesC8R5TDes8 @ 4 NONAME + _ZN11RBTNotifier7ConnectEv @ 5 NONAME + _ZN11RBTNotifier7VersionEv @ 6 NONAME + _ZN11RBTNotifierC1Ev @ 7 NONAME + _ZN11RBTNotifierC2Ev @ 8 NONAME + _ZN11RBTNotifier10PairDeviceERK8TPckgBufI10TBTDevAddrElR14TRequestStatus @ 9 NONAME + _ZN11RBTNotifier16CancelPairDeviceEv @ 10 NONAME + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifclient/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifclient/group/bld.inf Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,40 @@ +/* +* ============================================================================ +* Name : bld.inf +* Part of : bluetoothengine / bluetoothengine +* Description : Build information file for bluetoothengine subsystem +* Version : %version: 1 % +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1.1 +*/ + + +PRJ_PLATFORMS +DEFAULT + +PRJ_EXPORTS + +../inc/btnotifclient.h |../../../inc/btnotifclient.h +../rom/btnotifclient.iby CORE_MW_LAYER_IBY_EXPORT_PATH(btnotifclient.iby) +PRJ_MMPFILES + +btnotifclient.mmp + +PRJ_TESTMMPFILES + +../tsrc/btnotifclienttest/group/btnotifclienttest.mmp + +PRJ_TESTEXPORTS diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifclient/group/btnotifclient.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifclient/group/btnotifclient.mmp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,43 @@ +/* +* ============================================================================ +* Name : btnotifclient.mmp +* Part of : bluetoothengine / btnotifclient +* Description : Project definition file for project btnotifclient +* Version : %version: 1 % +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include +#include + +TARGET btnotifclient.dll +TARGETTYPE DLL +UID 0x1000008d 0x20026FF6 + +CAPABILITY CAP_GENERAL_DLL +VENDORID VID_DEFAULT + +SOURCEPATH ../src +SOURCE btnotifclient.cpp + +USERINCLUDE ../inc + +MW_LAYER_SYSTEMINCLUDE + +SYSTEMINCLUDE ../../inc + +LIBRARY euser.lib diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifclient/inc/btnotifclient.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifclient/inc/btnotifclient.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,179 @@ +/* +* ============================================================================ +* Name : btnotifclient.h +* Part of : bluetoothengine / btnotifclient +* Description : Session class for client-server interaction with btnotifserver. +* +* Copyright © 2009-2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef RBTNOTIFCLIENT_H +#define RBTNOTIFCLIENT_H + +#include +#include + +/** + * A handle to a session with the Bluetooth notifier server for showing + * Bluetooth-related notifications to the user. + * + * ?more_complete_description + * @code + * ?good_class_usage_example(s) + * @endcode + * + * @lib ?library + * @since Symbian^4 + */ +NONSHARABLE_CLASS( RBTNotifier ) : public RSessionBase + { +public: + + /** + * Constructor. + * + * @since Symbian^4 + */ + IMPORT_C RBTNotifier(); + + /** + * Connect to the Bluetooth notifier server. + * + * @since Symbian^4 + * @return KErrNone, if successful. Otherwise one of + * the system-wide error codes. + */ + IMPORT_C TInt Connect(); + + /** + * Get the version information about the client. + * + * @since Symbian^4 + * @return The version of the client-server interface implemented by this client. + */ + IMPORT_C TVersion Version(); + + /** + * Requests the extended notifier server to start the notifier + * identified by the specified UID. The request is synchronous; + * the call returns when the request is complete. + * + * @since Symbian^4 + * @param aNotifierUid The UID identifying the notifier. This is + * the same UID as used with RNotifier for the same purpose. + * @param aBuffer Data that can be passed to the notifier; the format and + * meaning of this depends on the notifier. + * @return KErrNone, if successful; KErrNotFound, if there + * is no notifier matching the specified UID; otherwise + * one of the other system-wide error codes. + */ + IMPORT_C TInt StartNotifier( TUid aNotifierUid, const TDesC8& aBuffer ); + + /** + * Requests the extended notifier server to start the notifier + * identified by the specified UID. This is an asynchronous request. + * + * @since Symbian^4 + * @param aRs The request status. On request completion, contains KErrNone, + * if successful; KErrNotFound, if there is no notifier matching the + * specified UID; KErrCancel, if the notifier was cancelled through + * RBTNotifier::CancelNotifier; otherwise, one of the other system + * wide error codes. + * @param aNotifierUid The UID identifying the notifier. This is + * the same UID as used with RNotifier for the same purpose. + * @param aBuffer Data that can be passed to the notifier; the format and + * meaning of this depends on the notifier. + * @param aResponse Response data from the notifier; the format and meaning + * of this depends on the notifier. + */ + IMPORT_C void StartNotifierAndGetResponse( TRequestStatus& aRs, + TUid aNotifierUid, const TDesC8& aBuffer, TDes8& aResponse ); + + /** + * Requests the Bluetooth notifier server to cancel the notifier + * identified by the specified UID. The request is synchronous; + * the call returns when the request is complete. + * + * @since Symbian^4 + * @param aNotifierUid The UID identifying the notifier. This is + * the same UID as used with RNotifier for the same purpose. + * @return KErrNone, if successful; KErrNotFound, if there + * is no notifier matching the specified UID; otherwise + * one of the other system-wide error codes. + */ + IMPORT_C TInt CancelNotifier( TUid aNotifierUid ); + + /** + * Requests the Bluetooth notifier server to update the active + * notifier identified by the specified UID, with the data supplied. + * The request is synchronous; the call returns when the request is complete. + * + * @since Symbian^4 + * @param aNotifierUid The UID identifying the notifier. This is + * the same UID as used with RNotifier for the same purpose. + * @param aBuffer Data that can be passed to the notifier; the format and + * meaning of this depends on the notifier. + * @param aResponse Response data from the notifier; the format and meaning + * of this depends on the notifier. + * @return KErrNone, if successful; KErrNotFound, if there + * is no notifier matching the specified UID; otherwise + * one of the other system-wide error codes. + */ + IMPORT_C TInt UpdateNotifier( TUid aNotifierUid, + const TDesC8& aBuffer, TDes8& aResponse ); + + /** + * Requests the Bluetooth notifier server to pair with the device + * specified by the given Bluetooth device address. + * The request is asynchronous; Use CancelPairing() to cancel + * an outstanding pairing request. + * + * @since Symbian^4 + * @param aAddr The address of the remote device to perform pairing with. + * @param aDeviceClass the CoD of the remote device. + * @param aStatus The request status. On request completion, contains KErrNone, + * if successful; KErrCancel, if the notifier was cancelled through + * RBTNotifier::CancelPair; otherwise, one of the other system + * wide error codes. + */ + IMPORT_C void PairDevice( const TBTDevAddrPckgBuf& aAddr, TInt32 aDeviceClass, + TRequestStatus& aStatus ); + + /** + * Requests the Bluetooth notifier server to cancel the current pairing + * request. The request is synchronous; + * the call returns when the request is complete. + * + * If this request is issued when the Bluetooth + * notifier server has completed pairing with the device, the pairing + * will not be un-done. That is, the device will not be unpaired. + * + * @since Symbian^4 + */ + IMPORT_C void CancelPairDevice(); + +private: + +private: // data + + /** + * ?description_of_member + */ +// ?type ?member_name; + + }; + +#endif // RBTNOTIFCLIENT_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifclient/rom/btnotifclient.iby --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifclient/rom/btnotifclient.iby Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Image description file for project btnotif +* +*/ + + +#ifndef BTNOTIFCLIENT_IBY +#define BTNOTIFCLIENT_IBY + +#include + +#ifdef __BT + +file=ABI_DIR/BUILD_DIR/btnotifclient.dll SHARED_LIB_DIR/btnotifclient.dll + +#endif // __BT + +#endif // BTNOTIFCLIENT_IBY diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifclient/src/btnotifclient.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifclient/src/btnotifclient.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,167 @@ +/* +* ============================================================================ +* Name : btnotifclient.cpp +* Part of : bluetoothengine / btnotifclient +* Description : Session class for client-server interaction with btnotifserver. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "btnotifclient.h" +#include "btnotifclientserver.h" + + +// --------------------------------------------------------------------------- +// start btnotif server from client. +// --------------------------------------------------------------------------- +// +TInt StartBTNotifSrv() + { + const TUidType serverUid( KNullUid, KNullUid, KBTNotifServerUid3 ); + // Create a new server process. Simultaneous launching of two processes + // should be detected when the second one attempts to create the server + // object, failing with KErrAlreadyExists. + RProcess server; + TInt err = server.Create( KBTNotifServerName, KNullDesC, serverUid ); + if( err != KErrNone ) + { + return err; + } + TRequestStatus status; + server.Rendezvous( status ); + if( status != KRequestPending ) + { + server.Kill( KErrCancel ); // Abort startup + } + else + { + server.Resume(); + } + User::WaitForRequest( status ); // Wait for start or death + err = status.Int(); + if( server.ExitType() == EExitPanic ) + { + // The server actually panicked; inform the client. + err = KErrDied; + } + server.Close(); + return err; + } + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// Constructor +// --------------------------------------------------------------------------- +// +EXPORT_C RBTNotifier::RBTNotifier() +: RSessionBase() + { + } + +// --------------------------------------------------------------------------- +// Return the client-server version number we implement. +// --------------------------------------------------------------------------- +// +EXPORT_C TVersion RBTNotifier::Version() + { + return TVersion( KBTNotifServerVersionMajor, KBTNotifServerVersionMinor, + KBTNotifServerVersionBuild ); + } + + +// --------------------------------------------------------------------------- +// Connect to the notifier server. Start the server if necessary. +// --------------------------------------------------------------------------- +// +EXPORT_C TInt RBTNotifier::Connect() + { + TInt err = CreateSession( KBTNotifServerName, Version() ); + if( err == KErrNotFound || err == KErrServerTerminated ) + { + err = StartBTNotifSrv(); + if( err == KErrNone || err == KErrAlreadyExists ) + { + err = CreateSession( KBTNotifServerName, Version() ); + } + } + return err; + } + + +// --------------------------------------------------------------------------- +// Start the specified notifier, synchronous call. +// --------------------------------------------------------------------------- +// +EXPORT_C TInt RBTNotifier::StartNotifier( TUid aNotifierUid, const TDesC8& aBuffer ) + { + return SendReceive( EBTNotifStartSyncNotifier, + TIpcArgs( (TInt) aNotifierUid.iUid, &aBuffer ) ); + } + + +// --------------------------------------------------------------------------- +// Start the specified notifier, asynchronous call. +// --------------------------------------------------------------------------- +// +EXPORT_C void RBTNotifier::StartNotifierAndGetResponse( TRequestStatus& aRs, + TUid aNotifierUid, const TDesC8& aBuffer, TDes8& aResponse ) + { + SendReceive( EBTNotifStartAsyncNotifier, + TIpcArgs( (TInt) aNotifierUid.iUid, &aBuffer, &aResponse ), aRs ); + } + + +// --------------------------------------------------------------------------- +// Cancel the specified notifier. +// --------------------------------------------------------------------------- +// +EXPORT_C TInt RBTNotifier::CancelNotifier( TUid aNotifierUid ) + { + return SendReceive( EBTNotifCancelNotifier, TIpcArgs( (TInt) aNotifierUid.iUid ) ); + } + + +// --------------------------------------------------------------------------- +// Update the specified notifier, synchronous call. +// --------------------------------------------------------------------------- +// +EXPORT_C TInt RBTNotifier::UpdateNotifier( TUid aNotifierUid, + const TDesC8& aBuffer, TDes8& aResponse ) + { + return SendReceive( EBTNotifUpdateNotifier, + TIpcArgs( (TInt) aNotifierUid.iUid, &aBuffer, &aResponse ) ); + } + +// --------------------------------------------------------------------------- +// Issue a pairing request. asynchronous call. +// --------------------------------------------------------------------------- +// +EXPORT_C void RBTNotifier::PairDevice( const TBTDevAddrPckgBuf& aDevice, + TInt32 aDeviceClass, TRequestStatus& aStatus ) + { + SendReceive( EBTEngPairDevice, + TIpcArgs( (TInt) EBTEngPairDevice, &aDevice, aDeviceClass ), aStatus ); + } + +// --------------------------------------------------------------------------- +// Cancel an ongoing pair request. +// --------------------------------------------------------------------------- +// +EXPORT_C void RBTNotifier::CancelPairDevice() + { + (void) SendReceive( EBTEngCancelPairDevice ); + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/bluetoothnotification.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/bluetoothnotification.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,262 @@ +/* +* ============================================================================ +* Name : bluetoothnotification.h +* Part of : bluetoothengine / btnotif +* Description : Class for managing an actual user notification or query. +* It hides UI framework-specifics in a private class. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BLUETOOTHNOTIFICATION_H +#define BLUETOOTHNOTIFICATION_H + +#include +#include +#include "bluetoothdevicedialogs.h" +#include "btnotificationresult.h" +#include "bluetoothtrace.h" + +class CBTNotificationManager; +class CHbSymbianVariantMap; + +/** + * CBluetoothNotification manages and controls notifications. + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBluetoothNotification ) : public CBase, + public MHbDeviceDialogObserver + { + + +public: + + /** + * Two-phased constructor. + * @param aManager Reference to the notification manager. + * @param aObserver Reference to our observer. + */ + static CBluetoothNotification* NewL( CBTNotificationManager* aManager ); + + /** + * Destructor. + */ + virtual ~CBluetoothNotification(); + + /** + * Sets the receiver of callbacks. + * + * @since Symbian^4 + * @param aObserver Pointer to the callback interface. + */ + inline void SetObserver( MBTNotificationResult* aObserver ) + { iObserver = aObserver; } + + /** + * Clears the receiver of callbacks. + * + * @since Symbian^4 + */ + inline void RemoveObserver() + { iObserver = NULL; } + + /** + * Reset the notification. + * + * @since Symbian^4 + */ + void Reset(); + + /** + * Getter for the notification type. + * + * @since Symbian^4 + * @return Notification type. + */ + inline TBluetoothDialogParams::TBTDialogType NotificationType() + { return iType; } + + /** + * Getter for the resource id. + * + * @since Symbian^4 + * @return Resource identifier. + */ + inline TBTDialogResourceId ResourceId() + { return iResourceId; } + + inline CHbSymbianVariantMap* Data() + { return iNotificationData; } + + /** + * Sets the type of notification (query, note, etc). + * + * @since Symbian^4 + * @param aType The type of the notification. + * @param aResourceId The id of the resource to be shown. + * @return Error code + */ + inline void SetNotificationType( TBluetoothDialogParams::TBTDialogType aType, + TBTDialogResourceId aResourceId ) + { iType = aType; iResourceId = aResourceId; } + + /** + * Sets the data to be shown to the user. + * + * @since Symbian^4 + * @param aType Identifies the type of data parameter to be set. + * @param aData Additional descriptor data to be shown in the dialog. + * @return Error code + */ + TInt SetData( TInt aDataType, const TDesC& aData ); + + /** + * Sets the data to be shown to the user. + * + * @since Symbian^4 + * @param aType Identifies the type of data parameter to be set. + * @param aData Additional integer data to be shown in the dialog. + * @return Error code + */ + TInt SetData( TInt aDataType, TInt aData ); + + /** + * Updates the data to be shown to the user. + * + * @since Symbian^4 + * @param ?arg1 ?description + * @return Error code + */ + TInt Update( const TDesC& aData =KNullDesC ); + + /** + * Show the notification, which means that it + * is added to the queue. + * + * @since Symbian^4 + * @param ?arg1 ?description + * @return Error code + */ + TInt Show(); + + /** + * Stop showing the notification. + * + * @since Symbian^4 + * @param ?arg1 ?description + * @return Error code + */ + TInt Close(); + + +private: + + CBluetoothNotification( CBTNotificationManager* aManager ); + + void ConstructL(); + + /** + * Sets the data to be shown to the user, leaves on error. + * + * @since Symbian^4 + * @param aType Identifies the type of data parameter to be set. + * @param aData Additional descriptor data to be shown in the dialog. + */ + void SetDataL( TInt aType, const TDesC& aData ); + + /** + * Sets the data to be shown to the user, leaves on error. + * + * @since Symbian^4 + * @param aType Identifies the type of data parameter to be set. + * @param aData Additional integer data to be shown in the dialog. + */ + void SetDataL( TInt aType, TInt aData ); + + /** + * From MHbDeviceDialogObserver. + * This callback is called when data is received from a device dialog. + * + * @since Symbian^4 + * @param aData contains data from the dialog plugin. + */ + virtual void DataReceived( CHbSymbianVariantMap& aData ); + + /** + * From MHbDeviceDialogObserver. + * This callback is called when a device dialog is closed. Any data sent by + * the dialog is indicated by the dataReceived() callback. If no observer is + * set in CHbDeviceDialog::Show the latest data can be retrieved with + * CHbDeviceDialog::receivedData(). + * + * @since Symbian^4 + * @param aCompletionCode gives the result of the dialog completion. Code can be + * either Symbian error code or device dialog error code. + */ + virtual void DeviceDialogClosed( TInt aCompletionCode ); + +#ifdef BLUETOOTHTRACE_ENABLED + void debugHbSymbianVariantMap( CHbSymbianVariantMap& aData); +#endif // BLUETOOTHTRACE_ENABLED + +private: // data + + /** + * The type of notification currently showing. + */ + TBluetoothDialogParams::TBTDialogType iType; + + /** + * The id of the resource (string identifier) + * of the currently showing notification. + */ + TBTDialogResourceId iResourceId; + + /** + * Reference to the queue manager. + * Not own. + */ + CBTNotificationManager* iManager; + + /** + * Reference to the receiver of the results. + * Not own. + */ + MBTNotificationResult* iObserver; + + /** + * The data to be shown to the user in a device dialog. + * Own. + */ + CHbSymbianVariantMap* iNotificationData; + + /** + * Buffer for receiving return data from the notifier. + */ + CHbSymbianVariantMap* iReturnData; + + /** + * Session object with the notification server. + * Own. + */ + CHbDeviceDialogSymbian *iDialog; + + BTUNITTESTHOOK + + }; + +#endif // BLUETOOTHNOTIFICATION_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/btnotifconnection.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifconnection.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,490 @@ +/* +* ============================================================================ +* Name : btnotifconnection.h +* Part of : bluetoothengine / btnotif +* Description : Class for observing events of a single connection, and for +* managing any user notifications related to the connection. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFCONNECTION_H +#define BTNOTIFCONNECTION_H + +#include +#include +#include +#include + +#include "bluetoothnotification.h" + +#include "bluetoothtrace.h" + +class CBTNotifConnectionTracker; +class CBTNotifPairingHelper; + +/** + * Utility function for getting the name of a device to display. + * + * @since Symbian^4 + * @param aName On return, will hold the device name to display. + * @param aDevice Data dtructure holding the device record. + */ +void GetDeviceNameL( TBTDeviceName& aName, const CBTDevice& aDevice ); + + +/** + * CBTNotifConnection handles the connection information and operations + * related to remote devices. + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifConnection ) : public CBase, + public MBTNotificationResult, + public MBtSimpleActiveObserver, + public MBTEngDevManObserver + { + +public: + + /** Enumeration for the current active operation. */ + enum TOperation + { + EIdle, + EAuthorizing, + EPairing, + EBonding, + EAdditionalNotes, // Marks the queries and notes which follow + // notifier requests, but are done after completing + // the actual notifier message + EBlocking, + EInternalOperations, // Marks internal operations such as registry update. + EReadingRegistry, + EUpdatingRegistry + }; + + /** Array of BT profiles. */ + typedef RArray RBTProfileArray; + + /** + * Two-phased constructor. + * @param aAddr Address of the remote device for this connection. + * @param aTracker Pointer to our parent + */ + static CBTNotifConnection* NewLC( const TBTDevAddr& aAddr, + CBTNotifConnectionTracker* aTracker ); + + /** + * Destructor. + */ + virtual ~CBTNotifConnection(); + + /** + * Get the address of the remote device for this connection. + * + * @since Symbian^4 + * @return The BD_ADDR. + */ + inline const TBTDevAddr& Address() const + { return iAddr; } + + /** + * Get the device record of the remote device for this connection. + * + * @since Symbian^4 + * @return The CBTDevice device record. + */ + inline CBTDevice* BTDevice() const + { return iDevice; } + + /** + * Get the current operation for this connection. + * + * @since Symbian^4 + * @param aProfile The profile identifying the service. + */ + inline CBTNotifConnection::TOperation CurrentOperation() const + { return iCurrentOp; } + + /** + * Checks if we have any outstanding request, and handle the next + * in line. Also checks the link state, and informs the tracker + * if we have finished processing and the link is down. + * + * @since Symbian^4 + */ + void CheckNextOperationL(); + + /** + * Completes the first outstanding client request and removes + * it from the queue. + * + * @since Symbian^4 + * @param aReason The reason code to complete the message with. + * @param aReply Data to write back to the client. + */ + void CompleteClientRequest( TInt aReason, const TDesC8& aReply ); + + /** + * Distinguish the type request of this connection and queue it + * or handle it. + * + * @since Symbian^4 + * @param aParams The parameters for this request from the client. + * @param aMessage The message from the client. + */ + void HandleNotifierRequestL( const TDesC8& aParams, const RMessage2& aMessage ); + + /** + * Update an outstanding request for this connection. + * + * @since Symbian^4 + * @param aParams The parameters of the original request from the client. + * @param aMessage The update message from the client. + */ + void HandleNotifierUpdateL( const TDesC8& aParams, const RMessage2& aMessage ); + + /** + * Cancel an outstanding request for this connection. + * + * @since Symbian^4 + * @param aMessage The message from the client. (Temp! find better way!) + */ + void CancelNotifierRequestL( const RMessage2& aMessage ); + + /** + * Start a bonding operation with the remote device. + * + * @since Symbian^4 + * @param aMessage The message from the client. + */ + void StartBondingL( const RMessage2& aMessage ); + + /** + * Cancel an ongoing bonding operation with the remote device. + * + * @since Symbian^4 + */ + void CancelBondingL(); + + /** + * The pairing handler has completed a pairing operation. If this was part + * of a bonding procedure then this will complete the client request. + * + * @since Symbian^4 + */ + void PairingCompleted(); + + /** + * Process a new pairing result, and determine if we need to show + * anything to the user. + * + * @since Symbian^4 + * @param aError Result of the pairing operation. + */ + void PairingResult( TInt aError ); + + /** + * A service-level connection has been made with the device + * observed by this instance. The appropriate notification + * will be shown to the user. + * + * @since Symbian^4 + * @param aProfile The profile identifying the service. + */ + void ServiceConnectedL( TBTProfile aProfile ); + + /** + * A service-level connection has disconnected from the device + * observed by this instance. The appropriate notification + * will be shown to the user. + * + * @since Symbian^4 + * @param aProfile The profile identifying the service. + */ + void ServiceDisconnectedL( TBTProfile aProfile ); + + /** + * Ask the user if he/she wants to block future connection requests. + * + * @since Symbian^4 + */ + void LaunchBlockingQueryL(); + + /** + * Modify the record for the remote device in BTRegistry, with the + * changes already made in the local record. + * + * @since Symbian^4 + */ + void UpdateRegistryEntryL(); + + /** + * Modify the record for the remote device in BTRegistry, if + * aTrusted == true, then update trusted status after reading device + * info from registry + * + * @since Symbian^4 + */ + void UpdateRegistryEntryL(TBool aTrusted); + +// from base class MBTNotificationResult + + /** + * From MBTNotificationResult. + * Handle an intermediate result from a user query. + * This ffunction is called if the user query passes information + * back before it has finished i.e. is dismissed. The final acceptance/ + * denial of a query is passed back in MBRNotificationClosed. + * + * @since Symbian^4 + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRDataReceived( CHbSymbianVariantMap & aData ); + + /** + * From MBTNotificationResult. + * The notification is finished. The resulting data (e.g. user input or + * acceptance/denial of the query) is passed back here. + * + * @since Symbian^4 + * @param aErr KErrNone or one of the system-wide error codes. + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData ); + +// from base class MBtSimpleActiveObserver + + /** + * From MBtSimpleActiveObserver. + * Callback to notify that an outstanding request has completed. + * + * @since Symbian^4 + * @param aActive The active object helper that completed this request. + * @param aStatus The status of the completed request. + */ + virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); + + /** + * From MBtSimpleActiveObserver. + * Callback for handling cancelation of an outstanding request. + * + * @since Symbian^4 + * @param aId The ID that identifies the outstanding request. + */ + virtual void CancelRequest( TInt aRequestId ); + + /** + * Callback to notify that an error has occurred in RunL. + * + * @param aActive Pointer to the active object that completed. + * @param sError The error occured in RunL + */ + virtual void HandleError( CBtSimpleActive* aActive, + TInt aError ); + +// from base class MBTEngDevmanObserver + + /** + * From MBTEngDevManObserver. + * Indicates to the caller that adding, deleting or modifying a device + * has completed. + * When this function is called, new commands can be issued to the + * CBTEngDevMan API immediately. + * + * @since S60 v3.2 + * @param aErr Status information, if there is an error. + */ + virtual void HandleDevManComplete( TInt aErr ); + + /** + * From MBTEngDevManObserver. + * Indicates to the caller that getting a device from registry + * has completed. + * + * @param aErr Status information, if there is an error. + * @param aDeviceArray Array of devices that match the given criteria + * (the array provided by the caller). + */ + virtual void HandleGetDevicesComplete( + TInt err, CBTDeviceArray* deviceArray ); + +private: + + /** + * C++ default constructor. + */ + CBTNotifConnection( const TBTDevAddr& aAddr, + CBTNotifConnectionTracker* aTracker ); + + /** + * Symbian 2nd-phase constructor. + */ + void ConstructL(); + + /** + * Get a notification and configure it according to the current operation. + * + * @since Symbian^4 + * @param aType The notification type. + * @param aResourceId Identifier for the resource to display. + */ + void PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, + TBTDialogResourceId aResourceId ); + + /** + * Handle the result from a notification that is finished. + * + * @since Symbian^4 + * @param aErr KErrNone or one of the system-wide error codes. + * @param aData The returned data. The actual format + * is dependent on the actual notifier. + */ + void NotificationClosedL( TInt aError, const TDesC8& aData ); + + /** + * Handle a request for authorization of this connection. + * + * @since Symbian^4 + * @param aParams The parameters for this request from the client. + */ + void HandleAuthorizationReqL( const TDesC8& aParams ); + + /** + * Process the user input and complete the outstanding authorization request. + * + * @since Symbian^4 + * @param aError The result off the notification. + * @param aData The data returned from the notification dialog. + */ + void CompleteAuthorizationReqL( TInt aError, const TDesC8& aData ); + + /** + * Process the user input for blocking a device. + * + * @since Symbian^4 + * @param aError The result off the notification. + * @param aData The data returned from the notification dialog. + */ + void CompleteBlockingReqL( TInt aError, const TDesC8& aData ); + + /** + * Fetch device from registry + * + * @since Symbian^4 + * @param addr BT address of device to fetch from registry + */ + void GetDeviceFromRegistry( const TBTDevAddr &addr ); + +private: // data + + /** + * The current operation we are carrying out. + */ + TOperation iCurrentOp; + + /** + * Address of the remote device, identifying this connection. + */ + TBTDevAddr iAddr; + + /** + * Package to receive updates of the physical link state. + */ + TBTBasebandEvent iBasebandEvent; + + /** + * Queue of handles (identifier) of client messages we have been requested to work on. + */ + RArray iMsgHandleQ; + + /** + * Array of accepted profile connections (as known here). + */ + RBTProfileArray iAcceptedConnections; + + /** + * Array of rejected profile connections (as known here). + */ + RBTProfileArray iDeniedConnections; + + /** + * Handle to observe and control the baseband connection. + */ + RBTPhysicalLinkAdapter iPhyLink; + + /** + * Subsession with BT registry. + */ + RBTRegistry iRegistry; + + /** + * Details of the remote device. + * Own. + */ + CBTDevice* iDevice; + + /** + * Details of the remote device as retrieved from BT registry. + * Own. + */ + CBTRegistryResponse* iRegistryResponse; + + /** + * helper for modifying registry. + * Own. + */ + CBTEngDevMan* iDevMan; + + /** + * Active object helper for observing physical link changes. + * Own. + */ + CBtSimpleActive* iPhyActive; + + /** + * Active object helper for observing BT registry changes. + * Own. + */ + CBtSimpleActive* iRegActive; + + /** + * Helper class for processing pairing-related operations. + * Own. + */ + CBTNotifPairingHelper* iPairingHelper; + + /** + * Pointer to an outstanding user interaction. + * Not own. + */ + CBluetoothNotification* iNotification; + + /** + * Pointer to our parent. + * Not own. + */ + CBTNotifConnectionTracker* iTracker; + + CBTDeviceArray* iRegDevArray; // used for retrieving devices from registry + + BTUNITTESTHOOK + + }; + +#endif // BTNOTIFCONNECTION_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/btnotifconnectiontracker.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifconnectiontracker.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,396 @@ +/* +* ============================================================================ +* Name : btnotifconnectiontracker.h +* Part of : bluetoothengine / btnotif +* Description : Bluetooth connection tracker and manager. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFCONNECTIONTRACKER_H +#define BTNOTIFCONNECTIONTRACKER_H + + +#include +#include +#include +#include +#include +#include "btnotifserver.h" + +class CBTNotifConnection; +class CBTNotificationManager; +class CbtnotifConnectionTrackerTest; + + + +/** + * CBTNotifConnectionTracker keeps track of remote device connections + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifConnectionTracker ) : public CBase, + public MBluetoothPhysicalLinksNotifier, + public MBTEngConnObserver, + public MBtSimpleActiveObserver + { + +public: + + /** + * Two-phased constructor. + * @param aServer Pointer to our parent + */ + static CBTNotifConnectionTracker* NewL( CBTNotifServer* aServer ); + + /** + * Destructor. + */ + virtual ~CBTNotifConnectionTracker(); + + /** + * Get a pointer to the btnotif server object. + * + * @since Symbian^4 + * @return The server. + */ + inline CBTNotifServer* Server() const + { return iServer; } + + /** + * Get a pointer to the notification manager. + * This handle can be used for queueing notifications. + * + * @since Symbian^4 + * @return The notification manager. + */ + inline CBTNotificationManager* NotificationManager() const + { return iServer->NotificationManager(); } + + /** + * Get the shared handle to BT registry server. + * This handle can be used for creating subsessions. + * + * @since Symbian^4 + * @return Session with BT registry server. + */ + inline RBTRegServ& RegistryServerSession() + { return iBTRegistrySession; } + + /** + * Get the handle to the socket server. + * This handle can be used for creating subsessions. + * + * @since Symbian^4 + * @return Session with the socket server. + */ + inline RSocketServ& SocketServerSession() + { return iSockServ; } + + /** + * Get the handle to the Bluetooth pairing server. + * This handle can be used for creating subsessions. + * + * @since Symbian^4 + * @return Session with the socket server or NULL. + */ + inline RBluetoothPairingServer* PairingServerSession() + { return iPairingServ; } + + /** + * Processes a message from a notifier client related to connections. + * + * @since Symbian^4 + * @param aMessage The message containing the details of the client request. + */ + void DispatchNotifierMessageL( const RMessage2& aMessage ); + + /** + * Handle a request related to pairing. + * + * @since Symbian^4 + * @param aUid The UID of the notification request. + */ + void HandleBondingRequestL( const RMessage2& aMessage ); + + /** + * Handle a change in the number of physical connections. + * This also handles the case where a connection monitor has finished + * its processing, and is now ready for removal. + * + * @since Symbian^4 + */ + void HandleLinkCountChangeL(); + + /** + * Check repeated connection attempts, and record rejected/accepted queries. + * + * @since Symbian^4 + * @param aDevice The details of the remote device for this query. + * @param aAccepted ETrue if the user accepted the request, EFalse if rejected. + * @return ETrue if the user should be queried for blocking this device, + * EFalse if no query should be launched by the caller. + */ + TBool UpdateBlockingHistoryL( const CBTDevice* aDevice, TBool aAccepted ); + +// from base class MBluetoothPhysicalLinksNotifier + /** Notification of a requested connection coming up. + * If no error is reported, then that connection is ready for use. + * + * @since Symbian^4 + * @param aErr the returned error + */ + virtual void HandleCreateConnectionCompleteL( TInt aErr ); + + /** Notification of a requested disconnection having taken place. + * If no error is reported, then that connection has been closed. + * + * @since Symbian^4 + * @param aErr the returned error + */ + virtual void HandleDisconnectCompleteL( TInt aErr ); + + /** Notification that all existing connections have been torn down. + * If no error is reported, then there are no Bluetooth connections existing. + * + * @since Symbian^4 + * @param aErr the returned error + */ + virtual void HandleDisconnectAllCompleteL( TInt aErr ); + +// from base class MBTEngConnObserver + + /** + * From MBTEngConnObserver. + * Indicates to the caller that a service-level connection has completed. + * This function is called for both incoming and outgoing connections. + * This function is also called when an outgoing connection request fails, + * e.g. with error code KErrCouldNotConnect. + * When this function is called, new commands can be issued to the + * CBTEngConnMan API immediately. + * + * @since S60 v3.2 + * @param aAddr The address of the remote device. + * @param aErr Status information of the connection. KErrNone if the + * connection succeeded, otherwise the error code with + * which the outgoing connection failed. KErrAlreadyExists + * is returned if there already is an existing connection + * for the selected profile(s), or otherwise e.g. + * KErrCouldNotConnect or KErrDisconnected for indicating + * connection problems. + * @param aConflicts If there already is a connection for the selected + * profile(s) of an outgoing connection request (the + * selection is performed by BTEng), then this array + * contains the bluetooth device addresses of the + * remote devices for those connections. + */ + virtual void ConnectComplete( TBTDevAddr& aAddr, TInt aErr, + RBTDevAddrArray* aConflicts = NULL ); + + /** + * From MBTEngConnObserver. + * Indicates to the caller that a service-level connection has disconnected. + * When this function is called, new commands can be issued to the + * CBTEngConnMan API immediately. + * + * @since S60 v3.2 + * @param aAddr The address of the remote device. + * @param aErr The error code with which the disconnection occured. + * KErrNone for a normal disconnection, + * or e.g. KErrDisconnected if the connection was lost. + */ + virtual void DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ); + +// from base class MBtSimpleActiveObserver + + /** + * From MBtSimpleActiveObserver. + * Callback to notify that an outstanding request has completed. + * + * @since Symbian^4 + * @param aActive The active object helper that completed this request. + * @param aStatus The status of the completed request. + */ + virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); + + /** + * From MBtSimpleActiveObserver. + * Callback for handling cancelation of an outstanding request. + * + * @since Symbian^4 + * @param aId The ID that identifies the outstanding request. + */ + virtual void CancelRequest( TInt aRequestId ); + + /** + * Callback to notify that an error has occurred in RunL. + * + * @param aActive Pointer to the active object that completed. + * @param sError The error occured in RunL + */ + virtual void HandleError( CBtSimpleActive* aActive, + TInt aError ); + +private: + + CBTNotifConnectionTracker( CBTNotifServer* aServer ); + + void ConstructL(); + + /** + * Parse a client message and find the correct connection handler + * for dispatching a request. + * The parsed client message may be a request that is being served, + * in case a cancel request has come in. The opcode identifies the + * client message that is currently being dispatched. + * + * @since Symbian^4 + * @param aOpcode The opcode of the original request. + * @param aMessage The client message to parse. + * @param aBuffer On return this contains the parameters read from the message. + * @return The connection that is identified by the address in the + * message, or NULL if none found. + */ + CBTNotifConnection* FindConnectionFromMessageL( TInt aOpcode, + const RMessage2& aMessage, TDes8& aBuffer ); + + /** + * Parse the Bluetooth address from a request for some notification. + * + * @since Symbian^4 + * @param aUid The UID of the notification request. + * @param aParamsBuf Descriptor containing the parameter read from the + * client message. + * @return Bluetooth address parsed from the descriptor. + */ + TBTDevAddr ParseAddressL( TInt aUid, const TDesC8& aParamsBuf ) const; + + /** + * Find the handler of a specific connection. + * + * @since Symbian^4 + * @param aAddr The remote device address identifying the connection. + * @return Connnection handler or NULL; + */ + CBTNotifConnection* FindConnectionHandler( const TBTDevAddr& aAddr ) const; + + /** + * Record and check the time between connection attempts. + * + * @since Symbian^4 + * @param aAccepted ETrue if the user accepted the request, EFalse if rejected. + * @return EFalse if the attempt followed the previous attempt too fast, + * otherwise ETrue. + */ + TBool RecordConnectionAttempts( TBool aAccepted ); + +private: // data + + /** + * PubSub key for tracking the number of connections. + */ + RProperty iLinkCount; + +// ToDo: remove this when registry notifications API is available!! + /** + * PubSub key for tracking registry changes. + */ + RProperty iRegistryChange; + + /** + * Helper active object for observing the link count. + * Own. + */ + CBtSimpleActive* iRegistryActive; +// End ToDo + + /** + * Array of pointers to observers of individual connections. + */ + RPointerArray iConnArray; +// RHashMap iConnArray; + + /** + * Time of the last denied connection attempt. + */ + TInt64 iLastReject; + + /** + * Array of device addresses that the user has denied access. + */ + RArray iDeniedRequests; + + /** + * Single session with BTRegistry, to be used for subsessions. + */ + RBTRegServ iBTRegistrySession; + + /** + * Single session with the socket server, to be used for subsessions. + */ + RSocketServ iSockServ; + + /** + * Address placeholder for receiving secure simple pairing results. + */ + TBTDevAddr iSspResultAddr; + + /** + * Session with pairing server for receiving secure simple pairing results. + */ + RBluetoothPairingResult iSspResultSession; + + /** + * Single session with the pairing server, to be used for subsessions. + * Own. + */ + RBluetoothPairingServer* iPairingServ; + + /** + * Object for managing the piconet. + * Own. + */ + CBTEngConnMan* iConnMan; + + /** + * Object for managing the piconet. + * Own. + */ + CBluetoothPhysicalLinks* iPhyLinks; + + /** + * Helper active object for observing the link count. + * Own. + */ + CBtSimpleActive* iLinkCountActive; + + /** + * Helper active object for receiving secure simple pairing results. + * Own. + */ + CBtSimpleActive* iSspResultActive; + + /** + * Reference to our parent the server class. + * Not own. + */ + CBTNotifServer* iServer; + + BTUNITTESTHOOK + + }; + +#endif // BTNOTIFCONNECTIONTRACKER_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/btnotifdeviceselector.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifdeviceselector.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,171 @@ +/* +* ============================================================================ +* Name : btnotifdeviceselector.h +* Part of : BTProximity / BTProximity +* Description : Class for tracking Bluetooth settings, and also for +* handling notes unrelated to specific connection. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFDEVICESELECTOR_H +#define BTNOTIFDEVICESELECTOR_H + + +#include +#include +#include +#include "bluetoothnotification.h" + +class CBTNotifServer; +class CAdvanceDevDiscoverer; +class CBtDevExtension; + +/** + * ?one_line_short_description + * ?more_complete_description + * + * @code + * ?good_class_usage_example(s) + * @endcode + * + * @lib ?library + * @since S60 ?S60_version *** for example, S60 v3.0 + */ +NONSHARABLE_CLASS( CBTNotifDeviceSelector ) : + public CBase, + public MBTNotificationResult, + public MDevDiscoveryObserver + { + +public: + + /** + * Two-phased constructor. + * @param aServer Pointer to our parent + */ + static CBTNotifDeviceSelector* NewL( CBTNotifServer& aServer ); + + /** + * Destructor. + */ + virtual ~CBTNotifDeviceSelector(); + + /** + * Processes a message from a notifier client related to settings. + * + * @since Symbian^4 + * @param aMessage The message containing the details of the client request. + */ + void DispatchNotifierMessageL( const RMessage2& aMessage ); + + /** + * Cancels an oustanding message from a notifier client related to settings. + * + * @since Symbian^4 + * @param aMessage The message containing the details of the original client request. + */ + void CancelNotifierMessageL( const RMessage2& aMessage ); + +private: +// from base class MBTNotificationResult + + /** + * From MBTNotificationResult. + * Handle an intermediate result from a user query. + * This ffunction is called if the user query passes information + * back before it has finished i.e. is dismissed. The final acceptance/ + * denial of a query is passed back in MBRNotificationClosed. + * + * @since Symbian^4 + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRDataReceived( CHbSymbianVariantMap& aData ); + + /** + * From MBTNotificationResult. + * The notification is finished. The resulting data (e.g. user input or + * acceptance/denial of the query) is passed back here. + * + * @since Symbian^4 + * @param aErr KErrNone or one of the system-wide error codes. + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData ); + + // From MDevDiscoveryObserver + + /** + * Callback to notify that a device has been found. + * + * @param aAddr the inquiry address that contains the inquiry information + * of the found device. + * @param aName the Bluetooth device name of the found device + */ + virtual void HandleNextDiscoveryResultL( + const TInquirySockAddr& aAddr, const TDesC& aName ); + + /** + * Callback to notify that the device search has completed. + * + * @param aErr the error code of device search result. + */ + virtual void HandleDiscoveryCompleted( TInt aErr ); + +private: + + CBTNotifDeviceSelector( CBTNotifServer& aServer ); + + void ConstructL(); + + void PrepareNotificationL( + TBluetoothDialogParams::TBTDialogType aType, + TBTDialogResourceId aResourceId ); + +private: // data + + /** + * Reference to our parent the server class. + * Not own. + */ + CBTNotifServer& iServer; + + /** + * Pointer to an outstanding user interaction. + * Not own. + */ + CBluetoothNotification* iNotification; + + /** + * device inquiry handler: + */ + CAdvanceDevDiscoverer* iDiscoverer; + + /** + * do not own the elements in the array. + */ + RPointerArray iDevices; + + /** + * The message for a pending device selection request from a RNotifier client. + */ + RMessage2 iMessage; + + }; + +#endif // BTNOTIFDEVICESELECTOR_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/btnotificationmanager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotificationmanager.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,145 @@ +/* +* ============================================================================ +* Name : btnotificationmanager.h +* Part of : bluetoothengine / btnotif +* Description : Class for managing user notification and query objects, and for serializing access to the notification server. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFICATIONMANAGER_H +#define BTNOTIFICATIONMANAGER_H + + +#include + +class CBTNotifServer; +class CBluetoothNotification; + +/** + * CBTNotificationManager manages Bt Notifications + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotificationManager ) : public CBase + { + +public: + + /** Enumeration for the priority of the notification. */ + enum TNotificationPriority + { + EPriorityLow, + EPriorityStandard, + EPriorityHigh + }; + + /** + * Two-phased constructor. + * @param aServer Pointer to our parent + */ + static CBTNotificationManager* NewL( const CBTNotifServer* aServer ); + + /** + * Destructor. + */ + virtual ~CBTNotificationManager(); + + CBluetoothNotification* GetNotification(); + + void ReleaseNotification( CBluetoothNotification* aNotification ); + + /** + * Add a notification to the queue of notifications scheduled to be + * shown. Notifications are serialized, to avoid overlapping notes. + * The queue is managed on priority of each notification. + * + * @since Symbian^4 + * @param aNotification The notification to be added. + * @param aPriority The priority of the notification. EPriorityHigh means + * that the note is put to the front of the queue. + * EPriorityStandard means that it is appended to the end, + * and should be used for most notes. EPriorityLow is not + * used yet. + * @return Error code. + */ + TInt QueueNotification( CBluetoothNotification* aNotification, + TNotificationPriority aPriority = EPriorityStandard ); + +private: + + CBTNotificationManager( const CBTNotifServer* aServer ); + + void ConstructL(); + + /** + * Process the notification queue and launch the next notification. + * + * @since Symbian^4 + */ + void ProcessNotificationQueueL(); + + /** + * Process the notification queue and launch the next notification. + * + * @since Symbian^4 + */ + void CleanupUnusedQueueL(); + + /** + * Create and queue an idle timer if there are no outstanding notifications, + * otherwise cancel the idle timer. + * + * @since Symbian^4 + */ + void CheckIdle(); + + /** + * Callback function for asynchronous processing of + * queued notification requests. + * + * @since Symbian^4 + * @param aPtr Pointer to notification manager instance. + */ + static TInt AsyncCallback( TAny* aPtr ); + +private: // data + + /** + * The queue of notifications to be shown to the user. + */ + RPointerArray iNotificationQ; + + /** + * The queue of spare notifications. + */ + RPointerArray iUnusedQ; + + /** + * Callback for asynchronous processing. + * Own. + */ + CAsyncCallBack* iAsyncCb; + + /** + * Pointer to our parent. + * Not own. + */ + const CBTNotifServer* iServer; + + }; + +#endif // BTNOTIFICATIONMANAGER_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/btnotificationresult.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotificationresult.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,66 @@ +/* +* ============================================================================ +* Name : btnotificationresult.h +* Part of : bluetoothengine / btnotif +* Description : Abstract interface for receiving the result of a user query. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFICATIONRESULT_H +#define BTNOTIFICATIONRESULT_H + +class CHbSymbianVariantMap; + +/** + * MBTNotificationResult returns the result from a user query. + * + * + * @since Symbian^4 + */ +class MBTNotificationResult + { + +public: + + /** + * Handle an intermediate result from a user query. + * This function is called if the user query passes information + * back before it has finished i.e. is dismissed. The final acceptance/ + * denial of a query is passed back in MBRNotificationClosed. + * + * @since Symbian^4 + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRDataReceived( CHbSymbianVariantMap& aData ) = 0; + + + /** + * The notification is finished. The resulting data (e.g. user input or + * acceptance/denial of the query) is passed back here. + * + * @since Symbian^4 + * @param aErr KErrNone or one of the system-wide error codes. + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData ) = 0; + + }; + + +#endif // BTNOTIFICATIONRESULT_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/btnotifpairinghelper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifpairinghelper.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,471 @@ +/* +* ============================================================================ +* Name : btnotifpairinghelper.h +* Part of : bluetoothengine / btnotif +* Description : Helper class for processing pairing requests and results, as extended functionality for CBTNotifConnection. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFPAIRINGHELPER_H +#define BTNOTIFPAIRINGHELPER_H + +#include +#include +#include +#include + +#include "bluetoothnotification.h" +#include "bluetoothtrace.h" + +class CBTNotifConnection; +class CBTNotifConnectionTracker; +class CBTDevice; + + +/** + * Helper class for performing pairing-related operations. + * + * This class is constructed only when there is a pairing-related event, + * and destructed after completion. Pairing-related events are bonding + * (outgoing bonding request from an application), pairing notifiers + * (PIN input i.e. legacy pairing, numeric comparison and passkey display), + * and Just Works pairing completion. + * + * The structure of operations is as follows: each event is initiated through + * StartXxL() operation, and finished with CompleteXxL(), there is also a + * CancelXxL() operation where needed. In addition there are the base class virtual + * functions, a few helper functions and HandleAuthenticationCompleteL, which + * processes a baseband authentication result. The same structure applies to + * suboperations, such as StartTrustedQueryL and CompleteTrustedQueryL. + * + * For bonding, there is StartBondingL, CompleteBondingL() CancelBondingL(); + * for pairing notifiers there is StartPairingNotifierL(), + * CancelPairingNotifierL(), CompletePairingNotifierL() and also + * UpdatePairingNotifierL(). For Just Works processing, there is + * StartJustWorksProcessingL(), CancelJustWorksProcessingL() and + * CompleteJustWorksProcessingL(). + * + * The design of this class is focussed on structure and maintainability first. + * Duplicate (state) information is kept to a minimum. And memory usage comes + * before processing. Pairing is an infrequent operation, and this class is + * only instantiated when there is pairing-related processing, so extreme + * focus on memory or processing efficiency would have relatively little effect. + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifPairingHelper ) : public CBase, + public MBTNotificationResult, + public MBtSimpleActiveObserver + { + +public: + + /** Enumeration identifying the stage of the pairing operation. */ + enum TPairingOp + { + EIdle, + EAcceptPairing, + ELegacyPairing, + ESspPairing, + EJustWorksPairing, + EAutoPairing, + EPostPairingOperations, // Marks the queries and notes which follow + // the real pairing input from the user. + EDedicatedBonding, + EUnpairing, + EAwaitingPairingResult, + EShowPairingSuccess, + EShowPairingFailure, + EQueryTrust, + EBlocking, + EPairingCancelled + }; + + /** + * Two-phased constructor. + * @param aConnection Pointer to the parent. + * @param aDevice Pointer to information of the remote device. + * aParam aTracker Pointer to the connection tracker. + */ + static CBTNotifPairingHelper* NewL( CBTNotifConnection* aConnection, + CBTNotifConnectionTracker* aTracker ); + + /** + * Destructor. + */ + virtual ~CBTNotifPairingHelper(); + + /** + * Get the address of the remote device for this connection. + * + * @since Symbian^4 + * @param aProfile The profile identifying the service. + */ + inline CBTNotifPairingHelper::TPairingOp CurrentOperation() const + { return iOperation; } + + /** + * The baseband authentication has completed, handle the result. + * + * @since Symbian^4 + * @param aError The result of the authentication procedure. + */ + void HandleAuthenticationCompleteL( TInt aError ); + + /** + * Start a bonding operation with the remote device. + * + * @since Symbian^4 + * @param aMessage The handle of the message from the client. + */ + void StartBondingL( TInt aHandle ); + + /** + * Cancel an ongoing bonding operation with the remote device. + * + * @since Symbian^4 + */ + void CancelBondingL(); + + /** + * Handle a notifier request for pairing with the remote device + * of this connection. + * + * @since Symbian^4 + * @param aUid The UID of the notifier for this pairing request. + * @param aParams The parameters for this request from the client. + */ + void StartPairingNotifierL( TInt aUid, const TDesC8& aParams ); + + /** + * Update an outstanding request for this connection. + * + * @since Symbian^4 + * @param aUid The UID of the notifier for this update. + * @param aParams The updated parameters for this request from the client. + */ + void UpdatePairingNotifierL( TInt aUid, const TDesC8& aParams ); + + /** + * Cancel an outstanding request for this connection. + * + * @since Symbian^4 + * @param aUid The UID of the notifier for this pairing request. + */ + void CancelPairingNotifierL( TInt aUid ); + + /** + * Start the processing of a completed Just Works pairing. + * This needs special attention, as this class is not notified + * other than by observing the registry, and the user is not + * notified otherwise either (which is the point of this association + * model). It needs to be verified that the pairing is related to + * a service access, as dedicated bonding should not be possible + * (for devices that do not have any IO capabilities). + * + * @since Symbian^4 + * @param aMessage The handle of the message from the client. + */ + void StartJustWorksProcessingL(); + + /** + * Cancel the processing of a completed Just Works pairing. + * + * @since Symbian^4 + */ + void CancelJustWorksProcessingL(); + +// from base class MBTNotificationResult + + /** + * From MBTNotificationResult. + * Handle an intermediate result from a user query. + * This function is called if the user query passes information + * back before it has finished i.e. is dismissed. The final acceptance/ + * denial of a query is passed back in MBRNotificationClosed. + * + * @since Symbian^4 + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRDataReceived( CHbSymbianVariantMap& aData ); + + /** + * From MBTNotificationResult. + * The notification is finished. The resulting data (e.g. user input or + * acceptance/denial of the query) is passed back here. + * + * @since Symbian^4 + * @param aErr KErrNone or one of the system-wide error codes. + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData ); + +// from base class MBtSimpleActiveObserver + + /** + * From MBtSimpleActiveObserver. + * Callback to notify that an outstanding request has completed. + * + * @since Symbian^4 + * @param aActive The active object helper that completed this request. + * @param aStatus The status of the completed request. + */ + virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); + + /** + * From MBtSimpleActiveObserver. + * Callback for handling cancelation of an outstanding request. + * + * @since Symbian^4 + * @param aId The ID that identifies the outstanding request. + */ + virtual void CancelRequest( TInt aRequestId ); + + /** + * Callback to notify that an error has occurred in RunL. + * + * @param aActive Pointer to the active object that completed. + * @param aError The error occurred in RunL. + */ + virtual void HandleError( CBtSimpleActive* aActive, TInt aError ); + +private: + + /** + * C++ default constructor. + */ + CBTNotifPairingHelper( CBTNotifConnection* aConnection, + CBTNotifConnectionTracker* aTracker ); + + /** + * Symbian 2nd-phase constructor. + */ + void ConstructL(); + + /** + * Process the user input and complete the outstanding pairing request. + * + * @since Symbian^4 + * @param aError The result off the notification. + * @param aResult The user response; ETrue if the user accepted the query, + * otherwise EFalse. + * @param aData The data returned from the notification dialog. + */ + void CompletePairingNotifierL( TInt aError, TBool aResult, const TDesC8& aData ); + + /** + * Completes a bonding operation. + * + * @since Symbian^4 + * @param aError The result of the bonding attempt. + */ + void CompleteBondingL( TInt aError ); + + /** + * Completes a bonding operation. + * + * @since Symbian^4 + * @param aError The result of the bonding attempt. + */ + void CompleteJustWorksProcessingL( TInt aError ); + + /** + * Ask the user to allow incoming pairing. + * + * @since Symbian^4 + */ + void StartAcceptPairingQueryL(); + + /** + * Process the user input and for accepting an incoming pairing and + * continue with the outstanding pairing request. + * + * @since Symbian^4 + * @param aError The result of the notification. + * @param aResult The user response; ETrue if the user accepted the query, + * otherwise EFalse. + */ + void CompleteAcceptPairingQueryL( TInt aError, TBool aResult ); + + /** + * Ask the user to set the device as trusted. + * + * @since Symbian^4 + * @param aData The data returned from the notification dialog. + */ + void StartTrustedQueryL(); + + /** + * Process the user input for setting the device as trusted. + * + * @since Symbian^4 + * @param aError The result of the notification. + * @param aResult The user response; ETrue if the user accepted the query, + * otherwise EFalse. + */ + void CompleteTrustedQueryL( TInt aError, TBool aResult ); + + /** + * Parse the parameters of a request for pairing. + * This function also returns values to use for dialog config, and sets + * the operation state member variable (iOperation). + * + * @since Symbian^4 + * @param aLocallyInitiated On return, will be set to ETrue if the pairing + * was initiated by us. + * @param aNumVal On return, this descriptor will contain a number to use in + * the pairing dialog. The meaning depends on the type of pairing. + * @param aDialogType On return, will contain the dialog type. + * @param aResourceId On return, will contain the resource id. + */ + void ParseNotifierReqParamsL( TBool& aLocallyInitiated, TDes& aNumVal, + TBluetoothDialogParams::TBTDialogType& aDialogType, + TBTDialogResourceId& aResourceId ); + + /** + * Parse the parameters of a request for pairing using pin query. + * + * @since Symbian^4 + * @param aLocallyInitiated On return, will be set to ETrue if the pairing + * was initiated by us. + * @param aNumVal On return, this will contain the minimum passcode length. + */ + void ParsePinCodeReqParamsL( TBool& aLocallyInitiated, TUint& aNumVal ); + + /** + * Parse the parameters of a request for pairing using numeric comparison. + * + * @since Symbian^4 + * @param aLocallyInitiated On return, will be set to ETrue if the pairing + * was initiated by us. + * @param aNumVal On return, this descriptor will contain the passkey to + * show to the user. + */ + void ParseNumericCompReqParamsL( TBool& aLocallyInitiated, TDes& aNumVal ); + + /** + * Parse the parameters of a request for pairing using passkey display. + * + * @since Symbian^4 + * @param aLocallyInitiated On return, will be set to ETrue if the pairing + * was initiated by us. + * @param aNumVal On return, this descriptor will contain the passkey to + * show to the user. + */ + void ParsePasskeyDisplayReqParamsL( TBool& aLocallyInitiated, TDes& aNumVal ); + + /** + * Check if we can guess the PIN and complete the notifier without + * user interaction. + * + * @since Symbian^4 + * @param aLocallyInitiated ETrue if we initiated the pairing, otherwise EFalse. + * @param aNumVal The minimum lenght of the passcode. + */ + void CheckAutoPairingL( TBool aLocallyInitiated, const TDesC& aNumVal ); + + /** + * Get a notification and configure it according to the current operation. + * + * @since Symbian^4 + * @param aType The notification type. + * @param aResourceId Identifier for the resource to display. + */ + void PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, + TBTDialogResourceId aResourceId ); + + /** + * Handle the result from a notification that is finished. + * + * @since Symbian^4 + * @param aErr KErrNone or one of the system-wide error codes. + * @param aData The returned data. The actual format + * is dependent on the actual notifier. + */ + void NotificationClosedL( TInt aError, const TDesC8& aData ); + +private: // data + + /** + * Identifier for the current operation. + */ + TPairingOp iOperation; + + /** + * UID of the notifier pairing dialog request. + */ + TInt iNotifierUid; + + /** + * Handle to the client message for dedicated bonding. Also serves as flag + * indicating that we are performing dedicated bonding. + */ + TInt iDedicatedBonding; + + /** + * Subsession with pairing server for dedicated bonding. + */ + RBluetoothDedicatedBondingInitiator iBondingSession; + + /** + * Handle for general bonding. + */ + RBTPhysicalLinkAdapter iBondingSocket; + + /** + * Buffer containing the parameters of the client message. + * Own. + */ + HBufC8* iParams; + + /** + * Active object helper for outgoing bonding. + * Own. + */ + CBtSimpleActive* iBondingActive; + + /** + * Pointer to the data record of the remote device. + * Not own. + */ + CBTDevice* iDevice; + + /** + * Pointer to an outstanding user interaction. + * Not own. + */ + CBluetoothNotification* iNotification; + + /** + * Pointer to the class that we are helping. + * Not own. + */ + CBTNotifConnection* iConnection; + + /** + * Pointer to our grandparent. + * Not own. + */ + CBTNotifConnectionTracker* iTracker; + + BTUNITTESTHOOK + + }; + +#endif // BTNOTIFPAIRINGHELPER_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/btnotifserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifserver.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,289 @@ +/* +* ============================================================================ +* Name : btnotifserver.h +* Part of : bluetoothengine / btnotif +* Description : Server class for handling commands from clients, and the +* central class in btnotif thread. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFSERVER_H +#define BTNOTIFSERVER_H + + +#include +#include + +#include "bluetoothtrace.h" + +class CBTNotifConnectionTracker; +class CBTNotifSettingsTracker; +class CBTNotificationManager; +class CBTNotifDeviceSelector; +class CBtDevRepository; + +class CbtnotifServerTest; // ToDo: shall be refactored under compile flag? + +/** + * Utility function for panicking the server. + * + * @since Symbian^4 + * @param aReason The panic reason code. + */ +void PanicServer( TInt aReason ); + +/** + * Utility function for panicking the server. + * + * @since Symbian^4 + * @param aMessage The handle to the client side. + * @param aReason The panic reason code. + */ +void PanicClient( const RMessage2& aMessage, TInt aReason ); + +/** BTNotif panic codes */ +enum TBTNotifServerPanic + { + EBTNotifPanicUnknown, + EBTNotifPanicCorrupt, + EBTNotifPanicMissing, + EBTNotifPanicNullMember, + EBTNotifPanicBadState, + EBTNotifPanicBadArgument, + EBTNotifPanicBadResult + }; + +/** Convenience macro for indicating unimplemented events */ +#define NOTIF_NOTIMPL +//{ __ASSERT_ALWAYS( 1, PanicServer( EBTNotifPanicNotImplemented ) ); } +/** Convenience macro for indicating unhandled events */ +#define NOTIF_NOTHANDLED( cond ) +//{ __ASSERT_ALWAYS( cond, PanicServer( EBTNotifPanicNotHandled ) ); } + + +/** + * CBTNotifServer handles notifications and also maintains state information related to + * the local device as well as remote devices. + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifServer ) : public CPolicyServer + { + +public: + + /** + * Two-phased constructor. + */ + static CBTNotifServer* NewLC(); + + /** + * Destructor. + */ + virtual ~CBTNotifServer(); + + /** + * Called when the BT power state changes. + * + * @since Symbian^4 + * @param aState The new BT power state. + */ + void HandlePowerStateChangeL( TBTPowerStateValue aState ); + + /** + * Called by a session during creation, to keep track of the number + * of active sessions. + * + * @since Symbian^4 + */ + void AddSession(); + + /** + * Called by a session during destruction, to keep track of the number + * of active sessions. + * + * @since Symbian^4 + */ + void RemoveSession(); + + /** + * Returns a handle to the settings tracker. + * + * @since Symbian^4 + * @param Pointer to the settings tracker. + */ + inline CBTNotifSettingsTracker* SettingsTracker() const + { return iSettingsTracker; } + + /** + * Returns a handle to the connection tracker. + * + * @since Symbian^4 + * @param Pointer to the connection tracker. + */ + inline CBTNotifConnectionTracker* ConnectionTracker() const + { return iConnectionTracker; } + + /** + * Returns a handle to the notification manager. + * + * @since Symbian^4 + * @param Pointer to the notification manager. + */ + inline CBTNotificationManager* NotificationManager() const + { return iNotificationMgr; } + + CBtDevRepository& DevRepository(); + + CBTNotifDeviceSelector& DeviceSelectorL(); + + /** + * Searches for a specific client message from a message handle + * on all active sessions, and complete the message with the + * specified reason code. + * + * @since Symbian^4 + * @param aHandle The handle identifying the message. + * @param aReply Data to write back to the client. + * @return KErrNone on success; KErrNotFound if the message is not found. + */ + TInt CompleteMessage( TInt aHandle, TInt aReason, const TDesC8& aReply ); + + /** + * Searches for and returns a specific client message from a message + * handle on all active sessions. + * + * @since Symbian^4 + * @param aHandle The handle identifying the message. + * @return Pointer to the message, NULL if not found. + */ + const RMessage2* FindMessageFromHandle( TInt aHandle ); + + /** + * Searches for and returns a specific client message from a message + * UID on all active sessions. + * The use of this method assumes that there can be only one message + * outstanding for a specific UID. This is enforced by RNotifier backend. + * + * @since Symbian^4 + * @param aUid The UID identifying the message. + * @return Pointer to the message, NULL if not found. + */ + const RMessage2* FindMessageFromUid( TInt aUid ); + +// from base class CPolicyServer + + /** + * From CPolicyServer. + * Creates and returns a server-side session object. + * + * @since Symbian^4 + * @param aVersion The version information supplied by the client. + * @param aMessage Represents the details of the client request that + * is requesting the creation of the session. + * @return A pointer to the newly created server-side session object. + */ + virtual CSession2* NewSessionL( const TVersion& aVersion, const RMessage2& aMessage ) const; + +private: + + CBTNotifServer(); + + void ConstructL(); + + /** + * Asynchronous second-phase constructor. This function is called asynchronously + * from ConstructL, to facilitate short initial construction, and allow construction + * of e.g. session to BTEngine. So in fact this is a third-phase constructor. + * + * @since Symbian^4 + */ + void AsyncConstructL(); + + void CheckIdle( TBTPowerStateValue aState ); + + /** + * Callback function for asynchronous construction. + * + * @since Symbian^4 + * @param aPtr Pointer to server instance. + */ + static TInt AsyncConstructCb( TAny* aPtr ); + + static TInt ShutdownTimeout( TAny* aPtr ); + +private: // data + + /** + * Counter for the number of active sessions. + */ + TInt iSessionCount; + + /** + * Helper class for tracking settings. + * Own. + */ + CBTNotifSettingsTracker* iSettingsTracker; + + /** + * Helper class for tracking connections. + * Own. + */ + CBTNotifConnectionTracker* iConnectionTracker; + + /** + * Helper class for managing the actual notifications. + * Own. + */ + CBTNotificationManager* iNotificationMgr; + + /** + * Remote device repository. + * Singleton in btnotifsrv. This is useful + * for getting the correct name for displaying in UI + * without the need getting the device everytime + * when a name is needed. + * Pairing handling also needs this repository to drive + * the logic flow. + */ + CBtDevRepository* iDevRep; + + /** + * Helper class for device searching and selection. + * Own. + */ + CBTNotifDeviceSelector* iDevSelector; + + /** + * Callback for asynchronous processing. + * Own. + */ + CAsyncCallBack* iAsyncCb; + + /** + * Timer for various timeouts. + * Own. + */ + CDeltaTimer* iTimer; + + TDeltaTimerEntry iShutdownTimerEntry; + + BTUNITTESTHOOK + + }; + +#endif // BTNOTIFSERVER_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/btnotifserversecpolicy.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifserversecpolicy.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,67 @@ +/* +* ============================================================================ +* Name : btnotifserversecpolicy.h +* Part of : bluetoothengine / btnotif *** Info from the SWAD +* Description : Security policy for btnotif client-server interface. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFSRVSECPOLICY_H +#define BTNOTIFSRVSECPOLICY_H + +/** Number of ranges in btnotif security policy */ +const TInt KBTNotifRangeCount = 4; + +/** Ranges of btnotif command opcodes */ +const TInt KBTNotifRanges[ KBTNotifRangeCount ] = + { + 0, // Range 0: 0 - EBTNotifMinValue (Out of range) + 10, // Range 1: All commands requiring no access control + 30, // Range 2: All commands requiring local services + // More ranges may be added here + 50 // Range 3: Out of range + }; + +/** Mapping of ranges to policies */ +const TUint8 KBTNotifElementsIndex[ KBTNotifRangeCount ] = + { + CPolicyServer::ENotSupported, // applies to 0th range (out of range) + CPolicyServer::EAlwaysPass, // no policy for the 1st range + 0, // policy 0 applies to 2nd range + CPolicyServer::ENotSupported // applies to xth range(out of range) + }; + +/** BTEng security policies, applied on a range of commands */ +const CPolicyServer::TPolicyElement KBTNotifPolicyElements[] = + { + { _INIT_SECURITY_POLICY_C1( ECapabilityLocalServices ), + CPolicyServer::EFailClient + } //policy 0, for now on all operations + // More policies may be added here + }; + +/** BTNotif security policy package (combining all the above) */ +const CPolicyServer::TPolicy KBTNotifServerPolicy = + { + CPolicyServer::EAlwaysPass, // Connection attempts may pass + KBTNotifRangeCount, // Number of ranges + KBTNotifRanges, // Array of ranges + KBTNotifElementsIndex, // Mapping of ranges to policies + KBTNotifPolicyElements // Array of policies + }; + +#endif // BTNOTIFSRVSECPOLICY_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/btnotifsession.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifsession.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,130 @@ +/* +* ============================================================================ +* Name : btnotifsession.h +* Part of : bluetoothengine / btnotif +* Description : Session class for handling commands from clients. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFSESSION_H +#define BTNOTIFSESSION_H + +#include "btnotifserver.h" + +/** + * CBTNotifSession maintains a session with a client. + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifSession ) : public CSession2 + { + +public: + + /** + * Two-phased constructor. + */ + static CBTNotifSession* NewL(); + + /** + * Destructor. + */ + virtual ~CBTNotifSession(); + +// from base class CSession2 + + /** + * From CSession2. + * Receives a message from a client. + * + * @since Symbian^4 + * @param aMessage The message containing the details of the client request. + */ + virtual void ServiceL( const RMessage2& aMessage ); + + /** + * From CSession2. + * Completes construction of the session. + * + * @since Symbian^4 + */ + virtual void CreateL(); + + /** + * Complete a client message from a message handle. + * + * @since Symbian^4 + * @param aHandle The handle identifying the message. + * @param aReason The reason code to complete the message with. + * @param aReply Data to write back to the client. + * @return KErrNone on success; KErrNotFound if the message is not found. + */ + TInt CompleteMessage( TInt aHandle, TInt aReason, const TDesC8& aReply ); + + /** + * Find a message identified by an RMessage2 handle. + * + * @since Symbian^4 + * @param aHandle The handle identifying the message. + * @return The message. + */ + const RMessage2* FindMessageFromHandle( TInt aHandle ) const; + + /** + * Find a message identified by an RNotifier notifier UID. + * + * @since Symbian^4 + * @param aUid The UID identifying the message. + * @return The message. + */ + const RMessage2* FindMessageFromUid( TInt aUid ) const; + +private: + + CBTNotifSession(); + + void ConstructL(); + + /** + * Returns a handle to our server. + * + * @since Symbian^4 + * @param Pointer to our server. + */ + inline CBTNotifServer* Server() const + { return (CBTNotifServer*) CSession2::Server(); } + + /** + * Processes a message from a client. + * + * @since Symbian^4 + * @param aMessage The message containing the details of the client request. + */ + void DispatchMessageL( const RMessage2& aMessage ); + +private: // data + + /** + * Array of messages currently being processed. + */ + RArray iMessageQ; + + BTUNITTESTHOOK + + }; + +#endif // BTNOTIFSESSION_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/btnotifsettingstracker.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/btnotifsettingstracker.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,172 @@ +/* +* ============================================================================ +* Name : btnotifsettingstracker.h +* Part of : BTProximity / BTProximity +* Description : Class for tracking Bluetooth settings, and also for +* handling notes unrelated to specific connection. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFSETTINGSTRACKER_H +#define BTNOTIFSETTINGSTRACKER_H + + +#include +#include + +#include "bluetoothnotification.h" + +class CBTNotifServer; + +/** + * CBTNotifSettingsTracker keeps track of local device settings + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifSettingsTracker ) : public CBase, + public MBTEngSettingsObserver, + public MBTNotificationResult + { + +public: + + /** + * Two-phased constructor. + * @param aServer Pointer to our parent + */ + static CBTNotifSettingsTracker* NewL( CBTNotifServer* aServer ); + + /** + * Destructor. + */ + virtual ~CBTNotifSettingsTracker(); + + /** + * Return the current power state + * + * @since Symbian^4 + * @return The current power state. + */ + inline TBTPowerStateValue GetPowerState() const + { return iPowerState; } + + /** + * Processes a message from a notifier client related to settings. + * + * @since Symbian^4 + * @param aMessage The message containing the details of the client request. + */ + void DispatchNotifierMessageL( const RMessage2& aMessage ); + + /** + * Cancels an oustanding message from a notifier client related to settings. + * + * @since Symbian^4 + * @param aMessage The message containing the details of the original client request. + */ + void CancelNotifierMessageL( const RMessage2& aMessage ); + +// from base class MBTEngSettingsObserver + + /** + * From MBTEngSettingsObserver. + * Provides notification of changes in the power state + * of the Bluetooth hardware. + * + * @since Symbian^4 + * @param aState EBTPowerOff if the BT hardware has been turned off, + * EBTPowerOn if it has been turned off. + */ + virtual void PowerStateChanged( TBTPowerStateValue aState ); + + /** + * From MBTEngSettingsObserver. + * Provides notification of changes in the discoverability + * mode of the Bluetooth hardware. + * + * @since Symbian^4 + * @param aState EBTDiscModeHidden if the BT hardware is in hidden mode, + * EBTDiscModeGeneral if it is in visible mode. + */ + virtual void VisibilityModeChanged( TBTVisibilityMode aState ); + +// from base class MBTNotificationResult + + /** + * From MBTNotificationResult. + * Handle an intermediate result from a user query. + * This ffunction is called if the user query passes information + * back before it has finished i.e. is dismissed. The final acceptance/ + * denial of a query is passed back in MBRNotificationClosed. + * + * @since Symbian^4 + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRDataReceived( CHbSymbianVariantMap& aData ); + + /** + * From MBTNotificationResult. + * The notification is finished. The resulting data (e.g. user input or + * acceptance/denial of the query) is passed back here. + * + * @since Symbian^4 + * @param aErr KErrNone or one of the system-wide error codes. + * @param aData the returned data. The actual format + * is dependent on the actual notifier. + */ + virtual void MBRNotificationClosed( TInt aError, const TDesC8& aData ); + +private: + + CBTNotifSettingsTracker( CBTNotifServer* aServer ); + + void ConstructL(); + +private: // data + + /** + * Local copy of current power state. + */ + TBTPowerStateValue iPowerState; + + /** + * Local copy of current visibility mode. + */ + TBTVisibilityMode iVisibilityMode; + + /** + * ?description_of_pointer_member + * Own. + */ + CBTEngSettings* iSettings; + + /** + * Pointer to an outstanding user interaction. + * Not own. + */ + CBluetoothNotification* iNotification; + + /** + * Reference to our parent the server class. + * Not own. + */ + CBTNotifServer* iServer; + + }; + +#endif // BTNOTIFSETTINGSTRACKER_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/inc/traceconfig.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/inc/traceconfig.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,126 @@ +/* +* ============================================================================ +* Name : traceconfig_template.h +* Part of : BluetoothUI / bluetoothuimodel *** Info from the SWAD +* Description : Configuration of debug tracing in btnotif +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ +#ifndef BLUETOOTHTRACECONFIG_H +#define BLUETOOTHTRACECONFIG_H + +/* +Sample usage: + void testTracing() + { + BOstrace0( TRACE_FATAL, TNAME_DEVLIST_1, "BOstrace0" ); + BOstrace1( TRACE_IMPORTANT, TNAME_DEVLIST_2, "BOstrace1 %d", 123 ); + _LIT(String, "\"Symbian Descriptor\""); + TPtrC ptr(String); + TBuf<20> buf(ptr); + BOstraceExt1( TRACE_NORMAL, TNAME_DEVLIST_3, "BOstraceExt1 %S", &ptr); + BOstraceExt2( TRACE_API, TNAME_DEVLIST_4, "BOstraceExt2 %d %S", 456, &ptr ); + BOstraceExt3( TRACE_FLOW, TNAME_DEVLIST, "BOstraceExt3 0x%x %d %S", 128, 256, &ptr ); + BOstraceExt4( TRACE_DETAILED, TNAME_DEVL_5IST, "BOstraceExt4 0x%x %d %S %S", 128, 256, &ptr, &buf ); + BOstraceExt5( TRACE_DEBUG, TNAME_DEVLIST_6, "BOstraceExt5 0x%x %d %S %S, %b", 128, 256, &ptr, &buf, 512 ); + BOstraceFunctionEntry0( TNAME_DEVLIST_7 ); + BOstraceFunctionEntry1( TNAME_DEVLIST_8, 0x00abcdef ); + BOstraceFunctionEntryExt(TNAME_DEVLIST_9, 0xdeadbeef, 123); + BOstraceFunctionExit0( TNAME_DEVLIST_9 ); + BOstraceFunctionExit1( TNAME_DEVLIST_10, 0x00beebee ); + BOstraceFunctionExitExt(TNAME_DEVLIST_11, 0x00badbed, -1); + BOstraceEventStart0( TNAME_DEVLIST_12, "BOstraceEventStart0" ); + BOstraceEventStart1( TNAME_DEVLIST_13, "BOstraceEventStart1", 789 ); + BOstraceEventStop( TNAME_DEVLIST_14, "BOstraceEventStop" ); + BOstraceState0( TNAME_DEVLIST_15, "connection state", 1 ); + BOstraceState1( TNAME_DEVLIST_16, "audio state", 2, 0xdeadbeef ); + BtTraceBlock( + for (int i = 0; i < 5; ++i) { + BOstrace1( TRACE_IMPORTANT, TNAME_DEVLIST_, "BtTraceBlock counter(1-5): %d", i+1 ); + }); + QString str("\"Qt String\""); + BtTraceQString0( TRACE_NORMAL, TNAME_DEVLIST_17, str); + BtTraceQString1( TRACE_NORMAL, TNAME_DEVLIST_18, "additional text;", str); + TBTDevAddr addr; + addr.SetReadable(_L("0060576ff376")); + BtTraceBtAddr0( TRACE_NORMAL, TNAME_DEVLIST_19, addr ); + BtTraceBtAddr1( TRACE_NORMAL, TNAME_DEVLIST_20, "additional trace;", addr ); + } + + */ + +// At early development phase, tracing is activated +#ifdef _DEBUG +#define BLUETOOTHTRACE_ENABLED +#endif //_DEBUG + +/* + * Tracing media configuration + */ +#ifdef BLUETOOTHTRACE_ENABLED + #ifdef __WINS__ + #define BLUETOOTHTRACE_MEDIA_FILE + #else + // RDEBUG is used for tracing output before we migrate to OST tracing. + #define BLUETOOTHTRACE_MEDIA_RDEBUG + // #define BLUETOOTHTRACE_MEDIA_OST + #endif // __WINS__ +#endif //BLUETOOTHTRACE_ENABLED + +/* + * Configuration of tracing to file + */ +#ifdef BLUETOOTHTRACE_MEDIA_FILE + +_LIT( KLogFile, "btenglog.txt" ); +_LIT( KLogDir, "bt" ); + +#endif //BLUETOOTHTRACE_MEDIA_FILE + +/* + * Configuration of tracing using RDebug + */ +#ifdef BLUETOOTHTRACE_MEDIA_RDEBUG + +#endif //BLUETOOTHTRACE_MEDIA_RDEBUG + +/* + * Configuration of tracing using OST + */ +#ifndef BLUETOOTHTRACE_MEDIA_OST + +/** + * Group-mapping aligning with OST groups. + * The purpose of using groups is to ease migrating tracing from legacy logging to OST. + */ +#define TRACE_FATAL "[FATAL]" +#define TRACE_IMPORTANT "[IMPTT]" +#define TRACE_NORMAL "[NORML]" +#define TRACE_API "[ API ]" +#define TRACE_FLOW "[FLOW ]" +#define TRACE_STATE "[STATE]" +#define TRACE_DETAILED "[DETLD]" +#define TRACE_DEBUG "[DEBUG]" +#define TRACE_PERFORMANCE "[PFMAN]" + +/** + * Component Identifier to be written into traces: + */ +_LIT(KComponentName, "[BtNotif]"); + +#endif //BLUETOOTHTRACE_MEDIA_OST + +#endif // BLUETOOTHTRACECONFIG_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/src/bluetoothnotification.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/bluetoothnotification.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,440 @@ +/* +* ============================================================================ +* Name : bluetoothnotification.cpp +* Part of : bluetoothengine / btnotif +* Description : Class for managing an actual user notification or query. +* It hides UI framework-specifics in a private class. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "bluetoothnotification.h" +#include +#include "btnotificationmanager.h" +#include "btnotifserver.h" +#include "bluetoothtrace.h" +#include // for debugging + +/** Identifier of Bluetooth device dialog plug-in. */ +_LIT( KBTDevDialogId, "com.nokia.hb.btdevicedialog/1.0" ); +/** Key name of result. */ +_LIT( KBTDevDialogResult, "result" ); +_LIT( KBTDevDialogInput, "input" ); + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBluetoothNotification::CBluetoothNotification( CBTNotificationManager* aManager ) +: iManager( aManager ) + { + } + + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBluetoothNotification::ConstructL() + { + iNotificationData = CHbSymbianVariantMap::NewL(); + iDialog = CHbDeviceDialogSymbian::NewL(); + } + + +// --------------------------------------------------------------------------- +// NewL. +// --------------------------------------------------------------------------- +// +CBluetoothNotification* CBluetoothNotification::NewL( + CBTNotificationManager* aManager ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + CBluetoothNotification* self = new( ELeave ) CBluetoothNotification( aManager ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + return self; + } + + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBluetoothNotification::~CBluetoothNotification() +{ + BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); + delete iDialog; + delete iNotificationData; + delete iReturnData; + BOstraceFunctionExit1( DUMMY_DEVLIST, this ) +} + + +// --------------------------------------------------------------------------- +// Resets the notification, clean all the internals. +// --------------------------------------------------------------------------- +// +void CBluetoothNotification::Reset() + { + BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); + iType = TBluetoothDialogParams::EInvalidDialog; + iResourceId = ENoResource; + iObserver = NULL; + iDialog->Cancel(); + iDialog->SetObserver( NULL ); // Not interested in a callback anymore. + delete iNotificationData; + iNotificationData = NULL; + iNotificationData = CHbSymbianVariantMap::NewL(); + delete iReturnData; + iReturnData = NULL; + iReturnData = CHbSymbianVariantMap::NewL(); + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Sets the data to be shown to the user. +// --------------------------------------------------------------------------- +// +TInt CBluetoothNotification::SetData( TInt aDataType, const TDesC& aData ) + { + TRAPD( err, SetDataL( aDataType, aData ) ); + return (int) err; + } + + +// --------------------------------------------------------------------------- +// Sets the data to be shown to the user. +// --------------------------------------------------------------------------- +// +TInt CBluetoothNotification::SetData( TInt aDataType, TInt aData ) + { + TRAPD( err, SetDataL( aDataType, aData ) ); + return (int) err; + } + +// --------------------------------------------------------------------------- +// Updates the data to be shown to the user. +// --------------------------------------------------------------------------- +// +TInt CBluetoothNotification::Update( const TDesC& aData ) + { + BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); + (void) aData; + int ret = iDialog->Update( *iNotificationData ); + delete iNotificationData; + iNotificationData = NULL; + iNotificationData = CHbSymbianVariantMap::NewL(); + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + return ret; + } + + +// --------------------------------------------------------------------------- +// Show the notification, which means that it is added to the queue. +// --------------------------------------------------------------------------- +// +TInt CBluetoothNotification::Show() + { + BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); + TRAPD( err, SetDataL( TBluetoothDialogParams::EDialogType, iType ) ); + if( !err ) + { + TRAP( err, SetDataL( TBluetoothDialogParams::EResource, iResourceId ) ); + } + delete iReturnData; + iReturnData = NULL; + if( !err ) + { + TRAP( err, iReturnData = CHbSymbianVariantMap::NewL() ); + } + if( !err ) + { + err = iDialog->Show( KBTDevDialogId(), *iNotificationData, this ); + } + delete iNotificationData; + iNotificationData = NULL; + iNotificationData = CHbSymbianVariantMap::NewL(); + + const TInt KPluginErr = CHbDeviceDialogSymbian::EPluginErrors + 1; + if( err == KPluginErr ) + { + err = KErrNotFound; + } + BOstraceFunctionExitExt( DUMMY_DEVLIST, this, err ); + return err; + } + + +// --------------------------------------------------------------------------- +// Stop showing the notification. +// --------------------------------------------------------------------------- +// +TInt CBluetoothNotification::Close() + { + BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); + iDialog->Cancel(); + iManager->ReleaseNotification( this ); + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + return KErrNone; + } + + +// --------------------------------------------------------------------------- +// Sets the data to be shown to the user. +// --------------------------------------------------------------------------- +// +void CBluetoothNotification::SetDataL( TInt aType, const TDesC& aData ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aType ); + TBuf16<6> key; + TInt err = 0; + CHbSymbianVariant* value = NULL; + switch( aType ) + { + case TBluetoothDialogParams::EAddress: + case TBluetoothDeviceDialog::EDeviceName: + case TBluetoothDeviceDialog::EAdditionalDesc: + case TBluetoothDialogParams::EDialogTitle: + key.Num(aType); + value = CHbSymbianVariant::NewL( (TAny*) &aData, CHbSymbianVariant::EDes ); + BtTraceBlock( + TBuf<32> buf; + switch (aType) { + case TBluetoothDialogParams::EAddress: + _LIT(KAddress,"EAddress"); + buf.Append(KAddress); + break; + case TBluetoothDeviceDialog::EDeviceName: + _LIT(KDeviceName,"EDeviceName"); + buf.Append(KDeviceName); + break; + case TBluetoothDeviceDialog::EAdditionalDesc: + _LIT(KAdditionalDesc,"EAdditionalDesc"); + buf.Append(KAdditionalDesc); + break; + } + TPtrC p(buf); + TPtrC16 *ptr = (TPtrC16 *)value->Data(); + BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, "SetData [%S] = [%S]", &p, ptr); + ); + err = iNotificationData->Add( key, value ); // Takes ownership of value + if ( err ) + { + // Note: need a proper exception handling. + // NOTIF_NOTHANDLED( err ) + } + break; + case TBluetoothDialogParams::EResource: + case TBluetoothDeviceDialog::EDeviceClass: + case TBluetoothDeviceDialog::EAdditionalInt: + PanicServer( EBTNotifPanicBadArgument ); + break; + case TBluetoothDialogParams::ENoParams: + case TBluetoothDeviceDialog::ENoParams: + default: + break; + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Sets the data to be shown to the user. +// --------------------------------------------------------------------------- +// +void CBluetoothNotification::SetDataL( TInt aType, TInt aData ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aType ); + TBuf<6> key; + TInt err = 0; + CHbSymbianVariant* value = NULL; + switch( aType ) + { + case TBluetoothDialogParams::EDialogType: + case TBluetoothDialogParams::EResource: + case TBluetoothDialogParams::EDialogTitle: + case TBluetoothDeviceDialog::EDeviceClass: + case TBluetoothDeviceDialog::EAdditionalInt: + key.Num(aType); + value = CHbSymbianVariant::NewL( (TAny*) &aData, CHbSymbianVariant::EInt ); + BtTraceBlock( + TBuf<32> buf; + switch (aType) { + case TBluetoothDialogParams::EDialogType: + buf = _L("EDialogType"); + break; + case TBluetoothDialogParams::EResource: + buf = _L("EResource"); + break; + case TBluetoothDeviceDialog::EDeviceClass: + buf = _L("EDeviceClass"); + break; + case TBluetoothDeviceDialog::EAdditionalInt: + buf = _L("EAdditionalInt"); + break; + } + TPtrC p(buf); + TInt *intPtr = (TInt *)value->Data(); + BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, "SetData [%S] = [%d]", &p, *intPtr); + ); + err = iNotificationData->Add( key, value ); // Takes ownership of value + if ( err ) + { + // need a proper exception handling. + //NOTIF_NOTHANDLED( !err ) + } + + break; + case TBluetoothDialogParams::EAddress: + case TBluetoothDeviceDialog::EDeviceName: + PanicServer( EBTNotifPanicBadArgument ); + break; + case TBluetoothDialogParams::ENoParams: + case TBluetoothDeviceDialog::ENoParams: + default: + break; + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + +// --------------------------------------------------------------------------- +// From class MHbDeviceDialogObserver. +// Callback called when data is received from a device dialog. +// --------------------------------------------------------------------------- +// +void CBluetoothNotification::DataReceived( CHbSymbianVariantMap& aData ) + { + BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); + BtTraceBlock( debugHbSymbianVariantMap(aData); ); + for( TInt i = 0; i < aData.Keys().MdcaCount(); i++ ) + { + TPtrC key( aData.Keys().MdcaPoint( i ).Ptr(), aData.Keys().MdcaPoint( i ).Length() ); + const CHbSymbianVariant* valueRef = aData.Get( key ); + CHbSymbianVariant* value = CHbSymbianVariant::NewL( valueRef->Data(), valueRef->Type() ); + TInt err = iReturnData->Add( key, value ); + NOTIF_NOTHANDLED( !err ) + } + iObserver->MBRDataReceived( aData ); + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + +#ifdef BLUETOOTHTRACE_ENABLED + +void CBluetoothNotification::debugHbSymbianVariantMap( CHbSymbianVariantMap& aData) + { + for( TInt i = 0; i < aData.Keys().MdcaCount(); i++ ) + { + TBuf<128> buf; + TPtrC key( aData.Keys().MdcaPoint( i ).Ptr(), aData.Keys().MdcaPoint( i ).Length() ); + buf = key; + buf.Append(_L(" = ")); + const CHbSymbianVariant* value = aData.Get( key ); + TBuf<16> nbr; + TBuf<32> newBuf; + switch (value->Type()) { + case CHbSymbianVariant::EInt : + buf.Append(_L("[EInt] ")); + nbr.Num(*((TInt*)value->Data())); + buf.Append(nbr); + break; + case CHbSymbianVariant::EBool : + buf.Append(_L("[EBool] ")); + buf.Append(*((TBool*)value->Data()) ? _L("True") : _L("False")); + break; + case CHbSymbianVariant::EUint : + buf.Append( _L("[EUint] ")); + nbr.Num(*((TUint*)value->Data())); + buf.Append(nbr); + break; + case CHbSymbianVariant::EReal : + buf.Append(_L("[EReal] ")); + nbr.Num(*((TReal*)value->Data())); + buf.Append(nbr); + break; + case CHbSymbianVariant::EDes : // TDesC + buf.Append(_L("[EDes] ")); + buf.Append(*((TPtrC16 *)value->Data())); + break; + case CHbSymbianVariant::EBinary : // TDesC8 + buf.Append(_L("[EBinary] ")); + // the following function caused problems when converting this function to + // a trace function in bluetoothtrace.h + CnvUtfConverter::ConvertToUnicodeFromUtf8(newBuf,*((TPtrC8 *)value->Data()) ); + buf.Append(newBuf); + break; + case CHbSymbianVariant::EChar : // a TChar + buf.Append(_L("[EChar] ")); + buf.Append(*((TChar *)value->Data())); + break; + case CHbSymbianVariant::ERect : // a TRect + case CHbSymbianVariant::EPoint : // a TPoint + case CHbSymbianVariant::ESize : // a TSize + case CHbSymbianVariant::EDesArray : // a MDesCArray + break; + default: + break; + } + TPtrC p(buf); + BOstraceExt1( TRACE_DEBUG, DUMMY_DEVLIST, "HbSymbianVariantMap [%S]", &p); + } + } +#endif // BLUETOOTHTRACE_ENABLED +// --------------------------------------------------------------------------- +// From class MHbDeviceDialogObserver. +// Callback called when a device dialog is closed. +// --------------------------------------------------------------------------- +// +void CBluetoothNotification::DeviceDialogClosed( TInt aCompletionCode ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aCompletionCode ); + TPckg result( EFalse ); + TPtrC8 resultPtr( result ); + const CHbSymbianVariant* value = iReturnData->Get( KBTDevDialogResult ); + if( value && value->IsValid() ) + { + result() = *value->Value(); + } + RBuf8 resultBuf; + value = iReturnData->Get( KBTDevDialogInput ); + if( value && value->IsValid() ) + { + HBufC8* data = value->Value(); + if( !resultBuf.Create( data->Length() + result.Length() ) ) + { + resultBuf = *data; + resultBuf.Insert( 0, result ); + resultPtr.Set( resultBuf ); + } + } + if( iObserver ) + { + if( aCompletionCode == CHbDeviceDialogSymbian::ECancelledError ) + { + aCompletionCode = KErrCancel; + } + iObserver->MBRNotificationClosed( aCompletionCode, resultPtr ); + } + iManager->ReleaseNotification( this ); + // Note that we might get deleted after releasing ourselves. + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/src/btnotifconnection.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifconnection.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,964 @@ +/* +* ============================================================================ +* Name : btnotifconnection.cpp +* Part of : bluetoothengine / btnotif +* Description : Class for observing events of a single connection, and for +* managing any user notifications related to the connection. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "btnotifconnection.h" +#include +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS +#include +#endif + +#include "btnotifconnectiontracker.h" +#include "btnotifpairinghelper.h" +#include "btnotificationmanager.h" +#include "btnotifclientserver.h" +#include "bluetoothtrace.h" + +/** Id for the baseband connection watcher active object. */ +const TInt KConnectionWatcher = 40; +/** Id for the registry watcher active object. */ +const TInt KRegistryWatcher = 41; +/** Id for the active object for updating the registry. */ +const TInt KRegistryRetriever = 42; +/** Event mask for subscribing to baseband connection events + * (need to check if these are appropriate). */ +const TInt KBbEventMask = ENotifyAnyRole | ENotifyAuthenticationComplete | + ENotifyPhysicalLinkUp | ENotifyPhysicalLinkDown | ENotifyPhysicalLinkError; + + +// ======== LOCAL FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// Decide the device name to display from the device information, and +// converts the name if necessary. +// --------------------------------------------------------------------------- +// +void GetDeviceNameL( TBTDeviceName& aName, const CBTDevice& aDevice ) + { + if( aDevice.IsValidFriendlyName() ) + { + aName.Copy( aDevice.FriendlyName() ); + } + else + { + aName.Zero(); + if( aDevice.IsValidDeviceName() ) + { + aName = BTDeviceNameConverter::ToUnicodeL( aDevice.DeviceName() ); + } + } + } + + +// --------------------------------------------------------------------------- +// Compare 2 device records device pairing has succeeded. +// aDev2 is the updated device record, aDev1 is the previous record. +// --------------------------------------------------------------------------- +// +TBool CheckRegistryPairedStatus( const CBTDevice* aOrig, const CBTDevice* aNew ) + { + TBool result = EFalse; + // Use the device class to check that this has any valid information. + if( aOrig->AsNamelessDevice().IsValidDeviceClass() && + !( aOrig->IsValidPaired() && aOrig->IsPaired() ) || + aOrig->LinkKeyType() == ELinkKeyUnauthenticatedUpgradable ) + { + // Only consider the result if the original device is not marked as paired. + if( aNew->IsValidPaired() && aNew->IsPaired() && aNew->IsValidLinkKey() && + aNew->LinkKeyType() != ELinkKeyUnauthenticatedUpgradable ) + { + // The new device record has valid pairing information, so + // this device is now paired. + result = ETrue; + } + } + return result; + } + + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTNotifConnection::CBTNotifConnection( const TBTDevAddr& aAddr, + CBTNotifConnectionTracker* aTracker ) +: iAddr( aAddr ), + iTracker( aTracker ) + { + } + + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::ConstructL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + iDevice = CBTDevice::NewL( iAddr ); + iPhyActive = CBtSimpleActive::NewL(*this, KConnectionWatcher ); + iRegActive = CBtSimpleActive::NewL( *this, KRegistryRetriever ); + // ToDo: need to check if this succeeds if a connection is + // being created, in case of outgoing pairing. + User::LeaveIfError( iPhyLink.Open( iTracker->SocketServerSession(), iAddr ) ); + // Subscribe to events. + iBasebandEvent.FillZ(); // To be sure that we are not reading false events. + iPhyLink.NotifyNextBasebandChangeEvent( iBasebandEvent, + iPhyActive->RequestStatus(), KBbEventMask ); + iPhyActive->GoActive(); + // Get the details from BT registry + TBTRegistrySearch pattern; + pattern.FindAddress( iAddr ); + User::LeaveIfError( iRegistry.Open( iTracker->RegistryServerSession() ) ); + iRegistry.CreateView( pattern, iRegActive->RequestStatus() ); + iRegActive->GoActive(); + iCurrentOp = EReadingRegistry; + iRegDevArray = new CBTDeviceArray(1); // only 1 entry ever used + // ToDo: more initialization needed? + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// NewLC. +// --------------------------------------------------------------------------- +// +CBTNotifConnection* CBTNotifConnection::NewLC( const TBTDevAddr& aAddr, + CBTNotifConnectionTracker* aTracker ) + { + CBTNotifConnection* self = new( ELeave ) CBTNotifConnection( aAddr, aTracker ); + CleanupStack::PushL( self ); + self->ConstructL(); + return self; + } + + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTNotifConnection::~CBTNotifConnection() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + if( iNotification ) + { + // Clear the notification callback, we cannot receive them anymore. + iNotification->RemoveObserver(); + iNotification->Close(); // Also dequeues the notification from the queue. + iNotification = NULL; + } + delete iRegActive; + delete iRegistryResponse; + iRegistry.Close(); + delete iDevMan; + + delete iPhyActive; + iPhyLink.Close(); + delete iDevice; + delete iPairingHelper; + + while( iMsgHandleQ.Count() ) + { + CompleteClientRequest( KErrDisconnected, KNullDesC8 ); + } + iMsgHandleQ.Close(); + iAcceptedConnections.Close(); + iDeniedConnections.Close(); + iRegDevArray->ResetAndDestroy(); + delete iRegDevArray; + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Check what to do next. +// This function should be called whenever we may be ready for the next +// request/action, which is from any callback function i.e. +// MBAORequestCompletedL, MBRNotificationClosed, HandleNotifierRequestL and +// CancelNotifierRequestL. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::CheckNextOperationL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + if( iCurrentOp == EIdle ) + { + // Check the link state, to see if it has gone down already. + TUint32 linkState = 0; + TInt err = iPhyLink.PhysicalLinkState( linkState ); + TBool linkDown = linkState & ENotifyPhysicalLinkDown; + if( ( !err && linkDown ) || err == KErrDisconnected ) + { + // The link state tells us that the link is down, + // inform the connection tracker the we are done. + iTracker->HandleLinkCountChangeL(); + // Note that we may be deleted now! + } + else if( iMsgHandleQ.Count() ) + { + // Get the next request and handle it. + // ToDo: differentiate between notifier and pairing message! + const RMessage2* message = iTracker->Server()->FindMessageFromHandle( iMsgHandleQ[0] ); + NOTIF_NOTHANDLED( message ) + TInt opcode = message->Function(); + if( opcode <= EBTNotifUpdateNotifier ) + { + TBuf8<0x250> paramsBuf; // Size needs to be long enough to read all possible parameter sizes. + message->ReadL( EBTNotifSrvParamSlot, paramsBuf ); + HandleNotifierRequestL( paramsBuf, *message ); + } + else + { + iMsgHandleQ.Remove( 0 ); + StartBondingL( *message ); + } + } + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Complete the first outstanding client request and removes it from the queue. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::CompleteClientRequest( TInt aReason, const TDesC8& aReply ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + NOTIF_NOTHANDLED( iMsgHandleQ.Count() ) + TInt err = iTracker->Server()->CompleteMessage( iMsgHandleQ[0], aReason, aReply ); + NOTIF_NOTHANDLED( !err ) + iMsgHandleQ.Remove( 0 ); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Distinguish a request and pass to corresponding handle. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::HandleNotifierRequestL( const TDesC8& aParams, + const RMessage2& aMessage ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aMessage.Int0() ); + if( !iMsgHandleQ.Count() || iMsgHandleQ[0] != aMessage.Handle() ) + { + // If we are processing a queued request, we of course don't queue + // it again. In that case we are handling the first request from the queue. + iMsgHandleQ.AppendL( aMessage.Handle() ); + } + if( iCurrentOp == EIdle || iCurrentOp == EBonding ) + { + // ToDo: check non-pairing operation when bonding + TInt uid = aMessage.Int0(); + if( uid == KBTManAuthNotifierUid.iUid ) + { + HandleAuthorizationReqL( aParams ); + } + else if( uid == KBTManPinNotifierUid.iUid || + uid == KBTPinCodeEntryNotifierUid.iUid || + uid == KBTNumericComparisonNotifierUid.iUid || + uid == KBTPasskeyDisplayNotifierUid.iUid ) + { + if( !iPairingHelper ) + { + BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, + "[BTNOTIF]\t CBTNotifConnection::HandleNotifierRequestL: creating CBTNotifPairingHelper"); + iPairingHelper = CBTNotifPairingHelper::NewL( this, iTracker ); + } + if( iCurrentOp != EBonding ) + { + iCurrentOp = EPairing; + } + iPairingHelper->StartPairingNotifierL( uid, aParams ); + } + // We may be done with the current request, proceed to the next one + CheckNextOperationL(); + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Update a notifier, update the outstanding dialog if the notifier request +// is currently being served. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::HandleNotifierUpdateL( const TDesC8& aParams, + const RMessage2& aMessage ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + NOTIF_NOTHANDLED( iCurrentOp != EIdle ) + (void) aParams; + TBuf8<0x250> paramsBuf; // Size needs to be long enough to read all possible sizes. + aMessage.ReadL( EBTNotifSrvParamSlot, paramsBuf ); + TInt uid = aMessage.Int0(); + if( uid == KBTManAuthNotifierUid.iUid ) + { + TBTNotifierUpdateParams params; + TPckgC paramsPckg( params ); + paramsPckg.Set( paramsBuf ); + // The result means result of conversion to unicode + if( !paramsPckg().iResult ) + { + // Only update locally, registry will update us with the same info later on. + iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( paramsPckg().iName ) ); + if( iNotification ) + { + // Update the dialog with the new name. It is up to the dialog to + // determine the validity (in case another dialog is shown). + //iNotification->Update( ) + } + } + } + else if( iPairingHelper && ( uid == KBTPinCodeEntryNotifierUid.iUid || + uid == KBTNumericComparisonNotifierUid.iUid || + uid == KBTPasskeyDisplayNotifierUid.iUid ) ) + { + // Just forward to pairing helper + iPairingHelper->UpdatePairingNotifierL( uid, paramsBuf ); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Cancel a request, dismiss the outstanding dialog if the notifier request +// is currently being served. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::CancelNotifierRequestL( const RMessage2& aMessage ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + NOTIF_NOTHANDLED( iCurrentOp != EIdle ) + TInt pos = iMsgHandleQ.Find( aMessage.Handle() ); + if( pos > KErrNotFound ) + { + // We have queued the message, remove it from the queue. + iMsgHandleQ.Remove( pos ); + // We use the supplied handle to remove it, as it may not be + // the first in the queue. + TInt err = iTracker->Server()->CompleteMessage( aMessage.Handle(), KErrCancel, KNullDesC8 ); + NOTIF_NOTHANDLED( !err ) + if( pos == 0 ) + { + // There could be the case that we are still post-processing + // the previous request (e.g. blocking query), then the next + // notification is not yet started but the first in the queue. + // We can see that from the current operation type. + if( iNotification && iCurrentOp < EAdditionalNotes ) + { + // Cancel the user query + // This will also unregister us from the notification. + TInt err = iNotification->Close(); + NOTIF_NOTHANDLED( !err ) + iNotification = NULL; + iCurrentOp = EIdle; + } + if( iPairingHelper ) + { + // The pairing helper calls back PairingCompleted and sets state. + iPairingHelper->CancelPairingNotifierL( aMessage.Int0() ); + // The pairing helper may have now been deleted. + } + } + } + // We may be done with the current request, proceed to the next one + CheckNextOperationL(); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Start a bonding operation with the remote device. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::StartBondingL( const RMessage2& aMessage ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aMessage.Function() ); + if( iCurrentOp == EIdle || iCurrentOp > EInternalOperations ) + { + __ASSERT_ALWAYS( !iPairingHelper, PanicServer( EBTNotifPanicBadState ) ); + iPairingHelper = CBTNotifPairingHelper::NewL( this, iTracker ); + // The pairingg helper stored the handle, not in our queue here. + // This is because bonding will generate a pairing notifier request, which + // will be completed first. The bookkeeping gets complicated if we have to + // re-order the queue here. + iPairingHelper->StartBondingL( aMessage.Handle() ); + iCurrentOp = EBonding; + } + else if( iCurrentOp == EPairing || iCurrentOp == EBonding ) + { + // We only do one pairing at the time. + User::Leave( KErrInUse ); + } + else + { + // We only store it here if it is not handled immediately. + iMsgHandleQ.AppendL( aMessage.Handle() ); + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Cancel an ongoing bonding operation with the remote device. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::CancelBondingL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + if( iPairingHelper ) + { + iPairingHelper->CancelBondingL(); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// The pairing handler has completed a pairing operation. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::PairingCompleted() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + __ASSERT_ALWAYS( iPairingHelper, PanicServer( EBTNotifPanicNullMember ) ); + if( iPairingHelper->CurrentOperation() == CBTNotifPairingHelper::EIdle ) + { + // We are still idle. Remove the pairing helper + delete iPairingHelper; + iPairingHelper = NULL; + } + if( iCurrentOp == EPairing || iCurrentOp == EBonding ) + { + iCurrentOp = EIdle; + TRAP_IGNORE( CheckNextOperationL() ); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Process a new pairing result, and determine if we need to show +// anything to the user. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::PairingResult( TInt aError ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + if( !iPairingHelper ) + { + TRAP_IGNORE( iPairingHelper = CBTNotifPairingHelper::NewL( this, iTracker ) ); + } + if( iPairingHelper ) + { + iPairingHelper->HandleAuthenticationCompleteL( aError ); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Process the new service-level connection, and determine if we need to +// show anything to the user. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::ServiceConnectedL( TBTProfile aProfile ) + { + (void) aProfile; + } + + +// --------------------------------------------------------------------------- +// Process the new service-level disconnection, and determine if we need to +// show anything to the user. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::ServiceDisconnectedL( TBTProfile aProfile ) + { + (void) aProfile; + } + + +// --------------------------------------------------------------------------- +// Ask the user if he/she wants to block future connection requests. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::LaunchBlockingQueryL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + iCurrentOp = EBlocking; + TBTDialogResourceId resourceId = EBlockUnpairedDevice; + if( iDevice->IsValidPaired() && iDevice->IsPaired() && + iDevice->LinkKeyType() != ELinkKeyUnauthenticatedUpgradable ) + { + resourceId = EBlockPairedDevice; + } + PrepareNotificationL( TBluetoothDialogParams::EQuery, resourceId ); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Modify the record for the remote device in BTRegistry, with the changes +// already made in the local record. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::UpdateRegistryEntryL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + // We use CBTEngDevMan here. We could use the registry API directly, however, + // using this convenience API makes the registry processing much simpler. + if( !iDevMan ) + { + iDevMan = CBTEngDevMan::NewL( this ); + } + iDevMan->ModifyDevice( *iDevice ); + if( iCurrentOp == EIdle || + ( ( iCurrentOp == EPairing || iCurrentOp == EBonding ) && + iPairingHelper->CurrentOperation() == CBTNotifPairingHelper::EIdle ) ) + { + // To make sure that we don't get deleted while updating. + iCurrentOp = EUpdatingRegistry; + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Modify the record for the remote device in BTRegistry, if aTrusted == true, then +// update trusted status after reading device info from registry +// +// --------------------------------------------------------------------------- + +void CBTNotifConnection::UpdateRegistryEntryL( TBool aTrusted ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aTrusted ); + if (!aTrusted) { + UpdateRegistryEntryL(); + return; + } + // We use CBTEngDevMan here. We could use the registry API directly, however, + // using this convenience API makes the registry processing much simpler. + if( !iDevMan ) + { + iDevMan = CBTEngDevMan::NewL( this ); + } + // first read device info from registry, to make sure we have up-to-date local info + iCurrentOp = EReadingRegistry; + GetDeviceFromRegistry( iDevice->BDAddr() ); + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + +// --------------------------------------------------------------------------- +// From class MBTNotificationResult. +// Handle a result from a user query. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::MBRDataReceived( CHbSymbianVariantMap & aData ) + { + (void) aData; + NOTIF_NOTIMPL + } + + +// --------------------------------------------------------------------------- +// From class MBTNotificationResult. +// The notification is finished. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::MBRNotificationClosed( TInt aError, const TDesC8& aData ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + // ToDo: call leaving function from here! + __ASSERT_ALWAYS( iCurrentOp != EIdle, PanicServer( EBTNotifPanicBadState ) ); + // First unregister from the notification, so we can already get the next one. + iNotification->RemoveObserver(); + iNotification = NULL; + TRAP_IGNORE( NotificationClosedL( aError, aData ) ); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// Handle the active object completion. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::RequestCompletedL( CBtSimpleActive* aActive, + TInt aStatus ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aActive->RequestId() ); + switch( aActive->RequestId() ) + { + case KRegistryRetriever: + { + BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, + "[BTNOTIF]\t CBTNotifConnection::MBAORequestCompletedL: KRegistryRetriever" ); + if( !iRegistryResponse ) + { + // We have just created the view, now get the results. + // There can only be one result, as the address is unique. + // (note: how about LE random addresses?) + // Or then we have tried to re-open an existing view, so we get KErrInuse. + // We anyway just get the results. + __ASSERT_ALWAYS( aStatus < 2, PanicServer( EBTNotifPanicCorrupt ) ); + iRegistryResponse = CBTRegistryResponse::NewL( iRegistry ); + iRegistryResponse->Start( iRegActive->RequestStatus() ); + iRegActive->GoActive(); + } + else + { + if( !aStatus ) + { + // There can be only one result. + __ASSERT_ALWAYS( iRegistryResponse->Results().Count() == 1, PanicServer( EBTNotifPanicCorrupt ) ); + CBTDevice* regDevice = iRegistryResponse->Results()[0]; + TBool paired = CheckRegistryPairedStatus( iDevice, regDevice ); + iDevice->UpdateL( *regDevice ); + if( paired ) + { + __ASSERT_ALWAYS( iPairingHelper, PanicServer( EBTNotifPanicNullMember ) ); + iPairingHelper->HandleAuthenticationCompleteL( KErrNone ); + } + } + // ToDo: error handling of registry response result? + delete iRegistryResponse; + iRegistryResponse = NULL; + } + if( iCurrentOp == EReadingRegistry && !iRegActive->IsActive() ) + { + // If this is part of the sequence of operations, we are done. + // Otherwise we just update with the latest info from registry, + // and then we don't interrupt or change the state. + iCurrentOp = EIdle; + } + } + // ToDo: start registry watching (preferably using registry API when this is available) + break; + case KRegistryWatcher: + { + BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, + "[BTNOTIF]\t CBTNotifConnection::MBAORequestCompletedL: KRegistryWatcher" ); + NOTIF_NOTHANDLED( !aStatus ) + // Ignore updates while we are already retrieving. + if( !iRegActive->IsActive() ) + { + // Refresh our information with the latest from registry + iRegActive->SetRequestId( KRegistryRetriever ); + TBTRegistrySearch pattern; + pattern.FindAddress( iAddr ); + iRegistry.CreateView( pattern, iRegActive->RequestStatus() ); + iRegActive->GoActive(); + } + } + break; + case KConnectionWatcher: + { + BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, + "[BTNOTIF]\t CBTNotifConnection::MBAORequestCompletedL: KConnectionWatcher" ); + TUint32 event = iBasebandEvent().EventType(); + // First subscribe to the next event notification. + // This will overwrite iBasebandEvent().EventType() with KBbEventMask + iPhyLink.NotifyNextBasebandChangeEvent( iBasebandEvent, + iPhyActive->RequestStatus(), KBbEventMask ); + iPhyActive->GoActive(); + // Link down and link error are handled in CheckNextOperationL below. + // ToDo: handle events! + if( event & ( ENotifyPhysicalLinkDown | ENotifyPhysicalLinkError ) ) + { + // We re-use the error code to store the indication that the + // link has disconnected. This will only be overridden by next + // event, which can only be a connection up event. + iBasebandEvent().SetErrorCode( KErrDisconnected ); + } + if( iPairingHelper ) + { + if( event & ( ENotifyPhysicalLinkDown | ENotifyPhysicalLinkError | + ENotifyAuthenticationComplete ) ) + { + // Results interesting for pairing result processing. + iPairingHelper->HandleAuthenticationCompleteL( iBasebandEvent().SymbianErrorCode() ); + } + else if( event & ENotifyPhysicalLinkUp && + iPairingHelper->CurrentOperation() == CBTNotifPairingHelper::EDedicatedBonding ) + { + iPairingHelper->StartBondingL( 0 ); + } + } + } + break; + default: + PanicServer( EBTNotifPanicBadState ); + break; + } + // We may be done with the current request, proceed to the next one + CheckNextOperationL(); + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// Cancel and clean up all requests related to the active object. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::CancelRequest( TInt aRequestId ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + if ( aRequestId == KConnectionWatcher ) + { + iPhyLink.CancelNextBasebandChangeEventNotifier(); + } + else if ( aRequestId == KRegistryWatcher && iRegistryResponse ) + { + iRegistryResponse->Cancel(); + } + else if ( aRequestId == KRegistryRetriever ) + { + iRegistry.CancelRequest( iRegActive->RequestStatus()); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::HandleError( CBtSimpleActive* aActive, + TInt aError ) + { + (void) aActive; + (void) aError; + } + +// --------------------------------------------------------------------------- +// From class MBTEngDevmanObserver. +// Registry modification has completed. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::HandleDevManComplete( TInt aErr ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + (void) aErr; + NOTIF_NOTHANDLED( !aErr ) + if( iCurrentOp == EUpdatingRegistry ) + { + // To make sure that we don't get deleted while updating. + iCurrentOp = EIdle; + } + // Refresh is done separately, we will get notified through + // the registry watcher of the change. + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// From class MBTEngDevmanObserver. +// Callback for getting a device from the registry +// +// Currently only used in context of setting device to trusted +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::HandleGetDevicesComplete( + TInt err, CBTDeviceArray* deviceArray ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, err ); + // err is not used here very much, -1 could be returned if there is no device in registry, + // but this case is covered by examing mRegDevArray. + if (!err && (iCurrentOp == EReadingRegistry) ) { + CBTDevice* dev (0); + if ( deviceArray->Count() ) { + dev = deviceArray->At( 0 ); + } + if ( dev ) { + iDevice = dev->CopyL(); + } + // Set device to trusted + // Copy the existing security settings. + TBTDeviceSecurity sec( iDevice->GlobalSecurity().SecurityValue(), + iDevice->GlobalSecurity().PasskeyMinLength() ); + sec.SetNoAuthorise( ETrue ); // new value: set device as trusted + iDevice->SetGlobalSecurity( sec ); + iDevMan->ModifyDevice( *iDevice ); // write trusted (& paired) status to registry + // To make sure that we don't get deleted while updating. + iCurrentOp = EUpdatingRegistry; + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + +// --------------------------------------------------------------------------- +// Retrieves device from registry based on BT address parameter +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::GetDeviceFromRegistry( const TBTDevAddr &addr ) +{ + BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); + TBTRegistrySearch searchPattern; + searchPattern.FindAddress( addr ); + // and get this device from registry + iRegDevArray->ResetAndDestroy(); + iDevMan->GetDevices(searchPattern, iRegDevArray); + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); +} + +// --------------------------------------------------------------------------- +// Get and configure a notification. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, + TBTDialogResourceId aResourceId ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + iNotification = iTracker->NotificationManager()->GetNotification(); + User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory + iNotification->SetObserver( this ); + iNotification->SetNotificationType( aType, aResourceId ); + // Set the address of the remote device + TBuf addr; + addr.Copy( iAddr.Des() ); + TInt err = iNotification->SetData( TBluetoothDialogParams::EAddress, addr ); + NOTIF_NOTHANDLED( !err ) + // Set the name of the remote device + TBTDeviceName name; + GetDeviceNameL( name, *iDevice ); + // ToDo: handle leave in name conversion! + err = iNotification->SetData( (TInt) TBluetoothDeviceDialog::EDeviceName, name ); + NOTIF_NOTHANDLED( !err ) + // Queue the notification for displaying to the user + err = iTracker->NotificationManager()->QueueNotification( iNotification ); + NOTIF_NOTHANDLED( !err ) + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// The notification is finished, handle the result. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::NotificationClosedL( TInt aError, const TDesC8& aData ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + switch( iCurrentOp ) + { + case EAuthorizing: + CompleteAuthorizationReqL( aError, aData ); + break; + case EBlocking: + CompleteBlockingReqL( aError, aData ); + break; + default: + NOTIF_NOTIMPL + break; + } + // We may be done with the current request, proceed to the next one + CheckNextOperationL(); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Handle a request for authorization of this connection. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::HandleAuthorizationReqL( const TDesC8& aParams ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + __ASSERT_ALWAYS( iCurrentOp == EIdle, PanicServer( EBTNotifPanicBadState ) ); + __ASSERT_ALWAYS( !iNotification, PanicServer( EBTNotifPanicCorrupt ) ); + TBTAuthorisationParams params; + TPckgC paramsPckg( params ); + paramsPckg.Set( aParams ); + iCurrentOp = EAuthorizing; + // The name in the parameter package is the latest one, retrieved from + // the remote device during this connection. + if( paramsPckg().iName.Length() ) + { + // Update the local device record. No need to update the registry, + // that will be done by the stack, and we will receive the update + // information when that has completed. + iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( paramsPckg().iName ) ); + } + PrepareNotificationL( TBluetoothDialogParams::EQuery, EAuthorization ); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Process the user input and complete the outstanding authorization request. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::CompleteAuthorizationReqL( TInt aError, const TDesC8& aData ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + // Set our state to idle for now. This may get changed if the user just chose + // to block, or if we have a pending request. + iCurrentOp = EIdle; + if( !aError ) + { + TPckgC result( EFalse ); + result.Set( aData ); + TBool proceed = iTracker->UpdateBlockingHistoryL( iDevice, result() ); + if( result() == EFalse && proceed ) + { + // The user denied the connection, ask to block the device. + LaunchBlockingQueryL(); + } + CompleteClientRequest( KErrNone, aData ); + } + else + { + CompleteClientRequest( aError, KNullDesC8 ); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Process the user input for blocking a device. +// --------------------------------------------------------------------------- +// +void CBTNotifConnection::CompleteBlockingReqL( TInt aError, const TDesC8& aData ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + TPckgC result( EFalse ); + result.Set( KNullDesC8 ); // to test! + result.Set( aData ); + iCurrentOp = EIdle; // May get changed if we have a pending request. + if( !aError && result() ) + { + // The user accepted to block this device. + TBTDeviceSecurity sec; // use default values when setting as banned. + sec.SetBanned( ETrue ); + iDevice->SetGlobalSecurity( sec ); + if( iDevice->IsValidPaired() && iDevice->IsPaired() ) + { + // Deleting the link key will also set the device as unpaired. + iDevice->DeleteLinkKey(); + } + UpdateRegistryEntryL(); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/src/btnotifconnectiontracker.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifconnectiontracker.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,721 @@ +/* +* ============================================================================ +* Name : btnotifconnectiontracker.cpp +* Part of : bluetoothengine / btnotif +* Description : Bluetooth connection tracker and manager. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "btnotifconnectiontracker.h" +#include +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS +#include +#endif + +#include "btnotifconnection.h" +#include "btnotifsession.h" +#include "btnotifclientserver.h" +#include "bluetoothtrace.h" + +/** Id for the link key watcher active object. */ +const TInt KLinkCountWatcher = 30; +/** Id for the pairing result watcher active object. */ +const TInt KSspResultWatcher = 31; +/** Id for the registry watcher active object (TEMP!). */ +const TInt KRegistryWatcher = 41; +/** Time window for determining if there are too many requests. */ +#ifndef __WINS__ +#define KDENYTHRESHOLD TTimeIntervalSeconds(3) +#else //__WINS__ +#define KDENYTHRESHOLD TTimeIntervalSeconds(5) +#endif //__WINS__ + + +// ======== LOCAL FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// Checks if the notifier is one launched by the security manager of the +// protocol stack. These notifiers need to be served unless really not possible. +// --------------------------------------------------------------------------- +// +TBool IsStackSecmanNotifier( TInt aUid ) + { + TBool result = EFalse; + if( aUid == KBTManAuthNotifierUid.iUid || aUid == KBTManPinNotifierUid.iUid || + aUid == KBTPinCodeEntryNotifierUid.iUid || aUid == KBTNumericComparisonNotifierUid.iUid || + aUid == KBTPasskeyDisplayNotifierUid.iUid ) + { + result = ETrue; + } + return result; + } + + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTNotifConnectionTracker::CBTNotifConnectionTracker( CBTNotifServer* aServer ) +: iServer( aServer ) + { + } + + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::ConstructL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + // Start watching the number of baseband links. + TInt err = iLinkCount.Attach( KPropertyUidBluetoothCategory, + KPropertyKeyBluetoothGetPHYCount ); + // There is not much point to continue if we can't attach to + // the link count key. + User::LeaveIfError( err ); + iLinkCountActive = CBtSimpleActive::NewL( *this, KLinkCountWatcher ); + iLinkCount.Subscribe( iLinkCountActive->RequestStatus() ); + iLinkCountActive->GoActive(); + // Open a handle to the registry server + User::LeaveIfError( iBTRegistrySession.Connect() ); + // Open a handle to the socket server + User::LeaveIfError( iSockServ.Connect() ); + iPairingServ = new( ELeave ) RBluetoothPairingServer(); + if( iPairingServ->Connect() ) + { + // Delete in case of error - there is no good other way to keep track. + delete iPairingServ; + iPairingServ = NULL; + } + else + { + iSspResultActive = CBtSimpleActive::NewL( *this, KSspResultWatcher ); + User::LeaveIfError( iSspResultSession.Open( *iPairingServ ) ); + iSspResultSession.SimplePairingResult( iSspResultAddr, iSspResultActive->RequestStatus() ); + iSspResultActive->GoActive(); + } + iConnMan = CBTEngConnMan::NewL( this ); + iPhyLinks = CBluetoothPhysicalLinks::NewL( *this, iSockServ ); +// ToDo: remove this when registry notifications API is available!! + err = iRegistryChange.Attach( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothRegistryTableChange ); + User::LeaveIfError( err ); + iRegistryActive = CBtSimpleActive::NewL( *this, KRegistryWatcher ); + iRegistryChange.Subscribe( iRegistryActive->RequestStatus() ); + iRegistryActive->GoActive(); +// End ToDo + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// NewL. +// --------------------------------------------------------------------------- +// +CBTNotifConnectionTracker* CBTNotifConnectionTracker::NewL( CBTNotifServer* aServer ) + { + CBTNotifConnectionTracker* self = new( ELeave ) CBTNotifConnectionTracker( aServer ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTNotifConnectionTracker::~CBTNotifConnectionTracker() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + iConnArray.ResetAndDestroy(); + iConnArray.Close(); + iDeniedRequests.Close(); + delete iLinkCountActive; + iLinkCount.Close(); + + delete iConnMan; + delete iPhyLinks; + iSockServ.Close(); + delete iSspResultActive; + iSspResultSession.Close(); + if( iPairingServ ) + { + iPairingServ->Close(); + delete iPairingServ; + } + delete iRegistryActive; + iRegistryChange.Close(); + iBTRegistrySession.Close(); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Process a client message related to notifiers. +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::DispatchNotifierMessageL( const RMessage2& aMessage ) + { + BOstraceFunctionEntryExt ( DUMMY_LIST, this, aMessage.Function() ); + TInt opcode = aMessage.Function(); + TInt uid = aMessage.Int0(); + const RMessage2* message = &aMessage; + // Use a pointer to the original message, so that we don't duplicate it. + // Then we avoid any bookkeeping for keeping them in sync. + if( opcode == EBTNotifCancelNotifier ) + { + // We only accept a cancel message from the same session as the original + // request (this is enforced by the RNotifier backend). So we use the + // session of the cancel request (if this would change, the same way as + // for updates can be followed). + // We need to find the original request to identify the handler of the + // connection; the uid points to the original request. + message = ( (CBTNotifSession *) aMessage.Session() )->FindMessageFromUid( uid ); + } + else if( opcode == EBTNotifUpdateNotifier ) + { + // We accept a update messages from any client, although in practice, + // they will all come from the same session (through RNotifier). + // We need to find the original request to identify the handler of the + // connection (the uid points to the original request). Through the + // server, we get it from any session. + message = iServer->FindMessageFromUid( uid ); + } + if( !message ) + { + // It's hard to continue if we don't know where to route the message. + User::Leave( KErrDisconnected ); + } + TBuf8<0x250> paramsBuf; // Size needs to be long enough to read all possible parameter sizes. + CBTNotifConnection* connection = FindConnectionFromMessageL( opcode, *message, paramsBuf ); + if( !connection ) + { + User::Leave( KErrDisconnected ); + } + switch( opcode ) + { + case EBTNotifStartSyncNotifier: + case EBTNotifStartAsyncNotifier: + connection->HandleNotifierRequestL( paramsBuf, aMessage ); + break; + case EBTNotifUpdateNotifier: + connection->HandleNotifierUpdateL( paramsBuf, aMessage ); + break; + case EBTNotifCancelNotifier: + // Complete the cancel message already here, so that the caller can + // continue, and the next operation can close sessions with the caller. + aMessage.Complete( KErrNone ); + connection->CancelNotifierRequestL( *message ); + break; + default: + break; + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Handle a request related to pairing. +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::HandleBondingRequestL( const RMessage2& aMessage ) + { + BOstraceFunctionEntryExt ( DUMMY_LIST, this, aMessage.Function() ); + // Bonding is an infrequently occurring operation, so we don't waste memory + // to keep a copy of the parameters. Instead we read them again when needed. + TPckgBuf addrBuf; + TInt opcode = aMessage.Function(); + if( opcode == EBTEngPairDevice ) + { + aMessage.ReadL( EBTNotifSrvParamSlot, addrBuf ); + } + else if( opcode == EBTEngCancelPairDevice ) + { + const RMessage2* message = + ( (CBTNotifSession *) aMessage.Session() )->FindMessageFromUid( EBTEngPairDevice ); + message->ReadL( EBTNotifSrvParamSlot, addrBuf ); + } + BtTraceBtAddr1( TRACE_DEBUG, DUMMY_LIST, "CBTNotifConnectionTracker::HandleBondingRequestL() addr=", addrBuf() ); + TInt err = KErrNotFound; + CBTNotifConnection* connection = FindConnectionHandler( addrBuf() ); + if( opcode == EBTEngPairDevice ) + { + if( !connection ) + { + // Create a connection first, then tell it to bond. + err = iPhyLinks->CreateConnection( addrBuf() ); + connection = CBTNotifConnection::NewLC( addrBuf(), this ); + iConnArray.AppendL( connection ); + CleanupStack::Pop( connection ); + } + else + { + // There is an existing connection. Care must be taken, the connection + // _should_ be disconnect first if this device is already paired, so that + // we are sure that we don't mix up the state of the connection. + RBTPhysicalLinkAdapter link; + err = link.Open( iSockServ, addrBuf() ); + TUint32 linkState = 0; + if( !err ) + { + err = link.PhysicalLinkState( linkState ); + } + if( !err && linkState & ( ENotifyAuthenticationComplete | ENotifyEncryptionChangeOn ) ) + { + // For now, we just reject the request. + err = KErrAlreadyExists; + } + link.Close(); + } + if( !err ) + { + // Start bonding immediately so that the connection object is in the right state. + connection->StartBondingL( aMessage ); + } + } + else if( opcode == EBTEngCancelPairDevice && connection ) + { + connection->CancelBondingL(); + err = KErrNone; + aMessage.Complete( err ); + } + // KErrNotFound is returned for a request to cancel pairing that has no connection. + if( err ) + { + aMessage.Complete( err ); + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Handle a change in the number of connections. +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::HandleLinkCountChangeL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + TInt linkCount = 0; + User::LeaveIfError( iLinkCount.Get( linkCount ) ); + if( linkCount ) + { + RBTDevAddrArray links; + CleanupClosePushL( links ); + User::LeaveIfError( iPhyLinks->Enumerate( links, 10 ) ); + __ASSERT_ALWAYS( links.Count(), PanicServer( EBTNotifPanicBadState ) ); + for( TInt i = iConnArray.Count() -1; i >= 0 ; i-- ) + { + // Loop backwards, as we may remove entries from the array. + + // First check the existing connections, and + // remove disconnected links + TBTDevAddr addr = iConnArray[i]->Address(); + TInt pos = links.Find( addr ); + if( pos > KErrNotFound ) + { + // The link we know is still connected, + // remove the watceher from the array. + links.Remove( pos ); + // ToDo: see comment below! + } + else if( iConnArray[i]->CurrentOperation() == CBTNotifConnection::EIdle ) + { + // This link is no more connected and idle, remove. + CBTNotifConnection* connection = iConnArray[i]; + iConnArray.Remove( i ); // Does not delete the object. + delete connection; + } + // else we wait for the link to complete its operations. + } + // Now we have an array with only the new connections. + // Add new watchers. + for( TInt i = 0; i < links.Count(); i++ ) + { + CBTNotifConnection* connection = CBTNotifConnection::NewLC( links[i], this ); + iConnArray.AppendL( connection ); + CleanupStack::Pop( connection ); + } + // Close the links RBTDevAddrArray, needed before going out of scope. + CleanupStack::PopAndDestroy(); + } + else + { + for( TInt i = iConnArray.Count() -1; i >= 0 ; i-- ) + { + if( iConnArray[i]->CurrentOperation() == CBTNotifConnection::EIdle ) + { + // This link is now idle, so we can remove it safely. + CBTNotifConnection* connection = iConnArray[i]; + iConnArray.Remove( i ); // Does not delete the object. + delete connection; + } + } + if( !iConnArray.Count() ) + { + // The array is idle, clean up the array resources. + iConnArray.Reset(); + } + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Check if this device has been denied a connection already before. +// Also check if a previous connection attempt has just been rejected. +// --------------------------------------------------------------------------- +// +TBool CBTNotifConnectionTracker::UpdateBlockingHistoryL( const CBTDevice* aDevice, + TBool aAccepted ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + __ASSERT_ALWAYS( aDevice, PanicServer( EBTNotifPanicBadArgument ) ); + // Check the time since the previous event. + TBool result = RecordConnectionAttempts( aAccepted ); + TInt pos = iDeniedRequests.Find( aDevice->BDAddr() ); + if( !aAccepted ) + { + if( pos == KErrNotFound ) + { + // The user denied the request from a new device, record the device address. + if( aDevice->IsValidPaired() && aDevice->IsPaired() ) + //[MCL]: && iDevice->LinkKeyType() != ELinkKeyUnauthenticatedUpgradable ) + { + // Paired devices are allowed one time rejection without a prompt for blocking. + result = EFalse; + } + iDeniedRequests.AppendL( aDevice->BDAddr() ); + } + // Nothing needed here if the address is already in the array. + } + else if( pos > KErrNotFound ) + { + // The user accepted a request, and it was from a device he/she + // previously rejected. Clear the history for this device from the array. + iDeniedRequests.Remove( pos ); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + return result; + } + + +// --------------------------------------------------------------------------- +// From class MBluetoothPhysicalLinksNotifier. +// Handle baseband connection completion. +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::HandleCreateConnectionCompleteL( TInt aErr ) + { + BOstraceFunctionEntryExt ( DUMMY_LIST, this, aErr ); + // We only connect links for starting outgoing bonding. + const RMessage2* message = iServer->FindMessageFromUid( (TInt) EBTEngPairDevice ); + if( message ) + { + TPckgBuf addrBuf; + message->ReadL( EBTNotifSrvParamSlot, addrBuf ); + CBTNotifConnection* connection = FindConnectionHandler( addrBuf() ); + __ASSERT_ALWAYS( connection, PanicServer( EBTNotifPanicBadState ) ); + if( !aErr && connection->CurrentOperation() == CBTNotifConnection::EIdle ) + { + TRAP( aErr, connection->StartBondingL( *message ) ); + } + if( aErr && connection->CurrentOperation() == CBTNotifConnection::EBonding ) + { + connection->PairingResult( aErr ); // Launch error note + } + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// From class MBluetoothPhysicalLinksNotifier. +// Handle baseband disconnection. +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::HandleDisconnectCompleteL( TInt aErr ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + // We only disconnect links for starting outgoing bonding. + const RMessage2* message = iServer->FindMessageFromUid( (TInt) EBTEngPairDevice ); + if( message ) + { + TPckgBuf addrBuf; + message->ReadL( EBTNotifSrvParamSlot, addrBuf ); + if( !aErr ) + { + aErr = iPhyLinks->CreateConnection( addrBuf() ); + } + if( aErr ) + { + iServer->CompleteMessage( message->Handle(), aErr, KNullDesC8 ); + CBTNotifConnection* connection = FindConnectionHandler( addrBuf() ); + __ASSERT_ALWAYS( connection, PanicServer( EBTNotifPanicBadState ) ); + connection->PairingResult( aErr ); // Launch error note + } + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// From class MBluetoothPhysicalLinksNotifier. +// Handle disconnection of all links. +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::HandleDisconnectAllCompleteL( TInt aErr ) + { + (void) aErr; + } + + +// --------------------------------------------------------------------------- +// From class MBTEngConnObserver. +// Handle service-level connection completion. +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::ConnectComplete( TBTDevAddr& aAddr, + TInt aErr, RBTDevAddrArray* aConflicts ) + { + (void) aAddr; + (void) aErr; + (void) aConflicts; + } + + +// --------------------------------------------------------------------------- +// From class MBTEngConnObserver. +// Handle service-level disconnection. +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ) + { + (void) aAddr; + (void) aErr; + } + + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// Handle the active object completion. +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::RequestCompletedL( CBtSimpleActive* aActive, + TInt aStatus ) + { + BOstraceFunctionEntryExt ( DUMMY_LIST, this, aActive->RequestId() ); + BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, + "CBTNotifConnectionTracker::MBAORequestCompletedL() requestid=%d status=%d", + aActive->RequestId(), aStatus); + if( aActive->RequestId() == KLinkCountWatcher ) + { + iLinkCount.Subscribe( aActive->RequestStatus() ); + aActive->GoActive(); + if( !aStatus ) + { + // HandleLinkCountChangeL(); + } + } +// ToDo: remove this when registry notifications API is available!! + else if( aActive->RequestId() == KRegistryWatcher ) + { + // BTRegistry notifies of a change. Check which one. + iRegistryChange.Subscribe( aActive->RequestStatus() ); + aActive->GoActive(); + TInt tableChanged = 0; + if( !aStatus && !iRegistryChange.Get( tableChanged ) && + tableChanged == KRegistryChangeRemoteTable ) + { + // A record for a remote device has changed. Tell all + // connections to update their record. + for( TInt i = 0; i < iConnArray.Count(); i++ ) + { + // Reuse the functionality in the connection + if( iConnArray[i]->CurrentOperation() < CBTNotifConnection::EReadingRegistry ) + { + iConnArray[i]->RequestCompletedL( aActive, aStatus ); + } + } + } + } +// End ToDo + else if( aActive->RequestId() == KSspResultWatcher ) + { + iSspResultSession.SimplePairingResult( iSspResultAddr, iSspResultActive->RequestStatus() ); + iSspResultActive->GoActive(); + CBTNotifConnection* connection = FindConnectionHandler( iSspResultAddr ); + // ToDo: how to handle a result of a link that already disconnected? + if( connection ) + { + connection->PairingResult( aStatus ); + } + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// Cancel and clean up all requests related to the active object. +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::CancelRequest( TInt aRequestId ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + if( aRequestId == KLinkCountWatcher ) + { + iLinkCount.Cancel(); + } + else if( aRequestId == KSspResultWatcher ) + { + iSspResultSession.CancelSimplePairingResult(); + } + else if ( aRequestId == KRegistryWatcher ) + { + iRegistryChange.Cancel(); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// +// --------------------------------------------------------------------------- +// +void CBTNotifConnectionTracker::HandleError( CBtSimpleActive* aActive, + TInt aError ) + { + (void) aActive; + (void) aError; + } + +// --------------------------------------------------------------------------- +// Parse the details from a client message and find the associated handler. +// --------------------------------------------------------------------------- +// +CBTNotifConnection* CBTNotifConnectionTracker::FindConnectionFromMessageL( + TInt aOpcode, const RMessage2& aMessage, TDes8& aBuffer ) + { + BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); + TInt uid = aMessage.Int0(); + aMessage.ReadL( EBTNotifSrvParamSlot, aBuffer ); + TBTDevAddr addr = ParseAddressL( uid, aBuffer ); + // If this is a + CBTNotifConnection* connection = FindConnectionHandler( addr ); + if( !connection && IsStackSecmanNotifier( uid ) && + ( aOpcode == EBTNotifStartAsyncNotifier || aOpcode == EBTNotifStartSyncNotifier ) ) + { + // A notifier from stack. This happens if e.g. the pairing + // request comes in before the link count changes (like security + // mode 3). Create the handler and queue the request. + // And note that + connection = CBTNotifConnection::NewLC( addr, this ); + iConnArray.AppendL( connection ); + CleanupStack::Pop( connection ); + } + BOstraceFunctionExitExt( DUMMY_DEVLIST, this, connection ); + return connection; + } + + +// --------------------------------------------------------------------------- +// read the address from a client message. +// --------------------------------------------------------------------------- +// +TBTDevAddr CBTNotifConnectionTracker::ParseAddressL( TInt aUid, + const TDesC8& aParamsBuf ) const + { + BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); + TBTDevAddr addr; + if( IsStackSecmanNotifier( aUid ) ) + { + // For all these, the address is the first data member, + // so can be read using the TBTNotifierParams data structure. + TBTNotifierParams params; + TPckgC paramsPckg( params ); + paramsPckg.Set( aParamsBuf ); + addr = paramsPckg().iBDAddr; + } + //else if( ) other notifier types + BOstraceFunctionExitExt( DUMMY_DEVLIST, this, &addr ); + return addr; + } + + +// --------------------------------------------------------------------------- +// Find a specific connection. +// --------------------------------------------------------------------------- +// +CBTNotifConnection* CBTNotifConnectionTracker::FindConnectionHandler( + const TBTDevAddr& aAddr ) const + { + BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); + CBTNotifConnection* conn = NULL; + if( aAddr != TBTDevAddr() ) + { + // This may be replaced by RArray::Find with appropriate key + for( TInt i = 0; i < iConnArray.Count(); i++ ) + { + if( iConnArray[i]->Address() == aAddr ) + { + conn = iConnArray[i]; + break; + } + } + } + BOstraceFunctionExitExt( DUMMY_DEVLIST, this, conn ); + return conn; + } + + +// --------------------------------------------------------------------------- +// Record and check the time between connection attempts. +// --------------------------------------------------------------------------- +// +TBool CBTNotifConnectionTracker::RecordConnectionAttempts( TBool aAccepted ) + { + BOstraceFunctionEntry1( DUMMY_DEVLIST, this ); + TBool result = ETrue; + TTime now( 0 ); + if( !aAccepted ) + { + now.UniversalTime(); + if( iLastReject ) + { + // Check the time between denied connections, that it does not go too fast. + TTimeIntervalSeconds prev( 0 ); + if( !now.SecondsFrom( TTime( iLastReject ), prev ) ) + { + if( prev <= KDENYTHRESHOLD ) + { + // We are getting the requests too fast. Present the user with + // an option to turn BT off. + //iServer->SettingsTracker()->SetPower( EFalse ); + result = EFalse; + } + } + } + } + // Record the current timestamp. + // It is reset in case the user accepted the request. + iLastReject = now.Int64(); + BOstraceFunctionExitExt( DUMMY_DEVLIST, this, result ); + return result; + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/src/btnotifdeviceselector.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifdeviceselector.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,262 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include +#include +#include +#include "btnotifdeviceselector.h" + +#include "btnotifserver.h" +#include "btnotificationmanager.h" +#include "btnotifclientserver.h" + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTNotifDeviceSelector::CBTNotifDeviceSelector( CBTNotifServer& aServer ) +: iServer( aServer ) + { + } + + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotifDeviceSelector::ConstructL() + { + iDiscoverer = CAdvanceDevDiscoverer::NewL( iServer.DevRepository(), *this ); + } + +// --------------------------------------------------------------------------- +// NewL. +// --------------------------------------------------------------------------- +// +CBTNotifDeviceSelector* CBTNotifDeviceSelector::NewL( CBTNotifServer& aServer ) + { + CBTNotifDeviceSelector* self = new( ELeave ) CBTNotifDeviceSelector( aServer ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTNotifDeviceSelector::~CBTNotifDeviceSelector() + { + if( iNotification ) + { + // Clear the notification callback, we cannot receive them anymore. + iNotification->RemoveObserver(); + iNotification->Close(); // Also dequeues the notification from the queue. + iNotification = NULL; + } + iDevices.ResetAndDestroy(); + iDevices.Close(); + delete iDiscoverer; + } + +// --------------------------------------------------------------------------- +// Process a client message related to notifiers. +// --------------------------------------------------------------------------- +// +void CBTNotifDeviceSelector::DispatchNotifierMessageL( const RMessage2& aMessage ) + { + BOstraceFunctionEntryExt ( DUMMY_LIST, this, aMessage.Function() ); + TInt opcode = aMessage.Function(); + TInt uid = aMessage.Int0(); + switch ( opcode ) + { + case EBTNotifCancelNotifier: + { + // We only accept a cancel message from the same session as the original + // request (this is enforced by the RNotifier backend). + TInt err( KErrNotFound ); + if ( !iMessage.IsNull() && opcode == iMessage.Function() && + aMessage.Session() == iMessage.Session() ) + { + iMessage.Complete( KErrCancel ); + err = KErrNone; + } + aMessage.Complete( err ); + break; + } + case EBTNotifUpdateNotifier: + { + // not handling so far + break; + } + case EBTNotifStartSyncNotifier: + { + // synch version of device searching is not supported: + aMessage.Complete( KErrNotSupported ); + break; + } + case EBTNotifStartAsyncNotifier: + { + if ( !iMessage.IsNull() ) + { + aMessage.Complete( KErrServerBusy ); + return; + } + PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource); + iDevices.ResetAndDestroy(); + iDiscoverer->DiscoverDeviceL(); + iMessage = aMessage; + break; + } + default: + { + aMessage.Complete( KErrNotSupported ); + } + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Cancels an outstanding client message related to notifiers. +// --------------------------------------------------------------------------- +// +void CBTNotifDeviceSelector::CancelNotifierMessageL( const RMessage2& aMessage ) + { + (void) aMessage; + } + +// --------------------------------------------------------------------------- +// From class MBTNotificationResult. +// Handle a result from a user query. +// --------------------------------------------------------------------------- +// +void CBTNotifDeviceSelector::MBRDataReceived( CHbSymbianVariantMap& aData ) + { + TInt err = KErrCancel; +// const CHbSymbianVariant* value = aData.Get(_L("selectedindex")); + if(aData.Keys().MdcaPoint(0).Compare(_L("selectedindex"))==KErrNone) + { + TInt val = *(static_cast(aData.Get(_L("selectedindex"))->Data())); + BOstrace1( TRACE_DEBUG, TNAME_DEVLIST_2, "MBRDataReceived, val %d", val ); + + if ( !iMessage.IsNull() ) + { + // TInt sel = val;// - TBluetoothDialogParams::EDialogExt; + TBTDeviceResponseParamsPckg devParams; + if ( val > -1 && val < iDevices.Count() ) + { + devParams().SetDeviceAddress( iDevices[val]->Addr() ); + err = iMessage.Write( EBTNotifSrvReplySlot, devParams ); + } + iMessage.Complete( err ); + } + + iDiscoverer->CancelDiscovery(); + } + else if(aData.Keys().MdcaPoint(0).Compare(_L("Stop"))==KErrNone) + { + iDiscoverer->CancelDiscovery(); + } + else if(aData.Keys().MdcaPoint(0).Compare(_L("Retry"))==KErrNone) + { + iDiscoverer->CancelDiscovery(); + iDevices.ResetAndDestroy(); + delete iDiscoverer; + iDiscoverer = NULL; + iDiscoverer = CAdvanceDevDiscoverer::NewL( iServer.DevRepository(), *this ); + iDiscoverer->DiscoverDeviceL(); + } + } + + +// --------------------------------------------------------------------------- +// From class MBTNotificationResult. +// The notification is finished. +// --------------------------------------------------------------------------- +// +void CBTNotifDeviceSelector::MBRNotificationClosed( TInt aError, const TDesC8& aData ) + { + (void) aError; + (void) aData; + iNotification->RemoveObserver(); + iNotification = NULL; + } + +// --------------------------------------------------------------------------- +// HandleNextDiscoveryResultL +// --------------------------------------------------------------------------- +// +void CBTNotifDeviceSelector::HandleNextDiscoveryResultL( + const TInquirySockAddr& aAddr, const TDesC& aName ) + { + // Todo: look for this device in repository before creating it. + CBtDevExtension* devext = CBtDevExtension::NewLC( aAddr, aName ); + iDevices.AppendL( devext ); + CleanupStack::Pop( devext ); + CHbSymbianVariantMap* map = iNotification->Data(); + TBuf<8> keyStr; + CHbSymbianVariant* devEntry; + + keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 ); + devEntry = CHbSymbianVariant::NewL( (TAny*) &(devext->Alias()), + CHbSymbianVariant::EDes ); + map->Add( keyStr, devEntry ); + iNotification->Update(); + } + +// --------------------------------------------------------------------------- +// HandleDiscoveryCompleted +// --------------------------------------------------------------------------- +// +void CBTNotifDeviceSelector::HandleDiscoveryCompleted( TInt aErr ) + { + (void) aErr; + // todo: update dialog + } + +// --------------------------------------------------------------------------- +// Get and configure a notification. +// --------------------------------------------------------------------------- +// +void CBTNotifDeviceSelector::PrepareNotificationL( + TBluetoothDialogParams::TBTDialogType aType, + TBTDialogResourceId aResourceId ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + iNotification = iServer.NotificationManager()->GetNotification(); + User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory + iNotification->SetObserver( this ); + iNotification->SetNotificationType( aType, aResourceId ); + + /* + _LIT(KTitleValue, "BT Search"); + TPtrC ptr; + ptr.Set( KTitleValue ); + iNotification->SetData( TBluetoothDialogParams::EDialogTitle, ptr ); + */ + + /*err = */ iServer.NotificationManager()->QueueNotification( iNotification ); + //NOTIF_NOTHANDLED( !err ) + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/src/btnotificationmanager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotificationmanager.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,202 @@ +/* +* ============================================================================ +* Name : btnotificationmanager.cpp +* Part of : bluetoothengine / btnotif +* Description : Class for managing user notification and query objects, and for serializing access to the notification server. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "btnotificationmanager.h" +#include "btnotifserver.h" + +#include "bluetoothnotification.h" + + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTNotificationManager::CBTNotificationManager( const CBTNotifServer* aServer ) +: iServer( aServer ) + { + } + + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotificationManager::ConstructL() + { + iAsyncCb = new( ELeave ) CAsyncCallBack( iServer->Priority() ); + TCallBack cb( AsyncCallback, this ); + iAsyncCb->Set( cb ); + } + + +// --------------------------------------------------------------------------- +// NewL. +// --------------------------------------------------------------------------- +// +CBTNotificationManager* CBTNotificationManager::NewL( const CBTNotifServer* aServer ) + { + CBTNotificationManager* self = new( ELeave ) CBTNotificationManager( aServer ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTNotificationManager::~CBTNotificationManager() + { + iNotificationQ.ResetAndDestroy(); + iNotificationQ.Close(); + iUnusedQ.ResetAndDestroy(); + iUnusedQ.Close(); + delete iAsyncCb; + } + + +// --------------------------------------------------------------------------- +// Get a new notification +// --------------------------------------------------------------------------- +// +CBluetoothNotification* CBTNotificationManager::GetNotification() + { + CBluetoothNotification* notification = NULL; + if( iUnusedQ.Count() ) + { + // Re-use the first idle notification. + notification = iUnusedQ[0]; + iUnusedQ.Remove( 0 ); + } + else + { + TRAP_IGNORE( notification = CBluetoothNotification::NewL( this ) ); + } + if( notification ) + { + if( iNotificationQ.Append( notification ) ) + { + // In case the appending fails, we just delete the notification. + // Otherwise we cannot keep track of it anymore. + delete notification; + notification = NULL; + } + } + return notification; + } + + +// --------------------------------------------------------------------------- +// Release the notification +// --------------------------------------------------------------------------- +// +void CBTNotificationManager::ReleaseNotification( CBluetoothNotification* aNotification ) + { + __ASSERT_ALWAYS( aNotification, PanicServer( EBTNotifPanicBadArgument ) ); + TInt pos = iNotificationQ.Find( aNotification ); + __ASSERT_ALWAYS( pos > KErrNotFound, PanicServer( EBTNotifPanicMissing ) ); + // ToDo: Cancel outstanding notification! + iNotificationQ.Remove( pos ); + TInt err = iUnusedQ.Append( aNotification ); + aNotification->Reset(); // Clean up notification's resources + if( err ) + { + // Just delete the notification. + delete aNotification; + } + if( !iAsyncCb->IsActive() ) + { + if( !iNotificationQ.Count() ) + { + // Set the priority so that this is the last scheduled active object to execute. + iAsyncCb->SetPriority( CActive::EPriorityIdle ); + } + iAsyncCb->CallBack(); + } + } + + +// --------------------------------------------------------------------------- +// Queue the notification with given priority +// --------------------------------------------------------------------------- +// +TInt CBTNotificationManager::QueueNotification( CBluetoothNotification* aNotification, + TNotificationPriority aPriority ) + { + TInt pos = iNotificationQ.Find( aNotification ); + __ASSERT_ALWAYS( pos > KErrNotFound, PanicServer( EBTNotifPanicMissing ) ); + if( aPriority == EPriorityHigh && pos != 0 ) + { + // ToDo: Move the note to the front of the queue + } + if( !iAsyncCb->IsActive() ) + { + if( iAsyncCb->Priority() != iServer->Priority() ) + { + // Reset priority back to original value + // We first check the current priority, otherwise CActive will do an + // unnecessary removal and adding of the callback from the active scheduler. + iAsyncCb->SetPriority( iServer->Priority() ); + } + iAsyncCb->CallBack(); + } + return KErrNone; + } + + +// --------------------------------------------------------------------------- +// Process the notification queue and launch the next notification. +// --------------------------------------------------------------------------- +// +void CBTNotificationManager::ProcessNotificationQueueL() + { + if( iNotificationQ.Count() ) + { + TInt err = iNotificationQ[0]->Show(); + // If the note is already showing, it will return KErrAlreadyExists + (void) err; // ToDo: add error handling!! + NOTIF_NOTHANDLED( !err || err == KErrAlreadyExists || err == KErrNotFound ) + } + else + { + // No outstanding notifications, and unused notifications. + // Clean up the unused notifications. + iUnusedQ.ResetAndDestroy(); + iNotificationQ.Reset(); // the queue is empty, reset it. + // Also clean up any resources. + } + } + + +// --------------------------------------------------------------------------- +// Callback for asynchronous processing of queued notification requests. +// --------------------------------------------------------------------------- +// +TInt CBTNotificationManager::AsyncCallback( TAny* aPtr ) + { + TRAPD( err, ( (CBTNotificationManager*) aPtr )->ProcessNotificationQueueL() ); + return err; + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/src/btnotifpairinghelper.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifpairinghelper.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,958 @@ +/* +* ============================================================================ +* Name : btnotifpairinghelper.cpp +* Part of : bluetoothengine / btnotif +* Description : Helper class for processing pairing requests and results, as extended functionality for CBTNotifConnection. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "btnotifpairinghelper.h" +#include +#include +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS +#include +#endif + +#include "btnotifconnection.h" +#include "btnotifconnectiontracker.h" +#include "btnotificationmanager.h" +#include "btnotifserver.h" +#include "bluetoothtrace.h" + +/** Id for the active object for a dedicated bonding session. */ +const TInt KDedicatedBonding = 50; +/** Length of the default PIN. */ +const TInt KDefaultPinLength = 4; +/** Default PIN character. */ +const TText8 KDefaultPinValue = '0'; +/** Format syntax for numeric comparison value. */ +_LIT( KNumCompFormat, "%06u" ); +/** Format syntax for passkey display value. */ +_LIT( KPassKeyFormat, "%06u" ); + + +// ======== LOCAL FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// ?description +// --------------------------------------------------------------------------- +// +/*?type ?function_name( ?arg_type ?arg, + ?arg_type ?arg ) + { + } +*/ + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor. +// --------------------------------------------------------------------------- +// +CBTNotifPairingHelper::CBTNotifPairingHelper( CBTNotifConnection* aConnection, + CBTNotifConnectionTracker* aTracker ) +: iConnection( aConnection ), + iTracker( aTracker ) + { + } + + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::ConstructL() + { + if( iConnection ) + { + iDevice = iConnection->BTDevice(); + } + } + + +// --------------------------------------------------------------------------- +// NewL +// --------------------------------------------------------------------------- +// +CBTNotifPairingHelper* CBTNotifPairingHelper::NewL( CBTNotifConnection* aConnection, + CBTNotifConnectionTracker* aTracker ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + CBTNotifPairingHelper* self = new( ELeave ) CBTNotifPairingHelper( aConnection, aTracker ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + return self; + } + + +// --------------------------------------------------------------------------- +// Destructor. +// --------------------------------------------------------------------------- +// +CBTNotifPairingHelper::~CBTNotifPairingHelper() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + if( iNotification ) + { + // Clear the notification callback, we cannot receive them anymore. + iNotification->RemoveObserver(); + iNotification->Close(); // Also dequeues the notification from the queue. + iNotification = NULL; + } + delete iParams; + if( iBondingActive ) + { + iBondingActive->Cancel(); // Will close subsession; + } + delete iBondingActive; + iBondingSession.Close(); + iBondingSocket.Close(); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Handle the authentication result from the baseband. Show the result in a note. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::HandleAuthenticationCompleteL( TInt aError ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); + if( iOperation == EDedicatedBonding || iOperation == EAwaitingPairingResult || + iOperation == EAutoPairing ) + { + // Default case (aError == 0): Success, we are now paired. + TBTDialogResourceId resourceId = EPairingSuccess; + TBool autoPairing = ( iOperation == EAutoPairing ); // Remember the autopairing state + iOperation = EShowPairingSuccess; + if( aError && aError != KHCIErrorBase ) + { + // Authentication failure, means pairing failed. + resourceId = EPairingFailure; + iOperation = EShowPairingFailure; + // Communicate the error now that we still remember it. + if( iDedicatedBonding ) + { + if( autoPairing && aError == KHCIErrorBase - EAuthenticationFailure ) + { + BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, + "[BTNOTIF]\t CBTNotifPairingHelper::HandleAuthenticationCompleteL: Autopairing failed, we need to try again."); + // Autopairing failed, we need to try again. + iOperation = EAutoPairing; // Reset back + resourceId = ENoResource; + } + CompleteBondingL( aError ); + } + } + if( resourceId ) + { + // Inform the user of the result. + BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, + "[BTNOTIF]\t CBTNotifPairingHelper::HandleAuthenticationCompleteL: pairing successful, inform user" ); + PrepareNotificationL( TBluetoothDialogParams::EGlobalNotif, resourceId ); + // MBRNotificationClosed will be called from this, which will + // check the next stage. + } + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Start a bonding operation with the remote device. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::StartBondingL( TInt aHandle ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aHandle ); + __ASSERT_ALWAYS( iOperation == EIdle || iOperation == EDedicatedBonding + || iOperation == EAutoPairing, PanicServer( EBTNotifPanicBadState ) ); + if( !iBondingActive ) + { + iBondingActive = CBtSimpleActive::NewL( *this, KDedicatedBonding ); + } + if( aHandle ) + { + iDedicatedBonding = aHandle; + } + if( iOperation == EIdle ) + { + iOperation = EDedicatedBonding; + } + if( iOperation == EDedicatedBonding && iTracker->PairingServerSession() ) + { + if( !iBondingActive->IsActive() ) + { + BtTraceBtAddr1( TRACE_DEBUG,DUMMY_LIST,"CBTNotifPairingHelper::StartBondingL()",iDevice->BDAddr() ); + iBondingSession.Start( *iTracker->PairingServerSession(), + iDevice->BDAddr(), iBondingActive->RequestStatus() ); + iBondingActive->GoActive(); + } + } + else + { + // We are doing autopairing (or the unlikely situation that the pairing server is unavailable) + CompleteBondingL( KErrServerTerminated ); + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this); + } + + +// --------------------------------------------------------------------------- +// Cancel an ongoing bonding operation with the remote device. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::CancelBondingL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + if( iDedicatedBonding ) + { + CompleteBondingL( KErrCancel ); // Closes sessions + if( iNotification ) + { + // Cancel the outstanding user query + // This will also unregister us from the notification. + TInt err = iNotification->Close(); + NOTIF_NOTHANDLED( !err ) + iNotification = NULL; + } + if( iNotifierUid ) + { + // Also finish up the notifier processing. + CompletePairingNotifierL( KErrCancel, EFalse, KNullDesC8 ); + } + iOperation = EIdle; + iConnection->PairingCompleted(); // This may delete us. + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Handle a notifier request for pairing with the remote device of this connection. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::StartPairingNotifierL( TInt aUid, const TDesC8& aParams ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aUid ); + if( iDevice->GlobalSecurity().Banned() && !iDedicatedBonding ) + { + // ToDo: should this case actually be ignored, and presume that + // the caller will take care of unblocking the device? + iOperation = EIdle; + User::Leave( KErrAccessDenied ); + } + // Store the parameters locally, we need them later again. + delete iParams; + iParams = NULL; + iParams = HBufC8::NewL( aParams.Length() ); + *iParams = aParams; + iNotifierUid = aUid; + + if( iDevice->IsValidPaired() && iDevice->IsPaired() ) + { + // The device is still paired, we unpair it first. + // Deleting the link key will set the device as unpaired. + iDevice->DeleteLinkKey(); + iOperation = EUnpairing; // So that parent state does not get changed. + iConnection->UpdateRegistryEntryL(); + // Note that this will only be done before trying autopairing, so + // it not interfere with a second attempt; + } + // Update the device name + TBTPasskeyDisplayParams params; // Enough for reading the base class type parameter + TPckgC paramsPckg( params ); + paramsPckg.Set( *iParams ); + if( paramsPckg().DeviceName().Length() ) + { + // The name in the parameter package is the latest one, retrieved from + // the remote device during this connection. Update locally. + iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( paramsPckg().DeviceName() ) ); + } + + TBool locallyInitiated = EFalse; + TBuf<8> numVal; + TBluetoothDialogParams::TBTDialogType dialog = TBluetoothDialogParams::EInvalidDialog; + TBTDialogResourceId resource = ENoResource; + // Read the notifier parameters (sets iOperation as well) + ParseNotifierReqParamsL( locallyInitiated, numVal, dialog, resource ); + // If this is an incoming pairing, we first ask the user to accept it. + if( !locallyInitiated && !iDedicatedBonding ) + { + // Ignore the initatior if we initiated bonding. + StartAcceptPairingQueryL(); // Overrides iOperation + } + else + { + __ASSERT_ALWAYS( resource != ENoResource, PanicServer( EBTNotifPanicBadState ) ); + CheckAutoPairingL( locallyInitiated, numVal ); + // CheckAutoPairingL sets + if( iOperation != EAutoPairing ) + { + PrepareNotificationL( dialog, resource ); + if( numVal.Length() ) + { + TInt err = iNotification->SetData( TBluetoothDeviceDialog::EAdditionalDesc, numVal ); + NOTIF_NOTHANDLED( !err ) + } + } + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Update a notifier, update the outstanding dialog if the notifier request +// is currently being served. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::UpdatePairingNotifierL( TInt aUid, const TDesC8& aParams ) + { + (void) aUid; + TBTNotifierUpdateParams2 params; // Enough for reading the base class type parameter + TPckgC paramsPckg( params ); + paramsPckg.Set( aParams ); + if( paramsPckg().Type() == TBTNotifierUpdateParams2::EPasskeyDisplay ) + { + // Paskey display update - keypress on remote device. + } + else + { + // name update + TBTDeviceNameUpdateParams nameUpdate; + TPckgC nameUpdatePckg( nameUpdate ); + nameUpdatePckg.Set( aParams ); + // The result means result of conversion to unicode + if( !nameUpdatePckg().Result() ) + { + // Only update locally, registry will update us with the same info later on. + iDevice->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( nameUpdatePckg().DeviceName() ) ); + if( iNotification ) + { + // Update the dialog with the new name. It is up to the dialog to + // determine the validity (in case another dialog is shown). + //iNotification->Update( ) + } + } + } + } + + +// --------------------------------------------------------------------------- +// Cancel a request, dismiss the outstanding dialog if the notifier request +// is currently being served. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::CancelPairingNotifierL( TInt aUid ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + // ToDo: we need to check that the UID and the outstanding notification + // type are matching? + if( iOperation > EIdle && iOperation < EPostPairingOperations && aUid == iNotifierUid && + ( aUid == KBTPinCodeEntryNotifierUid.iUid || + aUid == KBTNumericComparisonNotifierUid.iUid || + aUid == KBTPasskeyDisplayNotifierUid.iUid ) ) + { + if( iNotification ) + { + // Cancel the user query + // This will also unregister us from the notification. + TInt err = iNotification->Close(); + NOTIF_NOTHANDLED( !err ) + iNotification = NULL; + } + iOperation = EIdle; + iNotifierUid = 0; + // We do not call pairing completed from here, our parent will + // check our status by itself, and may delete us. + + // Any bonding requester needs to be informed though. + CancelBondingL(); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::StartJustWorksProcessingL() + { + } + + +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::CancelJustWorksProcessingL() + { + } + + +// --------------------------------------------------------------------------- +// From class MBTNotificationResult. +// Handle a result from a user query. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::MBRDataReceived( CHbSymbianVariantMap& aData ) + { + (void) aData; + NOTIF_NOTIMPL + } + + +// --------------------------------------------------------------------------- +// From class MBTNotificationResult. +// The notification is finished. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::MBRNotificationClosed( TInt aError, const TDesC8& aData ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); + // First unregister from the notification, so we can already get the next one. + iNotification->RemoveObserver(); + iNotification = NULL; + TRAP_IGNORE( NotificationClosedL( aError, aData ) ); + if( iOperation == EIdle ) + { + // Any error has been communicated already. + iConnection->PairingCompleted(); // This may delete us. + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// Handle the active object completion. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::RequestCompletedL( CBtSimpleActive* aActive, + TInt aStatus ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + switch( aActive->RequestId() ) + { + case KDedicatedBonding: + { + if( iDedicatedBonding ) + { + // If the result hasn't been processed already. + HandleAuthenticationCompleteL( aStatus ); + } + } + break; + default: + NOTIF_NOTIMPL + break; + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// Cancel and clean up all requests related to the active object. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::CancelRequest( TInt aRequestId ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + switch( aRequestId ) + { + case KDedicatedBonding: + iBondingSession.Close(); + break; + default: + NOTIF_NOTIMPL + break; + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::HandleError( CBtSimpleActive* aActive, + TInt aError ) + { + (void) aActive; + (void) aError; + } + +// --------------------------------------------------------------------------- +// Process the user input and complete the outstanding pairing request. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::CompletePairingNotifierL( TInt aError, TBool aResult, + const TDesC8& aData ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); + TInt err = aError; + TPtrC8 resultData; + if( !err ) + { + // The returned data is the entered passkey. + TBool proceed = iTracker->UpdateBlockingHistoryL( iDevice, aResult ); + if( iOperation == ESspPairing && iNotifierUid == KBTNumericComparisonNotifierUid.iUid ) + { + // Numeric comparison needs the boolean result passed back. + TPckgBuf userAcceptance( aResult ); + resultData.Set( userAcceptance ); + } + if( aResult ) + { + if( iOperation == ELegacyPairing || iOperation == EAutoPairing ) + { + // Check the passkey entered by the user. + // The length of the returned data equals the number of characters + // entered by the user. + TBTPinCode pinCode; + pinCode().iLength = aData.Length(); + TUint minLen = 0; + TBool locallyInitiated = EFalse; // Not used here. + ParsePinCodeReqParamsL( locallyInitiated, minLen ); + if( aData.Length() >= minLen ) + { + // Check that the length of the passkey meets the minimum + // required pin code length + for( TInt i = 0; i < aData.Length(); i++ ) + { + pinCode().iPIN[i] = aData[i]; + } + resultData.Set( pinCode ); + } + else + { + // PIN wasn't long enough. This should be handled by the dialog though. + err = KErrCompletion; + } + } + // Now we just wait for the result to come in. + if( iOperation != EAutoPairing ) + { + iOperation = EAwaitingPairingResult; + } + } + else + { + err = KErrCancel; + TBool locallyInitiated = EFalse; // Needed below + TBuf<8> numVal; // Not needed here. + TBluetoothDialogParams::TBTDialogType type = TBluetoothDialogParams::EInvalidDialog; + TBTDialogResourceId resource = ENoResource; // Resources and type are not needed here. + // Check the notifier parameters + ParseNotifierReqParamsL( locallyInitiated, numVal, type, resource ); + if( proceed && locallyInitiated && !iDedicatedBonding ) + { + // The user denied the connection, ask to block the device. + // This is only for pairing (and not bonding) initiated by us, + // as the user already gets the opportunity to block when + // rejecting an incoming pairing request. + // This case may be for someone requesting to access a service + // which requires authentication by us, but not by the remote device. + iConnection->LaunchBlockingQueryL(); + // For incoming pairing, blocking is asked after rejecting the + // pairing request. This is done in CompleteAcceptPairingQueryL + } + CompleteBondingL( err ); // Notify the client if there was a bonding request. + } + } + iNotifierUid = 0; // Clean up notifier data + delete iParams; + iParams = NULL; + if( err ) + { + iOperation = EIdle; // We are done now. + } + // Complete the message with the result, and result data if any. + iConnection->CompleteClientRequest( err, resultData ); + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Completes a bonding operation. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::CompleteBondingL( TInt aError ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); + if( iDedicatedBonding ) + { + if( iBondingActive ) + { + iBondingActive->Cancel(); // Will close subsession; + } + iBondingSession.Close(); // In case not active + iBondingSocket.Close(); + } + // Determine if we try another time. + if( ( iOperation == EAutoPairing && aError == KHCIErrorBase - EAuthenticationFailure ) || + ( iDedicatedBonding && iOperation == EAwaitingPairingResult && + aError == KErrRemoteDeviceIndicatedNoBonding ) || + aError == KErrServerTerminated ) + { + // The cases are: 2) autopairing with a headset that has a non-default passkey + // 2) SSP dedicated bonding with a device that does not allow that. + // 3) the pairing server is unavailable (unlikely) + // Then we try another time, requesting authentication on a + // RBTPhysicialLinkAdapter + BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, + "[BTNOTIF]\t CBTNotifPairingHelper::CompleteBondingL: trying another time." ); + TInt err = iBondingSocket.Open( iTracker->SocketServerSession(), iConnection->Address() ); + TUint32 linkState = 0; + if( !err ) + { + err = iBondingSocket.PhysicalLinkState( linkState ); + } + if( !err && linkState & ENotifyPhysicalLinkUp ) + { + err = iBondingSocket.Authenticate(); + // Now wait for the dialog and then the link state notification + } + else + { + // We need to wait for the link to come up. We wait until our + // parent calls us again. + iBondingSocket.Close(); + } + if( err ) + { + // Cannot continue, show the result to the user. + BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, + "[BTNOTIF]\t CBTNotifPairingHelper::HandleAuthenticationCompleteL: pairing failed, complete message." ); + iOperation = EShowPairingFailure; + PrepareNotificationL( TBluetoothDialogParams::ENote, EPairingFailure ); + } + } + if( iDedicatedBonding && iOperation != EAutoPairing ) + { + BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, + "[BTNOTIF]\t CBTNotifPairingHelper::CompleteBondingL: complete message." ); + TInt err = iTracker->Server()->CompleteMessage( iDedicatedBonding, aError, KNullDesC8 ); + NOTIF_NOTHANDLED( !err ) + iDedicatedBonding = 0; + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::CompleteJustWorksProcessingL( TInt aError ) + { + (void) aError; + } + + +// --------------------------------------------------------------------------- +// Ask the user to allow incoming pairing. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::StartAcceptPairingQueryL() + { + iOperation = EAcceptPairing; + PrepareNotificationL( TBluetoothDialogParams::EQuery, EIncomingPairing ); + // if rejected, the client message is completed in CompleteAcceptPairingQueryL + } + + +// --------------------------------------------------------------------------- +// The user was asked to accept an incoming pairing. Process and proceed. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::CompleteAcceptPairingQueryL( TInt aError, TBool aResult ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + // Set our state to idle for now. This may get changed if the user just chose + // to block, or if we have a pending request. + iOperation = EIdle; + TInt err = aError; + if( !err ) + { + TBool proceed = iTracker->UpdateBlockingHistoryL( iDevice, aResult ); + if( aResult ) + { + // User accepted, continue to show pairing query. + // Minimum lenght does not apply, should only be set on outgoing pairing + TBool locallyInitiated = EFalse; + TBuf<8> numVal; + TBluetoothDialogParams::TBTDialogType dialog = TBluetoothDialogParams::EInvalidDialog; + TBTDialogResourceId resource = ENoResource; + // Read the notifier parameters + ParseNotifierReqParamsL( locallyInitiated, numVal, dialog, resource ); + __ASSERT_ALWAYS( resource != ENoResource, PanicServer( EBTNotifPanicBadState ) ); + PrepareNotificationL( dialog, resource ); + if( numVal.Length() ) + { + TInt err = iNotification->SetData( TBluetoothDeviceDialog::EAdditionalDesc, numVal ); + NOTIF_NOTHANDLED( !err ) + } + } + else + { + err = KErrCancel; + if( proceed ) + { + // The user denied the connection, ask to block the device. + iConnection->LaunchBlockingQueryL(); + } + } + } + if( err ) + { + // The user denied the connection, or something else prevented completion. + CompletePairingNotifierL( err, EFalse, KNullDesC8 ); + } + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Launch a dialog for setting the device as trusted. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::StartTrustedQueryL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + // Assume that the registry update has come through by now. + iOperation = EQueryTrust; + PrepareNotificationL( TBluetoothDialogParams::EQuery, ESetTrusted ); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// Process the user input for setting the device as trusted. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::CompleteTrustedQueryL( TInt aError, TBool aResult ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); + BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, + "CBTNotifPairingHelper::CompleteTrustedQueryL() err=%d result=%d", aError, aResult ); + iOperation = EIdle; // We are done with pairing now. + if( !aError && aResult ) + { + // need to update pairing info from registry before writing trusted status + iConnection->UpdateRegistryEntryL(true); + } + CompleteBondingL( KErrNone ); // Notify the client if there was a bonding request. + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Parse the parameters of a request for pairing. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::ParseNotifierReqParamsL( TBool& aLocallyInitiated, + TDes& aNumVal, TBluetoothDialogParams::TBTDialogType& aDialogType, + TBTDialogResourceId& aResourceId ) + { + // Determine the notifier type by the length of the parameter buffer + if( iNotifierUid == KBTPinCodeEntryNotifierUid.iUid ) + { + aNumVal.Zero(); + TUint minLen = 0; + ParsePinCodeReqParamsL( aLocallyInitiated, minLen ); + if( minLen ) + { + // Don't set zero to this buffer, the buffer length serves for this. + aNumVal.Num( minLen ); + } + aDialogType = TBluetoothDialogParams::EInput; + aResourceId = EPinInput; + if( iOperation != EAutoPairing ) + { + iOperation = ELegacyPairing; + } + } + else if( iNotifierUid == KBTNumericComparisonNotifierUid.iUid ) + { + ParseNumericCompReqParamsL( aLocallyInitiated, aNumVal ); + aDialogType = TBluetoothDialogParams::EQuery; + aResourceId = ENumericComparison; + iOperation = ESspPairing; + } + else if( iNotifierUid == KBTPasskeyDisplayNotifierUid.iUid ) + { + ParsePasskeyDisplayReqParamsL( aLocallyInitiated, aNumVal ); + aDialogType = TBluetoothDialogParams::EQuery; + aResourceId = EPasskeyDisplay; + iOperation = ESspPairing; + } + } + + +// --------------------------------------------------------------------------- +// Parse the parameters of a request for pairing using pin query. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::ParsePinCodeReqParamsL( TBool& aLocallyInitiated, + TUint& aNumVal ) + { + TBTPinCodeEntryNotifierParams params; + TPckgC paramsPckg( params ); + paramsPckg.Set( *iParams ); + aLocallyInitiated = paramsPckg().LocallyInitiated(); + aNumVal = paramsPckg().PinCodeMinLength(); + } + + +// --------------------------------------------------------------------------- +// Parse the parameters of a request for pairing using numeric comparison. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::ParseNumericCompReqParamsL( TBool& aLocallyInitiated, + TDes& aNumVal ) + { + TBTNumericComparisonParams params; + TPckgC paramsPckg( params ); + paramsPckg.Set( *iParams ); + aLocallyInitiated = paramsPckg().LocallyInitiated(); + TBTNumericComparisonParams::TComparisonScenario scenario = + paramsPckg().ComparisonScenario(); + aNumVal.Format( KNumCompFormat, paramsPckg().NumericalValue() ); + } + + +// --------------------------------------------------------------------------- +// Parse the parameters of a request for pairing using passkey display. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::ParsePasskeyDisplayReqParamsL( TBool& aLocallyInitiated, + TDes& aNumVal ) + { + TBTPasskeyDisplayParams params; + TPckgC paramsPckg( params ); + paramsPckg.Set( *iParams ); + aLocallyInitiated = paramsPckg().LocallyInitiated(); + aNumVal.Format( KPassKeyFormat, paramsPckg().NumericalValue() ); + } + + +// --------------------------------------------------------------------------- +// Check if we can guess the PIN and complete the notifier without user interaction. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::CheckAutoPairingL( TBool aLocallyInitiated, const TDesC& aNumVal ) + { + TUint minLen = 0; + if( aNumVal.Length() ) + { + ParsePinCodeReqParamsL( aLocallyInitiated, minLen ); + } + // ToDo: Add support for NFC OOB pairing + if( iDedicatedBonding && iOperation == ELegacyPairing && + iDevice->DeviceClass().MajorDeviceClass() == EMajorDeviceAV && + iDevice->DeviceClass().MinorDeviceClass() != EMinorDeviceAVHandsfree && + minLen <= KDefaultPinLength ) + { + // Outgoing bonding with headset and no passkey requirement => AutomatedPairing + // Complete message with 0000 and return. + iOperation = EAutoPairing; + TBuf8 )> defaultPin( KDefaultPinLength ); + for( TInt i = 0; i < KDefaultPinLength; i++ ) + { + defaultPin[i] = KDefaultPinValue; + } + // Complete the pairing through the function dedicated to that. + CompletePairingNotifierL( KErrNone, ETrue, defaultPin ); + } + else if( iOperation == EAutoPairing ) + { + iOperation = ELegacyPairing; // Reset the autopairing status + } + } + + +// --------------------------------------------------------------------------- +// Get and configure a notification. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::PrepareNotificationL( TBluetoothDialogParams::TBTDialogType aType, + TBTDialogResourceId aResourceId ) + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + __ASSERT_ALWAYS( iOperation != EIdle || aType == TBluetoothDialogParams::ENote, PanicServer( EBTNotifPanicBadState ) ); + iNotification = iTracker->NotificationManager()->GetNotification(); + User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory + iNotification->SetObserver( this ); + iNotification->SetNotificationType( aType, aResourceId ); + TBTDeviceName name; + GetDeviceNameL( name, *iDevice ); + TInt err = iNotification->SetData( TBluetoothDeviceDialog::EDeviceName, name ); + NOTIF_NOTHANDLED( !err ) + // Re-use name buffer for 16-bit descriptor representation of remote address. + iConnection->Address().GetReadable( name ); + err = iNotification->SetData( TBluetoothDialogParams::EAddress, name ); + NOTIF_NOTHANDLED( !err ) + err = iNotification->SetData( (TInt) TBluetoothDeviceDialog::EDeviceClass, + iDevice->DeviceClass().DeviceClass() ); + err = iTracker->NotificationManager()->QueueNotification( iNotification ); + NOTIF_NOTHANDLED( !err ) + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + + +// --------------------------------------------------------------------------- +// The notification is finished, handle the result. +// --------------------------------------------------------------------------- +// +void CBTNotifPairingHelper::NotificationClosedL( TInt aError, const TDesC8& aData ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aError ); + // Read the result. + TPckgC result( EFalse ); + result.Set( aData.Ptr(), result.Length() ); // Read the part containing the result + // Set a pointer descriptor to capture the remaining data, if any. + TPtrC8 dataPtr( aData.Mid( result.Length() ) ); + switch( iOperation ) + { + case EAcceptPairing: + CompleteAcceptPairingQueryL( aError, result() ); + break; + case ELegacyPairing: + case ESspPairing: + CompletePairingNotifierL( aError, result(), dataPtr ); + break; + case EQueryTrust: + CompleteTrustedQueryL( aError, result() ); + break; + case EShowPairingSuccess: + StartTrustedQueryL(); + break; + case EShowPairingFailure: + // Pairing failure, we are done. + iOperation = EIdle; + break; + default: + NOTIF_NOTIMPL + break; + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/src/btnotifserver.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifserver.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,370 @@ +/* +* ============================================================================ +* Name : btnotifserver.cpp +* Part of : bluetoothengine / btnotif +* Description : Server class for handling commands from clients, and the +* central class in btnotif thread. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "btnotifserver.h" +#include +#include "btnotifsession.h" +#include "btnotifconnectiontracker.h" +#include "btnotifsettingstracker.h" +#include "btnotificationmanager.h" +#include "btnotifdeviceselector.h" +#include "btnotifserversecpolicy.h" +#include "btnotifclientserver.h" + +/** Panic category */ +_LIT( KBTNotifPanic, "BTNotif panic" ); + +/** Timeout (10 sec) for shutting down the server + * (when BT power is off and no clients connected). */ +const TInt KBTNtoifShutdownTimeout = 10 * 1000 * 1000; + +// ======== LOCAL FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// Start the server. +// --------------------------------------------------------------------------- +// +static void RunServerL() + { + BOstraceFunctionEntry0( DUMMY_DEVLIST ); + + (void) User::RenameThread( KBTNotifServerName ); + // Create and install the active scheduler for this thread. + CActiveScheduler* scheduler = new( ELeave ) CActiveScheduler(); + CleanupStack::PushL( scheduler ); + CActiveScheduler::Install( scheduler ); + // create the server (and leave it on the cleanup stack) + CBTNotifServer* notifServer = CBTNotifServer::NewLC(); + // Initialisation complete, now signal the client + RProcess::Rendezvous( KErrNone ); + // The server is now up and running. + BOstrace0( TRACE_NORMAL, DUMMY_DEVLIST, "[BTNOTIF]\t BTNotif server now up and running" ); + // The active scheduler runs during the lifetime of this thread. + CActiveScheduler::Start(); + // Stopping the active scheduler means terminating the thread. + // Cleanup the server and scheduler. + CleanupStack::PopAndDestroy( notifServer ); + CleanupStack::PopAndDestroy( scheduler ); + BOstraceFunctionExit0( DUMMY_DEVLIST ); + } + +// --------------------------------------------------------------------------- +// Panic the server. +// --------------------------------------------------------------------------- +// +void PanicServer( TInt aReason ) + { + User::Panic( KBTNotifPanic, aReason ); + } + +// --------------------------------------------------------------------------- +// Panic the client through the client-side message. +// --------------------------------------------------------------------------- +// +void PanicClient( const RMessage2& aMessage, TInt aReason ) + { + aMessage.Panic( KBTNotifPanic, aReason ); + } + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTNotifServer::CBTNotifServer() +: CPolicyServer( EPriorityUserInput, KBTNotifServerPolicy ) + { + } + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotifServer::ConstructL() + { + // Add the server to the active scheduler (from CServer2): + StartL( KBTNotifServerName ); + iAsyncCb = new( ELeave ) CAsyncCallBack( EPriorityHigh ); + TCallBack cb( AsyncConstructCb, this ); + iAsyncCb->Set( cb ); + iAsyncCb->CallBack(); + } + +// --------------------------------------------------------------------------- +// Asynchronous 3rd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotifServer::AsyncConstructL() + { + iSettingsTracker = CBTNotifSettingsTracker::NewL( this ); + if( iSettingsTracker->GetPowerState() == EBTPowerOn ) + { + iConnectionTracker = CBTNotifConnectionTracker::NewL( this ); + } + iNotificationMgr = CBTNotificationManager::NewL( this ); + + iTimer = CDeltaTimer::NewL(CActive::EPriorityLow); + TCallBack shutdownCb( ShutdownTimeout, this ); + iShutdownTimerEntry.Set( shutdownCb ); + // The server class does not handle any registry events. + // Classes that want to receive these events must register + // via observer interface. + iDevRep = CBtDevRepository::NewL(); + } + +// --------------------------------------------------------------------------- +// Callback for asynchronous construction. +// --------------------------------------------------------------------------- +// +TInt CBTNotifServer::AsyncConstructCb( TAny* aPtr ) + { + TRAPD( err, ( (CBTNotifServer*) aPtr )->AsyncConstructL() ); + return err; + } + + +// --------------------------------------------------------------------------- +// NewLC. +// --------------------------------------------------------------------------- +// +CBTNotifServer* CBTNotifServer::NewLC() + { + CBTNotifServer* self = new( ELeave ) CBTNotifServer(); + CleanupStack::PushL( self ); + self->ConstructL(); + return self; + } + + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTNotifServer::~CBTNotifServer() + { + delete iDevSelector; + delete iSettingsTracker; + delete iConnectionTracker; + delete iNotificationMgr; + delete iAsyncCb; + delete iTimer; + delete iDevRep; + } + +// --------------------------------------------------------------------------- +// Handle a change in BT power state. +// --------------------------------------------------------------------------- +// +void CBTNotifServer::HandlePowerStateChangeL( TBTPowerStateValue aState ) + { + if( aState && !iConnectionTracker ) + { + // only construct tracker if it is not available yet + iConnectionTracker = CBTNotifConnectionTracker::NewL( this ); + } + else + { + delete iConnectionTracker; + iConnectionTracker = NULL; + } + CheckIdle( aState ); + } + +// --------------------------------------------------------------------------- +// Increase the session count. +// --------------------------------------------------------------------------- +// +void CBTNotifServer::AddSession() + { + ++iSessionCount; + iTimer->Remove( iShutdownTimerEntry ); + } + + +// --------------------------------------------------------------------------- +// Decrease the session count. +// --------------------------------------------------------------------------- +// +void CBTNotifServer::RemoveSession() + { + if ( iSessionCount > 0 ) + { + // session counter can't be less than 0 + --iSessionCount; + } + CheckIdle( iSettingsTracker->GetPowerState() ); + } + +// --------------------------------------------------------------------------- +// get the singleton instance of device repository +// --------------------------------------------------------------------------- +// +CBtDevRepository& CBTNotifServer::DevRepository() + { + return *iDevRep; + } + +// --------------------------------------------------------------------------- +// get the singleton instance of device search notifier +// --------------------------------------------------------------------------- +// +CBTNotifDeviceSelector& CBTNotifServer::DeviceSelectorL() + { + if ( ! iDevSelector ) + { + iDevSelector = CBTNotifDeviceSelector::NewL( *this ); + } + return *iDevSelector; + } + +// --------------------------------------------------------------------------- +// Searches for a client message from a message handle and completes it. +// --------------------------------------------------------------------------- +// +TInt CBTNotifServer::CompleteMessage( TInt aHandle, TInt aReason, const TDesC8& aReply ) + { + TInt err = KErrNotFound; + iSessionIter.SetToFirst(); + CBTNotifSession* session = NULL; + while( ( session = (CBTNotifSession*) iSessionIter++ ) != NULL ) + { + err = session->CompleteMessage( aHandle, aReason, aReply ); + if( err != KErrNotFound ) + { + // Found the correct session, and message, and completed it. + break; + } + } + return err; + } + + +// --------------------------------------------------------------------------- +// Searches for a client message from a message handle and returns it. +// --------------------------------------------------------------------------- +// +const RMessage2* CBTNotifServer::FindMessageFromHandle( TInt aHandle ) + { + const RMessage2* message = NULL; + iSessionIter.SetToFirst(); + CBTNotifSession* session = NULL; + while( ( session = (CBTNotifSession*) iSessionIter++ ) != NULL ) + { + message = session->FindMessageFromHandle( aHandle ); + if( message ) + { + // Found the correct session and message to return. + break; + } + } + return message; + } + + +// --------------------------------------------------------------------------- +// Searches for a client message from a message handle and returns it. +// --------------------------------------------------------------------------- +// +const RMessage2* CBTNotifServer::FindMessageFromUid( TInt aUid ) + { + const RMessage2* message = NULL; + iSessionIter.SetToFirst(); + CBTNotifSession* session = NULL; + while( ( session = (CBTNotifSession*) iSessionIter++ ) != NULL ) + { + message = session->FindMessageFromUid( aUid ); + if( message ) + { + // Found the correct session and message to return. + break; + } + } + return message; + } + + +// --------------------------------------------------------------------------- +// From class CPolicyServer. +// Create a new session object. +// --------------------------------------------------------------------------- +// +CSession2* CBTNotifServer::NewSessionL( const TVersion& aVersion, + const RMessage2& aMessage ) const + { + (void) aMessage; + // Compare our version with client-side version, CServer2 requires that + // we leave if they are not compatible. + TVersion srvVersion( KBTNotifServerVersionMajor, KBTNotifServerVersionMinor, + KBTNotifServerVersionBuild ); + + if( !User::QueryVersionSupported( aVersion, srvVersion ) ) + { + // EFalse is returned if our version is not less than or + // equal to the client version. + User::Leave( KErrNotSupported ); + } + return CBTNotifSession::NewL(); + } + +void CBTNotifServer::CheckIdle( TBTPowerStateValue aState ) + { + // In special scenarios, we do not have to remove the timer and queue it + // again, but these scenarios rarely happen in end-user use cases. + iTimer->Remove( iShutdownTimerEntry ); + if ( iSessionCount == 0 && aState == EBTPowerOff ) + { + // BT power is off, start the shutdown timer. + TTimeIntervalMicroSeconds32 interval = KBTNtoifShutdownTimeout; + iTimer->Queue( interval, iShutdownTimerEntry ); + } + } + +TInt CBTNotifServer::ShutdownTimeout( TAny* aPtr ) + { + (void) aPtr; + CActiveScheduler::Stop(); + return KErrNone; + } + +// ======== GLOBAL FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// Main function of the executable. +// --------------------------------------------------------------------------- +// +GLDEF_C TInt E32Main() + { + __UHEAP_MARK; + CTrapCleanup* cleanup = CTrapCleanup::New(); + TInt err = KErrNoMemory; + if ( cleanup ) + { + TRAP( err, RunServerL() ); + delete cleanup; + } + __UHEAP_MARKEND; + return err; + } + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/src/btnotifsession.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifsession.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,304 @@ +/* +* ============================================================================ +* Name : btnotifsession.cpp +* Part of : bluetoothengine / btnotif +* Description : Session class for handling commands from clients. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "btnotifsession.h" +#include +#include "btnotifclientserver.h" +#include "btnotifsettingstracker.h" +#include "btnotifconnectiontracker.h" +#include "btnotifdeviceselector.h" + + +// ======== LOCAL FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// Start the server. +// --------------------------------------------------------------------------- +// +void LeaveIfNullL( const TAny* aPtr, TInt aLeaveCode ) + { + if( aPtr == NULL ) + { + User::Leave( aLeaveCode ); + } + } + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTNotifSession::CBTNotifSession() +: CSession2() + { + } + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotifSession::ConstructL() + { + } + +// --------------------------------------------------------------------------- +// NewL. +// --------------------------------------------------------------------------- +// +CBTNotifSession* CBTNotifSession::NewL() + { + CBTNotifSession* self = new( ELeave ) CBTNotifSession(); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTNotifSession::~CBTNotifSession() + { + for( TInt i = 0; i < iMessageQ.Count(); i++ ) + { + // Complete all outstanding messages with error code + iMessageQ[i].Complete( KErrSessionClosed ); + } + iMessageQ.Close(); // Cleans up all message objects. + Server()->RemoveSession(); + } + +// --------------------------------------------------------------------------- +// From class CSession2. +// Receives a message from a client. +// --------------------------------------------------------------------------- +// +void CBTNotifSession::ServiceL( const RMessage2& aMessage ) + { + TInt opCode = aMessage.Function(); + if ( opCode == EBTNotifCancelNotifier || + opCode == EBTNotifStartSyncNotifier || + opCode == EBTNotifStartAsyncNotifier || + opCode == EBTNotifUpdateNotifier ) + { + TInt uid = aMessage.Int0(); + if( uid == KDeviceSelectionNotifierUid.iUid ) + { + // Note for implementers: + // message queue is not used in this notifier handling (due + // to its drawbacks for exception handlings in various situations). + // implementations using message queue will be migrated step + // by step. + + TRAPD( err, { + CBTNotifDeviceSelector& selector = Server()->DeviceSelectorL(); + selector.DispatchNotifierMessageL( aMessage ); } + ); + if ( err ) + { + aMessage.Complete( err ); + } + // deviceselector takes the ownership of aMessage. + return; + } + } + + // Messages are completed by message handlers, not here. + // Queue the message already so that handlers can find it from the queue. + iMessageQ.AppendL( aMessage ); + // The position is assumed to not change during the execution of this function. + TInt handle = aMessage.Handle(); // Store the handle for de-queueing + TRAPD( err, DispatchMessageL( aMessage ) ); + if( err || ( aMessage.IsNull() && FindMessageFromHandle( handle ) ) ) + { + // If the message has been completed by now (handle is null and the message + // still in the queue), we remove it again from the queue. Otherwise it + // will be completed by the handling handler when it has handled the handling. + for( TInt i = 0; i < iMessageQ.Count(); i++ ) + { + // This may be replaced by RArray::Find with appropriate key + if( iMessageQ[i].Handle() == handle ) + { + iMessageQ.Remove( i ); + } + } + } + if( err && !aMessage.IsNull() ) + { + aMessage.Complete( err ); + } + } + + +// --------------------------------------------------------------------------- +// From class CSession2. +// Completes construction of the session. +// --------------------------------------------------------------------------- +// +void CBTNotifSession::CreateL() + { + Server()->AddSession(); + } + +// --------------------------------------------------------------------------- +// Complete a client message from a message handle with given data. +// If a zero-length descriptor is passed, no data will be written back. +// --------------------------------------------------------------------------- +// +TInt CBTNotifSession::CompleteMessage( TInt aHandle, TInt aReason, const TDesC8& aReply ) + { + TInt err = KErrNotFound; + // This may be replaced by RArray::Find with appropriate key + for( TInt i = 0; i < iMessageQ.Count(); i++ ) + { + if( iMessageQ[i].Handle() == aHandle ) + { + err = KErrNone; + if( aReply.Length() ) + { + // For now, assume a fixed index for the result. + // Change this if a the client can pass more arguments! + // ToDo: replace with constant! + err = iMessageQ[i].Write( EBTNotifSrvReplySlot, aReply ); + // Should the result be passed back to the calller, + // or used to complete the message? + } + iMessageQ[i].Complete( aReason ); + iMessageQ.Remove( i ); + break; + } + } + return err; + } + + +// --------------------------------------------------------------------------- +// Find a client message from an RMessage2 handle. +// --------------------------------------------------------------------------- +// +const RMessage2* CBTNotifSession::FindMessageFromHandle( TInt aHandle ) const + { + // This may be replaced by RArray::Find with appropriate key + for( TInt i = 0; i < iMessageQ.Count(); i++ ) + { + if( iMessageQ[i].Handle() == aHandle ) + { + return &iMessageQ[i]; + } + } + return NULL; + } + + +// --------------------------------------------------------------------------- +// Process a client message. +// The processing here relies on RNotifier backend server for queueing +// notifiers on the same channel. Therefore pairing (SSP and legacy) and +// authorization notifiers arrive in order, not simultaneously, even if +// they use arrive on different session instances. +// --------------------------------------------------------------------------- +// +void CBTNotifSession::DispatchMessageL( const RMessage2& aMessage ) + { + BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aMessage.Function() ); + CBTNotifSettingsTracker* settTracker = Server()->SettingsTracker(); + CBTNotifConnectionTracker* connTracker = Server()->ConnectionTracker(); + LeaveIfNullL( settTracker, KErrNotReady ); + TInt opcode = aMessage.Function(); + if( opcode < EBTNotifMinValue ) + { + User::Leave( KErrArgument ); + } + switch( opcode ) + { + case EBTNotifCancelNotifier: + case EBTNotifStartSyncNotifier: + case EBTNotifStartAsyncNotifier: + case EBTNotifUpdateNotifier: + { + // All these messages get the same treatment: forward + // to settings and connection tracker, who will deal with it appropriately. + // First the settings tracker handles the message. + settTracker->DispatchNotifierMessageL( aMessage ); + if( connTracker && !aMessage.IsNull() ) + { + // Pass it on to the connection tracker, if it hasn't been completed yet. + connTracker->DispatchNotifierMessageL( aMessage ); + } + else + { + // Power is off, can't do this now. + LeaveIfNullL( connTracker, KErrNotReady ); + } + if( opcode != EBTNotifStartAsyncNotifier && !aMessage.IsNull() ) + { + // Nobody has yet completed the message, and it is a synchronous + // one so we'll do it here to allow the notifier to keep on going. + aMessage.Complete( KErrNone ); + } + } + break; + case EBTEngPrepareDiscovery: + { + // This is functionality only related to existing connections. + // Can't do when power is off though. + LeaveIfNullL( connTracker, KErrNotReady ); + //connTracker->HandlePairingRequestL( aMessage ); + } + break; + case EBTEngPairDevice: + case EBTEngCancelPairDevice: + { + // This is functionality only related to connections. + // Can't do when power is off though. + LeaveIfNullL( connTracker, KErrNotReady ); + connTracker->HandleBondingRequestL( aMessage ); + } + break; + default: + // Communicate result back. + User::Leave( KErrNotSupported ); + break; + } + BOstraceFunctionExit1( DUMMY_DEVLIST, this ); + } + + +// --------------------------------------------------------------------------- +// Find a client message from an RNotifier UID. +// --------------------------------------------------------------------------- +// +const RMessage2* CBTNotifSession::FindMessageFromUid( TInt aUid ) const + { + // This may be replaced by RArray::Find with appropriate key + for( TInt i = 0; i < iMessageQ.Count(); i++ ) + { + if( iMessageQ[i].Int0() == aUid ) + { + return &iMessageQ[i]; + } + } + return NULL; + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifsrv/src/btnotifsettingstracker.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifsrv/src/btnotifsettingstracker.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,166 @@ +/* +* ============================================================================ +* Name : btnotifsettingstracker.cpp +* Part of : BTProximity / BTProximity +* Description : Class for tracking Bluetooth settings, and also for handling notes unrelated to specific connection. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "btnotifsettingstracker.h" +#include + +#include "btnotifserver.h" +#include "btnotificationmanager.h" +#include "btnotifclientserver.h" + + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBTNotifSettingsTracker::CBTNotifSettingsTracker( CBTNotifServer* aServer ) +: iServer( aServer ) + { + } + + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBTNotifSettingsTracker::ConstructL() + { + iSettings = CBTEngSettings::NewL( this ); + User::LeaveIfError( iSettings->GetPowerState( iPowerState ) ); + } + + +// --------------------------------------------------------------------------- +// NewL. +// --------------------------------------------------------------------------- +// +CBTNotifSettingsTracker* CBTNotifSettingsTracker::NewL( CBTNotifServer* aServer ) + { + CBTNotifSettingsTracker* self = new( ELeave ) CBTNotifSettingsTracker( aServer ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBTNotifSettingsTracker::~CBTNotifSettingsTracker() + { + if( iNotification ) + { + // Clear the notification callback, we cannot receive them anymore. + iNotification->RemoveObserver(); + iNotification->Close(); // Also dequeues the notification from the queue. + iNotification = NULL; + } + delete iSettings; + } + + +// --------------------------------------------------------------------------- +// Process a client message related to notifiers. +// --------------------------------------------------------------------------- +// +void CBTNotifSettingsTracker::DispatchNotifierMessageL( const RMessage2& aMessage ) + { + TUid uid = TUid::Uid( aMessage.Int0() ); + (void) uid; + } + + +// --------------------------------------------------------------------------- +// Cancels an outstanding client message related to notifiers. +// --------------------------------------------------------------------------- +// +void CBTNotifSettingsTracker::CancelNotifierMessageL( const RMessage2& aMessage ) + { + (void) aMessage; + } + + +// --------------------------------------------------------------------------- +// From class MBTEngSettingsObserver. +// Handle a power status change. +// --------------------------------------------------------------------------- +// +void CBTNotifSettingsTracker::PowerStateChanged( TBTPowerStateValue aState ) + { + iPowerState = aState; + TRAP_IGNORE( iServer->HandlePowerStateChangeL( aState ) ); + } + + +// --------------------------------------------------------------------------- +// From class MBTEngSettingsObserver. +// Handle a visibility mode change. +// --------------------------------------------------------------------------- +// +void CBTNotifSettingsTracker::VisibilityModeChanged( TBTVisibilityMode aState ) + { + if( iVisibilityMode == EBTVisibilityModeTemporary && + aState == EBTVisibilityModeHidden && iPowerState == EBTPowerOn ) + { + // Timeout expired, launch a note. + // Note that we get the power state change before this one, when powering + // off and setting visibility mode to hidden automatically. + NOTIF_NOTHANDLED( !iNotification ) + iNotification = iServer->NotificationManager()->GetNotification(); + if ( iNotification ) + { + iNotification->SetObserver( this ); + iNotification->SetNotificationType( TBluetoothDeviceDialog::ENote, EVisibilityTimeout ); + iServer->NotificationManager()->QueueNotification( iNotification ); + } + } + iVisibilityMode = aState; + } + + +// --------------------------------------------------------------------------- +// From class MBTNotificationResult. +// Handle a result from a user query. +// --------------------------------------------------------------------------- +// +void CBTNotifSettingsTracker::MBRDataReceived( CHbSymbianVariantMap& aData ) + { + (void) aData; + } + + +// --------------------------------------------------------------------------- +// From class MBTNotificationResult. +// The notification is finished. +// --------------------------------------------------------------------------- +// +void CBTNotifSettingsTracker::MBRNotificationClosed( TInt aError, const TDesC8& aData ) + { + (void) aError; + (void) aData; + iNotification->RemoveObserver(); + iNotification = NULL; + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifwrapper/data/101fd68f.rss --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifwrapper/data/101fd68f.rss Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,53 @@ +/* +* ============================================================================ +* Name : 101fd68f.rss +* Part of : bluetoothengine / btnotifwrapper +* Description : Resource definitions for project btnotifwrapper +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include +#include + +// --------------------------------------------------------------------------- +// ecomInfo +// ECOM registration info +// --------------------------------------------------------------------------- +// +RESOURCE REGISTRY_INFO ecomInfo + { + resource_format_version = RESOURCE_FORMAT_VERSION_2; + dll_uid = 0x101FD68F; + interfaces = + { + INTERFACE_INFO + { + interface_uid = KUikonUidPluginInterfaceNotifiers; + implementations = + { + IMPLEMENTATION_INFO + { + implementation_uid = 0x20026FEE; + version_no = 2; + display_name = "BTNOTIFPLUGINWRAPPER vQT"; + default_data = "BTNOTIFPLUGIN vQT"; + opaque_data = ""; + } + }; + } + }; + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifwrapper/inc/btnotifwrapper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifwrapper/inc/btnotifwrapper.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,267 @@ +/* +* ============================================================================ +* Name : btnotifwrapper.h +* Part of : bluetoothengine / btnotif +* Description : Wrapper for Bluetooth Notifiers +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFWRAPPER_H +#define BTNOTIFWRAPPER_H + + +#include +#include +#include + +class CBTNotifWrapperUnitTester; + +/** + * Function for creating the array of notifiers supported by this plug-in. + * The main purpose for declaring it here is to allow it to be used + * by the test module. + * + * @since Symbian^4 + * @return Array of notifiers. + */ +CArrayPtr* CreateNotifierArrayL(); + +/** + * RNotif plugin implementation providing the client API for BTNotif + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( CBTNotifWrapper ) : public CBase, + public MEikSrvNotifierBase2, + public MBtSimpleActiveObserver + { + +public: + + /** + * Two-phased constructor. + */ + static CBTNotifWrapper* NewLC( const TUid& aUid, const TUid& aChannel ); + + /** + * Destructor. + */ + virtual ~CBTNotifWrapper(); + +private: + +// from base class MEikSrvNotifierBase2 + + /** + * From MEikSrvNotifierBase2. + * Frees all resources owned by this notifier. + * + * @since Symbian^4 + */ + virtual void Release(); + + /** + * From MEikSrvNotifierBase2. + * Performs any initialisation that this notifier may require. + * As a minimum, the function should return a TNotifierInfo instance + * describing the notifier parameters. + * + * @since Symbian^4 + * @return Describes the parameters of the notifier. + */ + virtual TNotifierInfo RegisterL(); + + /** + * From MEikSrvNotifierBase2. + * Gets the notifier parameters. + * + * @since Symbian^4 + * @return Describes the parameters of the notifier. + */ + virtual TNotifierInfo Info() const; + + /** + * From MEikSrvNotifierBase2. + * This is called as a result of a client-side call to + * RNotifier::StartNotifier(), which the client uses to + * start a notifier from which it does not expect a response. + * + * @since Symbian^4 + * @param aBuffer Data that can be passed from the client-side. The format + * and meaning of any data is implementation dependent. + * @return A pointer descriptor representing data that may be returned. + * The format and meaning of any data is implementation dependent. + */ + virtual TPtrC8 StartL(const TDesC8& aBuffer); + + /** + * From MEikSrvNotifierBase2. + * This is called as a result of a client-side call to the asynchronous + * function RNotifier::StartNotifierAndGetResponse(). This means that the + * client is waiting, asynchronously, for the notifier to tell the + * client that it has finished its work. + * + * @since Symbian^4 + * @param aBuffer Data that can be passed from the client-side. The format + * and meaning of any data is implementation dependent. + * @param aReplySlot Identifies which message argument to use for the reply. + * This message argument will refer to a modifiable + * descriptor, a TDes8 type, into which data can be + * returned. The format and meaning of any returned data + * is implementation dependent. + * @param aMessage Encapsulates a client request. + */ + virtual void StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage); + + /** + * From MEikSrvNotifierBase2. + * Cancels an active notifier. + * This is called as a result of a client-side call to RNotifier::CancelNotifier(). + * + * @since Symbian^4 + */ + virtual void Cancel(); + + /** + * From MEikSrvNotifierBase2. + * Updates a currently active notifier with new data. + * This is called as a result of a client-side call + * to RNotifier::UpdateNotifier(). + * + * @since Symbian^4 + * @param aBuffer Data that can be passed from the client-side. The format + * and meaning of any data is implementation dependent. + * @return A pointer descriptor representing data that may be returned. + * The format and meaning of any data is implementation dependent. + */ + virtual TPtrC8 UpdateL(const TDesC8& aBuffer); + + /** + * From MEikSrvNotifierBase2. + * Updates a currently active notifier with new data. + * This is called as a result of a client-side call to the asynchronous + * function RNotifier::UpdateNotifierAndGetResponse(). + * + * @since Symbian^4 + * @param aBuffer Data that can be passed from the client-side. The format + * and meaning of any data is implementation dependent. + * @param aReplySlot Identifies which message argument to use for the reply. + * This message argument will refer to a modifiable + * descriptor, a TDes8 type, into which data can be + * returned. The format and meaning of any returned data + * is implementation dependent. + * @param aMessage Encapsulates a client request. + */ + virtual void UpdateL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage); + +// from base class MBtSimpleActiveObserver + + /** + * Callback to notify that an outstanding request has completed. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aStatus The status of the completed request. + */ + virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); + + /** + * Callback for handling cancelation of an outstanding request. + * + * @since Symbian^4 + * @param aId The ID that identifies the outstanding request. + */ + virtual void CancelRequest( TInt aRequestId ); + + /** + * Callback to notify that an error has occurred in RunL. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aError The error occurred in RunL. + */ + virtual void HandleError( CBtSimpleActive* aActive, TInt aError ); + +private: + + CBTNotifWrapper( const TUid& aUid, const TUid& aChannel ); + + void ConstructL(); + + /** + * Check if this notifier is a synchronous or asunchronous notifier. + * + * @since Symbian^4 + * @return ETrue is the notifier is synchronous, EFalse if asyncrhonous. + */ + TBool IsSync() const; + +private: // data + + /** + * The UID identifying the notifier. + */ + TUid iUid; + + /** + * The channel of the notifier. + */ + TUid iChannel; + + /** + * The replyslot for the result. + */ + TInt iReplySlot; + + /** + * Session with the BT notifier server. + */ + RBTNotifier iBTNotif; + + /** + * The client-side message containing the current request. + */ + RMessagePtr2 iMessage; + + /** + * Buffer containing a copy of the notifier parameters, for async notifiers. + * Own. + */ + HBufC8* iParamsBuf; + + /** + * Modifiable pointer descriptor for getting the response back. + */ + TPtr8 iResponsePtr; + + /** + * Buffer for receiving the response from the BT notifier server. + * Own. + */ + HBufC8* iResponseBuf; + + /** + * Active object helper class. + * Own. + */ + CBtSimpleActive* iActive; + + friend class CBTNotifWrapperUnitTester; + + }; + +#endif // BTNOTIFWRAPPER_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifwrapper/src/btnotifwrapper.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifwrapper/src/btnotifwrapper.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,315 @@ +/* +* ============================================================================ +* Name : btnotifwrapper.cpp +* Part of : bluetoothengine / btnotif +* Description : Wrapper for Bluetooth Notifiers +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "btnotifwrapper.h" +#include +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS +#include +#endif + +/** Identifier of the active object. */ +const TInt KWrapperActive = 10; + +// ======== MEMBER FUNCTIONS ======== + + +// --------------------------------------------------------------------------- +// ?description_if_needed +// --------------------------------------------------------------------------- +// +CBTNotifWrapper::CBTNotifWrapper( const TUid& aUid, const TUid& aChannel ) +: MEikSrvNotifierBase2(), + iUid( aUid ), + iChannel( aChannel ), + iResponsePtr( NULL, 0 ) + { + } + + +// --------------------------------------------------------------------------- +// ?description_if_needed +// --------------------------------------------------------------------------- +// +void CBTNotifWrapper::ConstructL() + { + // lazy initialization: members are created and destroyed when needed. + } + + +// --------------------------------------------------------------------------- +// NewLC +// --------------------------------------------------------------------------- +// +CBTNotifWrapper* CBTNotifWrapper::NewLC( const TUid& aUid, const TUid& aChannel ) + { + CBTNotifWrapper* self = new( ELeave ) CBTNotifWrapper( aUid, aChannel ); + CleanupStack::PushL( self ); + self->ConstructL(); + return self; + } + +// --------------------------------------------------------------------------- +// ?description_if_needed +// --------------------------------------------------------------------------- +// +CBTNotifWrapper::~CBTNotifWrapper() + { + Cancel(); // Cleans up buffers + delete iActive; + iBTNotif.Close(); + } + +// --------------------------------------------------------------------------- +// From class MEikSrvNotifierBase2. +// Frees all the resources i.e. destruct ourselves. +// --------------------------------------------------------------------------- +// +void CBTNotifWrapper::Release() + { + delete this; + } + +// --------------------------------------------------------------------------- +// From class MEikSrvNotifierBase2. +// ?implementation_description +// --------------------------------------------------------------------------- +// +MEikSrvNotifierBase2::TNotifierInfo CBTNotifWrapper::RegisterL() + { + return Info(); + } + + +// --------------------------------------------------------------------------- +// From class MEikSrvNotifierBase2. +// ?implementation_description +// --------------------------------------------------------------------------- +// +MEikSrvNotifierBase2::TNotifierInfo CBTNotifWrapper::Info() const + { + MEikSrvNotifierBase2::TNotifierInfo info; + info.iUid = iUid; + info.iChannel = iChannel; + info.iPriority = MEikSrvNotifierBase2::ENotifierPriorityVHigh; + return info; + } + + +// --------------------------------------------------------------------------- +// From class MEikSrvNotifierBase2. +// ?implementation_description +// --------------------------------------------------------------------------- +// +TPtrC8 CBTNotifWrapper::StartL(const TDesC8& aBuffer) + { + if( !IsSync() ) + { + // due to the charasteristics of Bluetooth and UI operations, + // most of Bluetooth notifiers do not support synchronous version. + User::Leave( KErrNotSupported ); + } + // Call notifier server and get response. + if( !iBTNotif.Handle() ) + { + User::LeaveIfError( iBTNotif.Connect() ); + } + User::LeaveIfError( iBTNotif.StartNotifier( iUid, aBuffer ) ); + iBTNotif.Close(); + return KNullDesC8(); + } + +// --------------------------------------------------------------------------- +// From class MEikSrvNotifierBase2. +// ?implementation_description +// --------------------------------------------------------------------------- +// +void CBTNotifWrapper::StartL(const TDesC8& aBuffer, TInt aReplySlot, + const RMessagePtr2& aMessage) + { + if( !iMessage.IsNull() ) + { + aMessage.Complete( KErrAlreadyExists ); + return; + } + + // Call notifier server and get response. + if( !iBTNotif.Handle() ) + { + User::LeaveIfError( iBTNotif.Connect() ); + } + if( !iActive ) + { + iActive = CBtSimpleActive::NewL( *this, KWrapperActive ); + } + + // We need to store the parameters locally, as aBuffer is destroyed after + // returning from this call. We do it on the heap, so we do not permanently + // consume memory for the buffer. + + iParamsBuf = HBufC8::NewL( aBuffer.Size() ); + *iParamsBuf = aBuffer; + + TInt len = aMessage.GetDesMaxLength( aReplySlot ); + iResponseBuf = HBufC8::NewL( len ); + // Copy in the response, to get the right buffer size. + iResponsePtr.Set( iResponseBuf->Des() ); + aMessage.ReadL( aReplySlot, iResponsePtr ); + + iBTNotif.StartNotifierAndGetResponse( iActive->RequestStatus(), + iUid, *iParamsBuf, iResponsePtr ); + iActive->GoActive(); + // record the request + iReplySlot = aReplySlot; + iMessage = aMessage; + } + +// --------------------------------------------------------------------------- +// From class MEikSrvNotifierBase2. +// ?implementation_description +// --------------------------------------------------------------------------- +// +void CBTNotifWrapper::Cancel() + { + // Call notifier server to cancel. + if( iActive ) + { + iActive->Cancel(); + } + if( !iMessage.IsNull() ) + { + iMessage.Complete( KErrCancel ); + } + iReplySlot = 0; + delete iParamsBuf; + iParamsBuf = NULL; + delete iResponseBuf; + iResponseBuf = NULL; + } + +// --------------------------------------------------------------------------- +// From class MEikSrvNotifierBase2. +// Synchronous notifier update. +// --------------------------------------------------------------------------- +// +TPtrC8 CBTNotifWrapper::UpdateL(const TDesC8& aBuffer) + { + // Call notifier server and get response. + TBuf8<256> response; + if( !iBTNotif.Handle() ) + { + User::LeaveIfError( iBTNotif.Connect() ); + } + User::LeaveIfError( iBTNotif.UpdateNotifier( iUid, aBuffer, response ) ); + return response; + } + +// --------------------------------------------------------------------------- +// From class MEikSrvNotifierBase2. +// Asynchronous notifier update. +// --------------------------------------------------------------------------- +// +void CBTNotifWrapper::UpdateL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage) + { + (void) aReplySlot; + (void) aBuffer; + if( iMessage.IsNull() ) + { + // There is no outstanding request, can't relate this to anything. + aMessage.Complete( KErrNotFound ); + return; + } + // Call notifier server and get response. + // Async updates are just for updating parameters, so they are still + // done synchronously between here and btnotif, as they don't + // require any user feedback or other response with + // asynchronous/long cycles. + TPtrC8 response = UpdateL( aBuffer ); + aMessage.WriteL( aReplySlot, response ); + aMessage.Complete( KErrNone ); + } + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// Callback to notify that an outstanding request has completed. +// --------------------------------------------------------------------------- +// +void CBTNotifWrapper::RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ) + { + ASSERT( aActive->RequestId() == KWrapperActive ); + (void) aActive; + if( !iMessage.IsNull() ) + { + TInt err( aStatus ); + if( !aStatus ) + { + // for testing: + //TPckgBuf response; + //response.Copy( *iResponseBuf ); + //response().BDAddr(); + err = iMessage.Write( iReplySlot, *iResponseBuf ); + } + iMessage.Complete( err ); + } + // Clean up after usage. + iBTNotif.Close(); + delete iParamsBuf; + iParamsBuf = NULL; + delete iResponseBuf; + iResponseBuf = NULL; + delete iActive; + iActive = NULL; + } + + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// Cancel and clean up all requests related to the active object. +// --------------------------------------------------------------------------- +// +void CBTNotifWrapper::CancelRequest( TInt aRequestId ) + { + ASSERT( aRequestId == KWrapperActive ); + (void) aRequestId; + iBTNotif.CancelNotifier( iUid ); + } + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// +// --------------------------------------------------------------------------- +// +void CBTNotifWrapper::HandleError( CBtSimpleActive* aActive, + TInt aError ) + { + // RequestCompletedL() is not leavable. + (void) aActive; + (void) aError; + } + +// --------------------------------------------------------------------------- +// Check if this is a synchronous notifier or not. +// --------------------------------------------------------------------------- +// +TBool CBTNotifWrapper::IsSync() const + { + return ( iUid == KBTGenericInfoNotifierUid ); + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/btnotifwrapper/src/btnotifwrapperproxy.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btnotifwrapper/src/btnotifwrapperproxy.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,126 @@ +/* +* ============================================================================ +* Name : btnotifwrapperproxy.cpp +* Part of : bluetoothengine / btnotifwrapper +* Description : ECOM plug-in entry implementation. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + + +#include +#include +#include +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS +#include +#endif +#include +//#include + +#include "btnotifwrapper.h" + +/** Granularity for constructing the array of notifiers */ +const TInt KBTNotifWrapperArraySize = 11; +/** Channel for discovery notifiers */ +const TUid KBTDiscoveryChannel = { 0x00000601 }; +/** Channel for authentication and authorisation notifiers */ +const TUid KBTAuthChannel = {0x00000602}; +/** Channel for OBEX passkey notifiers */ +//const TUid KBTObexAuthChannel = {0x00000603}; +/** Channel for power mode query */ +//const TUid KBTPowerModeChannel = {0x00000605}; +/** Channel for query notifiers */ +//const TUid KBTQueryChannel = {0x00000606}; +/** Channel for power mode query */ +//const TUid KBTInfoChannel = {0x00000610}; + + +// ======== LOCAL FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// ?description +// --------------------------------------------------------------------------- +// +void CreateAndAppendNotifierLC( CArrayPtr& aArray, + const TUid& aUid, const TUid& aChannel ) + { + CBTNotifWrapper* notifier = CBTNotifWrapper::NewLC( aUid, aChannel ); + aArray.AppendL( notifier ); + } + +// --------------------------------------------------------------------------- +// ?description +// --------------------------------------------------------------------------- +// +CArrayPtr* CreateNotifierArrayL() + { + CArrayPtrFlat* notifiers = + new( ELeave ) CArrayPtrFlat( KBTNotifWrapperArraySize ); + CleanupStack::PushL( notifiers ); + // Create all the notifiers: + // Connection authorization notifier + CreateAndAppendNotifierLC( *notifiers, KBTManAuthNotifierUid, KBTAuthChannel ); + // Old and new PIN notifiers + CreateAndAppendNotifierLC( *notifiers, KBTManPinNotifierUid, KBTAuthChannel ); + CreateAndAppendNotifierLC( *notifiers, KBTPinCodeEntryNotifierUid, KBTAuthChannel ); + // Secure simple pairing notifiers + CreateAndAppendNotifierLC( *notifiers, KBTNumericComparisonNotifierUid, KBTAuthChannel ); + CreateAndAppendNotifierLC( *notifiers, KBTPasskeyDisplayNotifierUid, KBTAuthChannel ); + + CreateAndAppendNotifierLC( *notifiers, KDeviceSelectionNotifierUid, KBTDiscoveryChannel ); + + /* + * Other notifiers to be migrated: + * + * existing stack notifiers: + * CreateAndAppendNotifierL( aArray, KPbapAuthNotifierUid, KBTObexPINChannel ); + * + * S60 SDK API: + * CreateAndAppendNotifierL( aArray, KPowerModeSettingNotifierUid, KBTPowerModeChannel ); + * + * S60-defined platform: + * CreateAndAppendNotifierL( aArray, KBTObexPasskeyQueryNotifierUid, KBTObexPINChannel ); + * CreateAndAppendNotifierL( aArray, KBTGenericInfoNotifierUid, KBTInfoChannel ); + * CreateAndAppendNotifierL( aArray, KBTGenericQueryNotifierUid, KBTQueryChannel ); + * + * new (PAN-related): + * CreateAndAppendNotifierL( aArray, KBTPanDeviceSelectionNotifierUid, KBTDiscoveryChannel ); + * CreateAndAppendNotifierL( aArray, KBTPanNapUplinkAuthorisationNotifierUid, KBTAuthChannel ); + */ + CleanupStack::Pop( notifiers->Count() + 1, notifiers ); // Each notifier + notifier array itself + return notifiers; + } + +// --------------------------------------------------------------------------- +// ECOM entry point. +// --------------------------------------------------------------------------- +// +const TImplementationProxy ImplementationTable[] = + { + IMPLEMENTATION_PROXY_ENTRY( 0x20026FEE, CreateNotifierArrayL ) + }; + +// ======== GLOBAL FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// ECOM factory method. +// --------------------------------------------------------------------------- +// +EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount ) + { + aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy ); + return ImplementationTable; + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/group/btnotifsrv.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/group/btnotifsrv.mmp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,64 @@ +/* +* ============================================================================ +* Name : btnotifsrv.mmp +* Part of : bluetoothengine / btnotif +* Description : Project definition file for project btnotif +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include +#include + +TARGET btnotifsrv.exe +TARGETTYPE exe +UID 0x1000008d 0x20026FED + +CAPABILITY CAP_SERVER NetworkControl PowerMgmt CommDD +VENDORID VID_DEFAULT + +SOURCEPATH ../btnotifsrv/src +SOURCE btnotifserver.cpp +SOURCE btnotifsession.cpp +SOURCE btnotifconnectiontracker.cpp +SOURCE btnotifconnection.cpp +SOURCE btnotifpairinghelper.cpp +SOURCE btnotifsettingstracker.cpp +SOURCE btnotificationmanager.cpp +SOURCE bluetoothnotification.cpp +SOURCE btnotifdeviceselector.cpp + +USERINCLUDE ../btnotifsrv/inc ../inc + +MW_LAYER_SYSTEMINCLUDE + +SYSTEMINCLUDE ../../inc +SYSTEMINCLUDE ../../../inc + +LIBRARY euser.lib +LIBRARY esock.lib +LIBRARY bluetooth.lib +LIBRARY btdevice.lib +LIBRARY btmanclient.lib +LIBRARY btextnotifiers.lib +LIBRARY btengsettings.lib +LIBRARY btengconnman.lib +LIBRARY btengdevman.lib +LIBRARY btserviceutil.lib +LIBRARY HbCore.lib +LIBRARY commonengine.lib +LIBRARY flogger.lib +LIBRARY charconv.lib diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/group/btnotifwrapper.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/group/btnotifwrapper.mmp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,52 @@ +/* +* ============================================================================ +* Name : btnotifwrapper.mmp +* Part of : bluetoothengine / btnotifwrapper +* Description : Project definition file for project btnotifwrapper +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include +#include + +TARGET btnotifwrapper.dll +TARGETTYPE PLUGIN +UID 0x10009D8D 0x101FD68F + +CAPABILITY CAP_ECOM_PLUGIN +VENDORID VID_DEFAULT + +START RESOURCE ../btnotifwrapper/data/101fd68f.rss +HEADER +TARGET btnotifwrapper.rsc +END // RESOURCE + +SOURCEPATH ../btnotifwrapper/src +SOURCE btnotifwrapper.cpp +SOURCE btnotifwrapperproxy.cpp + +USERINCLUDE ../btnotifwrapper/inc ../inc + +MW_LAYER_SYSTEMINCLUDE +SYSTEMINCLUDE ../../inc + +LIBRARY euser.lib +LIBRARY ecom.lib +LIBRARY eiksrv.lib +LIBRARY btnotifclient.lib +LIBRARY btserviceutil.lib + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/inc/bluetoothdevicedialogs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/inc/bluetoothdevicedialogs.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,177 @@ +/* +* ============================================================================ +* Name : bluetoothdevicedialogs.h +* Part of : bluetoothengine / btnotif +* Description : Data structures for passing dialog type and formatting between btnotif and the UI component showing the actual dialogs. Also defines identifiers for Bluetooth device dialogs. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BLUETOOTHDEVICEDIALOGS_H +#define BLUETOOTHDEVICEDIALOGS_H + +#include + +/** Enumeration for the type of notification to be launched. */ +enum TBTDialogResourceId + { + ENoResource, + EAuthorization, + EIncomingPairing, + EPinInput, + ENumericComparison, + EPasskeyDisplay, + EObexPasskeyInput, + ESetTrusted, + EBlockUnpairedDevice, + EBlockPairedDevice, + EPairingSuccess, + EPairingFailure, + EVisibilityTimeout, + EUnusedResource // The last ID + }; + + +/** + * TBluetoothDialogParams contains device dialog parameters except for device name and type + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( TBluetoothDialogParams ) + { + +public: + + /** Enumeration for the type of notification to be launched. */ + enum TBTDialogType + { + EInvalidDialog, + ENote, + EQuery, + EInput, + EDeviceSearch, + EGlobalNotif + }; + + /** Enumeration for the notification parameters data type to be configured. */ + enum TDialogDataType + { + ENoParams, + EDialogType, + EResource, + EAddress, + EDialogTitle, + EDialogExt // Id for first data type of derived class. + }; + + inline TBluetoothDialogParams(); + +public: // data + + /** + * Identifier for the type of notification. + */ + TInt iDialogType; + + /** + * Identifier for the resource to be shown in the dialog. + */ + TInt iResourceId; + + /** + * Address of the remote device (not used, for future extension). + */ + TBTDevAddr iAddr; + + /** + * Unused padding (not used, for future extension). + */ + TUint32 iPadding; + + }; + + +/** + * TBluetoothDeviceDialog contains more device dialog parameters + * + * @since Symbian^4 + */ +NONSHARABLE_CLASS( TBluetoothDeviceDialog ) : public TBluetoothDialogParams + { + +public: + + /** Enumeration for the notification parameters data type to be configured. */ + enum TDialogDataType + { + ENoParams = TBluetoothDialogParams::EDialogExt, + EDeviceName, + EDeviceClass, + EAdditionalInt, + EAdditionalDesc + }; + + inline TBluetoothDeviceDialog(); + +public: // data + + /** + * The name of the remote device. + */ + TBTDeviceName iDeviceName; + + /** + * The class of device of the remote device. + */ + TInt iDeviceClass; + + /** + * Additional data depending on the resource. + */ + TInt iIntParam; + + /** + * Additional data depending on the resource. + */ + TBuf<10> iDescParam; + + }; + + +/** Typedef'ed pckgbuf to send dialog parameters to the notification framework. */ +typedef TPckgBuf TBluetoothDialogParamsPckg; + +/** Typedef'ed pckgbuf to send dialog parameters to the notification framework. */ +typedef TPckgBuf TBluetoothDeviceDialogPckg; + + +inline TBluetoothDialogParams::TBluetoothDialogParams() +: iDialogType( EInvalidDialog ), + iResourceId( ENoResource ), + iAddr( TBTDevAddr() ), + iPadding( 0 ) + { + } + +inline TBluetoothDeviceDialog::TBluetoothDeviceDialog() +: iDeviceName( 0 ), + iDeviceClass( 0 ), + iIntParam( 0 ) + { + } + + +#endif // BLUETOOTHDEVICEDIALOGS_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/inc/bluetoothtrace.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/inc/bluetoothtrace.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,455 @@ +/* +* ============================================================================ +* Name : bluetoothtrace.h +* Part of : BluetoothUI / bluetoothuimodel *** Info from the SWAD +* Description : API declaration of run-time debug tracing +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BLUETOOTHTRACE_H +#define BLUETOOTHTRACE_H + +#include +#include "traceconfig.h" + +/* + * Common tracing utility definition to be used by Bluetooth projects. + * The configuration is loaded from traceconfig.h which shall be private for + * each individual project. + * + * In this utility, a set of OST-alike tracing macros are defined. + * (The purpose is to ease migration to OST in future.) + * + * Individual project can also define new macros based on this utility in + * its own space. + * + */ + +#ifdef BLUETOOTHTRACE_ENABLED + +#ifdef BLUETOOTHTRACE_MEDIA_OST + +/** + * Convert own macros to OST macros when OST tracing is used. + * In OST tracing, aTraceName must be a unique identifier in scope of a module. + * Thus many OST compiling errors may occur if the same TraceName is used in multiple + * tracing lines where tracing is miigrated from non-OST to OST. + * The fix is to renaming the TraceName:s to be unique. + */ +#include + +#define BOstrace0( aGroupName, aTraceName, aTraceText ) \ + OstTrace0( aGroupName, aTraceName, aTraceText ) + +#define BOstrace1( aGroupName, aTraceName, aTraceText, aParam ) \ + OstTrace1( aGroupName, aTraceName, aTraceText, aParam ) + +#define BOstraceData( aGroupName, aTraceName, aTraceText, aPtr, aLength ) \ + OstTraceData( aGroupName, aTraceName, aTraceText, aPtr, aLength ) + +#define BOstraceExt1( aGroupName, aTraceName, aTraceText, aParam ) \ + OstTraceExt1( aGroupName, aTraceName, aTraceText, aParam ) + +#define BOstraceExt2( aGroupName, aTraceName, aTraceText, aParam1, aParam2 ) \ + OstTraceExt2( aGroupName, aTraceName, aTraceText, aParam1, aParam2 ) + +#define BOstraceExt3( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3 ) \ + OstTraceExt3( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3 ) + +#define BOstraceExt4( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4 ) \ + OstTraceExt4( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4 ) + +#define BOstraceExt5( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4, aParam5 ) \ + OstTraceExt5( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4, aParam5 ) + +#define BOstraceFunctionEntry0( aTraceName ) \ + OstTraceFunctionEntry0( aTraceName ) + +#define BOstraceFunctionEntry1( aTraceName, aInstance ) \ + OstTraceFunctionEntry1( aTraceName, aInstance ) + +#define BOstraceFunctionEntryExt(aTraceName, aInstance, aArg) \ + OstTraceFunctionEntryExt(aTraceName, aInstance, aArg) + +#define BOstraceFunctionExit0( aTraceName ) \ + OstTraceFunctionExit0( aTraceName ) + +#define BOstraceFunctionExit1( aTraceName, aInstance ) \ + OstTraceFunctionExit1( aTraceName, aInstance ) + +#define BOstraceFunctionExitExt(aTraceName, aInstance, aRetval) \ + OstTraceFunctionExitExt(aTraceName, aInstance, aRetval) + +#define BOstraceEventStart0( aTraceName, aEventName ) \ + OstTraceEventStart0( aTraceName, aEventName ) + +#define BOstraceEventStart1( aTraceName, aEventName, aParam ) \ + OstTraceEventStart1( aTraceName, aEventName, aParam ) + +#define BOstraceEventStop( aTraceName, aEventName ) \ + OstTraceEventStop( aTraceName, aEventName ) + +#define BOstraceState0( aTraceName, aStateName, aNewState ) \ + OstTraceState0( aTraceName, aStateName, aNewState ) + +#define BOstraceState1( aTraceName, aStateName, aNewState, aInstance ) \ + OstTraceState1( aTraceName, aStateName, aNewState, aInstance ) + +#else // BLUETOOTHTRACE_MEDIA_OST + +#ifdef BLUETOOTHTRACE_MEDIA_FILE +#include +#else +#include +#endif + +/** + * When tracing compilation with OST is disabled, the TraceName in each OST trace line + * is ignored, that is, the Trace Names are not checked at compiling time, neither + * are they written into the specified trace output media. + */ + +/** + * Handlers below are used for tolerating overflow of formatting strings. + * to trucate rather than panic the caller. + */ +NONSHARABLE_CLASS( TBtTraceOflowTruncate8 ) : public TDes8Overflow + { +public: + void Overflow( TDes8& /*aDes*/ ) {} + }; + +NONSHARABLE_CLASS( TBtTraceOflowTruncate16 ) : public TDes16Overflow + { +public: + void Overflow( TDes16& /*aDes*/ ) {} + }; + +/** + * internal tracing implementation, do not use it out of this file. + */ +inline void Trace(const TDesC &trGrp, const TDesC &trTxt) +{ + _LIT(Format, "%S%S%S"); + TBuf16<0x180> str; + TPtrC cp(KComponentName); + str.Format(Format, &cp, &trGrp, &trTxt); +#ifdef BLUETOOTHTRACE_MEDIA_FILE + RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, str); +#else + RDebug::Print( str ); +#endif +} + +/* + * trace with no parameters + */ +#define BOstrace0( aGroupName, aTraceName, aTraceText ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + Trace( TrGrp, TrTxt ); \ +} + +/* + * trace with one 32-bit parameter + */ +#define BOstrace1( aGroupName, aTraceName, aTraceText, aParam ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + TBuf<512> buf; TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(TrTxt, &overflow, aParam); \ + Trace( TrGrp, buf ); \ +} + +/* + * trace with more than 32 bits of data. Not supported + */ +#define BOstraceData( aGroupName, aTraceName, aTraceText, aPtr, aLength ) + +/* + * trace with one parameter that is not 32-bit integer + */ +#define BOstraceExt1( aGroupName, aTraceName, aTraceText, aParam ) \ + BOstrace1( aGroupName, aTraceName, aTraceText, aParam ) + +/* + * trace with two parameters. + */ +#define BOstraceExt2( aGroupName, aTraceName, aTraceText, aParam1, aParam2 ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + TBuf<512> buf; TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(TrTxt, &overflow, aParam1, aParam2); \ + Trace( TrGrp, buf ); \ +} + +/* + * trace with three parameters. + */ +#define BOstraceExt3( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3 ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + TBuf<512> buf; TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(TrTxt, &overflow, aParam1, aParam2, aParam3); \ + Trace( TrGrp, buf ); \ +} + +/* + * trace with four parameters + */ +#define BOstraceExt4( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4 ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + TBuf<512> buf; TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(TrTxt, &overflow, aParam1, aParam2, aParam3, aParam4); \ + Trace( TrGrp, buf ); \ +} + +/* + * trace with five parameters + */ +#define BOstraceExt5( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4, aParam5 ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + TBuf<512> buf; TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(TrTxt, &overflow, aParam1, aParam2, aParam3, aParam4, aParam5); \ + Trace( TrGrp, buf ); \ +} + +/* + * Function entry trace without extra parameters. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionEntry0( aTraceName ) \ +{\ + _LIT(TrGrp, "[ API ]"); \ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, ">> "); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry );\ + Trace( TrGrp, buf ); \ +} + +/* + * Function entry trace with a parameter representing the instance identifier, e.g. + * "this" pointer. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionEntry1( aTraceName, aInstance ) \ +{\ + _LIT(TrGrp, "[ API ]");\ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, ">> "); _LIT(Fmt, " 0x%X(%d)"); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry); \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Fmt, &overflow, aInstance, aInstance); \ + Trace( TrGrp, buf ); \ +} + +/* + * Function entry trace, which traces function parameters. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionEntryExt(aTraceName, aInstance, aArg) \ +{ \ + _LIT(TrGrp, "[ API ]");\ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, ">> "); _LIT(Fmt, " 0x%X(%d) arg %d"); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry); \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Fmt, &overflow, aInstance, aInstance, aArg); \ + Trace( TrGrp, buf ); \ +} +/* + * Function exit trace without extra parameters. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionExit0( aTraceName ) \ +{\ + _LIT(TrGrp, "[ API ]"); \ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, "<< "); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry); \ + Trace( TrGrp, buf ); \ +} + +/* + * Function exit trace with a parameter representing the instance identifier + * for example "this" pointer. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionExit1( aTraceName, aInstance ) \ +{\ + _LIT(TrGrp, "[ API ]"); \ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, "<< "); _LIT(Fmt, " 0x%X(%d)"); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry); \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Fmt, &overflow, aInstance, aInstance); \ + Trace( TrGrp, buf ); \ +} + +/* + * Function exit trace with parameters representing the instance identifier, + * for example "this" pointer, and return value. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionExitExt(aTraceName, aInstance, aRetval) \ +{\ + _LIT(TrGrp, "[ API ]");\ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, "<< "); _LIT(Fmt, " 0x%X(%d) ret %d"); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry); \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Fmt, &overflow, aInstance, aInstance, aRetval); \ + Trace( TrGrp, buf ); \ +} + +/* + * Performance measurement event start trace without extra parameters. + * The trace is mapped to TRACE_PERFORMANCE group. + */ +#define BOstraceEventStart0( aTraceName, aEventName ) \ +{\ + _LIT(TrGrp, "[PFMAN]"); _LIT(EvName, aEventName); \ + _LIT(Entry, "[Start] "); \ + TBuf<512> buf(Entry); buf.Append( EvName ); \ + Trace( TrGrp, buf ); \ +} + +/* + * Performance measurement event start trace with single 32-bit parameter. + * The trace is mapped to TRACE_PERFORMANCE group. + */ +#define BOstraceEventStart1( aTraceName, aEventName, aParam ) \ +{\ + _LIT(TrGrp, "[PFMAN]"); _LIT(EvName, aEventName); \ + _LIT(Entry, "[Start] %S 0x%X(%d)"); \ + TPtrC evt(EvName); TBuf<512> buf; \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Entry, &overflow, &evt, aParam, aParam ); \ + Trace( TrGrp, buf ); \ +} + +/* + * Performance measurement event end trace. + * The trace is mapped to TRACE_PERFORMANCE group. + */ +#define BOstraceEventStop( aTraceName, aEventName ) \ +{\ + _LIT(TrGrp, "[PFMAN]"); _LIT(EvName, aEventName); \ + _LIT(Entry, "[Stop] "); \ + TBuf<512> buf(Entry); buf.Append( EvName ); \ + Trace( TrGrp, buf ); \ +} + +/* + * State transition event. + * The trace is mapped to TRACE_STATE group. + */ +#define BOstraceState0( aTraceName, aStateName, aNewState ) \ +{\ + _LIT(TrGrp, "[STATE]"); _LIT(StName, aStateName); \ + _LIT(Entry, "%S 0x%X(%d)"); \ + TPtrC evt(StName); TBuf<512> buf; \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Entry, &overflow, &evt, aNewState, aNewState ); \ + Trace( TrGrp, buf ); \ +} + +/* + * State transition event with instance identifier. + * The trace is mapped to TRACE_STATE group. + */ +#define BOstraceState1( aTraceName, aStateName, aNewState, aInstance ) \ +{\ + _LIT(TrGrp, "[STATE]"); _LIT(StName, aStateName); \ + _LIT(Entry, "%S 0x%X(%d) instance=0x%X(%d)"); \ + TPtrC evt(StName); TBuf<512> buf; \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Entry, &overflow, &evt, aNewState, aNewState, aInstance, aInstance ); \ + Trace( TrGrp, buf ); \ +} + +#endif // BLUETOOTHTRACE_MEDIA_OST + +// Extended tracing macros facilitating domain specific tracing needs: + +/* + * A block of source code merely for tracing purpose. + */ +#define BtTraceBlock( exp ) {exp} + +/* + * trace macro for BT device address printing with an additional trace text. + * aParam must be TBTDevAddr type. + */ +#define BtTraceBtAddr1( aGroupName, aTraceName, aTraceText, aParam ) \ +{ \ + _LIT(TrTxt, aTraceText); TPtrC p(TrTxt); \ + TBuf<12> buf; \ + aParam.GetReadable( buf ); TPtrC p2(buf);\ + BOstraceExt2( aGroupName, aTraceName, "%S%S", &p, &p2 ); \ +} + +/* + * trace macro for BT device address printing with no additional trace text. + * aParam must be TBTDevAddr type. + */ +#define BtTraceBtAddr0( aGroupName, aTraceName, aParam ) \ +{ \ + TBuf<12> buf; aParam.GetReadable( buf ); TPtrC p(buf); \ + BOstraceExt1( aGroupName, aTraceName, "%S", &p ); \ +} + +#else // BLUETOOTHTRACE_ENABLED + +#define BOstrace0( aGroupName, aTraceName, aTraceText ) +#define BOstrace1( aGroupName, aTraceName, aTraceText, aParam ) +#define BOstraceData( aGroupName, aTraceName, aTraceText, aPtr, aLength ) +#define BOstraceExt1( aGroupName, aTraceName, aTraceText, aParam ) +#define BOstraceExt2( aGroupName, aTraceName, aTraceText, aParam1, aParam2 ) +#define BOstraceExt3( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3 ) +#define BOstraceExt4( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4 ) +#define BOstraceExt5( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4, aParam5 ) + +#define BOstraceFunctionEntry0( aTraceName ) +#define BOstraceFunctionEntry1( aTraceName, aInstance ) +#define BOstraceFunctionEntryExt(aTraceName, aInstance, aArg) +#define BOstraceFunctionExit0( aTraceName ) +#define BOstraceFunctionExit1( aTraceName, aInstance ) +#define BOstraceEventStart0( aTraceName, aEventName ) +#define BOstraceEventStart1( aTraceName, aEventName, aParam ) +#define BOstraceFunctionExitExt(aTraceName, aInstance, aRetval) +#define BOstraceEventStop( aTraceName, aEventName ) +#define BOstraceState0( aTraceName, aStateName, aNewState ) +#define BOstraceState1( aTraceName, aStateName, aNewState, aInstance ) + +#define BtTraceBlock( exp ) +#define BtTraceBtAddr1( aGroupName, aTraceName, aTraceText, aParam ) +#define BtTraceBtAddr0( aGroupName, aTraceName, aParam ) + +#endif // BLUETOOTHTRACE_ENABLED + +/* + * Additional general purpose definition, a hook for defining a friend class + * for unit testing to get access to class internals. + */ +#ifndef BTUNITTEST +#define BTUNITTESTHOOK +#endif + +#endif // BLUETOOTHTRACE_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btnotif/inc/btnotifclientserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/inc/btnotifclientserver.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,69 @@ +/* +* ============================================================================ +* Name : btnotifclientserver.h +* Part of : bluetoothengine / btnotif +* Description : Definitions for the btnotif client-server interface. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTNOTIFCLIENTSERVER_H +#define BTNOTIFCLIENTSERVER_H + +/** BTNotif server name */ +_LIT( KBTNotifServerName, "btnotifsrv" ); + +/** btnotifsrv Uid3 for creating the server process */ +const TUid KBTNotifServerUid3 = { 0x20026FED }; + +/** + * BTNotif server version numbers; + * Major version number is 2 to distinguish + * from old btnotif architecture. + */ +const TInt KBTNotifServerVersionMajor = 2; +const TInt KBTNotifServerVersionMinor = 0; +const TInt KBTNotifServerVersionBuild = 0; + +/** + * Opcodes used in the client-server interface + * for identifying the requested command. + */ +enum TBTNotifServerRequest + { + EBTNotifMinValue = 9, + EBTNotifStartSyncNotifier, + EBTNotifStartAsyncNotifier, + EBTNotifCancelNotifier, + EBTNotifUpdateNotifier, + // Commands moved from BTEngine server. + EBTEngPrepareDiscovery = 43, + EBTEngPairDevice, + EBTEngCancelPairDevice, + }; + +/** + * Message slots Opcodes used in the client-server interface + * for identifying the requested command. + */ +enum TBTNotifServerRequestSlot + { + EBTNotifSrvUidSlot, + EBTNotifSrvParamSlot, + EBTNotifSrvReplySlot + }; + +#endif // T_BTNOTIFCLIENTSERVER_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/bwins/btserviceutilu.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/bwins/btserviceutilu.def Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,33 @@ +EXPORTS + ?CopyL@CBtDevExtension@@QAEPAV1@XZ @ 1 NONAME ; class CBtDevExtension * CBtDevExtension::CopyL(void) + ?GoActive@CBtSimpleActive@@QAEXXZ @ 2 NONAME ; void CBtSimpleActive::GoActive(void) + ?IsUserAwareBonded@CBtDevExtension@@QBEHXZ @ 3 NONAME ; int CBtDevExtension::IsUserAwareBonded(void) const + ?IsUserAwareBonded@CBtDevExtension@@SAHABVTBTNamelessDevice@@@Z @ 4 NONAME ; int CBtDevExtension::IsUserAwareBonded(class TBTNamelessDevice const &) + ?NewL@CBtSimpleActive@@SAPAV1@AAVMBtSimpleActiveObserver@@HH@Z @ 5 NONAME ; class CBtSimpleActive * CBtSimpleActive::NewL(class MBtSimpleActiveObserver &, int, int) + ?AllDevices@CBtDevRepository@@QBEABV?$RPointerArray@VCBtDevExtension@@@@XZ @ 6 NONAME ; class RPointerArray const & CBtDevRepository::AllDevices(void) const + ?IsBonded@CBtDevExtension@@SAHABVTBTNamelessDevice@@@Z @ 7 NONAME ; int CBtDevExtension::IsBonded(class TBTNamelessDevice const &) + ?RemoveObserver@CBtDevRepository@@QAEXPAVMBtDevRepositoryObserver@@@Z @ 8 NONAME ; void CBtDevRepository::RemoveObserver(class MBtDevRepositoryObserver *) + ?AddObserverL@CBtDevRepository@@QAEXPAVMBtDevRepositoryObserver@@@Z @ 9 NONAME ; void CBtDevRepository::AddObserverL(class MBtDevRepositoryObserver *) + ?SetRequestId@CBtSimpleActive@@QAEXH@Z @ 10 NONAME ; void CBtSimpleActive::SetRequestId(int) + ?SetDeviceL@CBtDevExtension@@QAEXPAVCBTDevice@@@Z @ 11 NONAME ; void CBtDevExtension::SetDeviceL(class CBTDevice *) + ??1CBtDevRepository@@UAE@XZ @ 12 NONAME ; CBtDevRepository::~CBtDevRepository(void) + ?SetObserver@CAdvanceDevDiscoverer@@QAEXAAVMDevDiscoveryObserver@@@Z @ 13 NONAME ; void CAdvanceDevDiscoverer::SetObserver(class MDevDiscoveryObserver &) + ?RequestStatus@CBtSimpleActive@@QAEAAVTRequestStatus@@XZ @ 14 NONAME ; class TRequestStatus & CBtSimpleActive::RequestStatus(void) + ??1CAdvanceDevDiscoverer@@UAE@XZ @ 15 NONAME ; CAdvanceDevDiscoverer::~CAdvanceDevDiscoverer(void) + ?Alias@CBtDevExtension@@QBEABVTDesC16@@XZ @ 16 NONAME ; class TDesC16 const & CBtDevExtension::Alias(void) const + ?NewL@CAdvanceDevDiscoverer@@SAPAV1@AAVCBtDevRepository@@AAVMDevDiscoveryObserver@@@Z @ 17 NONAME ; class CAdvanceDevDiscoverer * CAdvanceDevDiscoverer::NewL(class CBtDevRepository &, class MDevDiscoveryObserver &) + ?ServiceConnectionStatus@CBtDevExtension@@QBE?AW4TBTEngConnectionStatus@@XZ @ 18 NONAME ; enum TBTEngConnectionStatus CBtDevExtension::ServiceConnectionStatus(void) const + ?NewLC@CBtDevExtension@@SAPAV1@ABVTInquirySockAddr@@ABVTDesC16@@W4TDefaultDevNameOption@@@Z @ 19 NONAME ; class CBtDevExtension * CBtDevExtension::NewLC(class TInquirySockAddr const &, class TDesC16 const &, enum TDefaultDevNameOption) + ??1CBtDevExtension@@UAE@XZ @ 20 NONAME ; CBtDevExtension::~CBtDevExtension(void) + ?DiscoverDeviceL@CAdvanceDevDiscoverer@@QAEXW4TDevDiscoveryFilter@1@W4TBTMajorDeviceClass@@@Z @ 21 NONAME ; void CAdvanceDevDiscoverer::DiscoverDeviceL(enum CAdvanceDevDiscoverer::TDevDiscoveryFilter, enum TBTMajorDeviceClass) + ?NewLC@CBtDevExtension@@SAPAV1@PAVCBTDevice@@W4TDefaultDevNameOption@@@Z @ 22 NONAME ; class CBtDevExtension * CBtDevExtension::NewLC(class CBTDevice *, enum TDefaultDevNameOption) + ?IsJustWorksBonded@CBtDevExtension@@SAHABVTBTNamelessDevice@@@Z @ 23 NONAME ; int CBtDevExtension::IsJustWorksBonded(class TBTNamelessDevice const &) + ?Device@CBtDevExtension@@QBEABVCBTDevice@@XZ @ 24 NONAME ; class CBTDevice const & CBtDevExtension::Device(void) const + ?RequestId@CBtSimpleActive@@QAEHXZ @ 25 NONAME ; int CBtSimpleActive::RequestId(void) + ?IsInitialized@CBtDevRepository@@QBEHXZ @ 26 NONAME ; int CBtDevRepository::IsInitialized(void) const + ?Addr@CBtDevExtension@@QBEABVTBTDevAddr@@XZ @ 27 NONAME ; class TBTDevAddr const & CBtDevExtension::Addr(void) const + ?CancelDiscovery@CAdvanceDevDiscoverer@@QAEXXZ @ 28 NONAME ; void CAdvanceDevDiscoverer::CancelDiscovery(void) + ?NewL@CBtDevRepository@@SAPAV1@XZ @ 29 NONAME ; class CBtDevRepository * CBtDevRepository::NewL(void) + ??1CBtSimpleActive@@UAE@XZ @ 30 NONAME ; CBtSimpleActive::~CBtSimpleActive(void) + ?Device@CBtDevRepository@@QBEPBVCBtDevExtension@@ABVTBTDevAddr@@@Z @ 31 NONAME ; class CBtDevExtension const * CBtDevRepository::Device(class TBTDevAddr const &) const + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/eabi/btserviceutilu.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/eabi/btserviceutilu.def Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,37 @@ +EXPORTS + _ZN15CBtDevExtension10SetDeviceLEP9CBTDevice @ 1 NONAME + _ZN15CBtDevExtension5CopyLEv @ 2 NONAME + _ZN15CBtDevExtension5NewLCEP9CBTDevice21TDefaultDevNameOption @ 3 NONAME + _ZN15CBtDevExtension5NewLCERK16TInquirySockAddrRK7TDesC1621TDefaultDevNameOption @ 4 NONAME + _ZN15CBtDevExtensionD0Ev @ 5 NONAME + _ZN15CBtDevExtensionD1Ev @ 6 NONAME + _ZN15CBtDevExtensionD2Ev @ 7 NONAME + _ZN15CBtSimpleActive12SetRequestIdEi @ 8 NONAME + _ZN15CBtSimpleActive13RequestStatusEv @ 9 NONAME + _ZN15CBtSimpleActive4NewLER23MBtSimpleActiveObserverii @ 10 NONAME + _ZN15CBtSimpleActive8GoActiveEv @ 11 NONAME + _ZN15CBtSimpleActive9RequestIdEv @ 12 NONAME + _ZN15CBtSimpleActiveD0Ev @ 13 NONAME + _ZN15CBtSimpleActiveD1Ev @ 14 NONAME + _ZN15CBtSimpleActiveD2Ev @ 15 NONAME + _ZN16CBtDevRepository12AddObserverLEP24MBtDevRepositoryObserver @ 16 NONAME + _ZN16CBtDevRepository14RemoveObserverEP24MBtDevRepositoryObserver @ 17 NONAME + _ZN16CBtDevRepository4NewLEv @ 18 NONAME + _ZN16CBtDevRepositoryD0Ev @ 19 NONAME + _ZN16CBtDevRepositoryD1Ev @ 20 NONAME + _ZN16CBtDevRepositoryD2Ev @ 21 NONAME + _ZN21CAdvanceDevDiscoverer11SetObserverER21MDevDiscoveryObserver @ 22 NONAME + _ZN21CAdvanceDevDiscoverer15CancelDiscoveryEv @ 23 NONAME + _ZN21CAdvanceDevDiscoverer15DiscoverDeviceLENS_19TDevDiscoveryFilterE19TBTMajorDeviceClass @ 24 NONAME + _ZN21CAdvanceDevDiscoverer4NewLER16CBtDevRepositoryR21MDevDiscoveryObserver @ 25 NONAME + _ZN21CAdvanceDevDiscovererD0Ev @ 26 NONAME + _ZN21CAdvanceDevDiscovererD1Ev @ 27 NONAME + _ZN21CAdvanceDevDiscovererD2Ev @ 28 NONAME + _ZNK15CBtDevExtension17IsUserAwareBondedEv @ 29 NONAME + _ZNK15CBtDevExtension4AddrEv @ 30 NONAME + _ZNK15CBtDevExtension5AliasEv @ 31 NONAME + _ZNK15CBtDevExtension6DeviceEv @ 32 NONAME + _ZNK16CBtDevRepository10AllDevicesEv @ 33 NONAME + _ZNK16CBtDevRepository13IsInitializedEv @ 34 NONAME + _ZNK16CBtDevRepository6DeviceERK10TBTDevAddr @ 35 NONAME + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/export/advancedevdiscoverer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/export/advancedevdiscoverer.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,131 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Declares Bluetooth device inquiry helper class. +* +*/ + +#ifndef ADVANCEBTDEVDISCOVERER_H +#define ADVANCEBTDEVDISCOVERER_H + +#include +#include +#include +#include + +class CAdvanceDevDiscovererImpl; + +/** + * APIs from this class offer functionalities that are common in mw and app + * components of Bluetooth packages. They do not serve as domain APIs. + * + * Using these from external components is risky, due to possible source + * and binary breaks in future. + * + */ + +/** +* The interface of discovering in-range Bluetooth devices via Host Resolver. +* This class offers some options to search certain devices by CoD and other +* filters e.g., bonded and blocked. +* +* It requires the client to supply a CBtDevRepository instance for filtering +* devices. +*/ +NONSHARABLE_CLASS( CAdvanceDevDiscoverer ) : public CBase + { + +public: // Constructor and destructor + + /** + * Options for clients to specify criteria on discovered devices. + */ + enum TDevDiscoveryFilter + { + // do not filter in-range devices + ENoFilter = 0, + + // Excludes an in-range device if its device name is not available + ExcludeIfNoDevName = 0x01, + + // Excludes an in-range device if it is user-aware bonded with phone. + ExcludeUserAwareBonded = 0x02, + + // Excludes an in-range device if it is banned by phone. + ExcludeBanned = 0x04, + }; + + IMPORT_C static CAdvanceDevDiscoverer* NewL( + CBtDevRepository& aDevRep, + MDevDiscoveryObserver& aObserver ); + + /** + * Destructor. + */ + IMPORT_C virtual ~CAdvanceDevDiscoverer(); + + /** + * sets the discovery result receiver. + * + * @param aObserver the new observer to receive inquiry results + */ + IMPORT_C void SetObserver( MDevDiscoveryObserver& aObserver ); + + /** + * Discover currently in-range devices that matches the given major + * device class type. + + * Found devices will be informed by + * MBtDevDiscoveryObserver::HandleNextDiscoveryResult(). + * + * When no more device can be found, + * MBtDevDiscoveryObserver::HandleDiscoveryCompleted() will be issued. + * + * @param aFilter the filter that shall be applied when a device + * is discovered. If this is specified, only a device passing + * the filter will be informed to client. + * By default, no filter is applied. + * + * @param aDeviceClass the major device class which a found device + * must match. + * By default, it includes any device types. + */ + IMPORT_C void DiscoverDeviceL( + TDevDiscoveryFilter aFilter = CAdvanceDevDiscoverer::ENoFilter, + TBTMajorDeviceClass aDeviceClass = EMajorDeviceMisc ); + + /** + * Cancels any outstanding discovery request. + */ + IMPORT_C void CancelDiscovery(); + +private: + + /** + * C++ default constructor. + */ + CAdvanceDevDiscoverer(); + + /** + * The 2nd phase constructor + */ + void ConstructL( CBtDevRepository& aDevRep, MDevDiscoveryObserver& aObserver ); + +private: // Data + + CAdvanceDevDiscovererImpl* iImpl; +}; + +#endif + +// End of File diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/export/btdevextension.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/export/btdevextension.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,225 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: an extended BT device offering properties of +* a Bluetooth device that may be needed by Bluetooth UIs +* +*/ + +#ifndef BTDEVEXTENSION_H +#define BTDEVEXTENSION_H + +#include +#include +#include +#include + +/** + * APIs from this class offer functionalities that are common in mw and app + * components of Bluetooth packages. They do not serve as domain APIs. + * + * Using these from external components is risky, due to possible source + * and binary breaks in future. + * + */ + +/** + * The option for specify the default name for a BT device in + * case the device has neither a device name nor a friendly name. + */ +enum TDefaultDevNameOption + { + ENoDefaultName, + EColonSeperatedBDAddr, // device name will be formated + EPlainBDAddr, + }; + +/** + * Class CBtDevExtension + * + * This class provides the access to the properties of devices from BT registry. + * In addition, it provides other dynamic properties such as the connection + * and proximity statuses. Note that client should not store the dynamic + * properties for future use since they may change frequently. + * + */ +NONSHARABLE_CLASS( CBtDevExtension ) : public CBase + { + +public: + // placeholder for providing more properties of a device + enum TBtDevStatus + { + EUndefinedStatus, + EInRangUnknown = 0x01, + EInRange = 0x02, + EPermanentInRegistry = 0x04, + }; + + /** + * Two-phase constructor + * @param aDev a CBTDevice instance. The ownership is transferred. + * @param aNameOption the option for formating the default device + * name when the given aDev instance has no valid name. + */ + IMPORT_C static CBtDevExtension* NewLC( CBTDevice* aDev, + TDefaultDevNameOption aNameOption = EColonSeperatedBDAddr ); + + /** + * Two-phase constructor + * @param aDev a CBTDevice instance. The ownership is transferred. + * @param aNameOption the option for formating the default device + * name when the given aDev instance has no valid name. + */ + IMPORT_C static CBtDevExtension* NewLC( + const TInquirySockAddr& aAddr, + const TDesC& aName = KNullDesC, + TDefaultDevNameOption aNameOption = EColonSeperatedBDAddr ); + + /** + * Destructor + */ + IMPORT_C virtual ~CBtDevExtension(); + + /** + * Tells if the given device is bonded regardless of whether the pairing was + * performed under user awareness. + * + * @return ETrue if it is bonded. + */ + IMPORT_C static TBool IsBonded( const TBTNamelessDevice &dev ); + + /** + * Tells if the given device is bonded with the Just Works pairing model. + * + * @return ETrue if it is bonded and the pairing was performed with Just Works. + */ + IMPORT_C static TBool IsJustWorksBonded( const TBTNamelessDevice &dev ); + + /** + * Tells if the given device has been bonded under user awareness. + * User awareness refers that the user interacted or was informed during or + * immediately after the pairing completed. + * + * @return ETrue if the user is aware of the bonding. + */ + IMPORT_C static TBool IsUserAwareBonded( const TBTNamelessDevice &dev ); + + /** + * Returns the display name of this device for end users. + * @return the friendly name of the device if it is available; else, the device + * name if it is available; otherwise, the BDADDR seperated with ":". + */ + IMPORT_C const TDesC& Alias() const; + + /** + * Gets the device address. + * @return the device. + */ + IMPORT_C const TBTDevAddr& Addr() const; + + /** + * Gets the CBTDevice instance. + * @return the device. + */ + IMPORT_C const CBTDevice& Device() const; + + /** + * Checks if this device was bonded under user awareness. + * @return ETrue if it is user-aware bonded. + */ + IMPORT_C TBool IsUserAwareBonded() const; + + /** + * + * Returns the service (limited to services managed in bteng scope) + * level connection status of the specified device. + * + * @param aAddr the address of the device + * @return one of TBTEngConnectionStatus enums + */ + IMPORT_C TBTEngConnectionStatus ServiceConnectionStatus() const; + + /** + * Sets a device. The ownership is transferred. + * + * @param aDev the device to be set. + */ + IMPORT_C void SetDeviceL( CBTDevice* aDev ); + + /** + * Make a copy of this evice. + * + * @return a new device instance. + */ + IMPORT_C CBtDevExtension* CopyL(); + +public: + + /** + * Internally invoked in this module, not a DLL level API. + * + * Sets the service connection status of this device. + */ + void SetServiceConnectionStatus( TBTEngConnectionStatus aStatus ); + +private: + + /** + * C++ default constructor + */ + CBtDevExtension( TDefaultDevNameOption aNameOption ); + + /** + * Symbian 2nd-phase constructor + */ + void ConstructL( CBTDevice* aDev ); + + /** + * Update device properties due to setDeviceL or other events. + */ + void UpdateNameL(); + + /** + * Update the service connection status for this device: + */ + //void UpdateServiceStatusL(); + + /** + * formats the BD_Addr as the device name. + */ + void FormatAddressAsNameL(); + +private: + + RBuf iAlias; // contains: + // friendly name, if it is not empty; else + // device name, if it is not empty; else + // the assignment depending on the option chosen by client. + + // The Device instance ( in most case it is given by registry) + CBTDevice* iDev; + + // The bits of dynamic status + TInt iDynamicStatus; + + // Indicates the service connection status of this device + TBTEngConnectionStatus iServiceStatus; + + // The option chosen by the client to deal with default BT name assignment. + TDefaultDevNameOption iNameOption; + }; + +typedef RPointerArray RDevExtensionArray; + +#endif /*BTDEVEXTENSION_H*/ diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/export/btdevrepository.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/export/btdevrepository.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,156 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: The repository of remote devices from BT registry +* +*/ + +#ifndef BTDEVICEREPOSITORY_H +#define BTDEVICEREPOSITORY_H + +#include +#include +#include + +class CBtDevRepositoryImpl; + +/** + * APIs from this class offer functionalities that are common in mw and app + * components of Bluetooth packages. They do not serve as domain APIs. + * + * Using these from external components is risky, due to possible source + * and binary breaks in future. + * + */ + +/** + * Class MBtDevRepositoryObserver + * + * Callback class to notify changes in BT registry. + */ +class MBtDevRepositoryObserver + { +public: + + /** + * Callback to notify that the repository has finished initialization. + * Initialization completion means the repository has retieved all + * Bluetooth devices from BT registry, and it is subscribing to + * registry update events. + * + */ + virtual void RepositoryInitialiazed() = 0; + + /** + * Callback to notify that a device has been deleted from BT registry. + * + * + * @param aAddr the bd_addr of the deleted device + */ + virtual void BtDeviceDeleted( const TBTDevAddr& aAddr ) = 0; + + /** + * Callback to notify that the device has been added to BT registry. + * + * @param aDevice the device that has been added to registry + */ + virtual void BtDeviceAdded( const CBtDevExtension& aDevice ) = 0; + + /** + * Callback to notify that the property of a device in BT registry has been + * changed. + * + * @param aDevice the device that possesses the latest properties. + * @param aSimilarity the similarity of the properties comparing to the ones + * prior to this change. + * Refer CBTDevice::TBTDeviceNameSelector and + * TBTNamelessDevice::TBTDeviceSet for the meanings of the bits + * in this parameter. + */ + virtual void BtDeviceChangedInRegistry( + const CBtDevExtension& aDevice, TUint aSimilarity ) = 0; + }; + +/** + * Class CBtDevRepository + * + * This class provides the full access to remote devices in BT registry, + * and informs client when the properties of remote devices are changed. + * + */ +NONSHARABLE_CLASS( CBtDevRepository ) : public CBase + { +public: + + /** + * Two-phase constructor + */ + IMPORT_C static CBtDevRepository* NewL(); + + /** + * Destructor + */ + IMPORT_C virtual ~CBtDevRepository(); + + /** + * Add an observer to this reposity for receivng repository update + * events. + * @param aObserver the observer to be added. + */ + IMPORT_C void AddObserverL( MBtDevRepositoryObserver* aObserver ); + + /** + * Remove an observer from this repository. + * @param aObserver the observer to be removed. + */ + IMPORT_C void RemoveObserver( MBtDevRepositoryObserver* aObserver ); + + /** + * Tells if this repository has finished the initialization. + * Initialization completion means the repository has retieved all + * Bluetooth devices from BT registry, and it is subscribing to + * registry update events. + */ + IMPORT_C TBool IsInitialized() const; + + /** + * Get all devices in this repository. + * @return the device list + */ + IMPORT_C const RDevExtensionArray& AllDevices() const; + + /** + * Get a specific device by the given address. + * @param aAddr the address of the device to be retrieved + * @return the device pointer, NULL if the device is unavailable. + */ + IMPORT_C const CBtDevExtension* Device( const TBTDevAddr& aAddr ) const; + +private: + + /** + * C++ default constructor + */ + CBtDevRepository(); + + /** + * Symbian 2nd-phase constructor + */ + void ConstructL(); + +private: + + CBtDevRepositoryImpl* iImpl; + }; + +#endif /*BTDEVICEREPOSITORY_H*/ diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/export/btsimpleactive.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/export/btsimpleactive.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,194 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Active object helper class. +* +*/ + +#ifndef BTSIMPLEACTIVE_H +#define BTSIMPLEACTIVE_H + +#include + +class CBtSimpleActive; + +/** + * APIs from this class offer functionalities that are common in mw and app + * components of Bluetooth packages. They do not serve as domain APIs. + * + * Using these from external components is risky, due to possible source + * and binary breaks in future. + * + */ + + +/** + * Class MBtSimpleActiveObserver + * + * Callback class for receiving a completed active object event. + * Users of CBtSimpleActive need to derive from this class. + * + * @lib bteng*.lib + * @since S60 v3.2 + */ +class MBtSimpleActiveObserver + { +public: + + /** + * Callback from RunL() to notify that an outstanding request has completed. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aStatus The status of the completed request. + */ + virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ) = 0; + + /** + * Callback from Docancel() for handling cancelation of an outstanding request. + * + * @since Symbian^4 + * @param aId The ID that identifies the outstanding request. + */ + virtual void CancelRequest( TInt aRequestId ) = 0; + + /** + * Callback from RunError() to notify that an error has occurred in RunL. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aError The error occurred in RunL. + */ + virtual void HandleError( CBtSimpleActive* aActive, TInt aError ) = 0; + }; + +/** + * Class CBtSimpleActive. + * + * This Active Object provides its client a TRequestStatus for performing + * asynchronous requests. It does not know the detail of the asynch operation. + * All of AO callbacks, such as RunL, will be delegated to the client + * for processing, via interface MBtSimpleActiveObserver. + * + */ +NONSHARABLE_CLASS ( CBtSimpleActive ): public CActive + { + +public: + + /** + * Two-phase constructor + * + * @since Symbian^4 + * @param aObserver Pointer to callback interface that receives notification + * that the request has been completed. + * @param aId Identifier for the CBtSimpleActive instance. + * @param aPriority The priority of the active object. + * @return Pointer to the constructed CBtSimpleActive object. + */ + IMPORT_C static CBtSimpleActive* NewL( MBtSimpleActiveObserver& aObserver, TInt aId, + TInt aPriority = CActive::EPriorityStandard ); + + /** + * Destructor + */ + IMPORT_C virtual ~CBtSimpleActive(); + + /** + * Get the request ID of this active object. + * + * @since Symbian^4 + * @return The request ID of this active object. + */ + IMPORT_C TInt RequestId(); + + /** + * Set a new request ID for this active object. + * + * @since Symbian^4 + * @param The new request ID of this active object. + */ + IMPORT_C void SetRequestId( TInt aId ); + + /** + * Activate the active object. + * + * @since Symbian^4 + */ + IMPORT_C void GoActive(); + + /** + * Get a reference to the active object request status. + * + * @since Symbian^4 + * @return Reference to the active object request status. + */ + IMPORT_C TRequestStatus& RequestStatus(); + +private: +// from base class CActive + + /** + * From CActive. + * Called by the active scheduler when the request has been cancelled. + * + * @since S60 v3.2 + */ + void DoCancel(); + + /** + * From CActive. + * Called by the active scheduler when the request has been completed. + * + * @since S60 v3.2 + */ + void RunL(); + + /** + * From CActive. + * Called by the active scheduler when an error in RunL has occurred. + * + * @since S60 v3.2 + */ + TInt RunError( TInt aError ); + +private: + + /** + * C++ default constructor + * + * @since S60 v3.2 + * @param aObserver Pointer to callback interface that receives notification + * that the request has been completed. + * @param aId ID of the request (for the client to keep track of multiple + * active objects). + * @param aPriority Priority of + */ + CBtSimpleActive( MBtSimpleActiveObserver& aObserver, TInt aId, TInt aPriority ); + +private: // data + + /** + * ID of the request (used only by our client). + */ + TInt iRequestId; + + /** + * Our observer. + * Not own. + */ + MBtSimpleActiveObserver& iObserver; + + }; + +#endif // BTSIMPLEACTIVE_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/export/devdiscoveryobserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/export/devdiscoveryobserver.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef DEVDISCOVEREYOBSERVER_H +#define DEVDISCOVEREYOBSERVER_H + +#include +#include + +/** + * Class MDevDiscoveryObserver + * + * Callback class to notify the completion of device discovery. + */ +class MDevDiscoveryObserver + { +public: + + /** + * Callback to notify that a device has been found. + * + * @param aAddr the inquiry address that contains the inquiry information + * of the found device. + * @param aName the Bluetooth device name of the found device + */ + virtual void HandleNextDiscoveryResultL( + const TInquirySockAddr& aAddr, const TDesC& aName ) = 0; + + /** + * Callback to notify that the device search has completed. + * + * @param aErr the error code of device search result. + */ + virtual void HandleDiscoveryCompleted( TInt aErr ) = 0; + }; + +#endif + +// End of File diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/group/bld.inf Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,41 @@ +/* +* ============================================================================ +* Name : bld.inf +* Part of : bluetoothengine / bluetoothengine +* Description : Build information file for bluetoothengine subsystem +* +* Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1.1 +*/ + +PRJ_PLATFORMS +DEFAULT + +PRJ_EXPORTS + +../export/btsimpleactive.h MW_LAYER_PLATFORM_EXPORT_PATH(btservices/btsimpleactive.h) +../export/btdevextension.h MW_LAYER_PLATFORM_EXPORT_PATH(btservices/btdevextension.h) +../export/advancedevdiscoverer.h MW_LAYER_PLATFORM_EXPORT_PATH(btservices/advancedevdiscoverer.h) +../export/devdiscoveryobserver.h MW_LAYER_PLATFORM_EXPORT_PATH(btservices/devdiscoveryobserver.h) +../export/btdevrepository.h MW_LAYER_PLATFORM_EXPORT_PATH(btservices/btdevrepository.h) +../rom/btserviceutil.iby CORE_MW_LAYER_IBY_EXPORT_PATH(btserviceutil.iby) + +PRJ_MMPFILES +btserviceutil.mmp + +PRJ_TESTMMPFILES +../tsrc/btserviceutiltest/group/btserviceutiltest.mmp + +PRJ_TESTEXPORTS diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/group/btserviceutil.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/group/btserviceutil.mmp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Project definition file for project btservice utility +* +*/ + + +#include +#include + +TARGET btserviceutil.dll +TARGETTYPE dll +UID 0x1000008d 0x2002E6E0 + +CAPABILITY CAP_GENERAL_DLL +VENDORID VID_DEFAULT + +SOURCEPATH ../src + +SOURCE btsimpleactive.cpp +SOURCE btdevextension.cpp +SOURCE btdevrepository.cpp +SOURCE btdevrepositoryimpl.cpp + +SOURCE basicdevdiscoverer.cpp +SOURCE advancebtdevdiscoverer.cpp +SOURCE advancedevdiscovererimpl.cpp + +USERINCLUDE ../inc +MW_LAYER_SYSTEMINCLUDE + +LIBRARY euser.lib +LIBRARY btdevice.lib +LIBRARY btmanclient.lib +LIBRARY bluetooth.lib +LIBRARY esock.lib +LIBRARY btengconnman.lib diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/inc/advancedevdiscovererimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/inc/advancedevdiscovererimpl.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,176 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Declares Bluetooth device inquiry helper class. +* +*/ + +#ifndef ADVANCEDEVDISCOVERERIMPL_H +#define ADVANCEDEVDISCOVERERIMPL_H + +#include + +#include +#include + +class CBasicDevDiscoverer; +class CBtDevRepository; +class CBtDevExtension; + +/** +* A helper class for searching nearby Bluetooth devices. +*/ +NONSHARABLE_CLASS(CAdvanceDevDiscovererImpl) : public CBase, + public MDevDiscoveryObserver, + public MBtSimpleActiveObserver + { +public: + /** + * instantiator + */ + static CAdvanceDevDiscovererImpl* NewL( + CBtDevRepository& aDevRep, + MDevDiscoveryObserver& aObserver ); + + /** + * Destructor. + */ + virtual ~CAdvanceDevDiscovererImpl(); + + /** + * sets the inquiry result observer. + * + * @param aObserver the new observer to receive inquiry results + */ + void SetObserver( MDevDiscoveryObserver& aObserver ); + + /** + * Cancels all inquiry activity. + */ + void Cancel(); + + /** + * Discover currently in-range devices that matches the given major device class type. + * Found devices will be informed by + * MBtAdvanceDevDiscoveryObserver::HandleNextDiscoveryResult(). + * + * When no more device can be found, + * MBtAdvanceDevDiscoveryObserver::HandleDiscoveryCompleted() will be issued. + * + * @param aFilter the filter that shall be applied when a device + * is discovered. If this is specified, only a device passing + * the filter will be informed to client. + * + * @param aDeviceClass the major device class which a found device + * must match. + */ + void DiscoverDeviceL( + CAdvanceDevDiscoverer::TDevDiscoveryFilter aFilter, + TBTMajorDeviceClass aDeviceClass ); + + /** + * Discover currently in-range devices that match the given major device class. + * The devices in the given priority list have higher priority to + * be discovered, i.e., inquiry on these devices will take place first. + * + * Found devices will be informed by + * MDevDiscoveryObserver::HandleNextDiscoveryResult(). + * + * When no more device can be found, + * MDevDiscoveryObserver::HandleDiscoveryCompleted() will be issued. + * + * @param aPriorityList contains the devices to be discovered first + */ + void DiscoverDeviceL( + const RBTDevAddrArray& aPriorityList ); + +private: + + // from MDevDiscoveryObserver + + /** + * Callback to notify that a device has been found. + * + * @param aAddr the inquiry address that contains the inquiry information + * of the found device. + * @param aName the Bluetooth device name of the found device + */ + void HandleNextDiscoveryResultL( + const TInquirySockAddr& aAddr, const TDesC& aName ); + + /** + * Callback to notify that the device search has completed. + * + * @param aErr the error code of device search result. + */ + void HandleDiscoveryCompleted( TInt aErr ); + + // from MBtSimpleActiveObserver + + /** + * Callback to notify that an outstanding request has completed. + * + * @param aActive Pointer to the active object that completed. + * @param aStatus The status of the completed request. + */ + void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); + + /** + * Callback for handling cancelation of an outstanding request. + * + * @param aId The ID that identifies the outstanding request. + */ + void CancelRequest( TInt aId ); + + /** + * Callback to notify that an error has occurred in RunL. + * + * @param aActive Pointer to the active object that completed. + * @param aError The error occurred in RunL. + */ + void HandleError( CBtSimpleActive* aActive, TInt aError ); + +private: + + /** + * C++ default constructor. + */ + CAdvanceDevDiscovererImpl( + CBtDevRepository& aDevRep, + MDevDiscoveryObserver& aObserver ); + + /** + * The 2nd phase constructor + */ + void ConstructL(); + +private: // Data + + // for retrieving device properties + // Not own + CBtDevRepository& iDevRep; + + // our client + // Not own + MDevDiscoveryObserver& iObserver; + + // The class doing actual inquirying + CBasicDevDiscoverer* iBasicDiscoverer; + + // filters from CAdvanceDevDiscoverer::TDevDiscoveryFilter + TInt iFilter; + }; + +#endif + +// End of File diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/inc/basicdevdiscoverer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/inc/basicdevdiscoverer.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,160 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Declares Bluetooth device inquiry helper class. +* +*/ + +#ifndef BASICDEVDISCOVERER_H +#define BASICDEVDISCOVERER_H + +#include +#include +#include + +class MDevDiscoveryObserver; + +class CDeviceSearchRecord : public CBase + { +public: + TInquirySockAddr iAddr; + TBTDeviceName iName; + }; + +/** +* A basic implementation for searching nearby Bluetooth devices. +*/ +NONSHARABLE_CLASS(CBasicDevDiscoverer) : public CBase, public MBtSimpleActiveObserver + { +public: + + /** + * factory method + */ + static CBasicDevDiscoverer* NewL( MDevDiscoveryObserver& aObserver ); + + /** + * Destructor. + */ + virtual ~CBasicDevDiscoverer(); + + /** + * sets the inquiry result observer. + * + * @param aObserver the new observer to receive inquiry results + */ + void SetObserver( MDevDiscoveryObserver& aObserver ); + + /** + * Cancels all inquiry activity. + */ + void Cancel(); + + /** + * Discover currently in-range devices that matches the given major device class type. + * Found devices will be informed by + * MDevDiscoveryObserver::HandleNextDiscoveryResult(). + * + * When no device can be found any more, + * MDevDiscoveryObserver::HandleDiscoveryCompleted() will be issued. + * + * @param aDeviceClass the major device class device must match. + */ + void DiscoverDeviceL( TBTMajorDeviceClass aDeviceClass = EMajorDeviceMisc ); + +private: // from MBtSimpleActiveObserver + + /** + * Callback to notify that an outstanding request has completed. + * + * @param aActive Pointer to the active object that completed. + * @param aStatus The status of the completed request. + */ + void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); + + /** + * Callback for handling cancelation of an outstanding request. + * + * @param aId The ID that identifies the outstanding request. + */ + void CancelRequest( TInt aId ); + + /** + * Callback to notify that an error has occurred in RunL. + * + * @param aActive Pointer to the active object that completed. + * @param aError The error occurred in RunL. + */ + void HandleError( CBtSimpleActive* aActive, TInt aError ); + +private: + + /** + * C++ default constructor. + */ + CBasicDevDiscoverer( MDevDiscoveryObserver& aObserver ); + + /** + * The 2nd phase constructor + */ + void ConstructL(); + + /* + * retrieves the device name of the device pointed by + * iPagingNamePos to local array. + */ + void PageNextDeviceName(); + + /** + * Performs the result from an inquiry operation. + */ + TInt HandleInquiryResultL(); + + /** + * Create a heap object of CDeviceSearchRecord. + */ + CDeviceSearchRecord* NewInstanceL( + const TInquirySockAddr& aAddr, const TDesC& aName = KNullDesC ); + + /** + * resets the state and memory caused by a client request. + */ + void Reset(); + +private: // Data + + // Not own + MDevDiscoveryObserver& iObserver; + + // The major device class filter from the client. + TBTMajorDeviceClass iMajorDeviceClassFilter; + + // For inquiry and paging names: + CBtSimpleActive* iActive; + + RSocketServ iSocketServer; + RHostResolver iHostResolver; + TInquirySockAddr iInquirySockAddr; + TNameEntry iEntry; // Inquiry result record + + // Devices found so far + RPointerArray iDevices; + + // position in array iDevices: the item the current name paging operation is for + TInt iPagingNamePos; + + }; + +#endif + +// End of File diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/inc/btdevrepositoryimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/inc/btdevrepositoryimpl.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,263 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: The repository of remote devices from BT registry +* +*/ + +#ifndef BTDEVICEREPOSITORYIMPL_H +#define BTDEVICEREPOSITORYIMPL_H + +#include +#include +#include +#include +#include +#include +#include + +class MBtDevRepositoryObserver; + +/** + * Class CBtDevRepositoryImpl + * + * This class keep a storage of remote device information. + * + */ +NONSHARABLE_CLASS( CBtDevRepositoryImpl ) : + public CBase, + public MBtSimpleActiveObserver, + public MBTEngConnObserver + { +public: + + /** + * Two-phase constructor + */ + static CBtDevRepositoryImpl* NewL(); + + /** + * Destructor + */ + ~CBtDevRepositoryImpl(); + + /** + * Add an observer to this reposity for receivng repository update + * events. + * @param aObserver the observer to be added. + */ + void AddObserverL( MBtDevRepositoryObserver* aObserver ); + + /** + * Remove an observer from this repository. + * @param aObserver the observer to be removed. + */ + void RemoveObserver( MBtDevRepositoryObserver* aObserver ); + + /** + * Tells if this repository has finished the initialization. + * Initialization completion means the repository has retieved all + * Bluetooth devices from BT registry, and it is subscribing to + * registry update events. + */ + TBool IsInitialized() const; + + /** + * Gets all devices in this repository. + * @return the device list. + */ + const RDevExtensionArray& AllDevices() const; + + /** + * Get a specific device by the given address. + * @param aAddr the address of the device to be retrieved + * @return the device pointer, NULL if the device is unavailable. + */ + const CBtDevExtension* Device( const TBTDevAddr& aAddr ) const; + + /** + * Returns the service (limited to services managed in bteng scope) + * level connection status of the specified device. + * + * @param aAddr the address of the device + * @return one of TBTEngConnectionStatus enums + */ + //TBTEngConnectionStatus IsDeviceConnected( const TBTDevAddr& aAddr ); + +private: + + // from MBtSimpleActiveObserver + + /** + * Callback from RunL() to notify that an outstanding request has completed. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aStatus The status of the completed request. + */ + void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); + + /** + * Callback from Docancel() for handling cancelation of an outstanding request. + * + * @since Symbian^4 + * @param aId The ID that identifies the outstanding request. + */ + void CancelRequest( TInt aRequestId ); + + /** + * Callback from RunError() to notify that an error has occurred in RunL. + * + * @since Symbian^4 + * @param aActive Pointer to the active object that completed. + * @param aError The error occurred in RunL. + */ + void HandleError( CBtSimpleActive* aActive, TInt aError ); + + // From MBTEngConnObserver + + /** + * Indicates to the caller that a service-level connection has completed. + * This function is called for both incoming and outgoing connections. + * This function is also called when an outgoing connection request fails, + * e.g. with error code KErrCouldNotConnect. + * When this function is called, new commands can be issued to the + * CBTEngConnMan API immediately. + * @param aAddr The address of the remote device. + * @param aErr Status information of the connection. KErrNone if the + * connection succeeded, otherwise the error code with + * which the outgoing connection failed. KErrAlreadyExists + * is returned if there already is an existing connection + * for the selected profile(s), or otherwise e.g. + * KErrCouldNotConnect or KErrDisconnected for indicating + * connection problems. + * @param aConflicts If there already is a connection for the selected + * profile(s) of an outgoing connection request (the + * selection is performed by BTEng), then this array + * contains the bluetooth device addresses of the + * remote devices for those connections. + */ + void ConnectComplete( TBTDevAddr& aAddr, TInt aErr, + RBTDevAddrArray* aConflicts = NULL ); + + /** + * Indicates to the caller that a service-level connection has disconnected. + * When this function is called, new commands can be issued to the + * CBTEngConnMan API immediately. + * + * @param aAddr The address of the remote device. + * @param aErr The error code with which the disconnection occured. + * KErrNone for a normal disconnection, + * or e.g. KErrDisconnected if the connection was lost. + */ + void DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ); + +private: + + /** + * C++ default constructor + */ + CBtDevRepositoryImpl(); + + /** + * Symbian 2nd-phase constructor + */ + void ConstructL(); + + /** + * Creates a registry view which shall contain all remote devices. + */ + void CreateRemoteDeviceView(); + + /** + * retrieves remote devices from registry. + */ + void GetRemoteDevicesL(); + + /** + * handles the completion of paired device view creation + */ + void HandleCreateRemoteDeviceViewCompletedL( TInt aStatus); + + /** + * handles the completion of getting paired devices + */ + void HandleGetRemoteDevicesCompletedL( TInt aStatus ); + + /** + * Copy the remote devices to internal array storage. + */ + void UpdateRemoteDeviceRepositoryL(); + +private: + + /** + * The observers + * do not own them. + */ + RPointerArray iObservers; + + /** + * Registry sub session for remote device db. + * not own + */ + RBTRegistry iBTRegistry; + + // own. + RBTRegServ iBTRegServ; + + /** + * AO for registry operations + * own. + */ + CBtSimpleActive* iRegistryActive; + + /** + * the counter of not handled registry events. + */ + TInt iNotHandledRegEventCounter; + + /** + * temporary instance to retrieve paired devices. + * own. + */ + CBTRegistryResponse* iRegRespRemoteDevices; + + /** + * Property containing the BT registry change monitoring key + * own. + */ + RProperty iBtRegistryKey; + + /** + * AO for subscribing registry PubSub key + * own. + */ + CBtSimpleActive* iRegistryKeyActive; + + /** + * For connection status + */ + CBTEngConnMan* iBtengConn; + + /** + * contains the list of all devices. + * own. + */ + RDevExtensionArray iDevices; + + TInt iInitialized; + + }; + +#endif /*BTDEVICEREPOSITORYIMPL_H*/ diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/inc/btserviceutilconsts.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/inc/btserviceutilconsts.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Internal symbolic constants of this component +* +*/ + +#ifndef BTSERVICEUTILCONSTS_H +#define BTSERVICEUTILCONSTS_H + +#include + +namespace BtServiceUtil { + +const TInt KServiceRequestIdBase = 0x100; + +enum TRequestIdentifier + { + // Inquiry with Host Resolver + EBluetoothInquiry = KServiceRequestIdBase, + // Get the name of a device + EBluetoothPageDeviceName, + // Schedule the notification of search completion + EAsyncNotifyDeviceSearchCompleted, + // Create view table of remote devices from BT registry + ECreateRemoteDeviceViewRequest, + // Retrieves remote devices from BT registry + EGetRemoteDevicesRequest, + // Subsribes the PubSub key for BT registry update events + ERegistryPubSubWatcher + }; +} + +#endif + +// End of File diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/rom/btserviceutil.iby --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/rom/btserviceutil.iby Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Image description file for project btserviceutil +* +*/ + + +#ifndef BTSERVICEUTIL_IBY +#define BTSERVICEUTIL_IBY + +#include + +#ifdef __BT +file=ABI_DIR\BUILD_DIR\btserviceutil.dll SHARED_LIB_DIR\btserviceutil.dll + +#endif // __BT + +#endif // BTSERVICEUTIL_IBY diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/src/advancebtdevdiscoverer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/src/advancebtdevdiscoverer.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: CAdvanceDevDiscoverer class: the interface class for +* searching in-range Bluetooth devices using Host Resolver. +* +*/ + +#include +#include "advancedevdiscovererimpl.h" + +// ---------------------------------------------------------- +// CAdvanceDevDiscoverer::CAdvanceDevDiscoverer +// ---------------------------------------------------------- +// +CAdvanceDevDiscoverer::CAdvanceDevDiscoverer() + { + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscoverer::CAdvanceDevDiscoverer +// ---------------------------------------------------------- +// +void CAdvanceDevDiscoverer::ConstructL( + CBtDevRepository& aDevRep, + MDevDiscoveryObserver& aObserver ) + { + iImpl = CAdvanceDevDiscovererImpl::NewL( aDevRep, aObserver ); + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscoverer::NewL +// ---------------------------------------------------------- +// +EXPORT_C CAdvanceDevDiscoverer* CAdvanceDevDiscoverer::NewL( + CBtDevRepository& aDevRep, + MDevDiscoveryObserver& aObserver ) + { + CAdvanceDevDiscoverer* self = new (ELeave) CAdvanceDevDiscoverer(); + CleanupStack::PushL( self ); + self->ConstructL( aDevRep, aObserver ); + CleanupStack::Pop( self ); + return self; + } + +// ---------------------------------------------------------- +// Destructor +// ---------------------------------------------------------- +// +EXPORT_C CAdvanceDevDiscoverer::~CAdvanceDevDiscoverer() + { + delete iImpl; + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscoverer::SetObserver +// ---------------------------------------------------------- +// +EXPORT_C void CAdvanceDevDiscoverer::SetObserver( + MDevDiscoveryObserver& aObserver ) + { + iImpl->SetObserver( aObserver ); + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscoverer::DiscoverDeviceL +// ---------------------------------------------------------- +// +EXPORT_C void CAdvanceDevDiscoverer::DiscoverDeviceL( + TDevDiscoveryFilter aFilter, + TBTMajorDeviceClass aDeviceClass ) + { + iImpl->DiscoverDeviceL( aFilter, aDeviceClass ); + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscoverer::CancelDiscovery +// ---------------------------------------------------------- +// +EXPORT_C void CAdvanceDevDiscoverer::CancelDiscovery() + { + iImpl->Cancel(); + } + +// End of File diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/src/advancedevdiscovererimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/src/advancedevdiscovererimpl.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,180 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: class for searching BT devices +* +*/ +#include "advancedevdiscovererimpl.h" +#include "basicdevdiscoverer.h" + + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl::CAdvanceDevDiscovererImpl +// ---------------------------------------------------------- +// +CAdvanceDevDiscovererImpl::CAdvanceDevDiscovererImpl( + CBtDevRepository& aDevRep, + MDevDiscoveryObserver& aObserver ) + :iDevRep( aDevRep ), iObserver( aObserver ) + { + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl::ConstructL +// ---------------------------------------------------------- +// +void CAdvanceDevDiscovererImpl::ConstructL() + { + iBasicDiscoverer = CBasicDevDiscoverer::NewL( *this ); + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl::NewL +// ---------------------------------------------------------- +// +CAdvanceDevDiscovererImpl* CAdvanceDevDiscovererImpl::NewL( + CBtDevRepository& aDevRep, + MDevDiscoveryObserver& aObserver ) + { + CAdvanceDevDiscovererImpl* self = + new (ELeave) CAdvanceDevDiscovererImpl( aDevRep, aObserver ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl:: +// ---------------------------------------------------------- +// +CAdvanceDevDiscovererImpl::~CAdvanceDevDiscovererImpl() + { + delete iBasicDiscoverer; + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl::SetObserver +// ---------------------------------------------------------- +// +void CAdvanceDevDiscovererImpl::SetObserver( MDevDiscoveryObserver& aObserver ) + { + iObserver = aObserver; + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl:: +// ---------------------------------------------------------- +// +void CAdvanceDevDiscovererImpl::Cancel() + { + iBasicDiscoverer->Cancel(); + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl:: +// ---------------------------------------------------------- +// +void CAdvanceDevDiscovererImpl::DiscoverDeviceL( + CAdvanceDevDiscoverer::TDevDiscoveryFilter aFilter, + TBTMajorDeviceClass aDeviceClass ) + { + iBasicDiscoverer->DiscoverDeviceL( aDeviceClass ); + iFilter = aFilter; + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl::DiscoverDeviceL +// ---------------------------------------------------------- +// +void CAdvanceDevDiscovererImpl::DiscoverDeviceL( + const RBTDevAddrArray& aPriorityList ) + { + // to be implemented when BTUI requires this feature. + ( void ) aPriorityList; + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl::HandleNextDiscoveryResult +// ---------------------------------------------------------- +// +void CAdvanceDevDiscovererImpl::HandleNextDiscoveryResultL( + const TInquirySockAddr& aAddr, const TDesC& aName ) + { + TBool filtered = EFalse; + if ( iFilter ) + { + // For filtering, we need to examine the properties of + // this device from repository. + const CBtDevExtension* devExt = iDevRep.Device( aAddr.BTAddr() ); + // No filter is needed if this device is not in registry. + if ( devExt ) + { + if ( iFilter & CAdvanceDevDiscoverer::ExcludeUserAwareBonded) + { + // client does not want to discover devices that have been + // bonded already. + if ( devExt->IsUserAwareBonded() ) + { + filtered = ETrue; + } + } + } + } + if ( !filtered ) + { + iObserver.HandleNextDiscoveryResultL( aAddr, aName ); + } + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl::HandleDiscoveryCompleted +// ---------------------------------------------------------- +// +void CAdvanceDevDiscovererImpl::HandleDiscoveryCompleted( TInt aErr ) + { + iObserver.HandleDiscoveryCompleted( aErr ); + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl::RequestCompletedL +// Inform caller for received device and issue next EIR/Name request +// if the request was successful. +// ---------------------------------------------------------- +// +void CAdvanceDevDiscovererImpl::RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ) + { + (void) aActive; + (void) aStatus; + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl::CancelRequest +// ---------------------------------------------------------- +// +void CAdvanceDevDiscovererImpl::CancelRequest( TInt aId ) + { + (void) aId; + } + +// ---------------------------------------------------------- +// CAdvanceDevDiscovererImpl::HandleError +// ---------------------------------------------------------- +// +void CAdvanceDevDiscovererImpl::HandleError( CBtSimpleActive* aActive, TInt aError ) + { + (void) aActive; + (void) aError; + } + +// End of File diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/src/basicdevdiscoverer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/src/basicdevdiscoverer.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,318 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: class for searching BT devices +* +*/ +#include "basicdevdiscoverer.h" +#include +#include "btserviceutilconsts.h" + +// ---------------------------------------------------------- +// CBasicDevDiscoverer::CBasicDevDiscoverer +// ---------------------------------------------------------- +// +CBasicDevDiscoverer::CBasicDevDiscoverer( MDevDiscoveryObserver& aObserver ) + : iObserver( aObserver ) + { + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer::ConstructL +// ---------------------------------------------------------- +// +void CBasicDevDiscoverer::ConstructL() + { + User::LeaveIfError( iSocketServer.Connect() ); + iActive = CBtSimpleActive::NewL( *this, BtServiceUtil::EBluetoothInquiry ); + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer::NewL +// ---------------------------------------------------------- +// +CBasicDevDiscoverer* CBasicDevDiscoverer::NewL( MDevDiscoveryObserver& aObserver ) + { + CBasicDevDiscoverer* self = new (ELeave) + CBasicDevDiscoverer( aObserver ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer:: +// ---------------------------------------------------------- +// +CBasicDevDiscoverer::~CBasicDevDiscoverer() + { + delete iActive; + Reset(); + iSocketServer.Close(); + iDevices.Close(); + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer::SetObserver +// ---------------------------------------------------------- +// +void CBasicDevDiscoverer::SetObserver( MDevDiscoveryObserver& aObserver ) + { + iObserver = aObserver; + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer:: +// ---------------------------------------------------------- +// +void CBasicDevDiscoverer::Cancel() + { + iActive->Cancel(); + iHostResolver.Close(); + iDevices.ResetAndDestroy(); + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer:: +// ---------------------------------------------------------- +// +void CBasicDevDiscoverer::DiscoverDeviceL(TBTMajorDeviceClass aDeviceClass ) + { + // This class supports only one request at the time: + if ( iActive->IsActive() ) + { + User::Leave( KErrInUse ); + } + Reset(); + iMajorDeviceClassFilter = aDeviceClass; + _LIT( KLinkMgrDes, "BTLinkManager" ); + // Associate with bluetooth Link Manager. + TProtocolName protocol( KLinkMgrDes ); + TProtocolDesc pInfo; + User::LeaveIfError( iSocketServer.FindProtocol( protocol, pInfo)); + User::LeaveIfError( iHostResolver.Open(iSocketServer, + pInfo.iAddrFamily, pInfo.iProtocol)); + iActive->SetRequestId( BtServiceUtil::EBluetoothInquiry ); + iInquirySockAddr.SetAction( KHostResInquiry + KHostResEir + KHostResIgnoreCache ); + // We always do Generic Inquiry. + // Limited Inquiry could be added here in future on business need. + iInquirySockAddr.SetIAC(KGIAC); + iHostResolver.GetByAddress( iInquirySockAddr, iEntry, iActive->RequestStatus() ); + iActive->GoActive(); + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer::RequestCompletedL +// Inform caller for received device and issue next EIR/Name request +// if the request was successful. +// ---------------------------------------------------------- +// +void CBasicDevDiscoverer::RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ) + { + TInt errToObserver( aStatus ); + // position in array iDevices: the device item the observer will be notified of. + TInt devToNotify ( KErrNotFound ); + + if ( aActive->RequestId() == BtServiceUtil::EBluetoothInquiry ) + { + if ( aStatus == KErrNone ) + { + TInt pos = HandleInquiryResultL(); + // continue to inquiry for more devices in range + iHostResolver.Next( iEntry, iActive->RequestStatus() ); + iActive->GoActive(); + if ( pos > KErrNotFound && iDevices[pos]->iName.Length() > 0 ) + { + devToNotify = pos; + } + } + else if( iDevices.Count() > 0 ) + { + // an error from inquiry operation. + // we move to next step to get device names if some devices have been + // found but without a name. + iPagingNamePos = iDevices.Count() - 1; + aActive->SetRequestId( BtServiceUtil::EBluetoothPageDeviceName ); + PageNextDeviceName(); + } + } + else if ( aActive->RequestId() == BtServiceUtil::EBluetoothPageDeviceName ) + { + errToObserver = KErrNone; + devToNotify = iPagingNamePos; + // the name in iEntry was reset before paging operation, so we + // can rely on this length() at this time: + if ( aStatus == KErrNone && iEntry().iName.Length() > 0 ) + { + iDevices[iPagingNamePos]->iName = iEntry().iName; + } + // the return error is not checked here. We continue to page the rest + // device names. + --iPagingNamePos; + PageNextDeviceName(); + } + // request ID is BtServiceUtil::EAsyncNotifyDeviceSearchCompleted + else + { + iObserver.HandleDiscoveryCompleted( errToObserver ); + return; + } + + // AO not active means that this is neither inquiring nor paging name. + // Schedule an operation completion callback: + if ( !iActive->IsActive() && + aActive->RequestId() != BtServiceUtil::EAsyncNotifyDeviceSearchCompleted ) + { + // We inform the client of operation completion asynchronously, so that + // we will not end up with problems, e.g., invalid memory, + // if the client issues more request in the callback context. + aActive->SetRequestId( BtServiceUtil::EAsyncNotifyDeviceSearchCompleted ); + aActive->RequestStatus() = KRequestPending; + TRequestStatus* sta = &aActive->RequestStatus(); + User::RequestComplete( sta, errToObserver ); + aActive->GoActive(); + } + + // This could be possible in both inquiry and paging operations. + if ( devToNotify > KErrNotFound ) + { + // This device record is not used any more after we have informed client. + // Extract it and push to cleanup for detroy. + // This is to prevent peak memory usage in case of a great number of + // devices being in range. + CDeviceSearchRecord* rec = iDevices[devToNotify]; + iDevices.Remove( devToNotify ); + CleanupStack::PushL( rec ); + iObserver.HandleNextDiscoveryResultL( rec->iAddr, rec->iName ); + CleanupStack::PopAndDestroy( rec ); + } + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer::DoCancelRequest +// ---------------------------------------------------------- +// +void CBasicDevDiscoverer::CancelRequest( TInt aId ) + { + // host resolver needs to be cancelled. + // For request BtServiceUtil::EAsyncNotifyDeviceSearchCompleted, we + // are doing self-completing. Thus, nothing is needed now. + if ( aId == BtServiceUtil::EBluetoothInquiry || + aId == BtServiceUtil::EBluetoothPageDeviceName ) + { + iHostResolver.Cancel(); + } + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer::HandleError +// Inform UI from error occured. +// ---------------------------------------------------------- +// +void CBasicDevDiscoverer::HandleError( CBtSimpleActive* aActive, TInt aError ) + { + // We might have issued an request to Host Resolver in RequestCompleted(). + // Cancel AO just in case: + aActive->Cancel(); + Reset(); + // We cannot proceed more. Inform client: + iObserver.HandleDiscoveryCompleted( aError ); + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer:: +// ---------------------------------------------------------- +// +void CBasicDevDiscoverer::PageNextDeviceName() + { + // reset the name in entry so that previous result will + // not propogate if the next paging operation fails. + iEntry().iName.Zero(); + for (; iPagingNamePos > -1; --iPagingNamePos ) + { + // Get the next in-range device that has no device name yet + // This is practically meaning that the device would be + // < v2.1 + if( iDevices[iPagingNamePos]->iName.Length() == 0 ) + { + iInquirySockAddr.SetAction( KHostResName + KHostResIgnoreCache ); + TBTDevAddr btaddr = iDevices[iPagingNamePos]->iAddr.BTAddr(); + iInquirySockAddr.SetBTAddr( iDevices[iPagingNamePos]->iAddr.BTAddr() ); + iInquirySockAddr.SetIAC(KGIAC); + iHostResolver.GetByAddress( iInquirySockAddr, iEntry, iActive->RequestStatus() ); + iActive->GoActive(); + break; + } + } + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer::HandleInquiryResultL +// Inform of properties of the found BTdevice, +// which passes the search filter. Its name would be retrived +// later if not contained by the first round of inquiry. +// ---------------------------------------------------------- +// +TInt CBasicDevDiscoverer::HandleInquiryResultL() + { + TInquirySockAddr& sa = TInquirySockAddr::Cast( iEntry().iAddr ); + // parse the inquiry result if this device passes the filters: + if ( iMajorDeviceClassFilter == EMajorDeviceMisc + || sa.MajorClassOfDevice() == iMajorDeviceClassFilter ) + { + CDeviceSearchRecord* record = NewInstanceL( sa ); + CleanupStack::PushL( record ); + iDevices.InsertL(record, 0 ); + CleanupStack::Pop( record ); + + TBTDeviceName devName; + TBluetoothNameRecordWrapper eir( iEntry() ); + TInt length = eir.GetDeviceNameLength(); + TBool isComplete( EFalse ); + if( length > 0 ) + { + User::LeaveIfError( eir.GetDeviceName( record->iName, isComplete) ); + } + return 0; + } + return KErrNotFound; + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer::CompleteDiscovery +// ---------------------------------------------------------- +// +CDeviceSearchRecord* CBasicDevDiscoverer::NewInstanceL( + const TInquirySockAddr& aAddr, const TDesC& aName ) + { + CDeviceSearchRecord* record = new (ELeave) CDeviceSearchRecord(); + record->iAddr = aAddr; + record->iName = aName; + return record; + } + +// ---------------------------------------------------------- +// CBasicDevDiscoverer::Reset +// ---------------------------------------------------------- +// +void CBasicDevDiscoverer::Reset() + { + // Free the cache of host Resolver. + iHostResolver.Close(); + // Clean previous in-range devices whose proximity status + // may have been changed. + iDevices.ResetAndDestroy(); + } + +// End of File diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/src/btdevextension.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/src/btdevextension.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,268 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: an extended BT device offering properties of +* a Bluetooth device that may be needed by Bluetooth UIs +* +*/ + +#include + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBtDevExtension::CBtDevExtension( TDefaultDevNameOption aNameOption ) +: iNameOption( aNameOption ) + { + } + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBtDevExtension::ConstructL( CBTDevice* aDev ) + { + SetDeviceL( aDev ); + } + +// --------------------------------------------------------------------------- +// NewLC +// --------------------------------------------------------------------------- +// +EXPORT_C CBtDevExtension* CBtDevExtension::NewLC( + CBTDevice* aDev, TDefaultDevNameOption aNameOption ) + { + CBtDevExtension* self = NULL; + self = new (ELeave) CBtDevExtension( aNameOption ); + CleanupStack::PushL( self ); + self->ConstructL( aDev ); + return self; + } + +// --------------------------------------------------------------------------- +// NewL +// --------------------------------------------------------------------------- +// +EXPORT_C CBtDevExtension* CBtDevExtension::NewLC( + const TInquirySockAddr& aAddr, + const TDesC& aName, + TDefaultDevNameOption aNameOption ) + { + CBtDevExtension* self = new (ELeave) CBtDevExtension( aNameOption ); + CleanupStack::PushL( self ); + CBTDevice* dev = CBTDevice::NewLC( aAddr.BTAddr() ); + TBTDeviceClass cod( aAddr.MajorServiceClass(), + aAddr.MajorClassOfDevice(), aAddr.MinorClassOfDevice() ); + dev->SetDeviceClass( cod ); + if ( aName.Length() ) + { + dev->SetDeviceNameL( BTDeviceNameConverter::ToUTF8L( aName ) ); + } + self->ConstructL( dev ); + CleanupStack::Pop( dev ); + return self; + } + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +EXPORT_C CBtDevExtension::~CBtDevExtension() + { + iAlias.Close(); + delete iDev; + } + +// --------------------------------------------------------------------------- +// IsBonded +// --------------------------------------------------------------------------- +// +TBool CBtDevExtension::IsBonded( const TBTNamelessDevice &dev ) + { + // IsValidPaired tells if the paired bit of dev is valid + // and IsPaired tells if the device is paired or not: + return dev.IsValidPaired() && + dev.IsPaired() && + // Authentication due to OBEX cases e.g. file transfer, is not + // considered as bonded in Bluetooth UI: + dev.LinkKeyType() != ELinkKeyUnauthenticatedUpgradable; + } + +// --------------------------------------------------------------------------- +// IsJustWorksBonded +// --------------------------------------------------------------------------- +// +TBool CBtDevExtension::IsJustWorksBonded( const TBTNamelessDevice &dev ) + { + return IsBonded( dev ) && + dev.LinkKeyType() == ELinkKeyUnauthenticatedNonUpgradable; + } + +// --------------------------------------------------------------------------- +// IsUserAwareBonded +// --------------------------------------------------------------------------- +// +TBool CBtDevExtension::IsUserAwareBonded( const TBTNamelessDevice &dev ) + { + if ( IsJustWorksBonded( dev ) ) + { + // Just Works bonded devices can happen without user awareness. + // For example, authentication due to an incoming service connection request + // from a device without IO. + // We use cookies to identify if this JW pairing is user aware or not: + TInt32 cookie = dev.IsValidUiCookie() ? dev.UiCookie() : EBTUiCookieUndefined; + return (cookie & EBTUiCookieJustWorksPaired ); + } + // Pairing in other mode than Just Works are always user-aware: + return IsBonded( dev ); + } + + +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +EXPORT_C const TDesC& CBtDevExtension::Alias() const + { + return iAlias; + } + +// --------------------------------------------------------------------------- +// Addr() +// --------------------------------------------------------------------------- +// +EXPORT_C const TBTDevAddr& CBtDevExtension::Addr() const + { + return iDev->BDAddr(); + } + +// --------------------------------------------------------------------------- +// Device +// --------------------------------------------------------------------------- +// +EXPORT_C const CBTDevice& CBtDevExtension::Device() const + { + return *iDev; + } + + + +// --------------------------------------------------------------------------- +// IsUserAwareBonded +// --------------------------------------------------------------------------- +// +EXPORT_C TBool CBtDevExtension::IsUserAwareBonded() const + { + return IsUserAwareBonded( iDev->AsNamelessDevice() ); + } + +// --------------------------------------------------------------------------- +// ServiceConnectionStatus() +// --------------------------------------------------------------------------- +// +TBTEngConnectionStatus CBtDevExtension::ServiceConnectionStatus() const + { + return iServiceStatus; + } + +// --------------------------------------------------------------------------- +// SetDeviceL +// --------------------------------------------------------------------------- +// +EXPORT_C void CBtDevExtension::SetDeviceL( CBTDevice* aDev ) + { + delete iDev; + iDev = aDev; + // It is possible that the client set a NULL object to us. + if ( !iDev ) + { + iDev = CBTDevice::NewL(); + } + // No optimization here. If client sets an identical device instance + // We will still execute these steps: + UpdateNameL(); + //UpdateServiceStatusL(); + } + +EXPORT_C CBtDevExtension* CBtDevExtension::CopyL() + { + CBtDevExtension* newDev = CBtDevExtension::NewLC( NULL ); + CBTDevice* dev = iDev->CopyL(); + CleanupStack::PushL( dev ); + newDev->SetDeviceL( dev ); + CleanupStack::Pop( dev); + newDev->SetServiceConnectionStatus( ServiceConnectionStatus() ); + CleanupStack::Pop( newDev ); + return newDev; + } + +// --------------------------------------------------------------------------- +// ServiceConnectionStatus() +// --------------------------------------------------------------------------- +// +void CBtDevExtension::SetServiceConnectionStatus( + TBTEngConnectionStatus aStatus ) + { + iServiceStatus = aStatus; + } + + + +// --------------------------------------------------------------------------- +// UpdateL() +// --------------------------------------------------------------------------- +// +void CBtDevExtension::UpdateNameL() + { + // UI takes friendly name for displaying if it is available + iAlias.Zero(); + if ( iDev->IsValidFriendlyName() && iDev->FriendlyName().Length() != 0 ) + { + iAlias.CreateL( iDev->FriendlyName() ); + } + // otherwise, device name, if it is available, will be displayed + else if ( iDev->IsValidDeviceName() && iDev->DeviceName().Length() != 0 ) + { + iAlias.CreateL( BTDeviceNameConverter::ToUnicodeL(iDev->DeviceName() ) ); + } + if ( iAlias.Length() == 0 && + ( iNameOption == EColonSeperatedBDAddr || iNameOption == EPlainBDAddr ) ) + { + // Name for display is still missing. We need to make one for user to + // identify it. + FormatAddressAsNameL(); + } + } + +// --------------------------------------------------------------------------- +// FormatAddressAsNameL() +// --------------------------------------------------------------------------- +// +void CBtDevExtension::FormatAddressAsNameL() + { + // readable format of BD_ADDR is double size of BD ADDR size, + // and plus the seperators. + iAlias.ReAllocL( KBTDevAddrSize * 3 ); + _LIT(KColon, ":"); + if ( iNameOption == EColonSeperatedBDAddr ) + { + iDev->BDAddr().GetReadable( iAlias, KNullDesC, KColon, KNullDesC ); + } + else + { + iDev->BDAddr().GetReadable( iAlias ); + } + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/src/btdevrepository.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/src/btdevrepository.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,109 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Repository of remote Bluetooth devices +* +*/ + +#include +#include "btdevrepositoryimpl.h" + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBtDevRepository::CBtDevRepository() + { + } + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBtDevRepository::ConstructL() + { + iImpl = CBtDevRepositoryImpl::NewL(); + } + +// --------------------------------------------------------------------------- +// NewL +// --------------------------------------------------------------------------- +// +EXPORT_C CBtDevRepository* CBtDevRepository::NewL() + { + CBtDevRepository* self = NULL; + self = new (ELeave) CBtDevRepository(); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +EXPORT_C CBtDevRepository::~CBtDevRepository() + { + delete iImpl; + } + +// --------------------------------------------------------------------------- +// AddObserverL. +// Delegate to the implementor +// --------------------------------------------------------------------------- +// +EXPORT_C void CBtDevRepository::AddObserverL( MBtDevRepositoryObserver* aObserver ) + { + iImpl->AddObserverL( aObserver ); + } + +// --------------------------------------------------------------------------- +// RemoveObserver. +// Delegate to the implementor +// --------------------------------------------------------------------------- +// +EXPORT_C void CBtDevRepository::RemoveObserver( MBtDevRepositoryObserver* aObserver ) + { + iImpl->RemoveObserver( aObserver ); + } + +// --------------------------------------------------------------------------- +// AllDevices +// --------------------------------------------------------------------------- +// +EXPORT_C TBool CBtDevRepository::IsInitialized() const + { + return iImpl->IsInitialized(); + } + +// --------------------------------------------------------------------------- +// AllDevices +// --------------------------------------------------------------------------- +// +EXPORT_C const RDevExtensionArray& CBtDevRepository::AllDevices() const + { + return iImpl->AllDevices(); + } + +// --------------------------------------------------------------------------- +// Device +// --------------------------------------------------------------------------- +// +EXPORT_C const CBtDevExtension* CBtDevRepository::Device( + const TBTDevAddr& aAddr ) const + { + return iImpl->Device( aAddr ); + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/src/btdevrepositoryimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/src/btdevrepositoryimpl.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,439 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: respository of remote Bluetooth devices. +* +*/ + +#include "btdevrepositoryimpl.h" +#include +#include +#include +#include "btserviceutilconsts.h" + +// --------------------------------------------------------------------------- +// Tells if two CBTDevice instances are for the same remote device +// --------------------------------------------------------------------------- +// +TBool CompareDeviceByAddress( const CBTDevice& aDevA, const CBTDevice& aDevB ) + { + return aDevA.BDAddr() == aDevB.BDAddr(); + } + +// --------------------------------------------------------------------------- +// Tells if these two instances are for the same remote device +// --------------------------------------------------------------------------- +// +TBool MatchDeviceAddress(const TBTDevAddr* aAddr, const CBTDevice& aDev) + { + return *aAddr == aDev.BDAddr(); + } + +// --------------------------------------------------------------------------- +// Tells if these two instances are for the same remote device +// --------------------------------------------------------------------------- +// +TBool MatchDeviceAddress(const TBTDevAddr* aAddr, const CBtDevExtension& aDev) + { + return *aAddr == aDev.Device().BDAddr(); + } + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBtDevRepositoryImpl::CBtDevRepositoryImpl() + { + } + +// --------------------------------------------------------------------------- +// Symbian 2nd-phase constructor +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::ConstructL() + { + // connect to registry + User::LeaveIfError( iBTRegServ.Connect() ); + User::LeaveIfError( iBTRegistry.Open( iBTRegServ ) ); + iRegistryActive = CBtSimpleActive::NewL( + *this, BtServiceUtil::ECreateRemoteDeviceViewRequest ); + // Start to get the list of devices from registry. + CreateRemoteDeviceView(); + + User::LeaveIfError( iBtRegistryKey.Attach( + KPropertyUidBluetoothCategory, + KPropertyKeyBluetoothGetRegistryTableChange ) ); + + iRegistryKeyActive = CBtSimpleActive::NewL( *this, BtServiceUtil::ERegistryPubSubWatcher ); + iBtRegistryKey.Subscribe( iRegistryKeyActive->RequestStatus() ); + iRegistryKeyActive->GoActive(); + iBtengConn = CBTEngConnMan::NewL( this ); + } + +// --------------------------------------------------------------------------- +// NewL +// --------------------------------------------------------------------------- +// +CBtDevRepositoryImpl* CBtDevRepositoryImpl::NewL() + { + CBtDevRepositoryImpl* self = NULL; + self = new (ELeave) CBtDevRepositoryImpl(); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +CBtDevRepositoryImpl::~CBtDevRepositoryImpl() + { + iObservers.Close(); + delete iBtengConn; + delete iRegistryActive; + delete iRegRespRemoteDevices; + iDevices.ResetAndDestroy(); + iDevices.Close(); + iBTRegistry.Close(); + iBTRegServ.Close(); + delete iRegistryKeyActive; + iBtRegistryKey.Close(); + } + +// --------------------------------------------------------------------------- +// AddObserverL +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::AddObserverL( MBtDevRepositoryObserver* aObserver ) + { + // Do not allow null pointer. + if ( aObserver ) + { + iObservers.AppendL( aObserver ); + } + } + +// --------------------------------------------------------------------------- +// RemoveObserver +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::RemoveObserver( MBtDevRepositoryObserver* aObserver ) + { + TInt i = iObservers.Find( aObserver ); + if ( i >= 0 ) + { + iObservers.Remove( i ); + } + } + +// --------------------------------------------------------------------------- +// IsInitialized +// --------------------------------------------------------------------------- +// +TBool CBtDevRepositoryImpl::IsInitialized() const + { + return iInitialized; + } + +// --------------------------------------------------------------------------- +// AllDevices +// --------------------------------------------------------------------------- +// +const RDevExtensionArray& CBtDevRepositoryImpl::AllDevices() const + { + return iDevices; + } + +// --------------------------------------------------------------------------- +// Device +// --------------------------------------------------------------------------- +// +const CBtDevExtension* CBtDevRepositoryImpl::Device( + const TBTDevAddr& aAddr ) const + { + TInt pos = iDevices.Find( aAddr, MatchDeviceAddress); + if ( pos > -1 ) + { + return iDevices[pos]; + } + return NULL; + } + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// Checks if there is an authentication result. +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ) + { + if ( aActive->RequestId() == BtServiceUtil::ECreateRemoteDeviceViewRequest ) + { + HandleCreateRemoteDeviceViewCompletedL( aStatus ); + } + else if ( aActive->RequestId() == BtServiceUtil::EGetRemoteDevicesRequest ) + { + HandleGetRemoteDevicesCompletedL( aStatus ); + } + else if ( aActive->RequestId() == BtServiceUtil::ERegistryPubSubWatcher ) + { + TInt myChangedTable; + iBtRegistryKey.Subscribe( aActive->RequestStatus() ); + aActive->GoActive(); + TInt err = iBtRegistryKey.Get( myChangedTable ); + if( !err && myChangedTable == KRegistryChangeRemoteTable ) + { + if ( !iRegistryActive->IsActive() ) + { + CreateRemoteDeviceView(); + } + else + { + iNotHandledRegEventCounter++; + } + } + } + } + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// Checks if there is an authentication result. +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::CancelRequest( TInt aRequestId ) + { + if ( aRequestId == BtServiceUtil::ECreateRemoteDeviceViewRequest ) + { + iBTRegistry.CancelRequest(iRegistryActive->RequestStatus()); + } + else if ( aRequestId == BtServiceUtil::EGetRemoteDevicesRequest ) + { + iRegRespRemoteDevices->Cancel(); + } + else if ( aRequestId == BtServiceUtil::ERegistryPubSubWatcher ) + { + iBtRegistryKey.Cancel(); + } + } + +// --------------------------------------------------------------------------- +// From class MBtSimpleActiveObserver. +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::HandleError( CBtSimpleActive* aActive, TInt aError ) + { + (void) aError; + if ( aActive->RequestId() == BtServiceUtil::ECreateRemoteDeviceViewRequest || + aActive->RequestId() == BtServiceUtil::EGetRemoteDevicesRequest ) + {// leave happened in registry operation, delete registry response: + delete iRegRespRemoteDevices; + iRegRespRemoteDevices = NULL; + } + } + +// --------------------------------------------------------------------------- +// From class MBTEngConnObserver. +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::ConnectComplete( TBTDevAddr& aAddr, TInt aErr, + RBTDevAddrArray* aConflicts) + { + // connection is single profile based, to make sure getting the correct status, + // we always retrieve it from btengconnman: + (void)aConflicts; + (void) aErr; + TInt pos = iDevices.Find( aAddr, MatchDeviceAddress ); + if ( pos > -1 ) + { + TBTEngConnectionStatus status = EBTEngNotConnected; + // error returned from the call is treated as not connected. + (void) iBtengConn->IsConnected( aAddr, status ); + iDevices[pos]->SetServiceConnectionStatus( status ); + } + } + +// --------------------------------------------------------------------------- +// From class MBTEngConnObserver. +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ) + { + // unified handling for connections status events: + ConnectComplete( aAddr, aErr, NULL); + } + +// --------------------------------------------------------------------------- +// issue creating a remote device view from the registry +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::CreateRemoteDeviceView() + { + iNotHandledRegEventCounter = 0; + (void) iBTRegistry.CloseView(); + TBTRegistrySearch searchPattern; + searchPattern.FindAll(); + iRegistryActive->SetRequestId( BtServiceUtil::ECreateRemoteDeviceViewRequest ); + iBTRegistry.CreateView( searchPattern, iRegistryActive->iStatus ); + iRegistryActive->GoActive(); + } + +// --------------------------------------------------------------------------- +// gets the paired devices from the view created by CreatePairedDevicesView +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::GetRemoteDevicesL() + { + delete iRegRespRemoteDevices; + iRegRespRemoteDevices = NULL; + iRegRespRemoteDevices = CBTRegistryResponse::NewL( iBTRegistry ); + iRegistryActive->SetRequestId( BtServiceUtil::EGetRemoteDevicesRequest ); + iRegRespRemoteDevices->Start( iRegistryActive->iStatus ); + iRegistryActive->GoActive(); + } + +// --------------------------------------------------------------------------- +// re-create a paired device view if registry was changed during the previous +// operation. otherwise if the view is not empty, get the remote devices. +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::HandleCreateRemoteDeviceViewCompletedL( TInt aStatus ) + { + // aStatus may indicate the number of devices from registry. + // However, our algorithm does not rely on this return error + // for implementation simplicity. + (void) aStatus; + if (iNotHandledRegEventCounter) + { // more registry change detected, create paired device view again: + CreateRemoteDeviceView( ); + } + else + { + GetRemoteDevicesL( ); + } + } + +// --------------------------------------------------------------------------- +// update remote device list. if registry was changed, create a new view. +// otherwise inform client for any changes. +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::HandleGetRemoteDevicesCompletedL( TInt aStatus ) + { + // aStatus may indicate the number of devices from registry. + // However, our algorithm does not rely on this return error. + (void) aStatus; + if (iNotHandledRegEventCounter) + { // more registry change detected, create paired device view again: + CreateRemoteDeviceView( ); + return; + } + + UpdateRemoteDeviceRepositoryL(); + if ( !iInitialized ) + { + iInitialized = ETrue; + // The first time we have got the device lists from registry, + // Get the connections statuses of these devices from bteng. + for ( TInt i = iDevices.Count() - 1; i > -1; --i ) + { + TBTEngConnectionStatus status = EBTEngNotConnected; + // error returned from the call is treated as not connected. + (void) iBtengConn->IsConnected( iDevices[i]->Addr(), status ); + iDevices[i]->SetServiceConnectionStatus( status ); + } + for ( TInt i = 0; i < iObservers.Count(); ++i ) + { + iObservers[i]->RepositoryInitialiazed(); + } + } + } + +// --------------------------------------------------------------------------- +// update remote devices in local array with the latest data +// --------------------------------------------------------------------------- +// +void CBtDevRepositoryImpl::UpdateRemoteDeviceRepositoryL() + { + TIdentityRelation addrComp( CompareDeviceByAddress ); + RBTDeviceArray& devsFromReg = iRegRespRemoteDevices->Results(); + for ( TInt i = iDevices.Count() - 1; i > -1; --i ) + { + TInt pos = devsFromReg.Find( &(iDevices[i]->Device()), addrComp ); + if ( pos > KErrNotFound ) + { + // Device is found in registry, check if its properties have been changed + TUint similarity = devsFromReg[pos]->CompareTo( iDevices[i]->Device() ); + TBool changed = EFalse; + if ( similarity != + ( CBTDevice::EAllNameProperties | + TBTNamelessDevice::EAllNamelessProperties) ) + { + // This device was updated in registry. + // move its ownership to local store + iDevices[i]->SetDeviceL( devsFromReg[pos] ); + changed = ETrue; + } + else + { + // This device has no update: + delete devsFromReg[pos]; + } + // either the instance at pos has been moved or deleted. + devsFromReg.Remove( pos ); + if ( iInitialized && changed ) + { + for ( TInt i = 0; i < iObservers.Count(); ++i ) + { + iObservers[i]->BtDeviceChangedInRegistry( *iDevices[i], similarity ); + } + } + } + else + { + // This device was deleted from registry. + // Free it from the local store before informing client. + TBTDevAddr addr = iDevices[i]->Addr(); + delete iDevices[i]; + iDevices.Remove( i ); + if ( iInitialized ) + { + for ( TInt i = 0; i < iObservers.Count(); ++i ) + { + iObservers[i]->BtDeviceDeleted( addr ); + } + } + } + } + + // Remaining devices in iRegRespRemoteDevices are new devices: + for ( TInt i = 0; i < devsFromReg.Count() ; i++ ) + { + CBtDevExtension* devExt = CBtDevExtension::NewLC( devsFromReg[i] ); + iDevices.AppendL( devExt ); + CleanupStack::Pop( devExt ); + devsFromReg.Remove( i ); + if ( iInitialized ) + { + for ( TInt i = 0; i < iObservers.Count(); ++i ) + { + iObservers[i]->BtDeviceAdded( *iDevices[ iDevices.Count() - 1 ] ); + } + } + } + // the devices in devsFromReg was either deleted, or moved. + delete iRegRespRemoteDevices; + iRegRespRemoteDevices = NULL; + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btserviceutil/src/btsimpleactive.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btserviceutil/src/btsimpleactive.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,120 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Active object helper class. +* +*/ + +#include + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// C++ default constructor +// --------------------------------------------------------------------------- +// +CBtSimpleActive::CBtSimpleActive( MBtSimpleActiveObserver& aObserver, TInt aId, + TInt aPriority ) +: CActive( aPriority ), + iRequestId( aId ), + iObserver( aObserver ) + { + CActiveScheduler::Add( this ); + } + +// --------------------------------------------------------------------------- +// NewL +// --------------------------------------------------------------------------- +// +EXPORT_C CBtSimpleActive* CBtSimpleActive::NewL( MBtSimpleActiveObserver& aObserver, + TInt aId, TInt aPriority ) + { + CBtSimpleActive* self = new( ELeave ) CBtSimpleActive( aObserver, aId, aPriority ); + return self; + } + +// --------------------------------------------------------------------------- +// Destructor +// --------------------------------------------------------------------------- +// +EXPORT_C CBtSimpleActive::~CBtSimpleActive() + { + Cancel(); + } + +// ----------------------------------------------------------------------------- +// Get the identifier of this instance. +// ----------------------------------------------------------------------------- +// +EXPORT_C TInt CBtSimpleActive::RequestId() + { + return iRequestId; + } + +// ----------------------------------------------------------------------------- +// Set the identifier of this instance. +// ----------------------------------------------------------------------------- +// +EXPORT_C void CBtSimpleActive::SetRequestId( TInt aId ) + { + iRequestId = aId; + } + +// ----------------------------------------------------------------------------- +// Activate the active object. +// ----------------------------------------------------------------------------- +// +EXPORT_C void CBtSimpleActive::GoActive() + { + SetActive(); + } + +// ----------------------------------------------------------------------------- +// Get a reference to the active object request status. +// ----------------------------------------------------------------------------- +// +EXPORT_C TRequestStatus& CBtSimpleActive::RequestStatus() + { + return iStatus; + } + +// --------------------------------------------------------------------------- +// From class CActive. +// Called by the active scheduler when the request has been cancelled. +// --------------------------------------------------------------------------- +// +void CBtSimpleActive::DoCancel() + { + iObserver.CancelRequest( iRequestId ); + } + +// --------------------------------------------------------------------------- +// From class CActive. +// Called by the active scheduler when the request has been completed. +// --------------------------------------------------------------------------- +// +void CBtSimpleActive::RunL() + { + iObserver.RequestCompletedL( this, iStatus.Int() ); + } + +// --------------------------------------------------------------------------- +// From class CActive. +// Called by the active scheduler when an error in RunL has occurred. +// --------------------------------------------------------------------------- +// +TInt CBtSimpleActive::RunError( TInt aError ) + { + iObserver.HandleError( this, aError ); + return KErrNone; + } diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpplugin.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpplugin.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + + +#include +#include "BtCpPlugin.h" +#include "btcpuimainview.h" +#include "btcpuisettingitem.h" + +/*! + BtCpPlugin::BtCpPlugin + */ +BtCpPlugin::BtCpPlugin() +{ +} + +/*! + BtCpPlugin::~BtCpPlugin + */ +BtCpPlugin::~BtCpPlugin() +{ +} + +/*! + BtCpPlugin::createSettingFormItemData + */ +QList BtCpPlugin::createSettingFormItemData(CpItemDataHelper &itemDataHelper) const +{ + + return QList () << new BtCpUiSettingItem( + itemDataHelper, tr("Bluetooth")); + +} + +Q_EXPORT_PLUGIN2(BtCpPlugin, BtCpPlugin); diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpplugin.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpplugin.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + +#ifndef BTCPPLUGIN_H +#define BTCPPLUGIN_H + +#include +#include + +class BtCpPlugin : public QObject, public CpPluginInterface +{ + Q_OBJECT + Q_INTERFACES(CpPluginInterface) + +public: + + BtCpPlugin(); + ~BtCpPlugin(); + virtual QList createSettingFormItemData(CpItemDataHelper &itemDataHelper) const; +}; + +#endif /* BTCPPLUGIN_H */ diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpplugin.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpplugin.pro Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,65 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# + +TEMPLATE = lib +TARGET = btcpplugin +DEPENDPATH += . +INCLUDEPATH += . ../inc/ + + +CONFIG += qt hb plugin +LIBS += -lcpframework -lbtuimodel -lbtuidelegate + +MOC_DIR = moc +OBJECTS_DIR = obj + +#TRANSLATIONS = telephone_cp.ts +RESOURCES += btcpplugin.qrc + +# Input +HEADERS += btcpplugin.h \ + btcpuibaseview.h \ + btcpuimainview.h \ + btcpuisearchview.h \ + btcpuisettingitem.h + +SOURCES += btcpplugin.cpp \ + btcpuibaseview.cpp \ + btcpuimainview.cpp \ + btcpuisearchview.cpp \ + btcpuisettingitem.cpp + +symbian: { + DEFINES += PLUGINUID3=0x2002434E + TARGET.UID3 = 0x2002434E + TARGET.CAPABILITY = ALL -TCB + + TARGET.EPOCALLOWDLLDATA = 1 + INCLUDEPATH += $$MW_LAYER_SYSTEMINCLUDE + + PLUGIN_STUB_PATH = /resource/qt/plugins/controlpanel + + deploy.path = C: + pluginstub.sources = $${TARGET}.dll + pluginstub.path = $$PLUGIN_STUB_PATH + DEPLOYMENT += pluginstub + + qtplugins.path = $$PLUGIN_STUB_PATH + qtplugins.sources += qmakepluginstubs/$${TARGET}.qtplugin + + for(qtplugin, qtplugins.sources):BLD_INF_RULES.prj_exports += "./$$qtplugin $$deploy.path$$qtplugins.path/$$basename(qtplugin)" +} + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpplugin.qrc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpplugin.qrc Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,26 @@ + + + icons/qgn_graf_blid_det_circle.svg + icons/qgn_graf_blid_time.svg + icons/qgn_indi_bt_blocked.svg + icons/qgn_indi_bt_paired_add.svg + icons/qgn_indi_bt_trusted_add.svg + icons/qgn_prop_bt_audio.svg + icons/qgn_prop_bt_blocked_tab3.svg + icons/qgn_prop_bt_car_kit.svg + icons/qgn_prop_bt_carkit.svg + icons/qgn_prop_bt_computer.svg + icons/qgn_prop_bt_headset.svg + icons/qgn_prop_bt_keyboard.svg + icons/qgn_prop_bt_misc.svg + icons/qgn_prop_bt_mouse.svg + icons/qgn_prop_bt_phone.svg + icons/qgn_prop_bt_printer.svg + icons/qgn_prop_bt_unknown.svg + icons/qgn_frwidget_add_friend_photo.svg + + + docml/bt-main-view.docml + docml/bt-search-view.docml + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpuibaseview.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpuibaseview.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,45 @@ +/* +* ============================================================================ +* Name : btcpuibaseclass.cpp +* Part of : BluetoothUI / btapplication *** Info from the SWAD +* Description : Implements the baseclass for all views in btapplication. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "btcpuibaseview.h" +#include + +/*! + Constructor. + */ +BtCpUiBaseView::BtCpUiBaseView( BtuiModel &model, QGraphicsItem *parent ) + :CpBaseSettingView( 0 , parent ),mModel(model) +{ + +} + +/*! + Destructor. + */ +BtCpUiBaseView::~BtCpUiBaseView() +{ + +} + + + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpuibaseview.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpuibaseview.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,64 @@ +/* +* ============================================================================ +* Name : btcpuibaseview.h +* Part of : BluetoothUI / btapplication *** Info from the SWAD +* Description : Declaration of the baseclass for all views in btapplication. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTCPUIBASEVIEW_H +#define BTCPUIBASEVIEW_H + +#include +#include +#include +#include + +/*! + \class BtUiBaseView + \brief the class is the base class for all views in btapplication. + + */ +class BtCpUiBaseView : public CpBaseSettingView +{ + Q_OBJECT + +public: + + virtual ~BtCpUiBaseView(); + virtual void activateView( const QVariant& value, int cmdId ) = 0; + virtual void deactivateView() = 0; + +signals: + +protected: + explicit BtCpUiBaseView( BtuiModel &model, QGraphicsItem *parent = 0); + virtual void setSoftkeyBack() = 0; + virtual void switchToPreviousView() = 0; + +protected: + + //Does not own this model. + BtuiModel &mModel; + + QGraphicsItem *mParent; + int mPreviousViewId; + + Q_DISABLE_COPY(BtCpUiBaseView) +}; + +#endif // BTCPUIBASEVIEW_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpuimainview.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpuimainview.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,524 @@ +/* +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: BtCpUiMainView implementation +* +*/ + +#include "btcpuimainview.h" +#include +#include +#include +//#include "btuiviewutil.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "btcpuisearchview.h" +#include +#include +#include +#include "btqtconstants.h" + + +// docml to load +const char* BTUI_MAINVIEW_DOCML = ":/docml/bt-main-view.docml"; + +/*! + Constructs a new BtUiMainView using HBDocumentLoader. Docml (basically xml) file + has been generated using Application Designer. + + */ +BtCpUiMainView::BtCpUiMainView( BtuiModel &model, QGraphicsItem *parent ) + : BtCpUiBaseView( model, parent ), mAbstractDelegate(0) +{ + bool ret(false); + + mMainWindow = hbInstance->allMainWindows().first(); + mMainView = this; + + // Create view for the application. + // Set the name for the view. The name should be same as the view's + // name in docml. + setObjectName("view"); + + QObjectList objectList; + objectList.append(this); + // Pass the view to documentloader. Document loader uses this view + // when docml is parsed, instead of creating new view. + mLoader = new HbDocumentLoader(); + mLoader->setObjectTree(objectList); + + bool ok = false; + mLoader->load( BTUI_MAINVIEW_DOCML, &ok ); + // Exit if the file format is invalid + BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file" ); + + mOrientation = mMainWindow->orientation(); + + if (mOrientation == Qt::Horizontal) { + mLoader->load(BTUI_MAINVIEW_DOCML, "landscape", &ok); + BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: landscape section problem" ); + } + else { + mLoader->load(BTUI_MAINVIEW_DOCML, "portrait", &ok); + BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: landscape section problem" ); + } + + mDeviceNameEdit=0; + mDeviceNameEdit = qobject_cast( mLoader->findWidget( "lineEdit" ) ); + BTUI_ASSERT_X( mDeviceNameEdit != 0, "bt-main-view", "Device Name not found" ); + ret = connect(mDeviceNameEdit, SIGNAL(editingFinished ()), this, SLOT(changeBtLocalName())); + + mPowerButton=0; + mPowerButton = qobject_cast( mLoader->findWidget( "pushButton" ) ); + BTUI_ASSERT_X( mPowerButton != 0, "bt-main-view", "power button not found" ); + ret = connect(mPowerButton, SIGNAL(clicked()), this, SLOT(changePowerState())); + BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect power button" ); + + mVisibilityMode=0; + mVisibilityMode = qobject_cast( mLoader->findWidget( "combobox" ) ); + BTUI_ASSERT_X( mVisibilityMode != 0, "bt-main-view", "visibility combobox not found" ); + + mDeviceList=0; + mDeviceList = qobject_cast( mLoader->findWidget( "gridView" ) ); + BTUI_ASSERT_X( mDeviceList != 0, "bt-main-view", "Device List (grid view) not found" ); + + // listen for orientation changes + ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), + this, SLOT(changeOrientation(Qt::Orientation))); + BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView()", "connect orientationChanged() failed"); + + // load tool bar actions + HbAction *discoverAction = static_cast( mLoader->findObject( "discoverAction" ) ); + BTUI_ASSERT_X( discoverAction, "bt-main-view", "discover action missing" ); + ret = connect(discoverAction, SIGNAL(triggered()), this, SLOT(goToDiscoveryView())); + BTUI_ASSERT_X( ret, "bt-main-view", "orientation toggle can't connect" ); + + // load menu + HbMenu *optionsMenu = qobject_cast(mLoader->findWidget("viewMenu")); + BTUI_ASSERT_X( optionsMenu != 0, "bt-main-view", "Options menu not found" ); + this->setMenu(optionsMenu); + + // update display when setting data changed + ret = connect(&mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), + this, SLOT(updateSettingItems(QModelIndex,QModelIndex))); + BTUI_ASSERT_X( ret, "BtCpUiMainView::BtCpUiMainView", "can't connect dataChanged" ); + + QModelIndex top = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::BluetoothNameCol ); + QModelIndex bottom = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::VisibilityCol ); + // update name, power and visibility rows + updateSettingItems( top, bottom ); + + //Handle Visibility Change User Interaction + ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), + this, SLOT(visibilityChanged (int))); + // create other views + createViews(); + mCurrentView = this; + mCurrentViewId = MainView; + +} + +/*! + Destructs the BtCpUiMainView. + */ +BtCpUiMainView::~BtCpUiMainView() +{ + delete mLoader; // Also deletes all widgets that it constructed. + mMainWindow->removeView(mSearchView); + delete mSearchView; + if (mAbstractDelegate) + { + delete mAbstractDelegate; + } +} + +/*! + from base class, initialize the view + */ +void BtCpUiMainView::activateView(const QVariant& value, int cmdId ) +{ + Q_UNUSED(value); + Q_UNUSED(cmdId); + +} + +/*! + From base class. Handle resource before the current view is deactivated. + */ +void BtCpUiMainView::deactivateView() +{ + +} + +void BtCpUiMainView::itemActivated(QModelIndex index) +{ + Q_UNUSED(index); +} + +void BtCpUiMainView::goToDiscoveryView() +{ + changeView( SearchView, false, 0 ); +} + +Qt::Orientation BtCpUiMainView::orientation() +{ + return mOrientation; +} + +void BtCpUiMainView::changeBtLocalName() +{ + //Error handling has to be done. + if (!mAbstractDelegate) { + mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName, mModel); + connect( mAbstractDelegate, SIGNAL(commandCompleted(int,QVariant)), this, SLOT(btNameDelegateCompleted(int,QVariant)) ); + mAbstractDelegate->exec(mDeviceNameEdit->text ()); + } + else { + setPrevBtLocalName(); + } +} + +void BtCpUiMainView::setPrevBtLocalName() +{ + //Should we notify user this as Error...? + HbNotificationDialog::launchDialog(hbTrId("Error")); + QModelIndex index = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::BluetoothNameCol ); + + mDeviceNameEdit->setText( mModel.data(index,BtuiModel::settingDisplay).toString() ); +} + + +void BtCpUiMainView::btNameDelegateCompleted(int status, QVariant param) +{ + if(KErrNone == status) { + mDeviceNameEdit->setText(param.toString()); + } + else { + setPrevBtLocalName(); + } + //Error handling has to be done. + if (mAbstractDelegate) + { + disconnect(mAbstractDelegate); + delete mAbstractDelegate; + mAbstractDelegate = 0; + } + +} + +void BtCpUiMainView::visibilityChanged (int index) +{ + QList list; + + VisibilityMode mode = indexToVisibilityMode(index); + list.append(QVariant((int)mode)); + if(BtTemporary == VisibilityMode(mode)) { + //Right now hardcoded to 5 Mins. + list.append(QVariant(5)); + } + //Error handling has to be done. + if (!mAbstractDelegate) { + mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Visibility, mModel); + connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(visibilityDelegateCompleted(int)) ); + mAbstractDelegate->exec(list); + } + else { + setPrevVisibilityMode(); + } + +} + +void BtCpUiMainView::setPrevVisibilityMode() +{ + bool ret(false); + + //Should we notify this error to user..? + HbNotificationDialog::launchDialog(hbTrId("Error")); + QModelIndex index = mModel.index( BtuiModel::LocalSettingRow, BtuiModel::VisibilityCol ); + + ret = disconnect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), + this, SLOT(visibilityChanged (int))); + BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't disconnect signal" ); + + mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode) + mModel.data(index,BtuiModel::SettingValue).toInt()) ); + + //Handle Visibility Change User Interaction + ret = connect(mVisibilityMode, SIGNAL(currentIndexChanged (int)), + this, SLOT(visibilityChanged (int))); + BTUI_ASSERT_X( ret, "BtCpUiMainView::setPrevVisibilityMode", "can't connect signal" ); + +} + + +void BtCpUiMainView::visibilityDelegateCompleted(int status) +{ + + //This should be mapped to Qt error + if(KErrNone != status) { + setPrevVisibilityMode(); + } + + //Error handling has to be done. + if (mAbstractDelegate) + { + disconnect(mAbstractDelegate); + delete mAbstractDelegate; + mAbstractDelegate = 0; + } + +} + + +// called due to real orientation change event coming from main window +void BtCpUiMainView::changeOrientation( Qt::Orientation orientation ) +{ + bool ok = false; + mOrientation = orientation; + if( orientation == Qt::Vertical ) { + // load "portrait" section + mLoader->load( BTUI_MAINVIEW_DOCML, "portrait", &ok ); + BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: portrait section problem" ); + } else { + // load "landscape" section + mLoader->load( BTUI_MAINVIEW_DOCML, "landscape", &ok ); + BTUI_ASSERT_X( ok, "bt-main-view", "Invalid docml file: landscape section problem" ); + } +} + +void BtCpUiMainView::commandCompleted( int cmdId, int err, const QString &diagnostic ) +{ + Q_UNUSED(cmdId); + Q_UNUSED(err); + Q_UNUSED(diagnostic); + +} + +/*! + Slot for receiving notification of data changes from the model. + Identify the setting changed and update the corresponding UI item. + */ +void BtCpUiMainView::updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight) +{ + + // update only the part of the view specified by the model's row(s) + + for (int i=topLeft.column(); i <= bottomRight.column(); i++) { + QModelIndex index = mModel.index( BtuiModel::LocalSettingRow, i); + // Distinguish which setting value is changed. + switch ( i ) { + case BtuiModel::BluetoothNameCol : + mDeviceNameEdit->setText( mModel.data(index,BtuiModel::settingDisplay).toString() ); + break; + case BtuiModel::PowerStateCol: + mPowerButton->setText( mModel.data(index,BtuiModel::settingDisplay).toString() ); + break; + case BtuiModel::VisibilityCol: + mVisibilityMode->setCurrentIndex ( visibilityModeToIndex((VisibilityMode) + mModel.data(index,BtuiModel::SettingValue).toInt()) ); + break; + } + } + + +} + +/*! + Slot for receiving notification for user interaction on power state. + Manually update model data since HbPushButton is not linked to model directly. + */ +void BtCpUiMainView::changePowerState() +{ + + QModelIndex index = mModel.index(BtuiModel::LocalSettingRow, BtuiModel::PowerStateCol); + QVariant powerState = mModel.data(index, Qt::EditRole); + if (!mAbstractDelegate)//if there is no other delegate running + { + mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, mModel); + connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) ); + mAbstractDelegate->exec(powerState); + } + +} + +void BtCpUiMainView::powerDelegateCompleted(int status) +{ + Q_UNUSED(status); + //ToDo: Error handling here + if (mAbstractDelegate) + { + disconnect(mAbstractDelegate); + delete mAbstractDelegate; + mAbstractDelegate = 0; + } + //BTUI_ASSERT_X( status, "bt-main-view", "error in delegate complete" ); +} + +/*! + * Mapping from visibility mode UI row to VisibilityMode + */ +VisibilityMode BtCpUiMainView::indexToVisibilityMode(int index) +{ + VisibilityMode mode; + switch(index) { + case UiRowBtHidden: + mode = BtHidden; + break; + case UiRowBtVisible: + mode = BtVisible; + break; + case UiRowBtTemporary: + mode = BtTemporary; + break; + default: + mode = BtUnknown; + } + return mode; +} + +/*! + * Mapping from VisibilityMode to visibility mode UI row + */ +int BtCpUiMainView::visibilityModeToIndex(VisibilityMode mode) +{ + int uiRow; + switch(mode) { + case BtHidden: + uiRow = UiRowBtHidden; + break; + case BtVisible: + uiRow = UiRowBtVisible; + break; + case BtTemporary: + uiRow = UiRowBtTemporary; + break; + default: + uiRow = -1; // error + } + return uiRow; +} +////////////////////// +// +// from view manager +// +////////////////////// + +/*! + Create views(main view, device view and search view). + Add them to MainWindow. All views are long-lived and are deleted only when exiting the application + (or when main view is deleted). + */ +void BtCpUiMainView::createViews() +{ + Qt::Orientation orientation = mMainWindow->orientation(); + // Create other views + mSearchView = new BtCpUiSearchView( mModel, this ); + mMainWindow->addView(mSearchView); + mDeviceView = 0; // ToDo: add this later + + mCurrentView = this; + mCurrentViewId = MainView; + + + // QList stores the previous view ids for each view. + for( int i=0; i < LastView; i++ ) { + mPreviousViewIds.append( 0 ); + } +} + +/*! + Switch between the views. + Parameter cmdId is used for automatically executing command. + Parameter "value" is optional except for GadgetView, + which needs the BT address (QString) + */ +void BtCpUiMainView::changeView(int targetViewId, bool fromBackButton, + int cmdId, const QVariant& value ) +{ + mCurrentView->deactivateView(); + + // update the previous view Id in QList + // If launching the target view from back softkey, + // the previous viewId of target view should not be changed. + // Otherwise, loop happens between two views. + if(!fromBackButton) { + if ((targetViewId == DeviceView) && (mCurrentViewId == SearchView)) { + // we don't want to return to search view after e.g. pairing a new device + mPreviousViewIds[ targetViewId ] = MainView; + } + else { + // normal case: return to previous view + mPreviousViewIds[ targetViewId ] = mCurrentViewId; + } + } + + // set the new current view + mCurrentView = idToView(targetViewId); + mCurrentViewId = targetViewId; + mMainWindow->setCurrentView( mCurrentView ); + + // do preparation or some actions when new view is activated + mCurrentView->activateView( value, cmdId ); +} + + +BtCpUiBaseView * BtCpUiMainView::idToView(int targetViewId) +{ + switch (targetViewId) { + case MainView: + return mMainView; + case SearchView: + return mSearchView; + case DeviceView: + return mDeviceView; + default : + BTUI_ASSERT_X(false, "BtCpUiMainView::idToView", "invalid view id"); + } + return 0; +} + +/* + Jump to previous view. This function is used when back button is pressed. + */ +void BtCpUiMainView::switchToPreviousViewReally() +{ + // jump to previous view of current view. + if( (mCurrentViewId >= 0) && (mCurrentViewId < LastView)) { + changeView( mPreviousViewIds[mCurrentViewId], true, 0 ); + } + else { + BTUI_ASSERT_X(false, "BtCpUiMainView::switchToPreviousViewReally", "invalid view id"); + } +} + + +void BtCpUiMainView::setSoftkeyBack() +{ + +} + +void BtCpUiMainView::switchToPreviousView() +{ + +} + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpuimainview.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpuimainview.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,120 @@ +/* +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Main View of BT Application +* +*/ + +#ifndef BTCPUIMAINVIEW_H +#define BTCPUIMAINVIEW_H + +#include "btcpuibaseview.h" +#include +#include + +class HbLabel; +class HbLineEdit; +class HbPushButton; +class HbIcon; +class HbComboBox; +class HbDocumentLoader; +class HbGridView; +class BtAbstractDelegate; + + +class BtCpUiMainView : public BtCpUiBaseView +{ + Q_OBJECT + +public: + enum ViewIndex { + MainView, + SearchView, + DeviceView, + LastView + }; + explicit BtCpUiMainView( BtuiModel &model, QGraphicsItem *parent = 0 ); + ~BtCpUiMainView(); + // from view manager + void createViews(); + + Qt::Orientation orientation(); + + // from base class BtCpUiBaseView + virtual void setSoftkeyBack(); + virtual void activateView( const QVariant& value, int cmdId ); + virtual void deactivateView(); + +public slots: + void commandCompleted( int cmdId, int err, const QString &diagnostic ); + void changeOrientation( Qt::Orientation orientation ); + void itemActivated(QModelIndex index); + void changePowerState(); + void updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight); + + void goToDiscoveryView(); + + // from view manager + void changeView(int targetViewId, bool fromBackButton, int cmdId, const QVariant& value = 0 ); + void switchToPreviousViewReally(); + virtual void switchToPreviousView(); + + void visibilityChanged (int index); + void changeBtLocalName(); + + //from delegate classes + void powerDelegateCompleted(int status); + void visibilityDelegateCompleted(int status); + void btNameDelegateCompleted(int status, QVariant param); + +protected: + + +private: + VisibilityMode indexToVisibilityMode(int index); + int visibilityModeToIndex(VisibilityMode mode); + BtCpUiBaseView * idToView(int targetViewId); + + //Functions to set the Previous Local settings in case of error + void setPrevBtLocalName(); + void setPrevVisibilityMode(); + +private: + QAbstractItemModel* mSubModel; + HbDocumentLoader *mLoader; + HbLineEdit *mDeviceNameEdit; + HbPushButton *mPowerButton; + HbComboBox *mVisibilityMode; + QStringListModel *mVisiListModel; + HbGridView *mDeviceList; + + // data structures for switching between views + bool mEventFilterInstalled; + int mAutoCmdId; + Qt::Orientation mOrientation; + + // from view manager + HbMainWindow* mMainWindow; + BtCpUiBaseView* mMainView; + BtCpUiBaseView* mDeviceView; + BtCpUiBaseView* mSearchView; + BtCpUiBaseView* mCurrentView; + int mCurrentViewId; + HbAction *mBackAction; + QList mPreviousViewIds; + + //poiter to abstract delegate, and it is instantiated at runtime + BtAbstractDelegate* mAbstractDelegate; + +}; +#endif // BTCPUIMAINVIEW_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpuisearchview.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + +#include "btcpuisearchview.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "btcpuimainview.h" + + + +// docml to load +const char* BTUI_SEARCHVIEW_DOCML = ":/docml/bt-search-view.docml"; + +BtCpUiSearchView::BtCpUiSearchView(BtuiModel &model, QGraphicsItem *parent) : + BtCpUiBaseView(model,parent) +/*{ + mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); + BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action"); + + QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout( Qt::Vertical, this ); + // create button + HbPushButton *button = new HbPushButton(this); + button->setText("Press Me"); + button->setMaximumSize(150,50); + mainLayout->addItem(button); + +// (void) connect(button, SIGNAL(clicked()), this, SLOT(changePowerState())); + + setLayout(mainLayout); + + // create dummy options menu + HbMenu *optionsMenu = new HbMenu(); + HbAction *openGadgetGallery = optionsMenu->addAction("Open Device Gallery"); +// connect(openGadgetGallery, SIGNAL(triggered()), this, SLOT(openGadgetGalleryView())); + HbAction *openNewMainView = optionsMenu->addAction("Open new Main View"); +// connect(openNewMainView, SIGNAL(triggered()), this, SLOT(openNewMainView())); + setMenu(optionsMenu); + +}*/ + +{ + //bool ret(false); + + mSearchView = this; + mMainView = (BtCpUiMainView *) parent; + + mMainWindow = hbInstance->allMainWindows().first(); + + mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); + BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action"); + + + // read view info from docml file + + + // Create view for the application. + // Set the name for the view. The name should be same as the view's + // name in docml. + setObjectName("bt_search_view"); + + QObjectList objectList; + objectList.append(this); + // Pass the view to documentloader. Document loader uses this view + // when docml is parsed, instead of creating new view. + mLoader = new HbDocumentLoader(); + mLoader->setObjectTree(objectList); + + bool ok = false; + mLoader->load( BTUI_SEARCHVIEW_DOCML, &ok ); + // Exit if the file format is invalid + BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file" ); + + // Set title for the control panel + // ToDo: check if deprecated API + setTitle("Control Panel"); + + // assign automatically created widgets to local variables + + mDeviceIcon=0; + // can't use qobject_cast since HbIcon is not derived from QObject! + mDeviceIcon = qobject_cast( mLoader->findWidget( "icon" ) ); + BTUI_ASSERT_X( mDeviceIcon != 0, "bt-search-view", "Device Icon not found" ); + + mDeviceName=0; + mDeviceName = qobject_cast( mLoader->findWidget( "label_found_devices" ) ); + BTUI_ASSERT_X( mDeviceName != 0, "bt-search-view", "Device Name not found" ); + + mDeviceList=0; + mDeviceList = qobject_cast( mLoader->findWidget( "deviceList" ) ); + BTUI_ASSERT_X( mDeviceList != 0, "bt-search-view", "Device List not found" ); + + +// // set model to list view +// mDeviceList->setModel( mFilterProxy ); +// // define settings for list view +// mDeviceList->setSelectionMode(HbAbstractItemView::SingleSelection); +// // set prototype item for list view +// BtUiDevListGridItem *item = new BtUiDevListGridItem( mDeviceList ); +// mDeviceList->setItemPrototype(item); +// // connect to list view pressed signal +// ret = connect( mDeviceList, SIGNAL(pressed(QModelIndex)),this, SLOT(itemActivated(QModelIndex)) ); +// BTUI_ASSERT_X( ret, "bt-search-view", "device list can't connect" ); + + // read landscape orientation section from docml file if needed +// mOrientation = ((BTUIViewManager*)parent)->orientation(); + mOrientation = Qt::Vertical; + if (mOrientation == Qt::Horizontal) { + mLoader->load(BTUI_SEARCHVIEW_DOCML, "landscape", &ok); + BTUI_ASSERT_X( ok, "bt-search-view", "Invalid docml file: landscape section problem" ); + } + + + // load tool bar actions + HbAction *viewByAction = static_cast( mLoader->findObject( "viewByAction" ) ); + BTUI_ASSERT_X( viewByAction, "bt-search-view", "view by action missing" ); +// ret = connect(viewByAction, SIGNAL(triggered()), this, SLOT(noOp())); +// BTUI_ASSERT_X( ret, "bt-search-view", "viewByAction can't connect" ); + + HbAction *stopAction = static_cast( mLoader->findObject( "stopAction" ) ); + BTUI_ASSERT_X( stopAction, "bt-search-view", "view by action missing" ); +// ret = connect(stopAction, SIGNAL(triggered()), this, SLOT(noOp())); +// BTUI_ASSERT_X( ret, "bt-search-view", "stopAction can't connect" ); + + HbAction *retryAction = static_cast( mLoader->findObject( "retryAction" ) ); + BTUI_ASSERT_X( retryAction, "bt-search-view", "view by action missing" ); +// ret = connect(retryAction, SIGNAL(triggered()), this, SLOT(noOp())); +// BTUI_ASSERT_X( ret, "bt-search-view", "retryAction can't connect" ); + + + // load menu + HbMenu *optionsMenu = qobject_cast(mLoader->findWidget("viewMenu")); + BTUI_ASSERT_X( optionsMenu != 0, "bt-search-view", "Options menu not found" ); + this->setMenu(optionsMenu); + + + // update display when setting data changed +// ret = connect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), +// this, SLOT(updateSettingItems(QModelIndex,QModelIndex))); +// BTUI_ASSERT_X( ret, "BtCpUiSearchView::BtCpUiSearchView", "can't connect dataChanged" ); + +// QModelIndex top = mModel->index( Btuim::LocalDeviceName, KDefaultColumn ); +// QModelIndex bottom = mModel->index( Btuim::Visibility, KDefaultColumn ); +// // update name, power and visibility rows +// updateSettingItems( top, bottom ); + + +} + +BtCpUiSearchView::~BtCpUiSearchView() +{ + setNavigationAction(0); + delete mSoftKeyBackAction; +} + +void BtCpUiSearchView::deviceSelected(const QModelIndex& modelIndex) +{ + int row = modelIndex.row(); +} + +void BtCpUiSearchView::setSoftkeyBack() +{ + if (navigationAction() != mSoftKeyBackAction) { + setNavigationAction(mSoftKeyBackAction); + connect( mSoftKeyBackAction, SIGNAL(triggered()), this, SLOT(switchToPreviousView()) ); + } +} + +void BtCpUiSearchView::switchToPreviousView() +{ + BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView"); + // jump to previous view of current view. + mSearchView->deactivateView(); + + // set the new current view + mMainWindow->setCurrentView( mMainView ); + + // do preparation or some actions when new view is activated + mMainView->activateView( 0, 0 ); + +} + +void BtCpUiSearchView::activateView( const QVariant& value, int cmdId ) +{ + Q_UNUSED(value); + Q_UNUSED(cmdId); + + setSoftkeyBack(); +} + +void BtCpUiSearchView::deactivateView() +{ +} diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpuisearchview.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpuisearchview.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + +#ifndef BTCPUISEARCHVIEW_H +#define BTCPUISEARCHVIEW_H + +#include +#include +#include +#include "btcpuibaseview.h" + +class HbLabel; +class HbPushButton; +class HbIcon; +class HbDocumentLoader; +class HbListView; +class HbDataFormModel; +class HbDataFormModelItem; +class CpSettingFormItemData; + + +class BtCpUiSearchView : public BtCpUiBaseView +{ + Q_OBJECT + +public: + explicit BtCpUiSearchView(BtuiModel &model, QGraphicsItem *parent = 0); + virtual ~BtCpUiSearchView(); + virtual void activateView( const QVariant& value, int cmdId ); + virtual void deactivateView(); + virtual void setSoftkeyBack(); + +public slots: + void deviceSelected(const QModelIndex& modelIndex); + virtual void switchToPreviousView(); + +private: + HbDocumentLoader *mLoader; + HbLabel *mDeviceIcon; + HbLabel *mDeviceName; + HbListView *mDeviceList; + + // data structures for switching between views + bool mEventFilterInstalled; + int mAutoCmdId; + Qt::Orientation mOrientation; + + HbMainWindow* mMainWindow; + BtCpUiBaseView* mMainView; + BtCpUiBaseView* mSearchView; + HbAction *mSoftKeyBackAction; +// CpCustomLabelViewItem* mLabelItem; +// CpCustomListViewItem* mListItem; + HbToolBar* mToolBar; + HbAction* mViewBy; + HbAction* mStop; + HbAction* mRetry; + HbDataFormModel* mModel; +}; + +#endif// BTCPUISEARCHVIEW_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpuisettingitem.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpuisettingitem.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + +#include "btcpuisettingitem.h" +#include + +#include + +BtCpUiSettingItem::BtCpUiSettingItem(CpItemDataHelper &itemDataHelper, + const QString &text /*= QString()*/, + const QString &description /*= QString()*/, + const HbIcon &icon /*= HbIcon()*/, + const HbDataFormModelItem *parent /*= 0*/) + : CpSettingFormEntryItemData(itemDataHelper, + text, + description, + icon, + parent) +{ +} + +BtCpUiSettingItem::~BtCpUiSettingItem() +{ + +} + +void BtCpUiSettingItem::onLaunchView() +{ + mModel = new BtuiModel(); + + mMainWindow = hbInstance->allMainWindows().first(); + + mBtMainView = new BtCpUiMainView(*mModel); + + mCpView = mMainWindow->currentView(); + + mMainWindow->addView(mBtMainView); + mMainWindow->setCurrentView(mBtMainView); + + connect(mBtMainView, SIGNAL(aboutToClose()), this, SLOT(handleCloseView())); + +} + +void BtCpUiSettingItem::handleCloseView() +{ + mBtMainView->deactivateView(); + mMainWindow->setCurrentView(mCpView); + delete mBtMainView; + delete mModel; +} + + +CpBaseSettingView *BtCpUiSettingItem::createSettingView() const +{ + return 0; +} diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/btcpuisettingitem.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/btcpuisettingitem.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0"" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + +#ifndef BTCPUISETTINGITEM_H +#define BTCPUISETTINGITEM_H + +#include +#include + +#include "btcpuimainview.h" + +class BtCpUiSettingItem : public CpSettingFormEntryItemData +{ + Q_OBJECT +public: + explicit BtCpUiSettingItem(CpItemDataHelper &itemDataHelper, + const QString &text = QString(), + const QString &description = QString(), + const HbIcon &icon = HbIcon(), + const HbDataFormModelItem *parent = 0); + virtual ~BtCpUiSettingItem(); +private slots: + void onLaunchView(); + void handleCloseView(); +private: + virtual CpBaseSettingView *createSettingView() const; + +private: + HbMainWindow* mMainWindow; + + BtCpUiMainView *mBtMainView; + + //Owns this model. + BtuiModel *mModel; + + HbView *mCpView; + +}; + +#endif //BTCPUISETTINGITEM_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/docml/bt-main-view.docml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/docml/bt-main-view.docml Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/docml/bt-search-view.docml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/docml/bt-search-view.docml Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + + + +
diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_frwidget_add_friend_photo.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_frwidget_add_friend_photo.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_graf_blid_det_circle.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_graf_blid_det_circle.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_graf_blid_time.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_graf_blid_time.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_indi_bt_blocked.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_indi_bt_blocked.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_indi_bt_paired_add.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_indi_bt_paired_add.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_indi_bt_trusted_add.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_indi_bt_trusted_add.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_audio.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_audio.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_blocked_tab3.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_blocked_tab3.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_car_kit.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_car_kit.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_carkit.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_carkit.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_computer.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_computer.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_connected.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_connected.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,7 @@ + + + + + + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_headset.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_headset.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_keyboard.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_keyboard.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_misc.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_misc.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_mouse.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_mouse.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,10 @@ + + + + + + + + + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_phone.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_phone.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_printer.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_printer.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_unknown.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btcpplugin/icons/qgn_prop_bt_unknown.svg Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btui.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btui.pro Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,33 @@ +# +# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# + + +TEMPLATE = subdirs + +# Directories +SUBDIRS += btuimodel \ +btuidelegate \ +btcpplugin \ +tsrc + +CONFIG += ordered + +symbian: { + + BLD_INF_RULES.prj_exports += \ + "$${LITERAL_HASH}include" \ + "rom/btui.iby CORE_MW_LAYER_IBY_EXPORT_PATH(btui.iby)" +} \ No newline at end of file diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btabstractdelegate.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btabstractdelegate.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "btabstractdelegate.h" +#include "btuimodel.h" + +/*! + Constructor. + */ +BtAbstractDelegate::BtAbstractDelegate( BtuiModel& model, QObject *parent ) + : QObject( parent ), mModel(model) +{ +} + +/*! + Destructor. + */ +BtAbstractDelegate::~BtAbstractDelegate() +{ +} + +BtuiModel &BtAbstractDelegate::model() +{ + return mModel; +} diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btabstractdelegate.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btabstractdelegate.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTABSTRACTDELEGATE_H +#define BTABSTRACTDELEGATE_H + +#include +#include + +class BtuiModel; + +#ifdef BUILD_BTUIDELEGATE +#define BTUIDELEGATE_IMEXPORT Q_DECL_EXPORT +#else +#define BTUIDELEGATE_IMEXPORT Q_DECL_IMPORT +#endif + + +/*! + \class BtAbstractDelegate + \brief the base class for handling user requests from BT application. + + + \\sa btuidelegate + */ +class BTUIDELEGATE_IMEXPORT BtAbstractDelegate : public QObject +{ + Q_OBJECT + +public: + explicit BtAbstractDelegate( BtuiModel& model, QObject *parent = 0 ); + + virtual ~BtAbstractDelegate(); + + virtual void exec( const QVariant ¶ms ) = 0; + +signals: + void commandCompleted(int status, QVariant params = QVariant() ); + +protected: + + BtuiModel &model(); + +public slots: + +private: + + BtuiModel& mModel; + + Q_DISABLE_COPY(BtAbstractDelegate) + +}; + +#endif // BTABSTRACTDELEGATE_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btdelegateconsts.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegateconsts.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTDELEGATECONSTS_H +#define BTDELEGATECONSTS_H + +#include + +namespace BtDelegate + { + enum Command + { + Undefined, + ManagePower, + DeviceName, + Visibility, + }; + } + +#endif // BTDELEGATECONSTS_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btdelegatedevname.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatedevname.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "btdelegatedevname.h" +#include "btuimodel.h" +#include +#include + +BtDelegateDevName::BtDelegateDevName( BtuiModel& model, QObject *parent ) : + BtAbstractDelegate( model, parent ) +{ + TRAP_IGNORE( mBtEngSettings = CBTEngSettings::NewL() ); + Q_CHECK_PTR( mBtEngSettings ); + +} + +BtDelegateDevName::~BtDelegateDevName() +{ + delete mBtEngSettings; +} + +/*! + Validate the bluetooth device name given by the user: + Extra spaces (' ', '\n', '\t' and '\r') from the beginning, + middle and the end of the name are always removed; + the maximum lengthof a name is 30. + */ +bool BtDelegateDevName::validateName(QString &name ) +{ + // remove spaces at the beginning and end: + name = name.trimmed(); + // regular expression of one or more consecutive spaces: + QRegExp rx("[ \n\t\r]+"); + name.replace( rx, " "); + if (name.length() > 30 ) { + name.resize( 30 ); + } + return name.length() > 0; +} + +void BtDelegateDevName::exec( const QVariant ¶ms ) +{ + int error = KErrNone; + QString btDevName = params.toString(); + + validateName(btDevName); + + TPtrC ptrName(reinterpret_cast(btDevName.constData())); + + RBuf16 btName; + error = btName.Create(ptrName.Length()); + + if(error == KErrNone) { + btName.Copy(ptrName); + error = mBtEngSettings->SetLocalName(btName); + btName.Close(); + } + + emit commandCompleted(error, btDevName); +} + + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btdelegatedevname.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatedevname.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTDELEGATEDEVNAME_H +#define BTDELEGATEDEVNAME_H + +#include +#include +#include "btabstractdelegate.h" + +class BtuiModel; + +/*! + \class BtDelegateDevName + \brief the base class for handling Bluetooth Local Name. + */ +class BtDelegateDevName : public BtAbstractDelegate +{ + Q_OBJECT + +public: + explicit BtDelegateDevName( BtuiModel& model, QObject *parent = 0 ); + + virtual ~BtDelegateDevName(); + + virtual void exec( const QVariant ¶ms ); + +public slots: + +private: + bool validateName(QString &name ); + + CBTEngSettings* mBtEngSettings; + +private: + + Q_DISABLE_COPY(BtDelegateDevName) + +}; + +#endif // BTDELEGATEDEVNAME_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btdelegatefactory.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatefactory.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "btdelegatefactory.h" +#include "btdelegatepower.h" +#include "btuimodel.h" +#include "btdelegatedevname.h" +#include "btdelegatevisibility.h" + + +/*! + Constructor. + */ +BtAbstractDelegate * BtDelegateFactory::newDelegate( + BtDelegate::Command cmd, BtuiModel& model, QObject *parent ) +{ + switch ( cmd ) { + case BtDelegate::ManagePower: + return new BtDelegatePower( model, parent ); + case BtDelegate::DeviceName: + return new BtDelegateDevName( model, parent ); + case BtDelegate::Visibility: + return new BtDelegateVisibility( model, parent ); + } + return 0; +} + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btdelegatefactory.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatefactory.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTDELEGATEFACTORY_H +#define BTDELEGATEFACTORY_H + +#include +#include "btdelegateconsts.h" + +class BtAbstractDelegate; +class BtuiModel; + +#ifdef BUILD_BTUIDELEGATE +#define BTUIDELEGATE_IMEXPORT Q_DECL_EXPORT +#else +#define BTUIDELEGATE_IMEXPORT Q_DECL_IMPORT +#endif + +/*! + \class BtDelegateFactory + \brief the base class for creating concrete delegate instances + + \\sa btuidelegate + */ +class BTUIDELEGATE_IMEXPORT BtDelegateFactory +{ + +public: + static BtAbstractDelegate *newDelegate( + BtDelegate::Command cmd, BtuiModel& model, QObject *parent = 0 ); + +}; + +#endif // BTDELEGATEFACTORY_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btdelegatepower.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatepower.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,223 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "btdelegatepower.h" +#include "btuimodel.h" +#include +#include +#include + +/*! + Constructor. + */ +BtDelegatePower::BtDelegatePower( BtuiModel& model, QObject *parent ) + : BtAbstractDelegate( model, parent ) +{ + TRAP_IGNORE( mBtengSettings = CBTEngSettings::NewL(this) ); + Q_CHECK_PTR( mBtengSettings ); + +} + +/*! + Destructor. + */ +BtDelegatePower::~BtDelegatePower() +{ + delete mBtengSettings; + +} + +void BtDelegatePower::exec( const QVariant ¶ms ) +{ + if (params.toInt()){//turn power OFF + + switchBTOff(); + } + else{//turn power ON + + switchBTOn(); + } +} + + + +void BtDelegatePower::switchBTOn() +{ + int err = 0; + + //check if device is in OFFLINE mode first + TBTEnabledInOfflineMode enabledInOffline = EBTDisabledInOfflineMode; + if (checkOfflineMode(enabledInOffline)){ + //if (1){ + if (enabledInOffline){ + //if (1){ + // BT is allowed to be enabled in offline mode, show query. + HbMessageBox::question( tr("Turn Bluetooth on in offline mode?"),this, SLOT(btOnQuestionClose(HbAction*))); + + } + else{ + //if BT is not allowed to be enabled in offline mode, show message and complete + HbMessageBox::warning(tr("Bluetooth not allowed to be turned on in offline mode"),this, SLOT(btOnWarningClose())); + } + + } + else{ + //set BT on if the not in offline mode + err = mBtengSettings->SetPowerState((TBTPowerStateValue)(1)); + } + + if ( err ) { + QString info = "Unable to switch BT power ON" ; + emit commandCompleted(KErrGeneral); + } + +} + +void BtDelegatePower::btOnQuestionClose(HbAction *action) +{ + HbMessageBox *dlg = static_cast(sender()); + int err = 0; + if(action == dlg->actions().at(0)) + { + //user chooses "yes" for using BT in offline + err = mBtengSettings->SetPowerState((TBTPowerStateValue)(1)); + } + else + { + //if user chooses "NO", emits the signal + emit commandCompleted(KErrNone); + + } + if ( err ) { + QString info = "Unable to switch BT power ON" ; + emit commandCompleted(KErrGeneral); + } +} + +void BtDelegatePower::btOnWarningClose() +{ + emit commandCompleted(KErrNone); +} + + + +void BtDelegatePower::switchBTOff() +{ + int err = 0; + err = mBtengSettings->SetPowerState((TBTPowerStateValue)(0)); + + if ( err ) { + QString info = "Unable to switch BT power OFF" ; + emit commandCompleted(KErrGeneral); + } + +} + +void BtDelegatePower::btOffDialogClose(HbAction *action) +{ + Q_UNUSED( action ); + +} + +void BtDelegatePower::PowerStateChanged( TBTPowerStateValue aState ) +{ + Q_UNUSED( aState ); + emit commandCompleted(KErrNone); +} + +//Method derived from MBTEngSettingsObserver, no need to be implemented here +void BtDelegatePower::VisibilityModeChanged( TBTVisibilityMode aState ) +{ + Q_UNUSED( aState ); +} + +bool BtDelegatePower::checkOfflineMode(TBTEnabledInOfflineMode& aEnabledInOffline) +{ + TCoreAppUIsNetworkConnectionAllowed offline = ECoreAppUIsNetworkConnectionAllowed; + + mBtengSettings->GetOfflineModeSettings(offline, aEnabledInOffline); + return (!offline); + +} + +/*if (params.toBool()) { // turning power on + + // find out if local device is in offline mode + QModelIndex idx = mModel->index( Btuim::OfflineMode, 0); + QVariant var = mModel->data( idx, Qt::EditRole ); + bool offlineMode = var.toBool(); + + // find out whether BT is allowed in offline mode + var = mModel->data( idx, Btuim::SettingAdditionalParam ); + bool activationAllowed = var.toBool(); + + if (offlineMode) { + // in offline mode + if (activationAllowed) { + HbMessageBox *messageBox = new HbMessageBox(); + // BT is allowed to be enabled in offline mode, show query. + if (messageBox->question( tr("Activate Bluetooth in offline mode?") )) { + ret = mModel->setData(index, value, role); + } + delete messageBox; + } + else { + // BT is not allowed to be activated in offline mode, show note. + + HbDialog *mShowOnlyPopup = new HbDialog(); + mShowOnlyPopup->setAttribute(Qt::WA_DeleteOnClose); + mShowOnlyPopup->setModal(false); + mShowOnlyPopup->setBackgroundFaded(false); + mShowOnlyPopup->setDismissPolicy( HbPopup::NoDismiss ); + mShowOnlyPopup->setTimeout( 5000 ); // 5 sec + HbLabel *label = new HbLabel( tr("Bluetooth is not allowed in offline mode") ); + label->setAlignment(Qt::AlignCenter); + QSizeF popupSize(350,100); + mShowOnlyPopup->setMinimumSize(popupSize); + mShowOnlyPopup->setContentWidget(label); + mShowOnlyPopup->show(); + } + } + else { + // not in offline mode, forward the request to model. + ret = mModel->setData(index, value, role); + } + } + else { // turning power off + // first check if existing connections + QModelIndex idx = mModel->index(Btuim::BtConnections, 0); + QVariant var = mModel->data(idx, Qt::EditRole); + bool ok; + TInt connNum = var.toInt( &ok ); + BTUI_ASSERT_X( ok, "BtUiSettingsDelegate::setData", "wrong qvariant type"); + if (connNum) { + // there is at least 1 active connection, show query. + HbMessageBox *messageBox = new HbMessageBox(); + if (messageBox->question( tr("Turn Bluetooth off even though connections exist?") )) { + ret = mModel->setData(index, value, role); + } + delete messageBox; + } + else { + // no active connections exist, forward the request to model. + ret = mModel->setData(index, value, role); + } + }*/ + //emit commandCompleted(err); + //return ret; + //return false; diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btdelegatepower.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatepower.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTDELEGATEPOWER_H +#define BTDELEGATEPOWER_H + +#include +#include +#include "btabstractdelegate.h" + +class BtuiModel; +class HbAction; + +/*! + \class BtDelegatePower + \brief the base class for handling Bluetooth power management. + + \\sa btuidelegate + */ +class BtDelegatePower : public BtAbstractDelegate, public MBTEngSettingsObserver +{ + Q_OBJECT + +public: + explicit BtDelegatePower( BtuiModel& model, QObject *parent = 0 ); + + virtual ~BtDelegatePower(); + + virtual void exec( const QVariant ¶ms ); + + virtual void PowerStateChanged( TBTPowerStateValue aState ); + + virtual void VisibilityModeChanged( TBTVisibilityMode aState ); + +public slots: + void btOnQuestionClose(HbAction *action); + + void btOnWarningClose(); + + void btOffDialogClose(HbAction *action); + +private: + void switchBTOn(); + + void switchBTOff(); + + bool checkOfflineMode(TBTEnabledInOfflineMode& aEnabledInOffline); + +public slots: + +private: + CBTEngSettings* mBtengSettings; + +private: + + Q_DISABLE_COPY(BtDelegatePower) + +}; + +#endif // BTDELEGATEPOWER_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btdelegatevisibility.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatevisibility.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,129 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Delegate class for setting visibility mode +* +*/ + + +#include "btdelegatevisibility.h" +#include "btuimodel.h" +#include +#include "btqtconstants.h" +#include + +const int MAX_TEMPORARY_VISIBILITY = 60; // minutes, this value comes from the UI spec + +/*! + Constructor. + */ +BtDelegateVisibility::BtDelegateVisibility( BtuiModel& model, QObject *parent ) + : BtAbstractDelegate( model, parent ) +{ + TRAP_IGNORE( mBtengSettings = CBTEngSettings::NewL(this) ); + Q_CHECK_PTR( mBtengSettings ); + mOperationOngoing = false; +} + +/*! + Destructor. + */ +BtDelegateVisibility::~BtDelegateVisibility() +{ + delete mBtengSettings; +} +/*! + * executes visibility delegate functionality, ie. calls CBTEngSettings to set the visibility mode; + * when operation completes, emits commandCompleted signal + * Parameters: Qlist where first item is VisibilityMode integer specifying operation; + * for BtTemporary a 2nd parameter is give which signifies the number of minutes to stay visible. + */ +void BtDelegateVisibility::exec( const QVariant ¶ms ) +{ + int minutes, err = 0; + + if (mOperationOngoing) { + // complete command with error + emit commandCompleted(KErrInUse); + return; + } + mOperationOngoing = true; + + // read 1st parameter + BTUI_ASSERT_X(params.toList().at(0).isValid(), "BtDelegateVisibility::exec", "invalid parameter"); + VisibilityMode btQtMode = (VisibilityMode)params.toList().at(0).toInt(); + mOperation = BtEngVisibilityMode(btQtMode); + + // verify that we are setting visibility to a new value, otherwise we won't get a callback + TBTVisibilityMode visibilityMode( EBTVisibilityModeNoScans ); + err = mBtengSettings->GetVisibilityMode( visibilityMode ); + if (err) { + mOperationOngoing = false; + emit commandCompleted(err); + return; + } + if (visibilityMode == mOperation) { + mOperationOngoing = false; + emit commandCompleted(KErrNone); + return; + } + + switch (mOperation) { + case EBTVisibilityModeGeneral : + err = mBtengSettings->SetVisibilityMode(mOperation, 0); + break; + case EBTVisibilityModeHidden: + err = mBtengSettings->SetVisibilityMode(mOperation, 0); + break; + case EBTVisibilityModeTemporary: + BTUI_ASSERT_X(params.toList().at(1).isValid(), "BtDelegateVisibility::exec", "invalid time parameter"); + minutes = params.toList().at(1).toInt(); + BTUI_ASSERT_X(((minutes >= 0 ) && (minutes <= MAX_TEMPORARY_VISIBILITY)), + "BtDelegateVisibility::exec", "invalid time parameter"); + err = mBtengSettings->SetVisibilityMode(mOperation, minutes); + break; + default: + // error + BTUI_ASSERT_X(false, "BtDelegateVisibility::exec", "invalid parameter"); + } + if (err) { + // complete command with error + mOperationOngoing = false; + emit commandCompleted(err); + } +} + +void BtDelegateVisibility::PowerStateChanged( TBTPowerStateValue aState ) +{ + Q_UNUSED( aState ); +} + +/*! + * callback from BtEngine + * emits command complete with either: + * 1) KErrUnknown if something went wrong, or + * 2) KErrNone if everything ok + */ +void BtDelegateVisibility::VisibilityModeChanged( TBTVisibilityMode aState ) +{ + if (mOperationOngoing) { + //Error handling has to be done, if value is not set properly. + mOperationOngoing = false; + if (mOperation == aState) { + emit commandCompleted(KErrNone); + } + else { + emit commandCompleted(KErrUnknown); + } + } +} diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btdelegatevisibility.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btdelegatevisibility.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTDELEGATEVISIBILITY_H +#define BTDELEGATEVISIBILITY_H + +#include +#include +#include "btabstractdelegate.h" + +class BtuiModel; + +/*! + \class BtDelegateVisibility + \brief the base class for handling Bluetooth visibility management. + + \\sa btuidelegate + */ +class BtDelegateVisibility : public BtAbstractDelegate, public MBTEngSettingsObserver +{ + Q_OBJECT + +public: + explicit BtDelegateVisibility( BtuiModel& model, QObject *parent = 0 ); + + virtual ~BtDelegateVisibility(); + + virtual void exec( const QVariant ¶ms ); + + + +public slots: + +private: + + virtual void PowerStateChanged( TBTPowerStateValue aState ); + virtual void VisibilityModeChanged( TBTVisibilityMode aState ); + +private: + CBTEngSettings* mBtengSettings; + bool mOperationOngoing; + TBTVisibilityMode mOperation; + +private: + + Q_DISABLE_COPY(BtDelegateVisibility) + +}; + +#endif // BTDELEGATEVISIBILITY_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuidelegate/btuidelegate.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuidelegate/btuidelegate.pro Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,61 @@ +# +# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# + +TEMPLATE = lib +TARGET = btuidelegate +MOC_DIR = moc +DEFINES += BUILD_BTUIDELEGATE +INCLUDEPATH += . \ + ../inc + +CONFIG += qt \ + hb \ + dll +HEADERS += btdelegateconsts.h \ + btdelegatepower.h \ + btdelegatefactory.h \ + btabstractdelegate.h \ + btdelegatevisibility.h \ + btdelegatedevname.h + +SOURCES += btdelegatepower.cpp \ + btdelegatefactory.cpp \ + btabstractdelegate.cpp \ + btdelegatevisibility.cpp \ + btdelegatedevname.cpp + +symbian: { + SYMBIAN_PLATFORMS = WINSCW \ + ARMV5 + BLD_INF_RULES.prj_exports += "btdelegatefactory.h |../inc/btdelegatefactory.h" + BLD_INF_RULES.prj_exports += "btabstractdelegate.h |../inc/btabstractdelegate.h" + BLD_INF_RULES.prj_exports += "btdelegateconsts.h |../inc/btdelegateconsts.h" + TARGET.EPOCALLOWDLLDATA = 1 + TARGET.UID3 = 0xEE02434F + TARGET.CAPABILITY = CAP_GENERAL_DLL + INCLUDEPATH += $$MW_LAYER_SYSTEMINCLUDE + LIBS += -lbtengsettings \ + -lbtserviceutil \ + -lbtdevice \ + -lbtmanclient \ + -lesock \ + -lbluetooth \ + -lbtengdevman \ + -lbtengconnman \ + -lcentralrepository \ + -lflogger + //MMP_RULES -= EXPORTUNFROZEN +} diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuimodel/activewrapper.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/activewrapper.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,114 @@ +/* +* ============================================================================ +* Name : btuimsettings_p.cpp +* Part of : BluetoothUI / bluetoothuimodel *** Info from the SWAD +* Description : Implements the data source settings class used by BluetoothUiDataModel. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.1 +*/ + +#include "activewrapper.h" + +/*! + Constructor. + */ +ActiveWrapper::ActiveWrapper( int id, int priority, QObject *parent ) +: QObject( parent ){ + d = new ActiveWrapperPrivate( this, id, priority ); +} + +/*! + Destructor. + */ +ActiveWrapper::~ActiveWrapper(){ + delete d; +} + +int ActiveWrapper::getRequestId(){ + return d->mRequestId; +} + +void ActiveWrapper::setRequestId( int reqId ){ + d->mRequestId = reqId; +} + + +void ActiveWrapper::setActive() { + d->SetActive(); +} + +void ActiveWrapper::cancel(){ + d->Cancel(); +} + +bool ActiveWrapper::isActive(){ + return (bool) d->IsActive(); +} + +void ActiveWrapper::emitRequestCompleted( int status, int id ) { + emit requestCompleted( status, id ); +} + +void ActiveWrapper::emitCancelRequest( int id ) { + emit cancelRequest( id ); +} + +inline void ActiveWrapper::emitError( int status, int id ) { + emit error( status, id ); +} + +/*! + Constructor. + */ +ActiveWrapperPrivate::ActiveWrapperPrivate( + ActiveWrapper *parent, int id, int priority ) +: CActive( (TInt) priority ), + q( parent ), + mRequestId( id ) { + CActiveScheduler::Add( this ); +} + +/*! + Destructor. + */ +ActiveWrapperPrivate::~ActiveWrapperPrivate() { + Cancel(); +} + +/*! + \reimp + Called by the active scheduler when the request has been cancelled. + */ +void ActiveWrapperPrivate::RunL() { + q->emitRequestCompleted( iStatus.Int(), mRequestId ); +} + +/*! + \reimp + Called by Cancel() when the request is outstanding. + */ +void ActiveWrapperPrivate::DoCancel() { + q->emitCancelRequest( mRequestId ); +} + +/*! + \reimp + Called by the active scheduler when an error in RunL has occurred. + */ +TInt ActiveWrapperPrivate::RunError( TInt error ) { + q->emitRequestCompleted( error, mRequestId ); + return KErrNone; +} diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuimodel/activewrapper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/activewrapper.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,98 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef ACTIVEWRAPPER_H +#define ACTIVEWRAPPER_H + +#include +#include + +class ActiveWrapperPrivate; + +/*! + \class ActiveWrapper + \brief Helper class for using active objects in Qt classes. + + ActiveWrapper is a helper class for using active objects + from any Qt class. It wraps a CActive-derived class in an interface + that uses Qt's signal-slot mechanism for communicating status changes + of the active object. + + \\sa bluetoothuimodel + */ +class ActiveWrapper : public QObject +{ + Q_OBJECT + friend class ActiveWrapperPrivate; + +public: + explicit ActiveWrapper( int id, + int priority = CActive::EPriorityStandard, QObject *parent = NULL ); + ~ActiveWrapper(); + + int getRequestId(); + void setRequestId(int reqId); + void setActive(); + void cancel(); + bool isActive(); + +signals: + void requestCompleted( int status, int id ); + void cancelRequest( int id ); + void error( int status, int id ); + +private: + void emitRequestCompleted( int status, int id ); + void emitCancelRequest( int id ); + void emitError( int status, int id ); + +private: + ActiveWrapperPrivate *d; + +}; + + +/*! + \class ActiveWrapperPrivate + \brief Private class of ActiveWrapper, for using active objects in Qt classes. + + ActiveWrapperPrivate is a helper class for using active objects + from any Qt class. It derives from CActive and allows other classes to use + it for passing to asynchronous function calls through its RequestStatus method. + + \\sa bluetoothuimodel + */ +class ActiveWrapperPrivate : public CActive +{ + friend class ActiveWrapper; + +public: + explicit ActiveWrapperPrivate( ActiveWrapper *parent, int id, int priority ); + ~ActiveWrapperPrivate(); + +private: + virtual void RunL(); + virtual void DoCancel(); + virtual TInt RunError( TInt error ); + +private: + ActiveWrapper *q; + int mRequestId; +}; + +#endif // ACTIVEWRAPPER_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuimodel/btdevicedata.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/btdevicedata.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "btdevicedata.h" + +/*! + Constructor. + */ +BtDeviceData::BtDeviceData( + const QSharedPointer &data, + QObject *parent) + : QObject( parent ), mData( data ), mBtengConnMan(0) +{ + TRAP_IGNORE({ + mBtengConnMan = CBTEngConnMan::NewL( this ); + mDeviceRepo = CBtDevRepository::NewL( ); + }); + + Q_CHECK_PTR( mBtengConnMan ); + Q_CHECK_PTR( mDeviceRepo ); +} + +/*! + Destructor. + */ +BtDeviceData::~BtDeviceData() +{ + delete mBtengConnMan; + delete mDeviceRepo; +} + +void BtDeviceData::ConnectComplete( TBTDevAddr& addr, TInt err, + RBTDevAddrArray* conflicts ) +{ + Q_UNUSED( addr ); + Q_UNUSED( err ); + Q_UNUSED( conflicts ); +} + +void BtDeviceData::DisconnectComplete( TBTDevAddr& addr, TInt err ) +{ + Q_UNUSED( addr ); + Q_UNUSED( err ); +} + +void BtDeviceData::BtDeviceDeleted( const TBTDevAddr& addr ) +{ + Q_UNUSED( addr ); +} + +void BtDeviceData::BtDeviceAdded( const CBTDevice& device ) +{ + Q_UNUSED( device ); +} + +void BtDeviceData::BtDeviceChanged( const CBTDevice& device, TUint similarity ) +{ + Q_UNUSED( device ); + Q_UNUSED( similarity ); +} + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuimodel/btdevicedata.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/btdevicedata.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTDEVICEDATA_H +#define BTDEVICEDATA_H + +#include +#include +#include +#include +#include "btuimodel.h" + +/*! + \class BtDeviceData + \brief class for handling local Bluetooth setting updates. + + BtDeviceData class is responsible for providing the latest information + regarding the properties of remote devices and the connection status. + + \\sa bluetoothuimodel + */ +class BtDeviceData : public QObject, + public MBTEngConnObserver, + public MBtDevRepositoryObserver +{ + Q_OBJECT + +public: + BtDeviceData( + const QSharedPointer &data, + QObject *parent = 0 + ); + + virtual ~BtDeviceData(); + +private: + // from MBTEngConnObserver + + void ConnectComplete( TBTDevAddr& addr, TInt err, + RBTDevAddrArray* conflicts ); + + void DisconnectComplete( TBTDevAddr& addr, TInt err ); + + // From MBtDeviceRepositoryObserver + + void BtDeviceDeleted( const TBTDevAddr& addr ); + + void BtDeviceAdded( const CBTDevice& device ); + + void BtDeviceChanged( const CBTDevice& device, TUint similarity ); + +public slots: + //void activeRequestCompleted( int status, int id ); + +private: + +private: + QSharedPointer mData; + + CBTEngConnMan *mBtengConnMan; + + CBtDevRepository* mDeviceRepo; + + Q_DISABLE_COPY(BtDeviceData) + +}; + +#endif // BTLOCALSETTING_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuimodel/btlocalsetting.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/btlocalsetting.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,267 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "btlocalsetting.h" +#include +//#include +#include +#include +//#include +//#include +#include "btqtconstants.h" + +const int KLocalDeviceNameWatcher = 10; +const int KBtLinkCountWatcher = 11; + +/*! + Constructor. + */ +BtLocalSetting::BtLocalSetting( BtuiModel& model, QObject *parent ) + : QObject( parent ), mModel(model), mLocalDeviceWatcher(0) + { + int err( 0 ); + if (!err ) { + err = mLocalDeviceKey.Attach( KPropertyUidBluetoothCategory, + KPropertyKeyBluetoothGetRegistryTableChange ); + } + + Q_CHECK_PTR( !err ); // other proper alternative? + + TRAP_IGNORE({ + mBtengSetting = CBTEngSettings::NewL( this ); + mLocalDeviceWatcher = CBtSimpleActive::NewL(*this, KLocalDeviceNameWatcher ); + }); + + Q_CHECK_PTR( mBtengSetting ); + Q_CHECK_PTR( mLocalDeviceWatcher ); + + for ( int i = 0; i < BtuiModel::LocalSettingColCount; ++i ) { + // Initialize the list with empty values. + mData.append( BtuiModelDataItem() ); + } + + // subscribe to local device table change: + mLocalDeviceKey.Subscribe( mLocalDeviceWatcher->RequestStatus() ); + mLocalDeviceWatcher->GoActive(); + + // Get the device name + TBTDeviceName deviceName; + (void) mBtengSetting->GetLocalName( deviceName ); + updateDeviceName( QString::fromUtf16( deviceName.Ptr(), deviceName.Length() ) ); + + // Get the power setting. + TBTPowerStateValue power( EBTPowerOff ); + (void) mBtengSetting->GetPowerState( power ); + setPowerSetting( power ); + + // Get the visibility mode + TBTVisibilityMode visibilityMode( EBTVisibilityModeNoScans ); + (void) mBtengSetting->GetVisibilityMode( visibilityMode ); + setVisibilityMode( visibilityMode ); +} + +/*! + Destructor. + */ +BtLocalSetting::~BtLocalSetting() +{ + // delete main data structure + delete mBtengSetting; + delete mLocalDeviceWatcher; + mLocalDeviceKey.Close(); + + // delete mBtLinkCountWatcher; + //mBtLinkCountKey.Close(); +} + + +bool BtLocalSetting::isValid( int column) const +{ + return column < mData.count(); +} + +int BtLocalSetting::itemCount() const +{ + return mData.count(); +} + +void BtLocalSetting::data(QVariant& val, int col, int role ) const +{ + if ( isValid( col ) ) { + val = mData.at( col ).value( role ); + } + else { + val = QVariant( QVariant::Invalid ); + } +} + +BtuiModelDataItem BtLocalSetting::itemData( int col ) const +{ + if ( isValid( col ) ) { + return mData.at( col ); + } + return BtuiModelDataItem(); +} + + +/*! + Provides notification of changes in the power state + of the Bluetooth hardware. + + @param state EBTPowerOff if the BT hardware has been turned off, + EBTPowerOn if it has been turned on. + */ +void BtLocalSetting::PowerStateChanged( TBTPowerStateValue state ) +{ + setPowerSetting( state ); + emit settingDataChanged( BtuiModel::LocalSettingRow, BtuiModel::PowerStateCol, this ); +} + +/*! + Provides notification of changes in the discoverability + mode of the Bluetooth hardware. + @param state EBTDiscModeHidden if the BT hardware is in hidden mode, + EBTDiscModeGeneral if it is in visible mode. + */ +void BtLocalSetting::VisibilityModeChanged( TBTVisibilityMode state ) +{ + setVisibilityMode( state ); + emit settingDataChanged( BtuiModel::LocalSettingRow, BtuiModel::VisibilityCol, this ); +} + +void BtLocalSetting::RequestCompletedL( CBtSimpleActive* active, TInt status ) { + Q_UNUSED( active ); + Q_UNUSED( status ); + if ( active->RequestId() == KLocalDeviceNameWatcher ) { + mLocalDeviceKey.Subscribe( mLocalDeviceWatcher->RequestStatus() ); + mLocalDeviceWatcher->GoActive(); + updateDeviceName( QString() ); + } +} + +void BtLocalSetting::CancelRequest( TInt requestId ) { + if ( requestId == KLocalDeviceNameWatcher ) { + mLocalDeviceKey.Cancel(); + } + else if ( requestId == KBtLinkCountWatcher ) { + //mBtLinkCountKey.Cancel(); + } +} + +void BtLocalSetting::HandleError( CBtSimpleActive* active, TInt error ) { + Q_UNUSED( active ); + Q_UNUSED( error ); +} + +/*! + Update local Bluetooth device name in the data store. + @param name the latest Bluetooth name. + */ +void BtLocalSetting::updateDeviceName( const QString &name ) +{ + // To-do: the data structure initialization is not impled yet in the model + BtuiModelDataItem& item = + mData[ BtuiModel::BluetoothNameCol ]; + + if ( item.isEmpty() ) { + // Initialize with additional information on the setting + item[ BtuiModel::SettingIdentity ] = QVariant( tr( "Local Bluetooth name" ) ); + } + + bool setByUser = !name.isEmpty(); + + // The additional parameter is the flag indicating whether the + // Bluetooth name has been set by the user. + // The flag is set to true if the name has been set. + // requirement does not + //nitem[ BtuiModel::SettingValueParam ] = QVariant( setByUser ); + + QString resolvedName( name ); + if ( resolvedName.isEmpty() ) { + // We get the default name as suggestion for the user to set. + getNameFromRegistry( resolvedName ); + } + item[ BtuiModel::settingDisplay ] = QVariant( resolvedName ); + item[ BtuiModel::SettingValue ] = QVariant( resolvedName ); +} + +/*! + Updates all values related to the power setting. + */ +void BtLocalSetting::setPowerSetting( TBTPowerStateValue state ) +{ + BtuiModelDataItem& item = + mData[ BtuiModel::PowerStateCol ]; + if ( item.isEmpty() ) { + // Initialize with additional information on the setting + item[ BtuiModel::SettingIdentity ] = QVariant( tr( "Bluetooth power" ) ); + } + + bool powerOn = ( state == EBTPowerOn ); + + item[ BtuiModel::settingDisplay ] = + powerOn ? QVariant( tr( "On" ) ) : QVariant( tr( "Off" ) ); + item[ BtuiModel::SettingValue ] = QVariant( powerOn ); +} + +void BtLocalSetting::setVisibilityMode( TBTVisibilityMode state ) +{ + BtuiModelDataItem& item = mData[ BtuiModel::VisibilityCol ]; + + if ( item.isEmpty() ) { + item[ BtuiModel::SettingIdentity ] = QVariant( tr( "Phone visibility" ) ); + } + + if ( state == EBTVisibilityModeHidden ) + { + item [ BtuiModel::settingDisplay ] = QVariant( tr( "Hidden" ) ); + } + else if ( state == EBTVisibilityModeGeneral ) + { + item [ BtuiModel::settingDisplay ] = QVariant( tr( "Visible" ) ); + } + else + { + item [ BtuiModel::settingDisplay ] = QVariant( tr( "Temporarily visible" ) ); + } + item [ BtuiModel::SettingValue ] = QVariant( QtVisibilityMode(state) ); +} + +/*! + Get local Bluetooth device name from BTRegistry. + */ +void BtLocalSetting::getNameFromRegistry( QString &name ) +{ + RBTRegServ btRegServ; // Session with BTMan + RBTLocalDevice btReg; // Subsession with local device table + TBTLocalDevice localDev;// Data structure holding local device information + + TInt err = btRegServ.Connect(); + if ( !err ) { + err = btReg.Open( btRegServ ); + } + if ( !err ) { + // Read the BT local name from BT Registry. + err = btReg.Get( localDev ); + } + if ( !err ) { + name = QString::fromUtf8( (const char*) localDev.DeviceName().Ptr(), (int) localDev.DeviceName().Length() ); + } + btReg.Close(); + btRegServ.Close(); +} diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuimodel/btlocalsetting.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/btlocalsetting.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,116 @@ +/* +* ============================================================================ +* Name : btuimsettings.h +* Part of : BluetoothUI / bluetoothuimodel *** Info from the SWAD +* Description : Declaration of the class representing the Bluetooth +* settings source data. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTLOCALSETTING_H +#define BTLOCALSETTING_H + +#include +#include +#include +#include +#include + +#include "btuimodel.h" + +/*! + \class BtuimSettings + \brief class for handling local Bluetooth setting updates. + + BtLocalSetting class is responsible for providing the latest information + regarding the local Bluetooth settings such as device name and power state. + + \\sa bluetoothuimodel + */ +class BtLocalSetting : public QObject, + public MBTEngSettingsObserver, + public MBtSimpleActiveObserver +{ + Q_OBJECT + +public: + explicit BtLocalSetting( BtuiModel& model, QObject *parent = 0 ); + + virtual ~BtLocalSetting(); + + bool isValid( int col) const; + + int itemCount() const; + + void data(QVariant& val, int col, int role ) const; + + BtuiModelDataItem itemData( int col ) const; + +signals: + + void settingDataChanged( int row, int column, void *parent ); + +private: + // from MBTEngSettingsObserver + + void PowerStateChanged( TBTPowerStateValue state ); + + void VisibilityModeChanged( TBTVisibilityMode state ); + + // from MBtSimpleActiveObserver + + void RequestCompletedL( CBtSimpleActive* active, TInt status ); + + void CancelRequest( TInt requestId ); + + void HandleError( CBtSimpleActive* active, TInt error ); + + + +public slots: + //void activeRequestCompleted( int status, int id ); + +private: + + void setVisibilityMode( TBTVisibilityMode state ); + void updateDeviceName( const QString &name ); + + void setPowerSetting( TBTPowerStateValue state ); + + //void setOfflineSetting( bool state ); + //void setBtConnectionsSetting( int connections ); + + void getNameFromRegistry( QString &name ); + +private: + BtuiModelDataSource mData; + + BtuiModel& mModel; + + CBTEngSettings *mBtengSetting; + + // For monitoring local device name change + RProperty mLocalDeviceKey; + CBtSimpleActive *mLocalDeviceWatcher; + + //RProperty mBtLinkCountKey; + //CBTEngActive *mBtLinkCountWatcher; + Q_DISABLE_COPY(BtLocalSetting) + +}; + +#endif // BTLOCALSETTING_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuimodel/btuimodel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/btuimodel.cpp Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,138 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "btuimodel.h" +#include "btlocalsetting.h" + +/*! + This Constructor creates new instances of model data structure. + */ +BtuiModel::BtuiModel( QObject *parent ) + : QAbstractItemModel( parent ) +{ + mLocalSetting = QSharedPointer( new BtLocalSetting( *this ) ); + bool b = connect( mLocalSetting.data(), SIGNAL(settingDataChanged(int,int,void*)), this, SLOT(btDataChanged(int,int,void*))); + Q_ASSERT( b ); +} + +/*! + This Constructor shares the instances of model data structure with the + given model. + */ +BtuiModel::BtuiModel( const BtuiModel &model, QObject *parent ) + : QAbstractItemModel( parent ) +{ + mLocalSetting = model.mLocalSetting; + bool b = connect( mLocalSetting.data(), SIGNAL(settingDataChanged(int,int,void*)), this, SLOT(btDataChanged(int,int,void*))); + Q_ASSERT( b ); +} + +/*! + Destructor. + */ +BtuiModel::~BtuiModel() +{ +} + +/*! + \reimp + */ +QModelIndex BtuiModel::index( int row, int column, const QModelIndex &parent ) const +{ + Q_UNUSED( parent ); + if ( row == LocalSettingRow + && mLocalSetting->isValid( column ) ) { + // local setting data: + return createIndex( row, column, mLocalSetting.data() ); + } + else if ( row == RemoteDeviceRow ) { + + } + // invalid row and column: + return QModelIndex(); +} + +/*! + \reimp + */ +QModelIndex BtuiModel::parent( const QModelIndex &child ) const +{ + Q_UNUSED( child ); + // root level, no parent. + return QModelIndex(); +} + +/*! + \reimp + */ +int BtuiModel::rowCount( const QModelIndex &parent ) const +{ + Q_UNUSED( parent ); + return ModelRowCount; +} + +/*! + \reimp + */ +int BtuiModel::columnCount( const QModelIndex &parent ) const +{ + if ( parent.row() == LocalSettingRow + && mLocalSetting->isValid( parent.column() ) ) { + // local setting data: + return mLocalSetting->itemCount(); + } + else if ( parent.row() == RemoteDeviceRow ) { + } + return 0; +} + +/*! + \reimp + */ +QVariant BtuiModel::data( const QModelIndex &index, int role ) const +{ + QVariant val( QVariant::Invalid ); + if ( index.row() == LocalSettingRow ) { + mLocalSetting.data()->data( val, index.column(), role ); + } + else if ( index.row() == RemoteDeviceRow ) { + } + return val; +} + +QMap BtuiModel::itemData( const QModelIndex & index ) const +{ + if ( index.row() == LocalSettingRow ) { + mLocalSetting.data()->itemData( index.column() ); + } + else if ( index.row() == RemoteDeviceRow ) { + } + return QMap(); +} + +/*! + Slot for receiving notification of changes from the data source. + Forward the notification using dataChanged signal. + */ +void BtuiModel::btDataChanged( int row, int column, void *parent ) +{ + (void) parent; + QModelIndex idx = createIndex( row, column, parent ); + emit dataChanged( idx, idx ); +} + + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuimodel/btuimodel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/btuimodel.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,152 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTUIMODEL_H +#define BTUIMODEL_H + + +#include +#include +#include + +class BtLocalSetting; +class BtDeviceStore; + +// A data item in this model. For example, power state item consists +// of the information regarding the current Bluetooth power state. +typedef QMap< int, QVariant > BtuiModelDataItem; + +// A category of the model data for specific group +typedef QList< BtuiModelDataItem > BtuiModelDataSource; + +#ifdef BUILD_BTUIMODEL +#define BTUIMODEL_IMEXPORT Q_DECL_EXPORT +#else +#define BTUIMODEL_IMEXPORT Q_DECL_IMPORT +#endif + +/*! + \class BtuiModel + \brief The data model provided to Bluetooth UIs in QT + + BtuiModel provides APIs for accessing certain BT data, such as local Bluetooth + settings and the properties of remote BT devices. In addition, signals from this + model are provided for being informed of data update. + + This model is in two dimension (2 rows * n columns), i.e., + + row 0 (BT local setting) + col 0 (local device name) + col 1 (power state) + ... + row 1 (remote devices) + col 0 ( a remote device) + col 1 ( another device) + ... + + The data in this model is non-modifiable from the user interface (except device + search may add a number of in-range devices temporarily) , + determined by the characteristics of Bluetooth, the underline BT software + services and the BT application requirements. + + Whenever feasible, the detailed description should contain a simple + example code example: + \code + // ... + \endcode + + \sa \link model-view-programming.html Model/View Programming\endlink + */ + +class BTUIMODEL_IMEXPORT BtuiModel : public QAbstractItemModel +{ + Q_OBJECT + Q_ENUMS( RowId LocalSettingCol LocalSettingDataRole ) + +public: + + /** + * The parent row identifier of data model. Data in this model is grouped into + * two categories: the local Bluetooth settings and the remote device + * database. The data of each category is stored in multiple + * rows of a specified row. + */ + enum RowId { + LocalSettingRow = 0, + RemoteDeviceRow = 1, + ModelRowCount = 2 + }; + //Q_DECLARE_FLAGS(Rows, BtuiModelRow) + + /** + * child row identifiers of the local setting row + */ + enum LocalSettingCol { + BluetoothNameCol = 0, + PowerStateCol , + VisibilityCol, + SapModeCol, + AllowedInOfflineCol, + LocalSettingColCount, + }; + //Q_DECLARE_FLAGS(BtuiModelLocalSettings, BtuiModelLocalSettingColumn) + + /** + * Data roles that the items in the local setting row + */ + enum LocalSettingDataRole { + SettingIdentity = Qt::WhatsThisRole, + settingDisplay = Qt::DisplayRole, + SettingValue = Qt::EditRole, + SettingValueParam = Qt::UserRole + 1, // e.g., temp visibility time + }; + +public: + + explicit BtuiModel( QObject *parent = 0 ); + + explicit BtuiModel( const BtuiModel &model, QObject *parent = 0 ); + + virtual ~BtuiModel(); + + // from QAbstractItemModel + virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; + + virtual QModelIndex parent( const QModelIndex &child ) const; + + virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; + + virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; + + virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; + + virtual QMap itemData( const QModelIndex & index ) const; + +public slots: + + void btDataChanged(int row, int column, void *parent ); + +private: + QSharedPointer mLocalSetting; +}; + +//Q_DECLARE_OPERATORS_FOR_FLAGS(BtuiModel::Rows) + +Q_DECLARE_METATYPE(BtuiModelDataItem) +Q_DECLARE_METATYPE(BtuiModelDataSource) + +#endif // BTUIMODEL_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuimodel/btuimodel.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/btuimodel.pro Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,61 @@ +# +# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# + +TEMPLATE = lib +TARGET = btuimodel + +MOC_DIR = moc +DEFINES += BUILD_BTUIMODEL + +INCLUDEPATH += . \ + ../inc + +CONFIG += qt \ + hb \ + dll + +HEADERS += btdevicedata.h \ + btlocalsetting.h \ + btuimodel.h \ + activewrapper.h +SOURCES += btdevicedata.cpp \ + btlocalsetting.cpp \ + btuimodel.cpp \ + activewrapper.cpp + +symbian: { + SYMBIAN_PLATFORMS = WINSCW \ + ARMV5 + BLD_INF_RULES.prj_exports += "btuimodel.h |../inc/btuimodel.h" + + TARGET.EPOCALLOWDLLDATA = 1 + TARGET.UID3 = 0x2002434F + TARGET.CAPABILITY = CAP_GENERAL_DLL + + INCLUDEPATH += $$MW_LAYER_SYSTEMINCLUDE + + LIBS += -lbtengsettings \ + -lbtserviceutil \ + -lbtdevice \ + -lbtmanclient \ + -lesock \ + -lbluetooth \ + -lbtengdevman \ + -lbtengconnman \ + -lcentralrepository \ + -lflogger + //MMP_RULES -= EXPORTUNFROZEN +} diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/btuimodel/btuimodelutil.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/btuimodel/btuimodelutil.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,174 @@ +/* +* ============================================================================ +* Name : btuimutil.h +* Part of : BluetoothUI / bluetoothuimodel *** Info from the SWAD +* Description : utilities in the model for some often used functions, +* e.g. conversions between Qt and Symbian types. +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BTUIMODELUTIL_H +#define BTUIMODELUTIL_H + +#include +#include + +_LIT(KDefaultBTDevName, "Bluetooth Device" ); + +/*! + Converts a QString which contains a BT device address in readable format to + Symbian native TBTDevAddr type. + */ +inline void addrReadbleStringToSymbian( const QString &readable, TBTDevAddr &addr) +{ + TBuf buffer(readable.utf16()); + addr.SetReadable( buffer ); +} + +/*! + Converts a Symbian native TBTDevAddr to + QString which contains the BT device address in readable format. + */ +inline void addrSymbianToReadbleString( QString &readable, const TBTDevAddr &addr) +{ + TBuf buffer; + addr.GetReadable( buffer ); + readable = QString::fromUtf16( buffer.Ptr(), buffer.Length() ); +} + +/*! + Decide the device name to display from the device information, and + converts the name if necessary. If the device doesn't have a valid name, + the given default name will be used. +*/ +inline void getDeviceDisplayName( QString& dispName, const CBTDevice& device , + const TDesC& defaultName ) +{ + // friendly name is preferred if available + if( device.IsValidFriendlyName() && device.FriendlyName().Length()){ + dispName = QString::fromUtf16( + device.FriendlyName().Ptr(), device.FriendlyName().Length() ); + } + // next preferred is actual device name + else if( device.IsValidDeviceName() && device.DeviceName().Length() ) { + dispName = QString::fromUtf8( + (char*) device.DeviceName().Ptr(), device.DeviceName().Length() ); + } + else { + // finally, use default name if nothing else is available + dispName = QString::fromUtf16( + defaultName.Ptr(), defaultName.Length() ); + } +} + +/*! + Decide the device name to display from the device information, and + converts the name if necessary. If the device doesn't have a valid name, + the given default name will be used. +*/ +inline void getDeviceDisplayName( QString& dispName, const CBTDevice& device ) +{ + getDeviceDisplayName( dispName, device, KDefaultBTDevName ); +} + + +/*! + Guess if the given Class of Device indicates an Audio/Video device (headset and carkit) + or not. + Computer device supporting audio is not considered as AV device. +*/ +inline bool isAVDevice( const TBTDeviceClass &cod ) +{ + int majorDevCls = cod.MajorDeviceClass(); + int minorDevCls = cod.MinorDeviceClass(); + return ( ( majorDevCls == EMajorDeviceAV ) + || ( cod.MajorServiceClass() == EMajorServiceRendering + && majorDevCls != EMajorDeviceImaging ) ); +} + +/*! + Guess if the given Class of Device indicates an input device (keyboard and mouse) + or not. +*/ +inline bool isHIDDevice( const TBTDeviceClass &cod ) +{ + int majorDevCls = cod.MajorDeviceClass(); + int minorDevCls = cod.MinorDeviceClass(); + return ( ( majorDevCls == EMajorDevicePeripheral ) && + ( minorDevCls == EMinorDevicePeripheralKeyboard || + minorDevCls == EMinorDevicePeripheralPointer ) ); +} + +/*! + Tells if the given device has been paired. +*/ +inline bool isPaired( const CBTDevice &dev ) +{ + return dev.IsValidPaired() && dev.IsPaired() && + dev.LinkKeyType() != ELinkKeyUnauthenticatedUpgradable; +} + +/*! + Tells if the given device supports file transfer. +*/ +inline bool supportsFileTransfer( const TBTDeviceClass &cod ) +{ + int majorDevCls = cod.MajorDeviceClass(); + return ( majorDevCls == EMajorDevicePhone + || majorDevCls == EMajorDeviceComputer ); +} + +/*! + Tells if the given device is currently connected. +*/ +inline bool isConnected( CBTEngConnMan &btConnMan, + const TBTDevAddr &addr ) +{ + TBTEngConnectionStatus connectStatus( EBTEngNotConnected ); + btConnMan.IsConnected( addr, connectStatus ); + return connectStatus == EBTEngConnected; +} + +/*! + Tells if the given device is currently connected. +*/ +inline bool isConnected( CBTEngConnMan &btConnMan, + const CBTDevice &dev ) +{ + return isConnected( btConnMan, dev.BDAddr() ); +} + +/*! + Tells if the given device is connectible with services managed by bteng. +*/ +inline bool isConnectible( CBTEngConnMan &btConnMan, + const TBTDeviceClass &devClass ) +{ + TBool connectible( false ); + btConnMan.IsConnectable( devClass, connectible ); + return connectible; +} + +/*! + Tells if the given device is connectible with services managed by bteng. +*/ +inline bool isConnectible( CBTEngConnMan &btConnMan, + const CBTDevice &dev ) +{ + return isConnectible( btConnMan, dev.DeviceClass() ); +} +#endif // BTUIMODELUTIL_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/bwins/btuidelegateu.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/bwins/btuidelegateu.def Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,17 @@ +EXPORTS + ?staticMetaObject@BtAbstractDelegate@@2UQMetaObject@@B @ 1 NONAME ; struct QMetaObject const BtAbstractDelegate::staticMetaObject + ?qt_metacall@BtAbstractDelegate@@UAEHW4Call@QMetaObject@@HPAPAX@Z @ 2 NONAME ; int BtAbstractDelegate::qt_metacall(enum QMetaObject::Call, int, void * *) + ?newDelegate@BtDelegateFactory@@SAPAVBtAbstractDelegate@@W4Command@BtDelegate@@AAVBtuiModel@@PAVQObject@@@Z @ 3 NONAME ; class BtAbstractDelegate * BtDelegateFactory::newDelegate(enum BtDelegate::Command, class BtuiModel &, class QObject *) + ??_EBtAbstractDelegate@@UAE@I@Z @ 4 NONAME ; BtAbstractDelegate::~BtAbstractDelegate(unsigned int) + ??1BtAbstractDelegate@@UAE@XZ @ 5 NONAME ; BtAbstractDelegate::~BtAbstractDelegate(void) + ?metaObject@BtAbstractDelegate@@UBEPBUQMetaObject@@XZ @ 6 NONAME ; struct QMetaObject const * BtAbstractDelegate::metaObject(void) const + ?tr@BtAbstractDelegate@@SA?AVQString@@PBD0H@Z @ 7 NONAME ; class QString BtAbstractDelegate::tr(char const *, char const *, int) + ?commandCompleted@BtAbstractDelegate@@IAEXHVQVariant@@@Z @ 8 NONAME ; void BtAbstractDelegate::commandCompleted(int, class QVariant) + ?tr@BtAbstractDelegate@@SA?AVQString@@PBD0@Z @ 9 NONAME ; class QString BtAbstractDelegate::tr(char const *, char const *) + ??0BtAbstractDelegate@@QAE@AAVBtuiModel@@PAVQObject@@@Z @ 10 NONAME ; BtAbstractDelegate::BtAbstractDelegate(class BtuiModel &, class QObject *) + ?getStaticMetaObject@BtAbstractDelegate@@SAABUQMetaObject@@XZ @ 11 NONAME ; struct QMetaObject const & BtAbstractDelegate::getStaticMetaObject(void) + ?qt_metacast@BtAbstractDelegate@@UAEPAXPBD@Z @ 12 NONAME ; void * BtAbstractDelegate::qt_metacast(char const *) + ?model@BtAbstractDelegate@@IAEAAVBtuiModel@@XZ @ 13 NONAME ; class BtuiModel & BtAbstractDelegate::model(void) + ?trUtf8@BtAbstractDelegate@@SA?AVQString@@PBD0@Z @ 14 NONAME ; class QString BtAbstractDelegate::trUtf8(char const *, char const *) + ?trUtf8@BtAbstractDelegate@@SA?AVQString@@PBD0H@Z @ 15 NONAME ; class QString BtAbstractDelegate::trUtf8(char const *, char const *, int) + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/bwins/btuimodelu.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/bwins/btuimodelu.def Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,22 @@ +EXPORTS + ??0BtuiModel@@QAE@PAVQObject@@@Z @ 1 NONAME ; BtuiModel::BtuiModel(class QObject *) + ?tr@BtuiModel@@SA?AVQString@@PBD0@Z @ 2 NONAME ; class QString BtuiModel::tr(char const *, char const *) + ?qt_metacall@BtuiModel@@UAEHW4Call@QMetaObject@@HPAPAX@Z @ 3 NONAME ; int BtuiModel::qt_metacall(enum QMetaObject::Call, int, void * *) + ?itemData@BtuiModel@@UBE?AV?$QMap@HVQVariant@@@@ABVQModelIndex@@@Z @ 4 NONAME ; class QMap BtuiModel::itemData(class QModelIndex const &) const + ?qt_metacast@BtuiModel@@UAEPAXPBD@Z @ 5 NONAME ; void * BtuiModel::qt_metacast(char const *) + ?getStaticMetaObject@BtuiModel@@SAABUQMetaObject@@XZ @ 6 NONAME ; struct QMetaObject const & BtuiModel::getStaticMetaObject(void) + ??1BtuiModel@@UAE@XZ @ 7 NONAME ; BtuiModel::~BtuiModel(void) + ?parent@BtuiModel@@UBE?AVQModelIndex@@ABV2@@Z @ 8 NONAME ; class QModelIndex BtuiModel::parent(class QModelIndex const &) const + ?btDataChanged@BtuiModel@@QAEXHHPAX@Z @ 9 NONAME ; void BtuiModel::btDataChanged(int, int, void *) + ?trUtf8@BtuiModel@@SA?AVQString@@PBD0@Z @ 10 NONAME ; class QString BtuiModel::trUtf8(char const *, char const *) + ?metaObject@BtuiModel@@UBEPBUQMetaObject@@XZ @ 11 NONAME ; struct QMetaObject const * BtuiModel::metaObject(void) const + ?data@BtuiModel@@UBE?AVQVariant@@ABVQModelIndex@@H@Z @ 12 NONAME ; class QVariant BtuiModel::data(class QModelIndex const &, int) const + ?columnCount@BtuiModel@@UBEHABVQModelIndex@@@Z @ 13 NONAME ; int BtuiModel::columnCount(class QModelIndex const &) const + ??_EBtuiModel@@UAE@I@Z @ 14 NONAME ; BtuiModel::~BtuiModel(unsigned int) + ?trUtf8@BtuiModel@@SA?AVQString@@PBD0H@Z @ 15 NONAME ; class QString BtuiModel::trUtf8(char const *, char const *, int) + ?index@BtuiModel@@UBE?AVQModelIndex@@HHABV2@@Z @ 16 NONAME ; class QModelIndex BtuiModel::index(int, int, class QModelIndex const &) const + ?staticMetaObject@BtuiModel@@2UQMetaObject@@B @ 17 NONAME ; struct QMetaObject const BtuiModel::staticMetaObject + ??0BtuiModel@@QAE@ABV0@PAVQObject@@@Z @ 18 NONAME ; BtuiModel::BtuiModel(class BtuiModel const &, class QObject *) + ?rowCount@BtuiModel@@UBEHABVQModelIndex@@@Z @ 19 NONAME ; int BtuiModel::rowCount(class QModelIndex const &) const + ?tr@BtuiModel@@SA?AVQString@@PBD0H@Z @ 20 NONAME ; class QString BtuiModel::tr(char const *, char const *, int) + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/eabi/btuidelegateu.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/eabi/btuidelegateu.def Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,16 @@ +EXPORTS + _ZN17BtDelegateFactory11newDelegateEN10BtDelegate7CommandER9BtuiModelP7QObject @ 1 NONAME + _ZN18BtAbstractDelegate11qt_metacallEN11QMetaObject4CallEiPPv @ 2 NONAME + _ZN18BtAbstractDelegate11qt_metacastEPKc @ 3 NONAME + _ZN18BtAbstractDelegate16commandCompletedEi8QVariant @ 4 NONAME + _ZN18BtAbstractDelegate16staticMetaObjectE @ 5 NONAME DATA 16 + _ZN18BtAbstractDelegate19getStaticMetaObjectEv @ 6 NONAME + _ZN18BtAbstractDelegate5modelEv @ 7 NONAME + _ZN18BtAbstractDelegateC2ER9BtuiModelP7QObject @ 8 NONAME + _ZN18BtAbstractDelegateD0Ev @ 9 NONAME + _ZN18BtAbstractDelegateD1Ev @ 10 NONAME + _ZN18BtAbstractDelegateD2Ev @ 11 NONAME + _ZNK18BtAbstractDelegate10metaObjectEv @ 12 NONAME + _ZTI18BtAbstractDelegate @ 13 NONAME + _ZTV18BtAbstractDelegate @ 14 NONAME + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/eabi/btuimodelu.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/eabi/btuimodelu.def Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,23 @@ +EXPORTS + _ZN9BtuiModel11qt_metacallEN11QMetaObject4CallEiPPv @ 1 NONAME + _ZN9BtuiModel11qt_metacastEPKc @ 2 NONAME + _ZN9BtuiModel13btDataChangedEiiPv @ 3 NONAME + _ZN9BtuiModel16staticMetaObjectE @ 4 NONAME DATA 16 + _ZN9BtuiModel19getStaticMetaObjectEv @ 5 NONAME + _ZN9BtuiModelC1EP7QObject @ 6 NONAME + _ZN9BtuiModelC1ERKS_P7QObject @ 7 NONAME + _ZN9BtuiModelC2EP7QObject @ 8 NONAME + _ZN9BtuiModelC2ERKS_P7QObject @ 9 NONAME + _ZN9BtuiModelD0Ev @ 10 NONAME + _ZN9BtuiModelD1Ev @ 11 NONAME + _ZN9BtuiModelD2Ev @ 12 NONAME + _ZNK9BtuiModel10metaObjectEv @ 13 NONAME + _ZNK9BtuiModel11columnCountERK11QModelIndex @ 14 NONAME + _ZNK9BtuiModel4dataERK11QModelIndexi @ 15 NONAME + _ZNK9BtuiModel5indexEiiRK11QModelIndex @ 16 NONAME + _ZNK9BtuiModel6parentERK11QModelIndex @ 17 NONAME + _ZNK9BtuiModel8itemDataERK11QModelIndex @ 18 NONAME + _ZNK9BtuiModel8rowCountERK11QModelIndex @ 19 NONAME + _ZTI9BtuiModel @ 20 NONAME + _ZTV9BtuiModel @ 21 NONAME + diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/inc/bluetoothtrace.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/inc/bluetoothtrace.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,455 @@ +/* +* ============================================================================ +* Name : bluetoothtrace.h +* Part of : BluetoothUI / bluetoothuimodel *** Info from the SWAD +* Description : API declaration of run-time debug tracing +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BLUETOOTHTRACE_H +#define BLUETOOTHTRACE_H + +#include +#include "traceconfig.h" + +/* + * Common tracing utility definition to be used by Bluetooth projects. + * The configuration is loaded from traceconfig.h which shall be private for + * each individual project. + * + * In this utility, a set of OST-alike tracing macros are defined. + * (The purpose is to ease migration to OST in future.) + * + * Individual project can also define new macros based on this utility in + * its own space. + * + */ + +#ifdef BLUETOOTHTRACE_ENABLED + +#ifdef BLUETOOTHTRACE_MEDIA_OST + +/** + * Convert own macros to OST macros when OST tracing is used. + * In OST tracing, aTraceName must be a unique identifier in scope of a module. + * Thus many OST compiling errors may occur if the same TraceName is used in multiple + * tracing lines where tracing is miigrated from non-OST to OST. + * The fix is to renaming the TraceName:s to be unique. + */ +#include + +#define BOstrace0( aGroupName, aTraceName, aTraceText ) \ + OstTrace0( aGroupName, aTraceName, aTraceText ) + +#define BOstrace1( aGroupName, aTraceName, aTraceText, aParam ) \ + OstTrace1( aGroupName, aTraceName, aTraceText, aParam ) + +#define BOstraceData( aGroupName, aTraceName, aTraceText, aPtr, aLength ) \ + OstTraceData( aGroupName, aTraceName, aTraceText, aPtr, aLength ) + +#define BOstraceExt1( aGroupName, aTraceName, aTraceText, aParam ) \ + OstTraceExt1( aGroupName, aTraceName, aTraceText, aParam ) + +#define BOstraceExt2( aGroupName, aTraceName, aTraceText, aParam1, aParam2 ) \ + OstTraceExt2( aGroupName, aTraceName, aTraceText, aParam1, aParam2 ) + +#define BOstraceExt3( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3 ) \ + OstTraceExt3( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3 ) + +#define BOstraceExt4( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4 ) \ + OstTraceExt4( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4 ) + +#define BOstraceExt5( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4, aParam5 ) \ + OstTraceExt5( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4, aParam5 ) + +#define BOstraceFunctionEntry0( aTraceName ) \ + OstTraceFunctionEntry0( aTraceName ) + +#define BOstraceFunctionEntry1( aTraceName, aInstance ) \ + OstTraceFunctionEntry1( aTraceName, aInstance ) + +#define BOstraceFunctionEntryExt(aTraceName, aInstance, aArg) \ + OstTraceFunctionEntryExt(aTraceName, aInstance, aArg) + +#define BOstraceFunctionExit0( aTraceName ) \ + OstTraceFunctionExit0( aTraceName ) + +#define BOstraceFunctionExit1( aTraceName, aInstance ) \ + OstTraceFunctionExit1( aTraceName, aInstance ) + +#define BOstraceFunctionExitExt(aTraceName, aInstance, aRetval) \ + OstTraceFunctionExitExt(aTraceName, aInstance, aRetval) + +#define BOstraceEventStart0( aTraceName, aEventName ) \ + OstTraceEventStart0( aTraceName, aEventName ) + +#define BOstraceEventStart1( aTraceName, aEventName, aParam ) \ + OstTraceEventStart1( aTraceName, aEventName, aParam ) + +#define BOstraceEventStop( aTraceName, aEventName ) \ + OstTraceEventStop( aTraceName, aEventName ) + +#define BOstraceState0( aTraceName, aStateName, aNewState ) \ + OstTraceState0( aTraceName, aStateName, aNewState ) + +#define BOstraceState1( aTraceName, aStateName, aNewState, aInstance ) \ + OstTraceState1( aTraceName, aStateName, aNewState, aInstance ) + +#else // BLUETOOTHTRACE_MEDIA_OST + +#ifdef BLUETOOTHTRACE_MEDIA_FILE +#include +#else +#include +#endif + +/** + * When tracing compilation with OST is disabled, the TraceName in each OST trace line + * is ignored, that is, the Trace Names are not checked at compiling time, neither + * are they written into the specified trace output media. + */ + +/** + * Handlers below are used for tolerating overflow of formatting strings. + * to trucate rather than panic the caller. + */ +NONSHARABLE_CLASS( TBtTraceOflowTruncate8 ) : public TDes8Overflow + { +public: + void Overflow( TDes8& /*aDes*/ ) {} + }; + +NONSHARABLE_CLASS( TBtTraceOflowTruncate16 ) : public TDes16Overflow + { +public: + void Overflow( TDes16& /*aDes*/ ) {} + }; + +/** + * internal tracing implementation, do not use it out of this file. + */ +inline void Trace(const TDesC &trGrp, const TDesC &trTxt) +{ + _LIT(Format, "%S%S%S"); + TBuf16<0x180> str; + TPtrC cp(KComponentName); + str.Format(Format, &cp, &trGrp, &trTxt); +#ifdef BLUETOOTHTRACE_MEDIA_FILE + RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, str); +#else + RDebug::Print( str ); +#endif +} + +/* + * trace with no parameters + */ +#define BOstrace0( aGroupName, aTraceName, aTraceText ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + Trace( TrGrp, TrTxt ); \ +} + +/* + * trace with one 32-bit parameter + */ +#define BOstrace1( aGroupName, aTraceName, aTraceText, aParam ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + TBuf<512> buf; TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(TrTxt, &overflow, aParam); \ + Trace( TrGrp, buf ); \ +} + +/* + * trace with more than 32 bits of data. Not supported + */ +#define BOstraceData( aGroupName, aTraceName, aTraceText, aPtr, aLength ) + +/* + * trace with one parameter that is not 32-bit integer + */ +#define BOstraceExt1( aGroupName, aTraceName, aTraceText, aParam ) \ + BOstrace1( aGroupName, aTraceName, aTraceText, aParam ) + +/* + * trace with two parameters. + */ +#define BOstraceExt2( aGroupName, aTraceName, aTraceText, aParam1, aParam2 ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + TBuf<512> buf; TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(TrTxt, &overflow, aParam1, aParam2); \ + Trace( TrGrp, buf ); \ +} + +/* + * trace with three parameters. + */ +#define BOstraceExt3( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3 ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + TBuf<512> buf; TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(TrTxt, &overflow, aParam1, aParam2, aParam3); \ + Trace( TrGrp, buf ); \ +} + +/* + * trace with four parameters + */ +#define BOstraceExt4( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4 ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + TBuf<512> buf; TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(TrTxt, &overflow, aParam1, aParam2, aParam3, aParam4); \ + Trace( TrGrp, buf ); \ +} + +/* + * trace with five parameters + */ +#define BOstraceExt5( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4, aParam5 ) \ +{\ + _LIT(TrGrp, aGroupName); _LIT(TrTxt, aTraceText); \ + TBuf<512> buf; TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(TrTxt, &overflow, aParam1, aParam2, aParam3, aParam4, aParam5); \ + Trace( TrGrp, buf ); \ +} + +/* + * Function entry trace without extra parameters. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionEntry0( aTraceName ) \ +{\ + _LIT(TrGrp, "[ API ]"); \ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, ">> "); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry );\ + Trace( TrGrp, buf ); \ +} + +/* + * Function entry trace with a parameter representing the instance identifier, e.g. + * "this" pointer. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionEntry1( aTraceName, aInstance ) \ +{\ + _LIT(TrGrp, "[ API ]");\ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, ">> "); _LIT(Fmt, " 0x%X(%d)"); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry); \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Fmt, &overflow, aInstance, aInstance); \ + Trace( TrGrp, buf ); \ +} + +/* + * Function entry trace, which traces function parameters. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionEntryExt(aTraceName, aInstance, aArg) \ +{ \ + _LIT(TrGrp, "[ API ]");\ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, ">> "); _LIT(Fmt, " 0x%X(%d) arg %d"); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry); \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Fmt, &overflow, aInstance, aInstance, aArg); \ + Trace( TrGrp, buf ); \ +} +/* + * Function exit trace without extra parameters. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionExit0( aTraceName ) \ +{\ + _LIT(TrGrp, "[ API ]"); \ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, "<< "); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry); \ + Trace( TrGrp, buf ); \ +} + +/* + * Function exit trace with a parameter representing the instance identifier + * for example "this" pointer. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionExit1( aTraceName, aInstance ) \ +{\ + _LIT(TrGrp, "[ API ]"); \ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, "<< "); _LIT(Fmt, " 0x%X(%d)"); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry); \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Fmt, &overflow, aInstance, aInstance); \ + Trace( TrGrp, buf ); \ +} + +/* + * Function exit trace with parameters representing the instance identifier, + * for example "this" pointer, and return value. + * The trace is mapped to TRACE_API group. + */ +#define BOstraceFunctionExitExt(aTraceName, aInstance, aRetval) \ +{\ + _LIT(TrGrp, "[ API ]");\ + TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \ + _LIT(Entry, "<< "); _LIT(Fmt, " 0x%X(%d) ret %d"); \ + TBuf<512> buf; buf.Copy( func ); buf.Insert(0, Entry); \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Fmt, &overflow, aInstance, aInstance, aRetval); \ + Trace( TrGrp, buf ); \ +} + +/* + * Performance measurement event start trace without extra parameters. + * The trace is mapped to TRACE_PERFORMANCE group. + */ +#define BOstraceEventStart0( aTraceName, aEventName ) \ +{\ + _LIT(TrGrp, "[PFMAN]"); _LIT(EvName, aEventName); \ + _LIT(Entry, "[Start] "); \ + TBuf<512> buf(Entry); buf.Append( EvName ); \ + Trace( TrGrp, buf ); \ +} + +/* + * Performance measurement event start trace with single 32-bit parameter. + * The trace is mapped to TRACE_PERFORMANCE group. + */ +#define BOstraceEventStart1( aTraceName, aEventName, aParam ) \ +{\ + _LIT(TrGrp, "[PFMAN]"); _LIT(EvName, aEventName); \ + _LIT(Entry, "[Start] %S 0x%X(%d)"); \ + TPtrC evt(EvName); TBuf<512> buf; \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Entry, &overflow, &evt, aParam, aParam ); \ + Trace( TrGrp, buf ); \ +} + +/* + * Performance measurement event end trace. + * The trace is mapped to TRACE_PERFORMANCE group. + */ +#define BOstraceEventStop( aTraceName, aEventName ) \ +{\ + _LIT(TrGrp, "[PFMAN]"); _LIT(EvName, aEventName); \ + _LIT(Entry, "[Stop] "); \ + TBuf<512> buf(Entry); buf.Append( EvName ); \ + Trace( TrGrp, buf ); \ +} + +/* + * State transition event. + * The trace is mapped to TRACE_STATE group. + */ +#define BOstraceState0( aTraceName, aStateName, aNewState ) \ +{\ + _LIT(TrGrp, "[STATE]"); _LIT(StName, aStateName); \ + _LIT(Entry, "%S 0x%X(%d)"); \ + TPtrC evt(StName); TBuf<512> buf; \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Entry, &overflow, &evt, aNewState, aNewState ); \ + Trace( TrGrp, buf ); \ +} + +/* + * State transition event with instance identifier. + * The trace is mapped to TRACE_STATE group. + */ +#define BOstraceState1( aTraceName, aStateName, aNewState, aInstance ) \ +{\ + _LIT(TrGrp, "[STATE]"); _LIT(StName, aStateName); \ + _LIT(Entry, "%S 0x%X(%d) instance=0x%X(%d)"); \ + TPtrC evt(StName); TBuf<512> buf; \ + TBtTraceOflowTruncate16 overflow; \ + buf.AppendFormat(Entry, &overflow, &evt, aNewState, aNewState, aInstance, aInstance ); \ + Trace( TrGrp, buf ); \ +} + +#endif // BLUETOOTHTRACE_MEDIA_OST + +// Extended tracing macros facilitating domain specific tracing needs: + +/* + * A block of source code merely for tracing purpose. + */ +#define BtTraceBlock( exp ) {exp} + +/* + * trace macro for BT device address printing with an additional trace text. + * aParam must be TBTDevAddr type. + */ +#define BtTraceBtAddr1( aGroupName, aTraceName, aTraceText, aParam ) \ +{ \ + _LIT(TrTxt, aTraceText); TPtrC p(TrTxt); \ + TBuf<12> buf; \ + aParam.GetReadable( buf ); TPtrC p2(buf);\ + BOstraceExt2( aGroupName, aTraceName, "%S%S", &p, &p2 ); \ +} + +/* + * trace macro for BT device address printing with no additional trace text. + * aParam must be TBTDevAddr type. + */ +#define BtTraceBtAddr0( aGroupName, aTraceName, aParam ) \ +{ \ + TBuf<12> buf; aParam.GetReadable( buf ); TPtrC p(buf); \ + BOstraceExt1( aGroupName, aTraceName, "%S", &p ); \ +} + +#else // BLUETOOTHTRACE_ENABLED + +#define BOstrace0( aGroupName, aTraceName, aTraceText ) +#define BOstrace1( aGroupName, aTraceName, aTraceText, aParam ) +#define BOstraceData( aGroupName, aTraceName, aTraceText, aPtr, aLength ) +#define BOstraceExt1( aGroupName, aTraceName, aTraceText, aParam ) +#define BOstraceExt2( aGroupName, aTraceName, aTraceText, aParam1, aParam2 ) +#define BOstraceExt3( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3 ) +#define BOstraceExt4( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4 ) +#define BOstraceExt5( aGroupName, aTraceName, aTraceText, aParam1, aParam2, aParam3, aParam4, aParam5 ) + +#define BOstraceFunctionEntry0( aTraceName ) +#define BOstraceFunctionEntry1( aTraceName, aInstance ) +#define BOstraceFunctionEntryExt(aTraceName, aInstance, aArg) +#define BOstraceFunctionExit0( aTraceName ) +#define BOstraceFunctionExit1( aTraceName, aInstance ) +#define BOstraceEventStart0( aTraceName, aEventName ) +#define BOstraceEventStart1( aTraceName, aEventName, aParam ) +#define BOstraceFunctionExitExt(aTraceName, aInstance, aRetval) +#define BOstraceEventStop( aTraceName, aEventName ) +#define BOstraceState0( aTraceName, aStateName, aNewState ) +#define BOstraceState1( aTraceName, aStateName, aNewState, aInstance ) + +#define BtTraceBlock( exp ) +#define BtTraceBtAddr1( aGroupName, aTraceName, aTraceText, aParam ) +#define BtTraceBtAddr0( aGroupName, aTraceName, aParam ) + +#endif // BLUETOOTHTRACE_ENABLED + +/* + * Additional general purpose definition, a hook for defining a friend class + * for unit testing to get access to class internals. + */ +#ifndef BTUNITTEST +#define BTUNITTESTHOOK +#endif + +#endif // BLUETOOTHTRACE_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/inc/bluetoothuitrace.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/inc/bluetoothuitrace.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,182 @@ +/* +* ============================================================================ +* Name : bluetoothuitrace.h +* Part of : BluetoothUI / bluetoothuimodel *** Info from the SWAD +* Description : API declaration of run-time debug tracing in bluetoothui project +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ + +#ifndef BLUETOOTHUITRACE_H +#define BLUETOOTHUITRACE_H + +#include +#include + +#ifdef BLUETOOTHTRACE_ENABLED + +/* + * trace macro for Qt code with an additional trace text. + * param must be QString type. + */ +#define BtTraceQString1( groupName, traceName, traceText, param ) \ +{\ + _LIT(TrTxt, traceText); TPtrC p(TrTxt); \ + TPtrC textPtr(reinterpret_cast(param.utf16()), param.length() ); \ + BOstraceExt2( groupName, traceName, "%S%S", &p, &textPtr ); \ +} + +/* + * trace macro for Qt code with no additional trace text. + * param must be QString type. + */ +#define BtTraceQString0( groupName, traceName, param ) \ +{\ + TPtrC textPtr(reinterpret_cast(param.utf16()), param.length() ); \ + BOstraceExt1( groupName, traceName, "%S", &textPtr ); \ +} + +/* + * Macro for tracing a Bluetooth device entry in btuimdevlist + * with no additional trace text. + */ +#define BtTraceDevListEntry0( groupName, traceName, dev ) \ +{\ + QString info("["); \ + info += dev[Btuim::DevAddrReadableRole].toString() + "]"; \ + QString filterBinary; \ + filterBinary.setNum( dev[Btuim::MajorFilterRole].toInt(), 16); \ + info += "[" + filterBinary + "]"; \ + info += "[" \ + + dev[Btuim::LastUsedTimeRole].value().toString(Qt::ISODate ) \ + + "]" ; \ + info += "[" + dev[Btuim::DevNameRoleRole].toString() + "]" ; \ + TPtrC textPtr(reinterpret_cast(info.utf16()), info.length() ); \ + BOstraceExt1( groupName, traceName, "%S", &textPtr ); \ +} + +/* + * Macro for tracing a Bluetooth device entry in btuim + * with an additional trace text. + */ +#define BtTraceDevListEntry1( groupName, traceName, traceText, dev ) \ +{\ + QString info("["); \ + info += dev[Btuim::DevAddrReadableRole].toString() + "]"; \ + QString cod; \ + cod.setNum( dev[Btuim::ClassOfDeviceRole].toInt(), 16); \ + info += "[" + cod + "]"; \ + QString filterBinary; \ + filterBinary.setNum( dev[Btuim::MajorFilterRole].toInt(), 16); \ + info += "[" + filterBinary + "]"; \ + info += "[" \ + + dev[Btuim::LastUsedTimeRole].value().toString(Qt::ISODate ) \ + + "]" ; \ + info += "[" + dev[Btuim::DevNameRole].toString() + "]" ; \ + TPtrC textPtr(reinterpret_cast(info.utf16()), info.length() ); \ + _LIT(TrTxt, traceText); TPtrC p(TrTxt); \ + BOstraceExt2( groupName, traceName, "%S%S", &p, &textPtr ); \ +} + +/* + * Macro for Qt code with additional trace text. + * list must be QStringList type. + */ +#define BtTraceQStringList1( groupName, traceName, traceText, list ) \ +{\ + QString info(": ["); \ + info += list.join(".") + "]"; \ + TPtrC textPtr(reinterpret_cast(info.utf16()), info.length() ); \ + _LIT(TrTxt, traceText); TPtrC p(TrTxt); \ + BOstraceExt2( groupName, traceName, "%S%S", &p, &textPtr ); \ +} + +/* + * Macro for Qt code with no additional trace text. + * list must be QStringList type. + */ +#define BtTraceQStringList0( groupName, traceName, list ) \ +{\ + QString info(": ["); \ + info += list.join(".") + "]"; \ + TPtrC textPtr(reinterpret_cast(info.utf16()), info.length() ); \ + BOstraceExt1( groupName, traceName, "%S", &textPtr ); \ +} + + +/* + * Macro for tracing Bluetooth DevData data source in btuimdevdata + * with no additional trace text. +*/ +#define BtTraceDevDataEntry0( groupName, traceName, devData ) \ +{\ + QString info("["); \ + QMap< int, QVariant > val = devData.at( Btuim::DevDataIndexName ); \ + info += val.value(Qt::EditRole).toString() + "]" ; \ + val = devData.at( Btuim::DevDataIndexStatus ); \ + int statusBits = val.value(Qt::EditRole).toInt(); \ + info += "["; \ + info += QString::number(statusBits, 16 ); \ + info += "]"; \ + QStringList strl = val.value(Qt::DisplayRole).toStringList(); \ + info += "[" ; \ + for ( int i = 0; i < strl.count(); ++i ) { \ + info += strl.at(i) + ","; \ + } \ + info += "]" ; \ + val = devData.at( Btuim::DevDataIndexOptionsMenu ); \ + info += " opts:"; \ + QList cmdItems = val.value( Btuim::DevDataCmdItemsRole ).toList(); \ + for ( int i = 0; i < cmdItems.count(); i++ ) { \ + const Btuim::DevDataCmdItem& item = cmdItems.at(i).value(); \ + info += "[" + QString::number(item.mCmdId) + "," + QString::number(item.mEnabled) + "," + "]"; \ + } \ + val = devData.at( Btuim::DevDataIndexCmdList ); \ + info += " cmds:"; \ + cmdItems = val.value( Btuim::DevDataCmdItemsRole ).toList(); \ + for ( int i = 0; i < cmdItems.count(); i++ ) { \ + const Btuim::DevDataCmdItem& item = cmdItems.at(i).value(); \ + info += "[" + QString::number(item.mCmdId) + "," + QString::number(item.mEnabled) + "," + "]"; \ + } \ + TPtrC textPtr(reinterpret_cast(info.utf16()), info.length() ); \ + BOstraceExt1( groupName, traceName, "%S", &textPtr ); \ +} +#else + +#define BtTraceQString1( aGroupName, aTraceName, aTraceText, aParam ) +#define BtTraceQString0( aGroupName, aTraceName, aParam ) +#define BtTraceDevListEntry0( groupName, traceName, dev ) +#define BtTraceDevListEntry1( groupName, traceName, traceText, dev ) +#define BtTraceQStringList1( groupName, traceName, traceText, list ) +#define BtTraceQStringList0( groupName, traceName, list ) +#define BtTraceDevDataEntry0( groupName, traceName, devData ) +#endif // BLUETOOTHTRACE_ENABLED + +// At early development phase, we force assertion in release build to find out +// design and implementation issues. +//#ifndef QT_NO_DEBUG +#define BTUI_DEBUG +//#endif + +#if !defined(BTUI_ASSERT_X) +# ifdef BTUI_DEBUG +#define BTUI_ASSERT_X(cond, where, what) ((!(cond)) ? qt_assert_x(where, what,__FILE__,__LINE__) : qt_noop()) +# else +# define BTUI_ASSERT_X(cond, where, what) qt_noop() +# endif +#endif + +#endif // BLUETOOTHUITRACE_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/inc/btqtconstants.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/inc/btqtconstants.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef BTQTCONSTANTS_H +#define BTQTCONSTANTS_H + +#include + + +enum VisibilityMode { + BtHidden = 0x10, // using a different number space than TBTVisibilityMode + BtVisible, + BtTemporary, + BtUnknown + +}; + +// used for mapping between UI row and VisibilityMode item +enum VisibilityModeUiRowMapping { + UiRowBtHidden = 0, + UiRowBtVisible, + UiRowBtTemporary +}; + +inline VisibilityMode QtVisibilityMode(TBTVisibilityMode btEngMode) +{ + VisibilityMode mode; + switch(btEngMode) { + case EBTVisibilityModeHidden: + mode = BtHidden; + break; + case EBTVisibilityModeGeneral: + mode = BtVisible; + break; + case EBTVisibilityModeTemporary: + mode = BtTemporary; + break; + default: + mode = BtUnknown; + } + return mode; +} + +inline TBTVisibilityMode BtEngVisibilityMode(VisibilityMode btQtMode) +{ + TBTVisibilityMode mode; + switch(btQtMode) { + case BtHidden: + mode = EBTVisibilityModeHidden; + break; + case BtVisible: + mode = EBTVisibilityModeGeneral; + break; + case BtTemporary: + mode = EBTVisibilityModeTemporary; + break; + default: + mode = (TBTVisibilityMode)KErrUnknown; + } + return mode; +} + + +#endif // BTQTCONSTANTS_H diff -r 7e2761e776bd -r 48ae3789ce00 bluetoothengine/btui/inc/traceconfig.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btui/inc/traceconfig.h Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,126 @@ +/* +* ============================================================================ +* Name : traceconfig_template.h +* Part of : BluetoothUI / bluetoothuimodel *** Info from the SWAD +* Description : Configuration of debug tracing in bluetoothuimodel +* +* Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* Nokia Corporation +* ============================================================================ +* Template version: 4.2 +*/ +#ifndef BLUETOOTHTRACECONFIG_H +#define BLUETOOTHTRACECONFIG_H + +/* +Sample usage: + void testTracing() + { + BOstrace0( TRACE_FATAL, TNAME_DEVLIST_1, "BOstrace0" ); + BOstrace1( TRACE_IMPORTANT, TNAME_DEVLIST_2, "BOstrace1 %d", 123 ); + _LIT(String, "\"Symbian Descriptor\""); + TPtrC ptr(String); + TBuf<20> buf(ptr); + BOstraceExt1( TRACE_NORMAL, TNAME_DEVLIST_3, "BOstraceExt1 %S", &ptr); + BOstraceExt2( TRACE_API, TNAME_DEVLIST_4, "BOstraceExt2 %d %S", 456, &ptr ); + BOstraceExt3( TRACE_FLOW, TNAME_DEVLIST, "BOstraceExt3 0x%x %d %S", 128, 256, &ptr ); + BOstraceExt4( TRACE_DETAILED, TNAME_DEVL_5IST, "BOstraceExt4 0x%x %d %S %S", 128, 256, &ptr, &buf ); + BOstraceExt5( TRACE_DEBUG, TNAME_DEVLIST_6, "BOstraceExt5 0x%x %d %S %S, %b", 128, 256, &ptr, &buf, 512 ); + BOstraceFunctionEntry0( TNAME_DEVLIST_7 ); + BOstraceFunctionEntry1( TNAME_DEVLIST_8, 0x00abcdef ); + BOstraceFunctionEntryExt(TNAME_DEVLIST_9, 0xdeadbeef, 123 ); + BOstraceFunctionExit0( TNAME_DEVLIST_9 ); + BOstraceFunctionExit1( TNAME_DEVLIST_10, 0x00beebee ); + BOstraceFunctionExitExt(TNAME_DEVLIST_11, 0x00badbed, -1); + BOstraceEventStart0( TNAME_DEVLIST_12, "BOstraceEventStart0" ); + BOstraceEventStart1( TNAME_DEVLIST_13, "BOstraceEventStart1", 789 ); + BOstraceEventStop( TNAME_DEVLIST_14, "BOstraceEventStop" ); + BOstraceState0( TNAME_DEVLIST_15, "connection state", 1 ); + BOstraceState1( TNAME_DEVLIST_16, "audio state", 2, 0xdeadbeef ); + BtTraceBlock( + for (int i = 0; i < 5; ++i) { + BOstrace1( TRACE_IMPORTANT, TNAME_DEVLIST_, "BtTraceBlock counter(1-5): %d", i+1 ); + }); + QString str("\"Qt String\""); + BtTraceQString0( TRACE_NORMAL, TNAME_DEVLIST_17, str); + BtTraceQString1( TRACE_NORMAL, TNAME_DEVLIST_18, "additioanl text;", str); + TBTDevAddr addr; + addr.SetReadable(_L("0060576ff376")); + BtTraceBtAddr0( TRACE_NORMAL, TNAME_DEVLIST_19, addr ); + BtTraceBtAddr1( TRACE_NORMAL, TNAME_DEVLIST_20, "additional trace;", addr ); + } + + */ + +// At early development phase, tracing is activated +//#ifdef _DEBUG +#define BLUETOOTHTRACE_ENABLED +//#endif //_DEBUG + +/* + * Tracing media configuration + */ +#ifdef BLUETOOTHTRACE_ENABLED + #ifdef __WINS__ + #define BLUETOOTHTRACE_MEDIA_FILE + #else + // RDEBUG is used for tracing output before we migrate to OST tracing. + #define BLUETOOTHTRACE_MEDIA_RDEBUG + //#define BLUETOOTHTRACE_MEDIA_OST + #endif // __WINS__ +#endif //BLUETOOTHTRACE_ENABLED + +/* + * Configuration of tracing to file + */ +#ifdef BLUETOOTHTRACE_MEDIA_FILE + +_LIT( KLogFile, "btuiqt.txt" ); +_LIT( KLogDir, "bt" ); + +#endif //BLUETOOTHTRACE_MEDIA_FILE + +/* + * Configuration of tracing using RDebug + */ +#ifdef BLUETOOTHTRACE_MEDIA_RDEBUG + +#endif //BLUETOOTHTRACE_MEDIA_RDEBUG + +/* + * Configuration of tracing using OST + */ +#ifndef BLUETOOTHTRACE_MEDIA_OST + +/** + * Group-mapping aligning with OST groups. + * The purpose of using groups is to ease migrating tracing from legacy logging to OST. + */ +#define TRACE_FATAL "[FATAL]" +#define TRACE_IMPORTANT "[IMPTT]" +#define TRACE_NORMAL "[NORML]" +#define TRACE_API "[ API ]" +#define TRACE_FLOW "[FLOW ]" +#define TRACE_STATE "[STATE]" +#define TRACE_DETAILED "[DETLD]" +#define TRACE_DEBUG "[DEBUG]" +#define TRACE_PERFORMANCE "[PFMAN]" + +/** + * Component Identifier to be written into traces: + */ +_LIT(KComponentName, "[BtUi]"); + +#endif //BLUETOOTHTRACE_MEDIA_OST + +#endif // BLUETOOTHTRACECONFIG_H diff -r 7e2761e776bd -r 48ae3789ce00 sysdef_1_5_1.dtd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sysdef_1_5_1.dtd Mon May 03 14:36:07 2010 +0300 @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +