sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\debug\crashMonitor\src\scmthreaddata.cpp sl@0: // Core dump server - Thread Data for System Crash sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #include sl@0: sl@0: namespace Debug sl@0: { sl@0: /** sl@0: * TThreadData implementation sl@0: * @internal technology sl@0: */ sl@0: sl@0: /** sl@0: * TThreadData constructor sl@0: */ sl@0: TThreadData::TThreadData() sl@0: : iId(ESCMThreadData) sl@0: ,iVersion(EThreadData1) sl@0: ,iPriority(0) sl@0: ,iTid(0) sl@0: ,iOwnerId(0) sl@0: ,iSvcSP(0) sl@0: ,iSvcStack(0) sl@0: ,iSvcStacksize(0) sl@0: ,iUsrSP(0) sl@0: ,iUsrStack(0) sl@0: ,iUsrStacksize(0) sl@0: ,iNamesize(0) sl@0: ,iLastCpu(0) sl@0: ,iSvcHeap(0) sl@0: ,iSvcHeapSize(0) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Writes this classes data to the specified byte stream sl@0: * @param aWriter byte stream to use sl@0: * @return void sl@0: */ sl@0: TInt TThreadData::Serialize(TByteStreamWriter& aWriter) sl@0: { sl@0: TInt startPos = aWriter.CurrentPosition(); sl@0: sl@0: if(iId != ESCMThreadData) sl@0: { sl@0: CLTRACE("TThreadData::Serialize Corrupt ID"); sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: // ID saved first sl@0: aWriter.WriteInt(iId); // 4 sl@0: sl@0: aWriter.WriteShort((TUint16) iVersion); // 2 sl@0: sl@0: if(iVersion == EThreadData1) sl@0: { sl@0: // write data v1 format sl@0: aWriter.WriteInt(iPriority); // 4 sl@0: aWriter.WriteInt64(iTid); // 8 sl@0: aWriter.WriteInt64(iOwnerId); // 8 sl@0: aWriter.WriteInt(iSvcSP); // 4 sl@0: aWriter.WriteInt(iSvcStack); // 4 sl@0: aWriter.WriteInt(iSvcStacksize); // 4 sl@0: aWriter.WriteInt(iUsrSP); // 4 sl@0: aWriter.WriteInt(iUsrStack); // 4 sl@0: aWriter.WriteInt(iUsrStacksize); // 4 sl@0: aWriter.WriteInt(iLastCpu); // 4 sl@0: aWriter.WriteInt(iSvcHeap); // 4 sl@0: aWriter.WriteInt(iSvcHeapSize); // 4 sl@0: if(iName.Ptr()) sl@0: { sl@0: aWriter.WriteInt(iName.Length()); // 4 sl@0: for(TInt cnt = 0; cnt < iName.Length(); cnt++) sl@0: { sl@0: aWriter.WriteByte(iName[cnt]); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: aWriter.WriteInt(0); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: CLTRACE("TThreadData::Serialize Unsupported version"); sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: TInt endPos = aWriter.CurrentPosition(); sl@0: if( endPos - startPos != GetSize()) sl@0: { sl@0: // error between actual size & real size in data sl@0: CLTRACE("TThreadData::Serialize serialization size error"); sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: * Reads the classes data from the specified byte stream sl@0: * @param aReader Byte stream to use sl@0: * @return void sl@0: */ sl@0: TInt TThreadData::Deserialize(TByteStreamReader& aReader) sl@0: { sl@0: TInt startPos = aReader.CurrentPosition(); sl@0: sl@0: iId = (SCMStructId)aReader.ReadInt(); // 4 sl@0: if(iId != ESCMThreadData) sl@0: { sl@0: CLTRACE("TThreadData::Deserialize Corrupt ID read"); sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: iVersion = (TThreadDataVersion)aReader.ReadShort(); // 2 sl@0: sl@0: if(iVersion == EThreadData1) sl@0: { sl@0: // read data v1 format sl@0: iPriority = aReader.ReadInt(); // 4 sl@0: iTid = aReader.ReadInt64(); // 8 sl@0: iOwnerId = aReader.ReadInt64(); // 8 sl@0: iSvcSP = aReader.ReadInt(); // 4 sl@0: iSvcStack = aReader.ReadInt(); // 4 sl@0: iSvcStacksize = aReader.ReadInt(); // 4 sl@0: iUsrSP = aReader.ReadInt(); // 4 sl@0: iUsrStack = aReader.ReadInt(); // 4 sl@0: iUsrStacksize = aReader.ReadInt(); // 4 sl@0: iLastCpu = aReader.ReadInt(); // 4 sl@0: iSvcHeap = aReader.ReadInt(); // 4 sl@0: iSvcHeapSize = aReader.ReadInt(); // 4 sl@0: sl@0: iNamesize = aReader.ReadInt(); // 4 sl@0: sl@0: if(iName.Ptr() && iName.MaxLength() >= (TInt)iNamesize) sl@0: { sl@0: iName.SetLength(0); sl@0: sl@0: for(TUint cnt = 0; cnt < iNamesize; cnt++) sl@0: { sl@0: iName.Append(aReader.ReadByte()); //iNamesize bytes sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: iId = ESCMLast; //unrecognised header sl@0: CLTRACE("TThreadData::Deserialize Unsupported version"); sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: TInt endPos = aReader.CurrentPosition(); sl@0: if( endPos - startPos != GetSize()) sl@0: { sl@0: iId = ESCMLast; //unrecognised header sl@0: sl@0: // error between actual size & real size in data sl@0: CLTRACE("TThreadData::Deserialize serialization size error"); sl@0: return KErrCorrupt; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: * Returns the externalised size of this class sl@0: * @return TInt size sl@0: */ sl@0: TInt TThreadData::GetSize() const sl@0: { sl@0: if(iVersion == EThreadData1) sl@0: { sl@0: return 66 + iName.Length(); sl@0: } sl@0: else sl@0: { sl@0: CLTRACE("TThreadData::GetSize Unsupported version"); sl@0: return KErrNotSupported; sl@0: } sl@0: } sl@0: sl@0: }