bluetoothengine/btnotif/btnotifsrv/inc/btnotifserver.h
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     1 /*
       
     2 * Copyright (c) 2010 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: Server class for handling commands from clients, and the 
       
    15 *                central class in btnotif thread.
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef BTNOTIFSERVER_H
       
    20 #define BTNOTIFSERVER_H
       
    21 
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <btengsettings.h>
       
    25 
       
    26 #include "bluetoothtrace.h"
       
    27 
       
    28 class CBTNotifConnectionTracker;
       
    29 class CBTNotifSettingsTracker;
       
    30 class CBTNotificationManager;
       
    31 class CBTNotifDeviceSelector;
       
    32 class CBtDevRepository;
       
    33 
       
    34 class CbtnotifServerTest; // ToDo: shall be refactored under compile flag?
       
    35 
       
    36 /**
       
    37  * Utility function for panicking the server.
       
    38  *
       
    39  * @since Symbian^4
       
    40  * @param aReason The panic reason code.
       
    41  */
       
    42 void PanicServer( TInt aReason );
       
    43 
       
    44 /**
       
    45  * Utility function for panicking the server.
       
    46  *
       
    47  * @since Symbian^4
       
    48  * @param aMessage The handle to the client side.
       
    49  * @param aReason The panic reason code.
       
    50  */
       
    51 void PanicClient( const RMessage2& aMessage, TInt aReason );
       
    52 
       
    53 /**  BTNotif panic codes */
       
    54 enum TBTNotifServerPanic
       
    55     {
       
    56     EBTNotifPanicUnknown,
       
    57     EBTNotifPanicCorrupt,
       
    58     EBTNotifPanicMissing,
       
    59     EBTNotifPanicNullMember,
       
    60     EBTNotifPanicBadState,
       
    61     EBTNotifPanicBadArgument,
       
    62     EBTNotifPanicBadResult
       
    63     };
       
    64 
       
    65 /**  Convenience macro for indicating unimplemented events */
       
    66 #define NOTIF_NOTIMPL 
       
    67 //{ __ASSERT_ALWAYS( 1, PanicServer( EBTNotifPanicNotImplemented ) ); }
       
    68 /**  Convenience macro for indicating unhandled events */
       
    69 #define NOTIF_NOTHANDLED( cond ) 
       
    70 //{ __ASSERT_ALWAYS( cond, PanicServer( EBTNotifPanicNotHandled ) ); }
       
    71 
       
    72 
       
    73 /**
       
    74  * CBTNotifServer handles notifications and also maintains state information related to 
       
    75  * the local device as well as remote devices.
       
    76  *
       
    77  *  @since Symbian^4
       
    78  */
       
    79 NONSHARABLE_CLASS( CBTNotifServer ) : public CPolicyServer
       
    80     {
       
    81 
       
    82 public:
       
    83 
       
    84     /**
       
    85      * Two-phased constructor.
       
    86      */
       
    87     static CBTNotifServer* NewLC();
       
    88 
       
    89     /**
       
    90     * Destructor.
       
    91     */
       
    92     virtual ~CBTNotifServer();
       
    93 
       
    94     /**
       
    95      * Called when the BT power state changes.
       
    96      *
       
    97      * @since Symbian^4
       
    98      * @param aState The new BT power state.
       
    99      */
       
   100     void HandlePowerStateChangeL( TBTPowerStateValue aState );
       
   101 
       
   102     /**
       
   103      * Called by a session during creation, to keep track of the number
       
   104      * of active sessions.
       
   105      *
       
   106      * @since Symbian^4
       
   107      */
       
   108     void AddSession();
       
   109 
       
   110     /**
       
   111      * Called by a session during destruction, to keep track of the number
       
   112      * of active sessions.
       
   113      *
       
   114      * @since Symbian^4
       
   115      */
       
   116     void RemoveSession();
       
   117 
       
   118     /**
       
   119      * Returns a handle to the settings tracker.
       
   120      *
       
   121      * @since Symbian^4
       
   122      * @param Pointer to the settings tracker.
       
   123      */
       
   124     inline CBTNotifSettingsTracker* SettingsTracker() const
       
   125         { return iSettingsTracker; }
       
   126 
       
   127     /**
       
   128      * Returns a handle to the connection tracker.
       
   129      *
       
   130      * @since Symbian^4
       
   131      * @param Pointer to the connection tracker.
       
   132      */
       
   133     inline CBTNotifConnectionTracker* ConnectionTracker() const
       
   134         { return iConnectionTracker; }
       
   135 
       
   136     /**
       
   137      * Returns a handle to the notification manager.
       
   138      *
       
   139      * @since Symbian^4
       
   140      * @param Pointer to the notification manager.
       
   141      */
       
   142     inline CBTNotificationManager* NotificationManager() const
       
   143         { return iNotificationMgr; }
       
   144 
       
   145     CBtDevRepository& DevRepository();
       
   146     
       
   147     CBTNotifDeviceSelector& DeviceSelectorL();
       
   148     
       
   149 // from base class CPolicyServer
       
   150 
       
   151     /**
       
   152      * From CPolicyServer.
       
   153      * Creates and returns a server-side session object.
       
   154      *
       
   155      * @since Symbian^4
       
   156      * @param aVersion The version information supplied by the client.
       
   157      * @param aMessage Represents the details of the client request that 
       
   158      *                 is requesting the creation of the session.
       
   159      * @return A pointer to the newly created server-side session object.
       
   160      */
       
   161     virtual CSession2* NewSessionL( const TVersion& aVersion, const RMessage2& aMessage ) const;
       
   162 
       
   163 private:
       
   164 
       
   165     CBTNotifServer();
       
   166 
       
   167     void ConstructL();
       
   168 
       
   169     /**
       
   170      * Asynchronous second-phase constructor. This function is called asynchronously
       
   171      * from ConstructL, to facilitate short initial construction, and allow construction
       
   172      * of e.g. session to BTEngine. So in fact this is a third-phase constructor.
       
   173      *
       
   174      * @since Symbian^4
       
   175      */
       
   176     void AsyncConstructL();
       
   177 
       
   178     void CheckIdle( TBTPowerStateValue aState );
       
   179     
       
   180     /**
       
   181      * Callback function for asynchronous construction.
       
   182      *
       
   183      * @since Symbian^4
       
   184      * @param aPtr Pointer to server instance.
       
   185      */
       
   186     static TInt AsyncConstructCb( TAny* aPtr );
       
   187 
       
   188     static TInt ShutdownTimeout( TAny* aPtr );
       
   189     
       
   190 private: // data
       
   191 
       
   192     /**
       
   193      * Counter for the number of active sessions.
       
   194      */
       
   195     TInt iSessionCount;
       
   196 
       
   197     /**
       
   198      * Helper class for tracking settings.
       
   199      * Own.
       
   200      */
       
   201     CBTNotifSettingsTracker* iSettingsTracker;
       
   202 
       
   203     /**
       
   204      * Helper class for tracking connections.
       
   205      * Own.
       
   206      */
       
   207     CBTNotifConnectionTracker* iConnectionTracker;
       
   208 
       
   209     /**
       
   210      * Helper class for managing the actual notifications.
       
   211      * Own.
       
   212      */
       
   213     CBTNotificationManager* iNotificationMgr;
       
   214 
       
   215     /**
       
   216      * Remote device repository.
       
   217      * Singleton in btnotifsrv. This is useful
       
   218      * for getting the correct name for displaying in UI
       
   219      * without the need getting the device everytime
       
   220      * when a name is needed.
       
   221      * Pairing handling also needs this repository to drive
       
   222      * the logic flow.
       
   223      */
       
   224     CBtDevRepository* iDevRep;
       
   225     
       
   226     /**
       
   227      * Helper class for device searching and selection.
       
   228      * Own.
       
   229      */
       
   230     CBTNotifDeviceSelector* iDevSelector;
       
   231     
       
   232     /**
       
   233      * Callback for asynchronous processing.
       
   234      * Own.
       
   235      */
       
   236     CAsyncCallBack* iAsyncCb;
       
   237 
       
   238     /**
       
   239      * Timer for various timeouts.
       
   240      * Own.
       
   241      */
       
   242     CDeltaTimer* iTimer;
       
   243     
       
   244     /**
       
   245      * The function entry of shutdown timeout.
       
   246      */
       
   247     TDeltaTimerEntry iShutdownTimerEntry;
       
   248     
       
   249     BTUNITTESTHOOK
       
   250 
       
   251     };
       
   252 
       
   253 #endif // BTNOTIFSERVER_H