PECengine/PresenceServer2/ServerSrc/CPEngCSPSessManager.h
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     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:  One Session manager of the presence server
       
    15 * 				 Handles all management concerning one network session
       
    16 *  				 Opening, closing, ownership handling, updating
       
    17 *  				 of Session related data to network
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 #ifndef __CPENGCSPSESSMANAGER_H__
       
    24 #define __CPENGCSPSESSMANAGER_H__
       
    25 
       
    26 //  INCLUDES
       
    27 #include	<e32base.h>
       
    28 
       
    29 #include	"MPEngRequestHandlerObserver.h"
       
    30 #include	"MPEngSessionStatusObserver.h"
       
    31 
       
    32 #include	"PEngPresenceEngineConsts2.h"
       
    33 #include	"RPEngStorageAdminSubClient.h"
       
    34 
       
    35 
       
    36 // FORWARD DECLARATIONS
       
    37 class	MPEngRequestHandler;
       
    38 class	CPEngIncomingDataHandler;
       
    39 class	MPEngServer;
       
    40 class	CPEngSessionSlotId;
       
    41 class	CPEngAppAccessContainer;
       
    42 class	MPEngSubSession;
       
    43 class	MPEngTransactionFactory;
       
    44 class   RPEngStorageAdminClient;
       
    45 class   MPEngAccessHandler;
       
    46 class   MPEngPureDataHandler;
       
    47 class   RPEngMessage;
       
    48 
       
    49 // CLASS DECLARATION
       
    50 /**
       
    51  *  One Session manager of the presence server
       
    52  *  Handles all management concerning one network session
       
    53  *  Opening, closing, ownership handling, updating
       
    54  *  of Session related data to network
       
    55  *
       
    56  *  @lib PEngServer2
       
    57  *  @since 3.0
       
    58  */
       
    59 NONSHARABLE_CLASS( CPEngCSPSessManager ):
       
    60         public CBase,
       
    61         public MPEngRequestHandlerObserver,
       
    62         public MPEngSessionStatusObserver
       
    63     {
       
    64 public:  // Constructors and destructor
       
    65 
       
    66     /**
       
    67      * Two-phased constructor.
       
    68      */
       
    69     static CPEngCSPSessManager* NewLC( MPEngServer& aServer,
       
    70     const CPEngSessionSlotId& aSessId,
       
    71     RPEngStorageAdminClient& aAdmin );
       
    72 
       
    73     /**
       
    74      * Destructor.
       
    75      */
       
    76     ~CPEngCSPSessManager();
       
    77 
       
    78 private: // new function of MPEngRequestHandlerObserver
       
    79     /**
       
    80      *  Remove calling request handler from array of pending requests
       
    81      *
       
    82      *  @see <MPEngRequestHandlerObserver.h>
       
    83      *  @since 3.0
       
    84      */
       
    85     void CompleteRequestHandler(
       
    86         MPEngRequestHandler* aRequestHandler );
       
    87 
       
    88     /**
       
    89      *  Set Session slot state to open
       
    90      *
       
    91      *  @see <MPEngRequestHandlerObserver.h>
       
    92      *  @since 3.0
       
    93      */
       
    94     void SetCSPSessionOpenedL();
       
    95 
       
    96 private: // ne functions from MPEngSessionStatusObserver
       
    97 
       
    98     /**
       
    99      *	Handle Session status change
       
   100      *
       
   101      *  @since 3.0
       
   102      *
       
   103      *  @param new session slot state
       
   104      *  @param session slot event
       
   105      */
       
   106     void StatusChangedL( TPEngNWSessionSlotState aNewState,
       
   107                          TPEngNWSessionSlotEvent aNewEvent );
       
   108 
       
   109 public: // Slot management support
       
   110 
       
   111     /**
       
   112      *  Open method for clean up stack support
       
   113      *
       
   114      *  @since 3.0
       
   115      */
       
   116     void Open();
       
   117 
       
   118     /**
       
   119      *  Close method for clean up stack support
       
   120      *
       
   121      *  @since 3.0
       
   122      */
       
   123     void Close();
       
   124 
       
   125     /**
       
   126      *  Open method for sub-sessions
       
   127      *	Reference to the Sub-session is stored
       
   128      *	for future notifications
       
   129      *
       
   130      *  @since 3.0
       
   131      *	@param aServSubSession server sub-session
       
   132      */
       
   133     void OpenL( MPEngSubSession& aServSubSession );
       
   134 
       
   135     /**
       
   136      *  Close method for the sub-session
       
   137      *
       
   138      *  @since 3.0
       
   139      * 	@param aServSubSession server sub-session
       
   140      */
       
   141     void Close( MPEngSubSession* aServSubSession );
       
   142 
       
   143     /**
       
   144      *	Open reference to the session manager by the app Id
       
   145      *
       
   146      *  @since 3.0
       
   147      *  @param aAppId application Id to open reference
       
   148      */
       
   149     void AttachAppIdL( const TDesC& aAppId );
       
   150 
       
   151     /**
       
   152      *	Close reference to the session manager by the app Id
       
   153      *
       
   154      *  @since 3.0
       
   155      *  @param aAppId application Id to open reference
       
   156      */
       
   157     void DetachAppId( const TDesC& aAppId );
       
   158 
       
   159     /**
       
   160      *  Check if application Id is active
       
   161      *
       
   162      *  @since 3.0
       
   163      *  @param aAppId application Id
       
   164      */
       
   165     void AppIdActiveL( const TDesC& aAppId );
       
   166 
       
   167     /**
       
   168      *	Reserve Session slot for Process Id
       
   169      *
       
   170      *  @since 3.0
       
   171      *  @param aAppId application Id
       
   172      *  @param aProcessId process Id to reserve
       
   173      */
       
   174     void ReserveProcessL( const TDesC& aAppId,
       
   175                           const TDesC& aProcessId );
       
   176 
       
   177     /**
       
   178      *	Activate Process id
       
   179      *  Function leaves if there is not such a combination of
       
   180      *  process Id and application id registered
       
   181      *
       
   182      *  @since 3.0
       
   183      *  @param aAppId application Id
       
   184      *  @param aProcessId process Id to activate
       
   185      */
       
   186     void ActivateProcessL( const TDesC& aAppId,
       
   187                            const TDesC& aProcessId );
       
   188 
       
   189     /**
       
   190      *  Session slot Id
       
   191      *
       
   192      *  @since 3.0
       
   193      *  @return session slot Id
       
   194      */
       
   195     const CPEngSessionSlotId& SessionId() const;
       
   196 
       
   197 public: // Request handling
       
   198 
       
   199     /**
       
   200      *  Handle asynchronous request
       
   201      *
       
   202      *  @since 3.0
       
   203      *  @param aMessage RPEngMessage of the request
       
   204      *  @param aServSubSession server sub-session
       
   205      *  @param aServSessionId server session Id
       
   206      *  @param aServSubSessionId server sub-session Id of the request
       
   207      */
       
   208     void HandleAsynchronousRequestL(
       
   209         const RPEngMessage& aMessage,
       
   210         MPEngSubSession& aServSubSession,
       
   211         TInt32 aServSessionId,
       
   212         TInt   aServSubSessionId );
       
   213 
       
   214     /**
       
   215      *  Handle synchronous request
       
   216      *
       
   217      *  @since 3.0
       
   218      *  @param aMessage RPEngMessage of the request
       
   219      *  @param aServSessionId server session Id
       
   220      *  @param aServSubSessionId server sub-session Id of the request
       
   221      */
       
   222     void HandleSynchronousRequestL(
       
   223         const RPEngMessage& aMessage,
       
   224         TInt32 aServSessionId,
       
   225         TInt   aServSubSessionId );
       
   226 
       
   227     /**
       
   228      *	Handle Log In Request
       
   229      *
       
   230      *	@since 3.0
       
   231      *  @param aMessage RPEngMessage of the request
       
   232      *  @param aServSubSession server sub-session
       
   233      *  @param aServSessionId server session Id
       
   234      *  @param aServSubSessionId server sub-session Id of the request
       
   235      */
       
   236     void HandleLogInRequestL(	const RPEngMessage& aMessage,
       
   237                               MPEngSubSession& aSubSession,
       
   238                               TInt32 aServSessionId,
       
   239                               TInt   aServSubSessionId );
       
   240 
       
   241     /**
       
   242      *	Handle Log Oout Request
       
   243      *
       
   244      *	@since 3.0
       
   245      *  @param aMessage RPEngMessage of the request
       
   246      *  @param aServSubSession server sub-session
       
   247      *  @param aServSessionId server session Id
       
   248      *  @param aServSubSessionId server sub-session Id of the request
       
   249      */
       
   250     void HandleForceLogOutRequestL( const RPEngMessage& aMessage,
       
   251                                     MPEngSubSession& aSubSession,
       
   252                                     TInt32 aServSessionId,
       
   253                                     TInt   aServSubSessionId );
       
   254 
       
   255     /**
       
   256      *  Close reference to the session manager by the app Id
       
   257      *	Asynchronous version
       
   258      *
       
   259      *  @since 3.0
       
   260      *  @param aMessage RPEngMessage of the request
       
   261      *  @param aServSubSession server sub-session
       
   262      *  @param aServSessionId server session Id
       
   263      *  @param aServSubSessionId server sub-session Id of the request
       
   264      */
       
   265     void HandleDetachAppIdL( const RPEngMessage& aMessage,
       
   266                              MPEngSubSession& aSubSession,
       
   267                              TInt32 aServSessionId,
       
   268                              TInt   aServSubSessionId );
       
   269 
       
   270     /**
       
   271      *  Cancel particular asynchronous request
       
   272      *	Cancel all asynchronous request from the Server Session
       
   273      *  Cancel all asynchronous request from the Server Sub-session
       
   274      *
       
   275      *  @since 3.0
       
   276      *  @param aMessage RPEngMessage of the request
       
   277      *  @param aServSessionId server session Id
       
   278      *  @param aServSubSessionId server sub-session Id of the request
       
   279      */
       
   280     void CancelAsynchronousRequest(
       
   281         const RPEngMessage& aMessage,
       
   282         TInt32 aServSessionId,
       
   283         TInt   aServSubSessionId );
       
   284 
       
   285     void CancelAllSessionRequests(
       
   286         TInt32 aServSessionId );
       
   287 
       
   288     void CancelAllSubSessionRquests(
       
   289         TInt32 aServSessionId,
       
   290         TInt   aServSubSessionId );
       
   291 
       
   292 private:	// Function for handling of resources
       
   293 
       
   294     /**
       
   295      *  Load resources for the online state of the session
       
   296      *
       
   297      *  @since 3.0
       
   298      */
       
   299     void LoadResourcesL();
       
   300 
       
   301     /**
       
   302      *  Unloads resources for the offline state of Session slot
       
   303      *
       
   304      *  @since 3.0
       
   305      */
       
   306     void UnloadResources();
       
   307 
       
   308 private:	// request management
       
   309 
       
   310     /**
       
   311      *  Check if request is allowed
       
   312      *
       
   313      *
       
   314      *  @since 3.0
       
   315      *  @param aRequestFunction request function
       
   316      *  @param aServSessionId server session Id of the request
       
   317      *	@param aServSubSessionId server sub-session Id of the request
       
   318      */
       
   319     void CheckRequestValidityL (
       
   320         TInt aRequestFunction,
       
   321         TInt32 aServSessionId,
       
   322         TInt   aServSubSessionId );
       
   323 
       
   324     /**
       
   325      *  Find defined request in session manager
       
   326      *
       
   327      *  @since 3.0
       
   328      *  @param aRequestFunction request function to find
       
   329      *  @param aServSessionId session to look in
       
   330      *  @param aServSubSessionId sub-session to look in
       
   331      *  @return index or KerrNotFound
       
   332      */
       
   333     TInt FindRequest( TInt aRequestFunction );
       
   334 
       
   335     TInt FindRequestInSession(
       
   336         TInt aRequestFunction,
       
   337         TInt32 aServSessionId );
       
   338 
       
   339     TInt FindRequestInSubSession(
       
   340         TInt aRequestFunction,
       
   341         TInt32 aServSessionId,
       
   342         TInt   aServSubSessionId );
       
   343 
       
   344     /**
       
   345      *	Handle Send new data Request
       
   346      *
       
   347      *	@since 3.0
       
   348      *	@param aMessage RPEngMessage from Client
       
   349      *	@param aServSubSession server sub-session
       
   350      *	@param aServSessionId server session id
       
   351      *	@param aServSubSessionId server sub-session Id
       
   352      */
       
   353     void HandleUpdateDataRequestL( const RPEngMessage& aMessage,
       
   354                                    MPEngSubSession& aServSubSession,
       
   355                                    TInt32 aServSessionId,
       
   356                                    TInt   aServSubSessionId );
       
   357 
       
   358     /**
       
   359      *  Do Log In to the CSP session
       
   360      *
       
   361      *  @since 3.0
       
   362      *	@param aMessage RPEngMessage from Client
       
   363      *	@param aServSubSession server sub-session
       
   364      *	@param aServSessionId server session id
       
   365      *	@param aServSubSessionId server sub-session Id
       
   366      */
       
   367     void DoLogInL( const RPEngMessage& aMessage,
       
   368                    MPEngSubSession& aServSubSession,
       
   369                    TInt32 aServSessionId,
       
   370                    TInt   aServSubSessionId );
       
   371 
       
   372     /**
       
   373      *  Do log out from the CSP session
       
   374      *
       
   375      *  @since 3.0
       
   376      *	@param aMessage RPEngMessage from Client
       
   377      *	@param aServSubSession server sub-session
       
   378      *	@param aServSessionId server session id
       
   379      *	@param aServSubSessionId server sub-session Id
       
   380      */
       
   381     void DoLogOutL( const RPEngMessage& aMessage,
       
   382                     MPEngSubSession& aServSubSession,
       
   383                     TInt32 aServSessionId,
       
   384                     TInt   aServSubSessionId );
       
   385 
       
   386 private: // Helping functions
       
   387 
       
   388     /**
       
   389      *  Find Access counter
       
   390      *
       
   391      *  @since 3.0
       
   392      *  @param aAppId application Id
       
   393      *  @return pointer to access counter if found, NULL if not found
       
   394      */
       
   395     CPEngAppAccessContainer* AccessCounter( const TDesC& aAppId );
       
   396 
       
   397     /**
       
   398      *  Check reference counter and delete this object if needed
       
   399      *  @since 3.0
       
   400      */
       
   401     void CheckReferenceAccessD();
       
   402 
       
   403     /**
       
   404      *  Unload Transaction factories
       
   405      *  @since 3.0
       
   406      */
       
   407     void UnloadTransactionFactories();
       
   408 
       
   409     /**
       
   410      *  Reset access Containers
       
   411      *  @since 3.0
       
   412      */
       
   413     void ResetAccessContainers();
       
   414 
       
   415     /**
       
   416      *  Inform sub-session about app Id disconnection
       
   417      *  @since 3.0
       
   418      *  @param aAppId disconnected app Id
       
   419      */
       
   420     void NotifyDisconnectedAppId( const TDesC& aAppId );
       
   421 
       
   422     /**
       
   423      *  Inform sub-sessions about CPS close state
       
   424      *  @since 3.0
       
   425      */
       
   426     void NotifyCPSClose();
       
   427 
       
   428     /**
       
   429      *  Notify Storage Server about new event
       
   430      *  @since 3.0
       
   431      *  @param aEvent new event to notify
       
   432      *  @param aAppId application id event is related
       
   433      *  @param aAppIdState state of the application id
       
   434      */
       
   435     void NotifyNewEventL( TPEngNWSessionSlotEvent aEvent,
       
   436                           const TDesC& aAppId,
       
   437                           TPEngNWSessionSlotState aAppIdState );
       
   438 
       
   439     /**
       
   440      *  Leaves with error code if not connected.
       
   441      */
       
   442     void LeaveIfNotConnectedL() const;
       
   443 
       
   444 
       
   445 
       
   446 
       
   447 private:
       
   448 
       
   449     /**
       
   450      * C++ default constructor.
       
   451      */
       
   452     CPEngCSPSessManager( MPEngServer& aServer );
       
   453 
       
   454     /**
       
   455      * By default Symbian 2nd phase constructor is private.
       
   456      */
       
   457     void ConstructL( const CPEngSessionSlotId& aSessId,
       
   458                      RPEngStorageAdminClient& aAdmin );
       
   459 
       
   460 private:    // Data
       
   461 
       
   462     /// OWN: Access Plain Access Count, used by cleanUp support
       
   463     TInt											iAccessCount;
       
   464 
       
   465     /// OWN: Session slot Id
       
   466     CPEngSessionSlotId*								iSessionSlotId;
       
   467 
       
   468     /// OWN: Session state
       
   469     TPEngNWSessionSlotState							iState;
       
   470 
       
   471     /// OWN: Container of Access Counters
       
   472     CObjectCon*										iAccessCounters;
       
   473 
       
   474     ///	REF: Server
       
   475     MPEngServer&									iServer;
       
   476 
       
   477     /// OWN: Server sub-sessions,
       
   478     ///      Elements REFerenced
       
   479     RPointerArray<MPEngSubSession>					iServSubSessions;
       
   480 
       
   481     /// OWN: Storage Manager admin client
       
   482     RPEngStorageAdminSubClient						iStoreAdmin;
       
   483 
       
   484     /// OWN: Array of active request handlers
       
   485     ///      Elements OWNed
       
   486     RPointerArray<MPEngRequestHandler>				iRequestHandlers;
       
   487 
       
   488     /// OWN: Transaction factories
       
   489     RPointerArray<MPEngTransactionFactory>			iTransFactories;
       
   490 
       
   491     /// OWN: Online Plugins loaded
       
   492     TBool 											iPluginsLoaded;
       
   493 
       
   494     /// OWN: Access handlers
       
   495     MPEngAccessHandler*								iAccessHandler;
       
   496 
       
   497     /// OWN: pure data handler
       
   498     MPEngPureDataHandler*							iPureDataHandler;
       
   499 
       
   500     /// OWN: list of Incoming Listen Data Handlers
       
   501     ///      Elements OWNed
       
   502     RPointerArray<CPEngIncomingDataHandler>			iIncomingHandlers;
       
   503     };
       
   504 
       
   505 #endif      // __CPENGCSPSESSMANAGER_H__
       
   506 
       
   507 // End of File