remotemgmt_plat/syncml_ds_error_reporting_api/tsrc/SyncStatusSpy/src/CenrepUtils.cpp
branchRCL_3
changeset 62 19bba8228ff0
parent 13 06f47423ecee
equal deleted inserted replaced
61:b183ec05bd8c 62:19bba8228ff0
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include <bautils.h>				// BaflUtils
       
    21 #include <utf.h>
       
    22 #include <centralrepository.h>
       
    23 #include <NsmlOperatorErrorCRKeys.h>
       
    24 
       
    25 #include "CenrepUtils.h"
       
    26 
       
    27 _LIT( KPrivateFile, "C:\\logs\\Sync\\SyncStatus.txt" );
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =========================================
       
    30 
       
    31 
       
    32 void CCenrepUtils::WriteLogL( TUint32 aKey, TLogKey aValue  )
       
    33 	{
       
    34 	RFs fs;
       
    35 	User::LeaveIfError( fs.Connect() );  // create connect to fileserver
       
    36 	
       
    37 	CleanupClosePushL( fs );
       
    38 	RFile privateFile;
       
    39 	CleanupClosePushL( privateFile );
       
    40 
       
    41 	TInt ret = privateFile.Open( fs, KPrivateFile, EFileShareExclusive|EFileWrite ); // open file
       
    42 	if( ret == KErrNotFound )  // if file does not exist, create it
       
    43 		{
       
    44 		privateFile.Create( fs, KPrivateFile, EFileShareExclusive|EFileWrite );
       
    45 		}
       
    46 
       
    47 	TInt value = 0;
       
    48     CRepository* rep = CRepository::NewL( KCRUidOperatorDatasyncErrorKeys );
       
    49     rep->Get( aKey, value );
       
    50     delete rep;
       
    51 	HBufC8* dateBuf8 = HBufC8::NewLC( 64 );
       
    52 	TPtr8 ptrDateBuf8 = dateBuf8->Des();
       
    53 	HBufC8* timeBuf8 = HBufC8::NewLC( 64 );
       
    54 	TPtr8 ptrTimeBuf8 = timeBuf8->Des();
       
    55 
       
    56 	GetDateAndTimeL( ptrDateBuf8, ptrTimeBuf8 );
       
    57 	HBufC8* buf8 = HBufC8::NewLC( 512 );
       
    58 	TPtr8 ptrBuf8 = buf8->Des();
       
    59 
       
    60 	if( aValue == EErrorCode )
       
    61 		{
       
    62 		ptrBuf8.Format( _L8("[%S ] [ErrorCode: %d]\r\n"), &ptrTimeBuf8, value );
       
    63 		}
       
    64 	else if( aValue == EProfileId )
       
    65 		{
       
    66 		ptrBuf8.Format( _L8("[%S ] [SyncProfileId: %d]\r\n"), &ptrTimeBuf8, value );
       
    67 		}
       
    68 	else if( aValue == ESyncType )
       
    69         {
       
    70         ptrBuf8.Format( _L8("[%S ] [SyncType: %d]\r\n"), &ptrTimeBuf8, value );
       
    71         }
       
    72 	else if( aValue == ESyncInitiation )
       
    73 		{
       
    74 		ptrBuf8.Format( _L8("[%S ] [SyncInitiation: %d]\r\n"), &ptrTimeBuf8, value );
       
    75 		}
       
    76 
       
    77 	TInt size = 0;
       
    78 	privateFile.Size( size );
       
    79 	privateFile.Write( size, ptrBuf8 );
       
    80 
       
    81 	CleanupStack::PopAndDestroy( 5, &fs );//privateFile, dateBuf8, timeBuf8, buf8
       
    82     }
       
    83 
       
    84 void CCenrepUtils::GetDateAndTimeL( TDes8& aDateBuffer, TDes8& aTimeBuffer )
       
    85 	{
       
    86 	TTime time;
       
    87 	time.HomeTime();
       
    88 	HBufC* dateBuffer = HBufC::NewLC( 64 );
       
    89 	TPtr ptrDateBuffer = dateBuffer->Des();
       
    90 	HBufC* timeBuffer = HBufC::NewLC( 64 );
       
    91 	TPtr ptrTimeBuffer = timeBuffer->Des();
       
    92 	time.FormatL( ptrDateBuffer, _L( "%D%M%Y%/0%1%/1%2%/2%3%/3" ) );
       
    93 	time.FormatL( ptrTimeBuffer, _L( "%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B" ) );
       
    94 	CnvUtfConverter::ConvertFromUnicodeToUtf8( aDateBuffer, ptrDateBuffer );
       
    95 	CnvUtfConverter::ConvertFromUnicodeToUtf8( aTimeBuffer, ptrTimeBuffer );
       
    96 	CleanupStack::PopAndDestroy( 2 ); // dateBuffer, timeBuffer
       
    97 	}
       
    98 
       
    99 void CCenrepUtils::CreateSyncLogDirL()
       
   100 	{
       
   101 	RFs fs;
       
   102 	User::LeaveIfError( fs.Connect() );  // create connect to fileserver
       
   103 	CleanupClosePushL( fs );
       
   104 	if( !BaflUtils::FolderExists( fs, _L( "C:\\logs\\Sync\\" ) ) )
       
   105         {
       
   106         fs.MkDirAll( _L( "C:\\logs\\Sync\\" ) );
       
   107         }
       
   108 	CleanupStack::PopAndDestroy();
       
   109 	}
       
   110 
       
   111 void CCenrepUtils::ClearSyncLogL()
       
   112 	{
       
   113 	RFs fs;
       
   114 	User::LeaveIfError( fs.Connect() );  // create connect to fileserver
       
   115 	CleanupClosePushL( fs );
       
   116 	RFile privateFile;
       
   117 	CleanupClosePushL( privateFile );
       
   118 	privateFile.Replace( fs, KPrivateFile, EFileShareExclusive|EFileWrite );
       
   119 	CleanupStack::PopAndDestroy( 2 );
       
   120 	}
       
   121 // End of File