multimediacommsengine/mmcesrv/mmceserver/inc/mcemessagedispatcher.inl
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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 
       
    19 
       
    20 
       
    21 // -----------------------------------------------------------------------------
       
    22 // TMceMessageDispatcher::TMceMessageDispatcher
       
    23 // -----------------------------------------------------------------------------
       
    24 //
       
    25 template <class T>
       
    26 inline TMceMessageDispatcher<T>::TMceMessageDispatcher( T& aService, CMceCsServerITC& aItc )
       
    27    : iService( aService ),
       
    28      iItc( aItc )
       
    29     {
       
    30     }
       
    31 
       
    32 
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // TMceMessageDispatcher::DoServiceL
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 template <class T>
       
    39 inline void TMceMessageDispatcher<T>::DispatchL( TMceIds& aIds, 
       
    40                                                  TMceItcFunctions aFunction, 
       
    41 								                 const RMessage2& aMessage )
       
    42 
       
    43     {
       
    44 
       
    45     MCESRV_DEBUG("TMceMessageDispatcher::DispatchL, Entry");
       
    46     MCESRV_DEBUG_IDS("IDS", aIds );
       
    47     
       
    48     HBufC8* encodedMessage = NULL;
       
    49     HBufC8* content = NULL;
       
    50     CMceMsgBase* message = NULL;
       
    51     HBufC8* returnMessage = NULL;
       
    52     
       
    53     aIds.iItcContext = &aMessage;
       
    54     
       
    55     if ( aIds.iMsgType == EMceItcMsgTypeWriteString ||
       
    56          aIds.iMsgType == EMceItcMsgTypeReadString )
       
    57         {
       
    58         MCESRV_DEBUG("reading message from client");
       
    59 	    encodedMessage = ITC().ReadLC( aMessage, EMceItcArgContext );
       
    60 	    encodedMessage = !encodedMessage ? 
       
    61 	        KNullDesC8().AllocLC() : encodedMessage;
       
    62         
       
    63         if ( aIds.iMsgType == EMceItcMsgTypeReadString )
       
    64             {
       
    65             TPtr8 buffer = encodedMessage->Des();
       
    66             iService.DoServiceL( aIds, aFunction, buffer );
       
    67             ITC().WriteL( aMessage, 
       
    68                           buffer, 
       
    69                           EMceItcArgContext );
       
    70             }
       
    71         else
       
    72             {
       
    73             iService.DoServiceL( aIds, aFunction, *encodedMessage );
       
    74             }
       
    75         CleanupStack::PopAndDestroy( encodedMessage );
       
    76         }
       
    77     else if ( aIds.iMsgType != KMceNotAssigned )
       
    78 	    {
       
    79         MCESRV_DEBUG("reading message from client");
       
    80 	    encodedMessage = ITC().ReadLC( aMessage, EMceItcArgContext );
       
    81 	    encodedMessage = !encodedMessage ? 
       
    82 	        KNullDesC8().AllocLC() : encodedMessage;
       
    83 	    content = ITC().ReadLC( aMessage, EMceItcArgMessageContent );
       
    84         MCESRV_DEBUG_DVALUE("content size", content ? content->Length() : 0 );
       
    85 	    CleanupStack::Pop( content );
       
    86 	    iService.StoreClientContent( content );
       
    87         message = DecodeL( static_cast<TMceItcDataType>( aIds.iMsgType ), 
       
    88                            *encodedMessage );
       
    89         MCESRV_DEBUG("calling ServiceL with message"); 
       
    90         CleanupStack::PushL( message  );
       
    91         message->PushL();
       
    92         iService.DoServiceL( aIds, aFunction, *message );
       
    93         message->Pop();
       
    94         CleanupStack::PopAndDestroy( message );
       
    95         CleanupStack::PopAndDestroy( encodedMessage );
       
    96 	    }
       
    97     else
       
    98         {
       
    99         MCESRV_DEBUG("calling ServiceL without message"); 
       
   100         returnMessage = iService.DoServiceL( aIds, aFunction );
       
   101         if ( returnMessage )
       
   102             {
       
   103             CleanupStack::PushL( returnMessage );
       
   104             ITC().WriteL( aMessage, 
       
   105                           *returnMessage, 
       
   106                           EMceItcArgContext );
       
   107             CleanupStack::PopAndDestroy( returnMessage );
       
   108             }
       
   109         }
       
   110         
       
   111     MCESRV_DEBUG("TMceMessageDispatcher::DispatchL, Exit");
       
   112         
       
   113     }
       
   114     
       
   115 // -----------------------------------------------------------------------------
       
   116 // TMceMessageDispatcher::DecodeL
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 template <class T>
       
   120 inline CMceMsgBase* TMceMessageDispatcher<T>::DecodeL( TMceItcDataType aType, 
       
   121                                                        const TDesC8& aMessage )
       
   122     {
       
   123     MCESRV_DEBUG("TMceMessageDispatcher::DecodeL, Entry");
       
   124     
       
   125 	RDesReadStream readStream( aMessage );
       
   126     CleanupClosePushL( readStream );
       
   127     
       
   128     CMceMsgBase* message = TMceComFactory().CreateL( aType, readStream );
       
   129 	CleanupStack::PopAndDestroy(); // readStream
       
   130 	
       
   131     MCESRV_DEBUG_DVALUE("message type", aType );
       
   132 
       
   133     MCESRV_DEBUG("TMceMessageDispatcher::DecodeL, Exit");
       
   134 
       
   135     return message;
       
   136                 
       
   137     }
       
   138