videoutils_plat/videoconnutility_api/tsrc/VCXTestCommon/src/CIptvTestMobilecrashWatcher.cpp
branchRCL_3
changeset 22 826cea16efd9
parent 21 798ee5f1972c
child 23 13a33d82ad98
equal deleted inserted replaced
21:798ee5f1972c 22:826cea16efd9
     1 /*
       
     2 * Copyright (c) 2008 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 the License "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 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <BAUTILS.H>
       
    22 #include <S32FILE.H>
       
    23 
       
    24 #include "CIptvTestMobilecrashWatcher.h"
       
    25 #include "VCXTestLog.h"
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // MACROS
       
    34 
       
    35 // LOCAL CONSTANTS AND MACROS
       
    36 
       
    37 // MODULE DATA STRUCTURES
       
    38 
       
    39 // LOCAL FUNCTION PROTOTYPES
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 
       
    43 // ============================= LOCAL FUNCTIONS ===============================
       
    44 
       
    45 // ============================ MEMBER FUNCTIONS ===============================
       
    46 
       
    47 _LIT(KDriveC, "C:\\");
       
    48 _LIT(KDriveE, "E:\\");
       
    49 _LIT(KDriveF, "F:\\");
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CIptvTestMobilecrashWatcher::
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // might leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C CIptvTestMobilecrashWatcher* CIptvTestMobilecrashWatcher::NewL()
       
    58     {
       
    59     VCXLOGLO1(">>>CIptvTestMobilecrashWatcher::NewL");
       
    60     CIptvTestMobilecrashWatcher* self = new (ELeave) CIptvTestMobilecrashWatcher( );
       
    61     CleanupStack::PushL(self);
       
    62     self->ConstructL(ETrue);
       
    63     CleanupStack::Pop();
       
    64     VCXLOGLO1("<<<CIptvTestMobilecrashWatcher::NewL");
       
    65     return self;
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CIptvTestMobilecrashWatcher::
       
    70 // C++ default constructor can NOT contain any code, that
       
    71 // might leave.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C CIptvTestMobilecrashWatcher* CIptvTestMobilecrashWatcher::NewL(TBool aPanicEnabled)
       
    75     {
       
    76     VCXLOGLO1(">>>CIptvTestMobilecrashWatcher::NewL");
       
    77     CIptvTestMobilecrashWatcher* self = new (ELeave) CIptvTestMobilecrashWatcher( );
       
    78     CleanupStack::PushL(self);
       
    79     self->ConstructL(aPanicEnabled);
       
    80     CleanupStack::Pop();
       
    81     VCXLOGLO1("<<<CIptvTestMobilecrashWatcher::NewL");
       
    82     return self;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CIptvTestMobilecrashWatcher::~CIptvTestMobilecrashWatcher
       
    87 // destructor
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 EXPORT_C CIptvTestMobilecrashWatcher::~CIptvTestMobilecrashWatcher()
       
    91     {
       
    92     VCXLOGLO1(">>>CIptvTestMobilecrashWatcher::~CIptvTestMobilecrashWatcher");
       
    93 
       
    94    	iCrashesBefore.ResetAndDestroy();
       
    95    	iCrashesNow.ResetAndDestroy();
       
    96    	iFsSession.Close();
       
    97 
       
    98     VCXLOGLO1("<<<CIptvTestMobilecrashWatcher::~CIptvTestMobilecrashWatcher");
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CIptvTestMobilecrashWatcher::CIptvTestMobilecrashWatcher
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 CIptvTestMobilecrashWatcher::CIptvTestMobilecrashWatcher()
       
   106     {
       
   107     VCXLOGLO1(">>>CIptvTestMobilecrashWatcher::CIptvTestMobilecrashWatcher");
       
   108 
       
   109 
       
   110     VCXLOGLO1("<<<CIptvTestMobilecrashWatcher::CIptvTestMobilecrashWatcher");
       
   111     }
       
   112 
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CIptvTestMobilecrashWatcher::ConstructL()
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CIptvTestMobilecrashWatcher::ConstructL(TBool aPanicEnabled)
       
   119     {
       
   120     VCXLOGLO1(">>>CIptvTestMobilecrashWatcher::ConstructL");
       
   121 
       
   122 	iPanicEnabled = aPanicEnabled;
       
   123 	iFsSession.Connect();
       
   124 
       
   125     iCrashesBefore.ResetAndDestroy();
       
   126 	TRAP_IGNORE( ReadMobilecrashesL(iCrashesBefore, KDriveC) );
       
   127 	TRAP_IGNORE( 	ReadMobilecrashesL(iCrashesBefore, KDriveE) );
       
   128 	TRAP_IGNORE( ReadMobilecrashesL(iCrashesBefore, KDriveF) );
       
   129     VCXLOGLO1("<<<CIptvTestMobilecrashWatcher::ConstructL");
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CIptvTestMobilecrashWatcher::ReadMobilecrashesL()
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C void CIptvTestMobilecrashWatcher::ReadMobilecrashesL( RPointerArray<HBufC>& aCrashes, const TDesC& aDrive )
       
   137 	{
       
   138 	VCXLOGLO1(">>>CIptvTestMobilecrashWatcher::ReadMobilecrashes");
       
   139 
       
   140     CDir* dirList  = NULL;
       
   141 
       
   142     TBuf<KMaxFileName> path(aDrive);
       
   143 
       
   144     if(aDrive == KDriveC)
       
   145         {
       
   146         path.Append(_L("data\\"));
       
   147         }
       
   148 
       
   149     path.Append(_L("*.*"));
       
   150 
       
   151     if( !iFsSession.IsValidDrive(EDriveE) )
       
   152         {
       
   153         User::Leave( KErrNotSupported );
       
   154         }
       
   155 
       
   156     if ( iFsSession.GetDir( path, KEntryAttMatchExclude|KEntryAttDir, ESortByName, dirList ) == KErrNone )
       
   157         {
       
   158         CleanupStack::PushL( dirList );
       
   159 
       
   160         for ( TInt file = 0; file < dirList->Count(); file++ )
       
   161             {
       
   162             HBufC* fileName = HBufC::NewL(KMaxFileName);
       
   163             CleanupStack::PushL( fileName );
       
   164 
       
   165             fileName->Des().Append(aDrive);
       
   166             fileName->Des().Append((*dirList)[file].iName);
       
   167 
       
   168             if(fileName->Des().FindF( _L("mobilecrash") ) >= 0)
       
   169                 {
       
   170                 CleanupStack::Pop( fileName );
       
   171                 aCrashes.Append(fileName);
       
   172                 }
       
   173             else
       
   174                 {
       
   175                 CleanupStack::PopAndDestroy( fileName );
       
   176                 }
       
   177             }
       
   178         CleanupStack::PopAndDestroy( dirList );
       
   179         }
       
   180 
       
   181     VCXLOGLO1("<<<CIptvTestMobilecrashWatcher::ReadMobilecrashes");
       
   182 	}
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CIptvTestMobilecrashWatcher::CompareMobilecrashesL()
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 EXPORT_C TBool CIptvTestMobilecrashWatcher::CompareMobilecrashesL(RPointerArray<HBufC>& aCrashesBefore, RPointerArray<HBufC>& aCrashesNow)
       
   189 	{
       
   190 	VCXLOGLO1(">>>CIptvTestMobilecrashWatcher::CompareMobilecrashesL");
       
   191 	TBool newCrashes = EFalse;
       
   192 
       
   193 	TInt i = 0;
       
   194 	TInt e = 0;
       
   195 
       
   196 	VCXLOGLO2("CIptvTestMobilecrashWatcher:: crash files before: %d", aCrashesBefore.Count());
       
   197 	VCXLOGLO2("CIptvTestMobilecrashWatcher:: crash files now: %d", aCrashesNow.Count());
       
   198 
       
   199 	// remove crashesBefore from crashesNow
       
   200 
       
   201 	// Check is the mobilecrash log in the before array
       
   202 	for(e=0;e<aCrashesBefore.Count();e++)
       
   203 		{
       
   204 		for(i=0; i<aCrashesNow.Count(); i++)
       
   205 			{
       
   206 			TPtrC before = aCrashesBefore[e]->Des();
       
   207 			TPtrC now = aCrashesNow[i]->Des();
       
   208 
       
   209 			if(before == now )
       
   210 				{
       
   211 				HBufC* buf = aCrashesNow[i];
       
   212 				aCrashesNow.Remove(i);
       
   213 				delete buf;
       
   214 				break;
       
   215 				}
       
   216 			}
       
   217 		}
       
   218 
       
   219 	if(aCrashesNow.Count() > 0)
       
   220 		{
       
   221 		newCrashes = ETrue;
       
   222 		VCXLOGLO1("CIptvTestMobilecrashWatcher:: New mobilecrashes:");
       
   223 		for(i=0;i<aCrashesNow.Count(); i++)
       
   224 			{
       
   225 			TPtr16 file = aCrashesNow[i]->Des();
       
   226 			VCXLOGLO2("CIptvTestMobilecrashWatcher:: %S", &file);
       
   227 			}
       
   228 		}
       
   229 
       
   230 	VCXLOGLO1("<<<CIptvTestMobilecrashWatcher::CompareMobilecrashesL");
       
   231 	return newCrashes;
       
   232 	}
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CIptvTestMobilecrashWatcher::CheckNewCrashesL()
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 EXPORT_C void CIptvTestMobilecrashWatcher::CheckNewCrashesL()
       
   239 	{
       
   240 	VCXLOGLO1(">>>CIptvTestMobilecrashWatcher::CheckNewCrashesL");
       
   241 
       
   242 	iCrashesNow.ResetAndDestroy();
       
   243 	TRAP_IGNORE( ReadMobilecrashesL(iCrashesNow, KDriveC) );
       
   244 	TRAP_IGNORE( ReadMobilecrashesL(iCrashesNow, KDriveE) );
       
   245 	TRAP_IGNORE( ReadMobilecrashesL(iCrashesNow, KDriveF) );
       
   246 	if( CompareMobilecrashesL(iCrashesBefore, iCrashesNow) )
       
   247 		{
       
   248 		VCXLOGLO1("CIptvTestMobilecrashWatcher:: * ERROR * There's new mobilecrashes, panicing!");
       
   249 		User::Panic(_L("New mobilecrash log"), KErrGeneral);
       
   250 		}
       
   251 
       
   252 	VCXLOGLO1("<<<CIptvTestMobilecrashWatcher::CheckNewCrashesL");
       
   253 	}
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CIptvTestMobilecrashWatcher::ReturnNewCrashes()
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 EXPORT_C TBool CIptvTestMobilecrashWatcher::ReturnNewCrashes(RPointerArray<HBufC>& aArray)
       
   260 	{
       
   261 	VCXLOGLO1(">>>CIptvTestMobilecrashWatcher::CheckNewCrashesL");
       
   262 
       
   263 	aArray.ResetAndDestroy();
       
   264 	TRAP_IGNORE( ReadMobilecrashesL(aArray, KDriveC) );
       
   265 	TRAP_IGNORE( ReadMobilecrashesL(aArray, KDriveE) );
       
   266 	TRAP_IGNORE( ReadMobilecrashesL(aArray, KDriveF) );
       
   267 	TBool newCrashes = CompareMobilecrashesL(iCrashesBefore, aArray);
       
   268 	if( newCrashes )
       
   269 		{
       
   270 		VCXLOGLO1("CIptvTestMobilecrashWatcher:: * ERROR * There's new mobilecrashes!");
       
   271 		}
       
   272 
       
   273 	VCXLOGLO1("<<<CIptvTestMobilecrashWatcher::CheckNewCrashesL");
       
   274 	return newCrashes;
       
   275 	}
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CIptvTestMobilecrashWatcher::ReturnMobileCrashCount()
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 EXPORT_C TInt CIptvTestMobilecrashWatcher::ReturnMobileCrashCount()
       
   282 	{
       
   283 	VCXLOGLO1(">>>CIptvTestMobilecrashWatcher::ReturnMobileCrashCount");
       
   284 
       
   285     RPointerArray<HBufC> array;
       
   286 
       
   287     array.ResetAndDestroy();
       
   288     TRAP_IGNORE( ReadMobilecrashesL(array, KDriveC) );
       
   289     TRAP_IGNORE( ReadMobilecrashesL(array, KDriveE) );
       
   290     TRAP_IGNORE( ReadMobilecrashesL(array, KDriveF) );
       
   291 	TInt count = array.Count();
       
   292 	array.ResetAndDestroy();
       
   293 
       
   294 	VCXLOGLO1("<<<CIptvTestMobilecrashWatcher::ReturnMobileCrashCount");
       
   295 	return count;
       
   296 	}
       
   297 
       
   298 // ---------------------------------
       
   299 //  End of File