author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
sl@0 | 2 |
// All rights reserved. |
sl@0 | 3 |
// This component and the accompanying materials are made available |
sl@0 | 4 |
// under the terms of the License "Eclipse Public License v1.0" |
sl@0 | 5 |
// which accompanies this distribution, and is available |
sl@0 | 6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
sl@0 | 7 |
// |
sl@0 | 8 |
// Initial Contributors: |
sl@0 | 9 |
// Nokia Corporation - initial contribution. |
sl@0 | 10 |
// |
sl@0 | 11 |
// Contributors: |
sl@0 | 12 |
// |
sl@0 | 13 |
// Description: |
sl@0 | 14 |
// e32\debug\crashMonitor\src\scmlockdata.cpp |
sl@0 | 15 |
// some utility classes for writing data to flash buffer |
sl@0 | 16 |
// |
sl@0 | 17 |
// |
sl@0 | 18 |
|
sl@0 | 19 |
/** |
sl@0 | 20 |
@file |
sl@0 | 21 |
@internalTechnology |
sl@0 | 22 |
*/ |
sl@0 | 23 |
|
sl@0 | 24 |
|
sl@0 | 25 |
#include <scmdatatypes.h> |
sl@0 | 26 |
|
sl@0 | 27 |
namespace Debug |
sl@0 | 28 |
{ |
sl@0 | 29 |
|
sl@0 | 30 |
/** |
sl@0 | 31 |
* TSCMLockData constructor |
sl@0 | 32 |
* @param none |
sl@0 | 33 |
*/ |
sl@0 | 34 |
TSCMLockData::TSCMLockData() |
sl@0 | 35 |
: iId(ESCMLocks) |
sl@0 | 36 |
, iMutexHoldCount(-1) |
sl@0 | 37 |
, iMutexThreadWaitCount(-1) |
sl@0 | 38 |
{ |
sl@0 | 39 |
} |
sl@0 | 40 |
|
sl@0 | 41 |
/** |
sl@0 | 42 |
* TSCMLockData Serialize |
sl@0 | 43 |
* @param aWriter byte stream to use |
sl@0 | 44 |
* @return N/A |
sl@0 | 45 |
*/ |
sl@0 | 46 |
TInt TSCMLockData::Serialize(TByteStreamWriter& aWriter) |
sl@0 | 47 |
{ |
sl@0 | 48 |
TInt startPos = aWriter.CurrentPosition(); |
sl@0 | 49 |
|
sl@0 | 50 |
// ID saved first |
sl@0 | 51 |
if(iId != ESCMLocks) |
sl@0 | 52 |
{ |
sl@0 | 53 |
CLTRACE("TSCMLockData::Serialize Corrupt ID"); |
sl@0 | 54 |
return KErrCorrupt; |
sl@0 | 55 |
} |
sl@0 | 56 |
|
sl@0 | 57 |
// write id first |
sl@0 | 58 |
aWriter.WriteInt(iId); // 4 |
sl@0 | 59 |
// 2 counts written as shorts (should be enough range!) |
sl@0 | 60 |
aWriter.WriteShort((TInt16) iMutexHoldCount); // 2 |
sl@0 | 61 |
aWriter.WriteShort((TInt16) iMutexThreadWaitCount); // 2 |
sl@0 | 62 |
aWriter.WriteShort((TInt16) iLockCount); // 2 |
sl@0 | 63 |
|
sl@0 | 64 |
|
sl@0 | 65 |
TInt endPos = aWriter.CurrentPosition(); |
sl@0 | 66 |
if( endPos - startPos != GetSize()) |
sl@0 | 67 |
{ |
sl@0 | 68 |
// error between actual size & real size in data |
sl@0 | 69 |
CLTRACE("TSCMLockData::Serialize serialization size error"); |
sl@0 | 70 |
return KErrCorrupt; |
sl@0 | 71 |
} |
sl@0 | 72 |
|
sl@0 | 73 |
return KErrNone; |
sl@0 | 74 |
} |
sl@0 | 75 |
|
sl@0 | 76 |
/** |
sl@0 | 77 |
* Reads the classes data from the specified byte stream |
sl@0 | 78 |
* @param aReader Byte stream to use |
sl@0 | 79 |
* @return void |
sl@0 | 80 |
*/ |
sl@0 | 81 |
TInt TSCMLockData::Deserialize(TByteStreamReader& aReader) |
sl@0 | 82 |
{ |
sl@0 | 83 |
TInt startPos = aReader.CurrentPosition(); |
sl@0 | 84 |
|
sl@0 | 85 |
iId = (SCMStructId)aReader.ReadInt(); // 4 |
sl@0 | 86 |
if(iId != ESCMLocks) |
sl@0 | 87 |
{ |
sl@0 | 88 |
CLTRACE("TSCMLockData::Deserialize Corrupt ID read"); |
sl@0 | 89 |
return KErrCorrupt; |
sl@0 | 90 |
} |
sl@0 | 91 |
|
sl@0 | 92 |
iMutexHoldCount = (TInt) aReader.ReadShort(); |
sl@0 | 93 |
iMutexThreadWaitCount = (TInt) aReader.ReadShort(); |
sl@0 | 94 |
iLockCount = (TInt) aReader.ReadShort(); |
sl@0 | 95 |
|
sl@0 | 96 |
|
sl@0 | 97 |
TInt endPos = aReader.CurrentPosition(); |
sl@0 | 98 |
if( endPos - startPos != GetSize()) |
sl@0 | 99 |
{ |
sl@0 | 100 |
CLTRACE("TSCMLockData::Deserialize size error"); |
sl@0 | 101 |
return KErrCorrupt; |
sl@0 | 102 |
} |
sl@0 | 103 |
return KErrNone; |
sl@0 | 104 |
} |
sl@0 | 105 |
|
sl@0 | 106 |
/** |
sl@0 | 107 |
* Returns the externalised size of this class |
sl@0 | 108 |
* @return TInt size |
sl@0 | 109 |
*/ |
sl@0 | 110 |
TInt TSCMLockData::GetSize() const |
sl@0 | 111 |
{ |
sl@0 | 112 |
return KSCMLockDataMaxSize; |
sl@0 | 113 |
} |
sl@0 | 114 |
|
sl@0 | 115 |
/** |
sl@0 | 116 |
* MutexHoldCount |
sl@0 | 117 |
* @param none |
sl@0 | 118 |
* @return mutex hold count |
sl@0 | 119 |
*/ |
sl@0 | 120 |
TInt TSCMLockData::MutexHoldCount() const |
sl@0 | 121 |
{ |
sl@0 | 122 |
return iMutexHoldCount; |
sl@0 | 123 |
} |
sl@0 | 124 |
|
sl@0 | 125 |
/** |
sl@0 | 126 |
* SetMutexHoldCount |
sl@0 | 127 |
* @param |
sl@0 | 128 |
* @return |
sl@0 | 129 |
*/ |
sl@0 | 130 |
void TSCMLockData::SetMutexHoldCount(TInt aMutexHoldCount) |
sl@0 | 131 |
{ |
sl@0 | 132 |
iMutexHoldCount = aMutexHoldCount; |
sl@0 | 133 |
} |
sl@0 | 134 |
|
sl@0 | 135 |
/** |
sl@0 | 136 |
* MutexThreadWaitCount |
sl@0 | 137 |
* @param none |
sl@0 | 138 |
* @return number of threads waiting on held mutex - will only be valid if |
sl@0 | 139 |
* MutexHoldCount > 0 |
sl@0 | 140 |
*/ |
sl@0 | 141 |
TInt TSCMLockData::MutexThreadWaitCount() const |
sl@0 | 142 |
{ |
sl@0 | 143 |
return iMutexThreadWaitCount; |
sl@0 | 144 |
} |
sl@0 | 145 |
|
sl@0 | 146 |
/** |
sl@0 | 147 |
* SetMutexThreadWaitCount |
sl@0 | 148 |
* @param TInt - number of threads waiting on held mutex(es) |
sl@0 | 149 |
* @return void |
sl@0 | 150 |
*/ |
sl@0 | 151 |
void TSCMLockData::SetMutexThreadWaitCount(TInt aMutexThreadWaitCount) |
sl@0 | 152 |
{ |
sl@0 | 153 |
iMutexThreadWaitCount = aMutexThreadWaitCount; |
sl@0 | 154 |
} |
sl@0 | 155 |
|
sl@0 | 156 |
/** |
sl@0 | 157 |
* LockCount |
sl@0 | 158 |
* @param none |
sl@0 | 159 |
* @return TIOnt - the lock count |
sl@0 | 160 |
*/ |
sl@0 | 161 |
TInt TSCMLockData::LockCount() const |
sl@0 | 162 |
{ |
sl@0 | 163 |
return iLockCount; |
sl@0 | 164 |
} |
sl@0 | 165 |
|
sl@0 | 166 |
/** |
sl@0 | 167 |
* SetLockCount |
sl@0 | 168 |
* @param TInt - number of locks held |
sl@0 | 169 |
* @return void |
sl@0 | 170 |
*/ |
sl@0 | 171 |
void TSCMLockData::SetLockCount(TInt aLockCount) |
sl@0 | 172 |
{ |
sl@0 | 173 |
iLockCount = aLockCount; |
sl@0 | 174 |
} |
sl@0 | 175 |
|
sl@0 | 176 |
TBool TSCMLockData::operator == (const TSCMLockData& aOther) const |
sl@0 | 177 |
{ |
sl@0 | 178 |
return ( iId == aOther.iId && |
sl@0 | 179 |
iMutexHoldCount == aOther.iMutexHoldCount && |
sl@0 | 180 |
iMutexThreadWaitCount == aOther.iMutexThreadWaitCount && |
sl@0 | 181 |
iLockCount == aOther.iLockCount ); |
sl@0 | 182 |
} |
sl@0 | 183 |
|
sl@0 | 184 |
TBool TSCMLockData::operator != (const TSCMLockData& aOther) const |
sl@0 | 185 |
{ |
sl@0 | 186 |
return !(*this == aOther); |
sl@0 | 187 |
} |
sl@0 | 188 |
} |
sl@0 | 189 |
|
sl@0 | 190 |