os/mm/mmapitest/devsoundhaitest/src/T_DevSoundServer.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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_crepositorydata.h"
    23 
    24 /*@{*/
    25 /** Object wrappers literals */
    26 _LIT(KT_CMMFDevSound, 	"CMMFDevSound");
    27 _LIT(KT_CRepository,	"CRepository");
    28 _LIT(KApplicationName,"AccServer.exe");
    29 _LIT(KPROCESSNAME, "*AccServer*");
    30 _LIT(KCmdName,"");
    31 /*@}*/
    32 
    33 /**
    34  * 
    35  * Same code for Secure and non-secure variants
    36  * Called inside the MainL() function to create and start the
    37  * CTestServer derived server.
    38  * @return - Instance of the test server
    39  */
    40 CT_DevSoundServer* CT_DevSoundServer::NewL()
    41 	{
    42     CT_DevSoundServer* server = new (ELeave) CT_DevSoundServer();
    43     CleanupStack::PushL(server);
    44     server->ConstructL();
    45     server->DoCmdutilStartApp();
    46     CleanupStack::Pop(server);
    47     return server;
    48     }
    49 
    50 /**
    51  * Secure variant
    52  * Much simpler, uses the new Rendezvous() call to sync with the client
    53  */
    54 LOCAL_C void MainL()
    55 	{
    56 #if (defined __DATA_CAGING__)
    57     RProcess().DataCaging(RProcess::EDataCagingOn);
    58     RProcess().SecureApi(RProcess::ESecureApiOn);
    59 #endif
    60     CActiveScheduler* sched = NULL;
    61     sched = new(ELeave) CActiveScheduler;
    62     CActiveScheduler::Install(sched);
    63     CT_DevSoundServer* server = NULL;
    64 
    65     // Create the CTestServer derived server
    66     TRAPD(err, server = CT_DevSoundServer::NewL());
    67     if(!err)
    68 	    {
    69         // Sync with the client and enter the active scheduler
    70         RProcess::Rendezvous(KErrNone);
    71         sched->Start();
    72         }
    73 
    74     delete server;
    75     delete sched;
    76     }
    77 
    78 /**
    79  * 
    80  * Secure variant only
    81  * Process entry point. Called by client using RProcess API
    82  * @return - Standard Epoc error code on process exit
    83  */
    84 GLDEF_C TInt E32Main()
    85 	{
    86     __UHEAP_MARK;
    87     CTrapCleanup* cleanup = CTrapCleanup::New();
    88     if(cleanup == NULL)
    89 	    {
    90         return KErrNoMemory;
    91         }
    92 
    93 #if (defined TRAP_IGNORE)
    94 	TRAP_IGNORE(MainL());
    95 #else
    96     TRAPD(err,MainL());
    97 #endif
    98 
    99     delete cleanup;
   100     __UHEAP_MARKEND;
   101     return KErrNone;
   102     }
   103 /*
   104  * Creates an instance of CDataWrapper that wraps a CT_CMMFDevSoundData object 
   105  * @return wrapper	- a CDataWrapper instance that wraps the CT_CMMFDevSoundData object
   106  */
   107 CDataWrapper* CT_DevSoundServer::CT_DevSoundBlock::CreateDataL(const TDesC& aData)
   108 	{
   109 	CDataWrapper* wrapper = NULL;
   110 
   111 	if (KT_CMMFDevSound() == aData)
   112 		{
   113 		wrapper = CT_CMMFDevSoundData::NewL();
   114 		}
   115 	else if (KT_CRepository() == aData)
   116 		{
   117 		wrapper = CT_CRepositoryData::NewL();
   118 		}	
   119 	return wrapper;
   120 	}
   121 
   122 /*
   123  * Start the accessories server
   124  * @return err 		Symbian error code. KErrNone if successful
   125  */
   126 void CT_DevSoundServer::DoCmdutilStartApp()
   127 	{
   128 	RProcess process;
   129 	TInt err(KErrNone);
   130 	TFullName processName;
   131 	TFindProcess findProcess(KPROCESSNAME);
   132 	findProcess.Next(processName);
   133   if (processName != KNullDesC)
   134     {
   135     return;
   136     }
   137   
   138 	err = process.Create(KApplicationName,KCmdName);
   139 	// start the process running! Don't forget this.
   140 	if (err==KErrNone)
   141         {
   142         process.Resume(); //start .exe application
   143         }
   144 	process.Close(); // Closes the handle, not the process.
   145 	}