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