dbgagents/trkagent/dbgtrccomm/server/dbgtrcsrvsession.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     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 "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 "logging.h"
       
    19 #include "dbgtrcportmgr.h"
       
    20 #include "ostbaserouter.h"
       
    21 #include "dbgtrccmdcodes.h"
       
    22 #include "ostmessage.h"
       
    23 
       
    24 #include "dbgtrcsrvsession.h"
       
    25 #include "dbgtrcsrvserver.h"
       
    26 
       
    27 
       
    28 
       
    29 // Type definitions
       
    30 
       
    31 // Constants
       
    32 const TInt KDbgTrcServerTransferBufferExpandSize = 100;
       
    33 //const TInt KSlot0 = 0;
       
    34 const TInt KSlot1 = 1;
       
    35 const TInt KSlot2 = 2;
       
    36 //const TInt KSlot3 = 3;
       
    37 
       
    38 // Enumerations
       
    39 
       
    40 // Classes referenced
       
    41 
       
    42 // Static functions
       
    43 //
       
    44 // Checks for a null'd handle before attempting complete. 
       
    45 // If handle is null'd then don't complete as this will panic server.
       
    46 //
       
    47 void SafeComplete(const RMessagePtr2& aMessage, TInt aCompletionCode)
       
    48 {
       
    49 	if(!aMessage.IsNull())
       
    50 	{
       
    51 		aMessage.Complete(aCompletionCode);
       
    52 	}
       
    53 }
       
    54 
       
    55 
       
    56 //
       
    57 // CDbgTrcSrvSession (source)
       
    58 //
       
    59 
       
    60 //
       
    61 // CTrkTcbSrvServer::CDbgTrcSrvSession()
       
    62 //
       
    63 // Constructor
       
    64 //
       
    65 CDbgTrcSrvSession::CDbgTrcSrvSession(COstBaseRouter* aOstRouter)
       
    66 : 	iPendingRead(EFalse),
       
    67 	iPendingWrite(EFalse),
       
    68 	iPendingReadBufferLength(0),
       
    69 	iOstRouter(aOstRouter),
       
    70 	iRecvMessageQueue(1),
       
    71 	iProtocolIds(1)
       
    72 {
       
    73 	LOG_MSG("CDbgTrcSrvSession::CDbgTrcSrvSession");
       
    74 }
       
    75 
       
    76 //
       
    77 // CTrkTcbSrvServer::~CDbgTrcSrvSession()
       
    78 //
       
    79 // Destructor
       
    80 //
       
    81 CDbgTrcSrvSession::~CDbgTrcSrvSession()
       
    82 {
       
    83 	LOG_MSG("CDbgTrcSrvSession::~CDbgTrcSrvSession");
       
    84 	
       
    85 	HandleServerDestruction();
       
    86 	delete iTransferBuffer;
       
    87 	
       
    88 	iRecvMessageQueue.ResetAndDestroy();
       
    89 	iRecvMessageQueue.Close();
       
    90 	
       
    91 	iProtocolIds.Reset();
       
    92 	iProtocolIds.Close();
       
    93 	
       
    94 	//get a reference to the server
       
    95 	CDbgTrcSrvServer* dbgTrcServer = (CDbgTrcSrvServer*)Server();
       
    96 
       
    97 	//notify the server that the session has been opened
       
    98 	if (dbgTrcServer != NULL)
       
    99 		dbgTrcServer->SessionClosed();
       
   100 }
       
   101 
       
   102 //
       
   103 // CTrkTcbSrvServer::ConstructL()
       
   104 //
       
   105 // Creates an instance of CDbgTrcSrvSession.
       
   106 //
       
   107 void CDbgTrcSrvSession::ConstructL()
       
   108 {
       
   109 	LOG_MSG("CDbgTrcSrvSession::ConstructL");
       
   110 	
       
   111 	iTransferBuffer = CBufFlat::NewL(KDbgTrcServerTransferBufferExpandSize);
       
   112 	
       
   113 	iRecvMessageQueue.Reset();
       
   114 
       
   115 	iProtocolIds.Reset();
       
   116 	
       
   117 }
       
   118 
       
   119 void CDbgTrcSrvSession::CreateL()
       
   120 {
       
   121 	//get a reference to the server
       
   122 	CDbgTrcSrvServer* dbgTrcServer = (CDbgTrcSrvServer*)Server();
       
   123 	
       
   124 	//notify the server that the session has been opened
       
   125 	if (dbgTrcServer != NULL)
       
   126 		dbgTrcServer->SessionOpened();
       
   127 }
       
   128 //
       
   129 // CTrkTcbSrvServer::NewL()
       
   130 //
       
   131 // Static self construction
       
   132 //
       
   133 CDbgTrcSrvSession* CDbgTrcSrvSession::NewL(COstBaseRouter* aOstRouter)
       
   134 {
       
   135 	LOG_MSG("CDbgTrcSrvSession::NewL");
       
   136 
       
   137 	CDbgTrcSrvSession* self = new(ELeave) CDbgTrcSrvSession(aOstRouter);
       
   138 	CleanupStack::PushL(self);
       
   139 	self->ConstructL();
       
   140 	CleanupStack::Pop(self);
       
   141 	return self;
       
   142 }
       
   143 
       
   144 //
       
   145 // CTrkTcbSrvServer::HandleServerDestruction()
       
   146 //
       
   147 // Called by the server's destructor. We need to be told that the server is
       
   148 // being destroyed.
       
   149 //
       
   150 void CDbgTrcSrvSession::HandleServerDestruction()
       
   151 {
       
   152 	LOG_MSG("CDbgTrcSrvSession::HandleServerDestruction");
       
   153 	
       
   154 	// disconnect here just in case if the client has not disconnected before shutting down.
       
   155 	DoDisconnect();
       
   156 }
       
   157 
       
   158 //
       
   159 // CTrkTcbSrvServer::ServiceL()
       
   160 //
       
   161 // Services requests from a client.
       
   162 // Called by the IPC framework whenever a client sends a request to the server.
       
   163 //
       
   164 void CDbgTrcSrvSession::ServiceL(const RMessage2& aMessage)
       
   165 {
       
   166 	LOG_MSG("CDbgTrcSrvSession::ServiceL");
       
   167 
       
   168 	const TInt cmd = aMessage.Function();	
       
   169 	switch(cmd)
       
   170 	{
       
   171 		case EDbgTrcCmdCodeGetAcmConfig:
       
   172 			CmdGetAcmConfigL(aMessage);
       
   173 			break;
       
   174 		case EDbgTrcCmdCodeSetAcmConfig:
       
   175 			CmdSetAcmConfigL(aMessage);
       
   176 			break;
       
   177 		case EDbgTrcCmdCodeOpen:
       
   178 			CmdOpenCommPortL(aMessage);
       
   179 			break;
       
   180 		case EDbgTrcCmdCodeClose:
       
   181 			CmdCloseCommPort(aMessage);
       
   182 			break;
       
   183 		case EDbgTrcCmdCodeRegisterId:
       
   184 			CmdRegisterProtocol(aMessage);
       
   185 			break;
       
   186 		case EDbgTrcCmdCodeRegisterIds:
       
   187 			CmdRegisterProtocolIdsL(aMessage);
       
   188 			break;
       
   189 		case EDbgTrcCmdCodeUnRegisterId:
       
   190 			CmdUnRegisterProtocol(aMessage);
       
   191 			break;
       
   192 		case EDbgTrcCmdCodeUnRegisterIds:
       
   193 			CmdUnRegisterProtocolIdsL(aMessage);
       
   194 			break;
       
   195 		case EDbgTrcCmdCodeReadMsg:
       
   196 			CmdReadMsgL(aMessage);
       
   197 			break;
       
   198 		case EDbgTrcCmdCodeReadCancel:
       
   199 			CmdReadCancel(aMessage);			
       
   200 			break;
       
   201 		case EDbgTrcCmdCodeWriteMsg:
       
   202 			CmdWriteMsgL(aMessage);
       
   203 			break;
       
   204 		case EDbgTrcCmdCodeWriteCancel:
       
   205 			CmdWriteCancel(aMessage);			
       
   206 			break;
       
   207 		case EDbgTrcCmdDisconnect:
       
   208 			CmdDisconnect(aMessage);
       
   209 		default:
       
   210 			aMessage.Panic(KServerIntiatedSessionPanic, EDbgTrcServerInitiatedClientPanicInvalidOperation);
       
   211 			break;
       
   212 	}
       
   213 				
       
   214 }
       
   215 
       
   216 
       
   217 //
       
   218 // CTrkTcbSrvServer::CmdGetAcmConfigL()
       
   219 //
       
   220 // Gets the current port configuration 
       
   221 //
       
   222 void CDbgTrcSrvSession::CmdGetAcmConfigL(const RMessage2& aMessage)
       
   223 {
       
   224 	LOG_MSG("CDbgTrcSrvSession::CmdGetAcmConfigL");
       
   225 
       
   226 	const TInt desLength = static_cast<TInt>(aMessage.Int0());
       
   227 
       
   228 	if (desLength > 0 && desLength == sizeof(TAcmConfigV01))
       
   229 	{
       
   230 		TAcmConfig acmConfig;
       
   231 		iOstRouter->GetPortConfig(acmConfig);
       
   232 		
       
   233 		aMessage.WriteL(KSlot1, acmConfig);		
       
   234 		aMessage.Complete(KErrNone);
       
   235 	} 
       
   236 	else
       
   237 	{
       
   238 		aMessage.Complete(KErrBadDescriptor);		
       
   239 	}
       
   240 }
       
   241 
       
   242 //
       
   243 // CTrkTcbSrvServer::CmdSetAcmConfigL()
       
   244 //
       
   245 // Sets the port configuration if its not already set
       
   246 //
       
   247 void CDbgTrcSrvSession::CmdSetAcmConfigL(const RMessage2& aMessage)
       
   248 {
       
   249 	LOG_MSG("CDbgTrcSrvSession::CmdSetAcmConfigL");
       
   250 
       
   251 	const TInt desLength = static_cast<TInt>(aMessage.Int0());
       
   252 
       
   253 	if (desLength > 0 && desLength == sizeof(TAcmConfigV01))
       
   254 	{
       
   255 		TAcmConfig acmConfig;
       
   256 		aMessage.ReadL(KSlot1, acmConfig);
       
   257 		
       
   258 		TInt err = iOstRouter->SetPortConfig(acmConfig);		
       
   259 		
       
   260 		aMessage.Complete(err);
       
   261 	} 
       
   262 	else
       
   263 	{
       
   264 		aMessage.Complete(KErrBadDescriptor);
       
   265 	}
       
   266 }
       
   267 
       
   268 //
       
   269 // CTrkTcbSrvServer::CmdOpenCommPort()
       
   270 //
       
   271 // Opens the comm port, if its already opened, 
       
   272 // just increments the number of active connects and returns true
       
   273 //
       
   274 //
       
   275 void CDbgTrcSrvSession::CmdOpenCommPortL(const RMessage2& aMessage)
       
   276 {
       
   277 	LOG_MSG("CDbgTrcSrvSession::CmdOpenCommPort");
       
   278 
       
   279 	TInt err = iOstRouter->OpenCommPortL();
       
   280 	aMessage.Complete(err);
       
   281 }
       
   282 
       
   283 //
       
   284 // CTrkTcbSrvServer::CmdCloseCommPort()
       
   285 //
       
   286 // Closes the comm port, the port is actually closed when the
       
   287 // number of active connections is 0
       
   288 //
       
   289 //
       
   290 void CDbgTrcSrvSession::CmdCloseCommPort(const RMessage2& aMessage)
       
   291 {
       
   292 	LOG_MSG("CDbgTrcSrvSession::CmdCloseCommPort");
       
   293 
       
   294 	TInt err = iOstRouter->CloseCommPort();
       
   295 	aMessage.Complete(err);
       
   296 }
       
   297 
       
   298 //
       
   299 // CTrkTcbSrvServer::CmdRegisterProtocol()
       
   300 //
       
   301 // Registers the protocol with the id
       
   302 // This is necessary to be able to read messages
       
   303 //
       
   304 //
       
   305 void CDbgTrcSrvSession::CmdRegisterProtocol(const RMessage2& aMessage)
       
   306 {
       
   307 	LOG_MSG("CDbgTrcSrvSession::CmdRegisterProtocol");
       
   308 
       
   309 	const TOstProtIds aProtocolId = static_cast<TOstProtIds>(aMessage.Int0());
       
   310 	
       
   311 	TBool aNeedHeader = static_cast<TBool>(aMessage.Int1());
       
   312 	
       
   313 	iOstRouter->RegisterProtocol(aProtocolId, this, aNeedHeader);
       
   314 	
       
   315 	iProtocolIds.Append(aProtocolId);	
       
   316 	
       
   317 	aMessage.Complete(KErrNone);
       
   318 }
       
   319 
       
   320 //
       
   321 // CTrkTcbSrvServer::CmdUnRegisterProtocol()
       
   322 //
       
   323 // Registers the protocol with the id
       
   324 // This is necessary to be able to read messages
       
   325 //
       
   326 //
       
   327 void CDbgTrcSrvSession::CmdUnRegisterProtocol(const RMessage2& aMessage)
       
   328 {
       
   329 	LOG_MSG("CDbgTrcSrvSession::CmdUnRegisterProtocol");
       
   330 
       
   331 	const TOstProtIds aProtocolId = static_cast<TOstProtIds>(aMessage.Int0());
       
   332 	
       
   333 	iOstRouter->UnRegisterProtocol(aProtocolId);
       
   334 	for (TInt i=0; i<iProtocolIds.Count(); i++)
       
   335 	{
       
   336 		if (iProtocolIds[i] == aProtocolId)
       
   337 		{
       
   338 			iProtocolIds.Remove(i);
       
   339 			break;
       
   340 		}
       
   341 	}
       
   342 	
       
   343 	aMessage.Complete(KErrNone);
       
   344 }
       
   345 
       
   346 //
       
   347 // CTrkTcbSrvServer::CmdRegisterProtocolIds()
       
   348 //
       
   349 // Registers the protocol with the id
       
   350 // This is necessary to be able to read messages
       
   351 //
       
   352 //
       
   353 void CDbgTrcSrvSession::CmdRegisterProtocolIdsL(const RMessage2& aMessage)
       
   354 {
       
   355 	LOG_MSG("CDbgTrcSrvSession::CmdRegisterProtocolIdsL");
       
   356 
       
   357 	TBool aNeedHeader = static_cast<TBool>(aMessage.Int0());
       
   358 	const TInt numberOfIds = static_cast<TInt>(aMessage.Int1());
       
   359 
       
   360 	TBuf8<25> protocolIds;
       
   361 	aMessage.ReadL(KSlot2, protocolIds);
       
   362 	
       
   363 	const TUint8* protocolPtr = protocolIds.Ptr();
       
   364 	for (TInt i=0; i<numberOfIds; i++)
       
   365 	{
       
   366 		iOstRouter->RegisterProtocol((TOstProtIds)protocolPtr[i], this, aNeedHeader);
       
   367 		iProtocolIds.Append((TOstProtIds)protocolPtr[i]);
       
   368 	}
       
   369 	
       
   370 	aMessage.Complete(KErrNone);
       
   371 
       
   372 }
       
   373 
       
   374 //
       
   375 // CTrkTcbSrvServer::CmdUnRegisterProtocol()
       
   376 //
       
   377 // Registers the protocol with the id
       
   378 // This is necessary to be able to read messages
       
   379 //
       
   380 //
       
   381 void CDbgTrcSrvSession::CmdUnRegisterProtocolIdsL(const RMessage2& aMessage)
       
   382 {
       
   383 	LOG_MSG("CDbgTrcSrvSession::CmdUnRegisterProtocolIdsL");
       
   384 
       
   385 	const TInt numberOfIds = static_cast<TInt>(aMessage.Int0());
       
   386 	
       
   387 	TBuf8<25> protocolIds;
       
   388 	aMessage.ReadL(KSlot1, protocolIds);
       
   389 	
       
   390 	const TUint8* protocolPtr = protocolIds.Ptr();
       
   391 	for (TInt i=0; i<numberOfIds; i++)
       
   392 	{
       
   393 		iOstRouter->UnRegisterProtocol((TOstProtIds)protocolPtr[i]);
       
   394 		for (TInt j=0; j<iProtocolIds.Count(); j++)
       
   395 		{
       
   396 			if (iProtocolIds[j] == (TOstProtIds)protocolPtr[i])
       
   397 			{
       
   398 				iProtocolIds.Remove(j);
       
   399 				break;
       
   400 			}
       
   401 		}
       
   402 	}
       
   403 	
       
   404 	aMessage.Complete(KErrNone);
       
   405 }
       
   406 
       
   407 
       
   408 //
       
   409 // CTrkTcbSrvServer::CmdReadMsgL()
       
   410 //
       
   411 // Gets the data for read file request and calls the session engine read file method.
       
   412 //
       
   413 void CDbgTrcSrvSession::CmdReadMsgL(const RMessage2& aMessage)
       
   414 {		
       
   415 	LOG_MSG("CDbgTrcSrvSession::CmdReadMsg");
       
   416 
       
   417 	if (iProtocolIds.Count() <= 0)
       
   418 	{
       
   419 		// No protocols are registered, just complete request here.
       
   420 		aMessage.Complete(KErrAccessDenied);
       
   421 		return;
       
   422 	}
       
   423 	
       
   424 	if (iRecvMessageQueue.Count() > 0)
       
   425 	{
       
   426 		LOG_MSG("Message found in recieve queue");
       
   427 
       
   428 		iPendingReadBufferLength = static_cast<TUint>(aMessage.Int0());		
       
   429 		
       
   430 		COstMessage* ostMsg = iRecvMessageQueue[0];				
       
   431 		HBufC8* msg = ostMsg->iMsgBuffer;
       
   432 		
       
   433 		if (msg->Length() <= iPendingReadBufferLength)
       
   434 		{
       
   435 			//write the file data into the client descriptor
       
   436 			aMessage.WriteL(KSlot1, msg->Des());			
       
   437 			aMessage.Complete(KErrNone);
       
   438 			
       
   439 			// now remove the message from the queue
       
   440 			SafeDelete(iRecvMessageQueue[0]);			
       
   441 			iRecvMessageQueue.Remove(0);
       
   442 		}
       
   443 		else
       
   444 		{
       
   445 			aMessage.Complete(KErrBadDescriptor);
       
   446 		}
       
   447 	}
       
   448 	else
       
   449 	{
       
   450 		if (iPendingRead)
       
   451 		{			
       
   452 			aMessage.Complete(KErrAlreadyExists);
       
   453 		}
       
   454 		else
       
   455 		{
       
   456 			iBlockedRead = aMessage;
       
   457 			iPendingReadBufferLength = static_cast<TUint>(aMessage.Int0());		
       
   458 			
       
   459 			iPendingRead = ETrue;
       
   460 			
       
   461 			// initiate the read.
       
   462 			iOstRouter->ReadMessage();
       
   463 		}
       
   464 	}
       
   465 }
       
   466 
       
   467 void CDbgTrcSrvSession::CmdReadCancel(const RMessage2& aMessage)
       
   468 {
       
   469 	LOG_MSG("CDbgTrcSrvSession::CmdReadCancel");
       
   470 	
       
   471 	if (iPendingRead && iBlockedRead.Handle())
       
   472 	{
       
   473 		SafeComplete(iBlockedRead, KErrCancel);
       
   474 		iPendingRead = EFalse;						
       
   475 	}
       
   476 	
       
   477 	// now complete the read cancel request.	
       
   478 	SafeComplete(aMessage, KErrNone);
       
   479 }
       
   480 
       
   481 void CDbgTrcSrvSession::CmdWriteMsgL(const RMessage2& aMessage)
       
   482 {
       
   483 	LOG_MSG("CDbgTrcSrvSession::CmdWriteMsg");
       
   484 
       
   485 	if (iPendingWrite)
       
   486 	{
       
   487 		aMessage.Complete(KErrAlreadyExists);
       
   488 	}
       
   489 	else
       
   490 	{
       
   491 		const TBool hasHeader = static_cast<TInt>(aMessage.Int0());
       
   492 		const TInt msgLength = static_cast<TInt>(aMessage.Int1());
       
   493 	
       
   494 		if (msgLength > 0)
       
   495 		{
       
   496 			if (!hasHeader && iProtocolIds.Count() != 1)
       
   497 			{
       
   498 				// For now, if there is no header, then we should have only one protocol id registered by the client.
       
   499 				// otherwise we don't support writing the message.
       
   500 				aMessage.Complete(KErrNotSupported);
       
   501 				return;
       
   502 			}
       
   503 			
       
   504 			HBufC8* msgData = HBufC8::NewLC(msgLength);
       
   505 			TPtr8 pMsgData(msgData->Des());
       
   506 			aMessage.ReadL(KSlot2, pMsgData);
       
   507 			
       
   508 			iBlockedWrite = aMessage;
       
   509 			iPendingWrite = ETrue;
       
   510 			
       
   511 			if (hasHeader)
       
   512 				iOstRouter->WriteMessageL(*msgData, this);
       
   513 			else
       
   514 				iOstRouter->WriteMessageL(*msgData, this, iProtocolIds[0]);
       
   515 			//iOstRouter->WriteMessage(*msgData, this);
       
   516 			
       
   517 
       
   518 			CleanupStack::PopAndDestroy(msgData);			
       
   519 		}
       
   520 		else
       
   521 		{
       
   522 			aMessage.Complete(KErrBadDescriptor);
       
   523 		}		
       
   524 	}
       
   525 }
       
   526 
       
   527 void CDbgTrcSrvSession::CmdWriteCancel(const RMessage2& aMessage)
       
   528 {
       
   529 	LOG_MSG("CDbgTrcSrvSession::CmdWriteCancel");
       
   530 
       
   531 	// Just complete the pending writes, we don't really try to cancel the actual writes themselves.
       
   532 	if (iPendingWrite && iBlockedWrite.Handle())
       
   533 	{
       
   534 		SafeComplete(iBlockedWrite, KErrCancel);
       
   535 		iPendingWrite = EFalse;;							
       
   536 	}
       
   537 	
       
   538 	// now complete the write cancel message
       
   539 	aMessage.Complete(KErrNone);
       
   540 }
       
   541 
       
   542 void CDbgTrcSrvSession::CmdDisconnect(const RMessage2& aMessage)
       
   543 {
       
   544 	LOG_MSG("CDbgTrcSrvSession::CmdDisconnect");
       
   545 	
       
   546 	DoDisconnect();
       
   547 	aMessage.Complete(KErrNone);
       
   548 }
       
   549 
       
   550 
       
   551 void CDbgTrcSrvSession::DoDisconnect()
       
   552 {
       
   553 	LOG_MSG("CDbgTrcSrvSession::Disconnect");
       
   554 
       
   555 	for (TInt i=0; i<iProtocolIds.Count(); i++)
       
   556 	{
       
   557 		iOstRouter->UnRegisterProtocol(iProtocolIds[i]);				
       
   558 	}
       
   559 	iProtocolIds.Reset();
       
   560 
       
   561 	if (iPendingRead)
       
   562 	{
       
   563 		SafeComplete(iBlockedRead, KErrCancel);
       
   564 		iPendingRead = EFalse;					
       
   565 	}
       
   566 	if (iPendingWrite)
       
   567 	{
       
   568 		SafeComplete(iBlockedWrite, KErrCancel);
       
   569 		iPendingWrite = EFalse;				
       
   570 	}
       
   571 }
       
   572 
       
   573 //
       
   574 // CTrkTcbSrvServer::CmdShutDownServer()
       
   575 //
       
   576 // Stops the active scheduler. This way, server process will run to completion.
       
   577 //
       
   578 void CDbgTrcSrvSession::MessageAvailableL(TDesC8& aMsg)
       
   579 {
       
   580 	LOG_MSG("CDbgTrcSrvSession::MessageAvailable");
       
   581 
       
   582 	if (iPendingRead && iBlockedRead.Handle())
       
   583 	{
       
   584 		// read is pending, complete it now
       
   585 		if (aMsg.Length() <= iPendingReadBufferLength)
       
   586 		{
       
   587 			LOG_MSG("Completing read request");
       
   588 
       
   589 			//write the file data into the client descriptor
       
   590 			TRAPD(err, iBlockedRead.WriteL(KSlot1, aMsg))						
       
   591 			SafeComplete(iBlockedRead, err);	
       
   592 			
       
   593 			LOG_MSG("Completed read request");
       
   594 				
       
   595 			iPendingRead = EFalse;
       
   596 			// the message is completed, return from here
       
   597 			return;
       
   598 		}
       
   599 		else
       
   600 		{
       
   601 			LOG_MSG("Bad descriptor unable to complete read request");
       
   602 			SafeComplete(iBlockedRead, KErrBadDescriptor);
       
   603 			iPendingRead = EFalse;
       
   604 		}
       
   605 	}
       
   606 	else
       
   607 	{
       
   608 		LOG_MSG("Invalid read request handle");
       
   609 	}
       
   610 	
       
   611 	LOG_MSG("Queueing up the message");
       
   612 	//
       
   613 	// No pending read, so add the message to the recv queue
       
   614 	// Right now, there is no limit on the recv queue.
       
   615 	// Need to check if we need to limit the number of messages to be queued up.
       
   616 	// 
       
   617 	COstMessage* ostMessage = COstMessage::NewL(aMsg);
       
   618 	iRecvMessageQueue.Append(ostMessage);					
       
   619 }
       
   620 
       
   621 
       
   622 
       
   623 void CDbgTrcSrvSession::WriteComplete(TInt aErrCode)
       
   624 {
       
   625 	LOG_MSG("CDbgTrcSrvSession::WriteComplete");
       
   626 
       
   627 	if (iPendingWrite && iBlockedWrite.Handle())
       
   628 	{
       
   629 		LOG_MSG("Completing write request");
       
   630 
       
   631 		SafeComplete(iBlockedWrite, aErrCode);
       
   632 		iPendingWrite = EFalse;
       
   633 		
       
   634 		LOG_MSG("Completed write request");
       
   635 	}
       
   636 	else
       
   637 	{
       
   638 		LOG_MSG("Invalid write message handle");
       
   639 	}
       
   640 }
       
   641