ximpfw/presence/srcpresencedatamodel/presentitygroups/presentitygrouplisteventimp.cpp
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:  MOwnPresenceEvent API object implementation.
       
    15  *
       
    16 */
       
    17 
       
    18 #include "presentitygrouplisteventimp.h"
       
    19 #include "presentitygroupinfoimp.h"
       
    20 #include "ximpobjecthelpers.h"
       
    21 #include "ximpdatasubscriptionstateimp.h"
       
    22 #include "ximpidentityimp.h"
       
    23 #include <s32strm.h>
       
    24 
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CPresentityGroupListEventImp::NewLC()
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 EXPORT_C CPresentityGroupListEventImp* CPresentityGroupListEventImp::NewLC(
       
    31         RPrGrpInfoImpArray* aCreated,
       
    32         RPrGrpInfoImpArray* aUpdated,
       
    33         RPrGrpInfoImpArray* aDeleted,
       
    34         CXIMPDataSubscriptionStateImp* aState )
       
    35     {
       
    36     CPresentityGroupListEventImp* self = new( ELeave ) CPresentityGroupListEventImp();
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL( aCreated, aUpdated, aDeleted, aState );
       
    39     return self;
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CPresentityGroupListEventImp::NewLC()
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 EXPORT_C CPresentityGroupListEventImp* CPresentityGroupListEventImp::NewLC(
       
    47         RPrGrpInfoImpArray* aCreated,
       
    48         RPrGrpInfoImpArray* aUpdated,
       
    49         RPrGrpInfoImpArray* aDeleted,
       
    50         RPrGrpInfoImpArray* aCurrent,
       
    51         CXIMPDataSubscriptionStateImp* aState
       
    52         )
       
    53     {
       
    54     CPresentityGroupListEventImp* self = new( ELeave ) CPresentityGroupListEventImp();
       
    55     CleanupStack::PushL( self );
       
    56     if( aCurrent )
       
    57         {
       
    58         self->ConstructL( aCreated, aUpdated, aDeleted, aCurrent, aState );
       
    59         }
       
    60     else
       
    61         {
       
    62         self->ConstructL( aCreated, aUpdated, aDeleted, aState );
       
    63         }
       
    64     return self;
       
    65     }
       
    66     
       
    67 // ---------------------------------------------------------------------------
       
    68 // CPresentityGroupListEventImp::NewLC()
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CPresentityGroupListEventImp* CPresentityGroupListEventImp::NewL(
       
    72         RPrGrpInfoImpArray* aCreated,
       
    73         RPrGrpInfoImpArray* aUpdated,
       
    74         RPrGrpInfoImpArray* aDeleted,
       
    75         RPrGrpInfoImpArray* aCurrent,
       
    76         CXIMPDataSubscriptionStateImp* aState
       
    77         )
       
    78     {
       
    79     CPresentityGroupListEventImp* self = NewLC( aCreated, aUpdated, aDeleted, aCurrent, aState );
       
    80     CleanupStack::Pop( self );
       
    81     return self;
       
    82     }
       
    83     
       
    84 // ---------------------------------------------------------------------------
       
    85 // CPresentityGroupListEventImp::NewFromStreamLC()
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 CXIMPApiEventBase* CPresentityGroupListEventImp::NewFromStreamLC( RReadStream& aStream )
       
    89     {
       
    90     CPresentityGroupListEventImp* self = new( ELeave ) CPresentityGroupListEventImp;
       
    91     CleanupStack::PushL( self );
       
    92     self->ConstructL( aStream );
       
    93     return self;
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CPresentityGroupListEventImp::~CPresentityGroupListEventImp()
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 CPresentityGroupListEventImp::~CPresentityGroupListEventImp()
       
   101     {
       
   102     if( iConstructedFromStream )
       
   103         {
       
   104         delete iCreatedGroups;
       
   105         delete iUpdatedGroups;
       
   106         delete iDeletedGroups;
       
   107         delete iCurrentGroups;
       
   108         iCurrentGroups = NULL;
       
   109         }
       
   110 
       
   111     if ( iOwnsCurrentGroupsArray )
       
   112         {
       
   113         delete iCurrentGroups;
       
   114         }
       
   115 
       
   116     delete iSubscriptionState;
       
   117     }
       
   118 
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CPresentityGroupListEventImp::CPresentityGroupListEventImp()
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 CPresentityGroupListEventImp::CPresentityGroupListEventImp()
       
   125     {
       
   126     }
       
   127 
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CPresentityGroupListEventImp::ConstructL()
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void CPresentityGroupListEventImp::ConstructL(
       
   134         RPrGrpInfoImpArray* aCreated,
       
   135         RPrGrpInfoImpArray* aUpdated,
       
   136         RPrGrpInfoImpArray* aDeleted,
       
   137         CXIMPDataSubscriptionStateImp* aState )
       
   138     {
       
   139     iCreatedGroups = aCreated;
       
   140     iUpdatedGroups = aUpdated;
       
   141     iDeletedGroups = aDeleted;
       
   142 
       
   143     iCurrentGroups = new ( ELeave ) RPrGrpInfoImpArray;
       
   144     iOwnsCurrentGroupsArray = ETrue;
       
   145     iSubscriptionState = aState;
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CPresentityGroupListEventImp::ConstructL()
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void CPresentityGroupListEventImp::ConstructL(
       
   153         RPrGrpInfoImpArray* aCreated,
       
   154         RPrGrpInfoImpArray* aUpdated,
       
   155         RPrGrpInfoImpArray* aDeleted,
       
   156         RPrGrpInfoImpArray* aCurrent,
       
   157         CXIMPDataSubscriptionStateImp* aState
       
   158         )
       
   159     {
       
   160     iCreatedGroups = aCreated;
       
   161     iUpdatedGroups = aUpdated;
       
   162     iDeletedGroups = aDeleted;
       
   163     iCurrentGroups = aCurrent;
       
   164     iSubscriptionState = aState;
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // CPresentityGroupListEventImp::ConstructL()
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 void CPresentityGroupListEventImp::ConstructL( RReadStream& aStream )
       
   172     {
       
   173     iConstructedFromStream = ETrue;
       
   174 
       
   175     iCreatedGroups = new ( ELeave ) RPrGrpInfoImpArray;
       
   176     iUpdatedGroups = new ( ELeave ) RPrGrpInfoImpArray;
       
   177     iDeletedGroups = new ( ELeave ) RPrGrpInfoImpArray;
       
   178     iCurrentGroups = new ( ELeave ) RPrGrpInfoImpArray;
       
   179 
       
   180     FillArrayFromStreamL( *iCreatedGroups, aStream );
       
   181     FillArrayFromStreamL( *iUpdatedGroups, aStream );
       
   182     FillArrayFromStreamL( *iDeletedGroups, aStream );
       
   183     FillArrayFromStreamL( *iCurrentGroups, aStream );
       
   184 
       
   185     iSubscriptionState = CXIMPDataSubscriptionStateImp::NewL();
       
   186     iSubscriptionState->InternalizeL( aStream );
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // Implement supported interface access.
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 XIMPIMP_IF_BASE_GET_INTERFACE_BEGIN( CPresentityGroupListEventImp,
       
   194                                      MPresentityGroupListEvent )
       
   195     XIMPIMP_IF_BASE_GET_CLASS( CXIMPApiEventBase, this )
       
   196 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
   197 
       
   198 XIMPIMP_IF_BASE_GET_CONST_INTERFACE_BEGIN( CPresentityGroupListEventImp,
       
   199                                            MPresentityGroupListEvent )
       
   200     XIMPIMP_IF_BASE_GET_CONST_CLASS( CXIMPApiEventBase, this )                                            
       
   201 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
   202 
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // Implement methods from base event interface and base event class
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 XIMPIMP_IMPLEMENT_EVENT_BASE_METHODS( CPresentityGroupListEventImp,
       
   209                                       MPresentityGroupListEvent )
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CPresentityGroupListEventImp::EqualsContent()
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 TBool CPresentityGroupListEventImp::EqualsContent( 
       
   217     const CXIMPApiEventBase& aOtherInstance ) const
       
   218     {
       
   219     const CPresentityGroupListEventImp* tmp =
       
   220     TXIMPGetImpClassOrPanic< const CPresentityGroupListEventImp >::From( 
       
   221                                                         aOtherInstance.Base() );
       
   222     
       
   223     TBool same = ETrue;
       
   224 
       
   225     TBool x;
       
   226     x = CompareArrays( iCreatedGroups, tmp->iCreatedGroups );
       
   227     same &= x;
       
   228 
       
   229     x = CompareArrays( iUpdatedGroups, tmp->iUpdatedGroups );
       
   230     same &= x;
       
   231 
       
   232     x = CompareArrays( iDeletedGroups, tmp->iDeletedGroups );
       
   233     same &= x;
       
   234     
       
   235     x = CompareArrays( iCurrentGroups, tmp->iCurrentGroups );
       
   236     same &= x;
       
   237 
       
   238     x = iSubscriptionState->EqualsContent( *tmp->iSubscriptionState );
       
   239     same &= x;
       
   240 
       
   241     return same;
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // CPresentityGroupListEventImp::CompareArrays
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 TBool CPresentityGroupListEventImp::CompareArrays(
       
   249         RPrGrpInfoImpArray* aA, RPrGrpInfoImpArray* aB )
       
   250     {
       
   251     TBool same = ETrue;
       
   252 
       
   253     TBool x;
       
   254     x = aA->Count() == aB->Count();   // counts must match
       
   255     same &= x;
       
   256 
       
   257     if ( ! same )
       
   258         {
       
   259         // don't bother checking further if counts mismatch
       
   260         return same;
       
   261         }
       
   262 
       
   263     // now check whole array, arrays have equal length
       
   264     for ( TInt i = 0; i < aA->Count(); i++ )
       
   265         {
       
   266         x = 0 == ( (*aA)[ i ]->GroupId().Identity().Compare(
       
   267                     (*aB)[ i ]->GroupId().Identity() ) );
       
   268         same &= x;
       
   269 
       
   270         x = 0 == ( (*aA)[ i ]->GroupDisplayName().Compare(
       
   271                     (*aB)[ i ]->GroupDisplayName() ) );
       
   272         same &= x;
       
   273         }
       
   274 
       
   275     return same;
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // From class CXIMPApiEventBase.
       
   280 // CPresentityGroupListEventImp::ExternalizeL()
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 void CPresentityGroupListEventImp::ExternalizeL( RWriteStream& aStream ) const
       
   284     {
       
   285     WriteArrayToStreamL( *iCreatedGroups, aStream );
       
   286     WriteArrayToStreamL( *iUpdatedGroups, aStream );
       
   287     WriteArrayToStreamL( *iDeletedGroups, aStream );
       
   288     WriteArrayToStreamL( *iCurrentGroups, aStream );
       
   289 
       
   290     iSubscriptionState->ExternalizeL( aStream );
       
   291     }
       
   292 
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // From class MPresentityGroupListEvent.
       
   296 // CPresentityGroupListEventImp::NewGroupsCount()
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 TInt CPresentityGroupListEventImp::NewGroupsCount() const
       
   300     {
       
   301     return iCreatedGroups->Count();
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // From class MPresentityGroupListEvent.
       
   306 // CPresentityGroupListEventImp::NewGroup()
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 const MPresentityGroupInfo&
       
   310             CPresentityGroupListEventImp::NewGroup( TInt aIndex ) const
       
   311     {
       
   312     return *(*iCreatedGroups)[ aIndex ];
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // From class MPresentityGroupListEvent.
       
   317 // CPresentityGroupListEventImp::UpdatedGroupsCount()
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 TInt CPresentityGroupListEventImp::UpdatedGroupsCount() const
       
   321     {
       
   322     return iUpdatedGroups->Count();
       
   323     }
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 // From class MPresentityGroupListEvent.
       
   327 // CPresentityGroupListEventImp::UpdatedGroup()
       
   328 // ---------------------------------------------------------------------------
       
   329 //
       
   330 const MPresentityGroupInfo&
       
   331         CPresentityGroupListEventImp::UpdatedGroup( TInt aIndex ) const
       
   332     {
       
   333     return *(*iUpdatedGroups)[ aIndex ];
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // From class MPresentityGroupListEvent.
       
   338 // CPresentityGroupListEventImp::DisappearedGroupsCount()
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 TInt CPresentityGroupListEventImp::DisappearedGroupsCount() const
       
   342     {
       
   343     return iDeletedGroups->Count();
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // From class MPresentityGroupListEvent.
       
   348 // CPresentityGroupListEventImp::DisappearedGroup()
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 const MPresentityGroupInfo&
       
   352 CPresentityGroupListEventImp::DisappearedGroup( TInt aIndex ) const
       
   353     {
       
   354     return *(*iDeletedGroups)[ aIndex ];
       
   355     }
       
   356 
       
   357 // ---------------------------------------------------------------------------
       
   358 // From class MPresentityGroupListEvent.
       
   359 // CPresentityGroupListEventImp::CurrentGroupsCount()
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 TInt CPresentityGroupListEventImp::CurrentGroupsCount() const
       
   363     {
       
   364     return iCurrentGroups->Count();
       
   365     }
       
   366 
       
   367 // ---------------------------------------------------------------------------
       
   368 // From class MPresentityGroupListEvent.
       
   369 // CPresentityGroupListEventImp::CurrentGroup()
       
   370 // ---------------------------------------------------------------------------
       
   371 //
       
   372 const MPresentityGroupInfo& 
       
   373     CPresentityGroupListEventImp::CurrentGroup( TInt aIndex ) const
       
   374     {
       
   375     return *(*iCurrentGroups)[ aIndex ];
       
   376     }
       
   377 
       
   378 // ---------------------------------------------------------------------------
       
   379 // From class MPresentityGroupListEvent.
       
   380 // CPresentityGroupListEventImp::Status()
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 const MXIMPDataSubscriptionState&
       
   384     CPresentityGroupListEventImp::DataSubscriptionState() const
       
   385     {
       
   386     return *iSubscriptionState;
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // CPresentityGroupListEventImp::WriteArrayToStreamL()
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 void CPresentityGroupListEventImp::WriteArrayToStreamL(
       
   394         RPrGrpInfoImpArray& aArray, RWriteStream& aStream ) const
       
   395     {
       
   396     TInt count = aArray.Count();
       
   397     aStream.WriteInt32L( count );
       
   398         {
       
   399         for( TInt a = 0; a < count; ++a )
       
   400             {
       
   401             aArray[ a ]->ExternalizeL( aStream );
       
   402             }
       
   403         }
       
   404     }
       
   405 
       
   406 // ---------------------------------------------------------------------------
       
   407 // CPresentityGroupListEventImp::FillArrayFromStreamL
       
   408 // ---------------------------------------------------------------------------
       
   409 //
       
   410 void CPresentityGroupListEventImp::FillArrayFromStreamL(
       
   411         RPrGrpInfoImpArray& aArray,
       
   412         RReadStream& aStream )
       
   413     {
       
   414     TInt count = aStream.ReadInt32L();
       
   415     for( TInt a = 0; a < count; ++a )
       
   416         {
       
   417         // the stream MUST be in order (since it was externalized by this class)
       
   418         CPresentityGroupInfoImp* newInfo = CPresentityGroupInfoImp::NewLC();
       
   419         newInfo->InternalizeL( aStream );
       
   420         aArray.AppendL( newInfo );
       
   421         CleanupStack::Pop(); // newInfo
       
   422         }
       
   423     }
       
   424 
       
   425 // End of file
       
   426