IMPSengine/client/src/impspurecommand.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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: 
       
    15 *       WV engine pure data command
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32std.h>
       
    23 
       
    24 #include "impspurecli.h"
       
    25 #include "impspurecommand.h"
       
    26 #include "ImpsFields.h"
       
    27 #include "ImpsPacked.h"
       
    28 #include "impsutils.h"
       
    29 #include "ImpsDataAccessor.h"
       
    30 
       
    31 // MACROS
       
    32 #ifndef _DEBUG
       
    33 #define _NO_IMPS_LOGGING_
       
    34 #endif
       
    35 
       
    36 // ================= MEMBER FUNCTIONS =======================
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // CImpsPureCommand2::CImpsPureCommand2
       
    40 // ----------------------------------------------------------------------------
       
    41 CImpsPureCommand2::CImpsPureCommand2( 
       
    42     TInt aPriority, 
       
    43     RImpsPureClient2& aClient  ) :
       
    44     CActive( aPriority ), iClient( aClient ),
       
    45         iMessagePtr()
       
    46     {
       
    47     CActiveScheduler::Add( this );
       
    48     }
       
    49 
       
    50 // ----------------------------------------------------------------------------
       
    51 // CImpsPureCommand2::NewL
       
    52 // ----------------------------------------------------------------------------
       
    53 CImpsPureCommand2* CImpsPureCommand2::NewL( RImpsPureClient2& aClient )
       
    54      {
       
    55 
       
    56       // Perform the construction.
       
    57       CImpsPureCommand2* self = new (ELeave) CImpsPureCommand2( 
       
    58                                                    EPriorityUserInput, aClient);
       
    59 
       
    60       return self;
       
    61      }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // CImpsPureCommand2::~CImpsPureCommand2
       
    65 // ----------------------------------------------------------------------------
       
    66 CImpsPureCommand2::~CImpsPureCommand2()
       
    67      {
       
    68      // Cancel any outstanding requests
       
    69      Cancel();
       
    70 
       
    71      ResetMembers();
       
    72      }
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // CImpsPureCommand2::StartRunL
       
    76 // ----------------------------------------------------------------------------
       
    77 void CImpsPureCommand2::StartRunL( 
       
    78     TInt                aOpId,
       
    79     TImpsServRequest    aType )
       
    80     {
       
    81     iOpId = aOpId;
       
    82     iType = aType;
       
    83 
       
    84     if ( IsActive() )
       
    85         {
       
    86         User::Leave( KErrServerBusy );
       
    87         }
       
    88 
       
    89     // Set this active object active
       
    90     iStatus = KRequestPending;
       
    91     SetActive();
       
    92     }
       
    93 
       
    94 // ----------------------------------------------------------------------------
       
    95 // CImpsPureCommand2::RunL
       
    96 // ----------------------------------------------------------------------------
       
    97 
       
    98 void CImpsPureCommand2::RunL()
       
    99     {
       
   100 #ifndef _NO_IMPS_LOGGING_
       
   101     CImpsClientLogger::Log(_L("CImpsPureCommand2: RunL stat=%d h=%d cli=%d"), 
       
   102         iStatus.Int(), (TInt)this, (TInt)&iClient );
       
   103 #endif
       
   104 
       
   105     MImpsErrorHandler2* ehandler = iClient.ErrorHandler();
       
   106     // Successful cases are handled by CImpsImHandler.
       
   107     if ( iStatus == KErrNone )
       
   108         {
       
   109         return;
       
   110         }
       
   111 
       
   112     // Handler should be registered
       
   113     if ( ehandler )
       
   114         {
       
   115         TInt err( KErrNone );
       
   116         TRAP( err, ehandler->HandleErrorL( 
       
   117             iStatus.Int(),
       
   118             iOpId,
       
   119             NULL,
       
   120             NULL,
       
   121             *iClient.CspIdentifier() ));
       
   122         }
       
   123     }
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // CImpsPureCommand2::DoCancel
       
   127 // Before calling this the Cancel should have sent to the engine! 
       
   128 // ----------------------------------------------------------------------------
       
   129 void CImpsPureCommand2::DoCancel()
       
   130     {
       
   131     }
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // CImpsPureCommand2::ResetMembers
       
   135 // ----------------------------------------------------------------------------
       
   136 void CImpsPureCommand2::ResetMembers( )
       
   137     {
       
   138     delete iImpsFields;
       
   139     iImpsFields = NULL;
       
   140     if ( iKey )
       
   141         iKey->Destroy( );
       
   142     iKey = NULL;
       
   143     delete iAccessor;
       
   144     iAccessor = NULL;
       
   145     delete iMessage;
       
   146     iMessage = NULL;
       
   147     iMessagePtr.Set ( KNullDesC8 );
       
   148     }
       
   149 
       
   150 // ----------------------------------------------------------------------------
       
   151 // CImpsPureCommand2::InitialiseL
       
   152 // ----------------------------------------------------------------------------
       
   153 void CImpsPureCommand2::InitialiseL( const TImpsContent* aElementArray,
       
   154                                     const TUint aArraySize )
       
   155     {
       
   156     iImpsFields = CImpsFields::NewL();
       
   157     iAccessor = CImpsDataAccessor::NewL( iImpsFields );
       
   158     iKey = iAccessor->NewKeyL();
       
   159     for( TUint i = 0;i < aArraySize;i++ )
       
   160         iKey->AddL( CREATEKEY( aElementArray[i], 0 ) );
       
   161     }
       
   162 
       
   163 // ----------------------------------------------------------------------------
       
   164 // CImpsPureCommand2::InsertElementL
       
   165 // ----------------------------------------------------------------------------
       
   166 void CImpsPureCommand2::InsertElementL( const TDesC8& aElementValue,
       
   167                      const TImpsContent aElementName )
       
   168     {
       
   169     iKey->AddL( CREATEKEY( aElementName, 0 ) );
       
   170     iAccessor->StoreDesc8L( iKey, aElementValue );
       
   171     iKey->PopL( );
       
   172     }
       
   173 
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CImpsPureCommand2::SetMessageType
       
   177 // ----------------------------------------------------------------------------
       
   178 void CImpsPureCommand2::SetMessageType( TImpsMessageType aMsgType )
       
   179     {
       
   180     iMessageType = aMsgType;
       
   181     }
       
   182 
       
   183 // ----------------------------------------------------------------------------
       
   184 // CImpsPureCommand2::PackMessageL
       
   185 // ----------------------------------------------------------------------------
       
   186 TInt CImpsPureCommand2::PackMessageL( )
       
   187     {
       
   188     iImpsFields->SetMessageType( iMessageType );
       
   189     iMessage = HBufC8::NewL( iImpsFields->Size() );
       
   190     TImpsPackedEntity packedMessage( iMessage );
       
   191     TInt error = packedMessage.PackEntity( *iImpsFields );
       
   192     return error;
       
   193     }
       
   194 
       
   195 // ----------------------------------------------------------------------------
       
   196 // CImpsPureCommand2::PackAndSendL
       
   197 // ----------------------------------------------------------------------------
       
   198 TInt CImpsPureCommand2::PackAndSendL( TImpsMessageType aMsgType, TInt aOpId )
       
   199     {
       
   200     SetMessageType( aMsgType );
       
   201     TInt error = PackMessageL( );
       
   202     if( error == KErrNone )
       
   203         {
       
   204         // p[ 0 ] = ( TAny* )( iMessage );
       
   205         // p[ 1 ] = ( TAny* )( aOpId );
       
   206         iMessagePtr.Set( iMessage->Des() );
       
   207         TImpsServRequest req = EImpsServPres;
       
   208         error = iClient.SendReceive( req, TIpcArgs( &iMessagePtr, aOpId ) );
       
   209         }
       
   210    	return error;
       
   211     }
       
   212 //  End of File  
       
   213