traceservices/commsdebugutility/TE_commsdebugutility/src/designexample.cpp
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Runs the example code provided in the design and how to docs with flogger.
       
    15 
       
    16 #include <e32base.h>
       
    17 #include <e32cons.h>
       
    18 #include <comms-infras/commsdebugutility.h>
       
    19 
       
    20 #ifdef _DEBUG
       
    21 const TInt KFloggerFileFlushTime = 	1000000;	 //< Flogger flushes its file buffer every second
       
    22 const TInt KFloggerIdleTimeWait = 1000000;	 //< A guess (!) at how long the system needs to be idle before flogger's lower-priority thread kicks in and writes the data.
       
    23 const TInt KFloggerWriteTime = 500000;		///< Give flogger 1/2 second to write the data.
       
    24 const TInt KTimeToLog = KFloggerFileFlushTime + KFloggerIdleTimeWait + KFloggerWriteTime;   //< 2.5-second delay used to guarantee the logger will have written to the log file before reading the message.
       
    25 _LIT(KTitle1,"You have run the Comsdbg DesignExample.\n");
       
    26 _LIT(KTitle2,"Make sure commsdbg.ini contains the line:\n");
       
    27 _LIT(KTitle3,"LOG XComm *\n\n");
       
    28 #endif
       
    29 #ifndef __FLOG_ACTIVE
       
    30 _LIT(KError1,"Error: You have not built this with flogger enabled.\n");
       
    31 #endif
       
    32 #ifdef _DEBUG
       
    33 _LIT(KProgress1,"Running foo()...\n");
       
    34 _LIT(KProgress2,"Running X::SetInt(5)...\n");
       
    35 _LIT(KProgress3,"Running X::GetInt...\n");
       
    36 _LIT(KProgressDone,"All Done. Check c:\\logs\\log.txt for results.");
       
    37 #endif
       
    38 _LIT(KWindowTtl,"DesignExample");
       
    39 const TInt KConsWidth=50;
       
    40 const TInt KConsHeight=15;
       
    41 //***** Start of example code from Design Specification *****//
       
    42 	
       
    43 __FLOG_STMT(_LIT8(KSubsys,"XComm");)
       
    44 __FLOG_STMT(_LIT8(KComponent,"Sprocket");)
       
    45 __FLOG_STMT(_LIT8(KTempSubsys,"NewXComm");) // Temporary subsystem name
       
    46 __FLOG_STMT(_LIT8(KTempComponent,"NewSprocket");) // Temporary component name
       
    47 	
       
    48 	
       
    49 class X
       
    50 	{
       
    51 public:
       
    52 	inline X();
       
    53 	inline X(const X& aRhs);
       
    54 	inline X& operator=(const X& aRhs);
       
    55 	inline ~X();
       
    56 	
       
    57 	inline void ChangeTag();
       
    58 	inline void RestoreTag();
       
    59 
       
    60 	inline TUint GetInt();
       
    61 	inline void SetInt(TUint aVal);
       
    62 private:
       
    63 	TUint iInt;
       
    64 	__FLOG_DECLARATION_MEMBER;
       
    65 	};
       
    66 
       
    67 X::X() : iInt(0)
       
    68 	{
       
    69 	__FLOG_OPEN(KSubsys, KComponent);
       
    70 	}
       
    71 
       
    72 X::X(const X& aRhs) : iInt(aRhs.iInt)
       
    73 	{
       
    74 	__FLOG_OPEN(KSubsys, KComponent);
       
    75 	}
       
    76 
       
    77 X& X::operator=(const X& aRhs)
       
    78 	{
       
    79 	if (this != &aRhs)
       
    80 	    {
       
    81 	    iInt = aRhs.iInt;
       
    82     	__FLOG_OPEN(KSubsys, KComponent);
       
    83 	    }
       
    84 	return *this;
       
    85 	}
       
    86 
       
    87 void X::ChangeTag()
       
    88 	{
       
    89 	__FLOG_SET_TAGS(KTempSubsys, KTempComponent);
       
    90 	__FLOG(_L8("Temporally changed the tags in the log file "));
       
    91 	// The tags are changed
       
    92 	}
       
    93 
       
    94 void X::RestoreTag()
       
    95 	{
       
    96 	__FLOG_SET_TAGS(KSubsys, KComponent);
       
    97 	__FLOG(_L8("Restored the original tags in the log file "));
       
    98 	// The tags are restored 
       
    99 	}
       
   100 
       
   101 
       
   102 X::~X()
       
   103 	{
       
   104 	__FLOG_CLOSE;
       
   105 	}
       
   106 
       
   107 TUint X::GetInt()
       
   108 	{
       
   109 #ifdef __FLOG_ACTIVE
       
   110 	_LIT(KHiThere,"hi there "); 
       
   111 	_LIT8(KHiThere8,"hi there "); 
       
   112 	_LIT8(KDumpPi," Pi = %d.%d%d%d%d%d%d%d%d"); 
       
   113 	_LIT8(KGetInt," X::GetInt() - about to return the integer: %d ");
       
   114 #endif
       
   115 
       
   116 	//__FLOG("hi there");		//illegal - compile time error
       
   117 	__FLOG(KHiThere);		//ok - but inefficient in a Unicode build
       
   118 	__FLOG(KHiThere8);		//good!
       
   119 	__FLOG_0(KHiThere8);		//exactly the same as the previous line
       
   120 	__FLOG_9(KDumpPi, 3, 1, 4, 1, 5, 9, 2, 6, 5);
       
   121 
       
   122 	__FLOG_1(KGetInt, iInt);
       
   123 	return iInt;
       
   124 	}
       
   125 
       
   126 void X::SetInt(TUint aVal)
       
   127 	{
       
   128 	__FLOG_STMT(_LIT(KString, "X::SetInt - setting iInt to: ");)
       
   129 	__FLOG(KString);
       
   130 
       
   131 	__FLOG_STMT(_LIT8(KFormatForHex,"%2d");)
       
   132 	__FLOG_STMT(const TInt KMaxHexString = 3;)
       
   133 	__FLOG_STMT(TBuf8<KMaxHexString> buf;)
       
   134 	__FLOG_STMT(buf.Format(KFormatForHex,aVal);)
       
   135 	
       
   136 	__FLOG_HEXDUMP (( buf ));
       
   137 
       
   138 	iInt = aVal;
       
   139 	}
       
   140 
       
   141 
       
   142 __FLOG_STMT(_LIT8(KFooSubsys,"XComm");)
       
   143 __FLOG_STMT(_LIT8(KFooComponent,"Foo");)
       
   144 __FLOG_STMT(_LIT8(KDemoString,"Logging test");)
       
   145 
       
   146 void foo()
       
   147 	{
       
   148 	__FLOG_DECLARATION_VARIABLE;
       
   149 	__FLOG_OPEN(KFooSubsys, KFooComponent);
       
   150 	__FLOG_VA (( KDemoString ));
       
   151 	__FLOG_CLOSE;
       
   152 	}
       
   153 
       
   154 //***** End of example code from Design Specification *****//
       
   155 
       
   156 
       
   157 void MainL()
       
   158 {
       
   159 	// Create a console for communication to user of progress	
       
   160 	CConsoleBase *console=Console::NewL(KWindowTtl,TSize(KConsWidth,KConsHeight));
       
   161 	__FLOG_STMT(console->Printf(KTitle1);)
       
   162 	__FLOG_STMT(console->Printf(KTitle2);)
       
   163 	__FLOG_STMT(console->Printf(KTitle3);)
       
   164 	
       
   165 #ifndef __FLOG_ACTIVE
       
   166 	console->Printf(KError1);
       
   167 #endif
       
   168 
       
   169 	__FLOG_STMT(console->Printf(KProgress1));
       
   170 	foo();
       
   171 	
       
   172 	X XTest;
       
   173 	
       
   174 	__FLOG_STMT(console->Printf(KProgress2);)
       
   175 	XTest.SetInt(5);
       
   176 	__FLOG_STMT(console->Printf(KProgress3);)
       
   177 	XTest.GetInt();
       
   178 	__FLOG_STMT(console->Printf(KProgressDone);)
       
   179 	
       
   180 	__FLOG_STMT(User::After(KTimeToLog);)
       
   181 	__FLOG_STMT(User::After(KTimeToLog);)
       
   182 }
       
   183 
       
   184 
       
   185 GLDEF_C TInt E32Main()
       
   186 	{
       
   187     TRAP_IGNORE(MainL());
       
   188     
       
   189 	return KErrNone;
       
   190 	}