serviceproviders/sapi_location/tsrc/dev/tlocationprovidertest/src/ttrace.cpp
changeset 19 989d2f495d90
child 22 fc9cf246af83
equal deleted inserted replaced
14:a36b1e19a461 19:989d2f495d90
       
     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 #include <e32svr.h>
       
    19 #include <StifParser.h>
       
    20 #include <Stiftestinterface.h>
       
    21 #include <LbsRequestor.h>
       
    22 #include <LiwServiceHandler.h>
       
    23 #include <LiwCommon.h>
       
    24 
       
    25 #include "tcomplugin.h"
       
    26 
       
    27 
       
    28 _LIT(LogFileName , "C:\\Notifications.txt") ;
       
    29 
       
    30 //---------------------------------------------------------------------------------------------------------
       
    31 /** 
       
    32   *@ This call back interface is for testing Trace 
       
    33  */
       
    34  //---------------------------------------------------------------------------------------------------------
       
    35   
       
    36  class LocUpdateCallBack : public MLiwNotifyCallback
       
    37  {
       
    38    TInt iCount ;
       
    39    TInt iRetStatus ;
       
    40     public :
       
    41     	TInt HandleNotifyL(
       
    42             TInt aCmdId,
       
    43             TInt aEventId,
       
    44             CLiwGenericParamList& aEventParamList,
       
    45             const CLiwGenericParamList& aInParamList);
       
    46     
       
    47     	LocUpdateCallBack() :iCount(0) , iRetStatus(KErrGeneral)  //Default constructor 
       
    48     	{
       
    49     		;
       
    50     	}
       
    51   };
       
    52   
       
    53   
       
    54   
       
    55 TInt LocUpdateCallBack ::  HandleNotifyL(
       
    56             TInt aCmdId,
       
    57             TInt aEventId,
       
    58             CLiwGenericParamList& aEventParamList,
       
    59             const CLiwGenericParamList& aInParamList)
       
    60 {
       
    61 
       
    62    TBuf8<50> data ;
       
    63    TRealFormat format ;
       
    64 
       
    65 	iCount++ ;
       
    66 
       
    67 	RFile LogFile ;
       
    68 	RFs LogSession ;
       
    69 	TBuf8<50> Buffer(_L8("Latitude = ")) ;
       
    70 
       
    71 
       
    72 
       
    73 	LogSession.Connect() ;
       
    74 
       
    75 	if(LogFile.Open(LogSession ,LogFileName , EFileWrite | EFileShareAny )  == KErrNotFound)
       
    76 	{
       
    77 		LogFile.Create(LogSession ,LogFileName , EFileWrite | EFileShareAny ) ;
       
    78 
       
    79 	}
       
    80 
       
    81 	TInt End = 0 ;
       
    82 	TInt index = 0 ;
       
    83 	const TLiwGenericParam *GenericParam =  aEventParamList.FindFirst(index , KErrorCode) ;
       
    84 
       
    85 	if(!GenericParam)
       
    86 	{
       
    87 		return KErrGeneral ;
       
    88 	}
       
    89 
       
    90 	if((GenericParam->Value()).AsTInt32() != KErrNone)
       
    91 	{
       
    92 		return (GenericParam->Value()).AsTInt32() ;
       
    93 	}
       
    94 		
       
    95 	index = 0 ;
       
    96 
       
    97 	LogFile.Seek(ESeekEnd , End) ; //Seek to end of the file before writing 
       
    98 
       
    99 		const TLiwGenericParam *MapParam = aEventParamList.FindFirst(index ,KLocationMap) ;
       
   100 		
       
   101 		if(!MapParam)
       
   102 		{
       
   103 			return KErrGeneral ;
       
   104 		}
       
   105 
       
   106 		TLiwVariant Variant ;
       
   107 
       
   108 		Variant = MapParam->Value() ;
       
   109 		const CLiwMap *LocMap = Variant.AsMap() ;
       
   110 
       
   111 		TLiwVariant PosVariant ;
       
   112 
       
   113 		LocMap->FindL(KLongitudeKey , PosVariant) ;
       
   114 
       
   115 
       
   116 	TReal64 LongData = (TReal64)PosVariant.AsTReal() ; //Longitude
       
   117 		data.Num(LongData , format) ;
       
   118 		LogFile.Write(_L8("\n")) ;
       
   119 		LogFile.Write(_L8("Logitude = ")) ;
       
   120 		LogFile.Write(data) ;
       
   121 
       
   122 		LocMap->FindL(KLatitudeKey ,PosVariant) ; //Latitude 
       
   123 
       
   124 	TReal64 LatData = (TReal64)PosVariant.AsTReal() ;
       
   125 		data.Num(LatData , format) ;
       
   126 		LogFile.Write(_L8("   Latitude = ")) ;
       
   127 		LogFile.Write(data) ;
       
   128 
       
   129 		LocMap->FindL(KAltitudeKey , PosVariant) ; //Altitude
       
   130 	TReal32 AltData = PosVariant.AsTReal() ;
       
   131 		data.Num(AltData , format) ;
       
   132 
       
   133 		LogFile.Write(_L8("   Altitude = "))	 ;
       
   134 		LogFile.Write(data) ;
       
   135 		//LocMap->DecRef() ;
       
   136 	 	
       
   137 
       
   138 	LogFile.Close() ;
       
   139 	LogSession.Close() ;
       
   140 	
       
   141 	if(iCount)
       
   142 	{
       
   143 		iRetStatus = KErrNone ;
       
   144 		CActiveScheduler *Current = CActiveScheduler :: Current() ;
       
   145 		Current->Stop() ;
       
   146 		
       
   147 	}
       
   148 	
       
   149 	return KErrNone ;
       
   150 }
       
   151    
       
   152     	
       
   153 TInt GetLocFunctionL()
       
   154 {
       
   155  	__UHEAP_MARK;
       
   156 	LocUpdateCallBack MyUpdates ;
       
   157 	
       
   158 	
       
   159 	
       
   160     CActiveScheduler *Scheduler  = CActiveScheduler :: Current() ;
       
   161     
       
   162     if(!Scheduler)
       
   163     {
       
   164     	Scheduler = new CActiveScheduler ;
       
   165     }
       
   166     
       
   167    
       
   168     CActiveScheduler :: Install(Scheduler) ;
       
   169      
       
   170     
       
   171 	
       
   172   
       
   173     CLiwServiceHandler* ServiceHandler = CLiwServiceHandler::NewL();
       
   174   
       
   175     // Input and output parameter list
       
   176     CLiwGenericParamList* inputlist = &(ServiceHandler->InParamListL());
       
   177     CLiwGenericParamList* outputlist = &(ServiceHandler->OutParamListL());
       
   178     
       
   179     
       
   180 
       
   181 
       
   182 	CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KDataSource , KService);
       
   183 	
       
   184 
       
   185 	crit->SetServiceClass(TUid::Uid(KLiwClassBase));
       
   186 
       
   187 	RCriteriaArray a;
       
   188 	a.AppendL(crit);
       
   189 	
       
   190 	TRAPD (err ,ServiceHandler->AttachL(a) );
       
   191    
       
   192 	
       
   193 	
       
   194 	
       
   195 	
       
   196 	
       
   197 	
       
   198 	ServiceHandler->ExecuteServiceCmdL(*crit, *inputlist, *outputlist);
       
   199 
       
   200 	 
       
   201  	 
       
   202 
       
   203 	TInt pos = 0;
       
   204 	
       
   205 	const TLiwGenericParam *errorprm = outputlist->FindFirst(pos , KErrorCode) ;
       
   206 	
       
   207 	if(!errorprm)
       
   208 	{
       
   209 		return KErrGeneral ;
       
   210 	}
       
   211 	
       
   212 
       
   213 	_LIT8(KDataSource, "ILocation");
       
   214 	 
       
   215 	 pos = 0 ;
       
   216 
       
   217  	const TLiwGenericParam *genericparm = outputlist->FindFirst(pos,KLocationInterface);
       
   218 	
       
   219 	if(!genericparm)
       
   220 	{
       
   221 		return KErrGeneral ;
       
   222 	}
       
   223 	
       
   224    MLiwInterface* locinterface = (genericparm->Value()).AsInterface();
       
   225   
       
   226   
       
   227    
       
   228 
       
   229   // CLiwGenericParamList *OutParmList = CLiwGenericParamList :: NewL() ;
       
   230 
       
   231     
       
   232 
       
   233 	CLiwGenericParamList *InputList = CLiwGenericParamList :: NewL() ;
       
   234 	CLiwGenericParamList *OutParmList = CLiwGenericParamList :: NewL() ;
       
   235 	TBuf8<20>CmdBuf(KCmdTraceLocation) ;
       
   236 	
       
   237 
       
   238 	locinterface->ExecuteCmdL(CmdBuf , *InputList , *OutParmList ,KLiwOptASyncronous ,  &MyUpdates);
       
   239     
       
   240    CActiveScheduler :: Start() ;
       
   241     
       
   242    
       
   243     
       
   244     
       
   245     locinterface->Close();
       
   246     delete ServiceHandler ; 	
       
   247     delete InputList ;
       
   248     delete  OutParmList ;
       
   249     delete Scheduler ;
       
   250     __UHEAP_MARKEND;
       
   251     return 0 ; 
       
   252 }
       
   253 
       
   254 TInt GetLocUpdates(TAny */*Arg*/)
       
   255 {
       
   256 //;
       
   257 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   258 	TInt val = 0 ;
       
   259    
       
   260   //Install a new active scheduler to this thread 
       
   261   TRAPD(err , (val =GetLocFunctionL())) ;
       
   262    
       
   263     delete cleanup ;
       
   264     if(err)
       
   265         {
       
   266             return err ;
       
   267         }
       
   268     return val ;
       
   269 }
       
   270