satengine/SatServer/Engine/src/CSatSServer.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Manages the sessions.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CSatSServer.h"
       
    22 #include    "SatSOpcodes.h"
       
    23 #include    "CSatCommandContainer.h"
       
    24 #include    "CSatSSession.h"
       
    25 #include    "SatLog.h"
       
    26 #include    "SatServerFactory.h"
       
    27 #include    "CSatSUiClientHandler.h"
       
    28 //lint -e766 Used inside TRAP macro, lint misfunction.
       
    29 #include    "EnginePanic.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CSatSServer::CSatSServer
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CSatSServer::CSatSServer() :
       
    40 CPolicyServer( EPriorityHigh, satServerPolicy, ESharableSessions )
       
    41     {
       
    42     LOG( SIMPLE, "SATENGINE: CSatSServer::CSatSServer calling-exiting" )
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CSatSServer::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CSatSServer::ConstructL()
       
    51     {
       
    52     LOG( SIMPLE, "SATENGINE: CSatSServer::ConstructL calling" )
       
    53 
       
    54     iObjectConIx = CObjectConIx::NewL();
       
    55     iUiHandler = CSatSUiClientHandler::NewL( *this, iEventMediator );
       
    56     iCmdContainer = CSatCommandContainer::NewL(
       
    57         *this, iEventMediator, *iUiHandler );
       
    58 
       
    59     iUiHandler->SetUtils( iCmdContainer );
       
    60 
       
    61     const TInt err( Start( KSatServerName ) );
       
    62     __ASSERT_ALWAYS( err == KErrNone, PanicSatEngine( ESatSStartServer ) );
       
    63 
       
    64     LOG( SIMPLE, "SATENGINE: CSatSServer::ConstructL exiting" )
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CSatSServer::NewL
       
    69 // Two-phased constructor.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CSatSServer* CSatSServer::NewL()
       
    73     {
       
    74     LOG( SIMPLE, "SATENGINE: CSatSServer::NewL calling" )
       
    75     CSatSServer* self = new( ELeave ) CSatSServer();
       
    76 
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL();
       
    79     CleanupStack::Pop( self );
       
    80 
       
    81     LOG( SIMPLE, "SATENGINE: CSatSServer::NewL exiting" )
       
    82     return self;
       
    83     }
       
    84 
       
    85 // Destructor
       
    86 CSatSServer::~CSatSServer()
       
    87     {
       
    88     LOG( SIMPLE, "SATENGINE: CSatSServer::~CSatSServer calling" )
       
    89 
       
    90     iEventMediator.Reset();
       
    91 
       
    92     iRefreshSubSessions.Close();
       
    93     delete iCmdContainer;
       
    94     delete iUiHandler;
       
    95     delete iObjectConIx;
       
    96 
       
    97     LOG( SIMPLE, "SATENGINE: CSatSServer::~CSatSServer exiting" )
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CSatSServer::CompleteMessage
       
   102 // Completes current message from client with an error code.
       
   103 // (other items were commented in a header).
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CSatSServer::CompleteMessage(
       
   107     TInt aError ) const// Error code, which is used to complete the message.
       
   108     {
       
   109     LOG( SIMPLE, "SATENGINE: CSatSServer::CompleteMessage calling" )
       
   110 
       
   111     Message().Complete( aError );
       
   112 
       
   113     LOG( SIMPLE, "SATENGINE: CSatSServer::CompleteMessage exiting" )
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CSatSServer::CreateNewContainerL
       
   118 // (other items were commented in a header).
       
   119 // -----------------------------------------------------------------------------
       
   120 CObjectCon* CSatSServer::CreateNewContainerL()
       
   121     {
       
   122     LOG( SIMPLE, "SATENGINE: CSatSServer::CreateNewContainerL calling" )
       
   123 
       
   124     CObjectCon* objCon = iObjectConIx->CreateL();
       
   125 
       
   126     LOG( SIMPLE, "SATENGINE: CSatSServer::CreateNewContainerL exiting" )
       
   127     return objCon;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CSatSServer::AddL
       
   132 // (other items were commented in a header).
       
   133 // -----------------------------------------------------------------------------
       
   134 void CSatSServer::AddL( const MSatRefreshSubSession* aSubSession )
       
   135     {
       
   136     LOG( SIMPLE, "SATENGINE: CSatSServer::AddL calling" )
       
   137 
       
   138     User::LeaveIfError( iRefreshSubSessions.Append( aSubSession ) );
       
   139 
       
   140     LOG( SIMPLE, "SATENGINE: CSatSServer::AddL exiting" )
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CSatSServer::Remove
       
   145 // (other items were commented in a header).
       
   146 // -----------------------------------------------------------------------------
       
   147 void CSatSServer::Remove( const MSatRefreshSubSession* aSubSession )
       
   148     {
       
   149     LOG( SIMPLE, "SATENGINE: CSatSServer::Remove calling" )
       
   150     const TInt index( iRefreshSubSessions.Find( aSubSession ) );
       
   151 
       
   152     if ( KErrNotFound != index )
       
   153         {
       
   154         LOG( SIMPLE, "SATENGINE: CSatSServer::Remove KErrNotFound != index" )
       
   155         iRefreshSubSessions.Remove( index );
       
   156         }
       
   157 
       
   158     LOG( SIMPLE, "SATENGINE: CSatSServer::Remove exiting" )
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CSatSServer::NewSessionL
       
   163 // Creates new session if the clients version number matches with server
       
   164 // version number.
       
   165 // (other items were commented in a header).
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 CSession2* CSatSServer::NewSessionL(
       
   169     const TVersion& aVersion, // Clients version of the server
       
   170     const RMessage2& /*aMessage*/ ) const // Message
       
   171     {
       
   172     LOG( SIMPLE, "SATENGINE: CSatSServer::NewSessionL calling" )
       
   173 
       
   174     // Check we're the right version.
       
   175     TVersion satVersionInformation( KSatServerMajorVersionNumber,
       
   176         KSatServerMinorVersionNumber,KSatServerBuildVersionNumber );
       
   177 
       
   178     if ( !User::QueryVersionSupported( satVersionInformation, aVersion ) )
       
   179         {
       
   180         LOG( SIMPLE, "SATENGINE: CSatSServer::NewSessionL KErrNotSupported" )
       
   181         User::Leave( KErrNotSupported );
       
   182         }
       
   183 
       
   184     // Create a new session.
       
   185     CSatSSession* session =
       
   186         CSatSSession::NewL( const_cast<CSatSServer*>( this ),
       
   187             const_cast<TSatEventMediator&>( iEventMediator ),
       
   188             const_cast<MSatApi&>( iCmdContainer->USatAPI() ),
       
   189             *iUiHandler );
       
   190 
       
   191     LOG( SIMPLE, "SATENGINE: CSatSServer::NewSessionL exiting" )
       
   192     return session;
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CSatSServer::UiSession
       
   197 // Getter for ui session
       
   198 // (other items were commented in a header).
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 MSatUiSession* CSatSServer::UiSession()
       
   202     {
       
   203     LOG( SIMPLE, "SATENGINE: CSatSServer::UiSession calling" )
       
   204     MSatUiSession* result = NULL;
       
   205 
       
   206     //lint -e{1757} Post increment acceptable here.
       
   207     for ( iSessionIter.SetToFirst();
       
   208           iSessionIter.operator CSession2*() && ( !result );
       
   209           iSessionIter++ )
       
   210         {
       
   211         CSatSSession* session =
       
   212             static_cast<CSatSSession*>( iSessionIter.operator CSession2*() );
       
   213 
       
   214         // Has session ui subsession
       
   215         result = session->UiSubSession();
       
   216         }
       
   217 
       
   218     if ( NULL != result )
       
   219         {
       
   220         LOG( SIMPLE,
       
   221             "SATENGINE: CSatSServer::UiSession exiting (Ui session found)" )
       
   222         }
       
   223     else
       
   224         {
       
   225         LOG( SIMPLE,
       
   226             "SATENGINE: CSatSServer::UiSession exiting (Ui session not found)" )
       
   227         }
       
   228     LOG( SIMPLE, "SATENGINE: CSatSServer::UiSession exiting" )
       
   229     return result;
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CSatSServer::RefreshSubSessions
       
   234 // (other items were commented in a header).
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 const RPointerArray<MSatRefreshSubSession>&
       
   238     CSatSServer::RefreshSubSessions()
       
   239     {
       
   240     LOG( SIMPLE, "SATENGINE: CSatSServer::RefreshSubSessions calling-exiting" )
       
   241     return iRefreshSubSessions;
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CSatSServer::SatUtils
       
   246 // (other items were commented in a header).
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 MSatUtils* CSatSServer::SatUtils()
       
   250     {
       
   251     LOG( SIMPLE, "SATENGINE: CSatSServer::SatUtils calling-exiting" )
       
   252     return iCmdContainer;
       
   253     }
       
   254 
       
   255 //  End of File