os/mm/mmlibs/mmfw/tsrc/mmfunittest/DevSoundTest/CIPlugins/src/MMFDevSoundCIMuxDeMuxPluginImp.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/DevSoundTest/CIPlugins/src/MMFDevSoundCIMuxDeMuxPluginImp.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,299 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <ecom/implementationproxy.h>
    1.20 +#include <ecom/ecom.h>
    1.21 +#include <s32mem.h>				
    1.22 +
    1.23 +#include "devsoundciutestdevices.hrh"
    1.24 +#include "MMFDevSoundCIMuxDeMuxPluginImp.h"
    1.25 +
    1.26 +
    1.27 +
    1.28 +// MUX //
    1.29 +
    1.30 +TInt CMMFDevSoundCIMuxPluginImp::OpenInterface(TUid /*aInterfaceId*/)
    1.31 +	{
    1.32 +	// attempt to open the interface link with the
    1.33 +	// remote slave device
    1.34 +	iRemoteHandle = -1;
    1.35 +	TUid slaveId = {KUidMmfDevSoundCustomInterfaceDeMuxPlugin};
    1.36 +
    1.37 +	TInt handle = iUtility->OpenSlave(slaveId, KNullDesC8);
    1.38 +	if (handle >= 0)
    1.39 +		{
    1.40 +		iRemoteHandle = handle;
    1.41 +		}
    1.42 +
    1.43 +	return iRemoteHandle;
    1.44 +	}
    1.45 +
    1.46 +
    1.47 +void CMMFDevSoundCIMuxPluginImp::Release()
    1.48 +	{
    1.49 +	// close the slave device if it exists
    1.50 +	if (iRemoteHandle > 0)
    1.51 +		{
    1.52 +		// we assume the slave is closed correctly
    1.53 +		iUtility->CloseSlave(iRemoteHandle);
    1.54 +		}
    1.55 +
    1.56 +	TUid key = iKey;
    1.57 +	delete this;
    1.58 +
    1.59 +	// tell ECom to destroy us
    1.60 +	REComSession::DestroyedImplementation(key);
    1.61 +	}
    1.62 +
    1.63 +
    1.64 +void CMMFDevSoundCIMuxPluginImp::PassDestructorKey(TUid aDestructorKey)
    1.65 +	{
    1.66 +	// store the destructor key
    1.67 +	iKey = aDestructorKey;
    1.68 +	}
    1.69 +
    1.70 +
    1.71 +void CMMFDevSoundCIMuxPluginImp::CompleteConstructL(MMMFDevSoundCustomInterfaceMuxUtility* aCustomUtility)
    1.72 +	{
    1.73 +	// store a pointer to the the MMFDevSoundCustomMuxUtility class
    1.74 +	iUtility = aCustomUtility;
    1.75 +	}
    1.76 +
    1.77 +
    1.78 +MMMFDevSoundCustomInterfaceMuxPlugin* CMMFDevSoundCIMuxPluginImp::NewL()
    1.79 +	{
    1.80 +	CMMFDevSoundCIMuxPluginImp* self = new (ELeave) CMMFDevSoundCIMuxPluginImp;
    1.81 +	return self;
    1.82 +	}
    1.83 +
    1.84 +
    1.85 +TAny* CMMFDevSoundCIMuxPluginImp::CustomInterface(TUid /*aInterfaceId*/)
    1.86 +	{
    1.87 +	MMMFDevSoundCIMuxPluginInterface* interface = this;
    1.88 +	return interface;
    1.89 +	}
    1.90 +
    1.91 +
    1.92 +CMMFDevSoundCIMuxPluginImp::CMMFDevSoundCIMuxPluginImp()
    1.93 +	{
    1.94 +	}
    1.95 +
    1.96 +
    1.97 +CMMFDevSoundCIMuxPluginImp::~CMMFDevSoundCIMuxPluginImp()
    1.98 +	{
    1.99 +	}
   1.100 +
   1.101 +
   1.102 +TInt CMMFDevSoundCIMuxPluginImp::DevSoundCIMuxStopHeapFail()
   1.103 +	{
   1.104 +	TInt result = -1;
   1.105 +
   1.106 +	if (iRemoteHandle > 0)
   1.107 +		{	
   1.108 +		result = iUtility->SendSlaveSyncCommand(iRemoteHandle,
   1.109 +												EMMFDevSoundCIMuxDemuxStopHeapFail,
   1.110 +												KNullDesC8); 
   1.111 +		}
   1.112 +	return result;
   1.113 +	}
   1.114 +
   1.115 +
   1.116 +TInt CMMFDevSoundCIMuxPluginImp::DevSoundCIMuxCauseHeapFail(TInt aFailCount)
   1.117 +	{
   1.118 +	TInt result = -1;
   1.119 +
   1.120 +	if (iRemoteHandle > 0)
   1.121 +		{
   1.122 +		TPckgBuf<TInt> failCount(aFailCount);  
   1.123 +		result = iUtility->SendSlaveSyncCommand(iRemoteHandle,
   1.124 +												EMMFDevSoundCIMuxDemuxCauseHeapFail,
   1.125 +												failCount);  
   1.126 +		}
   1.127 +	return result;
   1.128 +	}
   1.129 +
   1.130 +TInt CMMFDevSoundCIMuxPluginImp::DevSoundCIMuxCheckHeapFail()
   1.131 +	{
   1.132 +	TInt result = -1;
   1.133 +	TPckgBuf<TInt> responsePckg;
   1.134 +	
   1.135 +	if (iRemoteHandle > 0)
   1.136 +		{
   1.137 +		result = iUtility->SendSlaveSyncCommandResult(iRemoteHandle,
   1.138 +												EMMFDevSoundCIMuxDemuxCheckHeapFail,
   1.139 +												KNullDesC8,
   1.140 +												responsePckg);  
   1.141 +		}
   1.142 +	
   1.143 +	User::LeaveIfError(result);
   1.144 +	return responsePckg();
   1.145 +
   1.146 +	}
   1.147 +
   1.148 +// DEMUX //
   1.149 +
   1.150 +TInt CMMFDevSoundCIDemuxPluginImp::OpenInterface(TUid /*aInterfaceId*/)
   1.151 +	{
   1.152 +	return KErrNone;
   1.153 +	}
   1.154 +
   1.155 +
   1.156 +void CMMFDevSoundCIDemuxPluginImp::Release()
   1.157 +	{
   1.158 +	TUid key = iKey;
   1.159 +
   1.160 +	delete this;
   1.161 +
   1.162 +	// tell ECom to destroy us
   1.163 +	REComSession::DestroyedImplementation(key);
   1.164 +	}
   1.165 +
   1.166 +
   1.167 +void CMMFDevSoundCIDemuxPluginImp::PassDestructorKey(TUid aDestructorKey)
   1.168 +	{
   1.169 +	// store the destructor key
   1.170 +	iKey = aDestructorKey;
   1.171 +	}
   1.172 +
   1.173 +
   1.174 +void CMMFDevSoundCIDemuxPluginImp::SetInterfaceTarget(MMMFDevSoundCustomInterfaceTarget* aTarget)
   1.175 +	{
   1.176 +	iTarget = aTarget;
   1.177 +	}
   1.178 +
   1.179 +
   1.180 +void CMMFDevSoundCIDemuxPluginImp::CompleteConstructL(MMMFDevSoundCustomInterfaceDeMuxUtility* aCustomUtility)
   1.181 +	{
   1.182 +	// store a pointer to the MMFDevSoundCustomDeMuxUtility class
   1.183 +	iUtility = aCustomUtility;
   1.184 +	}
   1.185 +
   1.186 +
   1.187 +void CMMFDevSoundCIDemuxPluginImp::RefreshL()
   1.188 +	{
   1.189 +	// Nothing to do in this implementation
   1.190 +	}
   1.191 +
   1.192 +
   1.193 +MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFDevSoundCIDemuxPluginImp::NewL()
   1.194 +	{
   1.195 +	CMMFDevSoundCIDemuxPluginImp* self = new (ELeave) CMMFDevSoundCIDemuxPluginImp;
   1.196 +	return self;
   1.197 +	}
   1.198 +
   1.199 +
   1.200 +CMMFDevSoundCIDemuxPluginImp::CMMFDevSoundCIDemuxPluginImp()
   1.201 +	{
   1.202 +	}
   1.203 +
   1.204 +
   1.205 +CMMFDevSoundCIDemuxPluginImp::~CMMFDevSoundCIDemuxPluginImp()
   1.206 +	{
   1.207 +	// Nothing to do in this implementation
   1.208 +	}
   1.209 +
   1.210 +
   1.211 +TInt CMMFDevSoundCIDemuxPluginImp::DoOpenSlaveL(TUid /*aInterface*/, const TDesC8& /*aPackageBuf*/)
   1.212 +	{
   1.213 +	// Nothing to do in this implementation
   1.214 +	return KErrNone;
   1.215 +	}
   1.216 +
   1.217 +
   1.218 +void CMMFDevSoundCIDemuxPluginImp::DoCloseSlaveL(TInt /*aHandle*/)
   1.219 +	{
   1.220 +	// Nothing to do in this implementation
   1.221 +	}
   1.222 +
   1.223 +TInt CMMFDevSoundCIDemuxPluginImp::DoSendSlaveSyncCommandL(const RMmfIpcMessage& aMessage)
   1.224 +	{
   1.225 +	TMMFDevSoundCIMessageData data;
   1.226 +	TInt result = KErrNotSupported;
   1.227 +
   1.228 +	// decode message
   1.229 +	iUtility->GetSyncMessageDataL(aMessage, data);
   1.230 +
   1.231 +	switch (data.iCommand)
   1.232 +		{
   1.233 +		case EMMFDevSoundCIMuxDemuxCauseHeapFail:
   1.234 +			{
   1.235 +			result = KErrNone;
   1.236 +			TPckgBuf<TInt> failCount;				//Create an empty TPckgBuf<INT TYPE> to be empty
   1.237 +			iUtility->ReadFromInputDesL(aMessage, &failCount);  //readFromInputDesL treats this as a descriptor and populates it
   1.238 +			User::__DbgSetAllocFail(RHeap::EUser,RHeap::EFailNext, failCount());
   1.239 +			break;
   1.240 +			}
   1.241 +		case EMMFDevSoundCIMuxDemuxStopHeapFail:
   1.242 +			{
   1.243 +			result = KErrNone;
   1.244 +			User::__DbgSetAllocFail(RHeap::EUser,RHeap::EFailNext,NULL);
   1.245 +			break;
   1.246 +			}
   1.247 +		default:
   1.248 +			{
   1.249 +			User::Leave(KErrNotSupported);
   1.250 +			}
   1.251 +		}
   1.252 +	return result;
   1.253 +	}
   1.254 +
   1.255 +
   1.256 +TInt CMMFDevSoundCIDemuxPluginImp::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)  //This method returns an error to Client Side
   1.257 +	{
   1.258 +	TMMFDevSoundCIMessageData data;
   1.259 +	TInt result = KErrNotSupported;
   1.260 +
   1.261 +	// decode message
   1.262 +	iUtility->GetSyncMessageDataL(aMessage, data); 
   1.263 +
   1.264 +	switch (data.iCommand)
   1.265 +		{
   1.266 +		case EMMFDevSoundCIMuxDemuxCheckHeapFail:
   1.267 +			{
   1.268 +			result = KErrNone;
   1.269 +			TPckgBuf<TBool> failCheck; 
   1.270 +			TAny *testAlloc = User::Alloc(1);	
   1.271 +			if ( testAlloc == NULL )
   1.272 +				{
   1.273 +				failCheck = EFalse;
   1.274 +				User::__DbgSetAllocFail(RHeap::EUser,RHeap::EFailNext,NULL);
   1.275 +				}
   1.276 +			else
   1.277 +				{
   1.278 +				failCheck = ETrue;
   1.279 +				User::Free(testAlloc);	
   1.280 +				}
   1.281 +			iUtility->WriteToOutputDesL(aMessage, failCheck);
   1.282 +			break;
   1.283 +			}
   1.284 +		default:
   1.285 +			{
   1.286 +			User::Leave(KErrNotSupported);
   1.287 +			}
   1.288 +		}
   1.289 +	return result;
   1.290 +	}
   1.291 +
   1.292 +
   1.293 +void CMMFDevSoundCIDemuxPluginImp::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& /*aMessage*/)
   1.294 +	{
   1.295 +	// not used in this interface
   1.296 +	}
   1.297 +
   1.298 +
   1.299 +void CMMFDevSoundCIDemuxPluginImp::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& /*aMessage*/)
   1.300 +	{
   1.301 +	// not used in this interface
   1.302 +	}