serviceproviders/sapi_location/tsrc/dev/tlocationprovidertest/src/tservicefailedtest.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 #include <lbs.h>
       
    25 
       
    26 #include "tcomplugin.h"
       
    27 
       
    28 _LIT(LogFileName , "C:\\Notifications.txt") ;
       
    29 
       
    30 class CallBack : public MLiwNotifyCallback
       
    31 {
       
    32 	
       
    33 	public :
       
    34 	TInt iRetStatus ;
       
    35 		
       
    36 		TInt HandleNotifyL(
       
    37             TInt aCmdId,
       
    38             TInt aEventId,
       
    39             CLiwGenericParamList& aEventParamList,
       
    40             const CLiwGenericParamList& aInParamList) ;
       
    41 
       
    42 		CallBack() : iRetStatus(KErrGeneral)  //Default constructor 
       
    43 			{
       
    44 				;
       
    45 			}
       
    46 	
       
    47 };
       
    48 
       
    49 TInt CallBack :: HandleNotifyL(
       
    50             TInt /*aCmdId*/,
       
    51             TInt aEventId,
       
    52             CLiwGenericParamList& aEventParamList,
       
    53             const CLiwGenericParamList& aInParamList) 
       
    54 {
       
    55   
       
    56   	TInt Index = 0 ;
       
    57   	const TLiwGenericParam *GenericParam = aEventParamList.FindFirst(Index , KErrorCode );
       
    58   	
       
    59   	TInt error ;
       
    60   	
       
    61   	if(GenericParam)
       
    62 			{
       
    63 				TLiwVariant Variant ;
       
    64 	
       
    65 				Variant = GenericParam->Value() ;
       
    66 				error  = Variant.AsTInt32() ;
       
    67 				iRetStatus = error ;
       
    68 				CActiveScheduler *Current  = CActiveScheduler :: Current() ;
       
    69 				Current->Stop() ;
       
    70 
       
    71 			}
       
    72 	return error ;			
       
    73 }
       
    74 
       
    75 
       
    76 /** 
       
    77   *@ This call back interface is for testing  Service Not available  
       
    78  */
       
    79  //---------------------------------------------------------------------------------------------------------
       
    80 
       
    81 
       
    82 TInt ServiceFailedFunctionL()
       
    83 {
       
    84 	
       
    85 	CallBack MyUpdates ;
       
    86 	
       
    87 	_LIT8(KService, "Service.Location");
       
    88     _LIT8(KIDataSource,"ILocation");
       
    89 
       
    90 	
       
    91 	
       
    92     CActiveScheduler *Scheduler  = CActiveScheduler :: Current() ;
       
    93     
       
    94     if(!Scheduler)
       
    95     {
       
    96     	Scheduler = new CActiveScheduler ;
       
    97     }
       
    98     
       
    99    
       
   100     CActiveScheduler :: Install(Scheduler) ;
       
   101      
       
   102     
       
   103 	
       
   104     CLiwServiceHandler* ServiceHandler = CLiwServiceHandler::NewL();
       
   105   
       
   106     // Input and output parameter list
       
   107     CLiwGenericParamList* inputlist = &(ServiceHandler->InParamListL());
       
   108     CLiwGenericParamList* outputlist = &(ServiceHandler->OutParamListL());
       
   109     
       
   110     
       
   111 
       
   112 
       
   113 	CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KService, KIDataSource);
       
   114 	
       
   115 
       
   116 	crit->SetServiceClass(TUid::Uid(KLiwClassBase));
       
   117 
       
   118 	RCriteriaArray a;
       
   119 	a.AppendL(crit);
       
   120 	
       
   121 	ServiceHandler->AttachL(a) ;
       
   122    
       
   123 	
       
   124 	 
       
   125  	 
       
   126 
       
   127 	TInt pos = 0;
       
   128 	
       
   129 	const TLiwGenericParam *errorprm = outputlist->FindFirst(pos , KErrorCode) ;
       
   130 	
       
   131 	if(!errorprm)
       
   132 	{
       
   133 		return KErrGeneral ;
       
   134 	}
       
   135 	
       
   136 
       
   137 	_LIT8(KDataSource, "ILocation");
       
   138 
       
   139  	const TLiwGenericParam *genericparm = outputlist->FindFirst(pos,KDataSource );
       
   140 	
       
   141 	if(!genericparm)
       
   142 	{
       
   143 	
       
   144 		return KErrGeneral ;
       
   145 	}
       
   146 	
       
   147    MLiwInterface* locinterface = (genericparm->Value()).AsInterface();
       
   148   // CLiwGenericParamList *OutParmList = CLiwGenericParamList :: NewL() ;
       
   149 
       
   150     
       
   151 
       
   152 	CLiwGenericParamList *InputList = CLiwGenericParamList :: NewL() ;
       
   153 	CLiwGenericParamList *OutParmList = CLiwGenericParamList :: NewL() ;
       
   154 	TBuf8<20>CmdBuf(KCmdTraceLocation) ;
       
   155 
       
   156 
       
   157 	locinterface->ExecuteCmdL(CmdBuf , *InputList , *OutParmList ,0 ,  &MyUpdates);
       
   158 	const TInt KSecond = 1000000;
       
   159 	const TInt KUpdateTimeOut = 15*KSecond ; // Default timeout value for synchrnous call waits..
       
   160 	
       
   161 	User :: After((TTimeIntervalMicroSeconds32 )KUpdateTimeOut) ;
       
   162 
       
   163 
       
   164 	CActiveScheduler :: Start() ;
       
   165 	delete Scheduler ;
       
   166 	
       
   167 	locinterface->Close();
       
   168 	delete InputList ;
       
   169 	delete  OutParmList ;
       
   170 	return  MyUpdates.iRetStatus ;
       
   171     	
       
   172     	
       
   173 
       
   174 }
       
   175 
       
   176 TInt ServiceFailedTest(TAny */*Arg*/)
       
   177 {
       
   178 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   179 	TRAPD(err , ServiceFailedFunctionL()) ;
       
   180 	delete cleanup ;
       
   181 	return err ;
       
   182 	
       
   183 }