presadap12/Parser2/Inc/CPEngSessionSlotState.h
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Presence Engine Session Slot State container.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef __CPENGSESSIONSLOTSTATE_H__
       
    19 #define __CPENGSESSIONSLOTSTATE_H__
       
    20 
       
    21 //  INCLUDES
       
    22 #include    <E32Base.h>
       
    23 #include    <BaDesca.h>
       
    24 #include    "PEngPresenceEngineConsts2.h"
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 // DATA TYPES
       
    30 
       
    31 /**
       
    32  * Data selection enmumeration to select
       
    33  * which parts of the CPEngSessionSlotState
       
    34  * to stream.
       
    35  *
       
    36  * @since 3.0
       
    37  */
       
    38 enum TPEngDataSelection
       
    39     {
       
    40     /**
       
    41      * Session Slot Id part.
       
    42      */
       
    43     EIdentification  = 0x00000001,
       
    44 
       
    45     /**
       
    46      * Registered application IDs part.
       
    47      */
       
    48     ERegistredIDs    = 0x00000010,
       
    49 
       
    50     /**
       
    51      * State specific data.
       
    52      * Active Application Ids and the state part.
       
    53      */
       
    54     EStateSpecific   = 0x00000100,
       
    55 
       
    56 
       
    57 
       
    58     //Mixed fields for real storage purposes.
       
    59 
       
    60     /**
       
    61      * Only Session Slot Id and Registered application IDs.
       
    62      */
       
    63     EPermanentData   = EIdentification | ERegistredIDs,
       
    64 
       
    65 
       
    66     /**
       
    67      * Whole state container data without the Slot ID.
       
    68      */
       
    69     EPureState       =  ERegistredIDs | EStateSpecific,
       
    70 
       
    71 
       
    72     /**
       
    73      * Whole state container data.
       
    74      */
       
    75     EWholeState      = EIdentification | ERegistredIDs | EStateSpecific,
       
    76 
       
    77     };
       
    78 
       
    79 
       
    80 
       
    81 // FORWARD DECLARATIONS
       
    82 class RWriteStream;
       
    83 class RReadStream;
       
    84 class CPEngSessionSlotId;
       
    85 class CPEngSessionSlotEvent;
       
    86 
       
    87 
       
    88 
       
    89 
       
    90 // CLASS DECLARATION
       
    91 
       
    92 
       
    93 /**
       
    94 * Presence Engine Session Slot State container.
       
    95 * It is used infernally by the PE for transportation
       
    96 * of the slot state between the engine components
       
    97 * and also to maintain the slot state both
       
    98 * in permanent and cached memory.
       
    99 *
       
   100 * @since 3.0
       
   101 */
       
   102 class CPEngSessionSlotState : public CBase
       
   103     {
       
   104     public: // Construction
       
   105 
       
   106         /**
       
   107          * Instantiates CPEngSessionSlotState object.
       
   108          *
       
   109          * @return New CPEngSessionSlotState instance.
       
   110          */
       
   111         IMPORT_C static CPEngSessionSlotState* NewL( );
       
   112         IMPORT_C static CPEngSessionSlotState* NewLC( );
       
   113 
       
   114 
       
   115         /**
       
   116          * Destructor.
       
   117          */
       
   118         ~CPEngSessionSlotState();
       
   119 
       
   120     protected:
       
   121 
       
   122         /**
       
   123          * C++ constructor.
       
   124          */
       
   125         CPEngSessionSlotState();
       
   126 
       
   127 
       
   128 
       
   129     public: // Getters
       
   130 
       
   131         /**
       
   132          * Session Slot ID identification
       
   133          *
       
   134          * @since 3.0
       
   135          * @return session slot ID identification class
       
   136          */
       
   137         IMPORT_C CPEngSessionSlotId& SessionSlotId( ) const;
       
   138 
       
   139 
       
   140         /**
       
   141          * Session slot Online state
       
   142          *
       
   143          * @since 3.0
       
   144          * @return session slot state
       
   145          */
       
   146         IMPORT_C TPEngNWSessionSlotState SessionSlotState() const;
       
   147 
       
   148 
       
   149         /**
       
   150          * Gets list of Application IDs which are registered
       
   151          * to this Session Slot.
       
   152          *
       
   153          * @since 3.0
       
   154          * @return descriptor array with application IDs
       
   155          */
       
   156         IMPORT_C const MDesC16Array& RegisteredApplications() const;
       
   157 
       
   158 
       
   159         /**
       
   160          * Gets list of Application IDs which are active with
       
   161          * this Session Slot.
       
   162          *
       
   163          * @since 3.0
       
   164          * @return descriptor array with application IDs
       
   165          */
       
   166         IMPORT_C const MDesC16Array& ActiveApplications() const;
       
   167 
       
   168 
       
   169         /**
       
   170          * Gets certain application state from
       
   171          * the session slot state.
       
   172          *
       
   173          * @since 3.0
       
   174          * @param aAppId Application Id for which to get the state.
       
   175          * @return State of the requested application Id.
       
   176          */
       
   177         IMPORT_C TPEngNWSessionSlotState AppState( const TDesC& aAppId ) const;
       
   178 
       
   179 
       
   180         /**
       
   181          * Checks if application is registered to this session slot.
       
   182          * If application is not registered, leaves with KErrNotFound
       
   183          *
       
   184          * @since 3.0
       
   185          * @param aAppId Application Id to check.
       
   186          */
       
   187         IMPORT_C void ApplicationRegisteredL( const TDesC& aAppId ) const;
       
   188 
       
   189 
       
   190 
       
   191 
       
   192     public: // Setters
       
   193 
       
   194         /**
       
   195          * Set session slot ID.
       
   196          *
       
   197          * @since 3.0
       
   198          * @param aSlotId New session slot Id.
       
   199          * @param aOwnershipTransfered ETrue if aSlotId ownership is
       
   200          *        transfered to CPEngSessionSlotState instance
       
   201          */
       
   202         IMPORT_C void SetSessionSlotId( CPEngSessionSlotId& aSlotId,
       
   203                                         TBool aOwnershipTransfered = EFalse );
       
   204 
       
   205 
       
   206         /**
       
   207          * Sets Session Slot State as closed.
       
   208          *
       
   209          * @since 3.0
       
   210          */
       
   211         IMPORT_C void SetSessionSlotStateClosed();
       
   212 
       
   213 
       
   214         /**
       
   215          * Update Session Slot State based on the event.
       
   216          *
       
   217          * @since 3.0
       
   218          * @param aSessEvent Session Slot event.
       
   219          * @return ETrue if state was updated because of event and
       
   220          *         state needs to be stored to permanent storage.
       
   221          *         Else EFalse.
       
   222          */
       
   223         IMPORT_C TBool UpdateStateL( const CPEngSessionSlotEvent& aSessEvent );
       
   224 
       
   225 
       
   226         /**
       
   227          * Updates and commits the Session Slot State
       
   228          * based on the event.
       
   229          *
       
   230          * @since 3.0
       
   231          * @param aSessEvent Session Slot event.
       
   232          * @return ETrue if state was updated because of event and
       
   233          *         state needs to be stored to permanent storage.
       
   234          *         Else EFalse.
       
   235          */
       
   236         IMPORT_C TBool UpdateAndCommitStateL( const CPEngSessionSlotEvent& aSessEvent );
       
   237 
       
   238 
       
   239         /**
       
   240          * Rollback last change
       
   241          *
       
   242          * @since 3.0
       
   243          */
       
   244         IMPORT_C void RollBackLastUpdate();
       
   245 
       
   246 
       
   247         /**
       
   248          * Commit last change
       
   249          *
       
   250          * @since 3.0
       
   251          */
       
   252         IMPORT_C void CommitLastUpdate();
       
   253 
       
   254 
       
   255 
       
   256     public: // Export import of the state
       
   257 
       
   258         /**
       
   259          * Internalize Session Slot state from stream.
       
   260          *
       
   261          * @since 3.0
       
   262          * @param aStream stream to internalize from
       
   263          * @param aSelection selection flag describing what to internalize
       
   264          */
       
   265         IMPORT_C void InternalizeL( RReadStream& aStream,
       
   266                                     TPEngDataSelection aSelection );
       
   267 
       
   268 
       
   269         /**
       
   270          * Externalize Session Slot state to stream
       
   271          *
       
   272          * @since 3.0
       
   273          * @param aStream stream to externalize
       
   274          * @param aSelection selection flag describing what to externalize
       
   275          */
       
   276         IMPORT_C void ExternalizeL( RWriteStream& aStream,
       
   277                                     TPEngDataSelection aSelection ) const;
       
   278 
       
   279 
       
   280         /**
       
   281          * Packs Session Slot State to the buffer.
       
   282          *
       
   283          * @since 3.0
       
   284          * @param aSelection selection flag describing what to pack
       
   285          * @return Buffer with streamed session slot state data.
       
   286          * Buffer ownership is returned to caller.
       
   287          */
       
   288         IMPORT_C HBufC8* PackDataLC( TPEngDataSelection aSelection ) const;
       
   289         IMPORT_C void PackDataL( TPEngDataSelection aSelection, RBuf8& aBuf ) const;
       
   290 
       
   291 
       
   292         /**
       
   293          * Unpacks Session Slot State from the passed descriptor
       
   294          *
       
   295          * @since 3.0
       
   296          * @param aDes Descriptor to unpack from.
       
   297          * @param aSelection selection flag describing what to unpack
       
   298          */
       
   299         IMPORT_C void UnpackDataL( const TDesC8& aDes,
       
   300                                    TPEngDataSelection aSelection );
       
   301 
       
   302         /**
       
   303          * Size of needed stream to externalizate the container.
       
   304          *
       
   305          * @since 3.0
       
   306          * @param aSelection selection flag describing what
       
   307          *        to calculate to the size.
       
   308          * @return size of the buffer in the bytes
       
   309          */
       
   310         IMPORT_C TInt Size( TPEngDataSelection aSelection ) const;
       
   311 
       
   312 
       
   313 
       
   314     private:    //Helpers
       
   315 
       
   316         /**
       
   317          * Add registered Application Id
       
   318          *
       
   319          * @since 3.0
       
   320          * @param aAppId application Id to be added
       
   321          */
       
   322         void AddRegisteredAppIdL( const TDesC& aAppId );
       
   323 
       
   324 
       
   325         /**
       
   326          * Remove registered Application Id
       
   327          *
       
   328          * @since 3.0
       
   329          * @param aAppId application Id to be removed
       
   330          */
       
   331         void RemoveRegisteredAppIdL( const TDesC& aAppId );
       
   332 
       
   333 
       
   334         /**
       
   335          * Add Active Application Id
       
   336          *
       
   337          * @since 3.0
       
   338          * @param aAppId application Id to be added
       
   339          */
       
   340         void AddActiveAppIdL( const TDesC& aAppId );
       
   341 
       
   342 
       
   343         /**
       
   344          * Remove Active Application Id
       
   345          *
       
   346          * @since 3.0
       
   347          * @param aAppId application Id to be removed
       
   348          */
       
   349         void RemoveActiveAppId( const TDesC& aAppId );
       
   350 
       
   351         /**
       
   352          * Checks is the Application Id registered or not
       
   353          *
       
   354          * @since 3.0
       
   355          * @param aAppId application Id to be check.
       
   356          * @return ETrue if app id is registered. Else EFalse.
       
   357          */
       
   358         TBool ApplicationRegistered( const TDesC& aAppId ) const;
       
   359 
       
   360 
       
   361 
       
   362     private: // data
       
   363 
       
   364         //OWN/REF: Session Slot ID
       
   365         CPEngSessionSlotId*             iSessionId;
       
   366 
       
   367         //OWN: Is previous session Slot ID owned or not
       
   368         TBool                           iSessionIdOwned;
       
   369 
       
   370         //OWN: Session Slot State
       
   371         TPEngNWSessionSlotState         iState;
       
   372 
       
   373         //OWN: Active Application's Application IDs
       
   374         CDesCArrayFlat                  iActiveApps;
       
   375 
       
   376         //OWN: Registered Application's Application IDs
       
   377         CDesCArrayFlat                  iRegisteredApps;
       
   378 
       
   379 
       
   380 
       
   381         // Roll back support for app id changes
       
   382 
       
   383         //OWN: Index of added active Id
       
   384         TInt                            iActiveAdded;
       
   385 
       
   386         //OWN: Index of removed active Id
       
   387         TInt                            iActiveRemoved;
       
   388 
       
   389         //OWN: Index of added Registered Id
       
   390         TInt                            iRegAdded;
       
   391 
       
   392         //OWN: Index of removed Registered Id
       
   393         TInt                            iRegRemoved;
       
   394 
       
   395     };
       
   396 
       
   397 #endif      // __CPENGNWSESSIONSLOTEVENT_H__
       
   398 // End of File