devsound/a3fdevsound/src/mmfaudioserver/mmfaudioserver.cpp
changeset 6 fe9d1bf55678
parent 0 b8ed18f6c07b
equal deleted inserted replaced
5:b220a9341636 6:fe9d1bf55678
    30 #include "devsoundsvrthreadpriorityconsts.h"
    30 #include "devsoundsvrthreadpriorityconsts.h"
    31 
    31 
    32 #ifdef _DEBUG
    32 #ifdef _DEBUG
    33 #include "e32debug.h"
    33 #include "e32debug.h"
    34 #define SYMBIAN_DEBPRN0(str)    RDebug::Print(str, this)
    34 #define SYMBIAN_DEBPRN0(str)    RDebug::Print(str, this)
       
    35 #define SYMBIAN_DEBPRN1(str, val1)          RDebug::Print(str, this, val1)
       
    36 #define SYMBIAN_DEBPRN2(str, val1, val2)    RDebug::Print(str, this, val1, val2)
    35 #else
    37 #else
    36 #define SYMBIAN_DEBPRN0(str)
    38 #define SYMBIAN_DEBPRN0(str)
       
    39 #define SYMBIAN_DEBPRN1(str, val1)
       
    40 #define SYMBIAN_DEBPRN2(str, val1, val2)
    37 #endif //_DEBUG
    41 #endif //_DEBUG
    38 
    42 
    39 
    43 
    40 // Time delay that the audio server wait before shutdown itself when is detected that the last DevSoundSession is closed
    44 // Time delay that the audio server wait before shutdown itself when is detected that the last DevSoundSession is closed
    41 const TInt KAudioServerShutDownDelay = 50000000; //50 sec
    45 const TInt KAudioServerShutDownDelay = 50000000; //50 sec
    48 	User::Panic(KAudioServerPanicCategory, aPanicCode);
    52 	User::Panic(KAudioServerPanicCategory, aPanicCode);
    49 	}
    53 	}
    50 
    54 
    51 // ============================ MEMBER FUNCTIONS ===============================
    55 // ============================ MEMBER FUNCTIONS ===============================
    52 
    56 
       
    57 
    53 // -----------------------------------------------------------------------------
    58 // -----------------------------------------------------------------------------
    54 // CMMFAudioServer::NewL
    59 // CMMFAudioServer::NewL
    55 // Two-phased constructor.
    60 // Two-phased constructor.
    56 // -----------------------------------------------------------------------------
    61 // @param aStayOpen whether or not the server should stay open permanently
    57 //
    62 // -----------------------------------------------------------------------------
    58 CMMFAudioServer* CMMFAudioServer::NewL()
    63 //
    59 	{
    64 CMMFAudioServer* CMMFAudioServer::NewL(TBool aStayOpen)
    60 	CMMFAudioServer* self = new(ELeave) CMMFAudioServer();
    65     {
    61 	CleanupStack::PushL(self);
    66     
    62 	self->ConstructL();
    67     CMMFAudioServer* self = new(ELeave) CMMFAudioServer(aStayOpen);
    63 	CleanupStack::Pop(self);
    68     CleanupStack::PushL(self);
    64 	return self;
    69     self->ConstructL();
    65 	}
    70     CleanupStack::Pop(self);
       
    71     return self;
       
    72     }
    66 
    73 
    67 // -----------------------------------------------------------------------------
    74 // -----------------------------------------------------------------------------
    68 // CMMFAudioServer::CMMFAudioServer
    75 // CMMFAudioServer::CMMFAudioServer
    69 // C++ default constructor can NOT contain any code, that
    76 // C++ default constructor can NOT contain any code, that
    70 // might leave.
    77 // might leave.
    71 // -----------------------------------------------------------------------------
    78 // -----------------------------------------------------------------------------
    72 //
    79 //
    73 CMMFAudioServer::CMMFAudioServer()
    80 CMMFAudioServer::CMMFAudioServer(TBool aStayOpen)
    74 	: CMmfIpcServer(EPriorityStandard)
    81 	: CMmfIpcServer(EPriorityStandard), iStayOpen (aStayOpen)
       
    82 
    75 	{
    83 	{
    76 	}
    84 	}
    77 
    85 
    78 // -----------------------------------------------------------------------------
    86 // -----------------------------------------------------------------------------
    79 // CMMFAudioServer::ConstructL
    87 // CMMFAudioServer::ConstructL
    80 // Symbian 2nd phase constructor can leave.
    88 // Symbian 2nd phase constructor can leave.
    81 // -----------------------------------------------------------------------------
    89 // -----------------------------------------------------------------------------
    82 //
    90 //
    83 void CMMFAudioServer::ConstructL()
    91 void CMMFAudioServer::ConstructL()
    84 	{
    92  	{
    85 	SYMBIAN_DEBPRN0(_L("CMMFAudioServer[0x%x]::ConstructL - enter"));
    93 	SYMBIAN_DEBPRN0(_L("CMMFAudioServer[0x%x]::ConstructL - enter"));
    86 
    94 	
    87 	SetPinClientDescriptors(ETrue);
    95 	SetPinClientDescriptors(ETrue);
    88 	// Call base class to Start server
    96 	// Call base class to Start server
    89 	StartL(KAudioServerName);
    97 	StartL(KAudioServerName);
    90 
    98 
    91 	iFourCCConvertor = CFourCCConvertor::NewL();
    99 	iFourCCConvertor = CFourCCConvertor::NewL();
    92 	iDelayAudioServerShutDown = CDelayAudioServerShutDown::NewL();
   100 	
       
   101 	if(!iStayOpen)
       
   102 	    {
       
   103 	    iDelayAudioServerShutDown = CDelayAudioServerShutDown::NewL();
       
   104 	    }
    93 
   105 
    94 	iFactory = CMMFAudioServerFactory::NewL();
   106 	iFactory = CMMFAudioServerFactory::NewL();
    95 	iFactory->StartL(*this);	
   107 	iFactory->StartL(*this);	
    96 
       
    97 	SYMBIAN_DEBPRN0(_L("CMMFAudioServer[0x%x]::ConstructL - exit"));
   108 	SYMBIAN_DEBPRN0(_L("CMMFAudioServer[0x%x]::ConstructL - exit"));
    98 	}
   109 	}
    99 
   110 
   100 // -----------------------------------------------------------------------------
   111 // -----------------------------------------------------------------------------
   101 // CMMFAudioServer::~CMMFAudioServer
   112 // CMMFAudioServer::~CMMFAudioServer
   189 // server, it will cancel its shutdown timer.
   200 // server, it will cancel its shutdown timer.
   190 // -----------------------------------------------------------------------------
   201 // -----------------------------------------------------------------------------
   191 //
   202 //
   192 void CMMFAudioServer::IncrementDevSoundCount()
   203 void CMMFAudioServer::IncrementDevSoundCount()
   193 	{
   204 	{
   194 	iDevSoundCount++;
   205     if(!iStayOpen)
   195 	//in the case we started the shutdown due to no more DevSound
   206         {
   196 	if(iDevSoundCount)
   207         iDevSoundCount++;
   197 		{
   208         //in the case we started the shutdown due to no more DevSound
   198 		ASSERT(iDelayAudioServerShutDown);
   209         if(iDevSoundCount)
   199 		if (iDelayAudioServerShutDown)
   210             {
   200 			{
   211             ASSERT(iDelayAudioServerShutDown);
   201 			iDelayAudioServerShutDown->Cancel();
   212             if (iDelayAudioServerShutDown)
   202 			}
   213                 {
   203 		}
   214                 iDelayAudioServerShutDown->Cancel();
       
   215                 }
       
   216             }
       
   217         }
   204 	}
   218 	}
   205 
   219 
   206 // -----------------------------------------------------------------------------
   220 // -----------------------------------------------------------------------------
   207 // CMMFAudioServer::DecrementDevSoundCount
   221 // CMMFAudioServer::DecrementDevSoundCount
   208 // Decrement the DevSound server counter. Once the number of DevSound server's
   222 // Decrement the DevSound server counter. Once the number of DevSound server's
   209 // instances becomes zero, Audio Server will start its shutdown routine.
   223 // instances becomes zero, Audio Server will start its shutdown routine.
   210 // -----------------------------------------------------------------------------
   224 // -----------------------------------------------------------------------------
   211 //
   225 //
   212 void CMMFAudioServer::DecrementDevSoundCount()
   226 void CMMFAudioServer::DecrementDevSoundCount()
   213 	{
   227 	{
   214 	iDevSoundCount--;
   228 
   215 	if (iDevSoundCount == 0)
   229     if(!iStayOpen)
   216 		{
   230         {
   217 		ASSERT(iDelayAudioServerShutDown);
   231         iDevSoundCount--;
   218 		if (iDelayAudioServerShutDown)
   232         //dont shut down if iStayOpen is set
   219 			{
   233         if (iDevSoundCount == 0)
   220 			iDelayAudioServerShutDown->SetDelay(TTimeIntervalMicroSeconds32(KAudioServerShutDownDelay));
   234             {
   221 			}
   235             
   222 		}
   236             ASSERT(iDelayAudioServerShutDown);
       
   237             if (iDelayAudioServerShutDown)
       
   238                 {
       
   239                 SYMBIAN_DEBPRN0(_L("CMMFAudioServer[0x%x]::DecrementDevSoundCount - shutting down server"));
       
   240                 iDelayAudioServerShutDown->SetDelay(TTimeIntervalMicroSeconds32(KAudioServerShutDownDelay));
       
   241                 }
       
   242             }
       
   243         }
   223 	}
   244 	}
   224 
   245 
   225 // -----------------------------------------------------------------------------
   246 // -----------------------------------------------------------------------------
   226 // CMMFAudioServer::SendEventToClient
   247 // CMMFAudioServer::SendEventToClient
   227 // Sends Event to DevSound client.
   248 // Sends Event to DevSound client.