devsound/devsoundpluginsupport/src/CustomInterfaces/errorconcealmentci.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     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 //
       
    15 
       
    16 #include <ecom/implementationproxy.h>
       
    17 #include <ecom/implementationproxy.h>
       
    18 #include <ecom/ecom.h>
       
    19 #include <s32mem.h>
       
    20 
       
    21 #include "errorconcealmentci.h"
       
    22 
       
    23 
       
    24 // MUX //
       
    25 
       
    26 TInt CMMFErrorConcealmentIntfcMux::OpenInterface(TUid /*aInterfaceId*/)
       
    27 	{
       
    28 	// attempt to open the interface link with the
       
    29 	// remote slave device
       
    30 	iRemoteHandle = -1;
       
    31 	TUid slaveId = {KMmfUidCustomInterfaceErrorConcealmentIntfcDeMux};
       
    32 
       
    33 	TInt handle = iUtility->OpenSlave(slaveId, KNullDesC8);
       
    34 	if (handle >= 0)
       
    35 		{
       
    36 		iRemoteHandle = handle;
       
    37 		}
       
    38 
       
    39 	return iRemoteHandle;
       
    40 	}
       
    41 
       
    42 
       
    43 void CMMFErrorConcealmentIntfcMux::Release()
       
    44 	{
       
    45 	// close the slave device if it exists
       
    46 	if (iRemoteHandle > 0)
       
    47 		{
       
    48 		// we assume the slave is closed correctly
       
    49 		iUtility->CloseSlave(iRemoteHandle);
       
    50 		}
       
    51 
       
    52 	TUid key = iKey;
       
    53 	delete this;
       
    54 
       
    55 	// tell ECom to destroy us
       
    56 	REComSession::DestroyedImplementation(key);
       
    57 	}
       
    58 
       
    59 
       
    60 void CMMFErrorConcealmentIntfcMux::PassDestructorKey(TUid aDestructorKey)
       
    61 	{
       
    62 	// store the destructor key
       
    63 	iKey = aDestructorKey;
       
    64 	}
       
    65 
       
    66 
       
    67 void CMMFErrorConcealmentIntfcMux::CompleteConstructL(MMMFDevSoundCustomInterfaceMuxUtility* aCustomUtility)
       
    68 	{
       
    69 	// store a pointer to the utility
       
    70 	iUtility = aCustomUtility;
       
    71 	}
       
    72 
       
    73 
       
    74 MMMFDevSoundCustomInterfaceMuxPlugin* CMMFErrorConcealmentIntfcMux::NewL()
       
    75 	{
       
    76 	CMMFErrorConcealmentIntfcMux* self = new (ELeave) CMMFErrorConcealmentIntfcMux;
       
    77 	return self;
       
    78 	}
       
    79 
       
    80 
       
    81 TAny* CMMFErrorConcealmentIntfcMux::CustomInterface(TUid /*aInterfaceId*/)
       
    82 	{
       
    83 	MMMFErrorConcealmentIntfc* interface = this;
       
    84 	return interface;
       
    85 	}
       
    86 
       
    87 
       
    88 CMMFErrorConcealmentIntfcMux::CMMFErrorConcealmentIntfcMux() :
       
    89 	iRemoteHandle(-1)
       
    90 	{
       
    91 	}
       
    92 
       
    93 
       
    94 CMMFErrorConcealmentIntfcMux::~CMMFErrorConcealmentIntfcMux()
       
    95 	{
       
    96 	}
       
    97 
       
    98 
       
    99 // from MErrorConcealmentIntfc
       
   100 TInt CMMFErrorConcealmentIntfcMux::ConcealErrorForNextBuffer()
       
   101 	{
       
   102 	TInt result = KErrBadHandle;
       
   103 
       
   104 	if (iRemoteHandle > 0)
       
   105 		{
       
   106 		// any return code other than zero is an error
       
   107 		result = iUtility->SendSlaveSyncCommand(iRemoteHandle,
       
   108 												EMMFDevSoundCIErrorConcealmentIntfcConcealErrorForNextBuffer,
       
   109 												KNullDesC8);
       
   110 		}
       
   111 
       
   112 	return result;
       
   113 	}
       
   114 
       
   115 
       
   116 // from MErrorConcealmentIntfc
       
   117 TInt CMMFErrorConcealmentIntfcMux::SetFrameMode(TBool aFrameModeOn)
       
   118 	{
       
   119 	TInt result = KErrBadHandle;
       
   120 
       
   121 	if (iRemoteHandle > 0)
       
   122 		{
       
   123 		// send the cng in the sync command
       
   124 		TPckgBuf<TBool> frameModeOn(aFrameModeOn);
       
   125 
       
   126 		// any return code other than zero is an error
       
   127 		result = iUtility->SendSlaveSyncCommand(iRemoteHandle,
       
   128 												EMMFDevSoundCIErrorConcealmentIntfcSetFrameMode,
       
   129 												frameModeOn);
       
   130 		}
       
   131 
       
   132 	return result;
       
   133 	}
       
   134 
       
   135 
       
   136 // from MErrorConcealmentIntfc
       
   137 TInt CMMFErrorConcealmentIntfcMux::FrameModeRqrdForEC(TBool& aFrameModeRqrd)
       
   138 	{
       
   139 	TInt result = KErrBadHandle;
       
   140 
       
   141 	if (iRemoteHandle > 0)
       
   142 		{
       
   143 		// holds the returned value.
       
   144 		TPckgBuf<TBool> retFrameModeRqrd;
       
   145 
       
   146 		// any return code other than zero is an error
       
   147 		result = iUtility->SendSlaveSyncCommandResult(iRemoteHandle,
       
   148 													  EMMFDevSoundCIErrorConcealmentIntfcFrameModeRqrdForEC,
       
   149 													  KNullDesC8,
       
   150 													  retFrameModeRqrd);
       
   151 
       
   152 		// assign return values to aFrameModeRqrd. Do nothing if there is an error
       
   153 		if(result == KErrNone)
       
   154 			{
       
   155 			aFrameModeRqrd = retFrameModeRqrd();
       
   156 			}
       
   157 		}
       
   158 
       
   159 	return result;
       
   160 	}
       
   161 
       
   162 
       
   163 
       
   164 // DEMUX //	
       
   165 
       
   166 TInt CMMFErrorConcealmentIntfcDeMux::OpenInterface(TUid /*aInterfaceId*/)
       
   167 	{
       
   168 	return KErrNone;
       
   169 	}
       
   170 
       
   171 
       
   172 void CMMFErrorConcealmentIntfcDeMux::Release()
       
   173 	{
       
   174 	TUid key = iKey;
       
   175 
       
   176 	delete this;
       
   177 
       
   178 	// tell ECom to destroy us
       
   179 	REComSession::DestroyedImplementation(key);
       
   180 	}
       
   181 
       
   182 
       
   183 void CMMFErrorConcealmentIntfcDeMux::PassDestructorKey(TUid aDestructorKey)
       
   184 	{
       
   185 	// store the destructor key
       
   186 	iKey = aDestructorKey;
       
   187 	}
       
   188 
       
   189 
       
   190 void CMMFErrorConcealmentIntfcDeMux::SetInterfaceTarget(MMMFDevSoundCustomInterfaceTarget* aTarget)
       
   191 	{
       
   192 	iTarget = aTarget;
       
   193 	}
       
   194 
       
   195 
       
   196 void CMMFErrorConcealmentIntfcDeMux::CompleteConstructL(MMMFDevSoundCustomInterfaceDeMuxUtility* aCustomUtility)
       
   197 	{
       
   198 	// store a pointer to the utility
       
   199 	iUtility = aCustomUtility;
       
   200 	}
       
   201 
       
   202 
       
   203 void CMMFErrorConcealmentIntfcDeMux::RefreshL()
       
   204 	{
       
   205 	// refetch the Error Concealment intfc custom interface if we already have a target
       
   206 	if (iTarget)
       
   207 		{
       
   208 		iInterfaceErrorConcealmentIntfc = static_cast <MMMFErrorConcealmentIntfc*> (iTarget->CustomInterface(KUidErrorConcealmentIntfc));
       
   209 
       
   210 		if (!iInterfaceErrorConcealmentIntfc)
       
   211 			{
       
   212 			iInterfaceErrorConcealmentIntfc = NULL;
       
   213 			User::Leave(KErrNotSupported);
       
   214 			}
       
   215 		}
       
   216 	}
       
   217 
       
   218 
       
   219 MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFErrorConcealmentIntfcDeMux::NewL()
       
   220 	{
       
   221 	CMMFErrorConcealmentIntfcDeMux* self = new (ELeave) CMMFErrorConcealmentIntfcDeMux;
       
   222 	return self;
       
   223 	}
       
   224 
       
   225 
       
   226 CMMFErrorConcealmentIntfcDeMux::CMMFErrorConcealmentIntfcDeMux()
       
   227 	{
       
   228 	}
       
   229 
       
   230 
       
   231 CMMFErrorConcealmentIntfcDeMux::~CMMFErrorConcealmentIntfcDeMux()
       
   232 	{
       
   233 	}
       
   234 
       
   235 
       
   236 TInt CMMFErrorConcealmentIntfcDeMux::DoOpenSlaveL(TUid /*aInterface*/, const TDesC8& /*aPackageBuf*/)
       
   237 	{
       
   238 	// fetch the Error Concealment intfc Hw Device custom interface
       
   239 	iInterfaceErrorConcealmentIntfc = static_cast<MMMFErrorConcealmentIntfc*> (iTarget->CustomInterface(KUidErrorConcealmentIntfc)); 
       
   240 
       
   241 	if (!iInterfaceErrorConcealmentIntfc)
       
   242 		{
       
   243 		iInterfaceErrorConcealmentIntfc = NULL;
       
   244 		User::Leave(KErrNotSupported);
       
   245 		}
       
   246 
       
   247 	return KErrNone;
       
   248 	}
       
   249 
       
   250 
       
   251 void CMMFErrorConcealmentIntfcDeMux::DoCloseSlaveL(TInt /*aHandle*/)
       
   252 	{
       
   253 	// nothing to do
       
   254 	}
       
   255 
       
   256 
       
   257 // original RMessage is supplied so that remote demux plugin can extract necessary details
       
   258 // using DeMux utility
       
   259 TInt CMMFErrorConcealmentIntfcDeMux::DoSendSlaveSyncCommandL(const RMmfIpcMessage& aMessage)
       
   260 	{
       
   261 	TMMFDevSoundCIMessageData data;
       
   262 	TInt result = KErrGeneral;
       
   263 
       
   264 	// decode message
       
   265 	iUtility->GetSyncMessageDataL(aMessage, data);
       
   266 
       
   267 	switch (data.iCommand)
       
   268 		{
       
   269 		case EMMFDevSoundCIErrorConcealmentIntfcConcealErrorForNextBuffer:
       
   270 			{
       
   271 			result = DoConcealErrorForNextBufferL();
       
   272 
       
   273 			break;
       
   274 			}
       
   275 		case EMMFDevSoundCIErrorConcealmentIntfcSetFrameMode:
       
   276 			{
       
   277 			TPckgBuf<TBool> frameModeOn; 
       
   278 			iUtility->ReadFromInputDesL(aMessage, &frameModeOn);
       
   279 			
       
   280 			result = DoSetFrameModeL(frameModeOn());
       
   281 
       
   282 			break;
       
   283 			}
       
   284 		default:
       
   285 			{
       
   286 			User::Leave(KErrNotSupported);
       
   287 			}
       
   288 		}
       
   289 
       
   290 	return result;
       
   291 	}
       
   292 
       
   293 
       
   294 // original RMessage is supplied so that remote demux plugin can extract necessary details
       
   295 // using DeMux utility
       
   296 TInt CMMFErrorConcealmentIntfcDeMux::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)
       
   297 	{
       
   298 	TMMFDevSoundCIMessageData data;
       
   299 	TInt result = KErrGeneral;
       
   300 
       
   301 	// decode message
       
   302 	iUtility->GetSyncMessageDataL(aMessage, data);
       
   303 
       
   304 	switch (data.iCommand)
       
   305 		{
       
   306 		case EMMFDevSoundCIErrorConcealmentIntfcFrameModeRqrdForEC:
       
   307 			{
       
   308 			TPckgBuf<TBool> frameModeRqrd; 
       
   309 
       
   310 			iUtility->ReadFromInputDesL(aMessage, &frameModeRqrd);
       
   311 
       
   312 			result = DoFrameModeRqrdForECL(frameModeRqrd());
       
   313 
       
   314 			TPckgBuf<TBool> des(frameModeRqrd());
       
   315 			iUtility->WriteToOutputDesL(aMessage, des);
       
   316 
       
   317 			break;
       
   318 			}
       
   319 		default:
       
   320 			{
       
   321 			User::Leave(KErrNotSupported);
       
   322 			}
       
   323 		}
       
   324 
       
   325 	return result;
       
   326 	}
       
   327 
       
   328 
       
   329 void CMMFErrorConcealmentIntfcDeMux::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& /*aMessage*/)
       
   330 	{
       
   331 	// not used in this interface
       
   332 	}
       
   333 
       
   334 
       
   335 void CMMFErrorConcealmentIntfcDeMux::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& /*aMessage*/)
       
   336 	{
       
   337 	// not used in this interface
       
   338 	}
       
   339 
       
   340 
       
   341 // Error Concealment intfc custom interface implementation
       
   342 TInt CMMFErrorConcealmentIntfcDeMux::DoConcealErrorForNextBufferL()
       
   343 	{
       
   344 	TInt result = KErrNotFound;
       
   345 
       
   346 	if (iInterfaceErrorConcealmentIntfc)
       
   347 		{
       
   348 		result = iInterfaceErrorConcealmentIntfc->ConcealErrorForNextBuffer();
       
   349 		}
       
   350 
       
   351 	return result;
       
   352 	}
       
   353 
       
   354 
       
   355 // Error Concealment intfc custom interface implementation
       
   356 TInt CMMFErrorConcealmentIntfcDeMux::DoSetFrameModeL(TBool aFrameModeRqrd)
       
   357 	{
       
   358 	TInt result = KErrNotFound;
       
   359 
       
   360 	if (iInterfaceErrorConcealmentIntfc)
       
   361 		{
       
   362 		result = iInterfaceErrorConcealmentIntfc->SetFrameMode(aFrameModeRqrd);
       
   363 		}
       
   364 		
       
   365 	return result;
       
   366 	}
       
   367 
       
   368 
       
   369 // Error Concealment intfc custom interface implementation
       
   370 TInt CMMFErrorConcealmentIntfcDeMux::DoFrameModeRqrdForECL(TBool& aFrameModeRqrd)
       
   371 	{
       
   372 	TInt result = KErrNotFound;
       
   373 
       
   374 	if (iInterfaceErrorConcealmentIntfc)
       
   375 		{
       
   376 		result = iInterfaceErrorConcealmentIntfc->FrameModeRqrdForEC(aFrameModeRqrd);
       
   377 		}
       
   378 
       
   379 	return result;
       
   380 	}
       
   381 
       
   382 
       
   383 //
       
   384 // ImplementationTable
       
   385 //
       
   386 const TImplementationProxy ImplementationTable[] = 
       
   387 	{
       
   388 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceErrorConcealmentIntfcMux,		CMMFErrorConcealmentIntfcMux::NewL),
       
   389 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceErrorConcealmentIntfcDeMux,	CMMFErrorConcealmentIntfcDeMux::NewL),
       
   390 	};
       
   391 
       
   392 //
       
   393 // ImplementationGroupProxy
       
   394 //
       
   395 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   396 	{
       
   397 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   398 
       
   399 	return ImplementationTable;
       
   400 	}
       
   401