stif/TestServer/src/TestServerClient.cpp
branchRCL_3
changeset 9 8a14024f954a
parent 0 a03f92240627
child 17 67c6ff54ec25
child 25 9aaae25af322
equal deleted inserted replaced
8:ecff51f1e7fb 9:8a14024f954a
   101                                     const TDesC& aConfigFile
   101                                     const TDesC& aConfigFile
   102                                     )
   102                                     )
   103     {
   103     {
   104     TFileName serverName;
   104     TFileName serverName;
   105 
   105 
   106 	TInt ret;
   106     TInt ret = KErrNone;
   107 
   107 
   108     // Create global semaphore start-up
   108     // Create global semaphore start-up. It will be indexed (if given name already exsists, index will be increased)
   109     RSemaphore startSemaphore;
   109     RSemaphore startSemaphore;
   110     TName semaphoreName = _L("startupSemaphore");
   110     TName semaphoreName = _L("startupSemaphore");
   111     semaphoreName.Append( aModuleName );
   111     semaphoreName.Append( aModuleName );
   112     ret = startSemaphore.CreateGlobal( semaphoreName, 0);
   112     TInt x = 0;
   113 	if ( ret != KErrNone )
   113     RBuf semName;
   114         {
   114     ret = semName.Create(KMaxName);
   115 		startSemaphore.Close();
   115     if(ret != KErrNone)
       
   116         {
       
   117         RDebug::Print(_L("RTestServer::Connect() Could not create buffer for semaphore name [%d]"), ret);
       
   118         return ret;
       
   119         }
       
   120     do
       
   121         {
       
   122         semName.Format(_L("%S%d"), &semaphoreName, x);
       
   123         ret = startSemaphore.CreateGlobal(semName, 0);
       
   124         RDebug::Print(_L("RTestServer::Connect() Creating global semaphore [%S] with result [%d]"), &semName, ret);
       
   125         if(ret != KErrAlreadyExists)
       
   126             {
       
   127             semaphoreName.Copy(semName);
       
   128             break;
       
   129             }
       
   130         x++;
       
   131         } while (ETrue);
       
   132     semName.Close();
       
   133     
       
   134     if ( ret != KErrNone )
       
   135         {
       
   136         startSemaphore.Close();
   116         return ret;
   137         return ret;
   117         }
   138         }
   118 
   139 
   119     // By default start 'testserverstarter.exe'
   140     // By default start 'testserverstarter.exe'
   120     TFileName pathAndExeModule;
   141     TFileName pathAndExeModule;
   127         pathAndExeModule.Copy( KDefaultExeName );    	
   148         pathAndExeModule.Copy( KDefaultExeName );    	
   128     	}
   149     	}
   129 
   150 
   130     RProcess pr;
   151     RProcess pr;
   131 
   152 
   132     ret = KErrNone;
   153     // Data to be passed to new process. It will contain module name and synchronization semaphore name separated with space.
       
   154     // I.e. it will be: "mymodule startupSemaphore0"
       
   155     RBuf data; 
       
   156     ret = data.Create(KMaxName);
       
   157     if(ret != KErrNone)
       
   158         {
       
   159         RDebug::Print(_L("RTestServer::Connect() Could not create buffer for data to be passed to process [%d]"), ret);
       
   160         return ret;
       
   161         }
       
   162     data.Format(_L("%S %S"), &aModuleName, &semaphoreName);
       
   163     RDebug::Print(_L("RTestServer::Connect() Data for new process prepared [%S]"), &data);
       
   164     
   133 
   165 
   134     // Indication is Create() operation needed
   166     // Indication is Create() operation needed
   135     TBool doCreate( ETrue );
   167     TBool doCreate( ETrue );
   136 
   168 
   137     #ifdef __WINS__ // CodeWarrior(emulator)
   169     #ifdef __WINS__ // CodeWarrior(emulator)
   138         // Create without path(Uses Symbian default path).
   170         // Create without path(Uses Symbian default path).
   139         // Note: If TestScriter used then module name is format:
   171         // Note: If TestScriter used then module name is format:
   140         // testscripter_testcasefilename
   172         // testscripter_testcasefilename
   141         ret = pr.Create( aModuleName,  aModuleName );
   173         
       
   174         ret = pr.Create( aModuleName, data );
   142         if( ret == KErrNone )
   175         if( ret == KErrNone )
   143             {
   176             {
   144             RDebug::Print( _L( "Combination (1): Caps modifier[%S], Module[%S]" ),
   177             RDebug::Print(_L("RTestServer::Connect() Combination (1): Caps modifier [%S], Data [%S]"), &aModuleName, &data);
   145                                     &aModuleName, &aModuleName );
       
   146             doCreate = EFalse;
   178             doCreate = EFalse;
   147             }
   179             }
   148     #endif // __WINS__
   180     #endif // __WINS__
   149 
   181 
   150     if ( doCreate )
   182     if ( doCreate )
   159             // In TestClass's test case (config) file can give name to caps
   191             // In TestClass's test case (config) file can give name to caps
   160             // modifier module.
   192             // modifier module.
   161             ret_caps = GetCapsModifier( aConfigFile, capsModifierName );
   193             ret_caps = GetCapsModifier( aConfigFile, capsModifierName );
   162             if( ret_caps != KErrNone )
   194             if( ret_caps != KErrNone )
   163                 {
   195                 {
   164                 RDebug::Print( _L( "Caps modifier was not defined. Default modifier will be used" ) );
   196                 RDebug::Print( _L( "RTestServer::Connect() Caps modifier was not defined. Default modifier will be used" ) );
   165                 }
   197                 }
   166             else
   198             else
   167                 {
   199                 {
   168                 #ifdef __WINS__ // CodeWarrior(emulator)
   200                 #ifdef __WINS__ // CodeWarrior(emulator)
   169                     // Create without path(Uses Symbian default path)
   201                     // Create without path(Uses Symbian default path)
   170                     ret = pr.Create( capsModifierName, aModuleName );
   202                     ret = pr.Create( capsModifierName, data );
   171                     if( ret == KErrNone )
   203                     if( ret == KErrNone )
   172                         {
   204                         {
   173                         RDebug::Print( _L( "Combination (2): Caps modifier[%S], Module[%S]" ),
   205                         RDebug::Print( _L( "RTestServer::Connect() Combination (2): Caps modifier [%S], Data [%S]"), &capsModifierName, &data);
   174                                         &capsModifierName, &aModuleName );
       
   175                         doCreate = EFalse;
   206                         doCreate = EFalse;
   176                         }
   207                         }
   177                 #endif // __WINS__
   208                 #endif // __WINS__
   178                 if ( doCreate )
   209                 if ( doCreate )
   179                     {
   210                     {
   198 
   229 
   199         // Check FindExeL error codes
   230         // Check FindExeL error codes
   200         if( find_ret != KErrNone )
   231         if( find_ret != KErrNone )
   201 			{
   232 			{
   202 			// Module was not found, using default exe: testserverstarter.exe
   233 			// Module was not found, using default exe: testserverstarter.exe
   203 			RDebug::Print( _L( "Correct caps modifier module not found, capabilities cannot set" ) );
   234 			RDebug::Print( _L( "RTestServer::Connect() Correct caps modifier module not found, capabilities cannot set" ) );
   204 			if ( aModuleName.Find( _L( "testscripter_ui_" ) ) == 0 ) 
   235 			if ( aModuleName.Find( _L( "testscripter_ui_" ) ) == 0 ) 
   205 				{
   236 				{
   206 				pathAndExeModule.Copy( KDefaultUiExeName );    	
   237 				pathAndExeModule.Copy( KDefaultUiExeName );    	
   207 				}
   238 				}
   208 			else
   239 			else
   211 				}           
   242 				}           
   212 			}
   243 			}
   213         if( trapd_ret != KErrNone )
   244         if( trapd_ret != KErrNone )
   214            {
   245            {
   215            // FindExeL fails
   246            // FindExeL fails
   216            RDebug::Print( _L( "Caps modifier module searching fails with error: %d" ), trapd_ret );
   247            RDebug::Print( _L( "RTestServer::Connect() Caps modifier module searching fails with error: %d" ), trapd_ret );
   217            startSemaphore.Close();
   248            startSemaphore.Close();
       
   249            data.Close();
   218            return trapd_ret;
   250            return trapd_ret;
   219            }
   251            }
   220 
   252 
   221         }
   253         }
   222 
   254 
   223     if ( doCreate )
   255     if ( doCreate )
   224         {
   256         {
   225         ret = pr.Create( pathAndExeModule, aModuleName );
   257         ret = pr.Create( pathAndExeModule, data );
   226         RDebug::Print(
   258         RDebug::Print(
   227             _L( "Combination (3): Caps modifier[%S], Module[%S]. Result: %d" ),
   259             _L( "RTestServer::Connect() Combination (3): Caps modifier [%S], Data [%S], Result [%d]" ),
   228             &pathAndExeModule, &aModuleName, ret );
   260             &pathAndExeModule, &data, ret );
   229         }
   261         }
   230 
   262 
   231         
   263     data.Close();
       
   264     
   232     if ( ret != KErrNone )
   265     if ( ret != KErrNone )
   233         {
   266         {
   234 		startSemaphore.Close();  
   267         startSemaphore.Close();  
   235         return ret;
   268         return ret;
   236         }
   269         }
   237 
   270 
   238     // Process created, continue start-up
   271     // Process created, continue start-up
   239     pr.Resume();
   272     pr.Resume();