sapi_location/tsrc/dev/tlocservicetest/src/tfunctionthread.cpp
changeset 0 14df0fbfcc4e
equal deleted inserted replaced
-1:000000000000 0:14df0fbfcc4e
       
     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 the License "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 class CGetLoc ; //Forward declaration
       
    19 #include "TLocTest.h"
       
    20 #include "locationservice.h"
       
    21 #include <f32file.h>
       
    22 #include <e32const.h>
       
    23 
       
    24 
       
    25 _LIT(LogFileName , "C:\\Notifications.txt") ;
       
    26 _LIT(KRequestor,"testapp");
       
    27 //---------------------------------------------------------------------------------------------------------
       
    28 /** 
       
    29   *@ This call back interface is for testing Trace 
       
    30  */
       
    31  //---------------------------------------------------------------------------------------------------------
       
    32   
       
    33  class LocUpdateCallBack : public MLocationCallBack
       
    34  {
       
    35    TInt iCount ;
       
    36    TInt iRetStatus ;
       
    37     public :
       
    38     	TInt HandleNotifyL(HPositionGenericInfo *posinfo , TInt aError) ;
       
    39     
       
    40     	LocUpdateCallBack() :iCount(0) , iRetStatus(KErrGeneral)  //Default constructor 
       
    41     	{
       
    42     		;
       
    43     	}
       
    44   };
       
    45   
       
    46   
       
    47   
       
    48 TInt LocUpdateCallBack :: HandleNotifyL(HPositionGenericInfo *posinfo , TInt aError)
       
    49 {
       
    50 
       
    51  if(aError != KErrNone)
       
    52  	{
       
    53  	 iRetStatus = aError ;
       
    54  	 CActiveScheduler :: Stop() ;
       
    55  	 return KErrNone ;
       
    56  	}
       
    57 if(iCount > 2)
       
    58 	{
       
    59 	 iRetStatus = aError ;
       
    60 	 CActiveScheduler *Current = CActiveScheduler :: Current() ;
       
    61 	 Current->Stop() ;
       
    62 	 return KErrNone ;
       
    63 	}
       
    64 		
       
    65  RFile LogFile ;
       
    66  RFs LogSession ;
       
    67  TBuf8<50> Buffer(_L8("Latitude = ")) ;
       
    68  
       
    69  TPosition OutPos ;
       
    70  
       
    71  posinfo->GetPosition(OutPos) ;
       
    72  
       
    73  
       
    74  
       
    75  LogSession.Connect() ;
       
    76  
       
    77  if(LogFile.Open(LogSession ,LogFileName , EFileWrite | EFileShareAny )  == KErrNotFound)
       
    78  {
       
    79   LogFile.Create(LogSession ,LogFileName , EFileWrite | EFileShareAny ) ;
       
    80  	
       
    81  }
       
    82  
       
    83  TInt End = 0 ;
       
    84  
       
    85  LogFile.Seek(ESeekEnd , End) ; //Seek to end of the file before writing 
       
    86  
       
    87  TBuf8<50> num ;
       
    88  TRealFormat format ;
       
    89  TReal64 Val = OutPos.Latitude() ;
       
    90  num.Num(Val , format) ;
       
    91 
       
    92  //Logging Latitude 
       
    93  LogFile.Write(_L8("Latitude = "));
       
    94  LogFile.Write(num) ;
       
    95  LogFile.Write(_L8("\n")) ;
       
    96 	 
       
    97  Val = OutPos.Longitude() ;
       
    98  num.Num(Val , format) ;
       
    99  
       
   100  //Logging Longitude
       
   101  
       
   102   LogFile.Write(_L8("Longitude = "));
       
   103   LogFile.Write(num) ;
       
   104   LogFile.Write(_L8("\n")) ;
       
   105  	
       
   106  	//Logging Altitude 
       
   107   Val = OutPos.Altitude() ;
       
   108   num.Num(Val , format) ;
       
   109   LogFile.Write(_L8("Altitude = "));
       
   110   LogFile.Write(num) ;
       
   111   LogFile.Write(_L8("\n"))  ;
       
   112   LogFile.Close() ;
       
   113   LogSession.Close() ;
       
   114   iCount++ ;
       
   115   return KErrNone ;	
       
   116 }
       
   117    
       
   118     	
       
   119 TInt GetLocFunctionL()
       
   120 {
       
   121    
       
   122     	
       
   123     
       
   124     LocUpdateCallBack MyUpdates  ;
       
   125     CActiveScheduler *Scheduler = new CActiveScheduler ;
       
   126     
       
   127     CActiveScheduler :: Install(Scheduler) ;
       
   128     CLocationService *CoreObj = CLocationService ::NewL() ;
       
   129     
       
   130     //not needed any more
       
   131     /*RRequestorStack infostack;
       
   132     
       
   133     const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
       
   134     												KRequestor) ;
       
   135     infostack.Append(identityInfo);
       
   136     CoreObj->SetRequestorIdentityL(infostack);*/
       
   137    
       
   138    // GelocUpdateCallBack  MyUpdates(&CmdId  , (CLocationService *)NULL) ;
       
   139     CoreObj->TraceL(&MyUpdates,EBasicInfo) ;
       
   140     
       
   141     CActiveScheduler :: Start() ;
       
   142     return 0 ; // Controll never reaches here
       
   143 }
       
   144 
       
   145 TInt GetLocUpdates(TAny */*Arg*/)
       
   146 {
       
   147 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   148   //Install a new active scheduler to this thread 
       
   149   TRAPD(err , GetLocFunctionL()) ;
       
   150     delete cleanup ;
       
   151 	return 0 ;
       
   152 }
       
   153 
       
   154 //---------------------------------------------------------------------------------------------------------
       
   155 /** 
       
   156   *@ This call back interface is for testing GetLocation Asynchronous 
       
   157  */
       
   158  //---------------------------------------------------------------------------------------------------------
       
   159  
       
   160  class AsyncGetLoc : public MLocationCallBack
       
   161  {
       
   162    TInt iCount ;
       
   163    TInt iRetStatus ;
       
   164    public :
       
   165     	TInt HandleNotifyL(HPositionGenericInfo* aPosInfo, TInt aError) ;
       
   166     
       
   167     	AsyncGetLoc() :iCount(0) , iRetStatus(KErrGeneral)  //Default constructor 
       
   168     	{
       
   169     		;
       
   170     	}
       
   171   };
       
   172   
       
   173   
       
   174   
       
   175 TInt AsyncGetLoc :: HandleNotifyL(HPositionGenericInfo* aPosInfo , TInt aError)
       
   176 {
       
   177  RFile LogFile ;
       
   178  RFs LogSession ;
       
   179  TBuf8<50> Buffer(_L8("Latitude = ")) ;
       
   180  
       
   181  
       
   182  if(aError != KErrNone)
       
   183  	{
       
   184  	 iRetStatus = aError ;
       
   185  	 CActiveScheduler :: Stop() ;
       
   186  	 return KErrNone ;
       
   187  	}
       
   188  
       
   189  
       
   190  LogSession.Connect() ;
       
   191  
       
   192  if(LogFile.Open(LogSession ,LogFileName , EFileWrite | EFileShareAny )  == KErrNotFound)
       
   193  {
       
   194   LogFile.Create(LogSession ,LogFileName , EFileWrite | EFileShareAny ) ;
       
   195  	
       
   196  }
       
   197  
       
   198  TInt End = 0 ;
       
   199  
       
   200  LogFile.Seek(ESeekEnd , End) ; //Seek to end of the file before writing 
       
   201  
       
   202  TPosition aOutPos ;
       
   203  
       
   204  aPosInfo->GetPosition(aOutPos) ;
       
   205  TBuf8<50> num ;
       
   206  TRealFormat format ;
       
   207  TReal64 Val = aOutPos.Latitude() ;
       
   208  num.Num(Val , format) ;
       
   209 
       
   210  //Logging Latitude 
       
   211  LogFile.Write(_L8("Latitude = "));
       
   212  LogFile.Write(num) ;
       
   213  LogFile.Write(_L8("\n")) ;
       
   214 	 
       
   215  Val = aOutPos.Longitude() ;
       
   216  num.Num(Val , format) ;
       
   217  
       
   218  //Logging Longitude
       
   219  
       
   220   LogFile.Write(_L8("Longitude = "));
       
   221   LogFile.Write(num) ;
       
   222   LogFile.Write(_L8("\n")) ;
       
   223  	
       
   224  	//Logging Altitude 
       
   225   Val = aOutPos.Altitude() ;
       
   226   num.Num(Val , format) ;
       
   227   LogFile.Write(_L8("Altitude = "));
       
   228   LogFile.Write(num) ;
       
   229   LogFile.Write(_L8("\n"))  ;
       
   230   LogFile.Close() ;
       
   231   LogSession.Close() ;
       
   232   iRetStatus = aError ;
       
   233   
       
   234   CActiveScheduler *Current = CActiveScheduler :: Current() ;
       
   235   Current->Stop() ;
       
   236   
       
   237   return KErrNone ;
       
   238   	
       
   239 }
       
   240 
       
   241 TInt GetLocAsynchFunctionL()
       
   242 {
       
   243 	CActiveScheduler *Scheduler = new CActiveScheduler ;
       
   244     
       
   245     CActiveScheduler :: Install(Scheduler) ;
       
   246     CLocationService *CoreObj = CLocationService ::NewL() ;
       
   247   
       
   248     AsyncGetLoc MyUpdates ;
       
   249     //not needed any more
       
   250     /*RRequestorStack infostack;
       
   251     
       
   252     const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
       
   253     												KRequestor) ;
       
   254     infostack.Append(identityInfo);
       
   255     CoreObj->SetRequestorIdentityL(infostack);*/
       
   256     CoreObj->GetLocationL(&MyUpdates,EBasicInfo) ;
       
   257     
       
   258     CActiveScheduler :: Start() ; 
       
   259     return 0 ;      //Controll never reaches here 
       
   260 }
       
   261 
       
   262 
       
   263 
       
   264 
       
   265 TInt FindLocationAsynch(TAny * /*Arg*/)
       
   266 {
       
   267 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   268   
       
   269     TRAPD(err , GetLocAsynchFunctionL()) ;
       
   270     delete cleanup ;
       
   271 	return 0 ;
       
   272 	
       
   273 }
       
   274 
       
   275 //---------------------------------------------------------------------------------------------------------
       
   276 /** 
       
   277   *@ This call back interface is for testing  Service Not available  
       
   278  */
       
   279  //---------------------------------------------------------------------------------------------------------
       
   280 
       
   281 TInt ServiceFailedFunctionL()
       
   282 {
       
   283 		
       
   284 		CActiveScheduler *Scheduler = new CActiveScheduler ;
       
   285 		CActiveScheduler :: Install(Scheduler) ;
       
   286 		CLocationService *CoreObj = CLocationService ::NewL() ;
       
   287 		
       
   288 		//not needed any more
       
   289 		/*RRequestorStack infostack;
       
   290     
       
   291 	    const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
       
   292 	    												KRequestor) ;
       
   293 	    infostack.Append(identityInfo);
       
   294 	    CoreObj->SetRequestorIdentityL(infostack);*/
       
   295 		
       
   296 		LocUpdateCallBack MyUpdates ;
       
   297     
       
   298     	CoreObj->TraceL(&MyUpdates,EBasicInfo) ;
       
   299     	CActiveScheduler :: Start() ; 
       
   300     	return  0 ;
       
   301     	
       
   302     	
       
   303 
       
   304 }
       
   305 
       
   306 
       
   307 
       
   308 TInt ServiceFailedTest(TAny */*Arg*/)
       
   309 {
       
   310 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   311 	TRAPD(err , ServiceFailedFunctionL()) ;
       
   312 	delete cleanup ;
       
   313 	return 0 ;
       
   314 	
       
   315 }
       
   316 
       
   317 
       
   318 
       
   319 TInt ConcurrentGetLocCallsL()
       
   320 	{
       
   321 	LocUpdateCallBack MyUpdates  ;
       
   322     CActiveScheduler *Scheduler = new CActiveScheduler ;
       
   323     
       
   324     CActiveScheduler :: Install(Scheduler) ;
       
   325     CLocationService *CoreObj = CLocationService ::NewL() ;
       
   326     
       
   327     //not needed any more
       
   328     /*RRequestorStack infostack;
       
   329     
       
   330     const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
       
   331     												KRequestor) ;
       
   332     infostack.Append(identityInfo);
       
   333     CoreObj->SetRequestorIdentityL(infostack);*/
       
   334    
       
   335     
       
   336      CoreObj->GetLocationL(&MyUpdates,EBasicInfo) ;
       
   337     
       
   338      TInt error = CoreObj->GetLocationL(&MyUpdates,EBasicInfo) ;
       
   339     
       
   340     
       
   341     return error ; 
       
   342 
       
   343 		
       
   344 		
       
   345 		
       
   346 	}
       
   347 
       
   348 
       
   349 TInt ConcurrentGetLocationCalls(TAny */*Arg*/)
       
   350 {
       
   351   
       
   352 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   353 	TInt  Val ;
       
   354 	//Install a new active scheduler to this thread 
       
   355 	TRAPD(err ,( Val = ConcurrentGetLocCallsL()) );
       
   356 	delete cleanup ;
       
   357  	
       
   358  	if(err)
       
   359  	    {
       
   360  	        return err ;
       
   361  	    }
       
   362 	return Val ;
       
   363 }
       
   364 
       
   365   
       
   366 
       
   367 TInt CTLocTest:: ConcurrentCallsGetLoc(CStifItemParser& /*aItem*/)
       
   368 	{
       
   369 	_LIT(KTLocTest ,"TLocTest");
       
   370 	iLog->Log(KTLocTest) ;
       
   371 	
       
   372 	TRequestStatus Status = KRequestPending  ;
       
   373 	RThread FunctionThread ;
       
   374     
       
   375     TInt ret = FunctionThread.Create(_L(" ConcurrentCallsGetLoc Thread") , ConcurrentGetLocationCalls ,KDefaultStackSize , 
       
   376     						KMinHeapSize , 0x5000 ,(TAny *) NULL);
       
   377     						
       
   378     if(ret == KErrNone)
       
   379 	    {
       
   380 	    FunctionThread.Logon(Status)	;
       
   381 	    FunctionThread.Resume() ;
       
   382 	    
       
   383 	    User :: WaitForRequest (Status)	;				
       
   384 	    
       
   385 
       
   386 	   ret = Status.Int() ;
       
   387 	    }
       
   388 	  FunctionThread.Close();  
       
   389 	  
       
   390 	  if(ret == KErrInUse)
       
   391 	    return KErrNone ;
       
   392 	  
       
   393 	   return KErrGeneral;	
       
   394 	}
       
   395 
       
   396 
       
   397 TInt ConcurrentTraceCallsL()
       
   398 	{
       
   399 	LocUpdateCallBack MyUpdates  ;
       
   400     CActiveScheduler *Scheduler = new CActiveScheduler ;
       
   401     
       
   402     CActiveScheduler :: Install(Scheduler) ;
       
   403     CLocationService *CoreObj = CLocationService ::NewL() ;
       
   404     
       
   405     //not needed any more
       
   406     /*RRequestorStack infostack;
       
   407     
       
   408     const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
       
   409     												KRequestor) ;
       
   410     infostack.Append(identityInfo);
       
   411     CoreObj->SetRequestorIdentityL(infostack);*/
       
   412    
       
   413     
       
   414      CoreObj->TraceL(&MyUpdates,EBasicInfo) ;(&MyUpdates,EBasicInfo) ;
       
   415     
       
   416      TInt error = CoreObj->TraceL(&MyUpdates,EBasicInfo) ;
       
   417     
       
   418     
       
   419     return error ; 
       
   420 
       
   421 		
       
   422 		
       
   423 		
       
   424 	}
       
   425 
       
   426 
       
   427 TInt ConcurrentTraceCalls(TAny */*Arg*/)
       
   428 {
       
   429   
       
   430 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   431 	TInt  Val ;
       
   432 	//Install a new active scheduler to this thread 
       
   433 	TRAPD(err ,( Val = ConcurrentTraceCallsL()) );
       
   434 	delete cleanup ;
       
   435  	
       
   436  	if(err)
       
   437  	    {
       
   438  	        return err ;
       
   439  	    }
       
   440 	return Val ;
       
   441 }
       
   442 
       
   443 	
       
   444 TInt CTLocTest:: ConcurrentCallsTrace(CStifItemParser& /*aItem*/)
       
   445 	{
       
   446 	_LIT(KTLocTest ,"TLocTest");
       
   447 	iLog->Log(KTLocTest) ;
       
   448 	
       
   449 	TRequestStatus Status = KRequestPending  ;
       
   450 	RThread FunctionThread ;
       
   451     
       
   452     TInt ret = FunctionThread.Create(_L(" ConcurrentCallsGetLoc Thread") , ConcurrentTraceCalls ,KDefaultStackSize , 
       
   453     						KMinHeapSize , 0x5000 ,(TAny *) NULL);
       
   454     						
       
   455     if(ret == KErrNone)
       
   456 	    {
       
   457 	    FunctionThread.Logon(Status)	;
       
   458 	    FunctionThread.Resume() ;
       
   459 	    
       
   460 	    User :: WaitForRequest (Status)	;				
       
   461 	    
       
   462 
       
   463 	   ret = Status.Int() ;
       
   464 	    }
       
   465 	  FunctionThread.Close();  
       
   466 	  
       
   467 	  if(ret == KErrInUse)
       
   468 	    return KErrNone ;
       
   469 	  
       
   470 	   return KErrGeneral;	
       
   471 	}
       
   472