kernel/eka/debug/crashMonitor/src/scmthreaddata.cpp
changeset 296 94f2adf59133
parent 293 0659d0e1a03c
child 297 b2826f67641f
equal deleted inserted replaced
293:0659d0e1a03c 296:94f2adf59133
     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\scmthreaddata.cpp
       
    15 // Core dump server - Thread Data for System Crash
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology
       
    22 */
       
    23 
       
    24 #include <scmdatatypes.h>
       
    25 
       
    26 namespace Debug
       
    27 	{
       
    28 	/**
       
    29 	 * TThreadData implementation
       
    30 	 * @internal technology
       
    31 	 */
       
    32 	
       
    33 	/**
       
    34 	 * TThreadData constructor
       
    35 	 */
       
    36 	TThreadData::TThreadData()
       
    37 	: iId(ESCMThreadData)
       
    38 		,iVersion(EThreadData1)
       
    39 		,iPriority(0)
       
    40 		,iTid(0)
       
    41 		,iOwnerId(0)
       
    42 		,iSvcSP(0)
       
    43 		,iSvcStack(0)
       
    44 		,iSvcStacksize(0)
       
    45 		,iUsrSP(0)
       
    46 		,iUsrStack(0)
       
    47 		,iUsrStacksize(0)
       
    48 		,iNamesize(0)
       
    49 		,iLastCpu(0)
       
    50 		,iSvcHeap(0)
       
    51 		,iSvcHeapSize(0)
       
    52 		{			
       
    53 		}
       
    54 	
       
    55 	/**
       
    56 	 * Writes this classes data to the specified byte stream
       
    57 	 * @param aWriter byte stream to use
       
    58 	 * @return void
       
    59 	 */	
       
    60 	TInt TThreadData::Serialize(TByteStreamWriter& aWriter)
       
    61 		{
       
    62 		TInt startPos = aWriter.CurrentPosition();
       
    63 		
       
    64 		if(iId != ESCMThreadData)
       
    65 			{
       
    66 			CLTRACE("TThreadData::Serialize Corrupt ID");
       
    67 			return KErrCorrupt;
       
    68 			}
       
    69 
       
    70 		// ID saved first 
       
    71 		aWriter.WriteInt(iId);		 				    // 4		
       
    72 		
       
    73 		aWriter.WriteShort((TUint16) iVersion);			// 2
       
    74 
       
    75 		if(iVersion == EThreadData1)
       
    76 			{
       
    77 			// write data v1 format					
       
    78 			aWriter.WriteInt(iPriority); 			 	// 4
       
    79 			aWriter.WriteInt64(iTid);  					// 8
       
    80 			aWriter.WriteInt64(iOwnerId);				// 8
       
    81 			aWriter.WriteInt(iSvcSP); 			 		// 4
       
    82 			aWriter.WriteInt(iSvcStack); 			 	// 4
       
    83 			aWriter.WriteInt(iSvcStacksize); 			 	// 4
       
    84 			aWriter.WriteInt(iUsrSP); 			 		// 4
       
    85 			aWriter.WriteInt(iUsrStack); 			 	// 4
       
    86 			aWriter.WriteInt(iUsrStacksize); 			 	// 4			
       
    87 			aWriter.WriteInt(iLastCpu); 			 	// 4
       
    88 			aWriter.WriteInt(iSvcHeap); 			 		// 4
       
    89 			aWriter.WriteInt(iSvcHeapSize); 			 	// 4
       
    90 			if(iName.Ptr())
       
    91 				{
       
    92 				aWriter.WriteInt(iName.Length());		// 4		
       
    93 				for(TInt cnt = 0; cnt < iName.Length(); cnt++)
       
    94 					{
       
    95 					aWriter.WriteByte(iName[cnt]);
       
    96 					}
       
    97 				}
       
    98 			else
       
    99 				{
       
   100 				aWriter.WriteInt(0);
       
   101 				}
       
   102 			}
       
   103 		else
       
   104 			{
       
   105 			CLTRACE("TThreadData::Serialize Unsupported version");
       
   106 			return KErrCorrupt;
       
   107 			}
       
   108 		
       
   109 		TInt endPos = aWriter.CurrentPosition();
       
   110 		if( endPos - startPos != GetSize())
       
   111 			{
       
   112 			// error between actual size & real size in data
       
   113 			CLTRACE("TThreadData::Serialize serialization size error");	
       
   114 			return KErrCorrupt;
       
   115 			}
       
   116 		
       
   117 		return KErrNone;
       
   118 		}
       
   119 	
       
   120 	/**
       
   121 	 * Reads the classes data from the specified byte stream
       
   122 	 * @param aReader Byte stream to use
       
   123 	 * @return void
       
   124 	 */
       
   125 	TInt TThreadData::Deserialize(TByteStreamReader& aReader)
       
   126 		{
       
   127 		TInt startPos = aReader.CurrentPosition();
       
   128 		
       
   129 		iId = (SCMStructId)aReader.ReadInt();					// 4
       
   130 		if(iId != ESCMThreadData)
       
   131 			{
       
   132 			CLTRACE("TThreadData::Deserialize Corrupt ID read");
       
   133 			return KErrCorrupt;
       
   134 			}
       
   135 		
       
   136 		iVersion = (TThreadDataVersion)aReader.ReadShort();			// 2
       
   137 
       
   138 		if(iVersion == EThreadData1)
       
   139 			{
       
   140 			// read data v1 format	
       
   141 			iPriority = aReader.ReadInt();		 				// 4		
       
   142 			iTid = aReader.ReadInt64(); 			 	    	// 8		
       
   143 			iOwnerId = aReader.ReadInt64();						// 8
       
   144 			iSvcSP = aReader.ReadInt();							// 4
       
   145 			iSvcStack = aReader.ReadInt();						// 4
       
   146 			iSvcStacksize = aReader.ReadInt();					// 4
       
   147 			iUsrSP = aReader.ReadInt();							// 4
       
   148 			iUsrStack = aReader.ReadInt();						// 4
       
   149 			iUsrStacksize = aReader.ReadInt();					// 4
       
   150 			iLastCpu = aReader.ReadInt();						// 4
       
   151 			iSvcHeap = aReader.ReadInt();	 			 		// 4
       
   152 			iSvcHeapSize = aReader.ReadInt();	 			 		// 4
       
   153 			
       
   154 			iNamesize = aReader.ReadInt();						// 4
       
   155 						
       
   156 			if(iName.Ptr() && iName.MaxLength() >= (TInt)iNamesize)
       
   157 				{
       
   158 				iName.SetLength(0);
       
   159 				
       
   160 				for(TUint cnt = 0; cnt < iNamesize; cnt++)
       
   161 					{
       
   162 					iName.Append(aReader.ReadByte());		//iNamesize bytes
       
   163 					} 
       
   164 				}	
       
   165 			}
       
   166 		else
       
   167 			{
       
   168 			iId = ESCMLast;	//unrecognised header
       
   169 			CLTRACE("TThreadData::Deserialize Unsupported version");
       
   170 			return KErrCorrupt;
       
   171 			}
       
   172 		
       
   173 		TInt endPos = aReader.CurrentPosition();
       
   174 		if( endPos - startPos != GetSize())
       
   175 			{
       
   176 			iId = ESCMLast;	//unrecognised header
       
   177 			
       
   178 			// error between actual size & real size in data
       
   179 			CLTRACE("TThreadData::Deserialize serialization size error");	
       
   180 			return KErrCorrupt;
       
   181 			}
       
   182 		return KErrNone;
       
   183 		}
       
   184 	
       
   185 	/**
       
   186 	 * Returns the externalised size of this class
       
   187 	 * @return TInt size
       
   188 	 */
       
   189 	TInt TThreadData::GetSize() const
       
   190 		{
       
   191 		if(iVersion == EThreadData1)
       
   192 			{
       
   193 			return 66 + iName.Length();
       
   194 			}
       
   195 		else
       
   196 			{
       
   197 			CLTRACE("TThreadData::GetSize Unsupported version");			
       
   198 			return KErrNotSupported;		
       
   199 			}
       
   200 		}
       
   201 	
       
   202 	}