serviceproviders/sapi_location/tsrc/dev/tlocservicetest/src/tfunctionthread.cpp
changeset 22 fc9cf246af83
parent 19 989d2f495d90
child 33 50974a8b132e
equal deleted inserted replaced
19:989d2f495d90 22:fc9cf246af83
    18 class CGetLoc ; //Forward declaration
    18 class CGetLoc ; //Forward declaration
    19 #include "TLocTest.h"
    19 #include "TLocTest.h"
    20 #include "locationservice.h"
    20 #include "locationservice.h"
    21 #include <f32file.h>
    21 #include <f32file.h>
    22 #include <e32const.h>
    22 #include <e32const.h>
    23 
    23 #include<liwcommon.h>
       
    24 TInt TraceTimeOutFuncL();
       
    25 
       
    26 TInt reqErr;//To share the error value from callback
       
    27 #define TRACE 1 
       
    28 #define GETLOCATION 0
    24 
    29 
    25 _LIT(LogFileName , "C:\\Notifications.txt") ;
    30 _LIT(LogFileName , "C:\\Notifications.txt") ;
    26 _LIT(KRequestor,"testapp");
    31 _LIT(KRequestor,"testapp");
    27 //---------------------------------------------------------------------------------------------------------
    32 //---------------------------------------------------------------------------------------------------------
    28 /** 
    33 /** 
    32   
    37   
    33  class LocUpdateCallBack : public MLocationCallBack
    38  class LocUpdateCallBack : public MLocationCallBack
    34  {
    39  {
    35    TInt iCount ;
    40    TInt iCount ;
    36    TInt iRetStatus ;
    41    TInt iRetStatus ;
    37     public :
    42     TInt iRequestType;
    38     	TInt HandleNotifyL(HPositionGenericInfo *posinfo , TInt aError) ;
    43     TInt iTransactionId;
    39     
    44 
    40     	LocUpdateCallBack() :iCount(0) , iRetStatus(KErrGeneral)  //Default constructor 
    45 
    41     	{
    46 public :
    42     		;
    47     TInt HandleNotifyL(HPositionGenericInfo *posinfo , TInt aError) ;
    43     	}
    48 
    44   };
    49 
       
    50     LocUpdateCallBack(TInt transId,TInt req) :iCount(0) , iRetStatus(KErrGeneral)  //Default constructor 
       
    51     	        {
       
    52     	        iTransactionId = transId;
       
    53     	        iRequestType = req;
       
    54     	        }
       
    55 
       
    56     inline TUint GetRequestType(void) 
       
    57         {
       
    58         return iRequestType ;
       
    59         }
       
    60 
       
    61 
       
    62     /**
       
    63      * GetTransactionId function returns transcation id associated with current async object
       
    64      *
       
    65      */
       
    66     inline TInt32 GetTransactionId(void)
       
    67         {
       
    68         return iTransactionId ;
       
    69         }
       
    70     };
    45   
    71   
    46   
    72   
    47   
    73   
    48 TInt LocUpdateCallBack :: HandleNotifyL(HPositionGenericInfo *posinfo , TInt aError)
    74 TInt LocUpdateCallBack :: HandleNotifyL(HPositionGenericInfo *posinfo , TInt aError)
    49 {
    75 {
    50 
    76 
    51  if(aError != KErrNone)
    77  if(aError != KErrNone)
    52  	{
    78  	{
    53  	 iRetStatus = aError ;
    79  	 iRetStatus = aError ;
    54  	 CActiveScheduler :: Stop() ;
    80         reqErr = KErrGeneral;
    55  	 return KErrNone ;
    81         CActiveScheduler :: Stop() ;
    56  	}
    82         return KErrGeneral ;
    57 if(iCount > 2)
    83         }
       
    84     iCount++ ;
       
    85     if(iCount > 1)
    58 	{
    86 	{
    59 	 iRetStatus = aError ;
    87 	 iRetStatus = aError ;
    60 	 CActiveScheduler *Current = CActiveScheduler :: Current() ;
    88 	 CActiveScheduler *Current = CActiveScheduler :: Current() ;
    61 	 Current->Stop() ;
    89 	 Current->Stop() ;
    62 	 return KErrNone ;
    90 	 return KErrNone ;
   116 }
   144 }
   117    
   145    
   118     	
   146     	
   119 TInt GetLocFunctionL()
   147 TInt GetLocFunctionL()
   120 {
   148 {
   121    
   149     __UHEAP_MARK ;
   122     	
   150     reqErr= KErrNone;
   123     
   151 
   124     LocUpdateCallBack MyUpdates  ;
   152     LocUpdateCallBack MyUpdates(9,TRACE)  ;
   125     CActiveScheduler *Scheduler = new CActiveScheduler ;
   153     CActiveScheduler *Scheduler = new CActiveScheduler ;
   126     
   154 
   127     CActiveScheduler :: Install(Scheduler) ;
   155     CActiveScheduler :: Install(Scheduler) ;
   128     CLocationService *CoreObj = CLocationService ::NewL() ;
   156     CLocationService *CoreObj = CLocationService ::NewL() ;
   129     
   157 
   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    
   158    
   138    // GelocUpdateCallBack  MyUpdates(&CmdId  , (CLocationService *)NULL) ;
       
   139     CoreObj->TraceL(&MyUpdates,EBasicInfo) ;
   159     CoreObj->TraceL(&MyUpdates,EBasicInfo) ;
   140     
   160 
   141     CActiveScheduler :: Start() ;
   161     CActiveScheduler :: Start() ;
   142     return 0 ; // Controll never reaches here
   162     delete CoreObj;
       
   163     delete Scheduler;
       
   164     __UHEAP_MARKEND ;
       
   165     return  reqErr; 
   143 }
   166 }
   144 
   167 
   145 TInt GetLocUpdates(TAny */*Arg*/)
   168 TInt GetLocUpdates(TAny */*Arg*/)
   146 {
   169 {
   147 	CTrapCleanup* cleanup = CTrapCleanup::New();
   170 	CTrapCleanup* cleanup = CTrapCleanup::New();
   159  
   182  
   160  class AsyncGetLoc : public MLocationCallBack
   183  class AsyncGetLoc : public MLocationCallBack
   161  {
   184  {
   162    TInt iCount ;
   185    TInt iCount ;
   163    TInt iRetStatus ;
   186    TInt iRetStatus ;
   164    public :
   187     TInt iRequestType;
   165     	TInt HandleNotifyL(HPositionGenericInfo* aPosInfo, TInt aError) ;
   188     TInt iTransactionId;
   166     
   189     public :
   167     	AsyncGetLoc() :iCount(0) , iRetStatus(KErrGeneral)  //Default constructor 
   190         TInt HandleNotifyL(HPositionGenericInfo* aPosInfo, TInt aError) ;
   168     	{
   191 
   169     		;
   192         AsyncGetLoc(TInt aTransId,TInt aReqType) :iCount(0) , iRetStatus(KErrGeneral)  //Default constructor 
   170     	}
   193     	        {
       
   194     	        iTransactionId = aTransId;
       
   195     	        iRequestType = aReqType;
       
   196     	        }
       
   197 
       
   198         inline TUint GetRequestType(void) 
       
   199             {
       
   200             return iRequestType ;
       
   201             }
       
   202 
       
   203 
       
   204         /**
       
   205          * GetTransactionId function returns transcation id associated with current async object
       
   206          *
       
   207          */
       
   208         inline TInt32 GetTransactionId(void)
       
   209             {
       
   210             return iTransactionId ;
       
   211             }
   171   };
   212   };
   172   
   213   
   173   
   214   
   174   
   215   
   175 TInt AsyncGetLoc :: HandleNotifyL(HPositionGenericInfo* aPosInfo , TInt aError)
   216 TInt AsyncGetLoc :: HandleNotifyL(HPositionGenericInfo* aPosInfo , TInt aError)
   180  
   221  
   181  
   222  
   182  if(aError != KErrNone)
   223  if(aError != KErrNone)
   183  	{
   224  	{
   184  	 iRetStatus = aError ;
   225  	 iRetStatus = aError ;
       
   226         reqErr = aError;
   185  	 CActiveScheduler :: Stop() ;
   227  	 CActiveScheduler :: Stop() ;
   186  	 return KErrNone ;
   228  	 return KErrNone ;
   187  	}
   229  	}
   188  
   230  
   189  
   231  
   238   	
   280   	
   239 }
   281 }
   240 
   282 
   241 TInt GetLocAsynchFunctionL()
   283 TInt GetLocAsynchFunctionL()
   242 {
   284 {
   243 	CActiveScheduler *Scheduler = new CActiveScheduler ;
   285     __UHEAP_MARK ;
   244     
   286     reqErr = KErrNone;
       
   287     CActiveScheduler *Scheduler = new CActiveScheduler ;
       
   288 
   245     CActiveScheduler :: Install(Scheduler) ;
   289     CActiveScheduler :: Install(Scheduler) ;
   246     CLocationService *CoreObj = CLocationService ::NewL() ;
   290     CLocationService *CoreObj = CLocationService ::NewL() ;
   247   
   291 
   248     AsyncGetLoc MyUpdates ;
   292     AsyncGetLoc MyUpdates(10,GETLOCATION) ;
   249     //not needed any more
   293     //not needed any more
   250     /*RRequestorStack infostack;
   294     /*RRequestorStack infostack;
   251     
   295 
   252     const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
   296     const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
   253     												KRequestor) ;
   297     												KRequestor) ;
   254     infostack.Append(identityInfo);
   298     infostack.Append(identityInfo);
   255     CoreObj->SetRequestorIdentityL(infostack);*/
   299     CoreObj->SetRequestorIdentityL(infostack);*/
   256     CoreObj->GetLocationL(&MyUpdates,EBasicInfo) ;
   300     CoreObj->GetLocationL(&MyUpdates,EBasicInfo) ;
   257     
   301 
   258     CActiveScheduler :: Start() ; 
   302     CActiveScheduler :: Start() ; 
   259     return 0 ;      //Controll never reaches here 
   303     delete CoreObj;
       
   304     delete Scheduler;
       
   305     __UHEAP_MARKEND ;
       
   306     return reqErr ; 
   260 }
   307 }
   261 
   308 
   262 
   309 
   263 
   310 
   264 
   311 
   278  */
   325  */
   279  //---------------------------------------------------------------------------------------------------------
   326  //---------------------------------------------------------------------------------------------------------
   280 
   327 
   281 TInt ServiceFailedFunctionL()
   328 TInt ServiceFailedFunctionL()
   282 {
   329 {
   283 		
   330     reqErr = KErrNone;
   284 		CActiveScheduler *Scheduler = new CActiveScheduler ;
   331     __UHEAP_MARK ;
   285 		CActiveScheduler :: Install(Scheduler) ;
   332     CActiveScheduler *Scheduler = new CActiveScheduler ;
   286 		CLocationService *CoreObj = CLocationService ::NewL() ;
   333     CActiveScheduler :: Install(Scheduler) ;
   287 		
   334     CLocationService *CoreObj = CLocationService ::NewL() ;
   288 		//not needed any more
   335 
   289 		/*RRequestorStack infostack;
   336     LocUpdateCallBack MyUpdates(11,TRACE) ;
   290     
   337 
   291 	    const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
   338     CoreObj->TraceL(&MyUpdates,EBasicInfo) ;
   292 	    												KRequestor) ;
   339     CActiveScheduler :: Start() ; 
   293 	    infostack.Append(identityInfo);
   340     delete CoreObj;
   294 	    CoreObj->SetRequestorIdentityL(infostack);*/
   341     delete Scheduler;
   295 		
   342     __UHEAP_MARKEND ;
   296 		LocUpdateCallBack MyUpdates ;
   343     return  reqErr ;
   297     
       
   298     	CoreObj->TraceL(&MyUpdates,EBasicInfo) ;
       
   299     	CActiveScheduler :: Start() ; 
       
   300     	return  0 ;
       
   301     	
   344     	
   302     	
   345     	
   303 
   346 
   304 }
   347 }
   305 
   348 
   306 
   349 
   307 
   350 
   308 TInt ServiceFailedTest(TAny */*Arg*/)
   351 TInt ServiceFailedTest(TAny */*Arg*/)
   309 {
   352 {
   310 	CTrapCleanup* cleanup = CTrapCleanup::New();
   353     TInt errRet;
   311 	TRAPD(err , ServiceFailedFunctionL()) ;
   354     CTrapCleanup* cleanup = CTrapCleanup::New();
   312 	delete cleanup ;
   355     TRAPD(err , errRet = ServiceFailedFunctionL()) ;
   313 	return 0 ;
   356     delete cleanup ;
       
   357 
       
   358     return errRet ;
   314 	
   359 	
   315 }
   360 }
   316 
   361 
   317 
   362 
   318 
   363 
   319 TInt ConcurrentGetLocCallsL()
   364 TInt ConcurrentGetLocCallsL()
   320 	{
   365 	{
   321 	LocUpdateCallBack MyUpdates  ;
   366     __UHEAP_MARK ;
       
   367     reqErr = KErrNone;
       
   368     LocUpdateCallBack MyUpdates(10,GETLOCATION)  ;
   322     CActiveScheduler *Scheduler = new CActiveScheduler ;
   369     CActiveScheduler *Scheduler = new CActiveScheduler ;
   323     
   370 
   324     CActiveScheduler :: Install(Scheduler) ;
   371     CActiveScheduler :: Install(Scheduler) ;
   325     CLocationService *CoreObj = CLocationService ::NewL() ;
   372     CLocationService *CoreObj = CLocationService ::NewL() ;
   326     
   373 
   327     //not needed any more
   374 
   328     /*RRequestorStack infostack;
   375 
   329     
   376     CoreObj->GetLocationL(&MyUpdates,EBasicInfo) ;
   330     const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
   377 
   331     												KRequestor) ;
   378     TRAPD(error, CoreObj->GetLocationL(&MyUpdates,EBasicInfo) );
   332     infostack.Append(identityInfo);
   379 
   333     CoreObj->SetRequestorIdentityL(infostack);*/
   380     CActiveScheduler :: Start() ; 
   334    
   381     delete CoreObj;
   335     
   382     delete Scheduler;
   336      CoreObj->GetLocationL(&MyUpdates,EBasicInfo) ;
   383     __UHEAP_MARKEND ;
   337     
   384 
   338      TInt error = CoreObj->GetLocationL(&MyUpdates,EBasicInfo) ;
   385     return error | reqErr ; 
   339     
       
   340     
       
   341     return error ; 
       
   342 
   386 
   343 		
   387 		
   344 		
   388 		
   345 		
   389 		
   346 	}
   390 	}
   362 	return Val ;
   406 	return Val ;
   363 }
   407 }
   364 
   408 
   365   
   409   
   366 
   410 
   367 TInt CTLocTest:: ConcurrentCallsGetLoc(CStifItemParser& /*aItem*/)
   411 
   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 
   412 
   396 
   413 
   397 TInt ConcurrentTraceCallsL()
   414 TInt ConcurrentTraceCallsL()
   398 	{
   415 	{
   399 	LocUpdateCallBack MyUpdates  ;
   416     __UHEAP_MARK ;
       
   417     reqErr = KErrNone;
       
   418     LocUpdateCallBack MyUpdates(12,TRACE)  ;
   400     CActiveScheduler *Scheduler = new CActiveScheduler ;
   419     CActiveScheduler *Scheduler = new CActiveScheduler ;
   401     
   420 
   402     CActiveScheduler :: Install(Scheduler) ;
   421     CActiveScheduler :: Install(Scheduler) ;
   403     CLocationService *CoreObj = CLocationService ::NewL() ;
   422     CLocationService *CoreObj = CLocationService ::NewL() ;
   404     
   423 
   405     //not needed any more
   424     //not needed any more
   406     /*RRequestorStack infostack;
   425     /*RRequestorStack infostack;
   407     
   426 
   408     const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
   427     const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
   409     												KRequestor) ;
   428     												KRequestor) ;
   410     infostack.Append(identityInfo);
   429     infostack.Append(identityInfo);
   411     CoreObj->SetRequestorIdentityL(infostack);*/
   430     CoreObj->SetRequestorIdentityL(infostack);*/
   412    
   431 
   413     
   432 
   414      CoreObj->TraceL(&MyUpdates,EBasicInfo) ;(&MyUpdates,EBasicInfo) ;
   433     CoreObj->TraceL(&MyUpdates,EBasicInfo) ;
   415     
   434 
   416      TInt error = CoreObj->TraceL(&MyUpdates,EBasicInfo) ;
   435     TRAPD(error,CoreObj->TraceL(&MyUpdates,EBasicInfo)) ;
   417     
   436 
   418     
   437     CActiveScheduler :: Start() ; 
   419     return error ; 
   438     delete CoreObj;
       
   439     delete Scheduler;
       
   440     __UHEAP_MARKEND ;
       
   441     return error | reqErr ; 
   420 
   442 
   421 		
   443 		
   422 		
   444 		
   423 		
   445 		
   424 	}
   446 	}
   439  	    }
   461  	    }
   440 	return Val ;
   462 	return Val ;
   441 }
   463 }
   442 
   464 
   443 	
   465 	
   444 TInt CTLocTest:: ConcurrentCallsTrace(CStifItemParser& /*aItem*/)
   466 
   445 	{
   467 TInt TraceTimeOutFunc(TAny */*Arg*/)
   446 	_LIT(KTLocTest ,"TLocTest");
   468     {
   447 	iLog->Log(KTLocTest) ;
   469 
   448 	
   470     CTrapCleanup* cleanup = CTrapCleanup::New();
   449 	TRequestStatus Status = KRequestPending  ;
   471     TInt  Val ;
   450 	RThread FunctionThread ;
   472     //Install a new active scheduler to this thread 
   451     
   473     TRAPD(err ,( Val = TraceTimeOutFuncL()) );
   452     TInt ret = FunctionThread.Create(_L(" ConcurrentCallsGetLoc Thread") , ConcurrentTraceCalls ,KDefaultStackSize , 
   474     delete cleanup ;
   453     						KMinHeapSize , 0x5000 ,(TAny *) NULL);
   475 
   454     						
   476     if(err)
   455     if(ret == KErrNone)
   477         {
   456 	    {
   478         return err ;
   457 	    FunctionThread.Logon(Status)	;
   479         }
   458 	    FunctionThread.Resume() ;
   480     return Val ;
   459 	    
   481     }
   460 	    User :: WaitForRequest (Status)	;				
   482 
   461 	    
   483 
   462 
   484 class LocUpdateCallBackTO : public MLocationCallBack
   463 	   ret = Status.Int() ;
   485     {
   464 	    }
   486     TInt iCount ;
   465 	  FunctionThread.Close();  
   487     TInt iRetStatus ;
   466 	  
   488     TInt iRequestType;
   467 	  if(ret == KErrInUse)
   489     TInt iTransactionId;
   468 	    return KErrNone ;
   490     public :
   469 	  
   491         TInt HandleNotifyL(HPositionGenericInfo *posinfo , TInt aError) ;
   470 	   return KErrGeneral;	
   492 
   471 	}
   493         LocUpdateCallBackTO(TInt transId,TInt req) :iCount(0) , iRetStatus(KErrGeneral)  //Default constructor 
   472 
   494                {
       
   495                iTransactionId = transId;
       
   496                iRequestType = req;
       
   497                }
       
   498 
       
   499         inline TUint GetRequestType(void) 
       
   500             {
       
   501             return iRequestType ;
       
   502             }
       
   503 
       
   504 
       
   505         /**
       
   506          * GetTransactionId function returns transcation id associated with current async object
       
   507          *
       
   508          */
       
   509         inline TInt32 GetTransactionId(void)
       
   510             {
       
   511             return iTransactionId ;
       
   512             }
       
   513 
       
   514 
       
   515     };
       
   516 
       
   517 
       
   518 
       
   519 TInt LocUpdateCallBackTO :: HandleNotifyL(HPositionGenericInfo *posinfo , TInt aError)
       
   520     {
       
   521     iCount++;
       
   522     if(aError != KErrTimedOut)
       
   523         {
       
   524         iRetStatus = aError ;
       
   525         CActiveScheduler *Current = CActiveScheduler :: Current() ;
       
   526         reqErr = KErrGeneral;
       
   527         Current->Stop() ;
       
   528 
       
   529         return KErrGeneral ;
       
   530         }
       
   531 
       
   532     else if(iCount > 2)
       
   533         {
       
   534         iRetStatus = aError ;
       
   535         CActiveScheduler *Current = CActiveScheduler :: Current() ;
       
   536         Current->Stop() ;
       
   537 
       
   538         }
       
   539     return KErrNone ;   
       
   540     }
       
   541 
       
   542 
       
   543 TInt TraceTimeOutFuncL()
       
   544     {
       
   545     __UHEAP_MARK ;
       
   546     reqErr = KErrNone;
       
   547     LocUpdateCallBackTO MyUpdates(14,TRACE)  ;
       
   548     CActiveScheduler *Scheduler = new CActiveScheduler ;
       
   549 
       
   550     CActiveScheduler :: Install(Scheduler) ;
       
   551     CLocationService *CoreObj = CLocationService ::NewL() ;
       
   552 
       
   553 
       
   554 
       
   555     TPositionUpdateOptions updateopts ;
       
   556     updateopts.SetUpdateTimeOut(3);
       
   557     TPositionFieldId FieldList[10] ;
       
   558     CoreObj->TraceL(&MyUpdates,EBasicInfo,FieldList,&updateopts) ;
       
   559 
       
   560 
       
   561     CActiveScheduler :: Start() ; 
       
   562     delete CoreObj;
       
   563     delete Scheduler;
       
   564     __UHEAP_MARKEND ;
       
   565     return reqErr;    
       
   566     }