dbgsrv/coredumpserver/test/flashdump/src/main.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     1 // Copyright (c) 2008-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 //
       
    15 
       
    16 #include "flashdump.h"
       
    17 #include "debuglogging.h"
       
    18 #include <e32base.h>
       
    19 #include <e32std.h>
       
    20 #include <e32cons.h>
       
    21 
       
    22 _LIT(KTextConsoleTitle, "The CrashFlash Dumper");
       
    23 
       
    24 LOCAL_D CConsoleBase* console; // write all messages to this
       
    25 
       
    26 
       
    27 GLDEF_C TInt E32Main();
       
    28 
       
    29 //  Local Functions
       
    30 
       
    31 LOCAL_C HBufC* ReadCommandLineL()
       
    32 	{
       
    33 	TInt cmdSize = User::CommandLineLength();
       
    34 
       
    35 	if(cmdSize > 0)
       
    36 		{
       
    37 		HBufC* cmd = HBufC::NewL(cmdSize);
       
    38 		TPtr p(cmd->Des());
       
    39 
       
    40 		User::CommandLine(p);
       
    41 		
       
    42 		return cmd;
       
    43 		}
       
    44 		
       
    45 	console->Printf(_L("\nusage: flashdump <filename>\n"));
       
    46 	console->Printf(_L("\nAny key to continue\n"));
       
    47 	console->Getch();
       
    48 	
       
    49 	return NULL;
       
    50 	}
       
    51 
       
    52 LOCAL_C void MainL()
       
    53 	{
       
    54 	CCrashFlashDump* dumper = CCrashFlashDump::NewL();
       
    55 	CleanupStack::PushL(dumper);
       
    56 	
       
    57 	HBufC* file = ReadCommandLineL();
       
    58 	if(!file)
       
    59 		{
       
    60 		User::Leave(KErrArgument);
       
    61 		}
       
    62 	
       
    63 	CleanupStack::PushL(file);
       
    64 	
       
    65 	LOG_MSG("Opening File");	
       
    66 	dumper->OpenFileL(file->Des());
       
    67 	
       
    68 	LOG_MSG("Dumping file to flash");
       
    69 	dumper->DumpFlashToFileL();
       
    70 	
       
    71 	CleanupStack::PopAndDestroy(file);
       
    72 	CleanupStack::PopAndDestroy(dumper);	
       
    73 	}
       
    74 
       
    75 LOCAL_C void DoStartL()
       
    76 	{
       
    77 	MainL();
       
    78 	}
       
    79 
       
    80 //  Global Functions
       
    81 
       
    82 GLDEF_C TInt E32Main()
       
    83 	{
       
    84 	// Create cleanup stack
       
    85 	__UHEAP_MARK;
       
    86 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
    87 
       
    88 	// Create output console
       
    89 	TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
       
    90 	if (createError)
       
    91 	return createError;
       
    92 
       
    93 	// Run application code inside TRAP harness, wait keypress when terminated
       
    94 	TRAPD(mainError, DoStartL());
       
    95 	if(mainError == KErrNone)
       
    96 		{
       
    97 		LOG_MSG("Flash dump succesful!");
       
    98 		}
       
    99 	else
       
   100 		{
       
   101 		LOG_MSG2("Flash dump failed with [%d]", mainError);
       
   102 		}
       
   103 	
       
   104 	delete console;
       
   105 	delete cleanup;
       
   106 	__UHEAP_MARKEND;
       
   107 	return mainError;
       
   108 	}
       
   109 
       
   110 
       
   111 //eof
       
   112 
       
   113