lbstest/lbstestproduct/agpshybridmodule/src/ctestharnesshandler.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2007-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 // Implementation of Test A_Gps module request handler component.
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "ctestharnesshandler.h"
       
    19 
       
    20 const TInt KBufferedMsgMaxCount = 6;
       
    21 
       
    22 CT_TestHarnessHandler::CT_TestHarnessHandler(MT_RequestObserver* aObserver) : 
       
    23 	CActive(EPriorityHigh),
       
    24 	iObserver(aObserver)
       
    25 	{
       
    26 	}
       
    27 	
       
    28 CT_TestHarnessHandler::~CT_TestHarnessHandler()
       
    29 	{
       
    30 	Cancel();
       
    31 	iTHChannel.Close();
       
    32 	iMsgBuffer.ResetAndDestroy();
       
    33 	}
       
    34 
       
    35 CT_TestHarnessHandler* CT_TestHarnessHandler::NewL(MT_RequestObserver* aObserver)
       
    36 	{
       
    37 	CT_TestHarnessHandler* self = new (ELeave) CT_TestHarnessHandler(aObserver);
       
    38 	CleanupStack::PushL(self);
       
    39 	self->ConstructL();
       
    40 	CleanupStack::Pop(self);
       
    41 	return self;
       
    42 	}
       
    43 	
       
    44 void CT_TestHarnessHandler::ConstructL()
       
    45 	{
       
    46     RT_LbsChannel::InitializeL(RT_LbsChannel::EChannelTAGPS2TH);
       
    47 	iMsgBuffer.ReserveL(KBufferedMsgMaxCount);
       
    48 	iTHChannel.OpenL(RT_LbsChannel::EChannelTAGPS2TH, *this);
       
    49 	CActiveScheduler::Add(this);
       
    50 	}
       
    51 
       
    52 void CT_TestHarnessHandler::SendDataOutResponse(TT_LbsAGpsResponseMsg::TModuleResponseType aResponse)
       
    53 	{
       
    54  	TT_LbsAGpsResponseMsg* aMsg = new TT_LbsAGpsResponseMsg(aResponse);
       
    55 
       
    56  	BufferMessage(aMsg);	
       
    57 	}
       
    58 	
       
    59 void CT_TestHarnessHandler::RunL()
       
    60 	{
       
    61 	User::LeaveIfError(iStatus.Int());
       
    62 		
       
    63 	if (iMsgBuffer.Count() > 0)
       
    64 		{	
       
    65 		SendResponseMessage(iMsgBuffer[0]);
       
    66 		iMsgBuffer.Remove(0);
       
    67 		}
       
    68 	}
       
    69 	
       
    70 void CT_TestHarnessHandler::DoCancel()
       
    71 	{
       
    72 	iTHChannel.CancelSendMessageNotification();
       
    73 	}
       
    74 	
       
    75 TInt CT_TestHarnessHandler::RunError(TInt aError)
       
    76 	{
       
    77 	return aError;
       
    78 	}
       
    79 
       
    80 void CT_TestHarnessHandler::SendResponseMessage(const TT_LbsMsgBase* aMessage)
       
    81 	{
       
    82 	iTHChannel.SendMessage(*aMessage, iStatus);
       
    83 	// The msg has now been sent to the channel. We can now delete it.
       
    84 	delete(aMessage);
       
    85 	SetActive();
       
    86 	}
       
    87 
       
    88 void CT_TestHarnessHandler::BufferMessage(const TT_LbsMsgBase* aMessage)
       
    89 	{	
       
    90 	if (!IsActive())
       
    91 		{
       
    92 		// The AO is not active, so there should be no buffered messages.
       
    93 		__ASSERT_DEBUG(iMsgBuffer.Count() == 0, User::Invariant());
       
    94 		
       
    95 		// Immediately send the new message.
       
    96 		SendResponseMessage(aMessage);
       
    97 		}
       
    98 	else
       
    99 		{
       
   100 		__ASSERT_ALWAYS(iMsgBuffer.Count() < KBufferedMsgMaxCount, User::Invariant());
       
   101 
       
   102 		// Still waiting for acknowledgement that a previous message
       
   103 		// was read, so buffer this new message.
       
   104 		iMsgBuffer.Append(aMessage);
       
   105 		}
       
   106 	}
       
   107 
       
   108 /** Process requests from the test step. Test data is passed to the test module via the input
       
   109 	data bus.
       
   110 */
       
   111 void CT_TestHarnessHandler::ProcessChannelMessage(RT_LbsChannel::TT_LbsChannelId /*aChannelId*/, 
       
   112 												 const TT_LbsMsgBase& aMessage)
       
   113 	{
       
   114 	TInt err = KErrNone;
       
   115 	
       
   116 	switch (aMessage.Type())
       
   117 		{
       
   118 		case TT_LbsMsgBase::EModuleRequestUpdateInit:
       
   119 			{
       
   120 			const TT_LbsAGpsRequestUpdateInitMsg& msg = static_cast<const TT_LbsAGpsRequestUpdateInitMsg&>(aMessage);
       
   121 			err = iObserver->ProcessRequestUpdateInit(msg.ConfigFileName(), msg.ConfigSection());
       
   122 			break;				
       
   123 			}
       
   124 		case TT_LbsMsgBase::EModuleRequestTimeOut:
       
   125 			{
       
   126 			const TT_LbsAGpsRequestTimeOut& msg = static_cast<const TT_LbsAGpsRequestTimeOut&>(aMessage);
       
   127 			iObserver->ProcessRequestTimeOut(msg.TimeOut());
       
   128 			break;				
       
   129 			}
       
   130 		case TT_LbsMsgBase::EModuleRequestOptions:
       
   131 			{
       
   132 			const TT_LbsAGpsRequestOptions& msg = static_cast<const TT_LbsAGpsRequestOptions&>(aMessage);
       
   133 			err = iObserver->ProcessRequestModuleOptions(msg.ModuleOption(), msg.ModuleValue());		
       
   134 			break;				
       
   135 			}
       
   136 		case TT_LbsMsgBase::EModuleRequestError:
       
   137 			{
       
   138 			const TT_LbsAGpsRequestError& msg = static_cast<const TT_LbsAGpsRequestError&>(aMessage);
       
   139 			iObserver->ProcessRequestError(msg.Error());
       
   140 			break;
       
   141 			}
       
   142 		case TT_LbsMsgBase::EModuleRequestForcedUpdate:
       
   143 			{
       
   144 			iObserver->ProcessRequestForcedUpdate();
       
   145 			break;
       
   146 			}
       
   147 		case TT_LbsMsgBase::EModuleImmediateMeasurements:
       
   148 			{
       
   149 			const TT_LbsAGpsImmediateMeasurements& msg = static_cast<const TT_LbsAGpsImmediateMeasurements&>(aMessage);
       
   150 			iObserver->ProcessImmediateMeasurements(msg.ImmediateMeasurements());
       
   151 			break;
       
   152 			}
       
   153 		default:
       
   154 			{
       
   155 			err = KErrNotSupported;									
       
   156 			break;										
       
   157 			}
       
   158 		}		
       
   159 
       
   160 	// Publish a response to the in coming data, now that we have handled it.
       
   161 	if (err == KErrNone)
       
   162 		{
       
   163 		SendDataOutResponse(TT_LbsAGpsResponseMsg::EModuleResponseOk);
       
   164 		}
       
   165 	else
       
   166 		{
       
   167 		SendDataOutResponse(TT_LbsAGpsResponseMsg::EModuleErr);
       
   168 		}
       
   169 
       
   170 	}
       
   171