Using the REcmt API

Using the REcmt API is very simple:

  1. First, you need the REcmt resource object:

    #ifdef _DEBUG
    
    #include <EcmtClient.h>
    
    #endif
    
    class CTestEcmtAppUi : public CAknAppUi
    
        {
    
        …
    
        private:
    
     #ifdef _DEBUG
    
             REcmt iEcmt;
    
     #endif
    
        …
    
        }
    
  2. In your class constructor, connect to the Ecmt Server:

    void CTestEcmtAppUi::ConstructL()
    
        {
    
        BaseConstructL();
    
        …
    
     #ifdef _DEBUG
    
        iEcmt.Connect();
    
     #endif
    
        }
    
  3. In your class destructor, disconnect from the Server:

    CTestEcmtAppUi::~CTestEcmtAppUi()
    
        {
    
     #ifdef _DEBUG
    
        iEcmt.Close();
    
     #endif
    

After these steps, you can send messages to the Ecmt Manager with the Write() or WriteFormat() function calls. See the following example:

void CTestEcmtAppUi::HandleCommandL(TInt aCommand)

    {

    switch ( aCommand )

         {

         case EEikCmdExit:

              {

#ifdef _DEBUG

              TBuf16<10> plainText( _L("Exiting\n") );

              iEcmt.Write( plainText );

              TBuf16<11> formattedText( _L("Number: %d\n") );

              TInt num = 10;

              iEcmt.WriteFormat( formattedText, num );

#endif

              Exit();

              break;

              }

          default:

              break;      

         }

    }
 

The logging commands are enclosed within #ifdef - #endif so that the logging functionality is not included in production release which should be compiled as UREL. The _DEBUG macro will be defined only when the application is compiled as UDEB.

If you need to use REcmt logging in several classes, you can either pass the REcmt reference on from the first connecting class or use separate instances in every logging class.