menucontentsrv/srvsrc/menusrv.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 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 // INCLUDE FILES
       
    19 
       
    20 #include "menusrv.h"
       
    21 #include "menusrvdef.h"
       
    22 #include "menusrvsession.h"
       
    23 #include "timeout.h"
       
    24 #include "menumsg.h"
       
    25 #include "menuutil.h"
       
    26 #include "menusrveng.h"
       
    27 
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // Custom check is applied to all IPCs. As IPC ids contain not only the ids
       
    32 // but other information is embadded into them.
       
    33     
       
    34 LOCAL_D const TInt KRangeCount = 1;
       
    35 
       
    36 LOCAL_D const TInt KSecurityRanges[KRangeCount] = 
       
    37     {
       
    38     EMenuNullFunction,
       
    39     };
       
    40     
       
    41 LOCAL_D const TUint8 SecurityRangesPolicy[KRangeCount] =
       
    42     {
       
    43     CPolicyServer::ECustomCheck
       
    44     };
       
    45 
       
    46 LOCAL_D const CPolicyServer::TPolicy KPolicy =
       
    47     {
       
    48     CPolicyServer::EAlwaysPass,
       
    49     KRangeCount,
       
    50     KSecurityRanges,
       
    51     SecurityRangesPolicy,
       
    52     NULL,
       
    53     };
       
    54 
       
    55 // ==================== LOCAL FUNCTIONS ====================
       
    56 
       
    57 /**
       
    58 * Stop the Active Scheduler.
       
    59 * @param aPtr Not used.
       
    60 * @return KErrNone.
       
    61 */
       
    62 LOCAL_C TInt StopScheduler( TAny* /*aPtr*/ )
       
    63     {
       
    64     // Called by the exit timer, after all clients disconnected (plus a small
       
    65     // delay). Stop the scheduler, this will enable he thread exit.
       
    66     CActiveScheduler::Stop();
       
    67     return KErrNone;
       
    68     }
       
    69 
       
    70 /**
       
    71 * Create a server.
       
    72 * @param Pointer to created server (if created) returned here.
       
    73 * @return Error code.
       
    74 */
       
    75 LOCAL_C TInt CreateServer( CMenuSrv*& aServer )
       
    76     {
       
    77     // The TRAP is not working in the same stack frame where the
       
    78     // CTrapCleanup was created. This is why we need this function.
       
    79     TRAPD( err, aServer = CMenuSrv::NewL() );
       
    80     return err;
       
    81     }
       
    82 
       
    83 // ==================== GLOBAL FUNCTIONS ====================
       
    84 
       
    85 // ---------------------------------------------------------
       
    86 // RunMenuServer
       
    87 // ---------------------------------------------------------
       
    88 //
       
    89 EXPORT_C TInt RunMenuServer()
       
    90     {
       
    91     __UHEAP_MARK;
       
    92     CTrapCleanup* trapCleanup = NULL;
       
    93     CActiveScheduler* activeScheduler = NULL;
       
    94     CMenuSrv* server = NULL;
       
    95 
       
    96     TInt err = User::RenameThread( KMenuSrvName );
       
    97     if ( !err )
       
    98         {
       
    99         // Create a trap cleanup, make and install an active scheduler.
       
   100         err = KErrNoMemory;
       
   101         trapCleanup = CTrapCleanup::New();
       
   102         if ( trapCleanup )
       
   103             {
       
   104             activeScheduler = new CActiveScheduler();
       
   105             if ( activeScheduler )
       
   106                 {
       
   107                 CActiveScheduler::Install( activeScheduler );
       
   108                 err = CreateServer( server );   // Not pushed (no leaving).
       
   109                 if ( !err )
       
   110                     {
       
   111                     err = server->Start( KMenuSrvName );
       
   112                     }
       
   113                 }
       
   114             else
       
   115             	{
       
   116             	err = KErrNoMemory;
       
   117             	}
       
   118             }
       
   119         }
       
   120     // Let the caller know how it went.
       
   121     RProcess::Rendezvous( err );
       
   122     if ( !err )
       
   123         {
       
   124         CActiveScheduler::Start(); // Start off. Exit timer will stop it.
       
   125         }
       
   126     CActiveScheduler::Install( NULL );
       
   127     delete activeScheduler;
       
   128     delete server;
       
   129     delete trapCleanup;
       
   130     __UHEAP_MARKEND;
       
   131     return err;
       
   132     }
       
   133 
       
   134 // ==================== MEMBER FUNCTIONS ====================
       
   135 
       
   136 // ---------------------------------------------------------
       
   137 // CMenuSrv::NewL
       
   138 // ---------------------------------------------------------
       
   139 //
       
   140 CMenuSrv* CMenuSrv::NewL()
       
   141     {
       
   142     CMenuSrv* srv = new (ELeave) CMenuSrv();
       
   143     CleanupStack::PushL( srv );
       
   144     srv->ConstructL();
       
   145     CleanupStack::Pop( srv );
       
   146     return srv;
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------
       
   150 // CMenuSrv::~CMenuSrv
       
   151 // ---------------------------------------------------------
       
   152 //
       
   153 CMenuSrv::~CMenuSrv()
       
   154     {
       
   155     // Cancel requests and delete all sessions first.
       
   156     // Base class would do it for us but that's too late - our sessions
       
   157     // call the server back (SessionClosed, RemoveContainer, etc.).
       
   158     Cancel();
       
   159     CSession2* session;
       
   160     iSessionIter.SetToFirst();
       
   161     while ( NULL != (session = iSessionIter++) )
       
   162         {
       
   163         delete session;
       
   164         }
       
   165     // Here we should have no objects that are dependent on us.
       
   166     delete iObjectConIx; // This kills iEngines too.
       
   167     delete iExitTimer;
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CMenuSrv::NewContainerL
       
   172 // ---------------------------------------------------------
       
   173 //
       
   174 CObjectCon* CMenuSrv::NewContainerL()
       
   175     {
       
   176     return iObjectConIx->CreateL();
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CMenuSrv::RemoveContainer
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 void CMenuSrv::RemoveContainer( CObjectCon* aCon )
       
   184     {
       
   185     iObjectConIx->Remove( aCon );
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------
       
   189 // CMenuSrv::GetEngineL
       
   190 // ---------------------------------------------------------
       
   191 //
       
   192 CMenuSrvEng* CMenuSrv::GetEngineL( const TDesC& aName )
       
   193     {
       
   194     CMenuSrvEng* eng = NULL;
       
   195     for ( TInt i = 0; i < iEngines->Count(); i++ )
       
   196         {
       
   197         eng = (CMenuSrvEng*)(*iEngines)[i];
       
   198         if ( eng->ContentName() == aName )
       
   199             {
       
   200             return eng;
       
   201             }
       
   202         }
       
   203     eng = CMenuSrvEng::NewL( *this, aName );
       
   204     CleanupClosePushL( *eng );
       
   205     iEngines->AddL( eng );
       
   206     CleanupStack::Pop( eng );
       
   207     return eng;
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------
       
   211 // CMenuSrv::EngineDeleted
       
   212 // ---------------------------------------------------------
       
   213 //
       
   214 void CMenuSrv::EngineDeleted()
       
   215     {
       
   216     if ( 1 >= iEngines->Count() )
       
   217         {
       
   218         // Last engine is being deleted now.
       
   219         // Exit now, without delay: the engines had the timeout.
       
   220         //
       
   221         // Engine count is 1 when the engine has been created and added.
       
   222         // Engine count is 0 in case of leave in GetEngineL().
       
   223         iExitTimer->Cancel();
       
   224         CActiveScheduler* currentScheduler = CActiveScheduler::Current();
       
   225         // No more sessions; schedule self-deletion.
       
   226         if (currentScheduler)
       
   227             {
       
   228             iExitTimer->After( TTimeIntervalMicroSeconds32( 0 ) );
       
   229             }
       
   230         }
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------
       
   234 // CMenuSrv::CMenuSrv
       
   235 // ---------------------------------------------------------
       
   236 //
       
   237 CMenuSrv::CMenuSrv()
       
   238 : CPolicyServer( CActive::EPriorityStandard, KPolicy, ESharableSessions )
       
   239     {
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------
       
   243 // CMenuSrv::ConstructL
       
   244 // ---------------------------------------------------------
       
   245 //
       
   246 void CMenuSrv::ConstructL()
       
   247     {
       
   248     iExitTimer = CTimeout::NewL
       
   249         ( CActive::EPriorityStandard, TCallBack( StopScheduler, NULL ) );
       
   250     iExitTimer->Cancel();
       
   251     iExitTimer->After( TTimeIntervalMicroSeconds32( KMenuSrvExitDelay ) );
       
   252     iObjectConIx = CObjectConIx::NewL();
       
   253     iEngines = iObjectConIx->CreateL();
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------
       
   257 // CMenuSrv::NewSessionL
       
   258 // ---------------------------------------------------------
       
   259 //
       
   260 CSession2* CMenuSrv::NewSessionL
       
   261 ( const TVersion& aVersion, const RMessage2& /*aMessage*/ ) const
       
   262     {
       
   263     TVersion version( KMenuMajorVersion, KMenuMinorVersion, KMenuBuild );
       
   264     if ( !User::QueryVersionSupported( version, aVersion ) )
       
   265         {
       
   266         User::Leave( KErrNotSupported );
       
   267         }
       
   268     CSession2* session = CMenuSrvSession::NewL( (CMenuSrv&)*this );
       
   269     iExitTimer->Cancel();   // We have a client, cancel exit (if pending).
       
   270     return session;
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------
       
   274 // CMenuSrv::CustomSecurityCheckL
       
   275 // ---------------------------------------------------------
       
   276 //
       
   277 CPolicyServer::TCustomResult CMenuSrv::CustomSecurityCheckL
       
   278     ( const RMessage2& aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/ )
       
   279     {
       
   280     TInt func = aMsg.Function();
       
   281     TCustomResult ret = EFail;
       
   282     if( func > EMenuTestCapabilityStart && 
       
   283         func < EMenuTestCapabilityEnd )
       
   284         {
       
   285         if( aMsg.HasCapability( ECapabilityAllFiles ) )
       
   286            {
       
   287            ret = EPass;
       
   288            }
       
   289         }
       
   290     else if( func > EMenuReadCapabilityStart && 
       
   291              func < EMenuReadCapabilityEnd )
       
   292         {
       
   293         if( aMsg.HasCapability( ECapabilityReadDeviceData ) )
       
   294            {
       
   295            ret = EPass;
       
   296            }
       
   297         }
       
   298     else if( func > EMenuWriteCapabilityStart && 
       
   299              func < EMenuWriteCapabilityEnd )
       
   300         {
       
   301         if( aMsg.HasCapability( ECapabilityWriteDeviceData ) )
       
   302            {
       
   303            ret = EPass;
       
   304            }
       
   305         }
       
   306     else
       
   307         {
       
   308         ;
       
   309         }
       
   310     return ret;
       
   311     }
       
   312 
       
   313 //  End of File