os/mm/mmapitest/devsoundhaitest/src/T_DevSoundServer.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmapitest/devsoundhaitest/src/T_DevSoundServer.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,145 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +#include "t_devsoundserver.h"
    1.24 +#include "t_cmmfdevsounddata.h"
    1.25 +#include "t_crepositorydata.h"
    1.26 +
    1.27 +/*@{*/
    1.28 +/** Object wrappers literals */
    1.29 +_LIT(KT_CMMFDevSound, 	"CMMFDevSound");
    1.30 +_LIT(KT_CRepository,	"CRepository");
    1.31 +_LIT(KApplicationName,"AccServer.exe");
    1.32 +_LIT(KPROCESSNAME, "*AccServer*");
    1.33 +_LIT(KCmdName,"");
    1.34 +/*@}*/
    1.35 +
    1.36 +/**
    1.37 + * 
    1.38 + * Same code for Secure and non-secure variants
    1.39 + * Called inside the MainL() function to create and start the
    1.40 + * CTestServer derived server.
    1.41 + * @return - Instance of the test server
    1.42 + */
    1.43 +CT_DevSoundServer* CT_DevSoundServer::NewL()
    1.44 +	{
    1.45 +    CT_DevSoundServer* server = new (ELeave) CT_DevSoundServer();
    1.46 +    CleanupStack::PushL(server);
    1.47 +    server->ConstructL();
    1.48 +    server->DoCmdutilStartApp();
    1.49 +    CleanupStack::Pop(server);
    1.50 +    return server;
    1.51 +    }
    1.52 +
    1.53 +/**
    1.54 + * Secure variant
    1.55 + * Much simpler, uses the new Rendezvous() call to sync with the client
    1.56 + */
    1.57 +LOCAL_C void MainL()
    1.58 +	{
    1.59 +#if (defined __DATA_CAGING__)
    1.60 +    RProcess().DataCaging(RProcess::EDataCagingOn);
    1.61 +    RProcess().SecureApi(RProcess::ESecureApiOn);
    1.62 +#endif
    1.63 +    CActiveScheduler* sched = NULL;
    1.64 +    sched = new(ELeave) CActiveScheduler;
    1.65 +    CActiveScheduler::Install(sched);
    1.66 +    CT_DevSoundServer* server = NULL;
    1.67 +
    1.68 +    // Create the CTestServer derived server
    1.69 +    TRAPD(err, server = CT_DevSoundServer::NewL());
    1.70 +    if(!err)
    1.71 +	    {
    1.72 +        // Sync with the client and enter the active scheduler
    1.73 +        RProcess::Rendezvous(KErrNone);
    1.74 +        sched->Start();
    1.75 +        }
    1.76 +
    1.77 +    delete server;
    1.78 +    delete sched;
    1.79 +    }
    1.80 +
    1.81 +/**
    1.82 + * 
    1.83 + * Secure variant only
    1.84 + * Process entry point. Called by client using RProcess API
    1.85 + * @return - Standard Epoc error code on process exit
    1.86 + */
    1.87 +GLDEF_C TInt E32Main()
    1.88 +	{
    1.89 +    __UHEAP_MARK;
    1.90 +    CTrapCleanup* cleanup = CTrapCleanup::New();
    1.91 +    if(cleanup == NULL)
    1.92 +	    {
    1.93 +        return KErrNoMemory;
    1.94 +        }
    1.95 +
    1.96 +#if (defined TRAP_IGNORE)
    1.97 +	TRAP_IGNORE(MainL());
    1.98 +#else
    1.99 +    TRAPD(err,MainL());
   1.100 +#endif
   1.101 +
   1.102 +    delete cleanup;
   1.103 +    __UHEAP_MARKEND;
   1.104 +    return KErrNone;
   1.105 +    }
   1.106 +/*
   1.107 + * Creates an instance of CDataWrapper that wraps a CT_CMMFDevSoundData object 
   1.108 + * @return wrapper	- a CDataWrapper instance that wraps the CT_CMMFDevSoundData object
   1.109 + */
   1.110 +CDataWrapper* CT_DevSoundServer::CT_DevSoundBlock::CreateDataL(const TDesC& aData)
   1.111 +	{
   1.112 +	CDataWrapper* wrapper = NULL;
   1.113 +
   1.114 +	if (KT_CMMFDevSound() == aData)
   1.115 +		{
   1.116 +		wrapper = CT_CMMFDevSoundData::NewL();
   1.117 +		}
   1.118 +	else if (KT_CRepository() == aData)
   1.119 +		{
   1.120 +		wrapper = CT_CRepositoryData::NewL();
   1.121 +		}	
   1.122 +	return wrapper;
   1.123 +	}
   1.124 +
   1.125 +/*
   1.126 + * Start the accessories server
   1.127 + * @return err 		Symbian error code. KErrNone if successful
   1.128 + */
   1.129 +void CT_DevSoundServer::DoCmdutilStartApp()
   1.130 +	{
   1.131 +	RProcess process;
   1.132 +	TInt err(KErrNone);
   1.133 +	TFullName processName;
   1.134 +	TFindProcess findProcess(KPROCESSNAME);
   1.135 +	findProcess.Next(processName);
   1.136 +  if (processName != KNullDesC)
   1.137 +    {
   1.138 +    return;
   1.139 +    }
   1.140 +  
   1.141 +	err = process.Create(KApplicationName,KCmdName);
   1.142 +	// start the process running! Don't forget this.
   1.143 +	if (err==KErrNone)
   1.144 +        {
   1.145 +        process.Resume(); //start .exe application
   1.146 +        }
   1.147 +	process.Close(); // Closes the handle, not the process.
   1.148 +	}