contentcontrolsrv/ccsrvapi/src/ccsrvmsg.cpp
changeset 0 79c6a41cd166
child 18 bd874ee5e5e2
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2  * Copyright (c) 2008 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:  
       
    15  *
       
    16  */
       
    17 
       
    18 // System include files
       
    19 #include <s32strm.h>
       
    20 #include <s32mem.h>
       
    21 
       
    22 // User include files
       
    23 #include "ccsrvapi.h"
       
    24 
       
    25 // Local constants
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CCcSrvMsg::NewL()
       
    31 // Two-phased constructor.
       
    32 // -----------------------------------------------------------------------------
       
    33 EXPORT_C CCcSrvMsg* CCcSrvMsg::NewL()
       
    34     {
       
    35     CCcSrvMsg* self = new ( ELeave ) CCcSrvMsg();
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop( self );
       
    39     return( self ) ;
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------
       
    43 // CCcSrvMsg::ConstructL()
       
    44 // -----------------------------------------------------------------------
       
    45 //
       
    46 void CCcSrvMsg::ConstructL()
       
    47     {
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------
       
    51 // CCcSrvMsg::CCcSrvMsg()
       
    52 // -----------------------------------------------------------------------
       
    53 //
       
    54 CCcSrvMsg::CCcSrvMsg()
       
    55     {
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------
       
    59 // CCcSrvMsg::~CCcSrvMsg()
       
    60 // -----------------------------------------------------------------------
       
    61 //
       
    62 CCcSrvMsg::~CCcSrvMsg()
       
    63     {
       
    64     delete iData;
       
    65     iData = NULL;
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CCcSrvMsg::MsgId()
       
    70 // -----------------------------------------------------------------------------
       
    71 EXPORT_C RMessage2 CCcSrvMsg::Message()
       
    72     {
       
    73     return( iMessage ) ;
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CCcSrvMsg::SetMsgId()
       
    78 // -----------------------------------------------------------------------------
       
    79 EXPORT_C void CCcSrvMsg::SetMessage( RMessage2& aMessage )
       
    80     {
       
    81     iMessage = aMessage;
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CCcSrvMsg::MsgId()
       
    86 // -----------------------------------------------------------------------------
       
    87 EXPORT_C TUint32 CCcSrvMsg::MsgId()
       
    88     {
       
    89     return( iMsgId ) ;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CCcSrvMsg::SetMsgId()
       
    94 // -----------------------------------------------------------------------------
       
    95 EXPORT_C void CCcSrvMsg::SetMsgId( TUint32 aMsgId )
       
    96     {
       
    97     iMsgId = aMsgId;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CCcSrvMsg::TrId()
       
   102 // -----------------------------------------------------------------------------
       
   103 EXPORT_C TUint32 CCcSrvMsg::TrId()
       
   104     {
       
   105     return( iTrId ) ;
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CCcSrvMsg::SetTrId()
       
   110 // -----------------------------------------------------------------------------
       
   111 EXPORT_C void CCcSrvMsg::SetTrId( TUint32 aTrId )
       
   112     {
       
   113     iTrId = aTrId;
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CCcSrvMsg::Status()
       
   118 // -----------------------------------------------------------------------------
       
   119 EXPORT_C TInt CCcSrvMsg::Status()
       
   120     {
       
   121     return( iStatus ) ;
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CCcSrvMsg::SetStatus()
       
   126 // -----------------------------------------------------------------------------
       
   127 EXPORT_C void CCcSrvMsg::SetStatus( TInt aStatus )
       
   128     {
       
   129     iStatus = aStatus;
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CCcSrvMsg::Data()
       
   134 // -----------------------------------------------------------------------------
       
   135 EXPORT_C TPtrC8 CCcSrvMsg::Data()
       
   136     {
       
   137     if ( iData )
       
   138         {
       
   139         return iData->Des();
       
   140         }
       
   141     else
       
   142         {
       
   143         return KNullDesC8();
       
   144         }
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CCcSrvMsg::SetData()
       
   149 // -----------------------------------------------------------------------------
       
   150 EXPORT_C void CCcSrvMsg::SetData( const TDesC8& aData )
       
   151     {
       
   152     if ( iData )
       
   153         {
       
   154         delete iData;
       
   155         }
       
   156     iData = aData.Alloc();
       
   157     iDataSize = iData->Des().Length();
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CCcSrvMsg::DataSize()
       
   162 // -----------------------------------------------------------------------------
       
   163 EXPORT_C TInt CCcSrvMsg::DataSize()
       
   164     {
       
   165     return iDataSize;
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CCcSrvMsg::ExternalizeL()
       
   170 // -----------------------------------------------------------------------------
       
   171 EXPORT_C void CCcSrvMsg::ExternalizeL( RWriteStream& aStream )
       
   172     {
       
   173     ExternalizeHeaderL( aStream );
       
   174     if ( iData )
       
   175         {
       
   176         aStream << *iData;
       
   177         }
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CCcSrvMsg::ExternalizeHeaderL()
       
   182 // -----------------------------------------------------------------------------
       
   183 EXPORT_C void CCcSrvMsg::ExternalizeHeaderL( RWriteStream& aStream )
       
   184     {
       
   185     aStream.WriteUint32L( iMsgId );
       
   186     aStream.WriteUint32L( iTrId );
       
   187     aStream.WriteInt32L( iStatus );
       
   188     aStream.WriteInt32L( iDataSize );
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CCcSrvMsg::InternalizeL()
       
   193 // -----------------------------------------------------------------------------
       
   194 EXPORT_C void CCcSrvMsg::InternalizeL( RReadStream& aStream )
       
   195     {
       
   196     InternalizeHeaderL( aStream );
       
   197     if ( iData )
       
   198         {
       
   199         delete iData;
       
   200         iData = NULL;
       
   201         }
       
   202     if ( iDataSize )
       
   203         {
       
   204         iData = HBufC8::NewL( aStream, iDataSize );
       
   205         }
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CCcSrvMsg::InternalizeHeaderL()
       
   210 // -----------------------------------------------------------------------------
       
   211 EXPORT_C void CCcSrvMsg::InternalizeHeaderL( RReadStream& aStream )
       
   212     {
       
   213     iMsgId = aStream.ReadUint32L();
       
   214     iTrId = aStream.ReadUint32L();
       
   215     iStatus = aStream.ReadInt32L();
       
   216     iDataSize = aStream.ReadInt32L();
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CCcSrvMsg::MarshalL()
       
   221 // -----------------------------------------------------------------------------
       
   222 EXPORT_C HBufC8* CCcSrvMsg::MarshalL()
       
   223     {
       
   224     // Externalize message
       
   225     CBufFlat* reqBuf = CBufFlat::NewL( KCcHeaderSize + iDataSize );
       
   226     CleanupStack::PushL( reqBuf );
       
   227     RBufWriteStream reqStream( *reqBuf );
       
   228     CleanupClosePushL( reqStream );
       
   229     ExternalizeL( reqStream );
       
   230     CleanupStack::PopAndDestroy( &reqStream );
       
   231     
       
   232     // Append externalized messgae to a descriptor
       
   233     HBufC8* msgDesc = HBufC8::NewL( reqBuf->Size() );
       
   234     TPtr8 msgPtr( NULL, 0 ); 
       
   235     msgPtr.Set( msgDesc->Des() );
       
   236     reqBuf->Read( 0, msgPtr, reqBuf->Size() );
       
   237     CleanupStack::PopAndDestroy( reqBuf );
       
   238     
       
   239     return msgDesc;
       
   240     }
       
   241 
       
   242 // End of file