IMPSengine/engsrv/inc/impsorphans.h
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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: Orphan message and message queue
       
    15 * 
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef Orphans_H
       
    20 #define Orphans_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include "impsservercommon.h"
       
    25 #include "impsapplauncherproxy.h"
       
    26 #include <impsservices.h>
       
    27 #include "impssrvutils.h"
       
    28 
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class COrphan;
       
    32 class CImpsFields;
       
    33 class MImpsDataAccessor;
       
    34 
       
    35 
       
    36 
       
    37 // CLASS DECLARATION
       
    38 /**
       
    39 *  Orphan message
       
    40 */
       
    41 
       
    42 class COrphan : public CBase
       
    43     {
       
    44     public:
       
    45         static COrphan* NewL(
       
    46             const TDesC& aCID,
       
    47             const TDesC& aSessionId,
       
    48             TImpsEventType aServiceType,
       
    49             const TDesC&    aSap,
       
    50             const TDesC&    aUserId,
       
    51             TTime aValidity,
       
    52             CImpsFields* aFields );
       
    53 
       
    54         ~COrphan();
       
    55         void Destroy();
       
    56         TDesC& ApplicationId();
       
    57         CImpsFields* Message();
       
    58         TTime Expiry();
       
    59         void RemoveOwnership();
       
    60 
       
    61         TBuf<KImpsMaxClientId> iCID;        //lint !e1925  // CSP client-id
       
    62         TBuf<KImpsMaxSID>   iSessionId;     //lint !e1925  // CSP session id
       
    63         TImpsEventType      iServiceType;    //lint !e1925  // event type
       
    64         HBufC*              iSap;
       
    65         HBufC*              iUserId;
       
    66         CImpsFields*        iFields;        //lint !e1925
       
    67         TTime               iExpiry;        // Validity time
       
    68         TDblQueLink         iLink;          //lint !e1925
       
    69 
       
    70 
       
    71     private:
       
    72         COrphan(
       
    73             const TDesC& aCID,
       
    74             const TDesC& aSessionId,
       
    75             TImpsEventType aServiceType,
       
    76             TTime aValidity,
       
    77             CImpsFields* aFields );
       
    78 
       
    79         void ConstructL(
       
    80             const TDesC&    aSap,
       
    81             const TDesC&    aUserId );
       
    82 
       
    83 
       
    84     };
       
    85 
       
    86 // CLASS DECLARATION
       
    87 /**
       
    88 *  Double linked fixed size queue for orphan messages. When the queue at max
       
    89 *  capacity the oldest item gets deleted.
       
    90 */
       
    91 
       
    92 class COrphanQueue : public CBase
       
    93     {
       
    94     public:
       
    95 
       
    96         /**
       
    97         * Constructs a new COrpanQueue with given capacity
       
    98         * @param aCapacity the capacity of the queue
       
    99         */
       
   100         COrphanQueue( TInt aCapacity );
       
   101 
       
   102         // Destructor
       
   103         ~COrphanQueue();
       
   104 
       
   105         /**
       
   106         * Sets the capacity of the queue
       
   107         * @param aNewCapacity the new capacity of the queue
       
   108         */
       
   109         void SetLength( TInt aNewCapacity );
       
   110 
       
   111         /**
       
   112         * Adds a new orphan message to the end of the queue
       
   113         * @param aOrphan an orphan message to be added
       
   114         */
       
   115         void Add( COrphan& aOrphan );
       
   116 
       
   117         /**
       
   118         * Destroys orphan messages in the queue with the given ClientID
       
   119         * @param aApplicationId an application ID to be destroyed
       
   120         */
       
   121         void DestroyOrphans( TDesC& aApplicationId );
       
   122 
       
   123         /**
       
   124         * Returns an orphan message with the given clientID and removes
       
   125         * it from the queue. If not found returns NULL.
       
   126         * @param aApplicationId an application ID to be returned
       
   127         * @param aServiceType the type of the client which requests the message
       
   128         */
       
   129         CImpsFields* OrphanMessageLC(
       
   130             const TDesC& aApplicationId,
       
   131             TImpsEventType aServiceType,
       
   132             TImpsSessIdent aCspId );
       
   133 
       
   134 
       
   135         /**
       
   136         * Deletes all expired orphan messages.
       
   137         * @param aExpiry expiry time
       
   138         */
       
   139         void DiscardExpired( TTime aExpiry );
       
   140 
       
   141     private:
       
   142         TDblQue<COrphan>        iOrphanList;
       
   143         TInt                    iCapacity;
       
   144         TInt                    iSize;
       
   145     };
       
   146 
       
   147 /**
       
   148 * CImpsOrphans
       
   149 */
       
   150 class CImpsOrphans : public CBase,
       
   151             public MImpsAppLaunchHandler
       
   152     {
       
   153     public:
       
   154 
       
   155         /**
       
   156         * Destructor
       
   157         */
       
   158         virtual ~CImpsOrphans();
       
   159 
       
   160         /**
       
   161         * create new instance
       
   162         */
       
   163         static CImpsOrphans* NewL();
       
   164 
       
   165         /**
       
   166         * Store message and launch application
       
   167         * @param aMsg orphan message
       
   168         */
       
   169         virtual void NewOrphanL( CImpsFields* aMsg, TImpsSessIdent aCspId );
       
   170 
       
   171         /**
       
   172         * Get next orphan
       
   173         * @param aApplicationId
       
   174         * @param aServiceType the type of the client which requests the message
       
   175         * @return new message, NULL if no match. Ownership of the msg is
       
   176         * passed to the caller of this method.
       
   177         */
       
   178         virtual CImpsFields* NextOrphanLC(
       
   179             const TDesC& aApplicationId,
       
   180             TImpsEventType aServiceType,
       
   181             TImpsSessIdent aCspId );
       
   182 
       
   183         /**
       
   184         * Check expiration of orphans
       
   185         */
       
   186         virtual void CheckExpiryL( );
       
   187 
       
   188         /**
       
   189         * Stop
       
   190         */
       
   191         virtual void Stop( );
       
   192 
       
   193     public:
       
   194         void HandleAppLaunch( const TDesC& aApplicationId, TInt aStatus );
       
   195 
       
   196     protected:
       
   197 
       
   198         void ConstructL();
       
   199 
       
   200         /**
       
   201         * Adds the orphan message to the queue.
       
   202         * @param aFields the received message in internal data format
       
   203         * @param aServiceType the type of the client which requests the message
       
   204         * @returns pointer to the orphaned message
       
   205         */
       
   206         COrphan* AddOrphanL(
       
   207             CImpsFields *aFields,
       
   208             TImpsEventType aServiceType,
       
   209             TImpsSessIdent aCspId );
       
   210 
       
   211         /**
       
   212         * Gets the IM validity from the internal data. If not present it returns
       
   213         * the default validity.
       
   214         * @param aAc data accessor
       
   215         * @param aValidity the validity
       
   216         */
       
   217         void GetValidityFromMessageL(
       
   218             MImpsDataAccessor& aAc,
       
   219             TTimeIntervalSeconds& aValidity );
       
   220 
       
   221         /**
       
   222         * Gets the corresponding service type for a given message
       
   223         * @param aMessageType type of the message
       
   224         * @returns the service type
       
   225         */
       
   226         TImpsEventType ServiceType( TImpsMessageType aMessageType );
       
   227 
       
   228     private:
       
   229         /**
       
   230         * Constructor
       
   231         */
       
   232         CImpsOrphans( );
       
   233 
       
   234     protected:
       
   235         // Orphan message queue
       
   236         COrphanQueue*           iOrphanQueue;
       
   237         CImpsAppLauncherProxy*  iLauncherProxy;
       
   238     };
       
   239 
       
   240 #endif