ncdengine/provider/client/src/ncdnodescreenshotproxy.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 CNcdNodeScreenshotProxy class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdnodescreenshotproxy.h"
       
    20 #include "ncdnodemetadataproxy.h"
       
    21 #include "ncdnodeproxy.h"
       
    22 #include "ncddownloadoperationproxy.h"
       
    23 #include "ncdoperationmanagerproxy.h"
       
    24 #include "ncdoperationdatatypes.h"
       
    25 #include "catalogsclientserver.h"
       
    26 #include "ncdnodeidentifier.h"
       
    27 #include "ncdnodefunctionids.h"
       
    28 #include "ncdnodeclassids.h"
       
    29 #include "ncdpanics.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 CNcdNodeScreenshotProxy::CNcdNodeScreenshotProxy(
       
    39     MCatalogsClientServer& aSession,
       
    40     TInt aHandle,
       
    41     CNcdNodeMetadataProxy& aMetadata )
       
    42     : CNcdInterfaceBaseProxy( aSession, aHandle, &aMetadata ),
       
    43       iMetadata( aMetadata )
       
    44     {
       
    45     }
       
    46 
       
    47 
       
    48 void CNcdNodeScreenshotProxy::ConstructL()
       
    49     {
       
    50     // Register the interface
       
    51     MNcdNodeScreenshot* interface( this );
       
    52     AddInterfaceL( 
       
    53         CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeScreenshot::KInterfaceUid ) );
       
    54 
       
    55     // Let this leave if the internalization fails.    
       
    56     InternalizeL();
       
    57     }
       
    58 
       
    59 
       
    60 CNcdNodeScreenshotProxy* CNcdNodeScreenshotProxy::NewL(
       
    61     MCatalogsClientServer& aSession,
       
    62     TInt aHandle,
       
    63     CNcdNodeMetadataProxy& aMetadata )
       
    64     {
       
    65     CNcdNodeScreenshotProxy* self = 
       
    66         CNcdNodeScreenshotProxy::NewLC( aSession, aHandle, aMetadata );
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 CNcdNodeScreenshotProxy* CNcdNodeScreenshotProxy::NewLC(
       
    72     MCatalogsClientServer& aSession,
       
    73     TInt aHandle,
       
    74     CNcdNodeMetadataProxy& aMetadata )
       
    75     {
       
    76     CNcdNodeScreenshotProxy* self = 
       
    77         new( ELeave ) CNcdNodeScreenshotProxy( aSession, aHandle, aMetadata );
       
    78     // Using PushL because the object does not have any references yet
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     return self;
       
    82     }
       
    83 
       
    84 
       
    85 CNcdNodeScreenshotProxy::~CNcdNodeScreenshotProxy()
       
    86     {
       
    87     // Remove interfaces implemented by this class from the interface list.
       
    88     // So, the interface list is up to date when this class object is deleted.
       
    89     RemoveInterface( MNcdNodeScreenshot::KInterfaceUid );
       
    90     
       
    91     // Delete member variables here.
       
    92     // Do not delete node and operation manager because
       
    93     // this object does not own them.
       
    94 
       
    95     iScreenshotMimeType.ResetAndDestroy();
       
    96     }
       
    97 
       
    98 
       
    99 CNcdNodeMetadataProxy& CNcdNodeScreenshotProxy::MetadataL() const
       
   100     {
       
   101     DLTRACEIN((""));
       
   102 
       
   103     if( IsObsolete() )
       
   104         {
       
   105         DLERROR(("Screenshot is obsolete. Metadata may not exist."));
       
   106         User::Leave( KNcdErrorObsolete );
       
   107         }
       
   108     
       
   109     DLTRACEOUT((""));
       
   110     
       
   111     return iMetadata;
       
   112     }
       
   113 
       
   114 
       
   115 void CNcdNodeScreenshotProxy::InternalizeL()
       
   116     {
       
   117     DLTRACEIN((""));
       
   118 
       
   119     HBufC8* data( NULL );
       
   120         
       
   121     // Because we do not know the exact size of the data, use
       
   122     // the alloc method, which creates the buffer of the right size
       
   123     // and sets the pointer to point to the created buffer.
       
   124     // Get all the data that is necessary to internalize this object
       
   125     // from the server side.
       
   126     TInt error(
       
   127         ClientServerSession().
       
   128         SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize,
       
   129                        KNullDesC8,
       
   130                        data,
       
   131                        Handle(),
       
   132                        0 ) );
       
   133 
       
   134     if ( error == KNcdErrorObsolete )
       
   135         {
       
   136         DLINFO(("Screenshot was obsolete"));
       
   137         SetObsolete( ETrue );
       
   138         // Remove interfaces implemented by this class from the top parent interface list.
       
   139         // So, the interface list is up to date after this object is removed
       
   140         // from its top parent.
       
   141         RemoveInterface( MNcdNodeScreenshot::KInterfaceUid );
       
   142         // Remove from the parent
       
   143         RemoveFromParent();
       
   144         // Now update the interface for this object just in case somebody needs it.
       
   145         // Register the interface
       
   146         MNcdNodeScreenshot* interface( this );
       
   147         AddInterfaceL( 
       
   148             CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeScreenshot::KInterfaceUid ) );
       
   149         }
       
   150     else
       
   151         {
       
   152         // Just in case it was some times obsolete but not anymore
       
   153         SetObsolete( EFalse );
       
   154         }
       
   155         
       
   156     // If error occurred during data transfer, leave here and forward the error.
       
   157     User::LeaveIfError( error );
       
   158 
       
   159     if ( data == NULL )
       
   160         {
       
   161         DLERROR((""));
       
   162         User::Leave( KErrNotFound );
       
   163         }
       
   164 
       
   165     CleanupStack::PushL( data );
       
   166 
       
   167     // Read the data from the stream and insert it to the memeber variables
       
   168     RDesReadStream stream( *data );
       
   169     CleanupClosePushL( stream );
       
   170 
       
   171     InternalizeDataL( stream );
       
   172 
       
   173     // Closes the stream
       
   174     CleanupStack::PopAndDestroy( &stream ); 
       
   175     CleanupStack::PopAndDestroy( data );
       
   176 
       
   177     DLTRACEOUT((""));    
       
   178     }
       
   179 
       
   180 
       
   181 // MNcdNodeScreenshot functions
       
   182 
       
   183 TInt CNcdNodeScreenshotProxy::ScreenshotCount() const
       
   184     {
       
   185     return iScreenshotCount;
       
   186     }
       
   187 
       
   188 const TDesC& CNcdNodeScreenshotProxy::ScreenshotMimeType( TInt aIndex ) const
       
   189     {
       
   190     NCD_ASSERT_ALWAYS( aIndex >= 0 && aIndex < ScreenshotCount(),
       
   191         ENcdPanicIndexOutOfRange );
       
   192     return *iScreenshotMimeType[aIndex];
       
   193     }
       
   194 
       
   195 MNcdDownloadOperation* CNcdNodeScreenshotProxy::LoadScreenshotL(
       
   196     TInt aIndex,
       
   197     MNcdDownloadOperationObserver* aObserver )
       
   198     {
       
   199     DLTRACEIN((""));
       
   200     NCD_ASSERT_ALWAYS( aIndex >= 0 && aIndex < ScreenshotCount(),
       
   201         ENcdPanicIndexOutOfRange );
       
   202 
       
   203     CNcdDownloadOperationProxy* download =
       
   204         MetadataL().Node().OperationManager().
       
   205         CreateDownloadOperationL(
       
   206             ENcdScreenshotDownload,
       
   207             MetadataL().Node(),
       
   208             KNullDesC,
       
   209             aObserver,
       
   210             aIndex );
       
   211 
       
   212     DLTRACEOUT((""));
       
   213 
       
   214     return download;
       
   215     }
       
   216 
       
   217 HBufC8* CNcdNodeScreenshotProxy::ScreenshotDataL( TInt aIndex ) const
       
   218     {
       
   219     NCD_ASSERT_ALWAYS( aIndex >= 0 && aIndex < ScreenshotCount(),
       
   220         ENcdPanicIndexOutOfRange );
       
   221 
       
   222     HBufC8* data( NULL );
       
   223 
       
   224     HBufC8* index = IntToDes8LC( aIndex );
       
   225 
       
   226     // Because we do not know the exact size of the data, use
       
   227     // the alloc method, which creates the buffer of the right size
       
   228     // and sets the pointer to point to the created buffer.
       
   229     User::LeaveIfError(
       
   230         ClientServerSession().
       
   231         SendSyncAlloc( NcdNodeFunctionIds::ENcdScreenshotData,
       
   232                        *index,
       
   233                        data,
       
   234                        Handle(),
       
   235                        0 ) );
       
   236 
       
   237     CleanupStack::PopAndDestroy( index );
       
   238 
       
   239     if ( data && data->Length() == 0 )
       
   240         {
       
   241         // If data does not contain any data, return NULL.
       
   242         delete data;
       
   243         return NULL;
       
   244         }
       
   245 
       
   246     return data;
       
   247     }
       
   248 
       
   249 
       
   250 // Other functions
       
   251 
       
   252 
       
   253 TBool CNcdNodeScreenshotProxy::IsObsolete() const
       
   254     {
       
   255     return iObsolete;
       
   256     }
       
   257 
       
   258 void CNcdNodeScreenshotProxy::SetObsolete( TBool aObsolete )
       
   259     {
       
   260     iObsolete = aObsolete;
       
   261     }    
       
   262     
       
   263     
       
   264 void CNcdNodeScreenshotProxy::InternalizeDataL( RReadStream& aStream )
       
   265     {
       
   266     DLTRACEIN((""));
       
   267 
       
   268     // Use catalogsutils.h functions to internalize
       
   269     // memebervariables according to the data received
       
   270     // from the server.
       
   271     // Make sure that the variables are set here in the same
       
   272     // order as they are externalized in the server side.
       
   273     // Small mistake here messes up everything!
       
   274 
       
   275     // First read the class id. Because, it is the first thing in the stream.
       
   276     TInt classId( aStream.ReadInt32L() );
       
   277     
       
   278     if ( classId != NcdNodeClassIds::ENcdNodeScreenshotClassId )
       
   279         {
       
   280         // classId is not recognized
       
   281         DLERROR(("Class id was not recognized!"));
       
   282         // For testing purposes assert here
       
   283         DASSERT( EFalse );
       
   284         
       
   285         // Otherwise leave is adequate
       
   286         User::Leave( KErrCorrupt );
       
   287         }
       
   288 
       
   289 
       
   290     iScreenshotCount = aStream.ReadInt32L();
       
   291 
       
   292     iScreenshotMimeType.ResetAndDestroy();
       
   293 
       
   294     // Set new values if screenshots exist.
       
   295     for ( TInt i = 0; i < iScreenshotCount; i++ )
       
   296         {
       
   297         HBufC* mimeType = NULL;
       
   298         InternalizeDesL( mimeType, aStream );
       
   299         CleanupStack::PushL( mimeType );
       
   300         iScreenshotMimeType.AppendL( mimeType );
       
   301         CleanupStack::Pop( mimeType );
       
   302         }
       
   303 
       
   304     DLTRACEOUT((""));
       
   305     }