dosservices/tsrc/public/basic/dosservertestplugin/src/Tfdoscontrol.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2004 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <ctffactory.h>
       
    21 #include <tftypes.h>
       
    22 #include <psvariables.h>
       
    23 #include "siftrace.h"
       
    24 #include "dosenums.h"
       
    25 #include "ctfdoscontrol.h"
       
    26 #include "ctfdoscontroltestcase.h"
       
    27 #include "ctfeventlistener.h"
       
    28 #include "CTFDosSharedDataTC.h"
       
    29 
       
    30 const TUid KUidDosTestCategory = {0x10200C6A};
       
    31 
       
    32 MTFDosControl* GetDosServerControl( void )
       
    33     {
       
    34     CTFStub* stub = CTFFactory::Stub( KTFStubTypeDosServerControl );
       
    35     return STATIC_CAST( CTFDosControl*, stub );
       
    36     }
       
    37 
       
    38 MTFDosControl::MTFDosControl( void )
       
    39     {
       
    40     }
       
    41     
       
    42     
       
    43 MTFDosControl::~MTFDosControl( void )
       
    44     {
       
    45     }
       
    46     
       
    47 
       
    48 CTFDosControl::CTFDosControl( void )
       
    49 : CTFStub( KTFStubTypeDosServerControl )
       
    50     {
       
    51     }
       
    52     
       
    53 //lint -e1740 Pointer not directly deleted by destructor
       
    54 CTFDosControl::~CTFDosControl( void )
       
    55     {
       
    56     ResetDosServices();
       
    57     COMPONENT_TRACE( ( _L( "DOSSERVERTESTPLUGIN - CTFDosServerControl::~CTFDosServerControl() - DosServer connection closed" ) ) );
       
    58     }
       
    59 //lint +e1740    
       
    60     
       
    61 void CTFDosControl::InitializeL( void )
       
    62     {
       
    63     COMPONENT_TRACE( ( _L( "DOSSERVERTESTPLUGIN - CTFDosServerControl::InitializeL()" ) ) );
       
    64     User::LeaveIfError( iDosServer.Connect() );            
       
    65     iInitialized = ETrue;
       
    66     COMPONENT_TRACE( ( _L( "DOSSERVERTESTPLUGIN - CTFDosServerControl::InitializeL - return" ) ) );
       
    67     }
       
    68 
       
    69 void CTFDosControl::ResetDosServices( void )
       
    70     {
       
    71     COMPONENT_TRACE( ( _L( "CTFDosServerStub::ResetDosServices()" ) ) );
       
    72     if ( iEventListener != NULL )
       
    73         {
       
    74         iEventListener->Stop();
       
    75         delete iEventListener;
       
    76         iEventListener = NULL;
       
    77         }  
       
    78   
       
    79     if ( iDosSharedData != NULL )
       
    80         {
       
    81         iDosSharedData->Close();
       
    82         delete iDosSharedData;
       
    83         iDosSharedData = NULL;
       
    84         }      
       
    85       if ( iDosExtension != NULL )
       
    86         {
       
    87         iDosExtension->Close();
       
    88         delete iDosExtension;
       
    89         iDosExtension = NULL;
       
    90         }
       
    91           
       
    92     iDosServer.Close();
       
    93     iInitialized = EFalse;
       
    94     COMPONENT_TRACE( ( _L( "CTFDosServerStub::ResetDosServices() - Success" ) ) );
       
    95     }
       
    96 
       
    97 void CTFDosControl::CallDosFunctionL( TTFDosServerControlTestCaseState& aParameter )
       
    98     {
       
    99     COMPONENT_TRACE( ( _L( "DOSSERVERTESTPLUGIN - CTFDosServerControl::CallDosFunctionL(%d, %d, %d)" ), aParameter.iDosFunction, aParameter.iArg1, aParameter.iArg2 ) );
       
   100     if ( !iInitialized )
       
   101         {
       
   102         InitializeL();
       
   103         }
       
   104     TInt retval = KTFErrDosServiceMissing;
       
   105     switch ( aParameter.iDosFunction )
       
   106         {      
       
   107          // SharedData TC
       
   108         case ETFDosSharedData_Open:
       
   109         	if ( iDosSharedData == NULL )
       
   110         		{
       
   111         		iDosSharedData = new ( ELeave ) RDosSharedData();
       
   112         		retval = iDosSharedData->Open ( iDosServer );
       
   113         		}
       
   114         	else
       
   115         		{
       
   116         		retval = KErrNone;
       
   117         		}
       
   118         	break;
       
   119         case ETFDosSharedData_Close:
       
   120             TRACE_ASSERT( iDosSharedData != NULL );
       
   121             if ( iDosSharedData != NULL )
       
   122                 {
       
   123                 iDosSharedData->Close();
       
   124                 delete iDosSharedData;
       
   125                 iDosSharedData = NULL;
       
   126                 }
       
   127             retval = KErrNone;
       
   128             break;
       
   129         case ETFDosSharedData_FillDisk:
       
   130         	if ( iSdDisk == NULL )
       
   131         	    {
       
   132         		iSdDisk = CSdDisk::NewL();
       
   133         	    }
       
   134         	
       
   135        		iSdDisk->FillDisk(iFs, aParameter.iArg1);
       
   136        		delete iSdDisk;
       
   137        		iSdDisk = NULL;
       
   138 				
       
   139 			retval = KErrNone;
       
   140 			break;
       
   141         case ETFDosSharedData_ReleaseDisk:
       
   142         	if ( iSdDisk == NULL )
       
   143         	    {
       
   144         		iSdDisk = CSdDisk::NewL();
       
   145         	    }
       
   146         	
       
   147        		iSdDisk->ReleaseDisk(iFs);
       
   148        		delete iSdDisk;
       
   149        		iSdDisk = NULL;
       
   150 				
       
   151 			retval = KErrNone;
       
   152     	    break;
       
   153         case ETFDosSharedData_CheckDiskSpace:
       
   154         	if ( iSdDisk == NULL )
       
   155         	    {
       
   156         		iSdDisk = CSdDisk::NewL();
       
   157         	    }
       
   158 
       
   159       		iFreeDiskSpace = iSdDisk->CheckDiskSpace( iFs );
       
   160      
       
   161    			RDebug::Print(_L("Shareddatatest ## CheckDiskSpace: %f Bytes"), iFreeDiskSpace);
       
   162        		        		      		
       
   163        		if ( aParameter.iArg1 != 0 )
       
   164        		    {       		    
       
   165        		    if ( aParameter.iArg1 == ( TInt(iFreeDiskSpace) / 1024 ) || 
       
   166        		         iSdDisk->CheckReserveFileSize( iFs ) == 0 )
       
   167        		        {
       
   168        			    retval = KErrNone;
       
   169        		        }
       
   170        		    else 
       
   171        		        {
       
   172        			    retval = KErrGeneral;
       
   173 				    iSdDisk->ReleaseDisk(iFs);
       
   174 	        	
       
   175 	        	    if ( iDosSharedData != NULL )
       
   176 	        	        {
       
   177 					    iDosSharedData->Close();
       
   178                		    delete iDosSharedData;
       
   179                		    iDosSharedData = NULL;
       
   180        			        }
       
   181         		
       
   182         		    delete iSdDisk;
       
   183         		    iSdDisk = NULL;
       
   184        		        }
       
   185         	    }
       
   186 
       
   187    		    else if ( aParameter.iArg2 == 1 )
       
   188    		        {
       
   189    		        if ( iSdDisk->CheckReserveFileSize( iFs ) == 256*1024 )
       
   190    		            {
       
   191    		            retval = KErrNone;
       
   192    		            }
       
   193    		        else
       
   194    		            {
       
   195    		            retval = KErrGeneral;
       
   196    		            }
       
   197    		        }
       
   198         	    
       
   199         	else
       
   200         	    {
       
   201         	    retval = KErrNone;    
       
   202         	    }
       
   203     	    break;    	   
       
   204         case ETFDosSharedData_RequestFreeDiskSpace:
       
   205         	if ( iDosSharedData != NULL )
       
   206         	    {
       
   207         		RDebug::Print(_L("Shareddatatest ## RequestfreeDiskSpace: %d kB"), aParameter.iArg1 * 1024);
       
   208         		iDosSharedData->RequestFreeDiskSpace(aParameter.iArg1 * 1024);
       
   209         		retval = KErrNone;
       
   210         	    }
       
   211 	        break;
       
   212         case ETFDosSharedData_RequestFreeDiskSpaceCancel:
       
   213         	if ( iDosSharedData != NULL )
       
   214         	    {
       
   215         		RDebug::Print(_L("Shareddatatest ## RequestfreeDiskSpaceCancel"));
       
   216         		iDosSharedData->RequestFreeDiskSpaceCancel();
       
   217         		retval = KErrNone;
       
   218         	    }    	    
       
   219 	        break;        
       
   220 	        
       
   221 	      case ETFDosExtension_Open:
       
   222             if ( iDosExtension == NULL )
       
   223                 {
       
   224                 iDosExtension = new ( ELeave ) RTFDosExtension();
       
   225                 retval = iDosExtension->Open( iDosServer );
       
   226                 }
       
   227             else
       
   228                 {
       
   229                 retval = KErrNone;
       
   230                 }
       
   231             break;
       
   232         case ETFDosExtension_CallFunction:
       
   233             TRACE_ASSERT( iDosExtension != NULL );
       
   234             if ( iDosExtension != NULL )
       
   235                 {
       
   236                 retval = iDosExtension->CallSyncDosExtFunction( aParameter.iArg1, ( TAny* )&aParameter.iArg2, sizeof ( aParameter.iArg2 ), ETrue );
       
   237                 }
       
   238             break;
       
   239         case ETFDosExtension_CallFunctionAndComplete:
       
   240             TRACE_ASSERT( iDosExtension != NULL );
       
   241             if ( iDosExtension != NULL )
       
   242                 {
       
   243                 TRequestStatus status;
       
   244                 retval = iDosExtension->CallAsyncDosExtFunction( status, aParameter.iArg1, ( TAny* )&aParameter.iArg2, sizeof ( TInt ), ETrue );                
       
   245                 }
       
   246             break;
       
   247         
       
   248         case ETFDosExtension_GeneralEvent:
       
   249             TRACE_ASSERT( iDosExtension != NULL );
       
   250             
       
   251             iEventListener = new ( ELeave ) CTFEventListener( iDosServer );
       
   252             iEventListener->StartListeningL( KLDSYDummyEvent, sizeof(TInt), EQueue );
       
   253     
       
   254             if ( iDosExtension != NULL )
       
   255                 {
       
   256                 TRequestStatus status;
       
   257                 iDosExtension->CallAsyncDosExtFunction( status, aParameter.iArg1, ( TAny* )&aParameter.iArg2, sizeof ( TInt ), EFalse );                
       
   258                 retval = KErrNone;
       
   259                 }
       
   260             break;    
       
   261             
       
   262         case ETFDosExtension_GeneralEventArray:
       
   263             TRACE_ASSERT( iDosExtension != NULL );
       
   264             
       
   265             iEventListener = new ( ELeave ) CTFEventListener( iDosServer );
       
   266             
       
   267             TRegisterEvent eventList[] = 
       
   268             {
       
   269                { KLDSYDummyEvent, sizeof ( TInt ), EQueue }    
       
   270             };
       
   271             
       
   272             iEventListener->StartListeningL( eventList, sizeof ( eventList ) / sizeof ( TRegisterEvent ) );
       
   273     
       
   274             if ( iDosExtension != NULL )
       
   275                 {
       
   276                 TRequestStatus status;
       
   277                 iDosExtension->CallAsyncDosExtFunction( status, aParameter.iArg1, ( TAny* )&aParameter.iArg2, sizeof ( TInt ), EFalse );                
       
   278                 retval = KErrNone;
       
   279                 }
       
   280             break;    
       
   281                         
       
   282         case ETFDosExtension_Close:
       
   283             TRACE_ASSERT( iDosExtension != NULL );
       
   284             if ( iDosExtension != NULL )
       
   285                 {
       
   286                 iDosExtension->Close();
       
   287                 delete iDosExtension;
       
   288                 iDosExtension = NULL;
       
   289                 }
       
   290                 
       
   291             if ( iEventListener != NULL )
       
   292                 {
       
   293                 iEventListener->Stop();
       
   294                 delete iEventListener;
       
   295                 iEventListener = NULL;
       
   296                 }
       
   297                     
       
   298             retval = KErrNone;
       
   299             break;
       
   300         
       
   301         case ETFRFs_Connect:
       
   302 					{
       
   303 					retval = iFs.Connect();	
       
   304 					}
       
   305 	        break;
       
   306 
       
   307 				case ETFRFs_Close:
       
   308 					{
       
   309 					iFs.Close();	
       
   310 					retval = KErrNone;
       
   311 					}
       
   312 	      break;
       
   313 	              	        
       
   314         default:
       
   315             TRACE_ASSERT_ALWAYS;
       
   316         break;
       
   317         }
       
   318     User::LeaveIfError( retval );
       
   319     }
       
   320 
       
   321 void CTFDosControl::NotifyDosEvent( TInt aEvent, TInt aParameter )
       
   322     {
       
   323     COMPONENT_TRACE( ( _L( "DOSSERVERTESTPLUGIN - CTFDosServerControl::NotifyDosEvent(%d, %d)" ), aEvent, aParameter ) );
       
   324     CTFDosControlTestCase* testCase = STATIC_CAST( CTFDosControlTestCase*, CurrentTestCase() );
       
   325     TRACE_ASSERT( testCase != NULL );
       
   326     if ( testCase != NULL )
       
   327         {
       
   328         testCase->NotifyDosEvent( aEvent, aParameter );
       
   329         }
       
   330     COMPONENT_TRACE( ( _L( "DOSSERVERTESTPLUGIN - CTFDosServerControl::NotifyDosEvent - return" ) ) );
       
   331     }
       
   332     
       
   333 TInt RTFDosExtension::CallSyncDosExtFunction( const TInt& aFunc, TAny* aParam = NULL, TInt aParLength = 0, TBool aAutoComplete = ETrue )
       
   334     {
       
   335     COMPONENT_TRACE( ( _L( "    DSYTESTTOOL - RTFDosExtension::CallSyncDosExtFunction(0x%x, 0x%x, 0x%x, 0x%x)" ), aFunc, aParam, aParLength, aAutoComplete ) );
       
   336     TExtensionParPckg package;
       
   337     package().iFunc = aFunc;
       
   338     package().iParLength = aParLength;
       
   339     package().iAutoComplete = aAutoComplete;
       
   340     TPtr8 ptr( ( TUint8* )aParam, aParLength, aParLength );
       
   341     TInt result = CallFunction( package, ptr );
       
   342     COMPONENT_TRACE( ( _L( "    DSYTESTTOOL - RTFDosExtension::CallSyncDosExtFunction - return 0x%x" ), result ) );
       
   343     return result;
       
   344     }
       
   345 
       
   346 
       
   347 TInt RTFDosExtension::CallAsyncDosExtFunction( TRequestStatus& aStatus, TInt aFunc, TAny* aParam = NULL, TInt aParLength = 0, TBool aAutoComplete = EFalse )
       
   348     {
       
   349     COMPONENT_TRACE( ( _L( "    DSYTESTTOOL - RTFDosExtension::CallAsyncDosExtFunction(0x%x, 0x%x, 0x%x, 0x%x, 0x%x)" ), &aStatus, aFunc, aParam, aParLength, aAutoComplete ) );
       
   350     TExtensionParPckg package;
       
   351     package().iFunc = aFunc;
       
   352     package().iParLength = aParLength;
       
   353     package().iAutoComplete = aAutoComplete;
       
   354     TPtr8 ptr( ( TUint8* )aParam, aParLength, aParLength );
       
   355     CallFunction( aStatus, package, ptr );
       
   356     User::WaitForRequest( aStatus );
       
   357     COMPONENT_TRACE( ( _L( "    DSYTESTTOOL - RTFDosExtension::CallAsyncDosExtFunction - return 0x%x" ), aStatus.Int() ) );
       
   358     return aStatus.Int();
       
   359     }
       
   360