ncdengine/provider/server/src/ncdnodeskinimpl.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:   Implements CNcdNodeSkin class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdnodeskinimpl.h"
       
    20 #include "catalogssession.h"
       
    21 #include "catalogsbasemessage.h"
       
    22 #include "ncdnodefunctionids.h"
       
    23 #include "ncdnodeclassids.h"
       
    24 #include "ncd_pp_skin.h"
       
    25 #include "catalogsconstants.h"
       
    26 #include "ncd_pp_dataentity.h"
       
    27 #include "ncd_cp_query.h"
       
    28 #include "catalogsutils.h"
       
    29 #include "catalogsdebug.h"
       
    30 #include "ncderrors.h"
       
    31 
       
    32 
       
    33 CNcdNodeSkin* CNcdNodeSkin::NewL()
       
    34     {
       
    35     CNcdNodeSkin* self =   
       
    36         CNcdNodeSkin::NewLC();
       
    37     CleanupStack::Pop( self );
       
    38     return self;        
       
    39     }
       
    40 
       
    41 CNcdNodeSkin* CNcdNodeSkin::NewLC()
       
    42     {
       
    43     CNcdNodeSkin* self = 
       
    44         new( ELeave ) CNcdNodeSkin( 
       
    45             NcdNodeClassIds::ENcdNodeSkinClassId );
       
    46     CleanupClosePushL( *self );
       
    47     self->ConstructL();
       
    48     return self;        
       
    49     }
       
    50 
       
    51 
       
    52 CNcdNodeSkin::~CNcdNodeSkin()
       
    53     {
       
    54     DLTRACEIN((""));
       
    55 
       
    56     // Delete member variables here
       
    57 
       
    58     delete iId;
       
    59     iId = NULL;
       
    60 
       
    61     delete iTimeStamp;
       
    62     iTimeStamp = NULL;
       
    63 
       
    64     delete iUri;
       
    65     iUri = NULL;
       
    66 
       
    67     DLTRACEOUT((""));
       
    68     }        
       
    69 
       
    70 NcdNodeClassIds::TNcdNodeClassId CNcdNodeSkin::ClassId() const
       
    71     {
       
    72     return iClassId;
       
    73     }
       
    74 
       
    75 
       
    76 // Internalization from the protocol
       
    77 
       
    78 void CNcdNodeSkin::InternalizeL( MNcdPreminetProtocolDataEntity& aData )
       
    79     {
       
    80     DLTRACEIN((""));
       
    81 
       
    82     // First create the new values
       
    83 
       
    84     HBufC* tmpId = aData.Skin()->Id().AllocLC();
       
    85     DLTRACE((_L("id: %S"), tmpId));
       
    86 
       
    87     HBufC* tmpTimeStamp = aData.Skin()->Timestamp().AllocLC();
       
    88     DLTRACE((_L("timestamp: %S"), tmpTimeStamp));
       
    89 
       
    90     HBufC* tmpUri = aData.Skin()->Uri().AllocLC();
       
    91     DLTRACE((_L("uri: %S"), tmpUri));
       
    92 
       
    93 
       
    94     // Now, that we are sure we have correctly created new values and the
       
    95     // code cannot leave here, set the tmp values to the member variables.
       
    96 
       
    97     delete iUri;
       
    98     iUri = tmpUri;
       
    99     CleanupStack::Pop( tmpUri );
       
   100 
       
   101     delete iTimeStamp;
       
   102     iTimeStamp = tmpTimeStamp;
       
   103     CleanupStack::Pop( tmpTimeStamp );
       
   104 
       
   105     delete iId;
       
   106     iId = tmpId;
       
   107     CleanupStack::Pop( tmpId );
       
   108 
       
   109     DLTRACEOUT(( _L("SkinId: %S"), iId ));
       
   110     }
       
   111 
       
   112 
       
   113 // Internalization from and externalization to the database
       
   114     
       
   115 void CNcdNodeSkin::ExternalizeL( RWriteStream& aStream )
       
   116     {
       
   117     DLTRACEIN((""));
       
   118 
       
   119     // Set all the membervariable values to the stream. So,
       
   120     // that the stream may be used later to create a new
       
   121     // object.
       
   122 
       
   123     // First insert data that the creator of this class object will use to
       
   124     // create this class object. Class id informs what class object
       
   125     // will be created.
       
   126     
       
   127     aStream.WriteInt32L( iClassId );
       
   128     
       
   129     
       
   130     // Write the data that will be used when internalize function
       
   131     // is called. catalogsutils.h contains good internalize and
       
   132     // externalize functions.
       
   133     // Make sure that this matches to the order that is used 
       
   134     // when this stream is internalized.
       
   135 
       
   136     ExternalizeDesL( *iId, aStream );
       
   137     ExternalizeDesL( *iTimeStamp, aStream );
       
   138     ExternalizeDesL( *iUri, aStream );
       
   139 
       
   140     DLTRACEOUT((""));
       
   141     }
       
   142 
       
   143 
       
   144 void CNcdNodeSkin::InternalizeL( RReadStream& aStream )
       
   145     {
       
   146     DLTRACEIN((""));
       
   147 
       
   148     // Read the class id first because it is set to the stream in internalize
       
   149     // function and it is not read from the stream anywhere else.
       
   150     TInt classId( aStream.ReadInt32L() );
       
   151     if ( classId != ClassId() )
       
   152         {
       
   153         DLTRACE(("Wrong class id"));
       
   154         DASSERT( EFalse );
       
   155         // Leave because the stream does not match this class object
       
   156         User::Leave( KErrCorrupt );
       
   157         }
       
   158     
       
   159     InternalizeDesL( iId, aStream );
       
   160     InternalizeDesL( iTimeStamp, aStream );
       
   161     InternalizeDesL( iUri, aStream );
       
   162 
       
   163     DLTRACEOUT(( _L("SkinId: %S"), iId ));
       
   164     }
       
   165 
       
   166 
       
   167 
       
   168 void CNcdNodeSkin::ReceiveMessage( MCatalogsBaseMessage* aMessage,
       
   169                                    TInt aFunctionNumber )
       
   170     {
       
   171     DLTRACEIN((""));    
       
   172 
       
   173     DASSERT( aMessage );
       
   174     
       
   175     // Now, we can be sure that rest of the time iMessage exists.
       
   176     // This member variable is set for the CounterPartLost function.
       
   177     iMessage = aMessage;
       
   178     
       
   179     TInt trapError( KErrNone );
       
   180     
       
   181     // Check which function is called by the proxy side object.
       
   182     // Function number are located in ncdnodefunctinoids.h file.
       
   183     switch( aFunctionNumber )
       
   184         {
       
   185         case NcdNodeFunctionIds::ENcdInternalize:
       
   186             // Internalize the proxy side according to the data
       
   187             // of this object.
       
   188             TRAP( trapError, InternalizeRequestL( *aMessage ) );
       
   189             break;
       
   190 
       
   191         case NcdNodeFunctionIds::ENcdRelease:
       
   192             // The proxy does not want to use this object anymore.
       
   193             // So, release the handle from the session.
       
   194             ReleaseRequest( *aMessage );
       
   195             break;
       
   196                     
       
   197         default:
       
   198             DLERROR(("Unidentified function request"));
       
   199             DASSERT( EFalse );
       
   200             break;
       
   201         }
       
   202 
       
   203     if ( trapError != KErrNone )
       
   204         {
       
   205         // Because something went wrong, the complete has not been
       
   206         // yet called for the message.
       
   207         // So, inform the client about the error if the
       
   208         // message is still available.
       
   209         aMessage->CompleteAndRelease( trapError );
       
   210         }
       
   211 
       
   212     // Because the message should not be used after this, set it NULL.
       
   213     // So, CounterPartLost function will know that no messages are
       
   214     // waiting the response at the moment.
       
   215     iMessage = NULL;        
       
   216     
       
   217     DLTRACEOUT((""));
       
   218     }
       
   219 
       
   220 void CNcdNodeSkin::CounterPartLost( const MCatalogsSession& aSession )
       
   221     {
       
   222     // This function may be called whenever -- when the message is waiting
       
   223     // response or when the message does not exist.
       
   224     // iMessage may be NULL here, because in the end of the
       
   225     // ReceiveMessage it is set to NULL. The life time of the message
       
   226     // ends shortly after CompleteAndRelease is called.
       
   227     if ( iMessage != NULL )
       
   228         {
       
   229         iMessage->CounterPartLost( aSession );
       
   230         }
       
   231     }
       
   232                 
       
   233 const TDesC& CNcdNodeSkin::SkinId() const
       
   234     {
       
   235     DASSERT( iId );
       
   236     return *iId;
       
   237     }
       
   238 
       
   239 const TDesC& CNcdNodeSkin::TimeStamp() const
       
   240     {
       
   241     DASSERT( iTimeStamp );
       
   242     return *iTimeStamp;
       
   243     }
       
   244 
       
   245 void CNcdNodeSkin::SetTimeStampL( const TDesC& aTimeStamp )
       
   246     {
       
   247     AssignDesL( iTimeStamp, aTimeStamp );
       
   248     }
       
   249 
       
   250 const TDesC& CNcdNodeSkin::Uri() const
       
   251     {
       
   252     DASSERT( iUri );
       
   253     return *iUri;
       
   254     }
       
   255 
       
   256 
       
   257 CNcdNodeSkin::CNcdNodeSkin( NcdNodeClassIds::TNcdNodeClassId aClassId )
       
   258 : CNcdCommunicable(),
       
   259   iClassId( aClassId )
       
   260     {
       
   261     }
       
   262 
       
   263 void CNcdNodeSkin::ConstructL()
       
   264     {
       
   265     iId = KNullDesC().AllocL();
       
   266     iTimeStamp = KNullDesC().AllocL();
       
   267     iUri = KNullDesC().AllocL();
       
   268     }
       
   269 
       
   270 
       
   271 
       
   272 void CNcdNodeSkin::InternalizeRequestL( MCatalogsBaseMessage& aMessage ) const
       
   273     {
       
   274     DLTRACEIN((""));
       
   275     
       
   276     CBufBase* buf = CBufFlat::NewL( KBufExpandSize );
       
   277     CleanupStack::PushL( buf );
       
   278     
       
   279     RBufWriteStream stream( *buf );
       
   280     CleanupClosePushL( stream );
       
   281 
       
   282 
       
   283     // Include all the necessary data to the stream.
       
   284     ExternalizeDataForRequestL( stream );     
       
   285     
       
   286     
       
   287     // Commits data to the stream when closing.
       
   288     CleanupStack::PopAndDestroy( &stream );
       
   289 
       
   290 
       
   291     // If this leaves, ReceiveMessage will complete the message.
       
   292     // NOTE: that here we expect that the buffer contains at least
       
   293     // some data. So, make sure that ExternalizeDataForRequestL inserts
       
   294     // something to the buffer.
       
   295     aMessage.CompleteAndReleaseL( buf->Ptr( 0 ), KErrNone );        
       
   296         
       
   297     
       
   298     DLTRACE(("Deleting the buf"));
       
   299     CleanupStack::PopAndDestroy( buf );
       
   300         
       
   301     DLTRACEOUT((""));
       
   302     }
       
   303     
       
   304 
       
   305 void CNcdNodeSkin::ExternalizeDataForRequestL( RWriteStream& aStream ) const
       
   306     {
       
   307     DLTRACEIN((""));
       
   308 
       
   309     if ( IsObsolete() )
       
   310         {
       
   311         DLINFO(("Set as obsolete. This means that server has removed the object."));
       
   312         User::Leave( KNcdErrorObsolete );
       
   313         }
       
   314         
       
   315     DLINFO(( _L("SkinID: %S"), iId ));
       
   316     // Skin existed. So, insert info that meta data was found.
       
   317     aStream.WriteInt32L( ClassId() );
       
   318 
       
   319     // Add additional content to the stream.
       
   320     // Make sure that this matches to the order that is used in the proxy
       
   321     // side when this stream is internalized.
       
   322     // NOTE: Be careful with the 8- and 16-bit descriptors. Remember to check
       
   323     // if the proxy wants the data in 16 or 8 bits?    
       
   324 
       
   325     ExternalizeDesL( SkinId(), aStream );
       
   326     ExternalizeDesL( TimeStamp(), aStream );
       
   327         
       
   328     DLTRACEOUT((""));
       
   329     }
       
   330 
       
   331 void CNcdNodeSkin::ReleaseRequest( MCatalogsBaseMessage& aMessage ) const
       
   332     {
       
   333     DLTRACEIN((""));
       
   334 
       
   335     // Decrease the reference count for this object.
       
   336     // When the reference count reaches zero, this object will be destroyed
       
   337     // and removed from the session.
       
   338     MCatalogsSession& requestSession( aMessage.Session() );
       
   339     TInt handle( aMessage.Handle() );
       
   340 
       
   341     // Send complete information back to proxy.
       
   342     aMessage.CompleteAndRelease( KErrNone );
       
   343         
       
   344     // Remove this object from the session.
       
   345     requestSession.RemoveObject( handle );
       
   346         
       
   347     DLTRACEOUT((""));
       
   348     }
       
   349 
       
   350