os/mm/devsound/sounddevbt/PlatSec/src/Client/MmfBtAudioServerProxy.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-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 <f32file.h>
sl@0
    17
#include <e32math.h>
sl@0
    18
#include <s32mem.h>
sl@0
    19
sl@0
    20
#include "MmfBtAudioServerProxy.h"
sl@0
    21
#include "MmfBtAudioServerStart.h"
sl@0
    22
#include "../../../inc/common/mmfBtBase.hrh"
sl@0
    23
#include "MmfBtAudioClientServer.h"
sl@0
    24
sl@0
    25
#define KMaxServerNameLength 256
sl@0
    26
sl@0
    27
static const TUid KUidAudioServer = {KUidMmfBtAudioServerDllUnicodeDefine};
sl@0
    28
sl@0
    29
sl@0
    30
EXPORT_C TInt RMMFAudioServerProxy::Open()
sl@0
    31
	{
sl@0
    32
sl@0
    33
	const TUidType serverUid(KNullUid,KNullUid,KUidAudioServer);
sl@0
    34
		
sl@0
    35
	// Assume the server is already running and attempt to create a session
sl@0
    36
	// 4 message slots
sl@0
    37
	TInt err = CreateSession(KAudioServerName, TVersion(KMMFAudioServerVersion,
sl@0
    38
														KMMFAudioServerMinorVersionNumber,
sl@0
    39
														KMMFAudioServerBuildVersionNumber));
sl@0
    40
	if(err == KErrNotFound)
sl@0
    41
		{
sl@0
    42
		// Server not running
sl@0
    43
		// Construct the server binary name
sl@0
    44
		TBuf<KMaxServerNameLength> serverFile;
sl@0
    45
		RProcess server;
sl@0
    46
sl@0
    47
		_LIT(KEmpty,"");
sl@0
    48
sl@0
    49
		err = server.Create(KAudioServerFileName, KEmpty, serverUid);
sl@0
    50
		if(err != KErrNone)
sl@0
    51
			return err;
sl@0
    52
		// Synchronise with the server
sl@0
    53
		TRequestStatus reqStatus;
sl@0
    54
		server.Rendezvous(reqStatus);
sl@0
    55
		
sl@0
    56
		if (reqStatus!=KRequestPending)
sl@0
    57
			{
sl@0
    58
			server.Kill(0);
sl@0
    59
			}
sl@0
    60
		else
sl@0
    61
			{
sl@0
    62
			// Start the test harness
sl@0
    63
			server.Resume();
sl@0
    64
			// Server will call the reciprocal static synchronise call
sl@0
    65
			}
sl@0
    66
		User::WaitForRequest(reqStatus); // wait for rendezvous or death
sl@0
    67
		server.Close();
sl@0
    68
		if(reqStatus.Int() != KErrNone)
sl@0
    69
			return reqStatus.Int();
sl@0
    70
		
sl@0
    71
		// Create the root server session
sl@0
    72
		err = CreateSession(KAudioServerName, TVersion(KMMFAudioServerVersion,
sl@0
    73
														KMMFAudioServerMinorVersionNumber,
sl@0
    74
														KMMFAudioServerBuildVersionNumber));
sl@0
    75
		}
sl@0
    76
	return err;		
sl@0
    77
		
sl@0
    78
	}
sl@0
    79
sl@0
    80
EXPORT_C TInt RMMFAudioServerProxy::SetDevSoundInfo()
sl@0
    81
	{
sl@0
    82
	return SendReceive(EMMFAudioLaunchRequests);
sl@0
    83
	}
sl@0
    84
sl@0
    85
EXPORT_C HBufC* RMMFAudioServerProxy::GetDevSoundServerNameL()
sl@0
    86
	{
sl@0
    87
	TInt len = GetDevSoundServerNameLengthL();
sl@0
    88
	len++;
sl@0
    89
	HBufC8* devSoundServerName = HBufC8::NewLC(len);
sl@0
    90
	TPtr8 devSoundServerNamePtr = devSoundServerName->Des();
sl@0
    91
	User::LeaveIfError(SendReceiveResult(EMMFDevSoundServerName,
sl@0
    92
					                     KNullDesC8,
sl@0
    93
					                     KNullDesC8,
sl@0
    94
					                     devSoundServerNamePtr));
sl@0
    95
sl@0
    96
	RDesReadStream stream;
sl@0
    97
	stream.Open(*devSoundServerName);
sl@0
    98
	CleanupClosePushL(stream);
sl@0
    99
sl@0
   100
	HBufC* devSoundServerNameFlat = HBufC::NewL(stream, KMaxTInt);
sl@0
   101
	
sl@0
   102
	CleanupStack::PopAndDestroy();//stream
sl@0
   103
	CleanupStack::PopAndDestroy(devSoundServerName);
sl@0
   104
sl@0
   105
	return devSoundServerNameFlat;
sl@0
   106
	}
sl@0
   107
sl@0
   108
sl@0
   109
TInt RMMFAudioServerProxy::GetDevSoundServerNameLengthL()
sl@0
   110
	{
sl@0
   111
	TPckgBuf<TInt> descriptorSizePckg;
sl@0
   112
	User::LeaveIfError(SendReceiveResult(EMMFDevSoundServerNameLength,
sl@0
   113
					                     KNullDesC8,
sl@0
   114
					                     KNullDesC8,
sl@0
   115
					                     descriptorSizePckg));
sl@0
   116
sl@0
   117
	return descriptorSizePckg();
sl@0
   118
	}
sl@0
   119
sl@0
   120