presetserver/serverinc/psserver.h
changeset 0 09774dfdd46b
child 12 608f67c22514
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Implementation of the preset server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CPSSERVER_H
       
    20 #define C_CPSSERVER_H
       
    21 
       
    22 #include <pscommon.h>
       
    23 #include <pspresetobserver.h>
       
    24 
       
    25 #include "psdatabase.h"
       
    26 #include "pspropertyobserver.h"
       
    27 
       
    28 class CPSDatabaseCleanup;
       
    29 class CPSShutdown;
       
    30 
       
    31 /**
       
    32  * Implementation of the preset server.
       
    33  */
       
    34 NONSHARABLE_CLASS( CPSServer ) : public CServer2, public MPSPresetObserver, public MPSPropertyChangeObserver
       
    35     {
       
    36 
       
    37 public:
       
    38 
       
    39     /**
       
    40      * Two-phased constructor.
       
    41      *
       
    42      * @return  The newly created object.
       
    43      */
       
    44     static CPSServer* NewL();
       
    45 
       
    46     /**
       
    47      * Destructor.
       
    48      */
       
    49     ~CPSServer();      
       
    50 
       
    51     /**
       
    52      * Panics the client with a specific reason.
       
    53      *
       
    54      * @param   aReason     Reason of the panic.
       
    55      */
       
    56     void PanicClient( TInt aReason ) const;
       
    57 
       
    58     /**
       
    59      * Returns the current IPC message.
       
    60      *
       
    61      * @return  The current IPC message.
       
    62      */
       
    63     const RMessage2& Message() const;
       
    64 
       
    65     /**
       
    66      * Returns the preset database.
       
    67      *
       
    68      * @return  The preset database.
       
    69      */
       
    70     RPSDatabase& Database();
       
    71     
       
    72     /**
       
    73      * Increments the session count. Should be called whenever a new session is created.
       
    74      */
       
    75     void IncrementSessionCount();
       
    76 
       
    77     /**
       
    78      * Decrements the session count. Should be called whenever a session is destroyed.
       
    79      */
       
    80     void DecrementSessionCount();
       
    81 
       
    82     /**
       
    83      * Called when a session is disconnected.
       
    84      *
       
    85      * @param	aMessage	Disconnect message.
       
    86      */
       
    87     void SessionDisconnected( const RMessage2& aMessage );
       
    88 
       
    89     /**
       
    90      * Appends a preset observer.
       
    91      *
       
    92      * @param   aMessage    IPC message of the request.
       
    93      */
       
    94     void AppendPresetObserverL( const RMessage2& aMessage );
       
    95 
       
    96     /**
       
    97      * Removes a preset change observer.
       
    98      *
       
    99      * @param   aMessage    IPC message of the request.
       
   100      */
       
   101     void RemovePresetObserver( const RMessage2& aMessage );
       
   102 
       
   103     /**
       
   104      * Appends a pending preset.
       
   105      *
       
   106      * @param   aId     Id of the preset.
       
   107      */
       
   108     void AppendPendingPresetL( TInt aId );
       
   109 
       
   110     /**
       
   111      * Commits a pending preset.
       
   112      *
       
   113      * @param   aId     Id of the preset.
       
   114      */
       
   115     void CommitPendingPresetL( TInt aId );
       
   116 
       
   117     /**
       
   118      * Removes a pending preset.
       
   119      *
       
   120      * @param   aId     Id of the preset.
       
   121      */
       
   122     void RemovePendingPreset( TInt aId );
       
   123 
       
   124     /**
       
   125      * Sets the index of a pending preset.
       
   126      *
       
   127      * @param   aId     Id of the preset.
       
   128      * @param   aIndex   Index to set.
       
   129      */
       
   130     void SetPendingPresetIndexL( TInt aId, TInt aIndex );
       
   131 
       
   132     /**
       
   133      * Sets the name of a pending preset.
       
   134      *
       
   135      * @param   aId     Id of the preset.
       
   136      * @param   aName   Name to set.
       
   137      */
       
   138     void SetPendingPresetNameL( TInt aId, const TDesC& aName );
       
   139 
       
   140     /**
       
   141      * Sets the data of a pending preset.
       
   142      *
       
   143      * @param   aId     Id of the preset.
       
   144      * @param   aData   Data to set.
       
   145      */
       
   146     void SetPendingPresetDataL( TInt aId, const TDesC8& aData );
       
   147 
       
   148 // from CServer2
       
   149 
       
   150     /**
       
   151      * @see CServer2::NewSessionL( const TVersion& aVersion, const RMessage2& aMessage ) const
       
   152      */
       
   153     CSession2* NewSessionL( const TVersion& aVersion, const RMessage2& aMessage ) const;
       
   154 
       
   155 // from MPSPresetObserver
       
   156 
       
   157     /**
       
   158      * @see MPSPresetObserver::HandlePresetChangedL( TInt aId, TUid aDataHandler, MPSPresetObserver::TPSReason aReason )
       
   159      */
       
   160     void HandlePresetChangedL( TInt aId, TUid aDataHandler, MPSPresetObserver::TPSReason aReason );
       
   161     
       
   162 // from MPSPropertyChangeObserver
       
   163 
       
   164     /**
       
   165      * @see MPSPropertyChangeObserver::HandlePropertyChangeL( const TUid& aCategory, const TUint aKey, const TInt aValue )
       
   166      */
       
   167     void HandlePropertyChangeL( const TUid& aCategory, const TUint aKey, const TInt aValue );
       
   168     
       
   169     /**
       
   170      * @see MPSPropertyChangeObserver::HandlePropertyChangeL( const TUid& aCategory, const TUint aKey, const TPSTextProperty& aValue )
       
   171      */    
       
   172     void HandlePropertyChangeL( const TUid& aCategory, const TUint aKey, const TPSTextProperty& aValue );
       
   173     
       
   174     /**
       
   175      * @see MPSPropertyChangeObserver::HandlePropertyChangeErrorL( const TUid& aCategory, const TUint aKey, TInt aError)
       
   176      */
       
   177     void HandlePropertyChangeErrorL( const TUid& aCategory, const TUint aKey, TInt aError);    
       
   178 
       
   179 private:
       
   180 
       
   181     /**
       
   182      * Constructor.
       
   183      */
       
   184     CPSServer();
       
   185 
       
   186     /**
       
   187      * Second-phase constructor.
       
   188      */
       
   189     void ConstructL();
       
   190 
       
   191     /**
       
   192      * Returns the index of the preset observer matching the supplied IPC message.
       
   193      *
       
   194      * @param   aMessage    IPC message of the request.
       
   195      * @return  Index of the observer, or <code>KErrNotFound</code> if it doesn't exist.
       
   196      */ 
       
   197     TInt PresetObserverIndex( const RMessage2& aMessage ) const;
       
   198 
       
   199     /**
       
   200      * Returns the index of a pending preset.
       
   201      *
       
   202      * @param   aId     Id of the preset.
       
   203      * @return  Index of the preset, or <code>KErrNotFound</code> if it doesn't exist.
       
   204      */
       
   205     TInt PendingPresetIndex( TInt aId ) const;
       
   206 
       
   207     /**
       
   208      * Notifies the preset observers about preset changes.
       
   209      *
       
   210      * @param   aId         Id of the preset that was changed.
       
   211      * @param   aReason     Reason for the change.
       
   212      */
       
   213     void NotifyPresetObserversL( TInt aId, TUid aDataHandler, MPSPresetObserver::TPSReason aReason );
       
   214 
       
   215     /**
       
   216      * Returns the index of the next unhandled notification related to the last handled notification identifier and the identifier of the observed preset.
       
   217      *
       
   218      * @param   aHandledNotificationId  Identifier of the notification that was most recently handled.
       
   219      * @param   aObservedPresetId       Identifier of the observed preset.
       
   220      * @return  Index of the notification matching the supplied parameters, or <code>KErrNotFound</code> if no such notification exists.
       
   221      */
       
   222     TInt NextUnhandledNotificationIndexById( TUint64 aHandledNotificationId, TInt aObservedPresetId );
       
   223 
       
   224     /**
       
   225      * Cleanup routine for deleting unused cached notifications.
       
   226      *
       
   227      * @param   aSelf   Pointer to self.
       
   228      * @return  Always <code>KErrNone</code>.
       
   229      */
       
   230     static TInt StaticCleanCachedNotifications( TAny* aSelf );
       
   231 
       
   232 private:
       
   233 
       
   234     /** The preset database. */
       
   235     RPSDatabase iDatabase;
       
   236     /** Shutdown timer that is activated after the last client disconnects. */
       
   237     CPSShutdown* iShutdown;
       
   238     /** Cleaner periodic that deletes all unused cached notifications. */
       
   239     CPeriodic* iCachedNotificationCleaner;
       
   240     /** Shutdown delay */
       
   241     TTimeIntervalMicroSeconds32 iShutdownDelay;
       
   242     /** The database cleanup handler. */
       
   243     CPSDatabaseCleanup* iCleanup;
       
   244     /** Presets that are locked, but not yet committed. */
       
   245     RPointerArray<CPSPendingPreset> iPendingPresets;
       
   246     /** File server session. */
       
   247     RFs iFs;
       
   248     /** Preset change notification requests. */
       
   249     RArray<RMessage2> iPresetObservers;    
       
   250     /** Notifications received so far. */
       
   251     RArray<TPSNotifyDataPackage> iNotifications;
       
   252     /* Pub&Sub observer */
       
   253     CPSPropertyObserver* iPropertyObserver;
       
   254     /** Number of connected sessions. */
       
   255     TInt iSessionCount;
       
   256     /** Running unique identifier for cached notifications. */
       
   257     TUint64 iCachedNotificationId;
       
   258     };
       
   259 
       
   260 #endif // C_CPSSERVER_H