ximpfw/core/srcdatamodel/ximprequestcompleteeventimp.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 /*
       
     2 * Copyright (c) 2009 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:  MXIMPRequestCompleteEvent API object implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32strm.h>
       
    20 
       
    21 #include "ximprequestcompleteeventimp.h"
       
    22 #include "ximpstatusimp.h"
       
    23 #include "ximpapidataobjfactory.h"
       
    24 #include "ximpapidataobjbase.h"
       
    25 
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // CXIMPRequestCompleteEventImp::NewL()
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C CXIMPRequestCompleteEventImp* CXIMPRequestCompleteEventImp::NewL()
       
    32     {
       
    33     TXIMPRequestId nullId = TXIMPRequestId::Null();
       
    34     
       
    35     CXIMPRequestCompleteEventImp* self =
       
    36             new( ELeave ) CXIMPRequestCompleteEventImp( nullId );
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL( KErrNone );
       
    39     CleanupStack::Pop( self );
       
    40     return self;
       
    41     }
       
    42 
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CXIMPRequestCompleteEventImp::NewLC()
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C CXIMPRequestCompleteEventImp* CXIMPRequestCompleteEventImp::NewLC(
       
    50        TXIMPRequestId& aRequestId, TInt aDefaultErrorValue )
       
    51     {
       
    52     CXIMPRequestCompleteEventImp* self =
       
    53             new( ELeave ) CXIMPRequestCompleteEventImp( aRequestId );
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL( aDefaultErrorValue );
       
    56     return self;
       
    57     }
       
    58 
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CXIMPRequestCompleteEventImp::NewLC()
       
    62 // Instantiation method for event automation.
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CXIMPApiEventBase*
       
    66     CXIMPRequestCompleteEventImp::NewFromStreamLC( RReadStream& aStream )
       
    67     {
       
    68     CXIMPRequestCompleteEventImp* self = new( ELeave ) CXIMPRequestCompleteEventImp;
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL( aStream );
       
    71     return self;
       
    72     }
       
    73 
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CXIMPRequestCompleteEventImp::~CXIMPRequestCompleteEventImp()
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CXIMPRequestCompleteEventImp::~CXIMPRequestCompleteEventImp()
       
    80     {
       
    81     delete iResult;
       
    82 
       
    83     // remove the owned objects
       
    84     for ( TInt i = 0; i < iParamArray.Count(); i++ )
       
    85         {
       
    86         SXIMPReqParam param = iParamArray[i];
       
    87         delete param.iParam;
       
    88         param.iParam = NULL;
       
    89         }
       
    90     iParamArray.Close();
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CXIMPRequestCompleteEventImp::CXIMPRequestCompleteEventImp()
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CXIMPRequestCompleteEventImp::CXIMPRequestCompleteEventImp()
       
    99     {
       
   100     }
       
   101 
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CXIMPRequestCompleteEventImp::CXIMPRequestCompleteEventImp()
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 CXIMPRequestCompleteEventImp::CXIMPRequestCompleteEventImp(
       
   108     TXIMPRequestId& aRequestId ) :
       
   109     iReqId( aRequestId )
       
   110     {
       
   111     }
       
   112 
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CXIMPRequestCompleteEventImp::ConstructL()
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CXIMPRequestCompleteEventImp::ConstructL( TInt aDefaultErrorValue )
       
   119     {
       
   120     iResult = CXIMPStatusImp::NewL();
       
   121     iResult->SetResultCode( aDefaultErrorValue );
       
   122     }
       
   123 
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CXIMPRequestCompleteEventImp::ConstructL()
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void CXIMPRequestCompleteEventImp::ConstructL( RReadStream& aStream )
       
   130     {
       
   131     // normal params
       
   132     TPckgBuf< TXIMPRequestId > bufReqId;
       
   133     aStream.ReadL( bufReqId );
       
   134     iReqId = bufReqId();
       
   135 
       
   136     iResult = CXIMPStatusImp::NewL();
       
   137     iResult->InternalizeL( aStream );
       
   138 
       
   139     // the array with variable parameters
       
   140     XIMPApiDataObjFactory::InternalizeL( aStream, iParamArray );
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // Implement supported interface access.
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 XIMPIMP_IF_BASE_GET_INTERFACE_BEGIN( CXIMPRequestCompleteEventImp,
       
   148                                      MXIMPRequestCompleteEvent )
       
   149     XIMPIMP_IF_BASE_GET_CLASS( CXIMPApiEventBase, this )
       
   150 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
   151 
       
   152 XIMPIMP_IF_BASE_GET_CONST_INTERFACE_BEGIN( CXIMPRequestCompleteEventImp,
       
   153                                            MXIMPRequestCompleteEvent )
       
   154     XIMPIMP_IF_BASE_GET_CONST_CLASS( CXIMPApiEventBase, this )
       
   155 XIMPIMP_IF_BASE_GET_INTERFACE_END()
       
   156 
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // Implement methods from base event interface and base event class
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 XIMPIMP_IMPLEMENT_EVENT_BASE_METHODS( CXIMPRequestCompleteEventImp,
       
   163                                       MXIMPRequestCompleteEvent )
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // CXIMPRequestCompleteEventImp::RequestId()
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 const TXIMPRequestId& CXIMPRequestCompleteEventImp::RequestId() const
       
   170     {
       
   171     return iReqId;
       
   172     }
       
   173 
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // CXIMPRequestCompleteEventImp::CompletionResult()
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 const MXIMPStatus& CXIMPRequestCompleteEventImp::CompletionResult() const
       
   180     {
       
   181     return *iResult;
       
   182     }
       
   183 
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CXIMPRequestCompleteEventImp::LookupCompletionDataByType()
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 const MXIMPBase* CXIMPRequestCompleteEventImp::LookupCompletionDataByType(
       
   191     TInt32 aInterfaceId ) const
       
   192     {
       
   193     const TInt count = iParamArray.Count();
       
   194     for( TInt i = 0; i < count; i++ )
       
   195         {
       
   196         if( iParamArray[ i ].iParamType == aInterfaceId )
       
   197             {
       
   198             return &iParamArray[ i ].iParam->Base();
       
   199             }
       
   200         }
       
   201 
       
   202     return NULL;
       
   203     }
       
   204 
       
   205 
       
   206 
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // CXIMPRequestCompleteEventImp::SetRequestId()
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 EXPORT_C void CXIMPRequestCompleteEventImp::SetRequestId( const TXIMPRequestId& aRequestId )
       
   213     {
       
   214     iReqId = aRequestId;
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // CXIMPRequestCompleteEventImp::EqualsContent
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 TBool CXIMPRequestCompleteEventImp::EqualsContent(
       
   222     const CXIMPApiEventBase& aOtherInstance ) const
       
   223     {
       
   224     const CXIMPRequestCompleteEventImp* tmp =
       
   225     TXIMPGetImpClassOrPanic< const CXIMPRequestCompleteEventImp >::From(
       
   226                                                         aOtherInstance.Base() );
       
   227 
       
   228     TBool same = ETrue;
       
   229 
       
   230     TBool x = ( iResult->ResultCode() == tmp->iResult->ResultCode() );
       
   231     same &= x;
       
   232 
       
   233     x = ( 0 == iResult->ProtocolResultDescription().Compare(
       
   234                 tmp->iResult->ProtocolResultDescription() ) );
       
   235     same &= x;
       
   236 
       
   237     // check parameter arrays for equality
       
   238     TInt myCount = iParamArray.Count();
       
   239     TInt otherCount = tmp->iParamArray.Count();
       
   240 
       
   241     x = myCount == otherCount;
       
   242     same &= x;
       
   243 
       
   244     if ( x )
       
   245         {
       
   246         // don't do potentially expensive operation unless arrays are
       
   247         // have same number of elements
       
   248 
       
   249         for ( TInt i = 0; i < myCount; i++ )
       
   250             {
       
   251             // assumes the parameters are IN ORDER
       
   252             x = iParamArray[ i ].iParam->EqualsContent( *( tmp->iParamArray[ i ].iParam ) );
       
   253             same &= x;
       
   254             }
       
   255         }
       
   256 
       
   257     return same;
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // CXIMPRequestCompleteEventImp::ExternalizeL()
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 void CXIMPRequestCompleteEventImp::ExternalizeL( RWriteStream& aStream ) const
       
   265     {
       
   266     // normal params
       
   267     TPckgBuf< TXIMPRequestId > bufReqId( iReqId );
       
   268     aStream.WriteL( bufReqId );
       
   269 
       
   270     iResult->ExternalizeL( aStream );
       
   271 
       
   272     // the array with variable parameters
       
   273     XIMPApiDataObjFactory::ExternalizeL( aStream, iParamArray );
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // CXIMPRequestCompleteEventImp::AppendParamL
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 EXPORT_C void CXIMPRequestCompleteEventImp::AppendParamL( CXIMPApiDataObjBase* aObj )
       
   281     {
       
   282     SXIMPReqParam param;
       
   283     param.iParamType = aObj->Base().GetInterfaceId();
       
   284     param.iParam = aObj;
       
   285     iParamArray.AppendL( param );
       
   286     }
       
   287 
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CXIMPRequestCompleteEventImp::CompletionResultImp()
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 EXPORT_C CXIMPStatusImp& CXIMPRequestCompleteEventImp::CompletionResultImp()
       
   294     {
       
   295     return *iResult;
       
   296     }
       
   297 
       
   298 // End of file
       
   299