serialserver/c32serialserver/Test/TE_C32/dummy.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Dummy CSY for testing.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include "CS_PORT.H"
       
    23 #include <d32comm.h>
       
    24 #include "C32COMM.H"
       
    25 #include <f32file.h>
       
    26 #include "dummy.h"
       
    27 #include "TTHREAD.H"	// Required for the "Start Server in CSY Test"
       
    28 
       
    29 
       
    30 //**********************************************************************
       
    31 //			            DUMMY PORT FACTORY CODE
       
    32 //**********************************************************************
       
    33 
       
    34 static void CleanupCObject(TAny* aCObject)
       
    35 /**
       
    36  * Clean up a CObject
       
    37  */
       
    38     {
       
    39     ((CObject*)aCObject)->Close();
       
    40     }
       
    41 
       
    42 
       
    43 CPort* CDummyPortFactory::NewPortL(const TUint aUnit)
       
    44 /**
       
    45  * Create a new port for the supplied unit number
       
    46  */
       
    47 	{
       
    48 	return CDummyPort::NewL(aUnit);
       
    49 	}
       
    50 
       
    51 
       
    52 void CDummyPortFactory::Info(TSerialInfo& aSerialInfo)
       
    53 /**
       
    54  * fill in the supplied structure.
       
    55  */
       
    56 	{
       
    57 	const TUint KCommLowUnit=0;
       
    58 	const TUint KCommHighUnit=0;
       
    59 	aSerialInfo.iDescription=SERIAL_DESCRIPTION;
       
    60 #if defined(DUMMYCSY16)
       
    61 	aSerialInfo.iName=SERIAL_NAME_SMALL;
       
    62 #else
       
    63 	aSerialInfo.iName=SERIAL_NAME;
       
    64 #endif
       
    65 	aSerialInfo.iLowUnit=KCommLowUnit;
       
    66 	aSerialInfo.iHighUnit=KCommHighUnit;
       
    67 #ifdef DUMMYCSY10
       
    68 	LoadAnotherCSY();// Modified to handle stackable csy ie. loading csy by other csy
       
    69 #endif
       
    70 #ifdef DUMMYCSY17
       
    71 	LoadAnotherCSYNoClose();// Modified to handle stackable csy ie. loading csy by other csy. Session is not closed after unload csy
       
    72 #endif
       
    73 	}
       
    74 
       
    75 #ifdef DUMMYCSY10 // Load one csy by another csy. session is closed after unload csy
       
    76 void CDummyPortFactory::LoadAnotherCSY()
       
    77 	{
       
    78 	_LIT(KCSYName,"DUMMY");
       
    79 	RCommServ commSess;
       
    80 	TInt res = commSess.Connect();
       
    81 	if(res == KErrNone)
       
    82 		{
       
    83 		res = commSess.LoadCommModule(KCSYName);
       
    84 		if(res == KErrNone)
       
    85 			{
       
    86 			commSess.UnloadCommModule(KCSYName);
       
    87 			commSess.Close();
       
    88 			}
       
    89 		}
       
    90 
       
    91 	}
       
    92 #endif
       
    93 
       
    94 #ifdef DUMMYCSY17 // Load one csy by another csy. session is not closed after unload csy
       
    95 void CDummyPortFactory::LoadAnotherCSYNoClose()
       
    96 	{
       
    97 	_LIT(KCSYName,"DUMMY");
       
    98 	RCommServ commSess;
       
    99 	TInt res = commSess.Connect();
       
   100 	if(res == KErrNone)
       
   101 		{
       
   102 		res = commSess.LoadCommModule(KCSYName);
       
   103 		if(res == KErrNone)
       
   104 			{
       
   105 			commSess.UnloadCommModule(KCSYName);
       
   106 			//Session close statement should be commented to test the whether the function
       
   107 			//CCommSession::CC32SessionCloseTimer::RunL() is called
       
   108 			//server thread should panic since the session is not closed
       
   109 
       
   110 			//commSess.Close();
       
   111 			}
       
   112 		}
       
   113 
       
   114 	}
       
   115 #endif
       
   116 
       
   117 
       
   118 void CDummyPortFactory::ConstructL()
       
   119 /**
       
   120  * Construct and init members
       
   121  */
       
   122 	{
       
   123 	TName name(SERIAL_NAME);
       
   124 	SetNameL(&name);
       
   125 	}
       
   126 
       
   127 
       
   128 CDummyPortFactory* CDummyPortFactory::NewL()
       
   129 /**
       
   130  * 2 phase constructor
       
   131  */
       
   132 	{
       
   133 	CDummyPortFactory* c=new(ELeave) CDummyPortFactory;
       
   134 	CleanupStack::PushL(TCleanupItem(CleanupCObject, c));
       
   135 	c->ConstructL();
       
   136 	CleanupStack::Pop();
       
   137 	return c;
       
   138 	}
       
   139 
       
   140 
       
   141 CDummyPortFactory::CDummyPortFactory()
       
   142 /**
       
   143  * C'tor
       
   144  */
       
   145 	{
       
   146 	__DECLARE_NAME(_S("CDummyPortFactory"));
       
   147 	iVersion=TVersion(KMajorVersion,KMinorVersion,KBuild);
       
   148 	}
       
   149 
       
   150 /**
       
   151 Returns capabilities for requested port
       
   152 */
       
   153 TSecurityPolicy CDummyPortFactory::PortPlatSecCapability(TUint aPort) const
       
   154 	{
       
   155 	TSecurityPolicy csySecurityPolicy;
       
   156 
       
   157 	switch(aPort)
       
   158 		{
       
   159 		case PORT_0_NOCAPS:
       
   160 		case PORT_6_NOCAPS:
       
   161 		csySecurityPolicy = TSecurityPolicy(TSecurityPolicy::EAlwaysPass);
       
   162 		break;
       
   163 		case PORT_1_NETWORKSERVICES:
       
   164 		csySecurityPolicy = TSecurityPolicy(ECapabilityNetworkServices);
       
   165 		break;
       
   166 		case PORT_2_NOTSUPPORT:
       
   167 		default:
       
   168 		csySecurityPolicy = TSecurityPolicy(TSecurityPolicy::EAlwaysFail);
       
   169 		break;
       
   170 		case PORT_3_ALLCAPS:
       
   171 		csySecurityPolicy = TSecurityPolicy(ECapabilityTCB);
       
   172 		break;
       
   173 		}
       
   174 	return csySecurityPolicy;
       
   175 	}
       
   176 
       
   177 //**********************************************************************
       
   178 //			            DUMMY PORT CODE
       
   179 //**********************************************************************
       
   180 
       
   181 
       
   182 CDummyPort::CDummyPort()
       
   183 /**
       
   184  * C'tor
       
   185  */
       
   186 	:iPtrDataIn(NULL,0)
       
   187 	,iPtrDataOut(NULL,0)
       
   188 	,iPtrCompData(NULL,0)
       
   189 	{
       
   190 	__DECLARE_NAME(_S("CDummyPort"));
       
   191 	iDummyCompleteDelayFast = KDummyCompleteDelayFast;
       
   192     iDummyCompleteDelaySlow = KDummyCompleteDelaySlow;
       
   193 	iConfig.iRate=EBps9600;
       
   194 	iConfig.iDataBits=EData8;
       
   195 	iConfig.iStopBits=EStop1;
       
   196 	iConfig.iParity=EParityNone;
       
   197 	iConfig.iFifo=EFifoEnable;
       
   198 	iConfig.iHandshake=KConfigObeyCTS;
       
   199 	iConfig.iParityError=KConfigParityErrorIgnore;
       
   200 	iConfig.iSIREnable=ESIRDisable;
       
   201 	iConfig.iTerminatorCount=0;
       
   202 	iConfig.iXonChar=0x11; // XON
       
   203 	iConfig.iXoffChar=0x13; // XOFF
       
   204 	iConfig.iSpecialRate=0;
       
   205 	iConfig.iParityErrorChar=0;
       
   206 
       
   207 	iPeerConfig.iRate = EBpsSpecial;
       
   208 	iPeerConfig.iDataBits = EData8;
       
   209 	iPeerConfig.iStopBits = EStop1;
       
   210 	iPeerConfig.iParity = EParityNone;
       
   211 	iPeerConfig.iHandshake = KConfigObeyCTS;
       
   212 	}
       
   213 
       
   214 
       
   215 CDummyPort* CDummyPort::NewL(TUint aUnit)
       
   216 /**
       
   217  * Make a new CPort for the comm server
       
   218  */
       
   219 	{
       
   220 	CDummyPort *p=new(ELeave) CDummyPort;
       
   221 	CleanupStack::PushL(TCleanupItem(CleanupCObject, p));
       
   222 	p->ConstructL(aUnit);
       
   223 
       
   224     CleanupStack::Pop();
       
   225 	return p;
       
   226 	}
       
   227 
       
   228 
       
   229 void CDummyPort::ConstructL(TUint aUnit)
       
   230 /**
       
   231  * construct and init members
       
   232  */
       
   233 	{
       
   234     // To avoid thread lock we cannot actually connect to the socket server now if
       
   235     // the socket server thread is calling us
       
   236     // Similarly we cannot load IRDA synchronously because this will cause a
       
   237     // different kind of thread lock.
       
   238 
       
   239     // Should really have some sundry checks
       
   240     // i.e. is irda.prt in the ESOCK.INI file
       
   241     // is there enough heap
       
   242     // will irda be able to access COMM::0
       
   243     // Basically we need to be pretty sure IRDA will start but without
       
   244     // actually starting it
       
   245 
       
   246 	/*
       
   247 	RDevComm comm;
       
   248 	TInt ret=comm.Open(0);
       
   249 	if (ret==KErrInUse)
       
   250 		User::Leave(KErrAccessDenied);
       
   251 	else
       
   252 		User::LeaveIfError(ret);
       
   253 	comm.Close();
       
   254 	*/
       
   255 	const TUint16 KDummyPacketMaxSize = 2048;
       
   256 	iRole=ECommRoleDTE;
       
   257 	iNotifySignalMask = 0;
       
   258 	iFlowControl=EFlowControlOff;
       
   259 	iRole=ECommRoleDTE;
       
   260 	iSignals = 0;
       
   261 	iCapsPtr = 0;
       
   262 
       
   263 	iCompleteSigPtr		= new(ELeave) CDummyCompleter(*this);
       
   264 	iCompleteFlowPtr	= new(ELeave) CDummyCompleter(*this);
       
   265 	iCompleteConfPtr	= new(ELeave) CDummyCompleter(*this);
       
   266 	iCompleteCapsPtr	= new(ELeave) CDummyCompleter(*this);
       
   267 	iCompleteReadPtr	= new(ELeave) CDummyCompleter(*this);
       
   268 	iCompleteWritePtr	= new(ELeave) CDummyCompleter(*this);
       
   269 	iCompleteBreakPtr	= new(ELeave) CDummyCompleter(*this);
       
   270 	iCompleteSetBreakPtr = new(ELeave) CDummyCompleter(*this);
       
   271 	iCompleteDataAvailablePtr	= new(ELeave) CDummyCompleter(*this);
       
   272 	iCompleteOutputEmptyPtr	= new(ELeave) CDummyCompleter(*this);
       
   273 	iCompleteClosePtr	= new(ELeave) CDummyCompleter(*this);
       
   274 
       
   275 	iBreakDelay = 1;
       
   276 
       
   277 	iDataIn = (TUint8*)User::Alloc(KDummyPacketMaxSize);
       
   278         if(!iDataIn)
       
   279             User::Leave(KErrNoMemory);
       
   280 	iPtrDataIn.Set(iDataIn, 0, KDummyPacketMaxSize);
       
   281 
       
   282 	iDataOut = (TUint8*)User::Alloc(KDummyPacketMaxSize);
       
   283         if(!iDataOut)
       
   284             User::Leave(KErrNoMemory);
       
   285 	iPtrDataOut.Set(iDataOut, 0, KDummyPacketMaxSize);
       
   286 
       
   287 	iCompData = (TUint8*)User::Alloc(KDummyPacketMaxSize);
       
   288         if(!iCompData)
       
   289             User::Leave(KErrNoMemory);
       
   290 	iPtrCompData.Set(iCompData, 0, KDummyPacketMaxSize);
       
   291 
       
   292 	TBuf8<64> testbufRead	=_L8("0123456789abcdefghijklmnopqrstuvxyxABCDEFGHIJKLMNOPQRSTUVXYZ[]\r\n");
       
   293 	TBuf8<100> testbufWrite	=_L8("This string has to be exactly like this othervice write returns KErrCommsLineFail.");
       
   294 	//ptrDataIn.Copy(testbufRead); /* Client Read */
       
   295 	TInt i;
       
   296 	for (i=0;i<KDummyPacketMaxSize/64;i++)
       
   297 		iPtrDataIn.Append(testbufRead);
       
   298 
       
   299 	iPtrCompData.Copy(testbufWrite); /* Client Read */
       
   300 	TName name;
       
   301 	name.Format(_L("%d"), aUnit);
       
   302 	SetNameL(&name);
       
   303 
       
   304 #if defined (_DEBUG_CONSOLE_)
       
   305 	name.Format(_L("IrCOMM::%d"),aUnit);
       
   306 	DEBUG_TRACE(iConsole.SetTitle(name);)
       
   307     DEBUG_TRACE(iConsole.Control(_L("+S +M"));)
       
   308 #endif
       
   309 
       
   310 	}
       
   311 
       
   312 
       
   313 CDummyPort::~CDummyPort()
       
   314 /**
       
   315  * D'tor called from the active shutterdowner
       
   316  */
       
   317 	{
       
   318 	//User::After(iDummyCompleteDelaySlow);
       
   319 	delete iCompleteSigPtr;
       
   320 	delete iCompleteFlowPtr;
       
   321 	delete iCompleteConfPtr;
       
   322 	delete iCompleteCapsPtr;
       
   323 	delete iCompleteReadPtr;
       
   324 	delete iCompleteWritePtr;
       
   325 	delete iCompleteBreakPtr;
       
   326 	delete iCompleteSetBreakPtr;
       
   327 	delete iCompleteDataAvailablePtr;
       
   328 	delete iCompleteOutputEmptyPtr;
       
   329 	delete iCompleteClosePtr;
       
   330 
       
   331 	User::Free(iDataIn);
       
   332 	User::Free(iCompData);
       
   333 	User::Free(iDataOut);
       
   334 
       
   335 #if defined (_DEBUG_CONSOLE_)
       
   336 	DEBUG_TRACE(iConsole.Printf(_L("PortClosed\n\r"));)
       
   337     DEBUG_TRACE(iConsole.Close();)
       
   338 #endif
       
   339 	}
       
   340 
       
   341 
       
   342 void CDummyPort::NotifySignalChange(TUint aSignalMask)
       
   343 /**
       
   344  * Stores the pointer which is also used as a flag to indicate
       
   345  * that we must notify C32 of signal changes
       
   346  */
       
   347 	{
       
   348 	iNotifySignalMask = aSignalMask * KSignalChanged;
       
   349 	if (iRole==ECommRoleDTE)
       
   350 		{
       
   351 		iSignals = (KSignalDTEInputs|KCTSChanged);
       
   352 		}
       
   353 	else
       
   354 		{
       
   355 		iSignals = (KSignalDCEInputs|KRTSChanged);
       
   356 		}
       
   357 
       
   358 	if (iNotifySignalMask&iSignals)
       
   359 		{
       
   360 		iCompleteSigPtr->Complete(ECommNotifySignals,iDummyCompleteDelayFast,KErrNone,iSignals);
       
   361 		}
       
   362 	}
       
   363 
       
   364 
       
   365 void CDummyPort::NotifySignalChangeCancel()
       
   366 /**
       
   367  * Clears the pointer which is also used as a flag to indicate
       
   368  * that we must not notify C32 of signal changes
       
   369  */
       
   370 	{
       
   371 	iCompleteSigPtr->CancelComplete();
       
   372 	}
       
   373 
       
   374 
       
   375 void CDummyPort::NotifyConfigChange()
       
   376 /**
       
   377  * Stores the pointer which is also used as a flag to indicate
       
   378  * that we must notify C32 of configuration changes
       
   379  */
       
   380 	{
       
   381 	iPeerConfig.iChangedMembers=KHandshakeChanged;
       
   382 	iPeerConfig.iHandshake = KConfigObeyCTS;
       
   383 	iPeerConfig.iRate =EBps9600;
       
   384 	iPeerConfig.iDataBits =EData8;
       
   385 	iPeerConfig.iParity =EParityNone;
       
   386 	iPeerConfig.iStopBits =EStop1;
       
   387 	iPeerConfig.iHandshake =(KConfigObeyCTS|KConfigObeyRTS);
       
   388 
       
   389 	TPckg<TCommNotificationV01> cfg(iPeerConfig);
       
   390 	iCompleteConfPtr->Complete(ECommNotifyConfigChange,iDummyCompleteDelayFast,KErrNone,cfg);
       
   391 
       
   392 	}
       
   393 
       
   394 
       
   395 void CDummyPort::NotifyConfigChangeCancel()
       
   396 /**
       
   397  * Clears the pointer which is also used as a flag to indicate
       
   398  * that we must not notify C32 of signal changes
       
   399  */
       
   400 	{
       
   401 	iCompleteConfPtr->CancelComplete();
       
   402 	}
       
   403 
       
   404 
       
   405 void CDummyPort::NotifyFlowControlChange()
       
   406 /**
       
   407  * Stores the pointer which is also used as a flag to indicate
       
   408  * that we must notify C32 of flow control changes
       
   409  */
       
   410 	{
       
   411 	iFlowControl=EFlowControlOn;
       
   412 	iCompleteFlowPtr->Complete(ECommNotifyFlowControl,iDummyCompleteDelayFast,KErrNone,iFlowControl);
       
   413 	}
       
   414 
       
   415 
       
   416 void CDummyPort::NotifyFlowControlChangeCancel()
       
   417 /**
       
   418  * Clears the pointer which is also used as a flag to indicate
       
   419  * that we must not notify C32 of flow control changes
       
   420  */
       
   421 	{
       
   422 	iCompleteFlowPtr->CancelComplete();
       
   423 	}
       
   424 
       
   425 
       
   426 void CDummyPort::NotifyBreak()
       
   427 /**
       
   428  * Set the flag on that we must notify C32 of break signal changes
       
   429  */
       
   430 	{
       
   431 	iCompleteBreakPtr->Complete(ECommNotifyBreak,iDummyCompleteDelayFast,KErrNone);
       
   432 	}
       
   433 
       
   434 
       
   435 void CDummyPort::NotifyBreakCancel()
       
   436 /**
       
   437  * Set the flag on that we must not notify C32 of break signal changes
       
   438  */
       
   439 	{
       
   440 	iCompleteBreakPtr->CancelComplete();
       
   441 	}
       
   442 
       
   443 
       
   444 TInt CDummyPort::GetFlowControlStatus(TFlowControl& aFlowControl)
       
   445 /**
       
   446  * Returns the current flow control state
       
   447  */
       
   448 	{
       
   449 	aFlowControl=EFlowControlOn;
       
   450 	return KErrNone;
       
   451 	}
       
   452 
       
   453 
       
   454 TInt CDummyPort::GetRole(TCommRole& aRole)
       
   455 /**
       
   456  * Returns the current role
       
   457  */
       
   458 	{
       
   459 	aRole = iRole;
       
   460 	return KErrNone;
       
   461 	}
       
   462 
       
   463 
       
   464 TInt CDummyPort::SetRole(TCommRole aRole)
       
   465 /**
       
   466  * Sets the role as DCE or DTE, and also the handshake according the
       
   467  * role set
       
   468  */
       
   469 	{
       
   470 
       
   471 	switch(aRole)
       
   472 		{
       
   473 		case ECommRoleDCE:
       
   474 			iConfig.iHandshake &=~KConfigObeyCTS;
       
   475 			iConfig.iHandshake |=KConfigObeyRTS;
       
   476 			iRole = aRole;
       
   477 			break;
       
   478 		case ECommRoleDTE:
       
   479 			iConfig.iHandshake &=~KConfigObeyRTS;
       
   480 			iConfig.iHandshake |=KConfigObeyCTS;
       
   481 			iRole = aRole;
       
   482 			break;
       
   483 
       
   484 		default:
       
   485 			break;
       
   486 		}
       
   487 	return KErrNone;
       
   488 	}
       
   489 
       
   490 
       
   491 void CPort::FreeMemory()
       
   492 /**
       
   493  * We do nothing
       
   494  */
       
   495 	{
       
   496 	// we do nothing
       
   497 	}
       
   498 
       
   499 
       
   500 void CDummyPort::StartRead(const TAny *aClientBuffer,TInt aLength)
       
   501 /**
       
   502  * Queue a read.  IPC is handled inside of C32 now.
       
   503  */
       
   504 	{
       
   505 
       
   506 	//_LIT8(KTestLog,"KCSYLoggingName start reading....");
       
   507 	//__FLOG_STATIC0(KC32LoggingName, KCSYLoggingName, KTestLog);
       
   508 
       
   509 	#ifdef DUMMYCSY12
       
   510 
       
   511 		User::After(KDummy12ReadWait); // Added to block other csys
       
   512 
       
   513 	#endif
       
   514 
       
   515 	if(aLength==0)
       
   516 		{
       
   517         iCompleteReadPtr->Complete(ECommRead,iDummyCompleteDelaySlow,KErrNone);
       
   518 		return;
       
   519 		}
       
   520     else
       
   521 		iClientPtr=(TAny*)aClientBuffer;
       
   522 
       
   523     if(aLength<0)
       
   524         {
       
   525         aLength = -aLength;
       
   526         }
       
   527 
       
   528     iClientLength=aLength;
       
   529 	iPtrDataIn.SetLength(aLength);
       
   530 	this->IPCWrite(aClientBuffer,iPtrDataIn,0);
       
   531 	iCompleteReadPtr->Complete(ECommRead,iDummyCompleteDelayFast,KErrNone);
       
   532 	//_LIT8(KTestLog1,"KCSYLoggingName end reading....");
       
   533 	//__FLOG_STATIC0(KC32LoggingName, KCSYLoggingName, KTestLog1);
       
   534 
       
   535     }
       
   536 
       
   537 
       
   538 void CDummyPort::ReadCancel()
       
   539 /**
       
   540  * cancel a pending read
       
   541  */
       
   542 	{
       
   543 	iCompleteReadPtr->CancelComplete();
       
   544     }
       
   545 
       
   546 
       
   547 TInt CDummyPort::QueryReceiveBuffer(TInt& aLength) const
       
   548 /**
       
   549  * Get the size of the receive buffer from the real serial port
       
   550  */
       
   551 	{
       
   552     aLength=iLength;
       
   553 	return KErrNone;
       
   554 	}
       
   555 
       
   556 
       
   557 void CDummyPort::ResetBuffers(TUint /*aFlags*/)
       
   558 /**
       
   559  * Flush the client buffers
       
   560  */
       
   561 	{
       
   562 	iLength=0;
       
   563 	}
       
   564 
       
   565 
       
   566 void CDummyPort::StartWrite(const TAny* aClientBuffer, TInt aLength)
       
   567 /**
       
   568  * Queue a write.
       
   569  */
       
   570 	{
       
   571 //	LOG(Log::Printf(_L("	**CDummyPort::StartWrite** :\r\n")));
       
   572 
       
   573 	TInt offset = 0;
       
   574     TInt result=this->IPCRead(aClientBuffer, iPtrDataOut,offset);
       
   575 	iPtrDataOut.SetLength(aLength);
       
   576     if(result==KErrNone)
       
   577         {
       
   578 		result = iPtrCompData.Match(iPtrDataOut);
       
   579 		if (result==0)
       
   580 			iCompleteWritePtr->Complete(ECommWrite,iDummyCompleteDelayFast,KErrNone);
       
   581 		else
       
   582 			iCompleteWritePtr->Complete(ECommWrite,iDummyCompleteDelayFast,KErrCommsLineFail);
       
   583 		}
       
   584     else
       
   585 		iCompleteWritePtr->CancelComplete();
       
   586 
       
   587 	}
       
   588 
       
   589 
       
   590 void CDummyPort::WriteCancel()
       
   591 /**
       
   592  * cancel a pending write
       
   593  */
       
   594 	{
       
   595     iCompleteWritePtr->CancelComplete();
       
   596 	}
       
   597 
       
   598 
       
   599 void CDummyPort::Break(TInt aTime)
       
   600 /**
       
   601  * Queue a break
       
   602  */
       
   603 	{
       
   604 	if (iBreakDelay!=aTime)
       
   605 		User::Panic(_L("Dummy"),E_ParametersCorrupted);
       
   606 	else
       
   607 		iCompleteSetBreakPtr->Complete(ECommBreak,aTime,KErrNone);
       
   608 	iBreakDelay*=100;
       
   609 	}
       
   610 
       
   611 
       
   612 void CDummyPort::BreakCancel()
       
   613 /**
       
   614  * Cancel a pending break
       
   615  */
       
   616 	{
       
   617     iCompleteSetBreakPtr->CancelComplete();
       
   618 	}
       
   619 
       
   620 
       
   621 TInt CDummyPort::SetConfig(const TDesC8& aPackage)
       
   622 /**
       
   623  * Set up the Comm LDD/PDD
       
   624  */
       
   625 	{
       
   626     // line characteristics should be set and the line states checked accordingly
       
   627     TCommConfigV01 c;
       
   628 
       
   629     Mem::FillZ(&c,sizeof(c));
       
   630 	TInt len=Min(aPackage.Length(),sizeof(c));
       
   631 	Mem::Copy(&c, aPackage.Ptr(),len);
       
   632 
       
   633 	if ((c.iStopBits!=EStop2))
       
   634 		User::Panic(_L("Dummy"),E_ParametersCorrupted); // Panic if parameter fails
       
   635 
       
   636 	if(c.iTerminatorCount>KConfigMaxTerminators)
       
   637 		{
       
   638 		return KErrNotSupported;
       
   639 		}
       
   640 	if (c.iSIREnable==ESIREnable)
       
   641 		{
       
   642 		return KErrNotSupported;
       
   643 		}
       
   644 
       
   645 	iConfig=c;
       
   646 
       
   647 //
       
   648 // Piggy back the "Start Server from CSY" test onto this request
       
   649 //
       
   650 
       
   651 	_LIT(KLibraryName,"TThread");
       
   652 	_LIT(KThreadName,"newserver");
       
   653 	const TInt kDefaultStackSize=0x2000;
       
   654 	const TInt kHeapSize=0x1000;
       
   655 	const TInt kMaxHeapSize=0x40000;
       
   656 
       
   657 		TInt res=RCommServ::CreateThreadInCommProc(KLibraryName,KThreadName,ServerThread,
       
   658 				kDefaultStackSize,kHeapSize,kMaxHeapSize);
       
   659 		 return res;
       
   660 
       
   661 	}
       
   662 
       
   663 
       
   664 TInt CDummyPort::GetConfig(TDes8& aPackage) const
       
   665 /**
       
   666  * Pass a config request
       
   667  */
       
   668 	{
       
   669     // simple - copy back iConfig
       
   670     TPckg<TCommConfigV01> cfg(iConfig);
       
   671     aPackage.Copy(cfg);
       
   672 	return KErrNone;
       
   673 	}
       
   674 
       
   675 
       
   676 TInt CDummyPort::GetCaps(TDes8& aPackage)
       
   677 /**
       
   678  * Read capabilities from the driver
       
   679  */
       
   680 	{
       
   681 	TCommCapsV01 *c;
       
   682 	TCommCapsV02 *c2=0;
       
   683 
       
   684 	c = (TCommCapsV01*)aPackage.Ptr();
       
   685 
       
   686 	if (aPackage.Size()==sizeof(TCommCapsV02))
       
   687 		{
       
   688 		c2 = (TCommCapsV02*)aPackage.Ptr();
       
   689 	    aPackage.SetLength(sizeof(TCommCapsV02));
       
   690 		}
       
   691 	else
       
   692 		{
       
   693 		aPackage.SetLength(sizeof(TCommCapsV01));
       
   694 		}
       
   695 
       
   696 	c->iRate=
       
   697     KCapsBps50 | KCapsBps75 | KCapsBps110 | KCapsBps134 | KCapsBps150 | KCapsBps300
       
   698     | KCapsBps600 | KCapsBps1200 | KCapsBps1800 | KCapsBps2000 | KCapsBps2400 | KCapsBps3600
       
   699     | KCapsBps4800 | KCapsBps7200 | KCapsBps9600 | KCapsBps19200 | KCapsBps38400
       
   700     | KCapsBps57600 | KCapsBps115200 ;
       
   701 
       
   702 	c->iDataBits=0xf; // All data sizes
       
   703 	c->iStopBits=0x3; // 1 and 2 stop bits
       
   704 	c->iParity=0x7; // None, Even and Odd
       
   705 	c->iHandshake=0x1ff; // All handshakes
       
   706 	c->iSignals=0x3f; // All signals
       
   707 	c->iFifo=KCapsHasFifo;
       
   708 	c->iSIR=0;
       
   709 
       
   710 	// Version 02 extended capabilities
       
   711 	if (c2!=0)
       
   712 		{
       
   713 		c2->iNotificationCaps=
       
   714 			(KNotifySignalsChangeSupported		| KNotifyRateChangeSupported
       
   715 			| KNotifyDataFormatChangeSupported	| KNotifyHandshakeChangeSupported
       
   716 			| KNotifyBreakSupported				| KNotifyFlowControlChangeSupported);
       
   717 		c2->iRoleCaps=KCapsRoleSwitchSupported;
       
   718 		c2->iFlowControlCaps=KCapsFlowControlStatusSupported;
       
   719 		}
       
   720 
       
   721 	return KErrNone;
       
   722 	}
       
   723 
       
   724 
       
   725 TInt CDummyPort::SetServerConfig(const TDesC8& aDes)
       
   726 /**
       
   727  *	set server configurations
       
   728  */
       
   729 	{
       
   730 	TCommServerConfigV01 *c;
       
   731 	c = (TCommServerConfigV01*)aDes.Ptr();
       
   732 	if (aDes.Size()!=sizeof(TCommServerConfigV01))
       
   733 		return KErrGeneral;
       
   734 
       
   735 	if (!((c->iBufFlags&KCommBufferPartial) && (c->iBufSize&0x10)))
       
   736 		User::Panic(_L("Dummy"),E_ParametersCorrupted);
       
   737 
       
   738 	iBufFlags=c->iBufFlags;
       
   739 	iBufSize=c->iBufSize;
       
   740 	return KErrNone;
       
   741 	}
       
   742 
       
   743 
       
   744 TInt CDummyPort::GetServerConfig(TDes8& aDes)
       
   745 /**
       
   746  *	get server configurations
       
   747  */
       
   748 	{
       
   749 
       
   750 	TCommServerConfigV01 *c;
       
   751 	c = (TCommServerConfigV01*)aDes.Ptr();
       
   752 	if (aDes.Size()!=sizeof(TCommServerConfigV01))
       
   753 		return KErrGeneral;
       
   754 
       
   755 	c->iBufFlags = iBufFlags;
       
   756 	c->iBufSize = iBufSize;
       
   757 
       
   758 	return KErrNone;
       
   759 	}
       
   760 
       
   761 
       
   762 TInt CDummyPort::GetSignals(TUint& aSignals)
       
   763 /**
       
   764  * get the status of the signal pins
       
   765  */
       
   766 	{
       
   767 	if (iRole==ECommRoleDTE)
       
   768 		aSignals = (KSignalDTEInputs);
       
   769 	else
       
   770 		aSignals = (KSignalDCEInputs);
       
   771 
       
   772 
       
   773 	return KErrNone;
       
   774 	}
       
   775 
       
   776 
       
   777 TInt CDummyPort::SetSignalsToMark(TUint aSignals)
       
   778 /**
       
   779  * set selected signals to high (logical 1)
       
   780  *
       
   781  * @param aSignals bitmask with the signals to be set
       
   782  * @return KErrNone always
       
   783  */
       
   784 	{
       
   785 
       
   786 	if (iRole==ECommRoleDTE)
       
   787 		{
       
   788 		if (aSignals!=KSignalDTEOutputs)
       
   789 			User::Panic(_L("Dummy"),E_ParametersCorrupted);
       
   790 		aSignals &= KSignalDTEOutputs;
       
   791 		}
       
   792 	else
       
   793 		{
       
   794 		if (aSignals!=KSignalDCEOutputs)
       
   795 			User::Panic(_L("Dummy"),E_ParametersCorrupted);
       
   796 		aSignals &= KSignalDCEOutputs;
       
   797 		}
       
   798 
       
   799     if(aSignals)
       
   800         {
       
   801         iSignals |= aSignals;
       
   802 		}
       
   803 	return KErrNone;
       
   804 	}
       
   805 
       
   806 
       
   807 TInt CDummyPort::SetSignalsToSpace(TUint aSignals)
       
   808 /**
       
   809  * set selected signals to low (logical 0)
       
   810  *
       
   811  * @param aSignals bitmask with the signals to be cleared
       
   812  * @return KErrNone always
       
   813  */
       
   814 	{
       
   815 
       
   816 
       
   817 	if (iRole==ECommRoleDTE)
       
   818 		{
       
   819 		if (aSignals!=KSignalDTEOutputs)
       
   820 			User::Panic(_L("Dummy"),E_ParametersCorrupted);
       
   821 	    aSignals &= KSignalDTEOutputs;
       
   822 		}
       
   823 	else
       
   824 		{
       
   825 		if (aSignals!=KSignalDCEOutputs)
       
   826 			User::Panic(_L("Dummy"),E_ParametersCorrupted);
       
   827 		aSignals &= KSignalDCEOutputs;
       
   828 		}
       
   829 
       
   830     if(aSignals)
       
   831         {
       
   832         iSignals &= ~aSignals;
       
   833         }
       
   834 	return KErrNone;
       
   835 	}
       
   836 
       
   837 
       
   838 TInt CDummyPort::GetReceiveBufferLength(TInt& aLength) const
       
   839 /**
       
   840  * get size of Tx and Rx buffer
       
   841  *
       
   842  * @param aLength reference to where the length will be written to
       
   843  * @return KErrNone always
       
   844  */
       
   845 	{
       
   846 
       
   847     aLength = iLength;
       
   848 	return KErrNone;
       
   849 	}
       
   850 
       
   851 
       
   852 TInt CDummyPort::SetReceiveBufferLength(TInt aLength)
       
   853 /**
       
   854  * set the size of Tx and Rx buffer
       
   855  *
       
   856  * @param aLength new length of Tx and Rx buffer
       
   857  * @return TInt error code
       
   858  */
       
   859 	{
       
   860 	iLength	= aLength;
       
   861     return KErrNone;
       
   862 	}
       
   863 
       
   864 
       
   865 void CDummyPort::NotifyDataAvailable()
       
   866 /**
       
   867  * Set the flag on that we must notify C32 when there has appeared data into
       
   868  * incoming buffer
       
   869  */
       
   870 	{
       
   871 	iCompleteDataAvailablePtr->Complete(ECommNotifyDataAvailable,iDummyCompleteDelaySlow,KErrNone);
       
   872 	}
       
   873 
       
   874 
       
   875 void CDummyPort::NotifyDataAvailableCancel()
       
   876 /**
       
   877  * Set the flag on that we must not notify C32 when there has appeared data
       
   878  * into incoming buffer
       
   879  */
       
   880 	{
       
   881 	iCompleteDataAvailablePtr->CancelComplete();
       
   882 	}
       
   883 
       
   884 
       
   885 void CDummyPort::NotifyOutputEmpty()
       
   886 /**
       
   887  * Set the flag on that we must not notify C32 when outgoing buffer is empty
       
   888  */
       
   889 	{
       
   890 	iCompleteOutputEmptyPtr->Complete(ECommNotifyOutputEmpty,iDummyCompleteDelaySlow,KErrNone);
       
   891 	}
       
   892 
       
   893 
       
   894 void CDummyPort::NotifyOutputEmptyCancel()
       
   895 /**
       
   896  * Set the flag on that we must not notify C32 when outgoing buffer is empty
       
   897  */
       
   898 	{
       
   899 	iCompleteOutputEmptyPtr->CancelComplete();
       
   900 	}
       
   901 
       
   902 
       
   903 void CDummyPort::Destruct()
       
   904 /**
       
   905  * Called from Port manager to close us down - we must call delete this sometime
       
   906  * soon (unless AcessCount goes positive again)
       
   907  */
       
   908 	{
       
   909 	if(iCompleteClosePtr)
       
   910 		{
       
   911 		if (!iCompleteClosePtr->IsActive()) // Don't want two completes at once
       
   912 			iCompleteClosePtr->Complete(ECommClose,iDummyCompleteDelaySlow,KErrNone);
       
   913 
       
   914 		}
       
   915 	}
       
   916 
       
   917 
       
   918 
       
   919 //**********************************************************************
       
   920 //			            DUMMY DLL ENTRY POINT CODE
       
   921 //**********************************************************************
       
   922 
       
   923 
       
   924 extern "C"
       
   925 	{
       
   926 	IMPORT_C CSerial* LibEntry(); // Force export
       
   927 	}
       
   928 
       
   929 
       
   930 EXPORT_C CSerial * LibEntry()
       
   931 /**
       
   932  * Lib main entry point
       
   933  */
       
   934 	{
       
   935 #ifdef DUMMYCSY15
       
   936 	return NULL;   // returning NULL ptr here so that load fails
       
   937 #else
       
   938 	CDummyPortFactory *c=NULL;
       
   939 	TRAPD(ret,c=CDummyPortFactory::NewL());
       
   940 	if (ret!=KErrNone)
       
   941 		{
       
   942 		return NULL;
       
   943 		}
       
   944 	return c;
       
   945 #endif
       
   946 	}
       
   947 
       
   948 
       
   949 //
       
   950 // implementation of CDummyCompleter
       
   951 //
       
   952 
       
   953 
       
   954 CDummyCompleter::CDummyCompleter(CDummyPort& aPort)
       
   955 /**
       
   956  * C'tor
       
   957  */
       
   958 	:CActive(EPriorityStandard)
       
   959 	,iPort(aPort)
       
   960 	,iReason(KErrNone)
       
   961 	{
       
   962 	CActiveScheduler::Add(this);
       
   963 	}
       
   964 
       
   965 
       
   966 void CDummyCompleter::Complete(TCommMess aMess,TTimeIntervalMicroSeconds32 anInterval, TInt aReason, TUint aValue)
       
   967 /**
       
   968  * complete a request
       
   969  */
       
   970 	{
       
   971 	iReason = aReason;
       
   972 	iMess = aMess;
       
   973 	iValue = aValue;
       
   974 	TInt ret=iTimer.CreateLocal();
       
   975 	if (ret!=KErrNone)
       
   976 		User::Panic(_L("Dummy"),E_ParametersCorrupted);
       
   977 	iTimer.After(iStatus,anInterval); // 2 seconds timeout
       
   978 	SetActive();
       
   979 	}
       
   980 
       
   981 
       
   982 void CDummyCompleter::Complete(TCommMess aMess,TTimeIntervalMicroSeconds32 anInterval, TInt aReason, const TDesC8& aDescriptor)
       
   983 /**
       
   984  * complete a request
       
   985  */
       
   986 	{
       
   987 	iReason = aReason;
       
   988 	iMess = aMess;
       
   989 	//iConfPtr = (TAny *)&aDescriptor;
       
   990 	Mem::FillZ(&iPeerConfig,sizeof(iPeerConfig));
       
   991 	TInt len=Min(aDescriptor.Length(),sizeof(iPeerConfig));
       
   992 	Mem::Copy(&iPeerConfig, aDescriptor.Ptr(),len);
       
   993 	TInt ret=iTimer.CreateLocal();
       
   994 	if (ret!=KErrNone)
       
   995 		User::Panic(_L("Dummy"),E_ParametersCorrupted);
       
   996 	iTimer.After(iStatus,anInterval); // 2 seconds timeout
       
   997 	SetActive();
       
   998 	}
       
   999 
       
  1000 
       
  1001 void CDummyCompleter::CancelComplete()
       
  1002 /**
       
  1003  * cancel a complete
       
  1004  */
       
  1005 	{
       
  1006 	Cancel();
       
  1007 	}
       
  1008 
       
  1009 
       
  1010 CDummyCompleter::~CDummyCompleter()
       
  1011 /**
       
  1012  * D'tor
       
  1013  */
       
  1014 	{
       
  1015 	CActive::Cancel();
       
  1016 	}
       
  1017 
       
  1018 
       
  1019 void CDummyCompleter::RunL()
       
  1020 /**
       
  1021  * a completer request has completed
       
  1022  */
       
  1023 	{
       
  1024 	TInt ret = iStatus.Int();
       
  1025 
       
  1026 	if (ret!=KErrNone)
       
  1027 		{
       
  1028 		return;
       
  1029 		}
       
  1030 
       
  1031 	switch(iMess)
       
  1032 		{
       
  1033 		case ECommNotifySignals:
       
  1034 
       
  1035 			iPort.SignalChangeCompleted(iValue,iReason);
       
  1036 			break;
       
  1037 		case ECommNotifyFlowControl:
       
  1038 			iPort.FlowControlChangeCompleted((TFlowControl)iValue,iReason);
       
  1039 			break;
       
  1040 		case ECommNotifyConfigChange:
       
  1041 			{
       
  1042 			TPckg<TCommNotificationV01> cfg(iPeerConfig);
       
  1043 			iPort.ConfigChangeCompleted(cfg,iReason);
       
  1044 			}
       
  1045 			break;
       
  1046 		case ECommNotifyBreak:
       
  1047 			iPort.BreakNotifyCompleted(iReason);
       
  1048 			break;
       
  1049 		case ECommBreak:
       
  1050 			iPort.BreakCompleted(iReason);
       
  1051 			break;
       
  1052 		case ECommRead:
       
  1053 			iPort.ReadCompleted(iReason);
       
  1054 			break;
       
  1055 		case ECommWrite:
       
  1056 			iPort.WriteCompleted(iReason);
       
  1057 			break;
       
  1058 		case ECommNotifyDataAvailable:
       
  1059 			iPort.NotifyDataAvailableCompleted(iReason);
       
  1060 			break;
       
  1061 		case ECommNotifyOutputEmpty:
       
  1062 			iPort.NotifyOutputEmptyCompleted(iReason);
       
  1063 			break;
       
  1064 		case ECommClose:
       
  1065 			if (iPort.AccessCount()==0)
       
  1066 				delete &iPort; // will delete this also
       
  1067 			break;
       
  1068 		default:
       
  1069 			break;
       
  1070 
       
  1071 		}
       
  1072 
       
  1073 	}
       
  1074 
       
  1075 
       
  1076 void CDummyCompleter::DoCancel()
       
  1077 /**
       
  1078  * called when a cancelling the request
       
  1079  */
       
  1080 	{
       
  1081 	iTimer.Cancel();
       
  1082 	}
       
  1083 
       
  1084 // EOF - DUMMY.CPP
       
  1085