ximpfw/presence/srcpresencedatamodel/presenceauthorization/presenceblocklisteventimp.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     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:  Presence block list event implementation.
       
    15  *
       
    16 */
       
    17 
       
    18 #include "presenceblocklisteventimp.h"
       
    19 #include "presenceblockinfoimp.h"
       
    20 #include "ximpobjecthelpers.h"
       
    21 #include "ximpidentityimp.h"
       
    22 #include "ximpdatasubscriptionstateimp.h"
       
    23 #include <s32strm.h>
       
    24 
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CPresenceBlockListEventImp::NewLC()
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 EXPORT_C CPresenceBlockListEventImp* CPresenceBlockListEventImp::NewLC(
       
    31         RPrBlockInfoImpArray* aAdded,
       
    32         RPrBlockInfoImpArray* aPending,
       
    33         RPrBlockInfoImpArray* aRemoved,
       
    34         RPrBlockInfoImpArray* aUpdated,
       
    35         CXIMPDataSubscriptionStateImp* aState
       
    36         )
       
    37     {
       
    38     CPresenceBlockListEventImp* self = new( ELeave ) CPresenceBlockListEventImp();
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL( aAdded, aPending, aRemoved, aUpdated, aState );
       
    41     return self;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CPresenceBlockListEventImp::NewFromStreamLC()
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CXIMPApiEventBase* CPresenceBlockListEventImp::NewFromStreamLC( RReadStream& aStream )
       
    49     {
       
    50     CPresenceBlockListEventImp* self = new( ELeave ) CPresenceBlockListEventImp;
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL( aStream );
       
    53     return self;
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CPresenceBlockListEventImp::~CPresenceBlockListEventImp()
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CPresenceBlockListEventImp::~CPresenceBlockListEventImp()
       
    61     {
       
    62     if( iConstructedFromStream )
       
    63         {
       
    64         delete iAdded;
       
    65         delete iCurrent;
       
    66         delete iRemoved;
       
    67         delete iUpdated;
       
    68         iCurrent = NULL; // Must be null for next branch.
       
    69         }
       
    70 
       
    71     if( iOwnsCurrent )
       
    72         {
       
    73         delete iCurrent;
       
    74         }
       
    75 
       
    76     delete iSubscriptionState;
       
    77     }
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CPresenceBlockListEventImp::CPresenceBlockListEventImp()
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CPresenceBlockListEventImp::CPresenceBlockListEventImp()
       
    85     {
       
    86     }
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CPresenceBlockListEventImp::ConstructL()
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CPresenceBlockListEventImp::ConstructL(
       
    94         RPrBlockInfoImpArray* aAdded,
       
    95         RPrBlockInfoImpArray* aPending,
       
    96         RPrBlockInfoImpArray* aRemoved,
       
    97         RPrBlockInfoImpArray* aUpdated,
       
    98         CXIMPDataSubscriptionStateImp* aState )
       
    99     {
       
   100     iAdded = aAdded;
       
   101     if( aPending )
       
   102         {
       
   103         iCurrent = aPending;
       
   104         }
       
   105     else
       
   106         {
       
   107         iCurrent = new ( ELeave ) RPrBlockInfoImpArray;
       
   108         iOwnsCurrent = ETrue;
       
   109         }
       
   110     iRemoved = aRemoved;
       
   111     iUpdated = aUpdated;
       
   112     iSubscriptionState = aState;
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CPresenceBlockListEventImp::ConstructL()
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CPresenceBlockListEventImp::ConstructL( RReadStream& aStream )
       
   120     {
       
   121     iConstructedFromStream = ETrue;
       
   122 
       
   123     iAdded = new ( ELeave ) RPrBlockInfoImpArray;
       
   124     iCurrent = new ( ELeave ) RPrBlockInfoImpArray;
       
   125     iRemoved = new ( ELeave ) RPrBlockInfoImpArray;
       
   126     iUpdated = new ( ELeave ) RPrBlockInfoImpArray;
       
   127     iSubscriptionState = CXIMPDataSubscriptionStateImp::NewL();
       
   128 
       
   129     FillArrayFromStreamL( *iAdded, aStream );
       
   130     FillArrayFromStreamL( *iCurrent, aStream );
       
   131     FillArrayFromStreamL( *iRemoved, aStream );
       
   132     FillArrayFromStreamL( *iUpdated, aStream );
       
   133     
       
   134     iSubscriptionState->InternalizeL( aStream );
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // Implement supported interface access.
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 XIMPIMP_IF_BASE_GET_INTERFACE_BEGIN( CPresenceBlockListEventImp,
       
   142                                      MPresenceBlockListEvent )
       
   143     XIMPIMP_IF_BASE_GET_CLASS( CXIMPApiEventBase, this )
       
   144 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
   145 
       
   146 
       
   147 XIMPIMP_IF_BASE_GET_CONST_INTERFACE_BEGIN( CPresenceBlockListEventImp,
       
   148                                            MPresenceBlockListEvent )
       
   149     XIMPIMP_IF_BASE_GET_CONST_CLASS( CXIMPApiEventBase, this )                                            
       
   150 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
   151 
       
   152 
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // Implement methods from base event interface and base event class
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 XIMPIMP_IMPLEMENT_EVENT_BASE_METHODS( CPresenceBlockListEventImp,
       
   159                                       MPresenceBlockListEvent )
       
   160 
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CPresenceBlockListEventImp::EqualsContent()
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 TBool CPresenceBlockListEventImp::EqualsContent( 
       
   167     const CXIMPApiEventBase& aOtherInstance ) const
       
   168     {
       
   169     const CPresenceBlockListEventImp* tmp =
       
   170     TXIMPGetImpClassOrPanic< const CPresenceBlockListEventImp>::From( 
       
   171                                                        aOtherInstance.Base() );
       
   172     TBool same = ETrue;
       
   173     TBool x = TXIMPEqualsContent< CPresenceBlockInfoImp >::Array( *iAdded, *( tmp->iAdded ) );
       
   174     same &= x;
       
   175 
       
   176     x = TXIMPEqualsContent< CPresenceBlockInfoImp >::Array( *iCurrent, *( tmp->iCurrent ) );
       
   177     same &= x;
       
   178 
       
   179     x = TXIMPEqualsContent< CPresenceBlockInfoImp >::Array( *iRemoved, *( tmp->iRemoved ) );
       
   180     same &= x;
       
   181 
       
   182     x = TXIMPEqualsContent< CPresenceBlockInfoImp >::Array( *iUpdated, *( tmp->iUpdated ) );
       
   183     same &= x;
       
   184     
       
   185     x = iSubscriptionState->EqualsContent( *tmp->iSubscriptionState );
       
   186     same &= x;
       
   187 
       
   188     return same;
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // From class CXIMPApiEventBase.
       
   193 // CPresenceBlockListEventImp::ExternalizeL()
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 void CPresenceBlockListEventImp::ExternalizeL( RWriteStream& aStream ) const
       
   197     {
       
   198     WriteArrayToStreamL( *iAdded, aStream );
       
   199     WriteArrayToStreamL( *iCurrent, aStream );
       
   200     WriteArrayToStreamL( *iRemoved, aStream );
       
   201     WriteArrayToStreamL( *iUpdated, aStream );
       
   202     iSubscriptionState->ExternalizeL( aStream );
       
   203     }
       
   204 
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // From MPresenceBlockListEvent class.
       
   208 // CPresenceBlockListEventImp::NewBlocksCount()
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 TInt CPresenceBlockListEventImp::NewBlocksCount() const
       
   212     {
       
   213     return iAdded->Count();
       
   214     }
       
   215     
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // From MPresenceBlockListEvent class.
       
   219 // CPresenceBlockListEventImp::NewBlock()
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 const MPresenceBlockInfo&
       
   223             CPresenceBlockListEventImp::NewBlock( TInt aIndex ) const
       
   224     {
       
   225     return *(*iAdded)[ aIndex ];
       
   226     }
       
   227     
       
   228 // ---------------------------------------------------------------------------
       
   229 // From MPresenceBlockListEvent class.
       
   230 // CPresenceBlockListEventImp::UpdatedBlocksCount()
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 TInt CPresenceBlockListEventImp::UpdatedBlocksCount() const
       
   234     {
       
   235     return iUpdated->Count();
       
   236     }
       
   237 
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // From MPresenceBlockListEvent class.
       
   241 // CPresenceBlockListEventImp::UpdatedBlock()
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 const MPresenceBlockInfo& 
       
   245     CPresenceBlockListEventImp::UpdatedBlock( TInt aIndex ) const
       
   246     {
       
   247     return *(*iUpdated)[ aIndex ];
       
   248     }
       
   249     
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // From MPresenceBlockListEvent class.
       
   253 // CPresenceBlockListEventImp::DisappearedBlocksCount()
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 TInt CPresenceBlockListEventImp::DisappearedBlocksCount() const
       
   257     {
       
   258     return iRemoved->Count();
       
   259     }
       
   260     
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // From MPresenceBlockListEvent class.
       
   264 // CPresenceBlockListEventImp::DisappearedBlock()
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 const MPresenceBlockInfo& 
       
   268     CPresenceBlockListEventImp::DisappearedBlock( TInt aIndex ) const
       
   269     {
       
   270     return *(*iRemoved)[ aIndex ];
       
   271     }
       
   272     
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // From MPresenceBlockListEvent class.
       
   276 // CPresenceBlockListEventImp::CurrentBlocksCount()
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 TInt CPresenceBlockListEventImp::CurrentBlocksCount() const
       
   280     {
       
   281     return iCurrent->Count();
       
   282     }
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // From MPresenceBlockListEvent class.
       
   286 // CPresenceBlockListEventImp::CurrentBlock()
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 const MPresenceBlockInfo&
       
   290     CPresenceBlockListEventImp::CurrentBlock( TInt aIndex ) const
       
   291     {
       
   292     return *(*iCurrent)[ aIndex ];
       
   293     }
       
   294 
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // From class MPresenceBlockListEvent.
       
   298 // CPresenceBlockListEventImp::DataSubscriptionState()
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 const MXIMPDataSubscriptionState&
       
   302     CPresenceBlockListEventImp::DataSubscriptionState() const
       
   303     {
       
   304     return *iSubscriptionState;
       
   305     }
       
   306 
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // CPresenceBlockListEventImp::WriteArrayToStreamL()
       
   310 // ---------------------------------------------------------------------------
       
   311 //
       
   312 void CPresenceBlockListEventImp::WriteArrayToStreamL(
       
   313         RPrBlockInfoImpArray& aArray, RWriteStream& aStream ) const
       
   314     {
       
   315     TInt count = aArray.Count();
       
   316     aStream.WriteInt32L( count );
       
   317         {
       
   318         for( TInt a = 0; a < count; ++a )
       
   319             {
       
   320             aArray[ a ]->ExternalizeL( aStream );
       
   321             }
       
   322         }
       
   323     }
       
   324 
       
   325 
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CPresenceBlockListEventImp::FillArrayFromStreamL
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 void CPresenceBlockListEventImp::FillArrayFromStreamL(
       
   332         RPrBlockInfoImpArray& aArray,
       
   333         RReadStream& aStream )
       
   334     {
       
   335     TInt count = aStream.ReadInt32L();
       
   336     for( TInt a = 0; a < count; ++a )
       
   337         {
       
   338         // the stream MUST be in order (since it was externalized by this class)
       
   339         CPresenceBlockInfoImp* newInfo = CPresenceBlockInfoImp::NewLC();
       
   340         newInfo->InternalizeL( aStream );
       
   341         aArray.AppendL( newInfo );
       
   342         CleanupStack::Pop(); // newInfo
       
   343         }
       
   344     }
       
   345 
       
   346 
       
   347 
       
   348 // End of file
       
   349