presencecache/presencecacheutils/src/presenceobjecthelpers.cpp
changeset 0 e686773b3f54
child 32 2828b4d142c0
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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:  Helpers for handling objects
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mpresencebuddyinfo2.h>
       
    20 #include "cacheobjecthelpers.h"
       
    21 #include "presenceobjecthelpers.h"
       
    22 #include "presencecachebuddyinfo.h"
       
    23 
       
    24 // ==================== TPresenceArrayPacker MEMBER FUNCTIONS ====================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // TPresenceArrayPacker::PackArrayL()
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 EXPORT_C HBufC8* TPresenceArrayPacker::PackArrayL( const RPointerArray< MPresenceBuddyInfo2 >& aBufferArray )
       
    31     {
       
    32     CBufFlat* packBuf = CBufFlat::NewL( KObjectBufGranurality );
       
    33     CleanupStack::PushL( packBuf );
       
    34 
       
    35     RBufWriteStream ws;
       
    36     ws.Open( *packBuf ); // CSI: 65 #
       
    37     CleanupClosePushL( ws );
       
    38 
       
    39     // Get count of objects
       
    40     TInt objCount( aBufferArray.Count() );
       
    41     // write the count
       
    42     ws.WriteInt32L( objCount );
       
    43     // objects
       
    44     MPresenceBuddyInfo2* info = NULL;    
       
    45     for ( TInt count(0); count < objCount; count++ )
       
    46         {
       
    47         info = aBufferArray[ count ];
       
    48         info->ExternalizeL( ws );
       
    49         }
       
    50 
       
    51     ws.CommitL();
       
    52     CleanupStack::PopAndDestroy(); //ws
       
    53 
       
    54     HBufC8* packBufDesc = packBuf->Ptr(0).AllocL();
       
    55     CleanupStack::PopAndDestroy( packBuf );
       
    56 
       
    57     return packBufDesc;
       
    58     }
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // TPresenceArrayPacker::UnPackArrayL()
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 EXPORT_C void TPresenceArrayPacker::UnPackArrayL( RPointerArray< MPresenceBuddyInfo2 >& aBufferArray, const TDesC8& aPack  )
       
    66     {
       
    67 	// No reset
       
    68     if ( ! aPack.Length() )
       
    69         {
       
    70         // empty, don't attempt to unpack
       
    71         return;
       
    72         }
       
    73 
       
    74     RDesReadStream rs;
       
    75     CleanupClosePushL( rs );
       
    76     rs.Open( aPack ); // CSI: 65 #
       
    77 
       
    78     // read the object count
       
    79     TInt objCount( rs.ReadInt32L() );
       
    80     
       
    81     MPresenceBuddyInfo2* info = NULL;      
       
    82 
       
    83 	for ( TInt count = 0; count < objCount; count++ )
       
    84         {
       
    85         info = MPresenceBuddyInfo2::NewLC();
       
    86         info->InternalizeL( rs );
       
    87         aBufferArray.AppendL( info );
       
    88         
       
    89 		}
       
    90     CleanupStack::Pop( objCount ); // all the objects
       
    91     CleanupStack::PopAndDestroy(); // rs    
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // PresenceCacheBuddyUtils::ResetBuddyInfoTimeStamp()
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C void PresenceCacheBuddyUtils::ResetBuddyInfoTimeStamp(
       
   100         MPresenceBuddyInfo2& aBuddy)
       
   101     {
       
   102     static_cast<CPresenceCacheBuddyInfo*>(&aBuddy)->ResetTimeStamp();
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // PresenceCacheBuddyUtils::IsBuddyInfoExpired()
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 EXPORT_C TBool PresenceCacheBuddyUtils::IsBuddyInfoExpired(
       
   110         const MPresenceBuddyInfo2& aBuddy)
       
   111     {
       
   112     return static_cast<const CPresenceCacheBuddyInfo*>(&aBuddy)->IsExpired();
       
   113     }
       
   114 
       
   115 
       
   116 // End of file