vghwinterface/vghwserialiser/src/remotefunctioncall.cpp
branchbug235_bringup_0
changeset 51 4f400a6ea71f
parent 7 ec0e558822c5
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 #include "remotefunctioncall.h"
       
    16 
       
    17 // Symbian User mode Panic & debugging information
       
    18 #if defined(__SYMBIAN32__) && !defined(__KERNEL_MODE__)
       
    19 #define USE_SYMBIAN_CLIENT_PANICS
       
    20 #include <e32debug.h>
       
    21 #include "serialisedapiuids.h"
       
    22 // Guest Serialiser panic codes
       
    23 typedef enum
       
    24 	{
       
    25 	ESerPanicMaxParamCountExceeded=1,
       
    26 	ESerPanicRequestOperationHasOutParameter,
       
    27 	ESerPanicVectorPtrIsNull,
       
    28 	ESerPanicVectorSizeIsNegative,
       
    29 	} TSerialiserPanic;
       
    30 
       
    31 _LIT(KSerialiserPanicCategory, "Vghw Ser");
       
    32 
       
    33 #ifdef _DEBUG
       
    34 	#define VGSERPANIC_ASSERT(condition, panic, api, opcode, pcount) if (!(condition)) \
       
    35 			{ SerialiserPanic(panic, #condition, __FILE__, __LINE__, api, opcode, pcount); }
       
    36 #else
       
    37 	#define VGSERPANIC_ASSERT(condition, panic, api, opcode, pcount) if (!(condition)) \
       
    38 			{ SerialiserPanic(panic, NULL, NULL, __LINE__, api, opcode, pcount); }
       
    39 #endif
       
    40 
       
    41 void SerialiserPanic(TSerialiserPanic aPanicCode, char* aCondition, char* aFile, TInt aLine, TInt32 aApiUid, TInt32 aOpcode, TInt32 aParamCount)
       
    42 	{
       
    43 	if (aCondition && aFile)
       
    44 		{
       
    45 		RDebug::Printf("Vghw Serialiser Panic %d for failed Assert (%s), at %s:%d", aPanicCode, aCondition, aFile, aLine);
       
    46 		}
       
    47 	else
       
    48 		{  
       
    49 		RDebug::Printf("Vghw Serialiser Panic %d for failed Assert (line %d)", aPanicCode, aLine);
       
    50 		}
       
    51 		
       
    52 	switch (aApiUid)
       
    53 		{
       
    54 		case SERIALISED_EGL_API_UID:
       
    55 			RDebug::Printf("Api=SERIALISED_EGL_API_UID, aOpcode=%d, ParamCount=%d", aOpcode, aParamCount);
       
    56 			break;
       
    57 		case SERIALISED_OPENGLES_1_1_API_UID:
       
    58 			RDebug::Printf("Api=SERIALISED_OPENGLES_1_1_API_UID, aOpcode=%d, ParamCount=%d", aOpcode, aParamCount);
       
    59 			break;
       
    60 		case SERIALISED_OPENVG_API_UID:
       
    61 			RDebug::Printf("Api=SERIALISED_OPENVG_API_UID, aOpcode=%d, ParamCount=%d", aOpcode, aParamCount);
       
    62 			break;
       
    63 		default:
       
    64 			RDebug::Printf("Api=%d, aOpcode=%d, ParamCount=%d", aApiUid, aOpcode, aParamCount);
       
    65 			break;
       
    66 		}
       
    67 	User::Panic(KSerialiserPanicCategory, aPanicCode);
       
    68 	}
       
    69 #endif
       
    70 
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // 
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 TUint32 RemoteFunctionCallData::TSimpleParam::Size() const
       
    77 	{
       
    78 	TUint32 size(0);
       
    79     size += sizeof( iDataType );
       
    80     size += sizeof( iDataTypeSize );
       
    81     size += iDataTypeSize;
       
    82 	return size;
       
    83 	}
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // 
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 TUint32 RemoteFunctionCallData::TVectorParam::Size( TParamDirection aDir, TOperationType aOpType, TInt aIndexToAlign ) const
       
    90     {
       
    91     TUint32 size(0);
       
    92     size += sizeof( iDataType );
       
    93     size += sizeof( iVectorLength );
       
    94     size += sizeof( iCallerAddress );
       
    95     size += sizeof( iDataTypeSize );
       
    96     size += sizeof( iDataTypeAlignment );
       
    97 
       
    98     if ( ( (aDir & EIn) && ( EOpRequestWithReply == aOpType || EOpRequest == aOpType ) ) 
       
    99             ||
       
   100          ( ( aDir & EOut ) && aOpType == EOpReply ) 
       
   101         )
       
   102         {            
       
   103         if ( iVectorLength )
       
   104             {
       
   105             TInt aNewIndex = RemoteFunctionCallData::AlignIndex( aIndexToAlign + size, iDataTypeAlignment );
       
   106             size += aNewIndex - ( aIndexToAlign + size );
       
   107             }
       
   108         size += iDataTypeSize*iVectorLength;
       
   109         }
       
   110     return size;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // 
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 TUint32 RemoteFunctionCallData::TParam::Size( TOperationType aOpType, TInt aIndexToAlign ) const
       
   118     {
       
   119 	TUint32 size(0);
       
   120     size += sizeof( iDir );
       
   121     size += sizeof( iType );
       
   122     if ( TParam::ESimple == iType )
       
   123         {
       
   124         size += iSimpleParam.Size();
       
   125         }
       
   126     else if ( TParam::EVector == iType )
       
   127         {
       
   128         size += iVectorParam.Size( iDir, aOpType, aIndexToAlign + size );
       
   129         }
       
   130 	return size;
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // 
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 SER_EXPORT_C void RemoteFunctionCallData::CopyData( TUint8* aDest, const TUint8* aSource, TInt32 aSize )
       
   138     {
       
   139     memcpy( aDest, aSource, aSize );
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // 
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 SER_EXPORT_C TInt RemoteFunctionCallData::AlignIndex( TInt aIndex, const TInt32 aAlignment )
       
   147     {
       
   148     const TInt remainder = aIndex % aAlignment;
       
   149     if ( remainder )
       
   150         {
       
   151         aIndex += aAlignment - remainder;
       
   152         }
       
   153     return aIndex;    
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // 
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 SER_EXPORT_C TUint32 RemoteFunctionCallData::SerialisedLength() const
       
   161     {
       
   162     TUint32 size(0);
       
   163     size += sizeof( iHeader.iOpCode );
       
   164     size += sizeof( iHeader.iTransactionId );
       
   165     size += sizeof( iHeader.iProcessId );
       
   166     size += sizeof( iHeader.iThreadId );
       
   167     size += sizeof( iHeader.iParameterCount );
       
   168     size += sizeof( iHeader.iOpType );
       
   169     size += sizeof( iHeader.iReturnValue );
       
   170     size += sizeof( iHeader.iApiUid );
       
   171 
       
   172     for ( TInt i = 0; i < iHeader.iParameterCount; i++ )
       
   173         {
       
   174         size += iParameters[i].Size( (RemoteFunctionCallData::TOperationType)iHeader.iOpType, size );
       
   175         }
       
   176     
       
   177     return size;
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // 
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 SER_EXPORT_C void RemoteFunctionCallData::SetThreadInformation( const TUint32 aProcessId, const TUint32 aThreadId )
       
   185     { 
       
   186     iHeader.iProcessId = aProcessId; iHeader.iThreadId = aThreadId; 
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // 
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 SER_EXPORT_C void RemoteFunctionCallData::SetTransactionId( TUint32 aTransactionId )
       
   194     { 
       
   195     iHeader.iTransactionId = aTransactionId; 
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // 
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 SER_EXPORT_C void RemoteFunctionCallData::SetOperationType( TInt32 aOpType )
       
   203     { 
       
   204     iHeader.iOpType = aOpType; 
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // 
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 SER_EXPORT_C void RemoteFunctionCallData::SetReturnValue( TUint32 aRetVal )
       
   212     { 
       
   213     iHeader.iReturnValue = aRetVal; 
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // 
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 SER_EXPORT_C const RemoteFunctionCallData::THeader& RemoteFunctionCallData::Header() const 
       
   221     { 
       
   222     return iHeader; 
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // 
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 SER_EXPORT_C TInt RemoteFunctionCallData::ParameterCount()
       
   230     { 
       
   231     return iHeader.iParameterCount; 
       
   232     }
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // 
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 SER_EXPORT_C RemoteFunctionCallData::TParam* RemoteFunctionCallData::Parameters()
       
   239     { 
       
   240     return iParameters; 
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // 
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 RemoteFunctionCallData::THeader& RemoteFunctionCallData::HeaderData()
       
   248     { 
       
   249     return iHeader; 
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // 
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 SER_EXPORT_C void RemoteFunctionCallData::GetVectorData( TInt32 aParamType, void** aData, TInt& aSize, TInt aIndex )
       
   257     {
       
   258     ASSERT( iParameters[aIndex].iVectorParam.iDataType == aParamType );
       
   259     ASSERT( aIndex < iHeader.iParameterCount );
       
   260 
       
   261     *aData = (void*)iParameters[aIndex].iVectorParam.iData;
       
   262     aSize = iParameters[aIndex].iVectorParam.iVectorLength;
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // 
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 SER_EXPORT_C void RemoteFunctionCallData::GetParamValue( TInt32 aParamType, TUint8* aData, TInt aIndex )
       
   270     {
       
   271     ASSERT( iParameters[aIndex].iSimpleParam.iDataType == aParamType );
       
   272     ASSERT( aIndex < iHeader.iParameterCount );
       
   273 
       
   274     RemoteFunctionCallData::CopyData( aData, (TUint8*)&iParameters[aIndex].iSimpleParam.iData, iParameters[aIndex].iSimpleParam.iDataTypeSize );
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // 
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 SER_EXPORT_C void RemoteFunctionCall::Init( TInt32 aOpCode, RemoteFunctionCallData::TOperationType aOpType )
       
   282     {
       
   283     iData.iHeader.iOpCode = aOpCode;
       
   284     iData.iHeader.iParameterCount = 0;
       
   285     iData.iHeader.iTransactionId = 0;
       
   286     iData.iHeader.iOpType = aOpType;
       
   287     iData.iHeader.iProcessId = 0;
       
   288     iData.iHeader.iThreadId = 0;
       
   289     iData.iHeader.iApiUid = GetAPIUid();
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // 
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 SER_EXPORT_C RemoteFunctionCall::RemoteFunctionCall( RemoteFunctionCallData& aData ):
       
   297     iData( aData )
       
   298     {
       
   299     
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // 
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 SER_EXPORT_C void RemoteFunctionCall::SetVectorData( TInt32 aParamType, const TUint8* aData, TInt aLength, TInt aIndex )
       
   307 	{
       
   308 	ASSERT( iData.iParameters[aIndex].iVectorParam.iDataType == aParamType );
       
   309 	ASSERT( aIndex < iData.iHeader.iParameterCount );
       
   310 	ASSERT( static_cast<TUint32>(aLength) <= iData.iParameters[aIndex].iVectorParam.iVectorLength );
       
   311 	ASSERT( RemoteFunctionCallData::EIn != iData.iParameters[aIndex].iDir );
       
   312 	
       
   313 	iData.iParameters[aIndex].iVectorParam.iData = aData;
       
   314 	iData.iParameters[aIndex].iVectorParam.iVectorLength = aLength;
       
   315 	}
       
   316 
       
   317 // -----------------------------------------------------------------------------
       
   318 // 
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 SER_EXPORT_C void RemoteFunctionCall::SetParamData( TInt32 aParamType, const TUint8* aData, TInt aIndex )
       
   322     {
       
   323     ASSERT( iData.iParameters[aIndex].iSimpleParam.iDataType == aParamType );
       
   324     ASSERT( aIndex < iData.iHeader.iParameterCount );
       
   325     ASSERT( RemoteFunctionCallData::EIn != iData.iParameters[aIndex].iDir );
       
   326 
       
   327     RemoteFunctionCallData::CopyData( (TUint8*)&iData.iParameters[aIndex].iSimpleParam.iData, aData, iData.iParameters[aIndex].iSimpleParam.iDataTypeSize );    
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // 
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 SER_EXPORT_C void RemoteFunctionCall::AppendParam( TInt32 aParamType, const TUint8* aData, RemoteFunctionCallData::TParamDirection aDir )
       
   335     {
       
   336 #ifdef USE_SYMBIAN_CLIENT_PANICS
       
   337 	VGSERPANIC_ASSERT( iData.iHeader.iParameterCount < RemoteFunctionCallData::KMaxParameterCount,
       
   338 		ESerPanicMaxParamCountExceeded, iData.iHeader.iApiUid, iData.iHeader.iOpCode, iData.iHeader.iParameterCount);
       
   339 	VGSERPANIC_ASSERT( (RemoteFunctionCallData::EIn == aDir) || (iData.iHeader.iOpCode != RemoteFunctionCallData::EOpRequest),
       
   340 		ESerPanicRequestOperationHasOutParameter, iData.iHeader.iApiUid, iData.iHeader.iOpCode, iData.iHeader.iParameterCount);
       
   341 #else
       
   342 	ASSERT( iData.iHeader.iParameterCount < RemoteFunctionCallData::KMaxParameterCount );
       
   343 #endif
       
   344 
       
   345 	RemoteFunctionCallData::TParam param;
       
   346     param.iType = RemoteFunctionCallData::TParam::ESimple;
       
   347     param.iDir = aDir;
       
   348     param.iSimpleParam.iDataType = aParamType;
       
   349     param.iSimpleParam.iDataTypeSize = GetTypeSize( param.iSimpleParam.iDataType );
       
   350     RemoteFunctionCallData::CopyData( (TUint8*)&param.iSimpleParam.iData, aData, param.iSimpleParam.iDataTypeSize );
       
   351     iData.iParameters[iData.iHeader.iParameterCount] = param;
       
   352     iData.iHeader.iParameterCount++;
       
   353     }
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // 
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 SER_EXPORT_C void RemoteFunctionCall::AppendVector( TInt32 aParamType, TUint32 aLength, const TUint8* aData, RemoteFunctionCallData::TParamDirection aDir )
       
   360     {        
       
   361 #ifdef USE_SYMBIAN_CLIENT_PANICS
       
   362 	VGSERPANIC_ASSERT( iData.iHeader.iParameterCount < RemoteFunctionCallData::KMaxParameterCount,
       
   363 		ESerPanicMaxParamCountExceeded, iData.iHeader.iApiUid, iData.iHeader.iOpCode, iData.iHeader.iParameterCount);
       
   364 	VGSERPANIC_ASSERT( (aLength & 0x80000000) == 0,
       
   365 		ESerPanicVectorSizeIsNegative, iData.iHeader.iApiUid, iData.iHeader.iOpCode, iData.iHeader.iParameterCount);
       
   366 #else
       
   367 	ASSERT( iData.iHeader.iParameterCount < RemoteFunctionCallData::KMaxParameterCount );
       
   368     ASSERT( (RemoteFunctionCallData::EIn == aDir) || (iData.iHeader.iOpCode != RemoteFunctionCallData::EOpRequest) );
       
   369 #endif
       
   370 
       
   371 
       
   372 	RemoteFunctionCallData::TParam param;
       
   373     param.iType = RemoteFunctionCallData::TParam::EVector;
       
   374     param.iDir = aDir;
       
   375     param.iVectorParam.iDataType = aParamType;
       
   376     param.iVectorParam.iData = aData;
       
   377     param.iVectorParam.iDataTypeSize = GetTypeSize( aParamType );
       
   378     param.iVectorParam.iDataTypeAlignment = GetTypeAlignment( aParamType );
       
   379 	
       
   380 	if ( aData )
       
   381 		{
       
   382 		param.iVectorParam.iVectorLength = aLength;
       
   383 		}
       
   384 	else
       
   385 		{
       
   386 #ifdef USE_SYMBIAN_CLIENT_PANICS
       
   387 		VGSERPANIC_ASSERT( (aLength == 0) || (aDir != RemoteFunctionCallData::EIn),
       
   388 				ESerPanicVectorPtrIsNull, iData.iHeader.iApiUid, iData.iHeader.iOpCode, iData.iHeader.iParameterCount);
       
   389 #endif
       
   390 		param.iVectorParam.iVectorLength = 0;
       
   391 		}
       
   392 
       
   393     if ( RemoteFunctionCallData::EOut & aDir )
       
   394         {
       
   395 #ifdef USE_SYMBIAN_CLIENT_PANICS
       
   396 		VGSERPANIC_ASSERT( iData.iHeader.iOpCode != RemoteFunctionCallData::EOpRequest,
       
   397 				ESerPanicRequestOperationHasOutParameter, iData.iHeader.iApiUid, iData.iHeader.iOpCode, iData.iHeader.iParameterCount);
       
   398 #endif
       
   399         param.iVectorParam.iCallerAddress = const_cast<TUint8*>( aData );
       
   400         }
       
   401     else
       
   402         {
       
   403         param.iVectorParam.iCallerAddress = NULL;
       
   404         }
       
   405 
       
   406     iData.iParameters[iData.iHeader.iParameterCount] = param;
       
   407     iData.iHeader.iParameterCount++;
       
   408     }
       
   409 
       
   410 // -----------------------------------------------------------------------------
       
   411 // 
       
   412 // -----------------------------------------------------------------------------
       
   413 //
       
   414 SER_EXPORT_C RemoteFunctionCallData& RemoteFunctionCall::Data()
       
   415     {
       
   416     return iData;
       
   417     }
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // 
       
   421 // -----------------------------------------------------------------------------
       
   422 //
       
   423 SER_EXPORT_C TUint32 RemoteFunctionCall::ReturnValue()
       
   424     {
       
   425     return iData.Header().iReturnValue;
       
   426     }
       
   427 
       
   428 // -----------------------------------------------------------------------------
       
   429 // 
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 SER_EXPORT_C void RemoteFunctionCall::SetReturnValue( TUint32 aRetValue )
       
   433     {
       
   434     iData.SetReturnValue( aRetValue );
       
   435     }