ncdengine/provider/client/src/ncdnodeskinproxy.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 CNcdNodeSkinProxy class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdnodeskinproxy.h"
       
    20 #include "ncdnodeproxy.h"
       
    21 #include "ncdnodemetadataproxy.h"
       
    22 #include "ncdoperationimpl.h"
       
    23 #include "ncdfiledownloadoperationproxy.h"
       
    24 #include "ncdoperationmanagerproxy.h"
       
    25 #include "ncdoperationdatatypes.h"
       
    26 #include "catalogsclientserver.h"
       
    27 #include "ncdnodeidentifier.h"
       
    28 #include "ncdnodefunctionids.h"
       
    29 #include "ncdnodeclassids.h"
       
    30 #include "catalogsinterfaceidentifier.h"
       
    31 #include "catalogsutils.h"
       
    32 #include "catalogsdebug.h"
       
    33 #include "ncderrors.h"
       
    34 
       
    35 
       
    36 // ======== PUBLIC MEMBER FUNCTIONS ========
       
    37 
       
    38 CNcdNodeSkinProxy::CNcdNodeSkinProxy(
       
    39     MCatalogsClientServer& aSession,
       
    40     TInt aHandle,
       
    41     CNcdNodeMetadataProxy& aMetadata )
       
    42     : CNcdInterfaceBaseProxy( aSession, aHandle, &aMetadata ),
       
    43       iMetadata( aMetadata ),
       
    44       iTimeStamp( 0 )
       
    45     {
       
    46     }
       
    47 
       
    48 
       
    49 void CNcdNodeSkinProxy::ConstructL()
       
    50     {
       
    51     // Register the interface
       
    52     MNcdNodeSkin* interface( this );
       
    53     AddInterfaceL( 
       
    54         CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeSkin::KInterfaceUid ) );
       
    55 
       
    56     // Make sure that the skin id contains at least some data.
       
    57     iSkinId = KNullDesC().AllocL();
       
    58 
       
    59     // Constructor already initialized timestamp to zero.
       
    60     
       
    61     InternalizeL();
       
    62     }
       
    63     
       
    64     
       
    65 CNcdNodeSkinProxy* CNcdNodeSkinProxy::NewL(
       
    66     MCatalogsClientServer& aSession,
       
    67     TInt aHandle,
       
    68     CNcdNodeMetadataProxy& aMetadata )
       
    69     {
       
    70     CNcdNodeSkinProxy* self = 
       
    71         CNcdNodeSkinProxy::NewLC( aSession, aHandle, aMetadata );
       
    72     CleanupStack::Pop( self );
       
    73     return self;
       
    74     }
       
    75 
       
    76 CNcdNodeSkinProxy* CNcdNodeSkinProxy::NewLC(
       
    77     MCatalogsClientServer& aSession,
       
    78     TInt aHandle,
       
    79     CNcdNodeMetadataProxy& aMetadata )
       
    80     {
       
    81     CNcdNodeSkinProxy* self = 
       
    82         new( ELeave ) CNcdNodeSkinProxy( aSession, aHandle, aMetadata );
       
    83     // Using PushL because the object does not have any references yet
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86     return self;
       
    87     }
       
    88 
       
    89 
       
    90 CNcdNodeSkinProxy::~CNcdNodeSkinProxy()
       
    91     {
       
    92     // Remove interfaces implemented by this class from the interface list.
       
    93     // So, the interface list is up to date when this class object is deleted.
       
    94     RemoveInterface( MNcdNodeSkin::KInterfaceUid );
       
    95 
       
    96     // Delete member variables here
       
    97     delete iSkinId;
       
    98     iSkinId = NULL;
       
    99 
       
   100     // Do not delete metadata because this object does not own it.
       
   101     }
       
   102 
       
   103 
       
   104 void CNcdNodeSkinProxy::InternalizeL()
       
   105     {
       
   106     DLTRACEIN((""));
       
   107 
       
   108     HBufC8* data( NULL );
       
   109         
       
   110     // Because we do not know the exact size of the data, use
       
   111     // the alloc method, which creates the buffer of the right size
       
   112     // and sets the pointer to point to the created buffer.
       
   113     // Get all the data that is necessary to internalize this object
       
   114     // from the server side.
       
   115     TInt error(
       
   116         ClientServerSession().
       
   117         SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize,
       
   118                        KNullDesC8,
       
   119                        data,
       
   120                        Handle(),
       
   121                        0 ) );
       
   122 
       
   123     if ( error == KNcdErrorObsolete )
       
   124         {
       
   125         DLINFO(("Skin was obsolete"));
       
   126         SetObsolete( ETrue );
       
   127         // Remove interfaces implemented by this class from the top parent interface list.
       
   128         // So, the interface list is up to date after this object is removed
       
   129         // from its top parent.
       
   130         RemoveInterface( MNcdNodeSkin::KInterfaceUid );
       
   131         // Remove from the parent
       
   132         RemoveFromParent();
       
   133         // Now update the interface for this object just in case somebody needs it.
       
   134         // Register the interface
       
   135         MNcdNodeSkin* interface( this );
       
   136         AddInterfaceL( 
       
   137             CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeSkin::KInterfaceUid ) );
       
   138         }
       
   139     else
       
   140         {
       
   141         // Just in case it was some times obsolete but not anymore
       
   142         SetObsolete( EFalse );
       
   143         }
       
   144 
       
   145     // If error occurred during data transfer, leave here and forward the error.
       
   146     User::LeaveIfError( error );
       
   147     
       
   148     if ( data == NULL )
       
   149         {
       
   150         DLERROR((""));
       
   151         User::Leave(  KErrNotFound );
       
   152         }
       
   153 
       
   154      CleanupStack::PushL( data );
       
   155 
       
   156      // Read the data from the stream and insert it to the memeber variables
       
   157      RDesReadStream stream( *data );
       
   158      CleanupClosePushL( stream );
       
   159     
       
   160      InternalizeDataL( stream );
       
   161     
       
   162      // Closes the stream
       
   163      CleanupStack::PopAndDestroy( &stream ); 
       
   164      CleanupStack::PopAndDestroy( data );
       
   165 
       
   166     DLTRACEOUT((""));    
       
   167     }
       
   168 
       
   169 
       
   170 // MNcdNodeSkin functions
       
   171 
       
   172 const TDesC& CNcdNodeSkinProxy::SkinId() const
       
   173     {
       
   174     DLTRACEIN((""));
       
   175     // SkinId is always set to contain some data. At least it is KNullDesC.
       
   176     DLINFO(( _L("SkinID: %S"), iSkinId ));
       
   177     return *iSkinId;
       
   178     }
       
   179 
       
   180 
       
   181 TTime CNcdNodeSkinProxy::SkinTimeStamp() const
       
   182     {
       
   183     return iTimeStamp;
       
   184     }
       
   185 
       
   186 
       
   187 MNcdFileDownloadOperation* CNcdNodeSkinProxy::LoadSkinL( 
       
   188         const TDesC& aTargetFileName,
       
   189         MNcdFileDownloadOperationObserver& aObserver )
       
   190     {
       
   191     DLTRACEIN((""));
       
   192 
       
   193     CNcdFileDownloadOperationProxy* operation(   
       
   194         MetadataL().Node().OperationManager().
       
   195         CreateFileDownloadOperationL( ENcdSkinDownload, 
       
   196                                       MetadataL().Node(), 
       
   197                                       &aObserver,
       
   198                                       aTargetFileName ) );
       
   199 
       
   200     // It is enought that the observer is informed
       
   201     // when the file operation is ready. So, no need to add
       
   202     // node or this class object to be observers.
       
   203 
       
   204     // No need to increase the operation ref count here because
       
   205     // it should be initially one.
       
   206 
       
   207     DLTRACEOUT((""));    
       
   208         
       
   209     return operation;
       
   210     }
       
   211     
       
   212 
       
   213 // Other functions
       
   214 
       
   215 CNcdNodeMetadataProxy& CNcdNodeSkinProxy::MetadataL() const
       
   216     {
       
   217     DLTRACEIN((""));
       
   218 
       
   219     if( IsObsolete() )
       
   220         {
       
   221         DLERROR(("Skin is obsolete. Metadata may not exist."));
       
   222         User::Leave( KNcdErrorObsolete );
       
   223         }
       
   224      
       
   225     DLTRACEOUT((""));
       
   226     
       
   227     return iMetadata;
       
   228     }
       
   229 
       
   230 
       
   231 TBool CNcdNodeSkinProxy::IsObsolete() const
       
   232     {
       
   233     return iObsolete;
       
   234     }
       
   235 
       
   236 void CNcdNodeSkinProxy::SetObsolete( TBool aObsolete )
       
   237     {
       
   238     iObsolete = aObsolete;
       
   239     }    
       
   240         
       
   241 
       
   242 void CNcdNodeSkinProxy::InternalizeDataL( RReadStream& aStream )
       
   243     {
       
   244     DLTRACEIN((""));
       
   245 
       
   246     // Use catalogsutils.h functions to internalize
       
   247     // memebervariables according to the data received
       
   248     // from the server.
       
   249     // Make sure that the variables are set here in the same
       
   250     // order as they are externalized in the server side.
       
   251     // Small mistake here messes up everything!
       
   252 
       
   253     // First read the class id. Because, it is the first thing in the stream.
       
   254     TInt classId( aStream.ReadInt32L() );
       
   255     
       
   256     if ( classId != NcdNodeClassIds::ENcdNodeSkinClassId )
       
   257         {
       
   258         // classId is not recognized
       
   259         DLERROR(("Class id was not recognized!"));
       
   260         // For testing purposes assert here
       
   261         DASSERT( EFalse );
       
   262         
       
   263         // Otherwise leave is adequate
       
   264         User::Leave( KErrCorrupt );
       
   265         }
       
   266 
       
   267 
       
   268     // Get the skin id from the stream
       
   269     InternalizeDesL( iSkinId, aStream );
       
   270     DLINFO(( _L("SkinID: %S"), iSkinId ));
       
   271     // Get the timestamp and change the descriptor info to be TTime type
       
   272     HBufC* timeStamp( NULL );
       
   273     InternalizeDesL( timeStamp, aStream );
       
   274     if ( timeStamp != NULL && timeStamp->Length() > 0 )
       
   275         {
       
   276         CleanupStack::PushL( timeStamp );
       
   277         iTimeStamp.Parse( *timeStamp );
       
   278         CleanupStack::PopAndDestroy( timeStamp );        
       
   279         }
       
   280     else
       
   281         {
       
   282         // Because the timestamp was not given, set the time to zero value.
       
   283         
       
   284         // In case time stamp descriptor was allocated but length was zero, delete.
       
   285         delete timeStamp;
       
   286         iTimeStamp = 0;
       
   287         }
       
   288         
       
   289     DLTRACEOUT((""));
       
   290     }