ncdengine/provider/client/src/ncdnodesupplierproxy.cpp
changeset 4 32704c33136d
equal deleted inserted replaced
-1:000000000000 4:32704c33136d
       
     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:   Contains CNcdNodeSupplierProxy class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdnodesupplierproxy.h"
       
    20 #include "ncdnodemanagerproxy.h"
       
    21 #include "catalogsdebug.h"
       
    22 #include "ncderrors.h"
       
    23 
       
    24 CNcdNodeSupplierProxy* CNcdNodeSupplierProxy::NewLC(
       
    25     MCatalogsClientServer& aSession,
       
    26     TInt aHandle, 
       
    27     CNcdNodeManagerProxy& aNodeManager,
       
    28     CNcdOperationManagerProxy& aOperationManager,
       
    29     CNcdFavoriteManagerProxy& aFavoriteManager ) 
       
    30     {
       
    31     DLTRACEIN((""));
       
    32     CNcdNodeSupplierProxy* self = new ( ELeave ) CNcdNodeSupplierProxy(
       
    33         aSession, aHandle, aNodeManager, aOperationManager, aFavoriteManager );
       
    34     CleanupStack::PushL( self );
       
    35     self->ConstructL();
       
    36     return self;
       
    37     }
       
    38     
       
    39 
       
    40 CNcdNodeSupplierProxy::CNcdNodeSupplierProxy(
       
    41     MCatalogsClientServer& aSession,
       
    42     TInt aHandle, 
       
    43     CNcdNodeManagerProxy& aNodeManager,
       
    44     CNcdOperationManagerProxy& aOperationManager,
       
    45     CNcdFavoriteManagerProxy& aFavoriteManager ) :
       
    46     CNcdNodeProxy( aSession, aHandle, aNodeManager, aOperationManager, aFavoriteManager ) 
       
    47     {
       
    48     }
       
    49 
       
    50 
       
    51 CNcdNodeSupplierProxy::~CNcdNodeSupplierProxy()
       
    52     {
       
    53     if ( iActualNode != NULL )
       
    54         {
       
    55         // No need to call Release here. We, can just directly delete the actual node.
       
    56         // This is because, this class was set as a parent for the actual node. So,
       
    57         // when this class is deleted, also reference counts of its children are zero.
       
    58         // And, so they can also be deleted. The destructor, of the CNcdNodeProxy parent class 
       
    59         // will automatically inform the nodemanager that these nodes can be removed from 
       
    60         // the cache.
       
    61         delete iActualNode;
       
    62         iActualNode = NULL;
       
    63         }
       
    64     }
       
    65 
       
    66 
       
    67 MNcdNode::TState CNcdNodeSupplierProxy::State() const
       
    68     {
       
    69     DLTRACEIN((""));
       
    70     if ( iActualNode ) 
       
    71         {
       
    72         return iActualNode->State();
       
    73         }
       
    74     else 
       
    75         {
       
    76         return MNcdNode::EStateNotInitialized;
       
    77         }
       
    78     }
       
    79 
       
    80 const TDesC& CNcdNodeSupplierProxy::CatalogSourceName() const 
       
    81     {
       
    82     DLTRACEIN((""));
       
    83     if ( iActualNode ) 
       
    84         {
       
    85         return iActualNode->CatalogSourceName();
       
    86         }
       
    87     else 
       
    88         {
       
    89         return CNcdNodeProxy::CatalogSourceName();
       
    90         }
       
    91     }
       
    92     
       
    93 MNcdNodeContainer* CNcdNodeSupplierProxy::ParentL() const 
       
    94     {
       
    95     DLTRACEIN((""));
       
    96     if ( iActualNode ) 
       
    97         {
       
    98         return iActualNode->ParentL();
       
    99         }
       
   100     else 
       
   101         {
       
   102         return CNcdNodeProxy::ParentL();
       
   103         }
       
   104     }
       
   105     
       
   106 
       
   107 MNcdLoadNodeOperation* CNcdNodeSupplierProxy::LoadL(
       
   108     MNcdLoadNodeOperationObserver& aObserver ) 
       
   109     {
       
   110     DLTRACEIN((""));
       
   111     if ( iActualNode ) 
       
   112         {
       
   113         return iActualNode->LoadL( aObserver );
       
   114         }
       
   115     else 
       
   116         {
       
   117         return CNcdNodeProxy::LoadL( aObserver );
       
   118         }
       
   119     }
       
   120     
       
   121 
       
   122 RCatalogsArray< MNcdOperation > CNcdNodeSupplierProxy::OperationsL() const 
       
   123     {
       
   124     DLTRACEIN((""));
       
   125     if ( iActualNode ) 
       
   126         {
       
   127         return iActualNode->OperationsL();
       
   128         }
       
   129     else 
       
   130         {
       
   131         return CNcdNodeProxy::OperationsL();
       
   132         }
       
   133     }
       
   134     
       
   135 void CNcdNodeSupplierProxy::OperationComplete(
       
   136     MNcdLoadNodeOperation& /*aOperation*/, TInt aError ) 
       
   137     {
       
   138     DLTRACEIN((""));
       
   139 
       
   140     if ( iActualNode != NULL )
       
   141         {
       
   142         DLINFO(("iActualNode has already been created. Nothing to do here."))
       
   143         return;
       
   144         }
       
   145         
       
   146     if ( aError == KErrNone || aError == KNcdErrorSomeCatalogsFailedToLoad )
       
   147         {
       
   148         DLINFO(("Set iActualNode"))
       
   149 
       
   150         // The actual node is loaded and can be requested from nodemanager.
       
   151         // This will replace the supplier node with the temporary node in nodemanager cache.
       
   152         // After that, if nodemanager is asked for the node, the temporary node is directly
       
   153         // given. But, if this node is used then this will forward, the requests to that temporary
       
   154         // node
       
   155         TRAPD( err, iActualNode = &NodeManager().ReplaceCacheNodeL( NodeIdentifier() ) );
       
   156         (void) &err; // prevents compiler warning of unreferenced variable
       
   157 
       
   158         // The actual node should always be created in server side if we come here.
       
   159         // So, above should have found it.
       
   160         DASSERT( err == KErrNone );
       
   161         
       
   162         if ( iActualNode != NULL )
       
   163             {
       
   164             // SetParentL is a safe call here because nodes are top level parents
       
   165             // as the default value. So, we can safely set a new parent for the
       
   166             // actual node. Notice, that this setting will insert the interfaces from
       
   167             // the actual node to this node. So, for example MNcdNode-interface pointer
       
   168             // will be replaced by the interface pointer of the actual node gotten above.
       
   169             TRAP(err, iActualNode->SetParentL( this ) );
       
   170             DASSERT( err == KErrNone );
       
   171             }
       
   172         }
       
   173     }