presencecache/presencecacheutils/inc/presencecachebuddyinfo.h
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2008 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CPRESENCECACHEBUDDYINFO_H
       
    20 #define CPRESENCECACHEBUDDYINFO_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 #include <e32hashtab.h>
       
    26 
       
    27 #include <mpresencebuddyinfo2.h>
       
    28 
       
    29 class RWriteStream;
       
    30 class RReadStream;
       
    31 
       
    32 // CLASS DECLARATION
       
    33 
       
    34 /**
       
    35  *  CPresenceCacheBuddyInfo
       
    36  * 
       
    37  */
       
    38 class CPresenceCacheBuddyInfo : public CBase, public MPresenceBuddyInfo2
       
    39     {
       
    40         
       
    41 public:
       
    42     // Constructors and destructor
       
    43 
       
    44     /**
       
    45      * Destructor.
       
    46      */
       
    47     ~CPresenceCacheBuddyInfo();
       
    48 
       
    49 
       
    50     /**
       
    51      * Two-phased constructor.
       
    52      */
       
    53     static CPresenceCacheBuddyInfo* NewL();
       
    54     
       
    55     /**
       
    56      * Two-phased constructor.
       
    57      */
       
    58     static CPresenceCacheBuddyInfo* NewLC();    
       
    59     
       
    60     /**
       
    61      * @return ETrue if buddy info is expired 
       
    62      */
       
    63     inline TBool IsExpired() const;
       
    64     
       
    65     /**
       
    66      * Reset buddy expiry time stamp
       
    67      */
       
    68     inline void ResetTimeStamp();
       
    69     
       
    70 public: //from MPresenceBuddyInfo2
       
    71     
       
    72     /**
       
    73      * Defined in a base class
       
    74      */
       
    75     void SetIdentityL( const TDesC& aBuddyId );
       
    76         
       
    77     /**
       
    78      * Defined in a base class
       
    79      */
       
    80     TPtrC BuddyId( ) const;        
       
    81 
       
    82     /**
       
    83      * Defined in a base class
       
    84      */
       
    85     void SetAvailabilityL( 
       
    86         TAvailabilityValues aAvailability,
       
    87         const TDesC& aAvailabilityText );
       
    88         
       
    89     /**
       
    90      * Defined in a base class
       
    91      */
       
    92     TAvailabilityValues Availability( );         
       
    93         
       
    94     /**
       
    95      * Defined in a base class
       
    96      */
       
    97     TPtrC AvailabilityText( );           
       
    98         
       
    99         
       
   100     /**
       
   101      * Defined in a base class
       
   102      */
       
   103     void SetAvatarL( const TDesC8& aAvatar );
       
   104         
       
   105     /**
       
   106      * Defined in a base class
       
   107      */
       
   108     TPtrC8 Avatar( );             
       
   109         
       
   110     /**
       
   111      * Defined in a base class
       
   112      */
       
   113     void SetStatusMessageL( const TDesC& aStatusMessage ); 
       
   114     
       
   115     /**
       
   116      * Defined in a base class
       
   117      */
       
   118     TPtrC StatusMessage( );      
       
   119         
       
   120     /**
       
   121      * Defined in a base class
       
   122      */
       
   123     void SetAnyFieldL( 
       
   124         const TDesC16& aKey,
       
   125         const TDesC8& aValue );
       
   126         
       
   127     /**
       
   128      * Defined in a base class
       
   129      */
       
   130     TPtrC8 GetAnyField( 
       
   131         const TDesC16& aKey ); 
       
   132         
       
   133     /**
       
   134      * Defined in a base class
       
   135      */
       
   136     void GetFieldKeysL( 
       
   137             CDesCArrayFlat& aKeys );
       
   138     
       
   139     /**
       
   140      * Defined in a base class
       
   141      */    
       
   142     void RemoveField(const TDesC& aKey );     
       
   143 
       
   144     /**
       
   145      * Defined in a base class
       
   146      */
       
   147     TBool EqualsIdentity(
       
   148         const MPresenceBuddyInfo2& aOtherInstance ) const;   
       
   149     
       
   150     /**
       
   151      * Defined in a base class
       
   152      */
       
   153     void ExternalizeL( RWriteStream& aStream ) const;
       
   154 
       
   155     /**
       
   156      * Defined in a base class
       
   157      */
       
   158     void InternalizeL( RReadStream& aStream );       
       
   159         
       
   160     
       
   161     
       
   162 
       
   163 private:
       
   164 
       
   165     /**
       
   166      * Constructor for performing 1st stage construction
       
   167      */
       
   168     CPresenceCacheBuddyInfo();
       
   169 
       
   170     /**
       
   171      * EPOC default constructor for performing 2nd stage construction
       
   172      */
       
   173     void ConstructL();
       
   174     
       
   175     void DoSet16BitValueL( 
       
   176             const TDesC& aKey,    
       
   177             const TDesC& aValue );
       
   178     
       
   179     TPtrC DoGet16BitValue(const TDesC& aKey );
       
   180         
       
   181     void ExternalizeFieldL( const TDesC& aData, RWriteStream& aStream ) const;
       
   182     
       
   183     void ExternalizeFieldL( const TDesC8& aData, RWriteStream& aStream ) const;    
       
   184             
       
   185     HBufC* InternalizeFieldL( RReadStream& aStream );
       
   186     
       
   187     HBufC8* InternalizeField8L( RReadStream& aStream );  
       
   188     
       
   189     /**
       
   190      * Set key and value, takes ownership of parameters
       
   191      */
       
   192     void SetAnyFieldPtrL( 
       
   193         HBufC16* aKey,
       
   194         HBufC8* aValue );    
       
   195           
       
   196     
       
   197 private: //data
       
   198     /**
       
   199      * Buddy id
       
   200      * OWN
       
   201      */
       
   202     MPresenceBuddyInfo2::TAvailabilityValues iAvailability;      
       
   203     HBufC* iBuddyId;    
       
   204     RPointerArray<HBufC> iIds;
       
   205     RPointerArray<HBufC8> iValues;     
       
   206     RHashMap<TDesC*, TInt> iHashMap;
       
   207     
       
   208     /**
       
   209      * Heap buffer for converted avavilablity text
       
   210      * OWN
       
   211      */  
       
   212     HBufC* iAvailabilityTextBuf;
       
   213     
       
   214     /**
       
   215      * Heap buffer for converted status text
       
   216      * OWN
       
   217      */ 
       
   218     HBufC* iStatusTextBuf;
       
   219 
       
   220     TInt64 iExpiryTime;
       
   221     TTime iExpiryTimeStamp;
       
   222     };
       
   223 
       
   224 inline TBool CPresenceCacheBuddyInfo::IsExpired() const
       
   225     {
       
   226     if(iExpiryTime)
       
   227         {
       
   228         // expiry is in use
       
   229         TTime now;
       
   230         now.UniversalTime();
       
   231         if( now > iExpiryTimeStamp )
       
   232             {
       
   233             return ETrue;
       
   234             }
       
   235         }
       
   236     return EFalse;
       
   237     }
       
   238 
       
   239 inline void CPresenceCacheBuddyInfo::ResetTimeStamp()
       
   240     {
       
   241     TTime now;
       
   242     now.UniversalTime();
       
   243     iExpiryTimeStamp = now.Int64() +  iExpiryTime;
       
   244     }
       
   245 
       
   246 
       
   247 #endif // CPRESENCECACHEBUDDYINFO_H