PECengine/AttributeLibrary2/SrcTransactions/CPEngAttributeFetchHandler.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Attribute fetch handler.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CPEngAttributeFetchHandler.h"
       
    20 #include "MPEngAttrFetchProcessor.h"
       
    21 #include "MPEngPresenceAttrManager.h"
       
    22 #include "MPEngPresenceAdvancedAttrModel2.h"
       
    23 #include "CPEngTransactionStatus.h"
       
    24 
       
    25 #include "PresenceDebugPrint.h"
       
    26 #include <PEngPresenceEngineConsts2.h>
       
    27 #include <E32Std.h>
       
    28 #include <badesca.h>
       
    29 
       
    30 
       
    31 
       
    32 
       
    33 
       
    34 //LOCAL constants
       
    35 namespace
       
    36     {
       
    37     /**
       
    38      * Granularity for array of fetched presence ids.
       
    39      * Usually there is just few fetched presence id's
       
    40      * at time.
       
    41      */
       
    42     const TInt KPEngFetchPresIdGranurality = 5;
       
    43 
       
    44     //Panic
       
    45     _LIT( KPEngAttrFetchHandlerPanic, "PEngAtFeHand" );
       
    46 
       
    47     //Panic reasons
       
    48     enum TPEngAttrFetchHandlerPanicReasons
       
    49         {
       
    50         EFetchHandlerInUse
       
    51         };
       
    52 
       
    53     void PEngAttrFetchHandlerPanic( TPEngAttrFetchHandlerPanicReasons aPanicReason )
       
    54         {
       
    55         User::Panic( KPEngAttrFetchHandlerPanic, aPanicReason );
       
    56         }
       
    57     }
       
    58 
       
    59 
       
    60 
       
    61 // ============================ MEMBER FUNCTIONS ===============================
       
    62 // -----------------------------------------------------------------------------
       
    63 // CPEngAttributeFetchHandler::NewL()
       
    64 // Two-phased constructor.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CPEngAttributeFetchHandler* CPEngAttributeFetchHandler::NewLC( MPEngPresenceAttrManager& aAttrManager,
       
    68                                                                const TDesC& aDomain,
       
    69                                                                const TDesC16& aData,
       
    70                                                                TInt aTransactionOperation,
       
    71                                                                TPEngWVCspVersion aCspVersion )
       
    72     {
       
    73     CPEngAttributeFetchHandler* self = new ( ELeave ) CPEngAttributeFetchHandler(
       
    74         aAttrManager,
       
    75         aTransactionOperation );
       
    76 
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL( aDomain, aCspVersion, aData );
       
    79     return self;
       
    80     }
       
    81 
       
    82 
       
    83 // Destructor
       
    84 CPEngAttributeFetchHandler::~CPEngAttributeFetchHandler()
       
    85     {
       
    86     Cancel();
       
    87     delete iFetchedProcessor;
       
    88     iResultModels.ResetAndDestroy();
       
    89     delete iResultStatus;
       
    90     }
       
    91 
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CPEngAttributeFetchHandler::CPEngAttributeFetchHandler
       
    95 // C++ default constructor can NOT contain any code, that
       
    96 // might leave.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 CPEngAttributeFetchHandler::CPEngAttributeFetchHandler( MPEngPresenceAttrManager& aAttrManager,
       
   100                                                         TInt aTransactionOperation )
       
   101         : CActive( CActive::EPriorityIdle ),    //Do parsing in low priority
       
   102         iAttributeManager( aAttrManager ),
       
   103         iTransactionOperation( aTransactionOperation )
       
   104     {
       
   105     CActiveScheduler::Add( this );
       
   106     }
       
   107 
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CPEngAttributeFetchHandler::ConstructL()
       
   111 // Symbian 2nd phase constructor can leave.
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CPEngAttributeFetchHandler::ConstructL( const TDesC& aDomain,
       
   115                                              TPEngWVCspVersion aCspVersion,
       
   116                                              const TDesC16& aData )
       
   117     {
       
   118     iResultStatus = CPEngTransactionStatus::NewL();
       
   119 
       
   120     RArray< TUint32 > attributes;
       
   121     CleanupClosePushL( attributes );
       
   122 
       
   123     CDesC16ArraySeg* presenceIds =  new ( ELeave ) CDesC16ArraySeg(
       
   124         KPEngFetchPresIdGranurality );
       
   125     CleanupStack::PushL( presenceIds );
       
   126 
       
   127     iAttributeManager.UnpackFetchRequestL( aData,
       
   128                                            *presenceIds,
       
   129                                            attributes );
       
   130 
       
   131     iFetchedProcessor = CreateAttrFetchProcessorL( iAttributeManager,
       
   132                                                    *presenceIds,
       
   133                                                    attributes.Array(),
       
   134                                                    aDomain,
       
   135                                                    iTransactionOperation,
       
   136                                                    aCspVersion );
       
   137 
       
   138     CleanupStack::PopAndDestroy( presenceIds );
       
   139     CleanupStack::PopAndDestroy(); //attributes
       
   140     }
       
   141 
       
   142 
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CPEngAttributeFetchHandler::RequestL()
       
   146 // From MPEngOutgoingTransactionHandler
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CPEngAttributeFetchHandler::RequestL( TDes8& aSendBuffer )
       
   150     {
       
   151     PENG_DP_TXT( "CPEngAttributeFetchHandler::RequestL()" );
       
   152 
       
   153     aSendBuffer.Zero();
       
   154     iFetchedProcessor->GenerateRequestL( aSendBuffer );
       
   155 
       
   156     PENG_DP_TXT( "CPEngAttributeFetchHandler::RequestL() - Done" );
       
   157     }
       
   158 
       
   159 
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CPEngAttributeFetchHandler::LastRunningTransactionHandler()
       
   163 // From MPEngOutgoingTransactionHandler
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void CPEngAttributeFetchHandler::LastRunningTransactionHandler()
       
   167     {
       
   168     PENG_DP_TXT( "CPEngAttributeFetchHandler::LastRunningTransactionHandler()" );
       
   169     //nothing to do
       
   170     }
       
   171 
       
   172 
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CPEngAttributeFetchHandler::ProcessResponseL()
       
   176 // From MPEngOutgoingTransactionHandler
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void CPEngAttributeFetchHandler::ProcessResponseL( const TDesC8& aResponse,
       
   180                                                    TRequestStatus& /*aStatus*/ )
       
   181 
       
   182     {
       
   183     PENG_DP_TXT( "CPEngAttributeFetchHandler::ProcessResponseL()" );
       
   184 
       
   185     __ASSERT_ALWAYS( !iRequest,
       
   186                      PEngAttrFetchHandlerPanic( EFetchHandlerInUse ) );
       
   187 
       
   188 
       
   189     // Initialize the response parsing
       
   190     // Will leave if response is corrupted
       
   191     iFetchedProcessor->InitResponseProcessingL( aResponse,
       
   192                                                 iResultModels,
       
   193                                                 *iResultStatus );
       
   194 
       
   195     //Temporary solution to do response handling synchronously
       
   196     while ( iFetchedProcessor->ProcessStepL() )
       
   197         {
       
   198         }
       
   199 
       
   200     if ( iTransactionOperation == EPEngTransOpAttributeFetchToObjects )
       
   201         {
       
   202         PENG_DP_TXT( "CPEngAttributeFetchHandler::ProcessResponseL() - parsing done. Streaming result models to objects." );
       
   203 
       
   204         HBufC16* dataResult = iAttributeManager.PackModelArrayL( iResultModels );
       
   205         CleanupStack::PushL( dataResult );
       
   206         iResultStatus->AddDataResultL( iTransactionOperation, dataResult );
       
   207         CleanupStack::Pop( dataResult );
       
   208         }
       
   209     else
       
   210         {
       
   211         PENG_DP_TXT( "CPEngAttributeFetchHandler::ProcessResponseL() - parsing done. Storing result models to cache." );
       
   212 
       
   213         iAttributeManager.ForceStoreBatchL( iResultModels );
       
   214         }
       
   215 
       
   216 
       
   217     //And start asynchronous processing
       
   218     /*
       
   219     iRequest = &aStatus;
       
   220     *iRequest = KRequestPending;
       
   221     IssueNewRound();
       
   222     */
       
   223 
       
   224     PENG_DP_TXT( "CPEngAttributeFetchHandler::ProcessResponseL() - Done" );
       
   225     }
       
   226 
       
   227 
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CPEngAttributeFetchHandler::CancelProcessing()
       
   231 // From MPEngOutgoingTransactionHandler
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void CPEngAttributeFetchHandler::CancelProcessing()
       
   235     {
       
   236     PENG_DP_TXT( "CPEngAttributeFetchHandler::CancelProcessing()" );
       
   237     Cancel();
       
   238     }
       
   239 
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CPEngAttributeFetchHandler::NewTransactionHandlersL()
       
   243 // From MPEngOutgoingTransactionHandler
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CPEngAttributeFetchHandler::NewTransactionHandlersL(
       
   247     RPointerArray<MPEngOutgoingTransactionHandler>& /*aHandlers*/ )
       
   248     {
       
   249     PENG_DP_TXT( "CPEngAttributeFetchHandler::NewTransactionHandlersL()" );
       
   250     }
       
   251 
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CPEngAttributeFetchHandler::TransactionCompleted()
       
   255 // From MPEngOutgoingTransactionHandler
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 TBool CPEngAttributeFetchHandler::TransactionCompleted()
       
   259     {
       
   260     PENG_DP_TXT( "CPEngAttributeFetchHandler::TransactionCompleted()" );
       
   261     return ETrue;
       
   262     }
       
   263 
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CPEngAttributeFetchHandler::TransactionResult()
       
   267 // From MPEngOutgoingTransactionHandler
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 CPEngTransactionStatus* CPEngAttributeFetchHandler::TransactionResult()
       
   271     {
       
   272     PENG_DP_TXT( "CPEngAttributeFetchHandler::TransactionResult()" );
       
   273 
       
   274     CPEngTransactionStatus* tmp = iResultStatus;
       
   275     iResultStatus = NULL;
       
   276     return tmp;
       
   277     }
       
   278 
       
   279 
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CPEngAttributeFetchHandler::ReleaseHandler()
       
   283 // From MPEngOutgoingTransactionHandler
       
   284 // -----------------------------------------------------------------------------
       
   285 //
       
   286 void CPEngAttributeFetchHandler::ReleaseHandler()
       
   287     {
       
   288     //nothing to do
       
   289     }
       
   290 
       
   291 
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CPEngAttributeFetchHandler::RunL()
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 void CPEngAttributeFetchHandler::RunL()
       
   298     {
       
   299     PENG_DP_TXT( "CPEngAttributeFetchHandler::RunL()" );
       
   300     if ( iFetchedProcessor->ProcessStepL() )
       
   301         {
       
   302         PENG_DP_TXT( "CPEngAttributeFetchHandler::RunL() - issuing new round." );
       
   303         IssueNewRound();
       
   304         return;
       
   305         }
       
   306 
       
   307     if ( iTransactionOperation == EPEngTransOpAttributeFetchToObjects )
       
   308         {
       
   309         PENG_DP_TXT( "CPEngAttributeFetchHandler::RunL() - parsing done. Streaming result models to objects." );
       
   310 
       
   311         HBufC16* dataResult = iAttributeManager.PackModelArrayL( iResultModels );
       
   312         CleanupStack::PushL( dataResult );
       
   313         iResultStatus->AddDataResultL( iTransactionOperation, dataResult );
       
   314         CleanupStack::Pop( dataResult );
       
   315         }
       
   316     else
       
   317         {
       
   318         PENG_DP_TXT( "CPEngAttributeFetchHandler::RunL() - parsing done. Storing result models to cache." );
       
   319 
       
   320         iAttributeManager.ForceStoreBatchL( iResultModels );
       
   321         }
       
   322 
       
   323 
       
   324     iResultModels.ResetAndDestroy();
       
   325     User::RequestComplete( iRequest, KErrNone );
       
   326     }
       
   327 
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // CPEngAttributeFetchHandler::RunError()
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 TInt CPEngAttributeFetchHandler::RunError( TInt aError )
       
   334     {
       
   335     PENG_DP( D_PENG_LIT( "CPEngAttributeFetchHandler::RunError(): %d" ), aError );
       
   336 
       
   337     iResultModels.ResetAndDestroy();
       
   338     User::RequestComplete( iRequest, aError );
       
   339     return KErrNone;
       
   340     }
       
   341 
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // CPEngAttributeFetchHandler::DoCancel()
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 void CPEngAttributeFetchHandler::DoCancel()
       
   348     {
       
   349     iResultModels.ResetAndDestroy();
       
   350     User::RequestComplete( iRequest, KErrCancel );
       
   351     }
       
   352 
       
   353 
       
   354 // -----------------------------------------------------------------------------
       
   355 // CPEngAttributeFetchHandler::IssueNewRound()
       
   356 // -----------------------------------------------------------------------------
       
   357 //
       
   358 void CPEngAttributeFetchHandler::IssueNewRound()
       
   359     {
       
   360     iStatus = KRequestPending;
       
   361 
       
   362     TRequestStatus *pS = &iStatus;
       
   363     User::RequestComplete( pS, KErrNone );
       
   364     SetActive();
       
   365     }
       
   366 
       
   367 
       
   368 //  End of File
       
   369 
       
   370