hti/HtiServicePlugins/HtiEchoServicePlugin/src/HtiEchoServicePlugin.cpp
branchRCL_3
changeset 59 8ad140f3dd41
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 2009 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:  HtiEchoServicePlugin implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "HtiEchoServicePlugin.h"
       
    21 #include <HtiDispatcherInterface.h>
       
    22 #include <HtiLogging.h>
       
    23 
       
    24 // CONSTANTS
       
    25 const static TUid KEchoServiceUid = { 0x1020DEBF };
       
    26 
       
    27 // MACROS
       
    28 
       
    29 // LOCAL CONSTANTS AND MACROS
       
    30 
       
    31 // MODULE DATA STRUCTURES
       
    32 
       
    33 // LOCAL FUNCTION PROTOTYPES
       
    34 
       
    35 // FORWARD DECLARATIONS
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // Create instance of concrete ECOM interface implementation
       
    40 CHtiEchoServicePlugin* CHtiEchoServicePlugin::NewL()
       
    41     {
       
    42     CHtiEchoServicePlugin* self = new (ELeave) CHtiEchoServicePlugin;
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop();
       
    46     return self;
       
    47     }
       
    48 
       
    49 // Constructor
       
    50 CHtiEchoServicePlugin::CHtiEchoServicePlugin():
       
    51     iReply( NULL )
       
    52     {
       
    53     }
       
    54 
       
    55 CHtiEchoServicePlugin::~CHtiEchoServicePlugin()
       
    56     {
       
    57     HTI_LOG_TEXT( "CHtiEchoServicePlugin destroy" );
       
    58     delete iReply;
       
    59     }
       
    60 
       
    61 // Second phase construction.
       
    62 void CHtiEchoServicePlugin::ConstructL()
       
    63     {
       
    64     HTI_LOG_TEXT( "CHtiEchoServicePlugin::ConstructL" );
       
    65     }
       
    66 
       
    67 void CHtiEchoServicePlugin::ProcessMessageL( const TDesC8& aMessage,
       
    68                                  THtiMessagePriority /*aPriority*/ )
       
    69     {
       
    70     HTI_LOG_FUNC_IN( "CHtiEchoServicePlugin::ProcessMessage" );
       
    71     HTI_LOG_FORMAT( "Msg len: %d", aMessage.Length() );
       
    72 
       
    73     if ( iReply )
       
    74         {
       
    75         HTI_LOG_TEXT( "sending previous echo, reject request" );
       
    76         return;
       
    77         }
       
    78 
       
    79     //make copy of the message and send it back
       
    80     iReply = HBufC8::NewL( aMessage.Length() );
       
    81     iReply->Des().Copy( aMessage );
       
    82 
       
    83     if ( iDispatcher->DispatchOutgoingMessage( iReply, KEchoServiceUid )
       
    84             == KErrNoMemory )
       
    85         {
       
    86         HTI_LOG_TEXT( "KErrNoMemory" );
       
    87         iDispatcher->AddMemoryObserver( this );
       
    88         }
       
    89     else
       
    90         {
       
    91         iReply = NULL;
       
    92         }
       
    93     HTI_LOG_FUNC_OUT( "CHtiEchoServicePlugin::ProcessMessage" );
       
    94     }
       
    95 
       
    96 void CHtiEchoServicePlugin::NotifyMemoryChange( TInt aAvailableMemory )
       
    97     {
       
    98 
       
    99     if ( iReply )
       
   100         {
       
   101         if ( aAvailableMemory >= iReply->Size() )
       
   102             {
       
   103             TInt err = iDispatcher->DispatchOutgoingMessage( iReply,
       
   104                             KEchoServiceUid );
       
   105 
       
   106             if (  err == KErrNone )
       
   107                 {
       
   108                 iReply = NULL;
       
   109                 iDispatcher->RemoveMemoryObserver( this );
       
   110                 }
       
   111             else if ( err != KErrNoMemory ) //some other error
       
   112                 {
       
   113                 delete iReply;
       
   114                 iReply = NULL;
       
   115                 iDispatcher->RemoveMemoryObserver( this );
       
   116                 }
       
   117             }
       
   118         }
       
   119     else
       
   120         {
       
   121         //some error, should not be called
       
   122         iDispatcher->RemoveMemoryObserver( this );
       
   123         }
       
   124     }
       
   125 
       
   126 
       
   127 // End of File