⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 Starter program with source code for symbian c++ application plaftorm
💻 CPP
字号:
#include <e32base.h>#include <e32cons.h>#include <stdlib.h>
#include <apgcli.h>#include <apgtask.h>
#include <w32std.h>
const TUid KUidcontext_log = { 0x05CCC0AF };
// This is the mainloop game loop or whatevervoid mainloop(void){
	//CConsoleBase* console;
	//console=Console::NewL(_L("Test Consol"),TSize (KConsFullScreen,KConsFullScreen)); // Create a consol
	//CleanupStack::PushL(console);
	//console->Printf(_L("mainloop")); // write all your messages here
	//console->Getch(); // get and ignore character
	//CleanupStack::PopAndDestroy(); // close console

	_LIT(filen, ""); //dummy

	RApaLsSession ls;
	User::LeaveIfError(ls.Connect());
	CleanupClosePushL(ls);

	TThreadId context_log_threadid;

	User::LeaveIfError( ls.StartDocument(filen, KUidcontext_log, context_log_threadid) );

	//console->Printf(_L("after startDocument")); // write all your messages here
	TRequestStatus context_log_status, timer_status;

	RWsSession ws;
	User::LeaveIfError(ws.Connect());
	CleanupClosePushL(ws);

	TApaTaskList tl(ws);

	//wake up on thread death
	RThread context_log_thread;
	context_log_thread.Open(context_log_threadid);
	context_log_thread.Logon(context_log_status);

	//restart every 24 hours
	RTimer timer; // The asynchronous timer and ...
	timer.CreateLocal(); // Always created for this thread.
	CleanupClosePushL(timer);

	TTime time;
	time.HomeTime();

	TTimeIntervalHours wait_interval(1);
	int wait_count=0; // we can only wait upto 1 hour at a time,
			// so count to 24...

	time += wait_interval;
	//TBuf<30> dt;
	//time.FormatL(dt, _L("%F%Y-%M-%D %H:%T:%S\n"));
	//console->Printf(dt);

	timer.At(timer_status,time);

	bool done=false; bool restarting=false;
	int restart_count=0; const int RESTART_MAX=20;

	while(!done) {
		User::WaitForRequest(timer_status, context_log_status);
		if (timer_status!=KRequestPending) {
			if (wait_count==23) {
				TApaTask context_log_task=tl.FindApp(KUidcontext_log);;
				if (!context_log_task.Exists()) {
					// restart
				} else {
					context_log_task.SendSystemEvent(EApaSystemEventShutdown);
				}
				restarting=true; restart_count=0;
				wait_count=0;
			} else {
				wait_count++;
			}
			time.HomeTime();
			time += wait_interval;
			//time.FormatL(dt, _L("%F%Y-%M-%D %H:%T:%S\n"));
			//console->Printf(_L("%d "), timer_status);
			//console->Printf(dt);
			timer.At(timer_status, time);
		} else if (context_log_status!=KRequestPending) {
			//restart
			//TTimeIntervalMicroSeconds32 w(10*1000*1000);
			//User::After(w);
			TInt etype, ereason;
			TExitCategoryName ecat;
			etype=context_log_thread.ExitType();
			ereason=context_log_thread.ExitReason();
			ecat=context_log_thread.ExitCategory();
			
			if ((etype!=0 || restarting) && restart_count<RESTART_MAX) {
				User::LeaveIfError( ls.StartDocument(filen, KUidcontext_log, context_log_threadid) );
				User::LeaveIfError(context_log_thread.Open(context_log_threadid));
				context_log_thread.Logon(context_log_status);
				restarting=false;
				restart_count++;
			} else {
				// user shutdown
				done=true;
			}
		}
	}
	//console->Getch(); // get and ignore character
	//CleanupStack::PopAndDestroy(4); //console, ws, ls, timer
	CleanupStack::PopAndDestroy(3); // ws, ls, timer
}_LIT(KTxtEPOC32EX,"Whoops!");#ifdef __WINS__EXPORT_C TInt InitEmulator() // mainloop function called by the emulator software{	__UHEAP_MARK;	CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack	TRAPD(error,mainloop()); // more initialization, then do example	__ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error));	delete cleanup; // destroy clean-up stack	__UHEAP_MARKEND;		//CloseSTDLIB();	User::Exit(0);		return KErrNone;}int GLDEF_C E32Dll(TDllReason){	return(KErrNone);}#elseGLDEF_C TInt E32Main() // mainloop function called by E32{	__UHEAP_MARK;	CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack	TRAPD(error,mainloop()); // more initialization, then do example	__ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error));	delete cleanup; // destroy clean-up stack	__UHEAP_MARKEND;		//CloseSTDLIB();	User::Exit(0);		return KErrNone; // and return}#endif

⌨️ 快捷键说明

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