⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmserver.cpp

📁 c++下s60终端对终端传输协议
💻 CPP
字号:
/* Copyright (c) 2005, Forum Nokia. All rights reserved */


// INCLUDE FILES
#include <e32svr.h>
#include <e32math.h>

#include "TmServer.h"
#include "ClientServerCommon.h"
#include "TmSession.h"

// ========================= MEMBER FUNCTIONS ==================================

// -----------------------------------------------------------------------------
// CTmServer::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CTmServer* CTmServer::NewL()
    {
    CTmServer* tmServer = CTmServer::NewLC();
    CleanupStack::Pop( tmServer );
    return tmServer;
    }

// -----------------------------------------------------------------------------
// CTmServer::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CTmServer* CTmServer::NewLC()
    {
    CTmServer* tmServer = new ( ELeave ) CTmServer( EPriorityNormal );
    CleanupStack::PushL( tmServer );
    tmServer->ConstructL();
    return tmServer;
    }

// -----------------------------------------------------------------------------
// CTmServer::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CTmServer::ConstructL()
    {
    StartL( KTmServerName );
    }

// -----------------------------------------------------------------------------
// CTmServer::CTmServer()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CTmServer::CTmServer( TInt aPriority )
: CServer2( aPriority )
    {
    // Implementation not required
    }

// -----------------------------------------------------------------------------
// CTmServer::NewSessionL()
// Creates a tm server session.
// -----------------------------------------------------------------------------
//
//CSharableSession* CTmServer::NewSessionL( const TVersion& aVersion ) const
CSession2* CTmServer::NewSessionL( const TVersion& aVersion, 
    const RMessage2& /*aMessage*/ ) const
    {
    // Check we are the right version
    if ( !User::QueryVersionSupported( TVersion( KTmServMajorVersionNumber,
                                                 KTmServMinorVersionNumber,
                                                 KTmServBuildVersionNumber ),
                                       aVersion ) )
        {
        User::Leave( KErrNotSupported );
        }

    // Make new session
    return CTmServerSession::NewL( *const_cast<CTmServer*> ( this ) );
                                     
    }

// -----------------------------------------------------------------------------
// CTmServer::IncrementSessions()
// Increments the count of the active sessions for this server.
// -----------------------------------------------------------------------------
//
void CTmServer::IncrementSessions()
    {
    iSessionCount++;
    }

// -----------------------------------------------------------------------------
// CTmServer::DecrementSessions()
// Decrements the count of the active sessions for this server.
// -----------------------------------------------------------------------------
//
void CTmServer::DecrementSessions()
    {
    iSessionCount--;
    if ( iSessionCount <= 0 )
        {
        // There could also be a timer that would allow the server to be running
        // and waiting for new sessions e.g. for a few minutes after the last 
        // session has ended. For simplicity's sake we do not implement a timer here.
        CActiveScheduler::Stop();
        }
    }

// -----------------------------------------------------------------------------
// CTmServer::RunError()
// Processes any errors.
// -----------------------------------------------------------------------------
//
TInt CTmServer::RunError( TInt aError )
    {
    if ( aError == KErrBadDescriptor )
        {
        // A bad descriptor error implies a badly programmed client,
        // so panic it; otherwise report the error to the client
        PanicClient( Message(), EBadDescriptor );
        }
    else
        {
        Message().Complete( aError );
        }

    // The leave will result in an early return from CServer::RunL(), skipping
    // the call to request another message. So do that now in order to keep the
    // server running.
    ReStart();

    return KErrNone;    // Handled the error fully
    }

// -----------------------------------------------------------------------------
// CTmServer::PanicClient()
// Panics the client.
// -----------------------------------------------------------------------------
//
//void CTmServer::PanicClient( const RMessage& aMessage, TTmServPanic aPanic )
void CTmServer::PanicClient( const RMessage2& aMessage, TTmServPanic aPanic )
    {
    aMessage.Panic( KTMExampleServer, aPanic );
    }

// -----------------------------------------------------------------------------
// CTmServer::PanicServer()
// Panics the server.
// -----------------------------------------------------------------------------
//
void CTmServer::PanicServer( TTmServPanic aPanic )
    {
    User::Panic( KTMExampleServer, aPanic );
    }

//*************************************************************************************
TInt CTmServer::RunServer()
    {
    __UHEAP_MARK;
    //
    CTrapCleanup* cleanup = CTrapCleanup::New();
    TInt ret = KErrNoMemory;
    if( cleanup )
        {
        TRAP( ret, CTmServer::RunServerL() );
        delete cleanup;
        }
    //
    __UHEAP_MARKEND;
    if( ret != KErrNone )
        {
        // Signal the client that server creation failed
        RProcess::Rendezvous( ret );
        }
    return ret;
    }

//*************************************************************************************
void CTmServer::RunServerL()
    {
    // Create and install the active scheduler we need
    CActiveScheduler *as=new (ELeave)CActiveScheduler;
    CleanupStack::PushL( as );
    CActiveScheduler::Install(as);

    // Create server
    CTmServer::NewLC();

    // Initialisation complete, now signal the client
    User::LeaveIfError(RThread().RenameMe(KTMExampleServer));
    RProcess::Rendezvous(KErrNone);

    // Ready to run
    CActiveScheduler::Start();

    // Cleanup the server and scheduler
    CleanupStack::PopAndDestroy(2, as);
    }


//*************************************************************************************

TInt E32Main()
    {
    TInt error(KErrNone);
    error = CTmServer::RunServer();
    return error;
    }

// End of File

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -