serviceproviders/sapi_sysinfo/tsrc/dev/providertests/tsysinfoprovidernegativetests/src/tvibranotifyreqcancel.cpp
changeset 5 989d2f495d90
child 23 50974a8b132e
equal deleted inserted replaced
1:a36b1e19a461 5: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 <Liwcommon.h>
       
    19 #include<LiwServiceHandler.h>
       
    20 
       
    21 #include "sysinfointerface.h"
       
    22 #include"entitykeys.h"
       
    23 #include "sysinfoaiwparams.hrh"
       
    24 #include"watchtimer.h"
       
    25 #include "serviceerrno.h"
       
    26 #include"tsysinfoprovidertests.h"
       
    27 
       
    28 using namespace LIW ;
       
    29 using namespace SysInfo;
       
    30 using namespace sysinfoaiwparams;	
       
    31 
       
    32 
       
    33 class CTestBTCancel : public CActive ,public MLiwNotifyCallback, public MTimeOutCallBack
       
    34 {
       
    35 public:
       
    36 	static CTestBTCancel* NewL(CStifLogger* aLog);
       
    37 	~CTestBTCancel();
       
    38 	void Start();
       
    39 	TInt Result();
       
    40 
       
    41 	TInt HandleNotifyL(TInt aCmdId,
       
    42 			            TInt aEventId,
       
    43 			            CLiwGenericParamList& aEventParamList,
       
    44 			            const CLiwGenericParamList& aInParamList);
       
    45     IMPORT_C static TInt32 GetTransactionID();
       
    46     
       
    47     void HandleTimeOut	();
       
    48     	
       
    49 private:
       
    50 	void ConstructL();
       
    51 
       
    52 	CTestBTCancel(CStifLogger* aLog);
       
    53 	
       
    54 	virtual void DoCancel();
       
    55 	
       
    56 	virtual void RunL();
       
    57 	
       
    58 	void TestFunc();
       
    59 	
       
    60 private:	
       
    61 	CActiveSchedulerWait* 	iWaitSchedular;
       
    62 	CLiwServiceHandler* iServiceHandler;
       
    63 	MLiwInterface* interface ;
       
    64 	TInt32 btstatus ;
       
    65 	TInt 					iResult;
       
    66 	CWatchTimer*			iTimer;
       
    67 	CStifLogger*			iLog;
       
    68 	
       
    69 };
       
    70 
       
    71 CTestBTCancel* CTestBTCancel::NewL(CStifLogger* aLog)
       
    72 	{
       
    73 	CTestBTCancel* self = new(ELeave) CTestBTCancel(aLog);
       
    74 	self->ConstructL();
       
    75 	return self;
       
    76 	}
       
    77 
       
    78 CTestBTCancel::~CTestBTCancel()
       
    79 	{
       
    80 	Cancel();
       
    81 	
       
    82 	interface->Close();
       
    83 	
       
    84 	delete iServiceHandler;
       
    85 	
       
    86 	if(iWaitSchedular->IsStarted())
       
    87 		iWaitSchedular->AsyncStop();
       
    88 	
       
    89 	if(iWaitSchedular)
       
    90 		delete iWaitSchedular;
       
    91 	
       
    92 	delete iTimer;
       
    93 
       
    94 	}
       
    95 
       
    96 void CTestBTCancel::ConstructL()
       
    97 	{
       
    98 	CActiveScheduler::Add(this);
       
    99 	iWaitSchedular = new(ELeave) CActiveSchedulerWait();
       
   100 	iTimer			= CWatchTimer::NewL(EPriorityNormal,this);
       
   101 
       
   102 	}
       
   103 
       
   104 CTestBTCancel::CTestBTCancel(CStifLogger* aLog) :
       
   105 CActive(EPriorityStandard),iResult(-1),iLog(aLog)
       
   106 	{
       
   107 	}
       
   108 
       
   109 void CTestBTCancel::DoCancel()
       
   110 	{
       
   111 	
       
   112 	//TRAPD(err1,iSysInfoService->GetInfoL(req1));
       
   113 		
       
   114 	}
       
   115 
       
   116 void CTestBTCancel::RunL()
       
   117 	{
       
   118 	TestFunc();
       
   119 	}
       
   120 
       
   121 void CTestBTCancel::Start()
       
   122 	{
       
   123 	
       
   124 	SetActive();
       
   125 	TRequestStatus* temp = &iStatus;
       
   126 	User::RequestComplete(temp, KErrNone);
       
   127 	iWaitSchedular->Start();	
       
   128 	}
       
   129 
       
   130 TInt CTestBTCancel::Result()
       
   131 	{
       
   132 	return iResult;
       
   133 	}
       
   134 
       
   135 void CTestBTCancel::TestFunc()
       
   136 	{
       
   137 
       
   138 	const TTimeIntervalMicroSeconds32 OneMinute(60000);
       
   139 
       
   140 	iServiceHandler = CLiwServiceHandler::NewL();
       
   141 	CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL());
       
   142 	CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL());
       
   143 
       
   144 	TInt 	err = KErrNone; 
       
   145 	
       
   146 	CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KIDataSource,KService);
       
   147 	crit->SetServiceClass(TUid::Uid(KLiwClassBase));
       
   148 
       
   149 	RCriteriaArray a;
       
   150 	a.AppendL(crit);    
       
   151 
       
   152 	iServiceHandler->AttachL(a);
       
   153 
       
   154 	iServiceHandler->ExecuteServiceCmdL(*crit, *inparam, *outparam); 
       
   155 
       
   156 	delete crit;
       
   157 	a.Reset();
       
   158 	
       
   159 	TInt pos = 0;
       
   160 
       
   161 	outparam->FindFirst( pos, KIDataSource );
       
   162 	if(pos != KErrNotFound)
       
   163 		{
       
   164 		//getting the interface handle
       
   165 		interface = (*outparam)[pos].Value().AsInterface();	
       
   166 		}
       
   167 
       
   168 	outparam->Reset();
       
   169 	inparam->Reset();
       
   170 	
       
   171 	if(interface)
       
   172 		{
       
   173 		TLiwGenericParam entity;
       
   174 		TLiwVariant  entityname;
       
   175 		TLiwGenericParam key;
       
   176 		TLiwVariant  keyname;
       
   177 		
       
   178 		entityname.Set(KConnectivity);
       
   179 		entity.SetNameAndValueL(KEntity,entityname);
       
   180 
       
   181 		keyname.Set(KBlueTooth);
       
   182 		key.SetNameAndValueL(KKey,keyname);
       
   183 
       
   184 		inparam->AppendL(entity);
       
   185 
       
   186 		inparam->AppendL(key);
       
   187 		
       
   188 		entity.Reset();
       
   189 		entityname.Reset();
       
   190 		key.Reset();
       
   191 		keyname.Reset();
       
   192 		iLog->Log(_L("before getnotification vibra Active:"));
       
   193 
       
   194 		//get  notification vibra Active
       
   195 		TRAPD(err1,	interface->ExecuteCmdL(KGetNotification,*inparam,*outparam,KLiwOptASyncronous,this));
       
   196 		iResult = err1;
       
   197 		iLog->Log(_L("after getnotification vibra Active:"));
       
   198 		TInt pos = 0, transactionid ;
       
   199 		const TLiwGenericParam* output2 = outparam->FindFirst( pos,KTransactionId );
       
   200 		iLog->Log(_L("after FindFirst vibra Active:"));
       
   201 
       
   202 		if(pos > 0)
       
   203 			transactionid = output2->Value().AsTInt32(); 
       
   204 		else;
       
   205 		
       
   206 		outparam->Reset();
       
   207 		inparam->Reset();
       
   208 		
       
   209 		iLog->Log(_L("before SetNameAndValueL vibra Active:"));
       
   210 
       
   211 		TLiwGenericParam transid;
       
   212 		transid.SetNameAndValueL(KTransactionId,transactionid);
       
   213 		inparam->AppendL(transid);
       
   214 		
       
   215 		transid.Reset();
       
   216 		iLog->Log(_L("before KCancel vibra Active:"));
       
   217 
       
   218 		TRAPD(errcancel,interface->ExecuteCmdL(KCancel,*inparam,*outparam,NULL,this));
       
   219 
       
   220 		iTimer->After(OneMinute);
       
   221 
       
   222 			if(errcancel == KErrNone)
       
   223 				{
       
   224 				pos = 0 ;
       
   225 				outparam->FindFirst( pos, KErrorCode );
       
   226 				if(pos != KErrNotFound)
       
   227 					{
       
   228 					iResult = (TInt)((*outparam)[pos].Value().AsTInt32());
       
   229 					}
       
   230 				if(iResult == SErrBadArgumentType)
       
   231 					{
       
   232 					iLog->Log(_L("after KCancel SErrBadArgumentType:"));
       
   233 					iResult =  0;	
       
   234 					}
       
   235 				else
       
   236 					{
       
   237 					iResult =  -1;	
       
   238 					}
       
   239 				}//err1
       
   240 		outparam->Reset();
       
   241 		inparam->Reset();
       
   242 		
       
   243 		}
       
   244 	else
       
   245 		{
       
   246 		iResult = err;
       
   247 		iWaitSchedular->AsyncStop();
       
   248 		}
       
   249 		
       
   250 	return ;
       
   251 	}
       
   252 
       
   253 TInt CTestBTCancel::HandleNotifyL(TInt /*aCmdId*/,
       
   254 		            TInt aEventId,
       
   255 		            CLiwGenericParamList& /*aEventParamList*/,
       
   256 		            const CLiwGenericParamList& /*aInParamList*/)
       
   257 	{
       
   258 	if(aEventId == KLiwEventCanceled)
       
   259 		{
       
   260 		iResult =KErrNone;
       
   261 		}
       
   262 	else
       
   263 		{
       
   264 		iResult =KErrGeneral;
       
   265 		}
       
   266 				
       
   267 	iWaitSchedular->AsyncStop();
       
   268 	return KErrNone;
       
   269 	}
       
   270 
       
   271 
       
   272 int BTAsyncReqCancel(CStifLogger* aLog)
       
   273 	{
       
   274 //	__UHEAP_MARK;
       
   275 
       
   276 	CTestBTCancel* test = CTestBTCancel::NewL(aLog);
       
   277 	
       
   278 	test->Start();
       
   279 	TInt retval =	test->Result();
       
   280 	aLog->Log(_L("after  test->Result:"));
       
   281 
       
   282 	delete test;
       
   283 //	__UHEAP_MARKEND;
       
   284 
       
   285 	return retval;
       
   286 	}
       
   287 
       
   288 void CTestBTCancel::HandleTimeOut()
       
   289 {
       
   290 	iWaitSchedular->AsyncStop();
       
   291 }