stif/StifKernelTestClassBase/src/StifKernelTestClassBase.cpp
branchRCL_3
changeset 59 8ad140f3dd41
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: This file contains DStifKernelTestClassBaseDriver 
       
    15 * implementation.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "StifKernelTestClass.h"
       
    21 #include "StifKernelTestClassBase.h"
       
    22 
       
    23 // EXTERNAL DATA STRUCTURES
       
    24 
       
    25 // EXTERNAL FUNCTION PROTOTYPES  
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 // MACROS
       
    30 
       
    31 // LOCAL CONSTANTS AND MACROS
       
    32 
       
    33 // MODULE DATA STRUCTURES
       
    34 
       
    35 // LOCAL FUNCTION PROTOTYPES
       
    36 
       
    37 // FORWARD DECLARATIONS
       
    38 
       
    39 // ============================= LOCAL FUNCTIONS ===============================
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // DStifKernelTestClassBaseDriver::DStifKernelTestClassBaseDriver
       
    45 // C++ default constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C DStifKernelTestClassBaseDriver::DStifKernelTestClassBaseDriver( 
       
    50     const TDesC& aName )
       
    51     {
       
    52 
       
    53     __KTRACE_OPT(KHARDWARE, 
       
    54        Kern::Printf("DStifKernelTestClassBaseDriver::DStifKernelTestClassBaseDriver()"));
       
    55 
       
    56     iVersion=TVersion( RStifKernelTestClass::EMajorVersionNumber,
       
    57                        RStifKernelTestClass::EMinorVersionNumber,
       
    58                        RStifKernelTestClass::EBuildVersionNumber );
       
    59  
       
    60     iName.Copy( aName.Left( KMaxName ) );
       
    61 
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // DStifKernelTestClassBaseDriver::Install
       
    66 // Set name.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 EXPORT_C TInt DStifKernelTestClassBaseDriver::Install()
       
    70     {
       
    71 
       
    72     __KTRACE_OPT(KHARDWARE, 
       
    73         Kern::Printf("DStifKernelTestClassBaseDriver::Install()"));
       
    74  
       
    75 
       
    76     return SetName( &iName );       // Set our name and return error code.
       
    77 
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // DStifKernelTestClassBaseDriver::~DStifKernelTestClassBaseDriver
       
    82 // Destructor.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C DStifKernelTestClassBaseDriver::~DStifKernelTestClassBaseDriver()
       
    86     {
       
    87 
       
    88     __KTRACE_OPT(KHARDWARE, 
       
    89         Kern::Printf("DStifKernelTestClassBaseDriver::~DStifKernelTestClassBaseDriver()"));
       
    90 
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // DStifKernelTestClassBaseDriver::GetCaps
       
    95 // Returns the drivers capabilities, may be used by LDD
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 EXPORT_C void DStifKernelTestClassBaseDriver::GetCaps( TDes8& /* aDes */ ) const
       
    99     {
       
   100 
       
   101     __KTRACE_OPT(KHARDWARE, 
       
   102         Kern::Printf("DStifKernelTestClassBaseDriver::GetCaps()"));
       
   103   
       
   104     }
       
   105 
       
   106 // ============================ MEMBER FUNCTIONS ===============================
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CStifKernelTestClassBase::CStifKernelTestClassBase
       
   110 // C++ default constructor can NOT contain any code, that
       
   111 // might leave.
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 
       
   115 EXPORT_C DStifKernelTestClassBase::DStifKernelTestClassBase( DLogicalDevice* /* aDevice */ )
       
   116     {
       
   117     // Get pointer to client threads DThread object
       
   118     iThread=&Kern::CurrentThread();
       
   119 
       
   120     // Open a reference on client thread so it's control block can't dissapear until
       
   121     // this driver has finished with it
       
   122     ((DObject*)iThread)->Open();
       
   123 
       
   124     __KTRACE_OPT(KHARDWARE, 
       
   125         Kern::Printf("DStifKernelTestClassBase::DStifKernelTestClassBase()"));         
       
   126     }
       
   127             
       
   128         
       
   129 // -----------------------------------------------------------------------------
       
   130 // DStifKernelTestClassBase::~DStifKernelTestClassBase()
       
   131 // Destructor
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 
       
   135 EXPORT_C DStifKernelTestClassBase::~DStifKernelTestClassBase()
       
   136     { 
       
   137 
       
   138     __KTRACE_OPT(KHARDWARE, 
       
   139         Kern::Printf("DStifKernelTestClassBase::~DStifKernelTestClassBase()"));
       
   140 
       
   141     // Close our reference on the client thread
       
   142     Kern::SafeClose((DObject*&)iThread,NULL);
       
   143 
       
   144             
       
   145     Delete();        
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CStifKernelTestClassBase::DoControl
       
   150 // Handle syncronous request,
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 
       
   154 TInt DStifKernelTestClassBase::DoControl( 
       
   155     TInt aFunction, 
       
   156     TAny* a1, 
       
   157     TAny* /* a2 */ )   
       
   158     {
       
   159 
       
   160     __KTRACE_OPT(KHARDWARE, 
       
   161         Kern::Printf("DStifKernelTestClassBase::DoControl()")); 
       
   162     
       
   163     TInt ret = KErrNone;
       
   164     switch( aFunction )
       
   165         {
       
   166         case RStifKernelTestClass::ERunMethod:
       
   167             {
       
   168             TStifRunMethodInfo methodInfo;
       
   169             TPckg<TStifRunMethodInfo> methodInfoPckg( methodInfo );
       
   170 
       
   171             TInt err = KErrNone;
       
   172                                                           
       
   173             ret = Kern::ThreadDesRead( iThread, a1, methodInfoPckg, 0, KChunkShiftBy0 );
       
   174             if( ret != KErrNone )
       
   175                 {
       
   176                 __KTRACE_OPT(KHARDWARE, 
       
   177                     Kern::Printf("DStifKernelTestClassBase::DoControl: ThreadDesRead fails! %d", 333));
       
   178                 return ret;
       
   179                 }                
       
   180                             
       
   181             // TRAP is not supported in EKA2 kernel, so we can't use it. However, it is not even needed 
       
   182             // any longer because kernel test cases cannot leave either. Although RunMethodL's name 
       
   183             // seems to allow leaves (L in the end of the name), it really doesn't!
       
   184             ret = RunMethodL( methodInfo.iMethodName, methodInfo.iMethodParams );                                           
       
   185                                      
       
   186             if( err != KErrNone )
       
   187                 {
       
   188                 methodInfo.iResult = err;
       
   189                 methodInfo.iMethodResultDes.Copy( _L("RunMethodL leave: ") );
       
   190                 methodInfo.iMethodResultDes.AppendNum( err );
       
   191                 }
       
   192             else if( ret != KErrNone )
       
   193                 {
       
   194                 methodInfo.iResult = ret;
       
   195                 methodInfo.iMethodResultDes.Copy( _L("RunMethodL returned error: ") );
       
   196                 methodInfo.iMethodResultDes.AppendNum( ret );
       
   197                 }
       
   198             else
       
   199                 {
       
   200                 methodInfo.iResult = KErrNone;
       
   201                 }
       
   202 
       
   203             ret = Kern::ThreadDesWrite( iThread, a1, methodInfoPckg, 0, 0, &Kern::CurrentThread() );
       
   204 
       
   205             }
       
   206             break;
       
   207         default:
       
   208             ret = KErrNotFound;
       
   209         }
       
   210         
       
   211     return ret;
       
   212     } 
       
   213 
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // void DStifKernelTestClassBase::HandleMsg(TMessageBase* aMsg)
       
   217 // Processes the DoControl call in EKA2
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220        
       
   221 EXPORT_C void DStifKernelTestClassBase::HandleMsg( TMessageBase* aMsg )
       
   222     {       
       
   223     __KTRACE_OPT(KHARDWARE, 
       
   224         Kern::Printf("DStifKernelTestClassBase::HandleMsg"));
       
   225     
       
   226     TThreadMessage& m=*(TThreadMessage*)aMsg;
       
   227 
       
   228     // Get the id
       
   229     TInt id=m.iValue;
       
   230    
       
   231     if(id == (TInt)ECloseMsg)
       
   232         {
       
   233         // Lets close the channel
       
   234         m.Complete( KErrNone, EFalse );
       
   235         return;
       
   236         }
       
   237         
       
   238     if (id == KMaxTInt)
       
   239         {
       
   240         // Cancel operations are not needed because we don't use async requests
       
   241         m.Complete( KErrNone, ETrue );
       
   242         return;
       
   243         }
       
   244    
       
   245     if( id > 0 ) 
       
   246         {
       
   247         // Process the DoControl call
       
   248         TInt r = DoControl( id, m.Ptr0(), m.Ptr1() );
       
   249         m.Complete( r, ETrue );
       
   250         return;
       
   251         }        
       
   252     }
       
   253 
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // DStifKernelTestClassBase::RunInternalL( 
       
   257 //                        const TStifKernelFunctionInfo* const aFunctions, 
       
   258 //                        TInt aCount, 
       
   259 //                        const TDesC& aMethod, 
       
   260 //                        const TDesC& aParams )
       
   261 //
       
   262 // Executes the test case. In EKA2 this function cannot leave.
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 
       
   266 EXPORT_C TInt DStifKernelTestClassBase::RunInternalL( 
       
   267                         const TStifFunctionInfo* const aFunctions, 
       
   268                         TInt aCount, 
       
   269                         const TDesC& aMethod, 
       
   270                         const TDesC& aParams )
       
   271     {
       
   272     
       
   273     TInt ret = KErrNotFound;
       
   274 
       
   275     TInt i = 0;
       
   276     TName funcName;
       
   277     
       
   278     // Search function from table and call it
       
   279     for ( i = 0; i < aCount; i++ )
       
   280         {
       
   281         funcName = aFunctions[i].iFunctionName;      
       
   282         if ( aMethod == funcName )
       
   283             {
       
   284             ret  = ( this->*(aFunctions[i].iMethod) )( aParams );
       
   285             break;            
       
   286             }
       
   287     
       
   288         }
       
   289 
       
   290     return ret;
       
   291     
       
   292     }
       
   293 
       
   294 // End of File