os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/designexample.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/designexample.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,190 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Runs the example code provided in the design and how to docs with flogger.
1.18 +
1.19 +#include <e32base.h>
1.20 +#include <e32cons.h>
1.21 +#include <comms-infras/commsdebugutility.h>
1.22 +
1.23 +#ifdef _DEBUG
1.24 +const TInt KFloggerFileFlushTime = 1000000; //< Flogger flushes its file buffer every second
1.25 +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.
1.26 +const TInt KFloggerWriteTime = 500000; ///< Give flogger 1/2 second to write the data.
1.27 +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.
1.28 +_LIT(KTitle1,"You have run the Comsdbg DesignExample.\n");
1.29 +_LIT(KTitle2,"Make sure commsdbg.ini contains the line:\n");
1.30 +_LIT(KTitle3,"LOG XComm *\n\n");
1.31 +#endif
1.32 +#ifndef __FLOG_ACTIVE
1.33 +_LIT(KError1,"Error: You have not built this with flogger enabled.\n");
1.34 +#endif
1.35 +#ifdef _DEBUG
1.36 +_LIT(KProgress1,"Running foo()...\n");
1.37 +_LIT(KProgress2,"Running X::SetInt(5)...\n");
1.38 +_LIT(KProgress3,"Running X::GetInt...\n");
1.39 +_LIT(KProgressDone,"All Done. Check c:\\logs\\log.txt for results.");
1.40 +#endif
1.41 +_LIT(KWindowTtl,"DesignExample");
1.42 +const TInt KConsWidth=50;
1.43 +const TInt KConsHeight=15;
1.44 +//***** Start of example code from Design Specification *****//
1.45 +
1.46 +__FLOG_STMT(_LIT8(KSubsys,"XComm");)
1.47 +__FLOG_STMT(_LIT8(KComponent,"Sprocket");)
1.48 +__FLOG_STMT(_LIT8(KTempSubsys,"NewXComm");) // Temporary subsystem name
1.49 +__FLOG_STMT(_LIT8(KTempComponent,"NewSprocket");) // Temporary component name
1.50 +
1.51 +
1.52 +class X
1.53 + {
1.54 +public:
1.55 + inline X();
1.56 + inline X(const X& aRhs);
1.57 + inline X& operator=(const X& aRhs);
1.58 + inline ~X();
1.59 +
1.60 + inline void ChangeTag();
1.61 + inline void RestoreTag();
1.62 +
1.63 + inline TUint GetInt();
1.64 + inline void SetInt(TUint aVal);
1.65 +private:
1.66 + TUint iInt;
1.67 + __FLOG_DECLARATION_MEMBER;
1.68 + };
1.69 +
1.70 +X::X() : iInt(0)
1.71 + {
1.72 + __FLOG_OPEN(KSubsys, KComponent);
1.73 + }
1.74 +
1.75 +X::X(const X& aRhs) : iInt(aRhs.iInt)
1.76 + {
1.77 + __FLOG_OPEN(KSubsys, KComponent);
1.78 + }
1.79 +
1.80 +X& X::operator=(const X& aRhs)
1.81 + {
1.82 + if (this != &aRhs)
1.83 + {
1.84 + iInt = aRhs.iInt;
1.85 + __FLOG_OPEN(KSubsys, KComponent);
1.86 + }
1.87 + return *this;
1.88 + }
1.89 +
1.90 +void X::ChangeTag()
1.91 + {
1.92 + __FLOG_SET_TAGS(KTempSubsys, KTempComponent);
1.93 + __FLOG(_L8("Temporally changed the tags in the log file "));
1.94 + // The tags are changed
1.95 + }
1.96 +
1.97 +void X::RestoreTag()
1.98 + {
1.99 + __FLOG_SET_TAGS(KSubsys, KComponent);
1.100 + __FLOG(_L8("Restored the original tags in the log file "));
1.101 + // The tags are restored
1.102 + }
1.103 +
1.104 +
1.105 +X::~X()
1.106 + {
1.107 + __FLOG_CLOSE;
1.108 + }
1.109 +
1.110 +TUint X::GetInt()
1.111 + {
1.112 +#ifdef __FLOG_ACTIVE
1.113 + _LIT(KHiThere,"hi there ");
1.114 + _LIT8(KHiThere8,"hi there ");
1.115 + _LIT8(KDumpPi," Pi = %d.%d%d%d%d%d%d%d%d");
1.116 + _LIT8(KGetInt," X::GetInt() - about to return the integer: %d ");
1.117 +#endif
1.118 +
1.119 + //__FLOG("hi there"); //illegal - compile time error
1.120 + __FLOG(KHiThere); //ok - but inefficient in a Unicode build
1.121 + __FLOG(KHiThere8); //good!
1.122 + __FLOG_0(KHiThere8); //exactly the same as the previous line
1.123 + __FLOG_9(KDumpPi, 3, 1, 4, 1, 5, 9, 2, 6, 5);
1.124 +
1.125 + __FLOG_1(KGetInt, iInt);
1.126 + return iInt;
1.127 + }
1.128 +
1.129 +void X::SetInt(TUint aVal)
1.130 + {
1.131 + __FLOG_STMT(_LIT(KString, "X::SetInt - setting iInt to: ");)
1.132 + __FLOG(KString);
1.133 +
1.134 + __FLOG_STMT(_LIT8(KFormatForHex,"%2d");)
1.135 + __FLOG_STMT(const TInt KMaxHexString = 3;)
1.136 + __FLOG_STMT(TBuf8<KMaxHexString> buf;)
1.137 + __FLOG_STMT(buf.Format(KFormatForHex,aVal);)
1.138 +
1.139 + __FLOG_HEXDUMP (( buf ));
1.140 +
1.141 + iInt = aVal;
1.142 + }
1.143 +
1.144 +
1.145 +__FLOG_STMT(_LIT8(KFooSubsys,"XComm");)
1.146 +__FLOG_STMT(_LIT8(KFooComponent,"Foo");)
1.147 +__FLOG_STMT(_LIT8(KDemoString,"Logging test");)
1.148 +
1.149 +void foo()
1.150 + {
1.151 + __FLOG_DECLARATION_VARIABLE;
1.152 + __FLOG_OPEN(KFooSubsys, KFooComponent);
1.153 + __FLOG_VA (( KDemoString ));
1.154 + __FLOG_CLOSE;
1.155 + }
1.156 +
1.157 +//***** End of example code from Design Specification *****//
1.158 +
1.159 +
1.160 +void MainL()
1.161 +{
1.162 + // Create a console for communication to user of progress
1.163 + CConsoleBase *console=Console::NewL(KWindowTtl,TSize(KConsWidth,KConsHeight));
1.164 + __FLOG_STMT(console->Printf(KTitle1);)
1.165 + __FLOG_STMT(console->Printf(KTitle2);)
1.166 + __FLOG_STMT(console->Printf(KTitle3);)
1.167 +
1.168 +#ifndef __FLOG_ACTIVE
1.169 + console->Printf(KError1);
1.170 +#endif
1.171 +
1.172 + __FLOG_STMT(console->Printf(KProgress1));
1.173 + foo();
1.174 +
1.175 + X XTest;
1.176 +
1.177 + __FLOG_STMT(console->Printf(KProgress2);)
1.178 + XTest.SetInt(5);
1.179 + __FLOG_STMT(console->Printf(KProgress3);)
1.180 + XTest.GetInt();
1.181 + __FLOG_STMT(console->Printf(KProgressDone);)
1.182 +
1.183 + __FLOG_STMT(User::After(KTimeToLog);)
1.184 + __FLOG_STMT(User::After(KTimeToLog);)
1.185 +}
1.186 +
1.187 +
1.188 +GLDEF_C TInt E32Main()
1.189 + {
1.190 + TRAP_IGNORE(MainL());
1.191 +
1.192 + return KErrNone;
1.193 + }