ncdengine/provider/client/src/ncdnodeproxy.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:   Contains CNcdNodeProxy class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdnodeproxy.h"
       
    20 #include "ncdrootnodeproxy.h"
       
    21 #include "ncdnodecontainer.h"
       
    22 #include "ncdnodefolderproxy.h"
       
    23 #include "ncdnodemetadataproxy.h"
       
    24 #include "ncdnodeuserdataproxy.h"
       
    25 #include "ncdoperationmanagerproxy.h"
       
    26 #include "ncdloadnodeoperationproxy.h"
       
    27 #include "catalogsclientserver.h"
       
    28 #include "ncdnodeidentifier.h"
       
    29 #include "ncdnodefunctionids.h"
       
    30 #include "ncdnodeclassids.h"
       
    31 #include "catalogsinterfaceidentifier.h"
       
    32 #include "catalogsdebug.h"
       
    33 #include "catalogsutils.h"
       
    34 #include "ncdnodemanagerproxy.h"
       
    35 #include "ncdfavoritemanagerproxy.h"
       
    36 #include "ncdquery.h"
       
    37 #include "ncdnodedisclaimerproxy.h"
       
    38 #include "ncdnodefavorite.h"
       
    39 #include "ncdnodeidentifiereditor.h"
       
    40 #include "ncdnodeseenproxy.h"
       
    41 
       
    42 
       
    43 CNcdNodeProxy::CNcdNodeProxy( MCatalogsClientServer& aSession,
       
    44                               TInt aHandle, 
       
    45                               CNcdNodeManagerProxy& aNodeManager,
       
    46                               CNcdOperationManagerProxy& aOperationManager,
       
    47                               CNcdFavoriteManagerProxy& aFavoriteManager ) 
       
    48 : CNcdInterfaceBaseProxy( aSession, aHandle, NULL ),
       
    49   iNodeManager( aNodeManager ),
       
    50   iOperationManager( aOperationManager ),
       
    51   iFavoriteManager( aFavoriteManager )
       
    52     {
       
    53     }
       
    54 
       
    55 
       
    56 void CNcdNodeProxy::ConstructL( )
       
    57     {
       
    58     DLTRACEIN(("this-ptr as MNcdNode: %X", static_cast<MNcdNode*>( this )));
       
    59 
       
    60     // Register the interfaces of this object
       
    61     MNcdNode* node( this );
       
    62     AddInterfaceL( 
       
    63         CCatalogsInterfaceIdentifier::NewL( node, this, MNcdNode::KInterfaceUid ) );
       
    64 
       
    65     // Make sure that at least some values are inserted to the link descriptors.
       
    66     // So, the references returned from functions of this class will contain at
       
    67     // least something.
       
    68     iTimestamp = KNullDesC().AllocL();
       
    69     iCatalogSourceName = KNullDesC().AllocL(); 
       
    70     iExpiredTime = 0;
       
    71 
       
    72     // Get the data from the server side.
       
    73     // It may be possible that actually not much is received
       
    74     // because the node may be in uninitialized state.
       
    75     // But at least the namespace and id information should be gotten.
       
    76     TRAPD( trapError, InternalizeL() );    
       
    77 
       
    78     // This node can not exist if the identifier data is not set.
       
    79     // So, if node identifier is not set this should leave and
       
    80     // prevent the creation of the node.
       
    81     if ( iNodeIdentifier == NULL )
       
    82         {
       
    83         User::LeaveIfError( trapError );
       
    84         }
       
    85     
       
    86     // Also make sure that parent identifier is set at least to empty value
       
    87     if ( iParentIdentifier == NULL )
       
    88         {
       
    89         // If we have to set the parent identifier here, it means that
       
    90         // the node link was not set yet. 
       
    91         // If node link was set, then the parent id was also set to correct value. 
       
    92         // And, then this value should not be set here.
       
    93         iParentIdentifier = CNcdNodeIdentifier::NewL();        
       
    94         }
       
    95         
       
    96     if ( iRealParentIdentifier == NULL ) 
       
    97         {
       
    98         iRealParentIdentifier = CNcdNodeIdentifier::NewL();
       
    99         }
       
   100 
       
   101     DLTRACEOUT((""));
       
   102     }
       
   103 
       
   104 
       
   105 CNcdNodeProxy::~CNcdNodeProxy()
       
   106     {
       
   107     DLTRACEIN(("this-ptr: %x", this));
       
   108     // Because this object is deleted. Remove the interfaces from the
       
   109     // interface list.
       
   110     RemoveInterface( MNcdNode::KInterfaceUid );
       
   111     RemoveInterface( MNcdNodeChildOfTransparent::KInterfaceUid );
       
   112     RemoveInterface( MNcdNodeFavorite::KInterfaceUid );
       
   113     
       
   114     // Inform node manager that this node is under deletion.    
       
   115     iNodeManager.NodeDeleted( this );
       
   116 
       
   117     delete iNodeIdentifier;
       
   118     iNodeIdentifier = NULL;
       
   119 
       
   120     // Delete link data
       
   121 
       
   122     delete iCatalogSourceName;
       
   123     iCatalogSourceName = NULL;
       
   124 
       
   125     delete iParentIdentifier;
       
   126     iParentIdentifier = NULL;
       
   127     
       
   128     delete iRealParentIdentifier;
       
   129     iRealParentIdentifier = NULL;
       
   130 
       
   131     delete iTimestamp;
       
   132     iTimestamp = NULL;
       
   133 
       
   134 
       
   135     // Delete the objects that are owned by this class and provide functionality
       
   136     // through the api.
       
   137     // Notice that the api-objects are Released (not deleted) from the UI side.
       
   138     // The node owns the data and the reference counter of the node keeps
       
   139     // track of the api objects it owns. When the reference counter of the node
       
   140     // reaches zero, it means that nobody is using the node or the classes owned
       
   141     // by the node. If somebody is using the object owned by the node, the reference
       
   142     // counter can not be zero until everything is released.
       
   143     // Thus, the node may delete the data here.
       
   144 
       
   145     delete iMetadata;
       
   146     iMetadata = NULL;
       
   147     
       
   148     delete iNodeSeen;
       
   149     iNodeSeen = NULL;
       
   150     DLTRACEOUT(("this-ptr: %x", this));
       
   151     }
       
   152 
       
   153 
       
   154 
       
   155 CNcdNodeIdentifier& CNcdNodeProxy::NodeIdentifier() const
       
   156     {
       
   157     return *iNodeIdentifier;    
       
   158     }
       
   159 
       
   160 
       
   161 CNcdNodeManagerProxy& CNcdNodeProxy::NodeManager() const
       
   162     {
       
   163     return iNodeManager;
       
   164     }
       
   165 
       
   166 
       
   167 CNcdOperationManagerProxy& CNcdNodeProxy::OperationManager() const
       
   168     {
       
   169     return iOperationManager;    
       
   170     }
       
   171 
       
   172 
       
   173 CNcdNodeMetadataProxy* CNcdNodeProxy::Metadata() const
       
   174     {
       
   175     //DASSERT( iMetadata );
       
   176     return iMetadata;
       
   177     }
       
   178 
       
   179 
       
   180 void CNcdNodeProxy::InternalizeL()
       
   181     {
       
   182     DLTRACEIN(("this-ptr: %x", this));
       
   183     DPROFILING_BEGIN( x );
       
   184     HBufC8* data( NULL );
       
   185         
       
   186     // Because we do not know the exact size of the data id, use
       
   187     // the alloc method, which creates the buffer of the right size
       
   188     // and sets the pointer to point to the created buffer.
       
   189     User::LeaveIfError(
       
   190             ClientServerSession().
       
   191                 SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize,
       
   192                                KNullDesC8,
       
   193                                data,
       
   194                                Handle(),
       
   195                                0 ) );
       
   196 
       
   197     if ( data == NULL )
       
   198         {
       
   199         User::Leave( KErrNotFound );
       
   200         }
       
   201 
       
   202     CleanupStack::PushL( data );
       
   203 
       
   204     DLINFO(( "Ncd node internalize data length: %d", data->Length() ));
       
   205 
       
   206     // Read the data from the stream and insert it to the memeber variables
       
   207     RDesReadStream stream( *data );
       
   208     CleanupClosePushL( stream );
       
   209     
       
   210     // Let this leave. If the node can not internalize itself, then
       
   211     // something is really badly wrong. In this case this node should
       
   212     // even be created. So, if this is called from ContstructL it should
       
   213     // most likely to leave also.
       
   214     InternalizeNodeDataL( stream );
       
   215 
       
   216     // Closes the stream
       
   217     CleanupStack::PopAndDestroy( &stream ); 
       
   218     CleanupStack::PopAndDestroy( data );
       
   219 
       
   220         
       
   221     // The node data was internalized.
       
   222         
       
   223     // Next, internalize the link data if it exists.    
       
   224     DLINFO(("Internalize node proxy link"));
       
   225     InternalizeLinkL();    
       
   226 
       
   227 
       
   228     // TRAP the functions after this. So, all the existing new interfaces
       
   229     // may be added to the interface list.
       
   230 
       
   231     // Also, metadata may be ready for initialization.
       
   232     DLINFO(("Internalize node proxy metadata"));
       
   233     TRAP_IGNORE( InternalizeMetadataL() );
       
   234     
       
   235     // Internalize node seen proxy.
       
   236     DLINFO(("Internalize node seen"));
       
   237     InternalizeNodeSeenL();
       
   238     
       
   239     // Install the MNcdNodeFavorite interface if the same metadata is favorite already.
       
   240     if ( iFavoriteManager.IsFavoriteL( *iNodeIdentifier ) ) 
       
   241         {
       
   242         MNcdNodeFavorite* node( this );
       
   243         AddInterfaceL( 
       
   244             CCatalogsInterfaceIdentifier::NewL( node, this, MNcdNodeFavorite::KInterfaceUid ) );
       
   245         }
       
   246     DPROFILING_END( x );
       
   247     DLTRACEOUT((""));
       
   248     }
       
   249     
       
   250     
       
   251 void CNcdNodeProxy::AddToFavoritesL( TBool aRemoveOnDisconnect ) 
       
   252     {
       
   253     DLTRACEIN(("aRemoveOnDisconnect: %d", aRemoveOnDisconnect));
       
   254     if ( !iFavoriteManager.IsFavoriteL( *iNodeIdentifier ) ) 
       
   255         {
       
   256         iFavoriteManager.AddToFavoritesL( *iNodeIdentifier, aRemoveOnDisconnect );        
       
   257         }
       
   258 
       
   259     // Register the MNcdNodeFavorite interface.
       
   260     MNcdNodeFavorite* node( this );
       
   261     AddInterfaceL( 
       
   262         CCatalogsInterfaceIdentifier::NewL( node, this, MNcdNodeFavorite::KInterfaceUid ) );        
       
   263     }
       
   264     
       
   265 
       
   266 
       
   267 // MNcdNode functions
       
   268 
       
   269 
       
   270 MNcdNode::TState CNcdNodeProxy::State() const
       
   271     {
       
   272     DLTRACEIN((_L("Node namespace=%S, id=%S"), &Namespace(), &Id() ));
       
   273 
       
   274     // Check if the link handle has been set, which means that also
       
   275     // link data has been internalized. Also, check if the metadata 
       
   276     // exists, which means that metadata has also been internalized.
       
   277     if ( LinkHandleSet() 
       
   278          && iMetadata != NULL )
       
   279         {
       
   280         DLINFO(("State was initialized"));
       
   281         // If state was initialized we have to check if the state
       
   282         // has acutally expired already 
       
   283         TTime now;
       
   284         now.HomeTime();
       
   285 
       
   286         DLINFO(("now time: %d", now.Int64() ));
       
   287         DLINFO(("expired time: %d", ExpiredTime().Int64() ));
       
   288 
       
   289         // We can just compare the times here. Server side
       
   290         // inserts the maximum value for the expired time if the
       
   291         // protocol has set never expire value for the validity delta.
       
   292         if ( now > ExpiredTime() )
       
   293             {
       
   294             DLTRACEOUT(("Expired"));
       
   295             return MNcdNode::EStateExpired;
       
   296             }
       
   297             
       
   298         DLTRACEOUT(("Initialized"));
       
   299         return MNcdNode::EStateInitialized;
       
   300         }
       
   301      else
       
   302         {
       
   303         // Node has not been initialized.
       
   304         DLTRACEOUT(("Not initialized"));
       
   305         return MNcdNode::EStateNotInitialized;
       
   306         }
       
   307     }
       
   308 
       
   309 
       
   310 const TDesC& CNcdNodeProxy::Id() const
       
   311     {
       
   312     DLTRACEIN((""));
       
   313     return iNodeIdentifier->NodeId(); 
       
   314     }
       
   315 
       
   316 const TDesC& CNcdNodeProxy::Namespace() const
       
   317     {
       
   318     DLTRACEIN((""));
       
   319     return iNodeIdentifier->NodeNameSpace();
       
   320     }
       
   321 
       
   322 const TDesC& CNcdNodeProxy::CatalogSourceName() const
       
   323     {
       
   324     DLTRACEIN((""));
       
   325     return *iCatalogSourceName;
       
   326     }    
       
   327 
       
   328 MNcdNodeContainer* CNcdNodeProxy::ParentL() const
       
   329     {
       
   330     DLTRACEIN((""));
       
   331 
       
   332     if( iParentIdentifier == NULL
       
   333         || iParentIdentifier->ContainsEmptyFields() )
       
   334         {
       
   335         DLTRACEOUT(("Parent identifier was not set. Return NULL"));
       
   336         return NULL;
       
   337         }
       
   338     else
       
   339         {
       
   340         DLINFO(("Parent identifier was set. Get the parent"));
       
   341 
       
   342         // This always gives reference to the node
       
   343         // We use pointer instead of reference afterwards.
       
   344         // NodeL leaves if the node was not found.
       
   345         MNcdNode* parent = &iNodeManager.NodeL( *iParentIdentifier );
       
   346 
       
   347         DLINFO(("Parent was gotten"));
       
   348         
       
   349         // This should always give something because parent is always container.
       
   350         // Notice, that the query interface increases the reference count automatically.
       
   351         MNcdNodeContainer* container = parent->QueryInterfaceL<MNcdNodeContainer>();
       
   352 
       
   353         DLTRACEOUT(( _L("Return parent container interface: %X"), container ));
       
   354         
       
   355         return container;
       
   356         }
       
   357     }
       
   358 
       
   359 MNcdLoadNodeOperation* CNcdNodeProxy::LoadL( MNcdLoadNodeOperationObserver& aObserver )
       
   360     {
       
   361     DLTRACEIN((""));
       
   362 
       
   363     CNcdLoadNodeOperationProxy* operation( NULL );
       
   364 
       
   365     operation =
       
   366         iOperationManager.CreateLoadNodeOperationL( *this );
       
   367 
       
   368     operation->AddObserverL( this );
       
   369     operation->AddObserverL( &aObserver );
       
   370 
       
   371     DLTRACEOUT((""));
       
   372 
       
   373     return operation;
       
   374     }
       
   375 
       
   376 RCatalogsArray<MNcdOperation> CNcdNodeProxy::OperationsL() const
       
   377     {
       
   378     DLTRACEIN(("this: %x, iMetadata: %x", this, iMetadata ));
       
   379     RCatalogsArray<MNcdOperation> operations;
       
   380     CleanupClosePushL( operations );
       
   381 
       
   382     if ( iMetadata ) 
       
   383         {
       
   384         // Get the original array and insert its content to catalogs array.
       
   385         // Also, increase the reference counter for the items.
       
   386         const RPointerArray<MNcdOperation>& origArray = iOperationManager.Operations();
       
   387         MNcdOperation* oper( NULL );
       
   388         MNcdNode* node( NULL );
       
   389         
       
   390         CNcdNodeMetadataProxy* metadata( NULL );
       
   391         DLTRACE(("Getting metaidentifier"));
       
   392         const CNcdNodeIdentifier& metadataId( iMetadata->Identifier() );
       
   393         
       
   394         DLTRACE(("Origarray.count: %d", origArray.Count() ));
       
   395         for ( TInt i = 0; i < origArray.Count(); ++i )
       
   396             {            
       
   397             oper = origArray[ i ];
       
   398             DLTRACE(("oper: %x", oper));
       
   399             // Notice that node ref count is increased. So, release it when done.
       
   400             node = oper->Node();
       
   401             if ( node ) 
       
   402                 {
       
   403                 CleanupReleasePushL( *node );
       
   404     
       
   405                 // Compare metadatas
       
   406                 metadata = static_cast<CNcdNodeProxy*>( node )->Metadata();
       
   407                 DLTRACE(("Metadata: %x", metadata));
       
   408                 if ( metadata && metadata->Identifier().Equals( metadataId ) )
       
   409                     {
       
   410                     DLTRACE(("Appending to ops array"));
       
   411                     operations.AppendL( oper );
       
   412                     oper->AddRef();
       
   413                     }
       
   414     
       
   415                 CleanupStack::PopAndDestroy( node );
       
   416                 }
       
   417             }
       
   418         }
       
   419 
       
   420     CleanupStack::Pop( &operations );
       
   421     
       
   422     DLTRACEOUT(( "" ));
       
   423     return operations;
       
   424     }
       
   425     
       
   426 
       
   427 void CNcdNodeProxy::AddToFavoritesL() 
       
   428     {
       
   429     AddToFavoritesL( EFalse );
       
   430     }
       
   431     
       
   432 
       
   433 // MNcdLoadNodeOperationObserver
       
   434 
       
   435 
       
   436 void CNcdNodeProxy::NodesUpdated( MNcdLoadNodeOperation& /*aOperation*/,
       
   437                                   RCatalogsArray< MNcdNode >& aNodes )
       
   438     {
       
   439     
       
   440     for ( TInt i = 0 ; i < aNodes.Count() ; i++ )    
       
   441         {
       
   442         // Should the node provide its own function instead of API interface
       
   443         // that can be called when node/nodes should be updated. Operations know
       
   444         // the node proxy object so they could use the function directly instead
       
   445         // of using more restricted API interfaces. Then, no casting would be required
       
   446         // here...        
       
   447         CNcdNodeProxy* node = static_cast<CNcdNodeProxy*>(aNodes[i]);
       
   448         TRAP_IGNORE( node->InternalizeL() );
       
   449         /*// make sure that this node is a child of this node
       
   450         TIdentityRelation<CNcdNodeIdentifier> relation(CNcdNodeIdentifier::Equals);        
       
   451         if ( iChildren.Find( node->NodeIdentifier(), relation ) == KErrNotFound )
       
   452             {
       
   453             
       
   454             }*/
       
   455         }    
       
   456     
       
   457     // This function of the observer interface does not need to do anythin here.
       
   458     }
       
   459     
       
   460 void CNcdNodeProxy::QueryReceived( MNcdLoadNodeOperation& /*aOperation*/,
       
   461                                    MNcdQuery* aQuery )
       
   462     {
       
   463     // This function of the observer interface does not need to do anythin here.
       
   464     aQuery->Release();
       
   465     }
       
   466 
       
   467 void CNcdNodeProxy::OperationComplete( MNcdLoadNodeOperation& /*aOperation*/,
       
   468                                        TInt /*aError*/ )
       
   469     {
       
   470     DLTRACEIN((""));
       
   471     DLINFO(("Nothing done."));
       
   472     DLTRACEOUT((""));
       
   473     }
       
   474 
       
   475     
       
   476 // MNcdNodeChildOfTransparent    
       
   477 
       
   478 MNcdNode* CNcdNodeProxy::TransparentParentL() const 
       
   479     {
       
   480     DLTRACEIN((""));
       
   481     DASSERT( iRealParentIdentifier );
       
   482     DASSERT( !iRealParentIdentifier->ContainsEmptyFields() );
       
   483     
       
   484     MNcdNode* parent( NULL );
       
   485     TRAPD( err, parent = &NodeManager().NodeL( *iRealParentIdentifier ) );    
       
   486 
       
   487     if ( err == KErrNotFound ) 
       
   488         {
       
   489         return NULL;
       
   490         }
       
   491         
       
   492     User::LeaveIfError( err );
       
   493     
       
   494     parent->AddRef();
       
   495     return parent;
       
   496     }
       
   497 
       
   498 
       
   499 // MNcdNodeFavorite
       
   500 
       
   501 void CNcdNodeProxy::RemoveFromFavoritesL() 
       
   502     {
       
   503     DLTRACEIN((""));
       
   504     iFavoriteManager.RemoveFromFavoritesL( *iNodeIdentifier );
       
   505     RemoveInterface( MNcdNodeFavorite::KInterfaceUid );
       
   506     }
       
   507     
       
   508     
       
   509 void CNcdNodeProxy::SetDisclaimerL( MNcdNode* aDisclaimerOwner ) 
       
   510     {
       
   511     DLTRACEIN((""));
       
   512     iFavoriteManager.SetNodeDisclaimerL( *iNodeIdentifier, aDisclaimerOwner );
       
   513     }
       
   514     
       
   515 
       
   516 MNcdQuery* CNcdNodeProxy::DisclaimerL() const 
       
   517     {
       
   518     DLTRACEIN((""));
       
   519     MNcdQuery* disclaimer = iFavoriteManager.NodeDisclaimerL( *iNodeIdentifier );
       
   520     if ( disclaimer ) 
       
   521         {
       
   522         disclaimer->AddRef();
       
   523         }
       
   524     return disclaimer;
       
   525     }
       
   526 
       
   527 
       
   528 // Other functions
       
   529 
       
   530 TBool CNcdNodeProxy::LinkHandleSet() const
       
   531     {
       
   532     return iLinkHandleSet;
       
   533     }
       
   534     
       
   535 TInt CNcdNodeProxy::LinkHandleL() const
       
   536     {
       
   537     if( !iLinkHandleSet )
       
   538         {
       
   539         // Link handle has not been set
       
   540         User::Leave( KErrNotReady );
       
   541         }
       
   542         
       
   543     return iLinkHandle;
       
   544     }
       
   545     
       
   546 void CNcdNodeProxy::SetLinkHandle( TInt aHandle )
       
   547     {
       
   548     iLinkHandle = aHandle;
       
   549     iLinkHandleSet = ETrue;
       
   550     }
       
   551 
       
   552 TTime CNcdNodeProxy::ExpiredTime() const
       
   553     {
       
   554     return iExpiredTime;
       
   555     }
       
   556     
       
   557 CNcdNodeIdentifier* CNcdNodeProxy::ParentIdentifier() const
       
   558     {
       
   559     return iParentIdentifier;
       
   560     }
       
   561 
       
   562 TBool CNcdNodeProxy::IsRemote() const
       
   563     {
       
   564     return iRemoteFlag;
       
   565     }    
       
   566 
       
   567 
       
   568 // ======== FUNCTIONS FOR NODE INTERNALIZATION ========
       
   569 
       
   570 
       
   571 void CNcdNodeProxy::InternalizeLinkL()
       
   572     {
       
   573     DLTRACEIN((""));
       
   574 
       
   575     // Get the handle for the link data
       
   576     if ( !LinkHandleSet() )
       
   577         {
       
   578         DLINFO(("Link handle was not set. Set it now."));
       
   579         TInt linkHandle( 0 );
       
   580         
       
   581         // Leave for example by using KErrNotFound if the link did not exist.
       
   582         User::LeaveIfError(
       
   583                 ClientServerSession().
       
   584                     SendSync( NcdNodeFunctionIds::ENcdLinkHandle,
       
   585                               KNullDesC,
       
   586                               linkHandle,
       
   587                               Handle() ) );    
       
   588         
       
   589         // Link existed. So, we got the handle.                      
       
   590         DLINFO(("Handle: %i", linkHandle));
       
   591         SetLinkHandle( linkHandle );        
       
   592         }
       
   593 
       
   594     HBufC8* data( NULL );
       
   595     // Because we do not know the exact size of the data id, use
       
   596     // the alloc method, which creates the buffer of the right size
       
   597     // and sets the pointer to point to the created buffer.
       
   598     User::LeaveIfError(
       
   599             ClientServerSession().
       
   600                 SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize,
       
   601                                KNullDesC8,
       
   602                                data,
       
   603                                LinkHandleL(),
       
   604                                0 ) );
       
   605 
       
   606     if ( data == NULL )
       
   607         {
       
   608         DLINFO(("Received link data was NULL"));
       
   609         User::Leave( KErrNotFound );
       
   610         }
       
   611 
       
   612     CleanupStack::PushL( data );
       
   613 
       
   614     DLINFO(( "Received link data length: %d", data->Length() ));
       
   615 
       
   616     // Read the data from the stream and insert it to the memeber variables
       
   617     RDesReadStream stream( *data );
       
   618     CleanupClosePushL( stream );
       
   619     
       
   620     InternalizeNodeLinkDataL( stream );
       
   621 
       
   622     // Closes the stream
       
   623     CleanupStack::PopAndDestroy( &stream ); 
       
   624     CleanupStack::PopAndDestroy( data );
       
   625 
       
   626     DLTRACEOUT((""));
       
   627     }
       
   628 
       
   629 
       
   630 void CNcdNodeProxy::InternalizeNodeDataL( RReadStream& aStream )
       
   631     {
       
   632     DLTRACEIN((""));
       
   633 
       
   634     // Read the class id of the node
       
   635     // (not actually needed here at the moment but may be used to check if the
       
   636     // data is of the right type...)
       
   637     aStream.ReadInt32L();
       
   638 
       
   639     // No need to put the newIdentifier into the cleanup stack because this
       
   640     // function will not leave before inserting the value to the member variable.
       
   641     CNcdNodeIdentifier* newIdentifier = CNcdNodeIdentifier::NewL( aStream );
       
   642     delete iNodeIdentifier;
       
   643     iNodeIdentifier = newIdentifier;
       
   644     
       
   645     DLTRACEOUT((""));
       
   646     }
       
   647 
       
   648 void CNcdNodeProxy::InternalizeNodeLinkDataL( RReadStream& aStream )
       
   649     {
       
   650     DLTRACEIN((""));
       
   651 
       
   652     HBufC* tmpTimeStamp( NULL );
       
   653     HBufC* tmpCatalogSourceName( NULL );
       
   654     TBool tmpRemoteFlag( EFalse );
       
   655     TInt64 tmpExpiredTime( 0 );
       
   656     CNcdNodeIdentifier* tmpParentIdentifier( NULL );
       
   657     CNcdNodeIdentifier* tmpRealParentIdentifier( NULL );
       
   658         
       
   659     // Read the class id of the link
       
   660     TInt tmpInt = aStream.ReadInt32L();
       
   661     DLINFO(("Classid: %d", tmpInt));
       
   662       
       
   663     if ( tmpInt != NcdNodeClassIds::ENcdNullObjectClassId )
       
   664         {
       
   665 
       
   666         InternalizeDesL( tmpTimeStamp, aStream );
       
   667         CleanupStack::PushL( tmpTimeStamp );
       
   668         DLINFO(( _L("timestamp: %S"), tmpTimeStamp ));
       
   669         
       
   670         InternalizeDesL( tmpCatalogSourceName, aStream );
       
   671         CleanupStack::PushL( tmpCatalogSourceName );
       
   672         DLINFO(( _L("catalogsource: %S"), tmpCatalogSourceName ));
       
   673 
       
   674         tmpRemoteFlag = aStream.ReadInt32L();
       
   675         DLINFO((_L("remote flag: %d"), tmpRemoteFlag));
       
   676         
       
   677         aStream >> tmpExpiredTime;        
       
   678         DLINFO(("expired time: %d", tmpExpiredTime ));
       
   679 
       
   680         tmpParentIdentifier = CNcdNodeIdentifier::NewLC( aStream );
       
   681         tmpRealParentIdentifier = CNcdNodeIdentifier::NewLC( aStream );
       
   682         }
       
   683     else
       
   684         {
       
   685         tmpTimeStamp = KNullDesC().AllocLC();
       
   686         tmpCatalogSourceName = KNullDesC().AllocLC();
       
   687         }
       
   688 
       
   689 
       
   690     // Now we can be sure that this function will not leave.
       
   691     // So it is safe to set the values for the member variables.
       
   692     delete iRealParentIdentifier;
       
   693     iRealParentIdentifier = tmpRealParentIdentifier;
       
   694     if ( tmpRealParentIdentifier ) 
       
   695         {
       
   696         CleanupStack::Pop( tmpRealParentIdentifier );
       
   697         }
       
   698 
       
   699     delete iParentIdentifier;
       
   700     iParentIdentifier = tmpParentIdentifier;
       
   701     if( tmpParentIdentifier )
       
   702         {
       
   703         CleanupStack::Pop( tmpParentIdentifier );
       
   704         if ( !iRealParentIdentifier->Equals( *iParentIdentifier ) ) 
       
   705             {
       
   706             // Must be child of transparent node since real parent identifier is
       
   707             // different. Register the MNcdNodeChildOfTransparent interface.
       
   708             DLINFO(("child of transparent"));
       
   709             MNcdNodeChildOfTransparent* interface( this );
       
   710             AddInterfaceL(
       
   711                 CCatalogsInterfaceIdentifier::NewL(
       
   712                     interface, this, MNcdNodeChildOfTransparent::KInterfaceUid ) );
       
   713             }
       
   714         }        
       
   715 
       
   716     if ( !iRealParentIdentifier || iRealParentIdentifier->Equals( *iParentIdentifier ) ) 
       
   717         {
       
   718         // Real parent in engine is same as in proxy -> parent is not transparent ->
       
   719         // remove the MNcdNodeChildOfTransparent interface.
       
   720         RemoveInterface( MNcdNodeChildOfTransparent::KInterfaceUid );
       
   721         }
       
   722             
       
   723     iExpiredTime = tmpExpiredTime;
       
   724 
       
   725     iRemoteFlag = tmpRemoteFlag;
       
   726 
       
   727     delete iCatalogSourceName;
       
   728     iCatalogSourceName = tmpCatalogSourceName;
       
   729     CleanupStack::Pop( tmpCatalogSourceName );
       
   730 
       
   731     delete iTimestamp;
       
   732     iTimestamp = tmpTimeStamp;
       
   733     CleanupStack::Pop( tmpTimeStamp );
       
   734 
       
   735     DLTRACEOUT((""));    
       
   736     }
       
   737 
       
   738 
       
   739 void CNcdNodeProxy::InternalizeMetadataL()
       
   740     {
       
   741     DLTRACEIN((""));
       
   742     
       
   743     if ( iMetadata == NULL )
       
   744         {
       
   745         DLINFO(("Metadata did not exist"));
       
   746 
       
   747         // Check if the metadata exists in the server side and update the information
       
   748         TInt metadataHandle( 0 );
       
   749             
       
   750         TInt handleError =
       
   751             ClientServerSession().
       
   752                 SendSync( NcdNodeFunctionIds::ENcdMetadataHandle,
       
   753                           KNullDesC,
       
   754                           metadataHandle,
       
   755                           Handle() );
       
   756 
       
   757         if ( handleError == KErrNotFound )
       
   758             {
       
   759             DLINFO(("Metadata did not exist in server side"));
       
   760             
       
   761             // Because metadata did not exist in the server side
       
   762             // Nothing to do here.
       
   763             return;
       
   764             }
       
   765         else
       
   766             {
       
   767             // If error occurred then leave
       
   768             User::LeaveIfError( handleError );    
       
   769             }
       
   770 
       
   771         DLINFO(("Metadata existed"));
       
   772                     
       
   773         // Now we can create the metadata object
       
   774         // Notice that this object will add its own interfaces to the
       
   775         // querylist when the object is created.
       
   776         // Also, notice that if the proxy object leaves during the construction
       
   777         // the destructor automatically releases the handle from the server side.
       
   778         iMetadata = CNcdNodeMetadataProxy::NewL( ClientServerSession(), 
       
   779                                                  metadataHandle,
       
   780                                                  *this );
       
   781         // Metadata ref counter is not increased here.
       
   782         // So, it will be zero until somebody asks for the metadata.
       
   783         // If the Release is called and
       
   784         // when the reference counter reaches zero, this node which
       
   785         // acts as parent will be deleted. The destructor of this
       
   786         // node will delete the metadata because this node owns it.
       
   787         }
       
   788     else
       
   789         {
       
   790         // Notice that that if the proxy object was created above,
       
   791         // it internalizes itself during construction. So, call
       
   792         // the internalize here only if the object was not constructed
       
   793         // above.
       
   794         // Proxy object existed.
       
   795         // So, internalize it with new data.
       
   796         iMetadata->InternalizeL();        
       
   797         }
       
   798 
       
   799     DLTRACEOUT((""));
       
   800     }
       
   801     
       
   802 
       
   803 void CNcdNodeProxy::InternalizeNodeSeenL() 
       
   804     {
       
   805     DLTRACEIN((""));
       
   806     if ( iNodeSeen ) 
       
   807         {
       
   808         // The proxy can internalize its state itself.
       
   809         iNodeSeen->InternalizeL();
       
   810         }
       
   811     else 
       
   812         {
       
   813         // The proxy object not created yet, create it.
       
   814         DLINFO(("Node seen did not exist"));
       
   815         TInt nodeSeenHandle( 0 );
       
   816         
       
   817         User::LeaveIfError(
       
   818             ClientServerSession().SendSync(
       
   819                 NcdNodeFunctionIds::ENcdNodeSeenHandle,
       
   820                 KNullDesC,
       
   821                 nodeSeenHandle,
       
   822                 Handle() ) );
       
   823 
       
   824         // Got the handle, create the proxy object. The proxy object internalizes itself
       
   825         // in construction.
       
   826         iNodeSeen = CNcdNodeSeenProxy::NewL(
       
   827             ClientServerSession(), nodeSeenHandle, *this );                    
       
   828         }
       
   829     }