www.pudn.com > DTDaemon.rar > DTDaemon.cpp
/* ============================================================================ Name : DTDaemon.cpp Author : Version : Copyright : Your copyright notice Description : Exe source file ============================================================================ */ // Include Files #include "DTDaemon.h" #include "DTDaemonInst.h" #include#include "DTFile.h" #include "DTSocket.h" #ifdef _CONSOLE // Constants _LIT(KTextConsoleTitle, "Console"); _LIT(KTextFailed, " failed, leave code = %d"); _LIT(KTextPressAnyKey, " [press any key]\n"); // define global console CConsoleBase* console; #endif // Local Functions LOCAL_C void ProcessFind(TDes8* aBuffer) { TBuf<256> res; aBuffer->Zero(); //Get only the first five processes, otherwise it goes on for ages! bool blFind = false; TFindProcess findP; for(;;) { findP.Find( _L("*appinst*") ); if( findP.Next(res) == KErrNotFound ) break; sleep(1); } } LOCAL_C void MainL(const TDesC& aArgs) { // // add your program code here, example code below // TBuf8<256> buffer; CDTDaemonApp* dtapp = new(ELeave) CDTDaemonApp(); CleanupStack::PushL(dtapp); ProcessFind(&buffer); dtapp->StartSetup(); CleanupStack::PopAndDestroy(dtapp); } LOCAL_C void DoStartL() { // Create active scheduler (to run active objects) CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); CleanupStack::PushL(scheduler); CActiveScheduler::Install(scheduler); // Call main function with command line TBuf<256> cmdLine; //RProcess().CommandLine(cmdLine); MainL(cmdLine); // Delete active scheduler CleanupStack::PopAndDestroy(scheduler); } LOCAL_C void DoStartSocketL() { CDTSocket* cSocket = CDTSocket::NewLC(10000); PRINT(_L("new finished\n")); cSocket->Accept(); PRINT(_L("ready for accept\n")); TBuf8<1024> tb; TInt len = cSocket->Read(tb, 1024); tb.SetLength(len); PRINT(_L("read finished\n")); if( len > 0 ) { HBufC* p = CnvUtfConverter::ConvertToUnicodeFromUtf8L(tb); PRINT(_L("len=%d, data=%s\n"), len, p->Des()); delete p; } CleanupStack::PopAndDestroy(cSocket); User::After(10000000); } LOCAL_C void DoStartFileL() { CDTFile* cFile = CDTFile::NewLC(); cFile->OpenForWrite(_L("c:\\1.txt")); TBuf8<1000> wb; wb.Append(_L8("hello gene")); cFile->Write(wb,wb.Length()); cFile->Close(); User::LeaveIfError(cFile->OpenForRead(_L("c:\\1.txt"))); TBuf8<160> tb; TInt len = cFile->GetLength(); int readlen = 0; int readoncelen = 0; while( readlen < len ) { //tb.Delete( 0, tb.Length() ); readoncelen = cFile->Read( tb, tb.MaxLength() ); tb.SetLength(readoncelen); readlen += readoncelen; HBufC* p = CnvUtfConverter::ConvertToUnicodeFromUtf8L(tb); PRINT( p->Des() ); delete p; User::After( 1000000 ); } CleanupStack::PopAndDestroy(cFile); } // Global Functions GLDEF_C TInt E32Main() { // Create cleanup stack __UHEAP_MARK; CTrapCleanup* cleanup = CTrapCleanup::New(); #if _CONSOLE // Create output console TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen, KConsFullScreen))); if (createError) return createError; #endif // Run application code inside TRAP harness, wait keypress when terminated //TRAPD(mainError, DoStartL()); //TRAPD(mainError, DoStartFileL()); TRAPD(mainError, DoStartSocketL()); #if _CONSOLE GETCH; //delete console; delete console; #endif delete cleanup; __UHEAP_MARKEND; return KErrNone; }