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\scmprocessdata.cpp sl@0: // Core dump server - Process 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: * TProcessData implementation sl@0: * @internal technology sl@0: */ sl@0: sl@0: /** sl@0: * TProcessData constructor sl@0: */ sl@0: TProcessData::TProcessData() sl@0: :iId(ESCMProcessData) sl@0: ,iVersion(EProcData1) sl@0: ,iPid(0) sl@0: ,iNamesize(0) sl@0: ,iPriority(0) sl@0: ,iSpare1(0) sl@0: ,iSpare2(0) sl@0: ,iSpare3(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 One of the OS wide codes sl@0: */ sl@0: TInt TProcessData::Serialize(TByteStreamWriter& aWriter) sl@0: { sl@0: TInt startPos = aWriter.CurrentPosition(); sl@0: sl@0: // ID saved first sl@0: aWriter.WriteInt(iId); // 4 sl@0: sl@0: if(iId != ESCMProcessData) sl@0: { sl@0: CLTRACE("TProcessData::Serialize Corrupt ID"); sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: aWriter.WriteShort((TUint16) iVersion); // 2 sl@0: sl@0: if(iVersion == EProcData1) sl@0: { sl@0: // write data v1 format sl@0: aWriter.WriteInt(iPriority); // 4 sl@0: aWriter.WriteInt64(iPid); // 8 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: sl@0: } sl@0: else sl@0: { sl@0: CLTRACE("TProcessData::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: CLTRACE2("TProcessData::Serialize serialization size error. Wrote [%d] but expected [%d]", endPos - startPos, GetSize()); sl@0: return KErrCorrupt; 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 One of the OS wide codes sl@0: */ sl@0: TInt TProcessData::Deserialize(TByteStreamReader& aReader) sl@0: { sl@0: TInt startPos = aReader.CurrentPosition(); sl@0: sl@0: iId = (SCMStructId)aReader.ReadInt(); // 4 sl@0: if(iId != ESCMProcessData) sl@0: { sl@0: CLTRACE("TProcessData::Deserialize failed - Read corrupt ID"); sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: iVersion = (TProcessDataVersion)aReader.ReadShort(); // 2 sl@0: sl@0: if(iVersion == EProcData1) sl@0: { sl@0: // read data v1 format sl@0: iPriority = aReader.ReadInt(); // 4 sl@0: iPid = aReader.ReadInt64(); // 8 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()); //iCategorySize bytes sl@0: } sl@0: } sl@0: sl@0: sl@0: } sl@0: else sl@0: { sl@0: iId = ESCMLast; //unrecognised header sl@0: CLTRACE("TProcessData::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("TProcessData::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 TProcessData::GetSize() const sl@0: { sl@0: if(iVersion == EProcData1) sl@0: { sl@0: return 22 + iName.Length(); sl@0: } sl@0: else sl@0: { sl@0: CLTRACE("TProcessData::GetSize Unsupported version"); sl@0: return KErrNotSupported; sl@0: } sl@0: } sl@0: sl@0: }