ncdengine/provider/server/src/ncdnodeidentifier.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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:   Implements CNcdNodeIdentifier class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32cmn.h>
       
    20 #include <s32strm.h>
       
    21 #include <s32mem.h>
       
    22 
       
    23 #include "ncdnodeidentifier.h"
       
    24 #include "ncdproviderdefines.h"
       
    25 #include "catalogsutils.h"
       
    26 #include "catalogsconstants.h"
       
    27 
       
    28 // CNcdNodeIdentifier uses different implementation when compiled for the server than
       
    29 // in other places
       
    30 #ifdef COMPONENT_CATALOGSSERVEREXE 
       
    31 
       
    32 #include "catalogsrefstring.h"
       
    33 #include "catalogsstringmanager.h"
       
    34 
       
    35 // For memory consumption logging
       
    36 #ifdef LOG_MEMORY_USAGE
       
    37 TInt64 CNcdNodeIdentifier::iCurrentMemory = 0;
       
    38 TInt64 CNcdNodeIdentifier::iMaxMemory = 0;
       
    39 TInt CNcdNodeIdentifier::iIdCount = 0;
       
    40 TInt CNcdNodeIdentifier::iMaxCount = 0;
       
    41 
       
    42     
       
    43 void CNcdNodeIdentifier::AddId( const CNcdNodeIdentifier& /*aId*/, TInt64& aMemory )
       
    44     {
       
    45 
       
    46     aMemory = 
       
    47 /*
       
    48         aId.NodeId().Size() + 
       
    49         aId.NodeNameSpace().Size() +
       
    50         aId.ServerUri().Size() +        */
       
    51         sizeof( CNcdNodeIdentifier ) -
       
    52         sizeof( TInt64 ); // ignore the size of this temporary member
       
    53     
       
    54     iCurrentMemory += aMemory;
       
    55     if ( iCurrentMemory > iMaxMemory ) 
       
    56         {
       
    57         iMaxMemory = iCurrentMemory;
       
    58         }        
       
    59   
       
    60     iIdCount++;
       
    61     if ( iIdCount > iMaxCount ) 
       
    62         {
       
    63         iMaxCount = iIdCount;
       
    64         }    
       
    65     DLTRACE(("Memory: %Ld kB, max: %Ld kB, count: %d, max: %d", 
       
    66         iCurrentMemory >> 10, iMaxMemory >> 10, iIdCount, iMaxCount ));       
       
    67     }
       
    68     
       
    69     
       
    70 void CNcdNodeIdentifier::RemoveId( const CNcdNodeIdentifier& /*aId*/, const TInt64& aMemory )
       
    71     {
       
    72     iIdCount--;
       
    73 
       
    74    
       
    75     iCurrentMemory -= aMemory;
       
    76     DLTRACE(("Memory: %Ld, max: %Ld, count: %d, max: %d", 
       
    77         iCurrentMemory, iMaxMemory, iIdCount, iMaxCount ));    
       
    78     
       
    79     }
       
    80 #endif // LOG_MEMORY_USAGE
       
    81 
       
    82 
       
    83 
       
    84 
       
    85 CNcdNodeIdentifier::CNcdNodeIdentifier(): CBase()
       
    86     {
       
    87     }
       
    88 
       
    89 
       
    90 CNcdNodeIdentifier::CNcdNodeIdentifier( const CNcdNodeIdentifier& aId ) 
       
    91     : CBase(),
       
    92     iNodeNameSpace( aId.iNodeNameSpace ),
       
    93     iNodeId( aId.iNodeId ), 
       
    94     iServerUri( aId.iServerUri ),
       
    95     iClientUid( aId.iClientUid )    
       
    96     {
       
    97     iNodeNameSpace->AddRef();
       
    98     iNodeId->AddRef();
       
    99     iServerUri->AddRef();
       
   100     }
       
   101 
       
   102 
       
   103 CNcdNodeIdentifier::~CNcdNodeIdentifier()
       
   104     {   
       
   105 #ifdef LOG_MEMORY_USAGE
       
   106     if ( iMyMemory ) 
       
   107         {        
       
   108         RemoveId( *this, iMyMemory );
       
   109         }
       
   110 #endif    
       
   111     
       
   112     ReleaseStrings();
       
   113     }
       
   114 
       
   115 
       
   116 void CNcdNodeIdentifier::ReleaseStrings()
       
   117     {
       
   118     if ( iNodeNameSpace ) 
       
   119         {
       
   120         CCatalogsStringManager::StringManager().ReleaseString( 
       
   121             NcdProviderDefines::ENcdStringNamespace,        
       
   122             *iNodeNameSpace );
       
   123         iNodeNameSpace = NULL;
       
   124         }
       
   125 
       
   126     if ( iNodeId ) 
       
   127         {
       
   128         CCatalogsStringManager::StringManager().ReleaseString( 
       
   129             NcdProviderDefines::ENcdStringNodeId,        
       
   130             *iNodeId );
       
   131         iNodeId = NULL;
       
   132         }
       
   133 
       
   134     if ( iServerUri ) 
       
   135         {
       
   136         CCatalogsStringManager::StringManager().ReleaseString( 
       
   137             NcdProviderDefines::ENcdStringServerUri,        
       
   138             *iServerUri );
       
   139         iServerUri = NULL;
       
   140         }
       
   141 
       
   142     }
       
   143 
       
   144 void CNcdNodeIdentifier::ConstructL( const TDesC& aNodeNameSpace,
       
   145                                      const TDesC& aNodeId,
       
   146                                      const TDesC& aServerUri,
       
   147                                      const TUid& aClientUid )
       
   148     {
       
   149     iNodeNameSpace = &CCatalogsStringManager::StringManager().StringL( 
       
   150         NcdProviderDefines::ENcdStringNamespace,
       
   151         aNodeNameSpace );
       
   152         
       
   153     iNodeId = &CCatalogsStringManager::StringManager().StringL( 
       
   154         NcdProviderDefines::ENcdStringNodeId, 
       
   155         aNodeId );
       
   156         
       
   157     iServerUri = &CCatalogsStringManager::StringManager().StringL(
       
   158         NcdProviderDefines::ENcdStringServerUri,
       
   159         aServerUri );
       
   160     
       
   161     iClientUid = aClientUid;    
       
   162 
       
   163 #ifdef LOG_MEMORY_USAGE
       
   164     AddId( *this, iMyMemory );
       
   165 #endif    
       
   166     }
       
   167     
       
   168 
       
   169 void CNcdNodeIdentifier::ConstructL( const TDesC8& aNodeIdentifierData )
       
   170     {
       
   171     RDesReadStream readStream( aNodeIdentifierData );
       
   172     CleanupClosePushL( readStream );
       
   173     InternalizeL( readStream );
       
   174     CleanupStack::PopAndDestroy( &readStream );
       
   175 
       
   176 #ifdef LOG_MEMORY_USAGE
       
   177     AddId( *this, iMyMemory );
       
   178 #endif    
       
   179     }
       
   180 
       
   181 
       
   182 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL()
       
   183     {
       
   184     CNcdNodeIdentifier* self = 
       
   185         CNcdNodeIdentifier::NewLC();
       
   186     CleanupStack::Pop( self );
       
   187     return self;        
       
   188     }
       
   189 
       
   190 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC()
       
   191     {
       
   192     CNcdNodeIdentifier* self = 
       
   193         new( ELeave ) CNcdNodeIdentifier();
       
   194     CleanupStack::PushL( self );
       
   195     self->ConstructL( KNullDesC(), KNullDesC(), KNullDesC(), TUid::Null() );
       
   196     return self;        
       
   197     }
       
   198 
       
   199 
       
   200 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL( const TDesC& aNodeNameSpace,
       
   201                                               const TDesC& aNodeId,
       
   202                                               const TUid& aClientUid )
       
   203     {
       
   204     CNcdNodeIdentifier* self = 
       
   205         CNcdNodeIdentifier::NewLC(
       
   206             aNodeNameSpace,
       
   207             aNodeId,
       
   208             aClientUid );
       
   209     CleanupStack::Pop( self );
       
   210     return self;        
       
   211     }
       
   212 
       
   213 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC( const TDesC& aNodeNameSpace,
       
   214                                                const TDesC& aNodeId,
       
   215                                                const TUid& aClientUid )
       
   216     {
       
   217     CNcdNodeIdentifier* self = 
       
   218         new( ELeave ) CNcdNodeIdentifier();
       
   219     CleanupStack::PushL( self );
       
   220     self->ConstructL( aNodeNameSpace, aNodeId, KNullDesC(), aClientUid );
       
   221     return self;        
       
   222     }
       
   223 
       
   224 
       
   225 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL( const TDesC& aNodeNameSpace,
       
   226                                               const TDesC& aNodeId,
       
   227                                               const TDesC& aServerUri,
       
   228                                               const TUid& aClientUid )
       
   229     {
       
   230     CNcdNodeIdentifier* self = 
       
   231         CNcdNodeIdentifier::NewLC(
       
   232             aNodeNameSpace,
       
   233             aNodeId,
       
   234             aServerUri,
       
   235             aClientUid );
       
   236     CleanupStack::Pop( self );
       
   237     return self;        
       
   238     }
       
   239 
       
   240 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC( const TDesC& aNodeNameSpace,
       
   241                                                const TDesC& aNodeId,
       
   242                                                const TDesC& aServerUri,
       
   243                                                const TUid& aClientUid )
       
   244     {
       
   245     CNcdNodeIdentifier* self = 
       
   246         new( ELeave ) CNcdNodeIdentifier();
       
   247     CleanupStack::PushL( self );
       
   248     self->ConstructL( aNodeNameSpace, aNodeId, aServerUri, aClientUid );
       
   249     return self;
       
   250     }
       
   251 
       
   252 
       
   253 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL(
       
   254     const CNcdNodeIdentifier& aNodeIdentifier )
       
   255     {
       
   256     CNcdNodeIdentifier* self = 
       
   257         CNcdNodeIdentifier::NewLC( aNodeIdentifier );
       
   258     CleanupStack::Pop( self );
       
   259     return self;        
       
   260     }
       
   261 
       
   262 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC(
       
   263     const CNcdNodeIdentifier& aNodeIdentifier )
       
   264     {
       
   265     CNcdNodeIdentifier* self = 
       
   266         new( ELeave ) CNcdNodeIdentifier( aNodeIdentifier );
       
   267     CleanupStack::PushL( self );
       
   268     return self;
       
   269     }
       
   270 
       
   271 
       
   272 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL( const TDesC8& aNodeIdentifierData )
       
   273     {
       
   274     CNcdNodeIdentifier* self = 
       
   275         CNcdNodeIdentifier::NewLC( aNodeIdentifierData );
       
   276     CleanupStack::Pop( self );
       
   277     return self;        
       
   278     }
       
   279 
       
   280 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC( const TDesC8& aNodeIdentifierData )
       
   281     {
       
   282     CNcdNodeIdentifier* self = new( ELeave ) CNcdNodeIdentifier();
       
   283     CleanupStack::PushL( self );
       
   284     self->ConstructL( aNodeIdentifierData );
       
   285     return self;        
       
   286     }
       
   287 
       
   288 
       
   289 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL( RReadStream& aReadStream )
       
   290     {
       
   291     CNcdNodeIdentifier* self = NewLC( aReadStream );
       
   292     CleanupStack::Pop( self );
       
   293     return self;        
       
   294     }
       
   295 
       
   296 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC( RReadStream& aReadStream )
       
   297     {
       
   298     CNcdNodeIdentifier* self = new( ELeave ) CNcdNodeIdentifier();
       
   299     CleanupStack::PushL( self );
       
   300     self->InternalizeL( aReadStream );
       
   301     return self;        
       
   302     }
       
   303 
       
   304 
       
   305 void CNcdNodeIdentifier::InternalizeL( RReadStream& aReadStream )
       
   306     {
       
   307     HBufC* temp = NULL;
       
   308     InternalizeDesL( temp, aReadStream );    
       
   309 
       
   310     
       
   311     // StringL handles the ownership of temp
       
   312     const CCatalogsRefString& nameSpace = 
       
   313         CCatalogsStringManager::StringManager().StringL( 
       
   314             NcdProviderDefines::ENcdStringNamespace,
       
   315             temp );
       
   316     
       
   317     CCatalogsStringManager::StringManager().ReleaseString(
       
   318         NcdProviderDefines::ENcdStringNamespace,
       
   319         iNodeNameSpace );
       
   320     
       
   321     iNodeNameSpace = &nameSpace;
       
   322     
       
   323     temp = NULL;
       
   324     
       
   325     InternalizeDesL( temp, aReadStream );
       
   326     
       
   327     
       
   328     const CCatalogsRefString& nodeId = 
       
   329         CCatalogsStringManager::StringManager().StringL( 
       
   330             NcdProviderDefines::ENcdStringNodeId,
       
   331             temp );
       
   332 
       
   333 
       
   334     CCatalogsStringManager::StringManager().ReleaseString(
       
   335         NcdProviderDefines::ENcdStringNodeId,
       
   336         iNodeId );
       
   337     
       
   338     iNodeId = &nodeId;
       
   339     
       
   340     temp = NULL;
       
   341     
       
   342     InternalizeDesL( temp, aReadStream );
       
   343     
       
   344     const CCatalogsRefString& serverUri = 
       
   345         CCatalogsStringManager::StringManager().StringL( 
       
   346             NcdProviderDefines::ENcdStringServerUri,
       
   347             temp );    
       
   348 
       
   349     CCatalogsStringManager::StringManager().ReleaseString(
       
   350         NcdProviderDefines::ENcdStringServerUri,
       
   351         iServerUri );
       
   352 
       
   353     iServerUri = &serverUri;          
       
   354    
       
   355     iClientUid.iUid = aReadStream.ReadInt32L();      
       
   356     }
       
   357 
       
   358 
       
   359 void CNcdNodeIdentifier::ExternalizeL( RWriteStream& aWriteStream ) const
       
   360     {
       
   361     ExternalizeDesL( NodeNameSpace(), aWriteStream );
       
   362     ExternalizeDesL( NodeId(), aWriteStream );
       
   363     ExternalizeDesL( ServerUri(), aWriteStream );
       
   364     aWriteStream.WriteInt32L( iClientUid.iUid );    
       
   365     }
       
   366  
       
   367         
       
   368 const TDesC& CNcdNodeIdentifier::NodeNameSpace() const
       
   369     {
       
   370     DASSERT( iNodeNameSpace );
       
   371     return *iNodeNameSpace;
       
   372     }    
       
   373 
       
   374 const TDesC& CNcdNodeIdentifier::NodeId() const
       
   375     {
       
   376     DASSERT( iNodeId );
       
   377     return *iNodeId;
       
   378     }
       
   379 
       
   380 const TDesC& CNcdNodeIdentifier::ServerUri() const
       
   381     {
       
   382     DASSERT( iServerUri );
       
   383     return *iServerUri;
       
   384     }
       
   385 
       
   386 const TUid& CNcdNodeIdentifier::ClientUid() const
       
   387     {
       
   388     return iClientUid;
       
   389     }
       
   390 
       
   391 
       
   392 HBufC8* CNcdNodeIdentifier::NodeIdentifierDataL() const
       
   393     {
       
   394     CBufBase* buf = CBufFlat::NewL( KBufExpandSize );
       
   395     CleanupStack::PushL( buf );
       
   396     RBufWriteStream stream( *buf );
       
   397     CleanupClosePushL( stream );
       
   398 
       
   399     // Get the data of this identifier into the stream which
       
   400     // directs the data into the buffer.
       
   401     ExternalizeL( stream );
       
   402 
       
   403     // Now data has been externalized into the buffer.
       
   404     // Create copy of the data and return it.
       
   405     HBufC8* data = buf->Ptr( 0 ).AllocL();
       
   406     CleanupStack::PopAndDestroy( &stream );
       
   407     CleanupStack::PopAndDestroy( buf );
       
   408     return data;
       
   409     }
       
   410     
       
   411 
       
   412 TBool CNcdNodeIdentifier::ContainsEmptyFields(
       
   413     TBool aCheckNameSpace,
       
   414     TBool aCheckId,
       
   415     TBool aCheckUri,
       
   416     TBool aCheckUid ) const
       
   417     {
       
   418     return ( aCheckNameSpace && NodeNameSpace() == KNullDesC() )
       
   419         || ( aCheckId && NodeId() == KNullDesC() )
       
   420         || ( aCheckUri && ServerUri() == KNullDesC() )
       
   421         || ( ClientUid() == TUid::Null() && aCheckUid );
       
   422     }
       
   423 
       
   424 
       
   425 TBool CNcdNodeIdentifier::Equals( 
       
   426     const CNcdNodeIdentifier& aObject,
       
   427     TBool aCompareNameSpace,
       
   428     TBool aCompareId,
       
   429     TBool aCompareUri,
       
   430     TBool aCompareUid ) const
       
   431     {
       
   432     // Use pointer comparison for strings
       
   433     return ( iNodeNameSpace == aObject.iNodeNameSpace
       
   434                 || !aCompareNameSpace ) 
       
   435            && ( iNodeId == aObject.iNodeId
       
   436                 || !aCompareId )
       
   437            && ( iServerUri == aObject.iServerUri 
       
   438                 || !aCompareUri )
       
   439            && ( ClientUid() == aObject.ClientUid() 
       
   440                 || !aCompareUid );
       
   441 
       
   442     }
       
   443 
       
   444 TBool CNcdNodeIdentifier::Equals( 
       
   445     const CNcdNodeIdentifier& aObject1,
       
   446     const CNcdNodeIdentifier& aObject2,
       
   447     TBool aCompareNameSpace,
       
   448     TBool aCompareId,
       
   449     TBool aCompareUri,
       
   450     TBool aCompareUid )
       
   451     {
       
   452     return aObject1.Equals( 
       
   453         aObject2, 
       
   454         aCompareNameSpace, 
       
   455         aCompareId,
       
   456         aCompareUri,
       
   457         aCompareUid );
       
   458     }
       
   459 
       
   460 
       
   461 TInt CNcdNodeIdentifier::Compare( 
       
   462     const CNcdNodeIdentifier& aObject1,
       
   463     const CNcdNodeIdentifier& aObject2 )
       
   464     {
       
   465     // First compare pointers, if they differ compare strings
       
   466     TInt comp = ( aObject1.iNodeId != aObject2.iNodeId );
       
   467     if ( comp ) 
       
   468         {
       
   469         comp = aObject1.NodeId().Compare( aObject2.NodeId() );    
       
   470         }
       
   471     
       
   472     if ( !comp ) 
       
   473         {
       
   474         comp = ( aObject1.iNodeNameSpace != aObject2.iNodeNameSpace );
       
   475         if ( comp ) 
       
   476             {            
       
   477             comp = aObject1.NodeNameSpace().Compare( aObject2.NodeNameSpace() );
       
   478             }
       
   479             
       
   480         if ( !comp ) 
       
   481             {
       
   482             comp = aObject1.ClientUid().iUid - aObject2.ClientUid().iUid;
       
   483             }
       
   484         }
       
   485     return comp;        
       
   486     }
       
   487 
       
   488 
       
   489 TInt CNcdNodeIdentifier::CompareOrderByUid( 
       
   490     const CNcdNodeIdentifier& aObject1,
       
   491     const CNcdNodeIdentifier& aObject2 )
       
   492     {
       
   493     TInt comp = aObject1.ClientUid().iUid - aObject2.ClientUid().iUid;
       
   494         
       
   495     if ( !comp ) 
       
   496         {
       
   497         comp = aObject1.NodeNameSpace().Compare( aObject2.NodeNameSpace() );
       
   498         if ( !comp ) 
       
   499             {
       
   500             comp = aObject1.NodeId().Compare( aObject2.NodeId() );            
       
   501             }
       
   502         }
       
   503     return comp;        
       
   504     }
       
   505 
       
   506 
       
   507 
       
   508 void CNcdNodeIdentifier::SetNodeIdL( const TDesC& aNodeId )
       
   509     {    
       
   510     const CCatalogsRefString& id = 
       
   511         CCatalogsStringManager::StringManager().StringL( 
       
   512             NcdProviderDefines::ENcdStringNodeId,
       
   513             aNodeId );
       
   514     
       
   515     CCatalogsStringManager::StringManager().ReleaseString(
       
   516         NcdProviderDefines::ENcdStringNodeId,
       
   517         iNodeId );
       
   518     
       
   519     iNodeId = &id;
       
   520     }
       
   521 
       
   522 
       
   523 
       
   524 
       
   525 #else // COMPONENT_CATALOGSSERVEREXE ********************************************************
       
   526 
       
   527 
       
   528 
       
   529 
       
   530 
       
   531 
       
   532 CNcdNodeIdentifier::CNcdNodeIdentifier(): CBase()
       
   533     {
       
   534     }
       
   535 
       
   536 CNcdNodeIdentifier::~CNcdNodeIdentifier()
       
   537     {   
       
   538     delete iNodeNameSpace;
       
   539     iNodeNameSpace = NULL;
       
   540     
       
   541     delete iNodeId;
       
   542     iNodeId = NULL;
       
   543 
       
   544     delete iServerUri;
       
   545     iServerUri = NULL;
       
   546     }
       
   547 
       
   548 
       
   549 void CNcdNodeIdentifier::ConstructL( const TDesC& aNodeNameSpace,
       
   550                                      const TDesC& aNodeId,
       
   551                                      const TDesC& aServerUri,
       
   552                                      const TUid& aClientUid )
       
   553     {
       
   554     iNodeNameSpace = aNodeNameSpace.AllocL();
       
   555     iNodeId = aNodeId.AllocL();
       
   556     iServerUri = aServerUri.AllocL();
       
   557     iClientUid = aClientUid;    
       
   558     }
       
   559 
       
   560 void CNcdNodeIdentifier::ConstructL( const TDesC8& aNodeIdentifierData )
       
   561     {
       
   562     RDesReadStream readStream( aNodeIdentifierData );
       
   563     CleanupClosePushL( readStream );
       
   564     InternalizeL( readStream );
       
   565     CleanupStack::PopAndDestroy( &readStream );
       
   566     }
       
   567 
       
   568 
       
   569 
       
   570 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL()
       
   571     {
       
   572     CNcdNodeIdentifier* self = 
       
   573         CNcdNodeIdentifier::NewLC();
       
   574     CleanupStack::Pop( self );
       
   575     return self;        
       
   576     }
       
   577 
       
   578 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC()
       
   579     {
       
   580     CNcdNodeIdentifier* self = 
       
   581         new( ELeave ) CNcdNodeIdentifier();
       
   582     CleanupStack::PushL( self );
       
   583     self->ConstructL( KNullDesC(), KNullDesC(), KNullDesC(), TUid::Null() );
       
   584     return self;        
       
   585     }
       
   586 
       
   587 
       
   588 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL( const TDesC& aNodeNameSpace,
       
   589                                               const TDesC& aNodeId,
       
   590                                               const TUid& aClientUid )
       
   591     {
       
   592     CNcdNodeIdentifier* self = 
       
   593         CNcdNodeIdentifier::NewLC(
       
   594             aNodeNameSpace,
       
   595             aNodeId,
       
   596             aClientUid );
       
   597     CleanupStack::Pop( self );
       
   598     return self;        
       
   599     }
       
   600 
       
   601 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC( const TDesC& aNodeNameSpace,
       
   602                                                const TDesC& aNodeId,
       
   603                                                const TUid& aClientUid )
       
   604     {
       
   605     CNcdNodeIdentifier* self = 
       
   606         new( ELeave ) CNcdNodeIdentifier();
       
   607     CleanupStack::PushL( self );
       
   608     self->ConstructL( aNodeNameSpace, aNodeId, KNullDesC(), aClientUid );
       
   609     return self;        
       
   610     }
       
   611 
       
   612 
       
   613 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL( const TDesC& aNodeNameSpace,
       
   614                                               const TDesC& aNodeId,
       
   615                                               const TDesC& aServerUri,
       
   616                                               const TUid& aClientUid )
       
   617     {
       
   618     CNcdNodeIdentifier* self = 
       
   619         CNcdNodeIdentifier::NewLC(
       
   620             aNodeNameSpace,
       
   621             aNodeId,
       
   622             aServerUri,
       
   623             aClientUid );
       
   624     CleanupStack::Pop( self );
       
   625     return self;        
       
   626     }
       
   627 
       
   628 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC( const TDesC& aNodeNameSpace,
       
   629                                                const TDesC& aNodeId,
       
   630                                                const TDesC& aServerUri,
       
   631                                                const TUid& aClientUid )
       
   632     {
       
   633     CNcdNodeIdentifier* self = 
       
   634         new( ELeave ) CNcdNodeIdentifier();
       
   635     CleanupStack::PushL( self );
       
   636     self->ConstructL( aNodeNameSpace, aNodeId, aServerUri, aClientUid );
       
   637     return self;
       
   638     }
       
   639 
       
   640 
       
   641 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL(
       
   642     const CNcdNodeIdentifier& aNodeIdentifier )
       
   643     {
       
   644     CNcdNodeIdentifier* self = 
       
   645         CNcdNodeIdentifier::NewLC( aNodeIdentifier );
       
   646     CleanupStack::Pop( self );
       
   647     return self;        
       
   648     }
       
   649 
       
   650 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC(
       
   651     const CNcdNodeIdentifier& aNodeIdentifier )
       
   652     {
       
   653     CNcdNodeIdentifier* self = 
       
   654         new( ELeave ) CNcdNodeIdentifier();
       
   655     CleanupStack::PushL( self );
       
   656     self->ConstructL(
       
   657         aNodeIdentifier.NodeNameSpace(),
       
   658         aNodeIdentifier.NodeId(),
       
   659         aNodeIdentifier.ServerUri(),
       
   660         aNodeIdentifier.ClientUid() );
       
   661     return self;
       
   662     }
       
   663 
       
   664 
       
   665 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL( const TDesC8& aNodeIdentifierData )
       
   666     {
       
   667     CNcdNodeIdentifier* self = 
       
   668         CNcdNodeIdentifier::NewLC( aNodeIdentifierData );
       
   669     CleanupStack::Pop( self );
       
   670     return self;        
       
   671     }
       
   672 
       
   673 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC( const TDesC8& aNodeIdentifierData )
       
   674     {
       
   675     CNcdNodeIdentifier* self = new( ELeave ) CNcdNodeIdentifier();
       
   676     CleanupStack::PushL( self );
       
   677     self->ConstructL( aNodeIdentifierData );
       
   678     return self;        
       
   679     }
       
   680 
       
   681 
       
   682 CNcdNodeIdentifier* CNcdNodeIdentifier::NewL( RReadStream& aReadStream )
       
   683     {
       
   684     CNcdNodeIdentifier* self = NewLC( aReadStream );
       
   685     CleanupStack::Pop( self );
       
   686     return self;        
       
   687     }
       
   688 
       
   689 CNcdNodeIdentifier* CNcdNodeIdentifier::NewLC( RReadStream& aReadStream )
       
   690     {
       
   691     CNcdNodeIdentifier* self = new( ELeave ) CNcdNodeIdentifier();
       
   692     CleanupStack::PushL( self );
       
   693     self->InternalizeL( aReadStream );
       
   694     return self;        
       
   695     }
       
   696 
       
   697 
       
   698 void CNcdNodeIdentifier::InternalizeL( RReadStream& aReadStream )
       
   699     {    
       
   700     InternalizeDesL( iNodeNameSpace, aReadStream );
       
   701     InternalizeDesL( iNodeId, aReadStream );
       
   702     InternalizeDesL( iServerUri, aReadStream );
       
   703     iClientUid.iUid = aReadStream.ReadInt32L();    
       
   704     }
       
   705 
       
   706 void CNcdNodeIdentifier::ExternalizeL( RWriteStream& aWriteStream ) const
       
   707     {
       
   708     ExternalizeDesL( *iNodeNameSpace, aWriteStream );
       
   709     ExternalizeDesL( *iNodeId, aWriteStream );
       
   710     ExternalizeDesL( *iServerUri, aWriteStream );
       
   711     aWriteStream.WriteInt32L( iClientUid.iUid );    
       
   712     }
       
   713  
       
   714         
       
   715 const TDesC& CNcdNodeIdentifier::NodeNameSpace() const
       
   716     {
       
   717     return *iNodeNameSpace;
       
   718     }    
       
   719 
       
   720 const TDesC& CNcdNodeIdentifier::NodeId() const
       
   721     {
       
   722     return *iNodeId;
       
   723     }
       
   724 
       
   725 const TDesC& CNcdNodeIdentifier::ServerUri() const
       
   726     {
       
   727     return *iServerUri;
       
   728     }
       
   729 
       
   730 const TUid& CNcdNodeIdentifier::ClientUid() const
       
   731     {
       
   732     return iClientUid;
       
   733     }
       
   734 
       
   735 
       
   736 HBufC8* CNcdNodeIdentifier::NodeIdentifierDataL() const
       
   737     {
       
   738     CBufBase* buf = CBufFlat::NewL( KBufExpandSize );
       
   739     CleanupStack::PushL( buf );
       
   740     RBufWriteStream stream( *buf );
       
   741     CleanupClosePushL( stream );
       
   742 
       
   743     // Get the data of this identifier into the stream which
       
   744     // directs the data into the buffer.
       
   745     ExternalizeL( stream );
       
   746 
       
   747     // Now data has been externalized into the buffer.
       
   748     // Create copy of the data and return it.
       
   749     HBufC8* data = buf->Ptr( 0 ).AllocL();
       
   750     CleanupStack::PopAndDestroy( &stream );
       
   751     CleanupStack::PopAndDestroy( buf );
       
   752     return data;
       
   753     }
       
   754 
       
   755 TBool CNcdNodeIdentifier::ContainsEmptyFields(
       
   756     TBool aCheckNameSpace,
       
   757     TBool aCheckId,
       
   758     TBool aCheckUri,
       
   759     TBool aCheckUid ) const
       
   760     {
       
   761     return ( aCheckNameSpace && NodeNameSpace() == KNullDesC() )
       
   762         || ( aCheckId && NodeId() == KNullDesC() )
       
   763         || ( aCheckUri && ServerUri() == KNullDesC() )
       
   764         || ( ClientUid() == TUid::Null() && aCheckUid );
       
   765     }
       
   766 
       
   767 
       
   768 TBool CNcdNodeIdentifier::Equals( 
       
   769     const CNcdNodeIdentifier& aObject,
       
   770     TBool aCompareNameSpace,
       
   771     TBool aCompareId,
       
   772     TBool aCompareUri,
       
   773     TBool aCompareUid ) const
       
   774     {
       
   775     return ( NodeNameSpace() == aObject.NodeNameSpace() 
       
   776                 || !aCompareNameSpace ) 
       
   777            && ( NodeId() == aObject.NodeId() 
       
   778                 || !aCompareId )
       
   779            // By default aCompareUri is EFalse so this order is a little
       
   780            // bit faster in default cases
       
   781            && ( !aCompareUri || 
       
   782                 ServerUri() == aObject.ServerUri() )
       
   783            && ( ClientUid() == aObject.ClientUid() 
       
   784                 || !aCompareUid );
       
   785     }
       
   786 
       
   787 TBool CNcdNodeIdentifier::Equals( 
       
   788     const CNcdNodeIdentifier& aObject1,
       
   789     const CNcdNodeIdentifier& aObject2,
       
   790     TBool aCompareNameSpace,
       
   791     TBool aCompareId,
       
   792     TBool aCompareUri,
       
   793     TBool aCompareUid )
       
   794     {
       
   795     return ( aObject1.NodeNameSpace() == aObject2.NodeNameSpace()
       
   796                 || !aCompareNameSpace )
       
   797            && ( aObject1.NodeId() == aObject2.NodeId()
       
   798                 || !aCompareId )
       
   799            // By default aCompareUri is EFalse so this order is a little
       
   800            // bit faster in default cases
       
   801            && ( !aCompareUri ||
       
   802                 aObject1.ServerUri() == aObject2.ServerUri() )
       
   803            && ( aObject1.ClientUid() == aObject2.ClientUid()
       
   804                 || !aCompareUid );
       
   805     }
       
   806 
       
   807 
       
   808 TInt CNcdNodeIdentifier::Compare( 
       
   809     const CNcdNodeIdentifier& aObject1,
       
   810     const CNcdNodeIdentifier& aObject2 )
       
   811     {
       
   812     TInt comp = aObject1.NodeId().Compare( aObject2.NodeId() );    
       
   813     
       
   814     if ( !comp ) 
       
   815         {
       
   816         comp = aObject1.NodeNameSpace().Compare( aObject2.NodeNameSpace() );
       
   817         if ( !comp ) 
       
   818             {
       
   819             comp = aObject1.ClientUid().iUid - aObject2.ClientUid().iUid;
       
   820             }
       
   821         }
       
   822     return comp;        
       
   823     }
       
   824 
       
   825 
       
   826 TInt CNcdNodeIdentifier::CompareOrderByUid( 
       
   827     const CNcdNodeIdentifier& aObject1,
       
   828     const CNcdNodeIdentifier& aObject2 )
       
   829     {
       
   830     TInt comp = aObject1.ClientUid().iUid - aObject2.ClientUid().iUid;
       
   831         
       
   832     if ( !comp ) 
       
   833         {
       
   834         comp = aObject1.NodeNameSpace().Compare( aObject2.NodeNameSpace() );
       
   835         if ( !comp ) 
       
   836             {
       
   837             comp = aObject1.NodeId().Compare( aObject2.NodeId() );            
       
   838             }
       
   839         }
       
   840     return comp;        
       
   841     }
       
   842 
       
   843 #endif
       
   844