ncdengine/provider/client/src/ncdrootnodeproxy.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 CNcdRootNodeProxy class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdrootnodeproxy.h"
       
    20 #include "catalogsclientserver.h"
       
    21 #include "ncdnodemanagerproxy.h"
       
    22 #include "ncdoperationmanagerproxy.h"
       
    23 #include "ncdnodeidentifier.h"
       
    24 #include "catalogsdebug.h"
       
    25 #include "ncdnodefunctionids.h"
       
    26 #include "catalogsinterfaceidentifier.h"
       
    27 #include "ncdloadnodeoperationproxy.h"
       
    28 #include "ncdchildentity.h"
       
    29 #include "ncderrors.h"
       
    30 
       
    31 
       
    32 // ======== PUBLIC MEMBER FUNCTIONS ========
       
    33 
       
    34 CNcdRootNodeProxy* CNcdRootNodeProxy::NewL( MCatalogsClientServer& aSession,
       
    35                                             TInt aHandle,
       
    36                                             CNcdNodeManagerProxy& aNodeManager,
       
    37                                             CNcdOperationManagerProxy& aOperationManager,
       
    38                                             CNcdFavoriteManagerProxy& aFavoriteManager )
       
    39     {
       
    40     CNcdRootNodeProxy* self = 
       
    41         CNcdRootNodeProxy::NewLC(
       
    42             aSession, aHandle, aNodeManager, aOperationManager, aFavoriteManager );
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 CNcdRootNodeProxy* CNcdRootNodeProxy::NewLC( MCatalogsClientServer& aSession,
       
    48                                              TInt aHandle,
       
    49                                              CNcdNodeManagerProxy& aNodeManager,
       
    50                                              CNcdOperationManagerProxy& aOperationManager,
       
    51                                              CNcdFavoriteManagerProxy& aFavoriteManager )
       
    52     {
       
    53     CNcdRootNodeProxy* self = 
       
    54         new( ELeave ) CNcdRootNodeProxy(
       
    55             aSession, aHandle, aNodeManager, aOperationManager, aFavoriteManager );  
       
    56     // Using PushL because the object does not have any references yet
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL();
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 CNcdRootNodeProxy::CNcdRootNodeProxy( MCatalogsClientServer& aSession,
       
    64                                       TInt aHandle,
       
    65                                       CNcdNodeManagerProxy& aNodeManager,
       
    66                                       CNcdOperationManagerProxy& aOperationManager,
       
    67                                       CNcdFavoriteManagerProxy& aFavoriteManager ) 
       
    68 : CNcdParentOfTransparentNodeProxy(
       
    69     aSession, aHandle, aNodeManager, aOperationManager, aFavoriteManager )
       
    70     {
       
    71     }
       
    72 
       
    73 
       
    74 void CNcdRootNodeProxy::ConstructL()
       
    75     {
       
    76     CNcdParentOfTransparentNodeProxy::ConstructL(); 
       
    77     }
       
    78 
       
    79 
       
    80 CNcdRootNodeProxy::~CNcdRootNodeProxy()
       
    81     {
       
    82     }
       
    83 
       
    84 
       
    85 TInt CNcdRootNodeProxy::ChildCount() const
       
    86     {
       
    87     return iChildren.Count();
       
    88     }
       
    89 
       
    90 
       
    91 MNcdNode* CNcdRootNodeProxy::ChildL( TInt aIndex )
       
    92     {
       
    93     DLTRACEIN(( _L("This parent: %S, %S"), &Namespace(), &Id() ));
       
    94 
       
    95            
       
    96     if ( aIndex < 0 || aIndex >= iChildren.Count() )
       
    97         {
       
    98         // Nothing to be done 
       
    99         DLERROR(( "Index error. child count: %d Given index: %d", 
       
   100                   iChildren.Count(), aIndex ));
       
   101         DASSERT( EFalse );
       
   102         User::Leave( KErrArgument );
       
   103         }
       
   104         
       
   105     const CNcdNodeIdentifier* child = &iChildren[aIndex]->Identifier();
       
   106         
       
   107     MNcdNode* node( NULL );
       
   108     
       
   109     TRAPD( err, node = &NodeManager().NodeL( *child ) );
       
   110     
       
   111     if ( err == KErrNotFound ) 
       
   112         {
       
   113         return NULL;
       
   114         }        
       
   115     
       
   116     User::LeaveIfError( err );
       
   117         
       
   118     // Increase the reference counter by one
       
   119     node->AddRef();
       
   120     
       
   121     DLTRACEOUT((""));
       
   122 
       
   123     return node;
       
   124     }
       
   125 
       
   126 MNcdNode::TState CNcdRootNodeProxy::State() const
       
   127     {
       
   128     DLTRACEIN((""));
       
   129 
       
   130     // Check if the link handle has been set, which means that also
       
   131     // link data has been internalized. Root node does not contain
       
   132     // metadata so it does not need to be checked.
       
   133     // The child count is also checked because in some situations when root loading
       
   134     // is cancelled the link handle may be set, but the children are not inserted to 
       
   135     // the root child list. So, the root should have children to be in initialized mode.
       
   136     if ( LinkHandleSet() && ChildCount() > 0 )
       
   137         {
       
   138         DLTRACE(("State was initialized"));
       
   139         // If state was initialized we have to check if the state
       
   140         // has acutally expired already 
       
   141         TTime now;
       
   142         now.HomeTime();
       
   143 
       
   144         DLTRACE(("now time: %d", now.Int64() ));
       
   145         DLTRACE(("expired time: %d", ExpiredTime().Int64() ));
       
   146 
       
   147         // We can just compare the times here. Server side
       
   148         // inserts the maximum value for the expired time if the
       
   149         // protocol has set never expire value for the validity delta.
       
   150         TBool isExpired = ( now > ExpiredTime() );
       
   151         TInt err = KErrNone;
       
   152         
       
   153         if ( !isExpired ) 
       
   154             {            
       
   155             TRAP( err, isExpired = IsTransparentChildExpiredL() );
       
   156             }
       
   157             
       
   158         if ( isExpired || err != KErrNone )
       
   159             {
       
   160             DLTRACEOUT(("Expired"));
       
   161             return MNcdNode::EStateExpired;
       
   162             }
       
   163             
       
   164         DLTRACEOUT(("Initialized"));
       
   165         return MNcdNode::EStateInitialized;
       
   166         }
       
   167      else
       
   168         {
       
   169         // Node has not been initialized.
       
   170         DLTRACEOUT(("Not intialized"));
       
   171         return MNcdNode::EStateNotInitialized;
       
   172         }
       
   173 
       
   174     }
       
   175 
       
   176 
       
   177 MNcdLoadNodeOperation* CNcdRootNodeProxy::LoadL( MNcdLoadNodeOperationObserver& aObserver )
       
   178     {
       
   179     DLTRACEIN((""));
       
   180     
       
   181     CNcdLoadNodeOperationProxy* operation( NULL );
       
   182 
       
   183     operation =
       
   184         OperationManager().
       
   185             CreateLoadRootNodeOperationL( *this );
       
   186 
       
   187     operation->AddObserverL( this );
       
   188     operation->AddObserverL( &aObserver );
       
   189 
       
   190     DLTRACEOUT((""));
       
   191 
       
   192     return operation;
       
   193     }
       
   194 
       
   195 
       
   196 MNcdLoadNodeOperation* CNcdRootNodeProxy::LoadChildrenL( TInt /*aIndex*/, 
       
   197                                                          TInt /*aSize*/,
       
   198                                                          TNcdChildLoadMode aMode,
       
   199                                                          MNcdLoadNodeOperationObserver& aObserver )
       
   200     {
       
   201     DLTRACEIN(("Root load mode: %d", aMode));
       
   202 
       
   203     // Root is a special case when children are loaded.
       
   204     // Because root operation always load its children same time normal LoadL is called
       
   205     // for the root, the children of the root are always up to date.
       
   206     // The only exception is, if the schemes are added to the root list separately.
       
   207     // Because of the possible schemes, this function is overloaded and the 
       
   208     // staring index is set to be zero and the size has to be the whole child array size which
       
   209     // includes the possible scheme.
       
   210     
       
   211     CNcdLoadNodeOperationProxy* operation = 
       
   212         OperationManager().CreateLoadNodeOperationL( *this, ETrue,
       
   213                                                      ServerChildCount(),
       
   214                                                      0,
       
   215                                                      1,
       
   216                                                      aMode );
       
   217 
       
   218     if( operation == NULL )
       
   219         {
       
   220         DLTRACEOUT(("NULL"));     
       
   221         return NULL;
       
   222         }
       
   223 
       
   224     operation->AddObserverL( this );
       
   225     operation->AddObserverL( &aObserver );
       
   226 
       
   227     DLTRACEOUT((""));        
       
   228 
       
   229     return operation;
       
   230     }
       
   231 
       
   232 
       
   233 RCatalogsArray<MNcdOperation> CNcdRootNodeProxy::OperationsL() const
       
   234     {
       
   235     DLTRACEIN((""));
       
   236     RCatalogsArray<MNcdOperation> operations;
       
   237     CleanupClosePushL( operations );
       
   238 
       
   239     // Operations will be get differently for root node, because root
       
   240     // node does not have metadata.
       
   241     
       
   242     // Get the original array and insert its content to catalogs array.
       
   243     // Also, increase the reference counter for the items.
       
   244     const RPointerArray<MNcdOperation>& origArray = OperationManager().Operations();
       
   245     const MNcdNode* thisNode( this );
       
   246     MNcdOperation* oper( NULL );
       
   247     MNcdNode* node( NULL );
       
   248 
       
   249     for ( TInt i = 0; i < origArray.Count(); ++i )
       
   250         {
       
   251         oper = origArray[ i ];
       
   252 
       
   253         // Notice that node ref count is increased. So, release it when done.
       
   254         node = oper->Node();
       
   255         CleanupReleasePushL( *node );
       
   256 
       
   257         if( node == thisNode )
       
   258             {
       
   259             operations.AppendL( oper );
       
   260             oper->AddRef();
       
   261             }
       
   262 
       
   263         CleanupStack::PopAndDestroy( node );
       
   264         }
       
   265 
       
   266     CleanupStack::Pop( &operations );
       
   267     
       
   268     DLTRACEOUT(( "" ));
       
   269     return operations;
       
   270     }
       
   271 
       
   272 
       
   273 void CNcdRootNodeProxy::OperationComplete( MNcdLoadNodeOperation& /*aOperation*/,
       
   274                                            TInt aError )
       
   275     {
       
   276     DLTRACEIN((""));
       
   277     // Should all the error code checks be removed and always internalize root node?
       
   278     if( aError == KErrNone || aError == KNcdErrorSomeCatalogsFailedToLoad || 
       
   279         aError == KErrCancel )
       
   280         {
       
   281         // Because operation went ok. Update the node data.
       
   282         TRAP_IGNORE( InternalizeL() );
       
   283         }
       
   284     DLTRACEOUT((""));
       
   285     }
       
   286