imservices/imfeatureplugin/srcimdatamodel/ximpimsubscriptionitembase.h
changeset 51 61fad867f68e
equal deleted inserted replaced
-1:000000000000 51:61fad867f68e
       
     1 /*
       
     2 * Copyright (c) 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:  IM Service Connection subscription item base.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef CXIMPPSCSUBSCRIPTIONITEMBASE_H
       
    19 #define CXIMPPSCSUBSCRIPTIONITEMBASE_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <ximpdatasubscriptionstate.h>
       
    23 #include "ximpsubscriptionitem.h"
       
    24 
       
    25 
       
    26 class MXIMPIMItemParent;
       
    27 class MXIMPPscContext;
       
    28 class CXIMPDataSubscriptionStateImp;
       
    29 
       
    30 /**
       
    31  * PSC subscription implementation
       
    32  *
       
    33  * @since S60 v3.2
       
    34  */
       
    35 class CXIMPIMSubscriptionItemBase : public CObject, public MXIMPSubscriptionItem
       
    36     {
       
    37 public: // Definitions
       
    38 
       
    39     /**
       
    40      * Subscription status
       
    41      */
       
    42     enum TSubscriptionStatus
       
    43         {
       
    44         ENotSubscribedAtAll,
       
    45         ESubscribedForOtherCtxOnly,
       
    46         ESubscribedForCtxOnly,
       
    47         ESubscribedForCtxAndOthers
       
    48         };
       
    49 
       
    50     /**
       
    51      * Subscription update event.
       
    52      * Update subscription based on event.
       
    53      */
       
    54     enum TSubscriptionEvent
       
    55         {
       
    56         ECompleteDataReceived
       
    57         };
       
    58 	/**
       
    59      * For linear ordering by pointers
       
    60      */
       
    61     static TInt OrderOfContexts( const MXIMPPscContext& aFirst,
       
    62                                  const MXIMPPscContext& aSecond );
       
    63 
       
    64     /**
       
    65      * For linear ordering by pointers
       
    66      */
       
    67     static TInt OrderOfItems( const CXIMPIMSubscriptionItemBase& aFirst,
       
    68                               const CXIMPIMSubscriptionItemBase& aSecond );
       
    69 
       
    70 protected: // Construction and destruction
       
    71 
       
    72     /**
       
    73      * Destruction
       
    74      * - Remember to inform parent about delete.
       
    75      */
       
    76     IMPORT_C virtual ~CXIMPIMSubscriptionItemBase();
       
    77 
       
    78 public: // Construction and destruction
       
    79 
       
    80     /**
       
    81      * Construction
       
    82      * @param aParent. Parent has to be informed when this object is deleted by RemoveMe method.
       
    83      */
       
    84     IMPORT_C CXIMPIMSubscriptionItemBase( MXIMPIMItemParent& aParent );
       
    85 
       
    86     /**
       
    87      * Base construction. Must be called from inherited classes ConstructL
       
    88      */
       
    89     IMPORT_C void BaseConstructL();
       
    90 
       
    91 
       
    92 public: // New methods
       
    93 
       
    94     IMPORT_C TSubscriptionStatus SubscriptionStatus( MXIMPPscContext* aContext );
       
    95 
       
    96     /**
       
    97      * Add subscriber for item.
       
    98      * @param aContext. Context to be added.
       
    99      */
       
   100     IMPORT_C void AddSubscriberL( MXIMPPscContext* aContext );
       
   101 
       
   102     /**
       
   103      * Remove subscriber from item
       
   104      * @param aContext. Context to be removed.
       
   105      */
       
   106     IMPORT_C void RemoveSubscriber( MXIMPPscContext* aContext );
       
   107 
       
   108     /**
       
   109      * Add subscriber for item.
       
   110      * @param aItem. Item to be added.
       
   111      */
       
   112     IMPORT_C void AddSubscriberL( CXIMPIMSubscriptionItemBase* aItem );
       
   113 
       
   114     /**
       
   115      * Remove subscriber from item
       
   116      * @param aContext. Item to be removed.
       
   117      */
       
   118     IMPORT_C void RemoveSubscriber( CXIMPIMSubscriptionItemBase* aItem );
       
   119 
       
   120     /**
       
   121      * Activate subscriber for item.
       
   122      * @param aItem. Item to be activated.
       
   123      */
       
   124     IMPORT_C void ActivateSubscriberL( CXIMPIMSubscriptionItemBase* aItem );
       
   125 
       
   126     /**
       
   127      * Call RemoveSubscriber for all contexts registered to item.
       
   128      */
       
   129     IMPORT_C void ForceClose();
       
   130 
       
   131     /**
       
   132      * Clean item if expired.
       
   133      * @return ETrue if expired and cleaned.EFalse if not.
       
   134      */
       
   135     IMPORT_C TBool CleanIfExpired();
       
   136 
       
   137     /**
       
   138      * Update subscription based on event happened.
       
   139      * @param aUpdateState. Event which happened.
       
   140      */
       
   141     IMPORT_C void UpdateSubscriptionStateL( TSubscriptionEvent aUpdateState );
       
   142     
       
   143     /**
       
   144      *
       
   145      */
       
   146     IMPORT_C const MXIMPDataSubscriptionState& DataSubscriptionState();
       
   147         
       
   148     /**
       
   149      * Count of subscribed contexts.
       
   150      */
       
   151     IMPORT_C TInt ContextCount() const;
       
   152 
       
   153     /**
       
   154      * Reference to context in index.
       
   155      */
       
   156     IMPORT_C MXIMPPscContext& Context( TInt aIndex );
       
   157 
       
   158     /**
       
   159      * Can context be found from contexts.
       
   160      */
       
   161     IMPORT_C TBool IsContext( MXIMPPscContext* aContext ) const;
       
   162 
       
   163 public: // From MXIMPSubscriptionItem
       
   164 
       
   165     /**
       
   166      * @see MXIMPSubscriptionItem
       
   167      */
       
   168     IMPORT_C void SynthesiseSubscriptionEventToAllCtxsL();
       
   169 
       
   170     /**
       
   171      * @see MXIMPSubscriptionItem
       
   172      */
       
   173     IMPORT_C void ActivateSubscriberL( MXIMPPscContext* aContext );
       
   174         
       
   175     /**
       
   176      * @see MXIMPSubscriptionItem
       
   177      */
       
   178     IMPORT_C void SetDataSubscriptionStateL( CXIMPDataSubscriptionStateImp& aNewState );
       
   179 
       
   180 public: // Helpers
       
   181 
       
   182     /**
       
   183      * Status for context
       
   184      */
       
   185     IMPORT_C CXIMPDataSubscriptionStateImp* StatusLC( MXIMPPscContext* aContext ) const;
       
   186 
       
   187     /**
       
   188      * Update time to new expire time.
       
   189      */
       
   190     IMPORT_C void UpdateExpirationL();
       
   191 
       
   192     /**
       
   193      * Change status after subscriber is added/removed.
       
   194      */
       
   195     IMPORT_C void ChangeStatusAfterAdd();
       
   196     IMPORT_C void ChangeStatusAfterRemove();
       
   197 
       
   198     /**
       
   199      * Count of subscribers. Items counted as 1.
       
   200      */
       
   201     IMPORT_C TInt CountOfSubscribers();
       
   202 
       
   203 protected: // New interface methods.
       
   204 
       
   205     /**
       
   206      * Clean data because expiration
       
   207      */
       
   208     virtual void CleanExpired() = 0;
       
   209 
       
   210 protected: // Data
       
   211 
       
   212     /**
       
   213      * Parent object to inform when object is deleted.
       
   214      * Used also for sending events.
       
   215      */
       
   216     MXIMPIMItemParent& iParent;
       
   217 
       
   218 
       
   219     /**
       
   220      * Subscribed contexts.
       
   221      */
       
   222     RPointerArray< MXIMPPscContext > iContexts;
       
   223     RPointerArray< MXIMPPscContext > iPreContexts;
       
   224     RPointerArray< CXIMPIMSubscriptionItemBase > iItems;
       
   225     RPointerArray< CXIMPIMSubscriptionItemBase > iPreItems;
       
   226 
       
   227     /**
       
   228      * Current IM info status.
       
   229      */
       
   230     CXIMPDataSubscriptionStateImp* iSubscriptionState;
       
   231 
       
   232     /**
       
   233      * Time when ready for expire.
       
   234      */
       
   235     TTime iExpireTime;
       
   236     };
       
   237 
       
   238 
       
   239 /* ======================================================================== */
       
   240 
       
   241 
       
   242 
       
   243 #endif // CXIMPPSCSUBSCRIPTIONITEMBASE_H