mmsharing/mmshmanagersrv/src/musmanagerserver.cpp
changeset 15 ccd8e69b5392
parent 2 b31261fd4e04
child 20 e8be2c2e049d
child 22 496ad160a278
equal deleted inserted replaced
2:b31261fd4e04 15:ccd8e69b5392
     1 /*
       
     2 * Copyright (c) 2006 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "musmanagerserver.h"
       
    20 #include "musunittesting.h"
       
    21 #include "muslogger.h"
       
    22 #include "musmanageripccommon.h"
       
    23 #include "musmanagerserverclosetimer.h"
       
    24 #include "musmanagerservercore.h"
       
    25 #include "musmanagerserverplatsecpolicy.h"
       
    26 #include "musmanagerserversession.h"
       
    27 
       
    28 // CONSTANTS
       
    29 const TUint KServerCloseWaitTime = 500; // milliseconds
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CMusManagerServer::NewL
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CMusManagerServer* CMusManagerServer::NewL()
       
    36     {
       
    37     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServer* CMusManagerServer::NewL()" );
       
    38 
       
    39     CMusManagerServer* self = CMusManagerServer::NewLC();
       
    40     CleanupStack::Pop( self );
       
    41     MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServer* CMusManagerServer::NewL()" );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CMusManagerServer::NewLC
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CMusManagerServer* CMusManagerServer::NewLC()
       
    50     {
       
    51     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServer* CMusManagerServer::NewLC()" );
       
    52 
       
    53     CMusManagerServer* self = new( ELeave ) CMusManagerServer( EPriorityHigh );
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL();
       
    56     MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServer* CMusManagerServer::NewLC()" );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CMusManagerServer::CMusManagerServer
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CMusManagerServer::CMusManagerServer ( TInt aPriority )
       
    65     : CPolicyServer( aPriority, KMusManagerServerPlatSecPolicy )
       
    66     {
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CMusManagerServer::ConstructL
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CMusManagerServer::ConstructL()
       
    74     {
       
    75     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServer::ConstructL()" );
       
    76 
       
    77     iActiveScheduler = new( ELeave ) CActiveScheduler ();
       
    78     CActiveScheduler::Install( iActiveScheduler );
       
    79 
       
    80     StartL( KMusManagerServerName );
       
    81 
       
    82     iCloseTimer = CMusManagerServerCloseTimer::NewL();
       
    83 
       
    84     iServerCore = CMusManagerServerCore::NewL( *this );
       
    85     MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServer::ConstructL()" );
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CMusManagerServer::~CMusManagerServer
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CMusManagerServer::~CMusManagerServer()
       
    93     {
       
    94     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServer::~CMusManagerServer()" );
       
    95 
       
    96     delete iCloseTimer;
       
    97 	//iServerCore.StopMonitoring();
       
    98     delete iServerCore;
       
    99 
       
   100     delete iActiveScheduler;
       
   101     CActiveScheduler::Install( NULL );
       
   102     MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServer::~CMusManagerServer()" );
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CMusManagerServer::IncrementSessions
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CMusManagerServer::StopServer()
       
   110     {
       
   111     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServer::StopServer()" );
       
   112     iCloseTimer->StopActiveSchedulerAfter( KServerCloseWaitTime );
       
   113     MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServer::StopServer()" );
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CMusManagerServer::IncrementSessions
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CMusManagerServer::IncrementSessions()
       
   121     {
       
   122     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServer::IncrementSessions()" );
       
   123 
       
   124     iSessionCount++;
       
   125 
       
   126     if ( iCloseTimer->IsActive() )
       
   127         {
       
   128         iCloseTimer->Cancel();
       
   129         }
       
   130     MUS_LOG1( "mus: [MUSSRV]  <- CMusManagerServer::IncrementSessions( %d )",
       
   131               iSessionCount );
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CMusManagerServer::DecrementSessions
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CMusManagerServer::DecrementSessions()
       
   139     {
       
   140     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServer::DecrementSessions()" );
       
   141 
       
   142     iSessionCount--;
       
   143 
       
   144     if( iSessionCount == 0 )
       
   145         {
       
   146         iServerCore->EventNoSessions();
       
   147         }
       
   148     MUS_LOG1( "mus: [MUSSRV]  <- CMusManagerServer::DecrementSessions( %d )",
       
   149               iSessionCount );
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CMusManagerServer::RunError
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 TInt CMusManagerServer::RunError(TInt aError)
       
   157     {
       
   158     MUS_LOG1( "mus: [MUSSRV]     -> CMusManagerServer::RunError( %d )",
       
   159                aError );
       
   160 
       
   161     if ( aError == KErrBadDescriptor )
       
   162         {
       
   163         // A bad descriptor error implies a badly programmed client,
       
   164         // so panic it; otherwise report the error to the client
       
   165         Message().Panic( KMusManagerServer(), EBadDescriptor );
       
   166         }
       
   167     else
       
   168         {
       
   169         Message().Complete( aError );
       
   170         }
       
   171     //
       
   172     // The leave will result in an early return from CServer::RunL(), skipping
       
   173     // the call to request another message. So do that now in order to keep the
       
   174     // server running.
       
   175     ReStart();
       
   176 
       
   177     MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServer::RunError()" );
       
   178     return KErrNone; // handled the error fully
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CMusManagerServer::NewSessionL
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 CSession2* CMusManagerServer::NewSessionL(
       
   186     const TVersion &aVersion,
       
   187     const RMessage2& /*aMessage*/ ) const
       
   188     {
       
   189     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServer::NewSessionL()" );
       
   190 
       
   191     // check we're the right version
       
   192     if ( !User::QueryVersionSupported( TVersion( KMusManagerServerMajorVersionNumber,
       
   193                                                  KMusManagerServerMinorVersionNumber,
       
   194                                                  KMusManagerServerBuildVersionNumber),
       
   195                                                  aVersion ) )
       
   196         {
       
   197         User::Leave( KErrNotSupported );
       
   198         }
       
   199     // make new session
       
   200     CMusManagerServerSession* session = CMusManagerServerSession::NewL(
       
   201                 const_cast<CMusManagerServer&>( *this ),
       
   202                 *iServerCore );
       
   203     MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServer::NewSessionL()" );
       
   204     return session;
       
   205 
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CMusManagerServer::SessionCount
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 TUint CMusManagerServer::SessionCount()
       
   213     {
       
   214     MUS_LOG( "mus: [MUSSRV]  -> CMusManagerServer::SessionCount()" );
       
   215     MUS_LOG( "mus: [MUSSRV]  <- CMusManagerServer::SessionCount()" );
       
   216     return iSessionCount;
       
   217     }