transdebugprint.cpp

来自「Symbian OS C++ for Mobile Phones v3 Exam」· C++ 代码 · 共 87 行

CPP
87
字号
// Copyright (c) 2004 - 2007, Symbian Software Ltd. All rights reserved.

#include <f32file.h>

#include "transport.h"


EXPORT_C void TransDebugPrint(const TText16* aFmt, ...)
/**
	Write the supplied debug information to the log file.
	This function is empty if TRANSPORT_LOGGING is not defined.

	@param	fmt				Standard Symbian OS format string for following arguments.
 */
	{
#ifndef TRANSPORT_LOGGING
	(void) aFmt;
#else
	VA_LIST argptr;
	VA_START(argptr, aFmt);

	TBuf<512> buf;
	const TPtrC fmtPtr(aFmt);
	buf.FormatList(fmtPtr, argptr);
    buf.Append('\r');
    buf.Append('\n');
    
	RFs fs;
	RFile f;
	
	TInt r = fs.Connect();
	
	// use a clean file every time the application is run
#if defined(__WINS__)
	_LIT(KLogFileName, "c:\\oandx.txt");
#elif defined(__SERIES60_3X__)
	_LIT(KLogFileName, "e:\\oandx.txt");
#else
	_LIT(KLogFileName, "d:\\oandx.txt");
#endif
	TAny* delPtr = Dll::Tls();
	if (delPtr == 0)
		{
		r = fs.Delete(KLogFileName);
		if (r == KErrNotFound)
			r = KErrNone;

		if (r == KErrNone)
			r = Dll::SetTls((TAny*)1);

		if (r != KErrNone)
			User::Panic(_L("lognodelete"), r);		
		}
	
	if (r == KErrNone)
		{
		TUint openMode = EFileShareExclusive | EFileStreamText | EFileWrite;
		r = f.Open(fs, KLogFileName, openMode);
		if (r == KErrNotFound)
			r = f.Create(fs, KLogFileName, openMode);
		}
		
	if (r == KErrNone)
		{
		TInt endDelta = 0;
		r = f.Seek(ESeekEnd, endDelta);
		}
	
	if (r == KErrNone)
		{
		TBuf8<512> buf8;
		buf8.Copy(buf);
		r = f.Write(buf8);
		}
	
	if (r == KErrNone)
		f.Flush();
	
	f.Close();
	fs.Close();
	
	VA_END(argptr);
#endif	// #else #ifndef TRANSPORT_LOGGING
	}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?