mmapitest/devsoundexthaitest/src/T_DevSoundServer.cpp
changeset 26 c36d67f77f75
equal deleted inserted replaced
15:c1e808730d6c 26:c36d67f77f75
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "t_devsoundserver.h"
       
    21 #include "t_cmmfdevsounddata.h"
       
    22 #include "t_crestrictedaudiooutputdata.h"
       
    23 #include "t_ctelephonyaudioroutingdata.h"
       
    24 #include "t_caudioinputdata.h"
       
    25 #include "t_caudiooutputdata.h"
       
    26 
       
    27 /*@{*/
       
    28 /** Object wrappers literals */
       
    29 _LIT(KT_CMMFDevSound, 	"CMMFDevSound");
       
    30 _LIT(KT_CRestrictedAudioOutput, "CRestrictedAudioOutput");
       
    31 _LIT(KT_CTelephonyAudioRouting, "CTelephonyAudioRouting");
       
    32 _LIT(KT_CAudioInput, 	"CAudioInput");
       
    33 _LIT(KT_CAudioOutput,	"CAudioOutput");
       
    34 _LIT(KApplicationName,"AccServer.exe");
       
    35 _LIT(KPROCESSNAME, "*AccServer*");
       
    36 _LIT(KCmdName,"");
       
    37 
       
    38 /*@}*/
       
    39 
       
    40 /**
       
    41  * 
       
    42  * Same code for Secure and non-secure variants
       
    43  * Called inside the MainL() function to create and start the
       
    44  * CTestServer derived server.
       
    45  * @return - Instance of the test server
       
    46  */
       
    47 CT_DevSoundServer* CT_DevSoundServer::NewL()
       
    48 	{
       
    49     CT_DevSoundServer* server = new (ELeave) CT_DevSoundServer();
       
    50     CleanupStack::PushL(server);
       
    51     server->ConstructL();
       
    52     server->DoCmdutilStartApp();
       
    53     CleanupStack::Pop(server);
       
    54     return server;
       
    55     }
       
    56 
       
    57 /**
       
    58  * Secure variant
       
    59  * Much simpler, uses the new Rendezvous() call to sync with the client
       
    60  */
       
    61 LOCAL_C void MainL()
       
    62 	{
       
    63 #if (defined __DATA_CAGING__)
       
    64     RProcess().DataCaging(RProcess::EDataCagingOn);
       
    65     RProcess().SecureApi(RProcess::ESecureApiOn);
       
    66 #endif
       
    67     CActiveScheduler* sched = NULL;
       
    68     sched = new(ELeave) CActiveScheduler;
       
    69     CActiveScheduler::Install(sched);
       
    70     CT_DevSoundServer* server = NULL;
       
    71 
       
    72     // Create the CTestServer derived server
       
    73     TRAPD(err, server = CT_DevSoundServer::NewL());
       
    74     if(!err)
       
    75 	    {
       
    76         // Sync with the client and enter the active scheduler
       
    77         RProcess::Rendezvous(KErrNone);
       
    78         sched->Start();
       
    79         }
       
    80 
       
    81     delete server;
       
    82     delete sched;
       
    83     }
       
    84 
       
    85 /**
       
    86  * 
       
    87  * Secure variant only
       
    88  * Process entry point. Called by client using RProcess API
       
    89  * @return - Standard Epoc error code on process exit
       
    90  */
       
    91 GLDEF_C TInt E32Main()
       
    92 	{
       
    93     __UHEAP_MARK;
       
    94     CTrapCleanup* cleanup = CTrapCleanup::New();
       
    95     if(cleanup == NULL)
       
    96 	    {
       
    97         return KErrNoMemory;
       
    98         }
       
    99 
       
   100 #if (defined TRAP_IGNORE)
       
   101 	TRAP_IGNORE(MainL());
       
   102 #else
       
   103     TRAPD(err,MainL());
       
   104 #endif
       
   105 
       
   106     delete cleanup;
       
   107     __UHEAP_MARKEND;
       
   108     return KErrNone;
       
   109     }
       
   110 /*
       
   111  * Creates an instance of CDataWrapper that wraps a CT_CMMFDevSoundData object 
       
   112  * @return wrapper	- a CDataWrapper instance that wraps the CT_CMMFDevSoundData object
       
   113  */
       
   114 CDataWrapper* CT_DevSoundServer::CT_DevSoundBlock::CreateDataL(const TDesC& aData)
       
   115 	{
       
   116 	CDataWrapper* wrapper = NULL;
       
   117 
       
   118 	if (KT_CMMFDevSound() == aData)
       
   119 		{
       
   120 		wrapper = CT_CMMFDevSoundData::NewL();
       
   121 		}	
       
   122 	else if (KT_CRestrictedAudioOutput() == aData)
       
   123 		{
       
   124 		wrapper = CT_CRestrictedAudioOutputData::NewL();
       
   125 		}
       
   126 	else if (KT_CTelephonyAudioRouting() == aData)
       
   127 		{
       
   128 		wrapper = CT_CTelephonyAudioRoutingData::NewL();
       
   129 		}
       
   130 	else if(KT_CAudioInput() == aData)
       
   131 		{
       
   132 		wrapper = CT_CAudioInputData::NewL();
       
   133 		}
       
   134 	else if(KT_CAudioOutput() == aData)
       
   135 		{
       
   136 		wrapper = CT_CAudioOutputData::NewL();
       
   137 		}
       
   138 
       
   139 	return wrapper;
       
   140 	}
       
   141 	
       
   142 	
       
   143 	
       
   144 /*
       
   145  * Start the accessories server
       
   146  * @return err 		Symbian error code. KErrNone if successful
       
   147  */
       
   148 void CT_DevSoundServer::DoCmdutilStartApp()
       
   149 	{
       
   150 	RProcess process;
       
   151 	TInt err(KErrNone);
       
   152 	TFullName processName;
       
   153 	TFindProcess findProcess(KPROCESSNAME);
       
   154 	findProcess.Next(processName);
       
   155   if (processName != KNullDesC)
       
   156     {
       
   157     return;
       
   158     }
       
   159   
       
   160 	err = process.Create(KApplicationName,KCmdName);
       
   161 	// start the process running! Don't forget this.
       
   162 	if (err==KErrNone)
       
   163         {
       
   164         process.Resume(); //start .exe application
       
   165         }
       
   166 	process.Close(); // Closes the handle, not the process.
       
   167 	}