ncdengine/provider/client/src/ncdloadnodeoperationproxy.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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:   CNcdLoadNodeOperationProxy class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <badesca.h>
       
    20 #include <s32strm.h>
       
    21 
       
    22 #include "ncdloadnodeoperationproxy.h"
       
    23 #include "ncdloadnodeoperationobserver.h"
       
    24 #include "ncdoperationfunctionids.h"
       
    25 #include "catalogsdebug.h"
       
    26 #include "catalogsclientserver.h"
       
    27 #include "ncdnodeidentifier.h"
       
    28 #include "ncdnodeproxy.h"
       
    29 #include "ncdnodemanagerproxy.h"
       
    30 #include "ncdoperationproxyremovehandler.h"
       
    31 #include "ncdqueryimpl.h"
       
    32 #include "ncdproviderdefines.h"
       
    33 #include "ncdnodefolderproxy.h"
       
    34 #include "ncdsearchrootnodeproxy.h"
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // ?description_if_needed
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CNcdLoadNodeOperationProxy* CNcdLoadNodeOperationProxy::NewL( 
       
    43     MCatalogsClientServer& aSession,
       
    44     TInt aHandle,
       
    45     MNcdOperationProxyRemoveHandler* aRemoveHandler,
       
    46     CNcdNodeProxy* aNode,
       
    47     CNcdNodeManagerProxy* aNodeManager,
       
    48     TBool aSearch,
       
    49     MNcdClientLocalizer* aLocalizer )
       
    50     {
       
    51     CNcdLoadNodeOperationProxy* self = CNcdLoadNodeOperationProxy::NewLC( 
       
    52         aSession,
       
    53         aHandle,
       
    54         aRemoveHandler,
       
    55         aNode,
       
    56         aNodeManager,
       
    57         aSearch,
       
    58         aLocalizer );
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // ?description_if_needed
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CNcdLoadNodeOperationProxy* CNcdLoadNodeOperationProxy::NewLC( 
       
    69     MCatalogsClientServer& aSession,
       
    70     TInt aHandle,
       
    71     MNcdOperationProxyRemoveHandler* aRemoveHandler,
       
    72     CNcdNodeProxy* aNode,
       
    73     CNcdNodeManagerProxy* aNodeManager,
       
    74     TBool aSearch,
       
    75     MNcdClientLocalizer* aLocalizer )
       
    76     {
       
    77     CNcdLoadNodeOperationProxy* self =
       
    78         new( ELeave ) CNcdLoadNodeOperationProxy( aSearch, aLocalizer );    
       
    79     self->AddRef();
       
    80     CleanupReleasePushL( *self );    
       
    81     self->ConstructL( aSession, aHandle, aRemoveHandler, aNode, aNodeManager );
       
    82     return self;
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // From MNcdLoadNodeOperation
       
    87 // ?implementation_description
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CNcdLoadNodeOperationProxy::AddObserverL(
       
    91     MNcdLoadNodeOperationObserver* aObserver )
       
    92     {
       
    93     DLTRACEIN(("adding observer: %d", aObserver ));
       
    94     iObservers.AppendL( aObserver );
       
    95     }
       
    96     
       
    97 // ---------------------------------------------------------------------------
       
    98 // From MNcdLoadNodeOperation
       
    99 // ?implementation_description
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 TInt CNcdLoadNodeOperationProxy::RemoveObserver(
       
   103     MNcdLoadNodeOperationObserver* aObserver )
       
   104     {
       
   105     DLTRACEIN((""));
       
   106     TInt index = iObservers.Find( aObserver );
       
   107     if ( index != KErrNotFound )
       
   108         {
       
   109         DLINFO(("removing observer: %d", iObservers[ index ] ));
       
   110         iObservers.Remove( index );
       
   111         return KErrNone;
       
   112         }
       
   113     else
       
   114         {
       
   115         return KErrNotFound;
       
   116         }
       
   117     }
       
   118     
       
   119 // ---------------------------------------------------------------------------
       
   120 // From MNcdConfigurationData
       
   121 // ?implementation_description
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 HBufC8* CNcdLoadNodeOperationProxy::ProtocolResponseDataL() 
       
   125     {
       
   126     HBufC8* buf(NULL);    
       
   127     // Get the configuration response data from server side operation.
       
   128     User::LeaveIfError( ClientServerSession().SendSyncAlloc( ENCDOperationFunctionGetData,
       
   129         SendBuf8L(),
       
   130         buf,
       
   131         Handle(),
       
   132         0 ) );
       
   133         
       
   134     return buf;
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // From MCatalogsBase
       
   139 // ?implementation_description
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 TNcdInterfaceId CNcdLoadNodeOperationProxy::OperationType() const
       
   143     {
       
   144     return static_cast<TNcdInterfaceId>(MNcdLoadNodeOperation::KInterfaceUid);
       
   145     }
       
   146 
       
   147 MNcdNodeContainer* CNcdLoadNodeOperationProxy::SearchRootNodeL()
       
   148     {
       
   149     CNcdSearchRootNodeProxy* searchRoot = &iNodeManager->SearchRootNodeL();
       
   150     searchRoot->AddRef();
       
   151     return searchRoot;
       
   152     }
       
   153 
       
   154 const TAny* CNcdLoadNodeOperationProxy::QueryInterfaceL( TInt aInterfaceId ) const
       
   155         {
       
   156         const TAny* result = NULL;
       
   157         switch( aInterfaceId )
       
   158             {
       
   159             case MNcdSearchOperation::KInterfaceUid:
       
   160                 {
       
   161                 if( iSearch )
       
   162                     {
       
   163                     result = static_cast< const MNcdSearchOperation* >( this );
       
   164                     }
       
   165                 break;
       
   166                 }
       
   167             case MNcdLoadNodeOperation::KInterfaceUid:
       
   168                 {
       
   169                 result = static_cast< const MNcdLoadNodeOperation* >( this );
       
   170                 break;
       
   171                 }
       
   172             case MNcdOperation::KInterfaceUid:
       
   173                 {
       
   174                 result = static_cast< const MNcdOperation* >( this );
       
   175                 break;
       
   176                 }
       
   177             case MCatalogsBase::KInterfaceUid:
       
   178                 {
       
   179                 result = static_cast< const MCatalogsBase* >( this );
       
   180                 break;
       
   181                 }
       
   182             case MNcdConfigurationData::KInterfaceUid:
       
   183                 {
       
   184                 if ( NodeProxy()->NodeIdentifier().NodeNameSpace() ==
       
   185                     NcdProviderDefines::KRootNodeNameSpace ) 
       
   186                     {
       
   187                     result = static_cast< const MNcdConfigurationData* >( this );
       
   188                     }
       
   189                 break;
       
   190                 }
       
   191             default:
       
   192                 {
       
   193                 break;
       
   194                 }
       
   195             }
       
   196 
       
   197         if( result != NULL )
       
   198             {
       
   199             AddRef();
       
   200             }
       
   201 
       
   202         return result;
       
   203         }        
       
   204 
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // ?description_if_needed
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 CNcdLoadNodeOperationProxy::CNcdLoadNodeOperationProxy(
       
   211     TBool aSearch, MNcdClientLocalizer* aLocalizer )
       
   212 : CNcdOperation< MNcdSearchOperation>( aLocalizer ), iSearch( aSearch )
       
   213     {
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // ?description_if_needed
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 CNcdLoadNodeOperationProxy::~CNcdLoadNodeOperationProxy()
       
   221     {    
       
   222     DLTRACEIN((""));
       
   223     iLoadedNodes.ResetAndDestroy();
       
   224     DASSERT( iRemoveHandler );
       
   225     if ( iRemoveHandler )
       
   226         {        
       
   227         DLTRACE(("Removing proxy from remove handler"));
       
   228         iRemoveHandler->RemoveOperationProxy( *this );
       
   229         }
       
   230     iObservers.Reset();
       
   231         
       
   232     DLTRACEOUT((""));
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // ?description_if_needed
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 void CNcdLoadNodeOperationProxy::ConstructL( MCatalogsClientServer& aSession,
       
   240     TInt aHandle,
       
   241     MNcdOperationProxyRemoveHandler* aRemoveHandler,
       
   242     CNcdNodeProxy* aNode,
       
   243     CNcdNodeManagerProxy* aNodeManager )
       
   244     {
       
   245     // first call parent's ConstructL
       
   246     CNcdBaseOperationProxy::ConstructL( aSession,
       
   247                                         aHandle,
       
   248                                         aRemoveHandler,
       
   249                                         aNode,
       
   250                                         aNodeManager );
       
   251     iNodeManager = aNodeManager;
       
   252     }
       
   253     
       
   254 // ---------------------------------------------------------------------------
       
   255 // ?implementation_description
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CNcdLoadNodeOperationProxy::HandleCompletedMessage(
       
   259     TNcdOperationMessageCompletionId aCompletionId,
       
   260     RReadStream& aReadStream,
       
   261     TInt aDataLength )
       
   262     {
       
   263     DLTRACEIN((_L("aCompletionId =%d, aDataLength =%d"), aCompletionId,
       
   264         aDataLength));
       
   265     switch ( aCompletionId )
       
   266         {
       
   267         case ENCDOperationMessageCompletionNodesUpdated:
       
   268             {
       
   269             DLTRACE(("ENCDOperationMessageCompletionNodesUpdated"));
       
   270             TRAPD(err,
       
   271                 {
       
   272                 TNcdSendableProgress progress;
       
   273                 progress.InternalizeL( aReadStream );
       
   274                 TInt nodeIdCount = aReadStream.ReadInt32L();
       
   275                 iLoadedNodes.ResetAndDestroy();
       
   276                 for ( TInt i = 0 ; i < nodeIdCount ; i++ )
       
   277                     {
       
   278                     CNcdNodeIdentifier* nodeId = CNcdNodeIdentifier::NewLC(
       
   279                         aReadStream );
       
   280                     DLINFO( (_L("Updated node: %S"), &nodeId->NodeId() ) );
       
   281                     iLoadedNodes.AppendL( nodeId );
       
   282                     CleanupStack::Pop( nodeId );
       
   283                     }
       
   284                 SendContinueMessageL();
       
   285                 }); //TRAPD
       
   286             aReadStream.Close();
       
   287             if ( err == KErrNone )
       
   288                 {                
       
   289                 ProgressCallback();
       
   290                 }
       
   291             else
       
   292                 {
       
   293                 CompleteCallback( err );
       
   294                 } 
       
   295             DLTRACE(("ENCDOperationMessageCompletionNodesUpdated done"));           
       
   296             break;
       
   297             }
       
   298         default:
       
   299             {
       
   300             CNcdBaseOperationProxy::HandleCompletedMessage( aCompletionId,
       
   301                 aReadStream,
       
   302                 aDataLength );
       
   303             break;
       
   304             }
       
   305         }
       
   306     DLTRACEOUT((""));
       
   307     }
       
   308 
       
   309 // ---------------------------------------------------------------------------
       
   310 // From CNcdBaseOperationProxy
       
   311 // ?implementation_description
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 void CNcdLoadNodeOperationProxy::ProgressCallback()
       
   315     {
       
   316     DLTRACEIN((""));
       
   317     DPROFILING_BEGIN( x );
       
   318     RCatalogsArray< MNcdNode > array;
       
   319     for ( TInt j = 0 ; j < iLoadedNodes.Count() ; j++ )
       
   320         {
       
   321         DLINFO((_L("Trying to get loaded node: namespace=%S, id=%S"),
       
   322             &iLoadedNodes[j]->NodeNameSpace(), &iLoadedNodes[j]->NodeId() ));
       
   323         TRAPD( err,
       
   324             {
       
   325             CNcdNodeProxy& node = iNodeManager->NodeL( *iLoadedNodes[j] );            
       
   326             node.OperationComplete( *this, KErrNone );
       
   327             array.AppendL( &node );
       
   328             node.InternalAddRef();
       
   329             }); // TRAPD
       
   330         if ( err != KErrNone )
       
   331             {
       
   332             DLINFO(( "error: %d", err ));            
       
   333             }
       
   334         }
       
   335     
       
   336     if ( array.Count() < 1 )
       
   337         {
       
   338         DLINFO(("error: couldn't get loaded nodes from nodemanager!"));
       
   339         //return;
       
   340         }
       
   341     
       
   342     for ( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   343         {
       
   344         DASSERT( iObservers[i] );        
       
   345         iObservers[i]->NodesUpdated( *this, array );
       
   346         }
       
   347     for ( TInt i = 0 ; i < array.Count() ; i++ )
       
   348         {
       
   349         static_cast<CNcdNodeProxy*>( array[i] )->InternalRelease();
       
   350         }
       
   351     array.Close();
       
   352     DPROFILING_END( x );
       
   353     DLTRACEOUT((""));
       
   354     }
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // From CNcdBaseOperationProxy
       
   358 // ?implementation_description
       
   359 // ---------------------------------------------------------------------------
       
   360 //
       
   361 void CNcdLoadNodeOperationProxy::QueryReceivedCallback( CNcdQuery* aQuery )
       
   362     {
       
   363     DLTRACEIN((""));
       
   364     for ( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   365         {
       
   366         aQuery->AddRef();
       
   367         iObservers[i]->QueryReceived( *this, aQuery );
       
   368         }
       
   369     DLTRACEOUT((""));
       
   370     }
       
   371     
       
   372 // ---------------------------------------------------------------------------
       
   373 // From CNcdBaseOperationProxy
       
   374 // ?implementation_description
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 void CNcdLoadNodeOperationProxy::CompleteCallback( TInt aError )
       
   378     {
       
   379     DLTRACEIN(( "err: %d", aError ));
       
   380     DPROFILING_BEGIN( x );
       
   381     AddRef();
       
   382     for ( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   383         {
       
   384         DLINFO(("Calling observer: %x", iObservers[i] ));
       
   385         iObservers[i]->OperationComplete( *this, aError );
       
   386         }
       
   387     Release();
       
   388     DPROFILING_END( x );
       
   389     DLTRACEOUT((""));    
       
   390     }