sysstatemgmt/systemstatemgr/test/testapps/src/ssmtestprocwritetime.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-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 // usage: ssmtestprocwritetime.exe <output filename> [<timeout (seconds)>]    *
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @test
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <f32file.h>
       
    26 #include <s32file.h>
       
    27 #include <sysmonclisess.h>
       
    28 #include <startupproperties.h>
       
    29 #include "ssmtestapps.h"
       
    30 #include "ssmdebug.h"
       
    31 
       
    32 static void RunL()
       
    33 	{
       
    34 	TBuf<KTestCommandLineMaxLength> commandLine;
       
    35 	if(User::CommandLineLength() > commandLine.MaxLength())
       
    36 		{
       
    37 		User::Leave(KErrTooBig);
       
    38 		}
       
    39 	User::CommandLine(commandLine);
       
    40 	
       
    41 	commandLine.TrimAll();
       
    42 	
       
    43 	DEBUGPRINT2A("Argument string: %S", &commandLine);
       
    44 	DEBUGPRINT2A("Logfile location: %S", &KTestAppLogFileLoc);
       
    45 	
       
    46 	TLex cmdLnLex(commandLine);
       
    47 
       
    48 	TBuf<KTestCommandLineMaxLength> logFileName;	
       
    49 	if (cmdLnLex.Eos()) // If there aren't any arguments, that is an error
       
    50 		{
       
    51 		User::Leave(KErrArgument);
       
    52 		}
       
    53 	else
       
    54 		{
       
    55 		TPtrC token(cmdLnLex.NextToken());
       
    56 		logFileName.Format(_L("%S%S"), &KTestAppLogFileLoc, &token);
       
    57 		DEBUGPRINT3A("Log file name (length: %d): %S", logFileName.Length(), &logFileName);
       
    58 		}
       
    59 	
       
    60 	TInt timeout = 0;
       
    61 	if(!cmdLnLex.Eos()) // If there was only one argument, we are finished and there was no timeout requested.
       
    62 		{
       
    63 		TPtrC token(cmdLnLex.NextToken());
       
    64 		TLex timeoutLex(token);
       
    65 		User::LeaveIfError(timeoutLex.Val(timeout)); // If Val() returns an error the second argument wasn't an integer
       
    66 		}
       
    67 	
       
    68 	TTime now;
       
    69 	now.UniversalTime();
       
    70 	TBuf<20> nowStr; // 64-bit integers have a maximum of 19 digits, plus the possibility of a - (though a current time shouldn't be negative)
       
    71     nowStr.AppendNum( now.Int64() );
       
    72 	
       
    73 	RFs fs;
       
    74 	User::LeaveIfError(fs.Connect());
       
    75 	CleanupClosePushL(fs);
       
    76 	RFileWriteStream ws;
       
    77 	User::LeaveIfError(ws.Replace(fs, logFileName, EFileShareExclusive|EFileWrite));
       
    78 	ws.PushL();
       
    79 	ws.WriteL(nowStr);
       
    80 	ws.CommitL();
       
    81 	CleanupStack::PopAndDestroy(2); // fs, ws
       
    82 
       
    83 	User::After(timeout * 1000000); // Microseconds = 1s
       
    84 	
       
    85 	RProcess::Rendezvous(KErrNone);
       
    86 	}
       
    87 
       
    88 TInt E32Main()
       
    89 	{
       
    90 	__UHEAP_MARK;
       
    91 
       
    92 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
    93 	TInt r=KErrNoMemory;
       
    94 	if (cleanup)
       
    95 		{
       
    96 		TRAP(r,RunL());
       
    97 		delete cleanup;
       
    98 		}
       
    99 
       
   100 	__UHEAP_MARKEND;
       
   101 	return r;
       
   102 	}