authenticationservices/authenticationserver/test/reftestplugin/tpinplugindlg/tpinplugindlg.cpp
changeset 102 deec7e509f66
parent 94 0e6c5a9328b5
child 108 ca9a0fc2f082
equal deleted inserted replaced
94:0e6c5a9328b5 102:deec7e509f66
     1 /*
       
     2 * Copyright (c) 2006-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 * Pinplugindlg.cpp
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "tpinplugindlg.h"
       
    21 #include <s32file.h>
       
    22 
       
    23 const TInt KErrInvalidPinLength			= -1002;
       
    24 _LIT(KPinPluginDailogPanicString,"CTestPinPluginDlgNotifier");
       
    25 
       
    26 // Lib main entry point.
       
    27 
       
    28 #ifdef _T_PINPLUGINDLG_TEXTSHELL
       
    29 EXPORT_C CArrayPtr<MNotifierBase2>* NotifierArray()
       
    30 #else
       
    31 CArrayPtr<MNotifierBase2>* NotifierArray()
       
    32 #endif
       
    33 	{
       
    34 	CArrayPtrFlat<MNotifierBase2>* subjects = NULL;
       
    35 	CTestPinPluginDlgNotifier* notifier;
       
    36 	TRAPD(err,
       
    37 		subjects = new (ELeave) CArrayPtrFlat<MNotifierBase2>(1);
       
    38 		CleanupStack::PushL(subjects);
       
    39 		notifier = CTestPinPluginDlgNotifier::NewL();
       
    40 		CleanupStack::PushL(notifier);
       
    41 		subjects->AppendL(notifier);
       
    42 		CleanupStack::Pop(2,subjects));	//notifier, subjects
       
    43 	if (err != KErrNone)
       
    44 		{
       
    45 		subjects = NULL;
       
    46 		}
       
    47 	return subjects;
       
    48 	}
       
    49 
       
    50 // Ecom plugin implementation for UI notifier
       
    51 
       
    52 #ifndef _T_PINPLUGINDLG_TEXTSHELL
       
    53 
       
    54 const TImplementationProxy ImplementationTable[] =
       
    55 	{
       
    56 	IMPLEMENTATION_PROXY_ENTRY(KTPinPluginDlgNotiferUid, NotifierArray)
       
    57 	};
       
    58 
       
    59 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
    60 	{
       
    61 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
    62 	return (ImplementationTable);
       
    63 	}
       
    64 
       
    65 #endif
       
    66 
       
    67 // TInputDetails
       
    68 //
       
    69 
       
    70 TInputDetails::TInputDetails(TPinPluginDialogOperation aOp, TInt aIndex, TInt aNewPinLength, TPinPluginDialogResult aCommandOutput) :
       
    71 	iOp(aOp), iPinValue(0), iIndex(aIndex), iNewPinLength(aNewPinLength), iCommandOutput(aCommandOutput)
       
    72 	{
       
    73 	}
       
    74 
       
    75 TInputDetails::TInputDetails(TPinPluginDialogOperation aOp, TPinValue& aPinValue, TPinPluginDialogResult aCommandOutput) :
       
    76 	iOp(aOp), iPinValue(aPinValue), iCommandOutput(aCommandOutput)
       
    77 	{
       
    78 	}
       
    79 
       
    80 
       
    81 // CTestPinPluginDlgNotifier
       
    82 //
       
    83 
       
    84 _LIT(KInputFile, "C:\\t_pinplugindlg_in.dat");
       
    85 _LIT(KOutputFile, "C:\\t_pinplugindlg_out.dat");
       
    86 
       
    87 CTestPinPluginDlgNotifier* CTestPinPluginDlgNotifier::NewL()
       
    88 	{
       
    89 	CTestPinPluginDlgNotifier* self=new (ELeave) CTestPinPluginDlgNotifier();
       
    90 	CleanupStack::PushL(self);
       
    91 	self->ConstructL();
       
    92 	CleanupStack::Pop(self);
       
    93 	return self;
       
    94 	}
       
    95 
       
    96 CTestPinPluginDlgNotifier::CTestPinPluginDlgNotifier()
       
    97 	{
       
    98 	iInfo.iUid = KUidPinPluginDialogNotifier;
       
    99 	iInfo.iChannel = TUid::Uid(0x00001200); // test uid
       
   100 	iInfo.iPriority = ENotifierPriorityHigh;
       
   101 	}
       
   102 
       
   103 void CTestPinPluginDlgNotifier::ConstructL()
       
   104 	{
       
   105 	User::LeaveIfError(iFs.Connect());
       
   106 	}
       
   107 
       
   108 TInt CTestPinPluginDlgNotifier::ReadDialogCountL()
       
   109 	{
       
   110 	RFileReadStream stream;
       
   111 	TInt err = stream.Open(iFs, KOutputFile, EFileRead | EFileShareExclusive);
       
   112 	// If the file doesn't exist yet just return zero
       
   113 	if (err == KErrNotFound)
       
   114 		{
       
   115 		return 0;
       
   116 		}
       
   117 	User::LeaveIfError(err);
       
   118 	stream.PushL();
       
   119 	TInt dialogCount = stream.ReadInt32L();
       
   120 	CleanupStack::PopAndDestroy(&stream); 
       
   121 	return dialogCount;
       
   122 	}
       
   123 
       
   124 TPinValue CTestPinPluginDlgNotifier::ReadPinValueL()
       
   125 	{
       
   126 	TPinValue pinValue;
       
   127 	RFileReadStream stream;
       
   128 	TInt err = stream.Open(iFs, KOutputFile, EFileRead | EFileShareExclusive);
       
   129 	// If the file doesn't exist yet just return zero
       
   130 	if (err == KErrNotFound)
       
   131 		{
       
   132 		pinValue.Copy(_L("0"));
       
   133 		return pinValue;
       
   134 		}
       
   135 	User::LeaveIfError(err);
       
   136 	stream.PushL();
       
   137 	stream.ReadInt32L();
       
   138 	TInt pinValueSize = stream.ReadInt32L();
       
   139 	HBufC8* pinValueBuf = HBufC8::NewMaxLC(pinValueSize);
       
   140 	TPtr8 pinValuePtr(pinValueBuf->Des());
       
   141 	stream.ReadL(pinValuePtr, pinValueSize);
       
   142 	pinValue.Copy(pinValuePtr);
       
   143 	CleanupStack::PopAndDestroy(2, &stream);	
       
   144 	return pinValue;
       
   145 	}
       
   146 	
       
   147 void CTestPinPluginDlgNotifier::WriteDialogCountL(TInt aCount)
       
   148 	{
       
   149 	RFileWriteStream stream;
       
   150 	TInt err = stream.Replace(iFs, KOutputFile, EFileWrite | EFileShareExclusive);
       
   151 	if (err == KErrNotFound)
       
   152 		{
       
   153 		err = stream.Create(iFs, KOutputFile, EFileWrite | EFileShareExclusive);
       
   154 		}
       
   155 	User::LeaveIfError(err);
       
   156 	stream.PushL();
       
   157 	stream.WriteInt32L(aCount);
       
   158 	stream.CommitL();
       
   159 	CleanupStack::PopAndDestroy(&stream); 
       
   160 	}
       
   161 
       
   162 void CTestPinPluginDlgNotifier::WritePinL(const TPinValue& aPinValue)
       
   163 	{
       
   164 	TInt dialogCount = ReadDialogCountL();
       
   165 
       
   166 	RFileWriteStream stream;
       
   167 	TInt err = stream.Replace(iFs, KOutputFile, EFileWrite | EFileShareExclusive);
       
   168 	if (err == KErrNotFound)
       
   169 		{
       
   170 		err = stream.Create(iFs, KOutputFile, EFileWrite | EFileShareExclusive);
       
   171 		}
       
   172 	User::LeaveIfError(err);
       
   173 	stream.PushL();
       
   174 	stream.WriteInt32L(dialogCount);
       
   175 	stream.WriteInt32L(aPinValue.Length());
       
   176 	stream.WriteL(aPinValue);
       
   177 	stream.CommitL();
       
   178 	CleanupStack::PopAndDestroy(&stream); 
       
   179 	}
       
   180 	
       
   181 void CTestPinPluginDlgNotifier::WriteMsgL(const TPinPluginInfoMessage& aMessage)
       
   182 	{
       
   183 	TInt dialogCount = ReadDialogCountL();
       
   184 	TPinValue pinValue = ReadPinValueL();
       
   185 	
       
   186 	RFileWriteStream stream;
       
   187 	TInt err = stream.Replace(iFs, KOutputFile, EFileWrite | EFileShareExclusive);
       
   188 	if (err == KErrNotFound)
       
   189 		{
       
   190 		err = stream.Create(iFs, KOutputFile, EFileWrite | EFileShareExclusive);
       
   191 		}
       
   192 	User::LeaveIfError(err);
       
   193 	stream.PushL();
       
   194 	stream.WriteInt32L(dialogCount);
       
   195 	stream.WriteInt32L(pinValue.Length());
       
   196 	stream.WriteL(pinValue);
       
   197 	stream.WriteInt32L(aMessage);
       
   198 	stream.CommitL();
       
   199 	CleanupStack::PopAndDestroy(&stream); 
       
   200 	}
       
   201 	
       
   202 TInputDetails* CTestPinPluginDlgNotifier::ReadInputDetailsL(TUint aOperation)
       
   203 	{
       
   204 	RFileReadStream stream;
       
   205 	User::LeaveIfError(stream.Open(iFs, KInputFile, EFileRead | EFileShareExclusive));
       
   206 	stream.PushL();
       
   207 
       
   208 	TPinValue pinvalue;
       
   209 	TInt index, newLength,dialogNumber;
       
   210 	TInt pinValueSize;
       
   211 
       
   212 	TPinPluginDialogOperation op = static_cast<TPinPluginDialogOperation>(stream.ReadInt32L());
       
   213 	
       
   214 	pinValueSize = stream.ReadInt32L();
       
   215 	HBufC8* pinValueBuf = HBufC8::NewMaxLC(pinValueSize);
       
   216 	TPtr8 pinValuePtr(pinValueBuf->Des());
       
   217 	stream.ReadL(pinValuePtr, pinValueSize);
       
   218 	pinvalue.Copy(pinValuePtr);
       
   219 	
       
   220 	index = stream.ReadInt32L();
       
   221 	if (index < 0 && index > 3)
       
   222 		{
       
   223 		index = 0;
       
   224 		}
       
   225 	newLength = stream.ReadInt32L();
       
   226 	
       
   227 	TPinPluginDialogResult outputCommand = static_cast<TPinPluginDialogResult>(stream.ReadInt32L());
       
   228 	TPinPluginDialogOperation op1 = static_cast<TPinPluginDialogOperation>(stream.ReadInt32L());
       
   229 	TPinPluginDialogResult finalOutputCommand = static_cast<TPinPluginDialogResult>(stream.ReadInt32L());
       
   230 	dialogNumber = stream.ReadInt32L();
       
   231 	if (op != aOperation)
       
   232 		{
       
   233 		op = op1;
       
   234 		}
       
   235 	else
       
   236 		{
       
   237 		// Update dialog count here so test code can see how many dialogs were
       
   238 		// requested if there were more than expected
       
   239 		TInt dialogCount = ReadDialogCountL() + 1;
       
   240 		WriteDialogCountL(dialogCount);
       
   241 		if (dialogNumber == dialogCount)
       
   242 			{
       
   243 			outputCommand = finalOutputCommand;
       
   244 			}
       
   245 		}
       
   246 	
       
   247 	TInputDetails* inputDetail = NULL;
       
   248 	if (op == EPinPluginTraining)
       
   249 		{
       
   250 		inputDetail = new (ELeave) TInputDetails(op, index, newLength, outputCommand);
       
   251 		}
       
   252 	else if (op == EPinPluginIdentify) 
       
   253 		{
       
   254 		inputDetail = new (ELeave) TInputDetails(op, pinvalue, outputCommand);
       
   255 		}
       
   256 	CleanupStack::PopAndDestroy(1, pinValueBuf);	
       
   257 	CleanupStack::PopAndDestroy(&stream); 
       
   258 
       
   259 	return inputDetail;
       
   260 	}
       
   261 
       
   262 
       
   263 void CTestPinPluginDlgNotifier::DoSelectPinL(const TInputDetails& aDetail, const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   264 	{
       
   265 	const TPinTrainingInput& input = reinterpret_cast<const TPinTrainingInput&>(*aBuffer.Ptr());
       
   266 
       
   267 	TPinDialogOutput output;
       
   268 	output.iIndex = aDetail.Index();
       
   269 	TInt pinLength = aDetail.NewPinLength();
       
   270 	if (pinLength == 0)
       
   271 		{
       
   272 		output.iNewPinLength = input.iCurrentPinLength;
       
   273 		}
       
   274 	else
       
   275 		{
       
   276 		output.iNewPinLength = pinLength;
       
   277 		}
       
   278 	output.iResult = aDetail.CommandOutput();
       
   279 	
       
   280 	TPinValue pinValue;
       
   281 	switch(output.iIndex)
       
   282 		{
       
   283 		case 0:
       
   284 			pinValue = input.iPinValue1;
       
   285 			break; 
       
   286 		case 1:
       
   287 			pinValue = input.iPinValue2;
       
   288 			break; 
       
   289 		case 2:
       
   290 			pinValue = input.iPinValue3;
       
   291 			break; 
       
   292 		case 3:
       
   293 			pinValue = input.iPinValue4;
       
   294 			break; 
       
   295 		}
       
   296 	WritePinL(pinValue);
       
   297 	TPinDialogOutputBuf outputBuf(output);
       
   298 	aMessage.WriteL(aReplySlot, outputBuf);
       
   299 	}
       
   300 
       
   301 void CTestPinPluginDlgNotifier::DoIdentifyPinL(const TInputDetails& aDetail, const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   302 	{
       
   303 	const TPinIdentifyInput& input = reinterpret_cast<const TPinIdentifyInput&>(*aBuffer.Ptr());
       
   304 
       
   305 	TPinDialogOutput output;
       
   306 	const TPinValue& pinInput = reinterpret_cast<const TPinValue&>(aDetail.PinValue());
       
   307 	TInt pinLength = pinInput.Length();
       
   308 	if (pinLength >= input.iMinLength && pinLength <= input.iMaxLength)
       
   309 		{
       
   310 		output.iPinValue = pinInput;
       
   311 		}
       
   312 	else
       
   313 		{
       
   314 		User::Leave(KErrInvalidPinLength);	
       
   315 		}
       
   316 	
       
   317 	WritePinL(pinInput);
       
   318 	output.iResult = aDetail.CommandOutput();
       
   319 	TPinDialogOutputBuf outputBuf(output);
       
   320 	aMessage.WriteL(aReplySlot, outputBuf);
       
   321 	}
       
   322 
       
   323 void CTestPinPluginDlgNotifier::DoInfoPinL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   324 	{
       
   325 	const TPinInfoInput& input = reinterpret_cast<const TPinInfoInput&>(*aBuffer.Ptr());
       
   326 	WriteMsgL(input.iMessage);
       
   327 	
       
   328 	TPinDialogOutput output;
       
   329 	TPinDialogOutputBuf outputBuf(output);
       
   330 	aMessage.WriteL(aReplySlot, outputBuf);
       
   331 	}
       
   332 
       
   333 void CTestPinPluginDlgNotifier::Release()
       
   334 	{
       
   335 	delete this;
       
   336 	}
       
   337 
       
   338 CTestPinPluginDlgNotifier::TNotifierInfo CTestPinPluginDlgNotifier::RegisterL()
       
   339 	{
       
   340 	return iInfo;
       
   341 	}
       
   342 
       
   343 CTestPinPluginDlgNotifier::TNotifierInfo CTestPinPluginDlgNotifier::Info() const
       
   344 	{
       
   345 	return iInfo;
       
   346 	}
       
   347 
       
   348 void CTestPinPluginDlgNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   349 	{
       
   350 	TRAPD(err, DoStartL(aBuffer, aReplySlot, aMessage));
       
   351 	aMessage.Complete(err);
       
   352 	}
       
   353 	
       
   354 void CTestPinPluginDlgNotifier::DoStartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   355 	{
       
   356 	TUint operation = *reinterpret_cast<const TInt *>(aBuffer.Ptr()) & KPinPluginDialogOperationMask;
       
   357 	
       
   358 	TInputDetails* detail = NULL;
       
   359 
       
   360 	TRAPD(err, detail = ReadInputDetailsL(operation));
       
   361 	
       
   362 	User::LeaveIfError(err);
       
   363 
       
   364 	CleanupStack::PushL(detail);
       
   365 	
       
   366 	switch (operation)
       
   367 		{
       
   368 		case EPinPluginTraining:
       
   369 			DoSelectPinL(*detail, aBuffer, aReplySlot, aMessage);
       
   370 			break;
       
   371 
       
   372 		case EPinPluginIdentify:
       
   373 			DoIdentifyPinL(*detail, aBuffer, aReplySlot, aMessage);
       
   374 			break;
       
   375 		case EPinPluginInfo:
       
   376 			DoInfoPinL(aBuffer, aReplySlot, aMessage);
       
   377 			break;
       
   378 		default:
       
   379 			User::Panic(_L("CTestPinPluginDlgNotifier"), 0);
       
   380 		}
       
   381 	CleanupStack::PopAndDestroy(detail);
       
   382 	}
       
   383 
       
   384 TPtrC8 CTestPinPluginDlgNotifier::StartL( const TDesC8& /*aBuffer*/ )
       
   385 	{
       
   386 	User::Panic(_L("CTestPinPluginDlgNotifier"), 0);
       
   387 	return TPtrC8(KNullDesC8);
       
   388 	}
       
   389 
       
   390 void CTestPinPluginDlgNotifier::Cancel()
       
   391 	{
       
   392 	// Don't think there is much we can do here. If a client deletes the
       
   393 	// client-side pinplugin dialog instance, after calling a method that 
       
   394 	// displays a dialog, this will not get called until the user dismisses
       
   395 	// the dialog. We can't do anything then.
       
   396 	}
       
   397 
       
   398 TPtrC8 CTestPinPluginDlgNotifier::UpdateL( const TDesC8& /*aBuffer*/ )
       
   399 	{
       
   400 	User::Panic(KPinPluginDailogPanicString, 0);
       
   401 	return NULL;
       
   402 	}
       
   403 
       
   404