ncdengine/provider/client/src/ncdnodeiconproxy.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 CNcdNodeIconProxy class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdnodeiconproxy.h"
       
    20 #include "ncdnodeproxy.h"
       
    21 #include "ncdnodemetadataproxy.h"
       
    22 #include "ncdoperationimpl.h"
       
    23 #include "ncddownloadoperationproxy.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 CNcdNodeIconProxy::CNcdNodeIconProxy(
       
    39     MCatalogsClientServer& aSession,
       
    40     TInt aHandle,
       
    41     CNcdNodeMetadataProxy& aMetadata )
       
    42 : CNcdInterfaceBaseProxy( aSession, aHandle, &aMetadata ),
       
    43   iMetadata( aMetadata )
       
    44     {
       
    45     }
       
    46 
       
    47 
       
    48 void CNcdNodeIconProxy::ConstructL()
       
    49     {
       
    50     // Register the interface
       
    51     MNcdNodeIcon* icon( this );
       
    52     AddInterfaceL( 
       
    53         CCatalogsInterfaceIdentifier::NewL( icon, this, MNcdNodeIcon::KInterfaceUid ) );
       
    54     // Let this leave if internalization fails.
       
    55     InternalizeL();
       
    56     }
       
    57 
       
    58 
       
    59 CNcdNodeIconProxy* CNcdNodeIconProxy::NewL(
       
    60     MCatalogsClientServer& aSession,
       
    61     TInt aHandle,
       
    62     CNcdNodeMetadataProxy& aMetadata )
       
    63     {
       
    64     CNcdNodeIconProxy* self = 
       
    65         CNcdNodeIconProxy::NewLC( aSession, aHandle, aMetadata );
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69 
       
    70 CNcdNodeIconProxy* CNcdNodeIconProxy::NewLC(
       
    71     MCatalogsClientServer& aSession,
       
    72     TInt aHandle,
       
    73     CNcdNodeMetadataProxy& aMetadata )
       
    74     {
       
    75     CNcdNodeIconProxy* self = 
       
    76         new( ELeave ) CNcdNodeIconProxy( aSession, aHandle, aMetadata );
       
    77     // Using PushL because the object does not have any references yet
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL();
       
    80     return self;
       
    81     }
       
    82 
       
    83 
       
    84 CNcdNodeIconProxy::~CNcdNodeIconProxy()
       
    85     {
       
    86     // Remove interfaces implemented by this class from the interface list.
       
    87     // So, the interface list is up to date when this class object is deleted.
       
    88     RemoveInterface( MNcdNodeIcon::KInterfaceUid );
       
    89 
       
    90     delete iIconId;
       
    91     iIconId = NULL;
       
    92     }
       
    93 
       
    94 
       
    95 CNcdNodeMetadataProxy& CNcdNodeIconProxy::MetadataL() const
       
    96     {
       
    97     DLTRACEIN((""));
       
    98 
       
    99     if( IsObsolete() )
       
   100         {
       
   101         DLERROR(("Icon is obsolete. Metadata may not exist."));
       
   102         User::Leave( KNcdErrorObsolete );
       
   103         }        
       
   104 
       
   105     DLTRACEOUT((""));
       
   106     
       
   107     return iMetadata;
       
   108     }
       
   109 
       
   110 
       
   111 void CNcdNodeIconProxy::InternalizeL()
       
   112     {
       
   113     DLTRACEIN((""));
       
   114 
       
   115     HBufC8* data( NULL );
       
   116         
       
   117     // Because we do not know the exact size of the data, use
       
   118     // the alloc method, which creates the buffer of the right size
       
   119     // and sets the pointer to point to the created buffer.
       
   120     TInt error(
       
   121         ClientServerSession().
       
   122         SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize,
       
   123                        KNullDesC8,
       
   124                        data,
       
   125                        Handle(),
       
   126                        0 ) );
       
   127 
       
   128     if ( error == KNcdErrorObsolete )
       
   129         {
       
   130         DLINFO(("Icon was obsolete"));
       
   131         SetObsolete( ETrue );
       
   132         // Remove interfaces implemented by this class from the top parent interface list.
       
   133         // So, the interface list is up to date after this object is removed
       
   134         // from its top parent.
       
   135         RemoveInterface( MNcdNodeIcon::KInterfaceUid );
       
   136         // Remove from the parent
       
   137         RemoveFromParent();
       
   138         // Now update the interface for this object just in case somebody needs it.
       
   139         // Register the interface
       
   140         MNcdNodeIcon* interface( this );
       
   141         AddInterfaceL( 
       
   142             CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeIcon::KInterfaceUid ) );
       
   143         }
       
   144     else
       
   145         {
       
   146         // Just in case it was some times obsolete but not anymore
       
   147         SetObsolete( EFalse );
       
   148         }
       
   149 
       
   150     // If error occurred during data transfer, leave here and forward the error.
       
   151     User::LeaveIfError( error );
       
   152     
       
   153     if ( data == NULL )
       
   154         {
       
   155         DLERROR((""));
       
   156         User::Leave( KErrNotFound );
       
   157         }
       
   158 
       
   159     CleanupStack::PushL( data );
       
   160 
       
   161     // Read the data from the stream and insert it to the member variables.
       
   162     RDesReadStream stream( *data );
       
   163     CleanupClosePushL( stream );
       
   164 
       
   165     InternalizeDataL( stream );
       
   166 
       
   167     // Closes the stream
       
   168     CleanupStack::PopAndDestroy( &stream ); 
       
   169     CleanupStack::PopAndDestroy( data );
       
   170 
       
   171     DLTRACEOUT((""));    
       
   172     }
       
   173 
       
   174 
       
   175 // MNcdNodeIcon functions
       
   176     
       
   177 const TDesC& CNcdNodeIconProxy::IconId() const
       
   178     {
       
   179     DLTRACEIN(("iIconId=%X",iIconId));
       
   180     if ( iIconId ) 
       
   181         {        
       
   182         return *iIconId;        
       
   183         }
       
   184     return KNullDesC();
       
   185     }
       
   186 
       
   187 const TDesC& CNcdNodeIconProxy::IconMimeType() const
       
   188     {
       
   189     DLTRACEIN((""));
       
   190     // NOTE: Currently protocol does not offer mime type!
       
   191     return KNullDesC;
       
   192     }
       
   193 
       
   194 MNcdDownloadOperation* CNcdNodeIconProxy::LoadIconL(
       
   195     MNcdDownloadOperationObserver* aObserver )
       
   196     {
       
   197     DLTRACEIN((""));
       
   198 
       
   199     CNcdDownloadOperationProxy* download =
       
   200         MetadataL().Node().OperationManager().
       
   201         CreateDownloadOperationL(
       
   202             ENcdIconDownload,
       
   203             MetadataL().Node(),
       
   204             *iIconId,
       
   205             aObserver );
       
   206             
       
   207     DLTRACEOUT((""));
       
   208     
       
   209     return download;
       
   210     }
       
   211 
       
   212 HBufC8* CNcdNodeIconProxy::IconDataL()
       
   213     {
       
   214     HBufC8* iconData( NULL );
       
   215         
       
   216     // Because we do not know the exact size of the data id, use
       
   217     // the alloc method, which creates the buffer of the right size
       
   218     // and sets the pointer to point to the created buffer.
       
   219     User::LeaveIfError(
       
   220             ClientServerSession().
       
   221                 SendSyncAlloc( NcdNodeFunctionIds::ENcdIconData,
       
   222                                KNullDesC8,
       
   223                                iconData,
       
   224                                Handle(),
       
   225                                0 ) );
       
   226     
       
   227     if ( iconData && iconData->Length() == 0 )
       
   228         {
       
   229         // If icon data does not contain any data, return NULL.
       
   230         delete iconData;
       
   231         return NULL;
       
   232         }
       
   233     DLTRACE(( _L("Icon data length: %d for id: %S"), iconData->Length(),
       
   234         &IconId() ));
       
   235     return iconData;
       
   236     }
       
   237 
       
   238 
       
   239 // Other functions
       
   240 
       
   241 TBool CNcdNodeIconProxy::IsObsolete() const
       
   242     {
       
   243     return iObsolete;
       
   244     }
       
   245 
       
   246 void CNcdNodeIconProxy::SetObsolete( TBool aObsolete )
       
   247     {
       
   248     iObsolete = aObsolete;
       
   249     }
       
   250 
       
   251 
       
   252 void CNcdNodeIconProxy::InternalizeDataL( RReadStream& aStream )
       
   253     {
       
   254     DLTRACEIN((""));
       
   255 
       
   256     // First read the class id. Because, it is the first thing in the stream.
       
   257     TInt classId( aStream.ReadInt32L() );
       
   258     
       
   259     if ( classId != NcdNodeClassIds::ENcdNodeIconClassId )
       
   260         {
       
   261         // classId is not recognized
       
   262         DLERROR(("Class id was not recognized!"));
       
   263         // For testing purposes assert here
       
   264         DASSERT( EFalse );
       
   265         
       
   266         // Otherwise leave is adequate
       
   267         User::Leave( KErrCorrupt );
       
   268         }
       
   269 
       
   270 
       
   271     // Get the icon id from the stream.
       
   272     InternalizeDesL( iIconId, aStream );
       
   273     DLINFO(( _L("iIconId=%S"),iIconId));
       
   274 
       
   275     DLTRACEOUT((""));
       
   276     }