guestrendering/vghwserialiser/inc/serializedfunctioncall.h
branchbug235_bringup_0
changeset 51 4f400a6ea71f
parent 49 3b4f7e9d873f
child 52 39e5f73667ba
equal deleted inserted replaced
49:3b4f7e9d873f 51:4f400a6ea71f
     1 // Copyright (c) 2010 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 "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 
       
    15 #ifndef SERIALIZEDFUNCTIONCALL_H_
       
    16 #define SERIALIZEDFUNCTIONCALL_H_
       
    17 
       
    18 #include "serializerplatform.h"
       
    19 
       
    20 class RemoteFunctionCallData;
       
    21 //Copy operations for simple and array parameters
       
    22 class MDataCopier
       
    23     {
       
    24 public:
       
    25     virtual TInt CopyData( TUint8* aDest, const TUint8* aSource, TUint32 aSize ) = 0; 
       
    26     virtual TInt CopyVector( TUint8* aDest, const TUint8* aSource, TUint32 aSize ) = 0;
       
    27     };
       
    28 
       
    29 /**
       
    30  * Serialized function call.
       
    31  * Serializes the parameters to a given memory location. 
       
    32  */ 
       
    33 class SerializedFunctionCall
       
    34     {
       
    35 public:    
       
    36     
       
    37     //Parse error
       
    38     enum TError
       
    39         {
       
    40         ESuccess,
       
    41         EMoreData,
       
    42         EParseError
       
    43         };
       
    44     
       
    45     //Parse state
       
    46     enum TParseState
       
    47         {
       
    48         EReadingApiUid,
       
    49         EReadingOpCode,
       
    50         EReadingTransactionId,
       
    51         EReadingParameterCount,
       
    52         EReadingProcessId,
       
    53         EReadingThreadId,
       
    54         EReadingOpType,
       
    55         EReadingReturnValue,
       
    56         EReadingParamDir,
       
    57         EReadingParamType,
       
    58         EReadingSimpleParamType,
       
    59         EReadingSimpleParamData,
       
    60         EReadingVectorParamType,
       
    61         EReadingVectorParamDataSize,
       
    62         EReadingVectorParamVectorLength,
       
    63         EReadingVectorParamCallerAddress,
       
    64         EReadingVectorParamData,
       
    65         EReadingDone
       
    66         };
       
    67     
       
    68     //Constructor
       
    69 	SER_IMPORT_C SerializedFunctionCall( RemoteFunctionCallData& aRFC, MDataCopier* aDataCopier = NULL );
       
    70 
       
    71     SER_IMPORT_C void SetDataCopier( MDataCopier* aDataCopier );
       
    72 
       
    73     //Parses a serialized function call. Updates parameter array and utilises data copier to
       
    74     // copy array parameters
       
    75     SER_IMPORT_C TInt ParseBuffer( const TUint8* aBuffer, const TInt aBufferLength );
       
    76         
       
    77     //Serializes function call to a stream.
       
    78     SER_IMPORT_C TInt WriteToBuffer( TUint8* aBuffer, const TInt aStreamMaxLength, TInt aOffset = 0 );
       
    79     
       
    80 private:
       
    81 
       
    82     //Writes header to stream
       
    83     TInt WriteHeaderToBuffer( TUint8* aBuffer, const TInt aStreamMaxLength, TInt aOffset = 0 );
       
    84 
       
    85     //Reads header from buffer
       
    86     TInt ReadHeaderFromBuffer( const TUint8* aBuffer, const TInt aBufferLength );
       
    87 
       
    88     //Writes a data. Accounts destination buffer overflow and can continue write
       
    89     // from a given offset
       
    90     TInt Write( TUint8* aDest, TInt& aDestIndex, const TInt aDestSize,
       
    91             const TUint8* aSource, const TInt aSize, TInt& aSourceIndex, 
       
    92             const TInt aOffset, TBool aVector );
       
    93     
       
    94     //Serializes a simple param to a current stream
       
    95     TInt WriteParam( const TUint8* aParam, const TInt aParamSize );
       
    96 
       
    97     //Serializes an array param to a current stream
       
    98     //TInt WriteVector( const TUint8* aParam, const TInt aParamSize );
       
    99 	TInt WriteVector( const TUint8* aParam, const TInt32 aDataTypeSize, const TInt aVectorSize, const TInt8 aDataTypeAlignment );
       
   100 
       
   101     //Initialises write state
       
   102     void StartWrite( TUint8* aBuffer, const TInt aStreamMaxLength, TInt aOffset = 0 );
       
   103     
       
   104     //Gets a direct pointer to the stream data for an array parameter
       
   105 	//TUint8* ReadVector( const TInt aParamSize );
       
   106 	TUint8* ReadVectorPointer( const TInt32 aDataTypeSize, const TInt aVectorSize, const TInt8 aDataTypeAlignment );
       
   107 	
       
   108 	//Reads simple parameter from a stream
       
   109     TInt ReadParam( TUint8* aParam, const TInt aParamSize );
       
   110     
       
   111     //Reads an array parameter from a stream and utilises data copier for data transfer
       
   112 	//TInt ReadVectorParam( TUint8* aParam, const TInt aParamSize );
       
   113 	TInt ReadVectorParam( TUint8* aParam, const TInt32 aDataTypeSize, const TInt aVectorSize, const TInt8 aDataTypeAlignment );
       
   114 
       
   115     //Reads a data. Accounts source buffer overflow and can continue read
       
   116     // from a given offset
       
   117 	TInt Read( TUint8* aDest, TInt& aDestIndex, const TInt aDestSize,
       
   118             const TUint8* aSource, TInt& aSourceIndex, const TInt aSourceSize, TBool aVector );
       
   119 
       
   120     //Initialises a read state
       
   121     void StartRead( const TUint8* aBuffer, const TInt aBufferLength );
       
   122 
       
   123     //Last error
       
   124     TError GetLastError() { return iError; }
       
   125 
       
   126 	RemoteFunctionCallData& GetRemoteFunctionCall() { return iRFC; }
       
   127 
       
   128 private:
       
   129 	RemoteFunctionCallData& iRFC;
       
   130     MDataCopier* iDataCopier;
       
   131 
       
   132     TError iError;
       
   133 
       
   134 	struct WriteState
       
   135 		{
       
   136 		//Write state
       
   137 		TUint8* iBuffer;
       
   138 		TInt iDestIndex;
       
   139 		TInt iStreamMaxLength;
       
   140 		TInt iSourceIndex;
       
   141 		TInt iOffset;        
       
   142 		};
       
   143 
       
   144 	struct ReadState
       
   145 		{
       
   146 		//Read state
       
   147 		TInt iReadDestOffset;
       
   148 		const TUint8* iReadBuffer;
       
   149 		TInt iReadBufferIndex;
       
   150 		TInt iReadBufferLength;
       
   151 		TParseState iParseState;
       
   152 		TInt iParamsIndex;
       
   153 		};
       
   154 
       
   155 	union 
       
   156 		{
       
   157 		WriteState iWriteState;
       
   158 		ReadState iReadState;
       
   159 		};
       
   160 
       
   161 	};
       
   162 
       
   163 #endif