os/mm/mmlibs/mmfw/tsrc/mmfunittest/DevSoundTest/CIPlugins/src/MMFDevSoundCIMuxDeMuxPluginImp.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2008-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 //
    15 
    16 #include <ecom/implementationproxy.h>
    17 #include <ecom/ecom.h>
    18 #include <s32mem.h>				
    19 
    20 #include "devsoundciutestdevices.hrh"
    21 #include "MMFDevSoundCIMuxDeMuxPluginImp.h"
    22 
    23 
    24 
    25 // MUX //
    26 
    27 TInt CMMFDevSoundCIMuxPluginImp::OpenInterface(TUid /*aInterfaceId*/)
    28 	{
    29 	// attempt to open the interface link with the
    30 	// remote slave device
    31 	iRemoteHandle = -1;
    32 	TUid slaveId = {KUidMmfDevSoundCustomInterfaceDeMuxPlugin};
    33 
    34 	TInt handle = iUtility->OpenSlave(slaveId, KNullDesC8);
    35 	if (handle >= 0)
    36 		{
    37 		iRemoteHandle = handle;
    38 		}
    39 
    40 	return iRemoteHandle;
    41 	}
    42 
    43 
    44 void CMMFDevSoundCIMuxPluginImp::Release()
    45 	{
    46 	// close the slave device if it exists
    47 	if (iRemoteHandle > 0)
    48 		{
    49 		// we assume the slave is closed correctly
    50 		iUtility->CloseSlave(iRemoteHandle);
    51 		}
    52 
    53 	TUid key = iKey;
    54 	delete this;
    55 
    56 	// tell ECom to destroy us
    57 	REComSession::DestroyedImplementation(key);
    58 	}
    59 
    60 
    61 void CMMFDevSoundCIMuxPluginImp::PassDestructorKey(TUid aDestructorKey)
    62 	{
    63 	// store the destructor key
    64 	iKey = aDestructorKey;
    65 	}
    66 
    67 
    68 void CMMFDevSoundCIMuxPluginImp::CompleteConstructL(MMMFDevSoundCustomInterfaceMuxUtility* aCustomUtility)
    69 	{
    70 	// store a pointer to the the MMFDevSoundCustomMuxUtility class
    71 	iUtility = aCustomUtility;
    72 	}
    73 
    74 
    75 MMMFDevSoundCustomInterfaceMuxPlugin* CMMFDevSoundCIMuxPluginImp::NewL()
    76 	{
    77 	CMMFDevSoundCIMuxPluginImp* self = new (ELeave) CMMFDevSoundCIMuxPluginImp;
    78 	return self;
    79 	}
    80 
    81 
    82 TAny* CMMFDevSoundCIMuxPluginImp::CustomInterface(TUid /*aInterfaceId*/)
    83 	{
    84 	MMMFDevSoundCIMuxPluginInterface* interface = this;
    85 	return interface;
    86 	}
    87 
    88 
    89 CMMFDevSoundCIMuxPluginImp::CMMFDevSoundCIMuxPluginImp()
    90 	{
    91 	}
    92 
    93 
    94 CMMFDevSoundCIMuxPluginImp::~CMMFDevSoundCIMuxPluginImp()
    95 	{
    96 	}
    97 
    98 
    99 TInt CMMFDevSoundCIMuxPluginImp::DevSoundCIMuxStopHeapFail()
   100 	{
   101 	TInt result = -1;
   102 
   103 	if (iRemoteHandle > 0)
   104 		{	
   105 		result = iUtility->SendSlaveSyncCommand(iRemoteHandle,
   106 												EMMFDevSoundCIMuxDemuxStopHeapFail,
   107 												KNullDesC8); 
   108 		}
   109 	return result;
   110 	}
   111 
   112 
   113 TInt CMMFDevSoundCIMuxPluginImp::DevSoundCIMuxCauseHeapFail(TInt aFailCount)
   114 	{
   115 	TInt result = -1;
   116 
   117 	if (iRemoteHandle > 0)
   118 		{
   119 		TPckgBuf<TInt> failCount(aFailCount);  
   120 		result = iUtility->SendSlaveSyncCommand(iRemoteHandle,
   121 												EMMFDevSoundCIMuxDemuxCauseHeapFail,
   122 												failCount);  
   123 		}
   124 	return result;
   125 	}
   126 
   127 TInt CMMFDevSoundCIMuxPluginImp::DevSoundCIMuxCheckHeapFail()
   128 	{
   129 	TInt result = -1;
   130 	TPckgBuf<TInt> responsePckg;
   131 	
   132 	if (iRemoteHandle > 0)
   133 		{
   134 		result = iUtility->SendSlaveSyncCommandResult(iRemoteHandle,
   135 												EMMFDevSoundCIMuxDemuxCheckHeapFail,
   136 												KNullDesC8,
   137 												responsePckg);  
   138 		}
   139 	
   140 	User::LeaveIfError(result);
   141 	return responsePckg();
   142 
   143 	}
   144 
   145 // DEMUX //
   146 
   147 TInt CMMFDevSoundCIDemuxPluginImp::OpenInterface(TUid /*aInterfaceId*/)
   148 	{
   149 	return KErrNone;
   150 	}
   151 
   152 
   153 void CMMFDevSoundCIDemuxPluginImp::Release()
   154 	{
   155 	TUid key = iKey;
   156 
   157 	delete this;
   158 
   159 	// tell ECom to destroy us
   160 	REComSession::DestroyedImplementation(key);
   161 	}
   162 
   163 
   164 void CMMFDevSoundCIDemuxPluginImp::PassDestructorKey(TUid aDestructorKey)
   165 	{
   166 	// store the destructor key
   167 	iKey = aDestructorKey;
   168 	}
   169 
   170 
   171 void CMMFDevSoundCIDemuxPluginImp::SetInterfaceTarget(MMMFDevSoundCustomInterfaceTarget* aTarget)
   172 	{
   173 	iTarget = aTarget;
   174 	}
   175 
   176 
   177 void CMMFDevSoundCIDemuxPluginImp::CompleteConstructL(MMMFDevSoundCustomInterfaceDeMuxUtility* aCustomUtility)
   178 	{
   179 	// store a pointer to the MMFDevSoundCustomDeMuxUtility class
   180 	iUtility = aCustomUtility;
   181 	}
   182 
   183 
   184 void CMMFDevSoundCIDemuxPluginImp::RefreshL()
   185 	{
   186 	// Nothing to do in this implementation
   187 	}
   188 
   189 
   190 MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFDevSoundCIDemuxPluginImp::NewL()
   191 	{
   192 	CMMFDevSoundCIDemuxPluginImp* self = new (ELeave) CMMFDevSoundCIDemuxPluginImp;
   193 	return self;
   194 	}
   195 
   196 
   197 CMMFDevSoundCIDemuxPluginImp::CMMFDevSoundCIDemuxPluginImp()
   198 	{
   199 	}
   200 
   201 
   202 CMMFDevSoundCIDemuxPluginImp::~CMMFDevSoundCIDemuxPluginImp()
   203 	{
   204 	// Nothing to do in this implementation
   205 	}
   206 
   207 
   208 TInt CMMFDevSoundCIDemuxPluginImp::DoOpenSlaveL(TUid /*aInterface*/, const TDesC8& /*aPackageBuf*/)
   209 	{
   210 	// Nothing to do in this implementation
   211 	return KErrNone;
   212 	}
   213 
   214 
   215 void CMMFDevSoundCIDemuxPluginImp::DoCloseSlaveL(TInt /*aHandle*/)
   216 	{
   217 	// Nothing to do in this implementation
   218 	}
   219 
   220 TInt CMMFDevSoundCIDemuxPluginImp::DoSendSlaveSyncCommandL(const RMmfIpcMessage& aMessage)
   221 	{
   222 	TMMFDevSoundCIMessageData data;
   223 	TInt result = KErrNotSupported;
   224 
   225 	// decode message
   226 	iUtility->GetSyncMessageDataL(aMessage, data);
   227 
   228 	switch (data.iCommand)
   229 		{
   230 		case EMMFDevSoundCIMuxDemuxCauseHeapFail:
   231 			{
   232 			result = KErrNone;
   233 			TPckgBuf<TInt> failCount;				//Create an empty TPckgBuf<INT TYPE> to be empty
   234 			iUtility->ReadFromInputDesL(aMessage, &failCount);  //readFromInputDesL treats this as a descriptor and populates it
   235 			User::__DbgSetAllocFail(RHeap::EUser,RHeap::EFailNext, failCount());
   236 			break;
   237 			}
   238 		case EMMFDevSoundCIMuxDemuxStopHeapFail:
   239 			{
   240 			result = KErrNone;
   241 			User::__DbgSetAllocFail(RHeap::EUser,RHeap::EFailNext,NULL);
   242 			break;
   243 			}
   244 		default:
   245 			{
   246 			User::Leave(KErrNotSupported);
   247 			}
   248 		}
   249 	return result;
   250 	}
   251 
   252 
   253 TInt CMMFDevSoundCIDemuxPluginImp::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)  //This method returns an error to Client Side
   254 	{
   255 	TMMFDevSoundCIMessageData data;
   256 	TInt result = KErrNotSupported;
   257 
   258 	// decode message
   259 	iUtility->GetSyncMessageDataL(aMessage, data); 
   260 
   261 	switch (data.iCommand)
   262 		{
   263 		case EMMFDevSoundCIMuxDemuxCheckHeapFail:
   264 			{
   265 			result = KErrNone;
   266 			TPckgBuf<TBool> failCheck; 
   267 			TAny *testAlloc = User::Alloc(1);	
   268 			if ( testAlloc == NULL )
   269 				{
   270 				failCheck = EFalse;
   271 				User::__DbgSetAllocFail(RHeap::EUser,RHeap::EFailNext,NULL);
   272 				}
   273 			else
   274 				{
   275 				failCheck = ETrue;
   276 				User::Free(testAlloc);	
   277 				}
   278 			iUtility->WriteToOutputDesL(aMessage, failCheck);
   279 			break;
   280 			}
   281 		default:
   282 			{
   283 			User::Leave(KErrNotSupported);
   284 			}
   285 		}
   286 	return result;
   287 	}
   288 
   289 
   290 void CMMFDevSoundCIDemuxPluginImp::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& /*aMessage*/)
   291 	{
   292 	// not used in this interface
   293 	}
   294 
   295 
   296 void CMMFDevSoundCIDemuxPluginImp::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& /*aMessage*/)
   297 	{
   298 	// not used in this interface
   299 	}