PECengine/StorageManager2/ServerSrc/CPEngStorageServer.h
branchRCL_3
changeset 17 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
16:6ca72c0fe49a 17:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 2002 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:  See class description below.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __CPENGSTORAGESERVER_H__
       
    20 #define __CPENGSTORAGESERVER_H__
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32def.h>
       
    24 #include <s32std.h>
       
    25 #include <e32svr.h>
       
    26 #include <s32file.h>	// file server
       
    27 
       
    28 #include "MPEngStorageServer.h"
       
    29 #include "PEngPresenceEngineConsts2.h"
       
    30 
       
    31 
       
    32 // FORWARD DECLARATION
       
    33 class CPEngStorageFolder;
       
    34 class TPEngServerParams;
       
    35 class CPEngSAPChangeObserver;
       
    36 class CPEngSessionSlotId;
       
    37 class CPEngSessionSlotState;
       
    38 class CPEngSessionSlotEvent;
       
    39 class CPEngHandlerListenEvents;
       
    40 class CPEngTimer;
       
    41 
       
    42 /**
       
    43  *  Main Server class of the presence server
       
    44  *  @since 3.0
       
    45  */
       
    46 class   CPEngStorageServer
       
    47             : public CPolicyServer,
       
    48             public MPEngStorageServer
       
    49             //, public MBackupOperationObserver
       
    50     {
       
    51     public:		// Constructors and destructors
       
    52 
       
    53         /**
       
    54          * Two-phased constructor.
       
    55          */
       
    56         static CPEngStorageServer* NewL( TInt aPriority );	// Static constructor
       
    57 
       
    58         /**
       
    59          * Two-phased constructor.
       
    60          */
       
    61         static CPEngStorageServer* NewLC( TInt aPriority );	// Static constructor
       
    62 
       
    63         /**
       
    64          * Destructor.
       
    65          */
       
    66         virtual ~CPEngStorageServer();				// Destructor (virtual)
       
    67 
       
    68     protected:	// Constructors and destructors
       
    69 
       
    70         /**
       
    71          * C++ default constructor.
       
    72          */
       
    73         CPEngStorageServer( TInt aPriority );
       
    74 
       
    75         /**
       
    76          * Symbian 2nd phase constructor
       
    77          */
       
    78         void ConstructL();		// Second phase construct
       
    79 
       
    80     public:		// New methods
       
    81 
       
    82         /*
       
    83          * Starts the server, called from clients Connect() method or from WinsMain()
       
    84          */
       
    85         static TInt ExecuteServerL( TPEngServerParams& aParams );
       
    86 
       
    87         /*
       
    88          *	Stops the server, actually just calls CActiveScheduler::Stop();
       
    89          */
       
    90         void StopServer();
       
    91 
       
    92         /*
       
    93          *	Run server
       
    94          */
       
    95         static void RunServerL( TPEngServerParams& aParams );
       
    96 
       
    97     public: // new functions from MPEngStorageServer
       
    98 
       
    99         /**
       
   100          *  Add subsession to the container
       
   101          *  @see <MPEngStorageServer.h>
       
   102          */
       
   103         void AddSubSessionL( CObject& aSubSession );
       
   104 
       
   105         /**
       
   106          *  Remove subsession from the container
       
   107          *  @see <MPEngStorageServer.h>
       
   108          */
       
   109         void RemoveSubSessionL( CObject& aSubSession );
       
   110 
       
   111 
       
   112         /**
       
   113          *	Start Listening of the Global events
       
   114          *	@see <MPEngStorageServer.h>
       
   115          */
       
   116         void RegisterGlobEventListenerL( const RPEngMessage& aMessage,
       
   117                                          TUint32 aSessionId );
       
   118 
       
   119         /**
       
   120          *	Cancel specified asynchronous request of the client
       
   121          *	@see <MPEngStorageServer.h>
       
   122          */
       
   123         void CancelRequestL( const RPEngMessage& aMessage,
       
   124                              TUint32 aSessionId );
       
   125 
       
   126         /**
       
   127          *  Cancel all session's asynchronous request
       
   128          *	@see <MPEngStorageServer.h>
       
   129          */
       
   130         void CancelAllSessionRequests( TUint32 aSessionId );
       
   131 
       
   132         /**
       
   133          *	Reload Asynchronous scout of the async observer
       
   134          *	@see <MPEngStorageServer.h>
       
   135          */
       
   136         void ReloadAsynchronousScoutL( const RPEngMessage& aMessage,
       
   137                                        TUint32 aSessionId );
       
   138 
       
   139         /**
       
   140          *	Create Session slot Folder
       
   141          *	@see <MPEngStorageServer.h>
       
   142          */
       
   143         void CreateSessionFolderL( const RPEngMessage& aMessage );
       
   144 
       
   145         /**
       
   146          *	Remove Session slot Folder
       
   147          *	@see <MPEngStorageServer.h>
       
   148          */
       
   149         void RemoveSessionFolderL( const RPEngMessage& aMessage );
       
   150 
       
   151         /**
       
   152          *	Get session slot state
       
   153          *	@see <MPEngStorageServer.h>
       
   154          */
       
   155         void SessionStateL( const RPEngMessage& aMessage );
       
   156 
       
   157         /**
       
   158          *	Get All Session slots states
       
   159          *	@see <MPEngStorageServer.h>
       
   160          */
       
   161         void AllSessionStatesL( const RPEngMessage& aMessage );
       
   162 
       
   163         /**
       
   164          *	Get Storage Folder Instance and return its pointer
       
   165          *	@see <MPEngStorageServer.h>
       
   166          */
       
   167         CPEngStorageFolder* StorageFolderL(
       
   168             const RPEngMessage& aMessage );
       
   169 
       
   170         /**
       
   171          *	Notify new global Session Slot event
       
   172          *	@see <MPEngStorageServer.h>
       
   173          */
       
   174         void NotifyGlobalEvent( const TDesC8& aGlobalEvent );
       
   175 
       
   176         /**
       
   177          *  Notify Error to the listeners of new events
       
   178          *	@see <MPEngStorageServer.h>
       
   179          */
       
   180         void NotifyError( TInt aError );
       
   181 
       
   182         /**
       
   183          *	Check if passed Application Id is registered for
       
   184          *	defined session slot
       
   185          *	@see <MPEngStorageServer.h>
       
   186          */
       
   187         void IsAppIdRegisteredL( const RPEngMessage& aMessage );
       
   188 
       
   189         /**
       
   190          *	Is back up operation active
       
   191          *	@see <MPEngStorageServer.h>
       
   192          */
       
   193         TBool BackUpActive();
       
   194 
       
   195 
       
   196         /**
       
   197          *  Wipe Session Slot folder
       
   198          *	@see <MPEngStorageServer.h>
       
   199          */
       
   200         void WipeSessionSlotFolderL( const RPEngMessage& aMessage );
       
   201 
       
   202 
       
   203 
       
   204     public: // Reference counted access related functions
       
   205 
       
   206         /**
       
   207          *	Session has been created
       
   208          *	More in the file <MPEngStorageServer.h>
       
   209          *
       
   210          *	@since 3.0
       
   211          */
       
   212         void SessionCreated();
       
   213 
       
   214         /**
       
   215          *	Session is dying, check if server is needed
       
   216          *	More in the file <MPEngStorageServer.h>
       
   217          *
       
   218          *	@since 3.0
       
   219          */
       
   220         void SessionDied();
       
   221 
       
   222         /**
       
   223          *  Timer expired, kill server if not needed anymore
       
   224          *
       
   225          *	@since 3.0
       
   226          */
       
   227         void TimeExpired();
       
   228 
       
   229 
       
   230     public:		// Methods derived from CServer2
       
   231 
       
   232         /*
       
   233          *	Called when new client is connecting, version number of the client is checked here.
       
   234          */
       
   235         CSession2* NewSessionL( const TVersion& aVersion, const RMessage2& aMessage ) const;
       
   236 
       
   237 
       
   238 
       
   239     private:	// New methods
       
   240 
       
   241         /*
       
   242          *	Calls CActiveScheduler::Start()
       
   243          */
       
   244         void StartServer();
       
   245 
       
   246         /**
       
   247          *	Read Session ID from the client's message
       
   248          *
       
   249          *  @since 3.0
       
   250          *  @param aMessage client's message
       
   251          *  @return session slot ID class, ownership transferred
       
   252          */
       
   253         CPEngSessionSlotId* TranslateSessionIdLC( const RPEngMessage& aMessage );
       
   254 
       
   255         /**
       
   256          *	Try to find session Folder if it is active
       
   257          *
       
   258          *  @since 3.0
       
   259          *  @param aSessionId session Id to find folder for
       
   260          *  @return session Id class if folder is loaded, NULL if not
       
   261          */
       
   262         CPEngStorageFolder* FindStorageFolder(
       
   263             const CPEngSessionSlotId& aSessionId );
       
   264 
       
   265         /**
       
   266          *	Load storage folder,
       
   267          *	there is open handle to the returner pointer
       
   268          *
       
   269          *	@since 3.0
       
   270          */
       
   271         CPEngStorageFolder* LoadStorageFolderL(
       
   272             const CPEngSessionSlotId& aSessionId );
       
   273 
       
   274         /**
       
   275          *	Load session slot state
       
   276          *
       
   277          *  @since 3.0
       
   278          *  @param aSessId session slot Id
       
   279          *	@param aCreate flag if session shall be created if needed
       
   280          *	@param aSessState returned session slot state
       
   281          *	@param aStorageFolder returned storage folder, if loaded
       
   282          *	@param aStateFileName returned file name of session state
       
   283          *  @return number of items on clean up stack added by function
       
   284          */
       
   285         inline TInt LoadSessionStateLCX(
       
   286             CPEngSessionSlotId& aSessId,
       
   287             TBool aCreate,
       
   288             CPEngSessionSlotState*& aSessState,
       
   289             CPEngStorageFolder*& aStorageFolder,
       
   290             HBufC*& aStateFileName );
       
   291         /**
       
   292          *	Read State file from permanent store if it does exists
       
   293          *
       
   294          *  @since 3.0
       
   295          *  @param aSessionId session Identification
       
   296          *  @param aFileName file name of the state file
       
   297          *  @return state of the session folder
       
   298          */
       
   299         CPEngSessionSlotState* ReadSessionStatePermanentLC(
       
   300             const CPEngSessionSlotId& aSessionId,
       
   301             HBufC*& aFileName );
       
   302 
       
   303         /**
       
   304          *	Modify State file name to folder name
       
   305          *
       
   306          *  @since 3.0
       
   307          *  @param aFileName which will be altered to folder name
       
   308          */
       
   309         inline void UpdateFileToFolderName( TDes& aFileName );
       
   310 
       
   311         /**
       
   312          *	Create session directory in the file system
       
   313          *
       
   314          *  @since 3.0
       
   315          *  @param aFileName file name of the session slot state file
       
   316          */
       
   317         inline void CreateSessionDirectoryL( TDes& aFileName );
       
   318 
       
   319         /**
       
   320          *	Store data to the file
       
   321          *
       
   322          *  @since 3.0
       
   323          *  @param aFileName file name of the target file
       
   324          *	@param aData date to be stored into the file
       
   325          *	@return KErrNone if it went OK or system wide error code
       
   326          */
       
   327         inline TInt StoreFile( const TDesC& aFileName, const TDesC8& aData );
       
   328 
       
   329         /**
       
   330          *	Read data from the file
       
   331          *
       
   332          *  @since 3.0
       
   333          *  @param aFileName file name of the target file
       
   334          *	@return buffer with the data of the file
       
   335          */
       
   336         inline void ReadFileL( const TDesC& aFileName,
       
   337                                RBuf8& aBuff );
       
   338 
       
   339         /**
       
   340          *	Clean storage from session
       
   341          *
       
   342          *  @since 3.0
       
   343          *  @param file name of the session file
       
   344          *	@return KErrNone if cleaning goes fine
       
   345          */
       
   346         inline TInt CleanStorageFromSessionL( TDes& aFileName );
       
   347 
       
   348         /**
       
   349          *	Create Buffer with global event
       
   350          *
       
   351          *  @since 3.0
       
   352          *  @param aState session state
       
   353          *	@param aEvent event notification
       
   354          *  @return new session slot event
       
   355          */
       
   356         inline CPEngSessionSlotEvent* PackGlobEventLC(
       
   357             CPEngSessionSlotState& aState,
       
   358             TPEngNWSessionSlotEvent aEvent,
       
   359             const TDesC& aAppId );
       
   360 
       
   361         /**
       
   362          *	Update Session Slot state
       
   363          *
       
   364          *  @since 3.0
       
   365          *  @param aFolder folder of the session, can be NULL
       
   366          *	@param aState state of the session slot
       
   367          *	@param aEvent new session slot event
       
   368          *	@param aFileName file name of the state of the session
       
   369          *
       
   370          */
       
   371         inline void UpdateSessionSltStateL(
       
   372             CPEngStorageFolder* aFolder,
       
   373             CPEngSessionSlotState& aState,
       
   374             CPEngSessionSlotEvent& aEvent,
       
   375             TDes& aFileName );
       
   376 
       
   377 
       
   378     private:	// New notification engine functions
       
   379 
       
   380         /**
       
   381          *	Find Request Handler
       
   382          *
       
   383          *	@since 3.0
       
   384          *	@param aSessionID Session ID
       
   385          *	@param aFunction request function
       
   386          *	@return pointer to Request Handler it it exists or NULL
       
   387          */
       
   388         inline CPEngHandlerListenEvents* FindRequestHandler( TUint32 aSessionId,
       
   389                                                              TPEngStorageServerMessages aFunction );
       
   390 
       
   391     private:	// Data
       
   392 
       
   393         /// OWN: Container collection
       
   394         ///      All containers created by this collection are also
       
   395         ///      owned by this colletion
       
   396         CObjectConIx*						    iContainerIx;
       
   397 
       
   398         /// OWN: Container of Sub sesssions
       
   399         ///      Owned over iContainerIx
       
   400         CObjectCon*								iSubSessionCnt;
       
   401 
       
   402         /// OWN: Container of the Storage Cages
       
   403         ///      Owned over iContainerIx
       
   404         CObjectCon*								iFoldersCnt;
       
   405 
       
   406         /// OWN: Container with the Observers,
       
   407         ///      Owned over iContainerIx
       
   408         CObjectCon*								iObserversCnt;
       
   409 
       
   410 
       
   411         /// OWN: Flag if server is running
       
   412         TBool									iRunning;
       
   413 
       
   414 
       
   415         /// OWN: File server client on the Storage Server
       
   416         RFs										iFs;
       
   417 
       
   418         /// OWN: Session count
       
   419         TInt									iSessCount;
       
   420 
       
   421         /// OWN: Back up operation active
       
   422         TBool									iBackUpActive;
       
   423 
       
   424         /// OWN: Temp folder Name
       
   425         HBufC*									iTempFolder;
       
   426 
       
   427         /// OWN: Server shut down timer
       
   428         CPEngTimer*								iTimeOut;
       
   429 
       
   430         /// OWN: Communication buffer to minimize allocations
       
   431         RBuf16									iBuff16;
       
   432 
       
   433         /// OWN: Communication buffer to minimize allocations
       
   434         RBuf8									iBuff8;
       
   435     };
       
   436 
       
   437 #endif      //  __CPENGSTORAGESERVER_H__
       
   438