bluetoothengine/bteng/inc/btengserver.h
changeset 0 f63038272f30
child 10 0707dd69d236
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  BTEng server header definition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef BTENGSERVER_H
       
    20 #define BTENGSERVER_H
       
    21 
       
    22 #include <bluetooth/btpowercontrol.h>
       
    23 #ifndef __WINS__
       
    24 #include <bluetooth/dutmode.h>
       
    25 #endif  //__WINS__  
       
    26 #include <bt_sock.h>
       
    27 #include <bttypes.h>
       
    28 #include <btfeaturescfg.h>
       
    29 #include "btengdomaincrkeys.h"
       
    30 #include "btengconstants.h"
       
    31 
       
    32 class CBTEngSrvState;
       
    33 class CBTEngSrvPluginMgr;
       
    34 class CBTEngPlugin;
       
    35 class CBTEngSrvBBConnMgr;
       
    36 class CBTEngSrvKeyWatcher;
       
    37 class CBTEngSdpDbHandler;
       
    38 class CBTEngPairMan;
       
    39 class CPolicyServer;
       
    40 class TEComResolverParams;
       
    41 class CImplementationInformation;
       
    42 class CDeltaTimer;
       
    43 
       
    44 /**
       
    45  * Main function in which the server is running.
       
    46  *
       
    47  * @since S60 v3.2
       
    48  */
       
    49 static void RunServerL();
       
    50 
       
    51 /**
       
    52  * Utility to panic the client.
       
    53  *
       
    54  * @since S60 v3.2
       
    55  * @param aMessage Client message
       
    56  * @param aPanic Panic reason code.
       
    57  */
       
    58 void PanicClient( const RMessage2& aMessage, TInt aPanic );
       
    59 
       
    60 /**
       
    61  * Utility to panic the server.
       
    62  *
       
    63  * @since S60 v3.2
       
    64  * @param aPanic Panic reason code.
       
    65  */
       
    66 void PanicServer( TInt aPanic );
       
    67 
       
    68 /**  Panic category */
       
    69 _LIT( KBTEngPanic, "BTEng panic" );
       
    70 
       
    71 /**  Panic codes */
       
    72 enum TBTEngServerPanic
       
    73     {
       
    74     EBTEngPanicMemoryLeak = 10000,
       
    75     EBTEngPanicArgumentIsNull,
       
    76     EBTEngPanicMemberVarIsNull,
       
    77     EBTEngPanicCorrupt,
       
    78     EBTEngPanicCorruptSettings
       
    79     };
       
    80 
       
    81 
       
    82 /**
       
    83  *  Class CBTEngServer
       
    84  *
       
    85  *  Core server class of BTEng.
       
    86  *
       
    87  *  @lib bteng.lib
       
    88  *  @since S60 S60 v3.2
       
    89  */
       
    90 NONSHARABLE_CLASS( CBTEngServer ) : public CPolicyServer
       
    91     {
       
    92 
       
    93     friend class CBTEngSrvSession;
       
    94     friend class CBTEngSrvState;
       
    95     friend class CBTEngSrvPluginMgr;
       
    96     friend class CBTEngSrvKeyWatcher;
       
    97     friend class CBTEngPairMan;
       
    98 
       
    99 public:
       
   100 
       
   101     static CBTEngServer* NewLC();
       
   102 
       
   103     virtual ~CBTEngServer();
       
   104 
       
   105     /**
       
   106      * ?description
       
   107      *
       
   108      * @since S60 v3.2
       
   109      * @param aState The new power state.
       
   110      * @param aTemp Turn BT off after use (ETrue) or not (EFalse).
       
   111      */
       
   112     void SetPowerStateL( TBTPowerStateValue aState, TBool aTemporary );
       
   113 
       
   114     /**
       
   115      * ?description
       
   116      *
       
   117      * @since S60 v3.2
       
   118      * @param ?arg1 ?description
       
   119      */
       
   120     void SetVisibilityModeL( TBTVisibilityMode aMode, TInt aTime );
       
   121     
       
   122      /**
       
   123      * ?description
       
   124      *
       
   125      * @since S60 v3.2
       
   126      * @param ?arg1 ?description
       
   127      */
       
   128     void UpdateVisibilityModeL( TInt aStackScanMode );
       
   129 
       
   130     /**
       
   131      * ?description
       
   132      *
       
   133      * @since S60 v3.2
       
   134      * @param ?arg1 ?description
       
   135      */
       
   136     void DisconnectAllL();
       
   137 
       
   138     /**
       
   139      * ?description
       
   140      *
       
   141      * @since S60 v3.2
       
   142      * @param ?arg1 ?description
       
   143      */
       
   144     void SetDutMode( TInt aDutMode );
       
   145 
       
   146     /**
       
   147      * ?description
       
   148      *
       
   149      * @since S60 v3.2
       
   150      * @param ?arg1 ?description
       
   151      */
       
   152     void ScanModeTimerCompletedL();
       
   153 
       
   154     /**
       
   155      * ?description
       
   156      *
       
   157      * @since S60 v3.2
       
   158      * @param ?arg1 ?description
       
   159      */
       
   160      void DisconnectAllCompleted();
       
   161 
       
   162     /**
       
   163      * ?description
       
   164      *
       
   165      * @since S60 v3.2
       
   166      * @param ?arg1 ?description
       
   167      */
       
   168     void DispatchPluginMessageL( const RMessage2& aMessage );
       
   169 
       
   170     /**
       
   171      * Increment the session count.
       
   172      *
       
   173      * @since S60 v3.2
       
   174      */
       
   175      void AddSession();
       
   176 
       
   177     /**
       
   178      * Decrement the session count.
       
   179      *
       
   180      * @since S60 v3.2
       
   181      * @param aAutoOff Indicator if this session had requested BT temporary on.
       
   182      */
       
   183      void RemoveSession( TBool aAutoOff );
       
   184      
       
   185      /**
       
   186      * ?description
       
   187      *
       
   188      * @since S60 v3.2
       
   189      * @param ?arg1 ?description
       
   190      */
       
   191      void SetUiIndicatorsL();
       
   192      
       
   193      /**
       
   194      * ?description
       
   195      *
       
   196      * @since S60 v3.2
       
   197      * @param ?arg1 ?description
       
   198      */
       
   199      void SetIndicatorStateL( const TInt aIndicator, const TInt aState );
       
   200 
       
   201     /**
       
   202      * Check whether BT should be turned off automatically.
       
   203      *
       
   204      * @since S60 v5.0
       
   205      */
       
   206      void CheckAutoPowerOffL();
       
   207 
       
   208     /**
       
   209      * Utility to get HW power state.
       
   210      *
       
   211      * @since S60 v5.1
       
   212      * @param aState On return, this will contain the current HW power state.
       
   213      * @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   214      */
       
   215     TInt GetHwPowerState( TBTPowerStateValue& aState );
       
   216 
       
   217      /**
       
   218      * queue a timer if Simple Pairing debug mode has been enabled.
       
   219      *
       
   220      * @since S60 v3.2
       
   221      * @param aDebugMode State of Simple Pairing debug mode.
       
   222      */
       
   223      void CheckSspDebugModeL( TBool aDebugMode );
       
   224      
       
   225      /**
       
   226       * Gets the access to pairing manager. Ownership is not transferred.
       
   227       * @return the pairing manager
       
   228       */
       
   229      CBTEngPairMan& PairManager();
       
   230      
       
   231      /**
       
   232       * Be informed when registry remote device table is changed
       
   233       */
       
   234      void RemoteRegistryChangeDetected();
       
   235 
       
   236      /**
       
   237       * gets the reference of socket server session
       
   238       */
       
   239      RSocketServ& SocketServ();
       
   240      
       
   241      /**
       
   242       * gets the reference of registry session.
       
   243       */
       
   244      RBTRegServ& BTRegServ();
       
   245      
       
   246      /**
       
   247       * Returns the service (limited to services managed in bteng scope)
       
   248       * level connection status of the specified device.
       
   249       *
       
   250       * @param aAddr the address of the device
       
   251       * @return one of TBTEngConnectionStatus enums
       
   252       */
       
   253      TBTEngConnectionStatus IsDeviceConnected( const TBTDevAddr& aAddr );
       
   254      
       
   255 // from base class CPolicyServer
       
   256 
       
   257     /**
       
   258      * From CPolicyServer.
       
   259      * ?description
       
   260      *
       
   261      * @since S60 v3.2
       
   262      * @param ?arg1 ?description
       
   263      */
       
   264     virtual CSession2* NewSessionL( const TVersion& aVersion, 
       
   265                                      const RMessage2& aMessage ) const;
       
   266 
       
   267 // from base class MBTPowerManagerObserver
       
   268 
       
   269     BluetoothFeatures::TEnterpriseEnablementMode EnterpriseEnablementMode() const;
       
   270     
       
   271 private:
       
   272 
       
   273     CBTEngServer();
       
   274 
       
   275     void ConstructL();
       
   276 
       
   277     /**
       
   278      * Checks if power is off and no session are connected, and
       
   279      * starts a shutdown timer if so.
       
   280      *
       
   281      * @since S60 v3.2
       
   282      * @param ?arg1 ?description
       
   283      */
       
   284      void CheckIdle();
       
   285 
       
   286     /**
       
   287      * ?description
       
   288      *
       
   289      * @since S60 v3.2
       
   290      * @param ?arg1 ?description
       
   291      */
       
   292     TInt SetPowerState( TBool aState );
       
   293 
       
   294     /**
       
   295      * ?description
       
   296      *
       
   297      * @since S60 v3.2
       
   298      * @param ?arg1 ?description
       
   299      */
       
   300     TInt SetLocalNameL();
       
   301     
       
   302     TInt GetLocalNameFromRegistryL(TDes& aName);
       
   303 
       
   304     /**
       
   305      * ?description
       
   306      *
       
   307      * @since S60 v3.2
       
   308      * @param ?arg1 ?description
       
   309      */
       
   310     void SetClassOfDeviceL();
       
   311 
       
   312     /**
       
   313      * ?description
       
   314      *
       
   315      * @since S60 v3.2
       
   316      * @param ?arg1 ?description
       
   317      */
       
   318     void InitBTStackL();
       
   319 
       
   320     /**
       
   321      * ?description
       
   322      *
       
   323      * @since S60 v3.2
       
   324      * @param ?arg1 ?description
       
   325      */
       
   326     void StopBTStackL();
       
   327 
       
   328     /**
       
   329      * ?description
       
   330      *
       
   331      * @since S60 v3.2
       
   332      * @param ?arg1 ?description
       
   333      */
       
   334     void UpdateCenRepPowerKeyL( TBTPowerStateValue aValue );
       
   335 
       
   336     /**
       
   337      * ?description
       
   338      *
       
   339      * @since S60 v3.2
       
   340      * @param ?arg1 ?description
       
   341      */
       
   342     void LoadBTPowerManagerL();
       
   343 
       
   344     /**
       
   345      * ?description
       
   346      *
       
   347      * @since S60 v3.2
       
   348      * @param ?arg1 ?description
       
   349      */
       
   350     void ManageDIServiceL( TBool aState );
       
   351     
       
   352     /**
       
   353      * Reads the product-specific IDs for this phone from central repository.
       
   354      * These values are used in the BT Device Information profile.
       
   355      *
       
   356      * @since S60 v3.2
       
   357      * @param aVendorId On return, holds the vendor ID for this phone.
       
   358      * @param aProductId On return, holds the product ID for this phone.
       
   359      */
       
   360     void GetProductIdsL( TInt& aVendorId, TInt& aProductId );
       
   361     
       
   362 	/**
       
   363      * Checks if a client requests temporary power on/off, and keeps track 
       
   364      * of the number of clients requesting that.
       
   365      *
       
   366      * @since S60 v5.0
       
   367      * @param aCurrentState On return, will contain the current power state.
       
   368      * @param aNewState The requested power state.
       
   369      * @param aTemporary Indicates if this is about a tempororary state change.
       
   370      */
       
   371     void CheckTemporaryPowerStateL( TBTPowerStateValue& aCurrentState, 
       
   372                                      TBTPowerStateValue aNewState, 
       
   373                                      TBool aTemporary );
       
   374 
       
   375     /**
       
   376      * Callback function for expiry of CDeltaTimer timer of temporary 
       
   377      * visibility mode.
       
   378      *
       
   379      * @since S60 v3.2
       
   380      * @param aPtr Pointer to ourselves.
       
   381      * @return Result
       
   382      */
       
   383     static TInt ScanModeTimerCallBack( TAny* aPtr );
       
   384     
       
   385     /**
       
   386      * Callback function for completion of disconnecting all 
       
   387      * Bluetoooth Baseband links.
       
   388      *
       
   389      * @since S60 v3.2
       
   390      * @param aPtr Pointer to ourselves.
       
   391      * @return Result
       
   392      */
       
   393     static TInt DisconnectAllCallBack( TAny* aPtr );
       
   394     
       
   395     /**
       
   396      * Callback function for expiriy CDeltaTimer timer of server idle timeout.
       
   397      *
       
   398      * @since S60 v3.2
       
   399      * @param aPtr Pointer to ourselves.
       
   400      * @return Result
       
   401      */
       
   402     static TInt IdleTimerCallBack( TAny* aPtr );
       
   403     
       
   404     /**
       
   405      * Callback function for expiriy CDeltaTimer timer of 
       
   406      * Simple Pairing Debug Mode.
       
   407      *
       
   408      * @since S60 v3.2
       
   409      * @param aPtr Pointer to ourselves.
       
   410      * @return Result
       
   411      */
       
   412     static TInt DebugModeTimerCallBack( TAny* aPtr );
       
   413     
       
   414     /**
       
   415      * Callback function for turning BT off automatically after all
       
   416      * connections are gone.
       
   417      *
       
   418      * @since S60 v5.0
       
   419      * @param aPtr Pointer to ourselves.
       
   420      * @return Result
       
   421      */
       
   422     static TInt AutoPowerOffCallBack( TAny* aPtr );
       
   423 	
       
   424 private: // data
       
   425 
       
   426     /**
       
   427      * Counter of the number of open sessions, which is used to 
       
   428      * stop the server when no session exists and Bluetooth is off.
       
   429      */
       
   430     TInt iSessionCount;
       
   431 
       
   432     /**
       
   433      * Handle to BT Power Manager library; this handle must exist 
       
   434      * for the lifetime of the loaded library.
       
   435      */
       
   436     TUint32 iDiSdpRecHandle;
       
   437 
       
   438     /**
       
   439      * Flag indicating if BT is going to be switched off automatically.
       
   440      */
       
   441     TBool iAutoSwitchOff;
       
   442 
       
   443     /**
       
   444      * Number of clients that are using BT temporarily.
       
   445      * Note that this is equal or less than the active number of links.
       
   446      */
       
   447     TInt iAutoOffClients;
       
   448 
       
   449     /**
       
   450      * Flag indicating hidden mode has been set for temporary power on.
       
   451      */
       
   452     TBool iRestoreVisibility;
       
   453 
       
   454     /**
       
   455     * To decide wether DUT mode should be enabled in power mode
       
   456     * change callback.
       
   457     */   
       
   458     TBool iEnableDutMode;
       
   459 
       
   460     /**
       
   461      * Remember which timer has been queued. (CDeltaTimer does not 
       
   462      * provide this information).
       
   463      */
       
   464     TUint32 iTimerQueued;
       
   465 
       
   466     /**
       
   467      * Callback for expiry of temporary visibility mode timer.
       
   468      */
       
   469     TDeltaTimerEntry iScanModeCallBack;
       
   470 
       
   471     /**
       
   472      * Callback for expiry of temporary power on mode timer.
       
   473      */
       
   474     TDeltaTimerEntry iPowerOffCallBack;
       
   475 
       
   476     /**
       
   477      * Callback for expiry of idle timer.
       
   478      */
       
   479     TDeltaTimerEntry iIdleCallBack;
       
   480     /**
       
   481      * Callback for expiry of Simple Pairing debug mode.
       
   482      */
       
   483     TDeltaTimerEntry iDebugModeCallBack;
       
   484 
       
   485     /**
       
   486      * Handle to BT Power Manager library; this handle must exist 
       
   487      * for the lifetime of the loaded library.
       
   488      */
       
   489     RLibrary iPowerMgrLib;
       
   490 #ifndef __WINS__
       
   491     /**
       
   492      *  Handle for DUT mode API
       
   493      */
       
   494     RBluetoothDutMode iDutMode;
       
   495 #endif  //__WINS__  
       
   496 
       
   497     /**
       
   498      * Pairing manager.
       
   499      */
       
   500     CBTEngPairMan* iPairMan;
       
   501     
       
   502     /**
       
   503     * Socket Server instance for this and other classes to access Bluetooth socket APIs.
       
   504     */   
       
   505     RSocketServ iSocketServ;
       
   506     
       
   507     
       
   508     /**
       
   509     * Registry Server instance for bteng to access Bluetooth registry APIs.
       
   510     */      
       
   511     RBTRegServ iBTRegServ;
       
   512      
       
   513     /**
       
   514      * BT Power Manager.
       
   515      * Own.
       
   516      */
       
   517     CBTEngSrvState* iServerState;
       
   518 
       
   519     /**
       
   520      * ECOM plugin manager.
       
   521      * Own.
       
   522      */
       
   523     CBTEngSrvPluginMgr* iPluginMgr;
       
   524 
       
   525     /**
       
   526      * Bluetooth Baseband connection manager.
       
   527      * Own.
       
   528      */
       
   529     CBTEngSrvBBConnMgr* iBBConnMgr;
       
   530 
       
   531     /**
       
   532      * Watcher for the relevant CenRep and PubSub keys.
       
   533      * Own.
       
   534      */
       
   535     CBTEngSrvKeyWatcher* iWatcher;
       
   536 
       
   537     /**
       
   538      * BT Power Manager (HCIv2 version).
       
   539      */
       
   540     RBTPowerControl iPowerMgr;
       
   541 
       
   542 #ifdef __WINS__
       
   543     /**
       
   544      * Current BT power state (power manager is not used in emulator).
       
   545      */
       
   546     TBTPowerState iPowerState;
       
   547 #endif  //__WINS__
       
   548 
       
   549     /**
       
   550      * SDP database handler.
       
   551      * Own.
       
   552      */
       
   553     CBTEngSdpDbHandler* iSdpDbHandler;
       
   554 
       
   555     /**
       
   556      * Timer for setting various timeouts.
       
   557      * Own.
       
   558      */
       
   559     CDeltaTimer* iTimer;
       
   560 
       
   561     BluetoothFeatures::TEnterpriseEnablementMode iEnterpriseEnablementMode;
       
   562     };
       
   563 
       
   564 
       
   565 #endif // BTENGSERVER