os/mm/devsound/devsoundpluginsupport/src/CustomInterfaces/gettimestampsci.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.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <ecom/implementationproxy.h>
sl@0
    17
#include <ecom/implementationproxy.h>
sl@0
    18
#include <ecom/ecom.h>
sl@0
    19
sl@0
    20
#include "gettimestampsci.h"
sl@0
    21
sl@0
    22
class TPositionTimestamp
sl@0
    23
	{
sl@0
    24
public:
sl@0
    25
	TTimeIntervalMicroSeconds iBufferPosition;
sl@0
    26
	TTime iTimestamp;
sl@0
    27
	};
sl@0
    28
sl@0
    29
// MUX //
sl@0
    30
/*****************************************************************************/
sl@0
    31
sl@0
    32
TInt CMMFGetTimestampsMux::OpenInterface(TUid /*aInterfaceId*/)
sl@0
    33
	{
sl@0
    34
	// attempt to open the interface link with the
sl@0
    35
	// remote slave device
sl@0
    36
	iRemoteHandle = -1;
sl@0
    37
	TUid slaveId = {KMmfUidCustomInterfaceGetTimestampsDeMux};
sl@0
    38
		
sl@0
    39
	TInt handle = iUtility->OpenSlave(slaveId, KNullDesC8);
sl@0
    40
	if (handle >= 0)
sl@0
    41
		{
sl@0
    42
		iRemoteHandle = handle;
sl@0
    43
		}
sl@0
    44
		
sl@0
    45
	return iRemoteHandle;
sl@0
    46
	}
sl@0
    47
sl@0
    48
/*****************************************************************************/
sl@0
    49
void CMMFGetTimestampsMux::Release()
sl@0
    50
	{
sl@0
    51
	// close the slave device if it exists
sl@0
    52
	if (iRemoteHandle > 0)
sl@0
    53
		{
sl@0
    54
		// we assume the slave is closed correctly
sl@0
    55
		iUtility->CloseSlave(iRemoteHandle);
sl@0
    56
		}
sl@0
    57
	
sl@0
    58
	TUid key = iDestructorKey;
sl@0
    59
	delete this;
sl@0
    60
	
sl@0
    61
	// tell ECom to destroy us
sl@0
    62
	REComSession::DestroyedImplementation(key);
sl@0
    63
	}
sl@0
    64
sl@0
    65
/*****************************************************************************/	
sl@0
    66
void CMMFGetTimestampsMux::PassDestructorKey(TUid aDestructorKey)
sl@0
    67
	{
sl@0
    68
	// store the destructor key
sl@0
    69
	iDestructorKey = aDestructorKey;
sl@0
    70
	}
sl@0
    71
sl@0
    72
/*****************************************************************************/
sl@0
    73
void CMMFGetTimestampsMux::CompleteConstructL(MMMFDevSoundCustomInterfaceMuxUtility* aCustomUtility)
sl@0
    74
	{
sl@0
    75
	// store a pointer to the utility
sl@0
    76
	iUtility = aCustomUtility;
sl@0
    77
	}
sl@0
    78
sl@0
    79
/*****************************************************************************/	
sl@0
    80
MMMFDevSoundCustomInterfaceMuxPlugin* CMMFGetTimestampsMux::NewL()
sl@0
    81
	{
sl@0
    82
	CMMFGetTimestampsMux* self = new (ELeave) CMMFGetTimestampsMux;
sl@0
    83
	return self;
sl@0
    84
	}
sl@0
    85
sl@0
    86
/*****************************************************************************/	
sl@0
    87
TAny* CMMFGetTimestampsMux::CustomInterface(TUid /*aInterfaceId*/)
sl@0
    88
	{
sl@0
    89
	MMMFGetTimestamps* interface = this;
sl@0
    90
	return interface;
sl@0
    91
	}
sl@0
    92
	
sl@0
    93
/*****************************************************************************/
sl@0
    94
CMMFGetTimestampsMux::CMMFGetTimestampsMux() :
sl@0
    95
	iRemoteHandle(-1)
sl@0
    96
	{	
sl@0
    97
	}
sl@0
    98
sl@0
    99
/*****************************************************************************/
sl@0
   100
CMMFGetTimestampsMux::~CMMFGetTimestampsMux()
sl@0
   101
	{	
sl@0
   102
	}
sl@0
   103
sl@0
   104
/*****************************************************************************/
sl@0
   105
// from MMMFGetTimestamps
sl@0
   106
TInt CMMFGetTimestampsMux::MmgtSetRecordSystemTimestampsEnabled(TBool aEnable)
sl@0
   107
	{
sl@0
   108
	if (iRemoteHandle > 0)
sl@0
   109
		{
sl@0
   110
		// send the enable flag in the sync command
sl@0
   111
		TPckgBuf<TBool> flag(aEnable);
sl@0
   112
sl@0
   113
		// any return code other than zero is an error
sl@0
   114
		return iUtility->SendSlaveSyncCommand(iRemoteHandle, EMMFDevSoundCIGetTimestampsEnable, flag);
sl@0
   115
		}
sl@0
   116
	else
sl@0
   117
		{
sl@0
   118
		return KErrNotReady;
sl@0
   119
		}
sl@0
   120
	}
sl@0
   121
sl@0
   122
TInt CMMFGetTimestampsMux::MmgtGetSystemTimestampForBuffer(const TTimeIntervalMicroSeconds& aBufferPosition,
sl@0
   123
															TTime& aTimestamp) const
sl@0
   124
	{
sl@0
   125
	TInt err = KErrNotReady;
sl@0
   126
	if (iRemoteHandle > 0)
sl@0
   127
		{
sl@0
   128
		// send the position and timestamp in the sync command
sl@0
   129
		TPositionTimestamp value;
sl@0
   130
		value.iBufferPosition = aBufferPosition;
sl@0
   131
		value.iTimestamp = aTimestamp;
sl@0
   132
		TPckgBuf<TPositionTimestamp> pckgBuffer(value);
sl@0
   133
sl@0
   134
		// any return code other than zero is an error
sl@0
   135
		err = iUtility->SendSlaveSyncCommandResult(iRemoteHandle, EMMFDevSoundCIGetTimestampsForBuffer, 
sl@0
   136
													pckgBuffer, pckgBuffer);
sl@0
   137
		aTimestamp = pckgBuffer().iTimestamp;
sl@0
   138
		}
sl@0
   139
sl@0
   140
	return err;
sl@0
   141
	}
sl@0
   142
sl@0
   143
sl@0
   144
sl@0
   145
// DEMUX //	
sl@0
   146
/*****************************************************************************/
sl@0
   147
TInt CMMFGetTimestampsDeMux::OpenInterface(TUid /*aInterfaceId*/)
sl@0
   148
	{
sl@0
   149
	return KErrNone;
sl@0
   150
	}
sl@0
   151
sl@0
   152
/*****************************************************************************/	
sl@0
   153
void CMMFGetTimestampsDeMux::Release()
sl@0
   154
	{
sl@0
   155
	TUid key = iDestructorKey;
sl@0
   156
	
sl@0
   157
	delete this;
sl@0
   158
	
sl@0
   159
	// tell ECom to destroy us
sl@0
   160
	REComSession::DestroyedImplementation(key);
sl@0
   161
	}
sl@0
   162
	
sl@0
   163
/*****************************************************************************/	
sl@0
   164
void CMMFGetTimestampsDeMux::PassDestructorKey(TUid aDestructorKey)
sl@0
   165
	{
sl@0
   166
	// store the destructor key
sl@0
   167
	iDestructorKey = aDestructorKey;
sl@0
   168
	}
sl@0
   169
	
sl@0
   170
/*****************************************************************************/	
sl@0
   171
void CMMFGetTimestampsDeMux::SetInterfaceTarget(MMMFDevSoundCustomInterfaceTarget* aTarget)
sl@0
   172
	{
sl@0
   173
	iTarget = aTarget;
sl@0
   174
	}
sl@0
   175
sl@0
   176
/*****************************************************************************/	
sl@0
   177
void CMMFGetTimestampsDeMux::CompleteConstructL(MMMFDevSoundCustomInterfaceDeMuxUtility* aCustomUtility)
sl@0
   178
	{
sl@0
   179
	// store a pointer to the utility
sl@0
   180
	iUtility = aCustomUtility;
sl@0
   181
	}
sl@0
   182
sl@0
   183
/*****************************************************************************/
sl@0
   184
void CMMFGetTimestampsDeMux::RefreshL()
sl@0
   185
	{
sl@0
   186
	// refetch the play back status custom interface if we already have a target
sl@0
   187
	if (iTarget)
sl@0
   188
		{
sl@0
   189
		MMMFGetTimestamps* ptr = NULL;
sl@0
   190
sl@0
   191
		ptr = static_cast <MMMFGetTimestamps*> (iTarget->CustomInterface(KUidGetTimestamps));
sl@0
   192
	
sl@0
   193
		if (!ptr)
sl@0
   194
			{
sl@0
   195
			iInterfaceGetTimestamps = NULL;
sl@0
   196
			User::Leave(KErrNotSupported);
sl@0
   197
			}
sl@0
   198
		else
sl@0
   199
			{
sl@0
   200
			iInterfaceGetTimestamps = ptr;
sl@0
   201
			}	
sl@0
   202
		}
sl@0
   203
	}
sl@0
   204
sl@0
   205
/*****************************************************************************/
sl@0
   206
MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFGetTimestampsDeMux::NewL()
sl@0
   207
	{
sl@0
   208
	CMMFGetTimestampsDeMux* self = new (ELeave) CMMFGetTimestampsDeMux;
sl@0
   209
	return self;
sl@0
   210
	}
sl@0
   211
sl@0
   212
/*****************************************************************************/	
sl@0
   213
CMMFGetTimestampsDeMux::CMMFGetTimestampsDeMux()
sl@0
   214
	{	
sl@0
   215
	}
sl@0
   216
sl@0
   217
/*****************************************************************************/
sl@0
   218
CMMFGetTimestampsDeMux::~CMMFGetTimestampsDeMux()
sl@0
   219
	{
sl@0
   220
	}
sl@0
   221
sl@0
   222
/*****************************************************************************/
sl@0
   223
TInt CMMFGetTimestampsDeMux::DoOpenSlaveL(TUid /*aInterface*/, const TDesC8& /*aPackageBuf*/)
sl@0
   224
	{
sl@0
   225
	// fetch the Playback status Hw Device custom interface
sl@0
   226
	MMMFGetTimestamps* ptr = NULL;
sl@0
   227
sl@0
   228
	ptr = static_cast<MMMFGetTimestamps*> (iTarget->CustomInterface(KUidGetTimestamps)); 
sl@0
   229
	
sl@0
   230
	if (!ptr)
sl@0
   231
		{
sl@0
   232
		iInterfaceGetTimestamps = NULL;
sl@0
   233
		User::Leave(KErrNotSupported);
sl@0
   234
		}
sl@0
   235
	else
sl@0
   236
		{
sl@0
   237
		iInterfaceGetTimestamps = ptr;
sl@0
   238
		}
sl@0
   239
	return KErrNone;
sl@0
   240
	}
sl@0
   241
	
sl@0
   242
/*****************************************************************************/	
sl@0
   243
void CMMFGetTimestampsDeMux::DoCloseSlaveL(TInt /*aHandle*/)
sl@0
   244
	{
sl@0
   245
	// nothing to do
sl@0
   246
	}
sl@0
   247
sl@0
   248
/*****************************************************************************/
sl@0
   249
// original RMessage is supplied so that remote demux plugin can extract necessary details
sl@0
   250
// using DeMux utility
sl@0
   251
TInt CMMFGetTimestampsDeMux::DoSendSlaveSyncCommandL(const RMmfIpcMessage& aMessage)
sl@0
   252
	{
sl@0
   253
	TMMFDevSoundCIMessageData data;
sl@0
   254
sl@0
   255
	TInt retVal = KErrNone;
sl@0
   256
	
sl@0
   257
	// decode message
sl@0
   258
	iUtility->GetSyncMessageDataL(aMessage, data);
sl@0
   259
	
sl@0
   260
	switch (data.iCommand)
sl@0
   261
		{
sl@0
   262
		case EMMFDevSoundCIGetTimestampsEnable:
sl@0
   263
			{
sl@0
   264
			TPckgBuf<TBool> flag; 
sl@0
   265
			iUtility->ReadFromInputDesL(aMessage, &flag);
sl@0
   266
			retVal = DoMmgtSetRecordSystemTimestampsEnabled(flag());
sl@0
   267
			break;
sl@0
   268
			}
sl@0
   269
		default:
sl@0
   270
			{
sl@0
   271
			User::Leave(KErrNotSupported);
sl@0
   272
			}
sl@0
   273
		}
sl@0
   274
	return retVal;
sl@0
   275
	}
sl@0
   276
	
sl@0
   277
/*****************************************************************************/	
sl@0
   278
TInt CMMFGetTimestampsDeMux::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)
sl@0
   279
	{
sl@0
   280
	TMMFDevSoundCIMessageData data;
sl@0
   281
sl@0
   282
	TInt retVal = KErrNone;
sl@0
   283
	
sl@0
   284
	// decode message
sl@0
   285
	iUtility->GetSyncMessageDataL(aMessage, data);
sl@0
   286
	
sl@0
   287
	switch (data.iCommand)
sl@0
   288
		{
sl@0
   289
		case EMMFDevSoundCIGetTimestampsForBuffer:
sl@0
   290
			{
sl@0
   291
			TPckgBuf<TPositionTimestamp> value; 
sl@0
   292
			iUtility->ReadFromInputDesL(aMessage, &value);
sl@0
   293
			retVal = DoMmgtGetSystemTimestampForBuffer(value().iBufferPosition, value().iTimestamp);
sl@0
   294
			iUtility->WriteToOutputDesL(aMessage, value);
sl@0
   295
			break;
sl@0
   296
			}
sl@0
   297
		default:
sl@0
   298
			{
sl@0
   299
			User::Leave(KErrNotSupported);
sl@0
   300
			}
sl@0
   301
		}
sl@0
   302
	return retVal;
sl@0
   303
	}
sl@0
   304
	
sl@0
   305
/*****************************************************************************/	
sl@0
   306
void CMMFGetTimestampsDeMux::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& /*aMessage*/)
sl@0
   307
	{
sl@0
   308
	// not used in this interface
sl@0
   309
	}
sl@0
   310
	
sl@0
   311
/*****************************************************************************/	
sl@0
   312
void CMMFGetTimestampsDeMux::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& /*aMessage*/)
sl@0
   313
	{
sl@0
   314
	// not used in this interface
sl@0
   315
	}
sl@0
   316
sl@0
   317
/*****************************************************************************/
sl@0
   318
// Get Timestamp custom interface implementation
sl@0
   319
TInt CMMFGetTimestampsDeMux::DoMmgtSetRecordSystemTimestampsEnabled(TBool aEnable)
sl@0
   320
	{
sl@0
   321
	if (!iInterfaceGetTimestamps)
sl@0
   322
		{
sl@0
   323
		return KErrNotReady;
sl@0
   324
		}
sl@0
   325
	else
sl@0
   326
		{
sl@0
   327
		return iInterfaceGetTimestamps->MmgtSetRecordSystemTimestampsEnabled(aEnable);
sl@0
   328
		}	
sl@0
   329
	}
sl@0
   330
		
sl@0
   331
TInt CMMFGetTimestampsDeMux::DoMmgtGetSystemTimestampForBuffer(const TTimeIntervalMicroSeconds& aBufferPosition,
sl@0
   332
																TTime& aTimestamp)
sl@0
   333
	{
sl@0
   334
	if (!iInterfaceGetTimestamps)
sl@0
   335
		{
sl@0
   336
		return KErrNotReady;
sl@0
   337
		}
sl@0
   338
	else
sl@0
   339
		{
sl@0
   340
		return iInterfaceGetTimestamps->MmgtGetSystemTimestampForBuffer(aBufferPosition, aTimestamp);
sl@0
   341
		}
sl@0
   342
	}
sl@0
   343
/*****************************************************************************/
sl@0
   344
//
sl@0
   345
// ImplementationTable
sl@0
   346
//
sl@0
   347
sl@0
   348
const TImplementationProxy ImplementationTable[] = 
sl@0
   349
	{
sl@0
   350
	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceGetTimestampsMux, CMMFGetTimestampsMux::NewL),
sl@0
   351
	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceGetTimestampsDeMux, CMMFGetTimestampsDeMux::NewL),
sl@0
   352
	};
sl@0
   353
sl@0
   354
/*****************************************************************************/
sl@0
   355
//
sl@0
   356
// ImplementationGroupProxy
sl@0
   357
//
sl@0
   358
//
sl@0
   359
sl@0
   360
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
sl@0
   361
	{
sl@0
   362
	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
sl@0
   363
sl@0
   364
	return ImplementationTable;
sl@0
   365
	}
sl@0
   366
sl@0
   367