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