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