os/kernelhwsrv/kernel/eka/debug/crashMonitor/src/scmprocessdata.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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\scmprocessdata.cpp
    15 // Core dump server - Process 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 	 * TProcessData implementation
    30 	 * @internal technology
    31 	 */
    32 	
    33 	/**
    34 	 * TProcessData constructor
    35 	 */
    36 	TProcessData::TProcessData()
    37 		:iId(ESCMProcessData)
    38 		,iVersion(EProcData1)				
    39 		,iPid(0)
    40 		,iNamesize(0)
    41 		,iPriority(0)
    42 		,iSpare1(0)
    43 		,iSpare2(0)	
    44 		,iSpare3(0)
    45 		{
    46 		}
    47 	
    48 	/**
    49 	 * Writes this classes data to the specified byte stream
    50 	 * @param aWriter byte stream to use
    51 	 * @return One of the OS wide codes
    52 	 */	 
    53 	TInt TProcessData::Serialize(TByteStreamWriter& aWriter)
    54 		{
    55 		TInt startPos = aWriter.CurrentPosition();
    56 		
    57 		// ID saved first 
    58 		aWriter.WriteInt(iId);		 				// 4
    59 		
    60 		if(iId != ESCMProcessData)
    61 			{
    62 			CLTRACE("TProcessData::Serialize Corrupt ID");
    63 			return KErrCorrupt;
    64 			}
    65 		
    66 		aWriter.WriteShort((TUint16) iVersion);			// 2
    67 
    68 		if(iVersion == EProcData1)
    69 			{
    70 			// write data v1 format				
    71 			aWriter.WriteInt(iPriority); 			 	// 4
    72 			aWriter.WriteInt64(iPid);  					// 8
    73 			if(iName.Ptr())
    74 				{
    75 				aWriter.WriteInt(iName.Length());		// 4
    76 				for(TInt cnt = 0; cnt < iName.Length(); cnt++)
    77 					{
    78 					aWriter.WriteByte(iName[cnt]);
    79 					}
    80 				}
    81 			else
    82 				{
    83 				aWriter.WriteInt(0);
    84 				}
    85 
    86 
    87 			}
    88 		else
    89 			{
    90 			CLTRACE("TProcessData::Serialize Unsupported version");
    91 			return KErrCorrupt;
    92 			}
    93 		
    94 		TInt endPos = aWriter.CurrentPosition();
    95 		if( endPos - startPos != GetSize())
    96 			{
    97 			// error between actual size & real size in data
    98 			CLTRACE2("TProcessData::Serialize serialization size error. Wrote [%d] but expected [%d]", endPos - startPos, GetSize());
    99 			return KErrCorrupt;
   100 			}
   101 		return KErrNone;
   102 		}				
   103 		
   104 	/**
   105 	 * Reads the classes data from the specified byte stream
   106 	 * @param aReader Byte stream to use
   107 	 * @return One of the OS wide codes
   108 	 */
   109 	TInt TProcessData::Deserialize(TByteStreamReader& aReader)
   110 		{
   111 		TInt startPos = aReader.CurrentPosition();
   112 		
   113 		iId = (SCMStructId)aReader.ReadInt();		 				// 4
   114 		if(iId != ESCMProcessData)
   115 			{
   116 			CLTRACE("TProcessData::Deserialize failed - Read corrupt ID");
   117 			return KErrCorrupt;
   118 			}
   119 		
   120 		iVersion = (TProcessDataVersion)aReader.ReadShort();			// 2
   121 
   122 		if(iVersion == EProcData1)
   123 			{
   124 			// read data v1 format						
   125 			iPriority = aReader.ReadInt(); 			 	    // 4		
   126 			iPid = aReader.ReadInt64();						// 8
   127 			
   128 			iNamesize = aReader.ReadInt();					// 4			
   129 			
   130 			if(iName.Ptr() && iName.MaxLength() >= (TInt)iNamesize)
   131 				{
   132 				iName.SetLength(0);
   133 				
   134 				for(TUint cnt = 0; cnt < iNamesize; cnt++)
   135 					{
   136 					iName.Append(aReader.ReadByte());		//iCategorySize bytes
   137 					} 
   138 				}
   139 			
   140 
   141 			}
   142 		else
   143 			{
   144 			iId = ESCMLast;	//unrecognised header
   145 			CLTRACE("TProcessData::Deserialize Unsupported version");
   146 			return KErrCorrupt;
   147 			}
   148 		
   149 		TInt endPos = aReader.CurrentPosition();
   150 		if( endPos - startPos != GetSize())
   151 			{
   152 			iId = ESCMLast;	//unrecognised header
   153 			
   154 			// error between actual size & real size in data
   155 			CLTRACE("TProcessData::Deserialize serialization size error");
   156 			return KErrCorrupt;			
   157 			}
   158 		return KErrNone;
   159 		}
   160 	
   161 	/**
   162 	 * Returns the externalised size of this class
   163 	 * @return TInt size
   164 	 */
   165 	TInt TProcessData::GetSize() const
   166 		{
   167 		if(iVersion == EProcData1)
   168 			{
   169 			return 22 + iName.Length();
   170 			}
   171 		else
   172 			{
   173 			CLTRACE("TProcessData::GetSize Unsupported version");			
   174 			return KErrNotSupported;		
   175 			}
   176 		}
   177 	
   178 	}