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

📄 tmserversession.cpp

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


// INCLUDE FILES
#include <e32math.h>
#include <e32cmn.h> // TIpcArgs
#include "TmServerSession.h"

// FUNCTION PROTOTYPES
TInt StartServer();

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

// -----------------------------------------------------------------------------
// RTmServerSession::RTmServerSession()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
EXPORT_C RTmServerSession::RTmServerSession()
: RSessionBase()
    {
    // No implementation required
    }

// -----------------------------------------------------------------------------
// RTmServerSession::Connect()
// Connects to the server and creates a session.
// -----------------------------------------------------------------------------
//
EXPORT_C TInt RTmServerSession::Connect()
    {
    TInt error = StartServer();

    if ( KErrNone == error )
        {
        error = CreateSession( KTmServerName, Version());
        }
    return error;
    }

// -----------------------------------------------------------------------------
// RTmServerSession::Version()
// Gets the version number.
// -----------------------------------------------------------------------------
//
TVersion RTmServerSession::Version() const
    {
    return( TVersion( KTmServMajorVersionNumber,
                      KTmServMinorVersionNumber,
                      KTmServBuildVersionNumber ) );
    }

// -----------------------------------------------------------------------------
// RTmServerSession::GetServerAddress()
// 
// -----------------------------------------------------------------------------
//
EXPORT_C void RTmServerSession::GetServerAddress(TDes& anAddress) const
    {
    // This call waits for the server to complete the request before
    // proceeding. 
    SendReceive( ETmServRequestAddress, TIpcArgs(&anAddress));

    }


// -----------------------------------------------------------------------------
// RTmServerSession::SetServerAddress()
// 
// -----------------------------------------------------------------------------
//
EXPORT_C void RTmServerSession::SetServerAddress(const TDesC& anAddress) const
    {
    // This call waits for the server to complete the request before
    // proceeding. 
    SendReceive( ETmServSetAddress, TIpcArgs(&anAddress) );

    }

// -----------------------------------------------------------------------------
// RTmServerSession::GetServerPort()
// 
// -----------------------------------------------------------------------------
//
EXPORT_C void RTmServerSession::GetServerPort( TDes& aPort) const
    {
    // This call waits for the server to complete the request before
    // proceeding.
    SendReceive( ETmServRequestPort, TIpcArgs(&aPort) );
    }


// -----------------------------------------------------------------------------
// RTmServerSession::SetServerPort()
// 
// -----------------------------------------------------------------------------
//
EXPORT_C void RTmServerSession::SetServerPort(const TDesC& aPort) const
    {
    // This call waits for the server to complete the request before
    // proceeding. 
    SendReceive( ETmServSetPort, TIpcArgs(&aPort) );
    }

// -----------------------------------------------------------------------------
// RTmServerSession::GetServerType()
// 
// -----------------------------------------------------------------------------
//
EXPORT_C void RTmServerSession::GetServerType(TDes& aType) const
    {
    // This call waits for the server to complete the request before
    // proceeding.
    SendReceive( ETmServRequestType, TIpcArgs(&aType) );
    }


// -----------------------------------------------------------------------------
// RTmServerSession::SetServerType()
// 
// -----------------------------------------------------------------------------
//
EXPORT_C void RTmServerSession::SetServerType(const TDesC& aType) const
    {
    // This call waits for the server to complete the request before
    // proceeding. 
    SendReceive( ETmServSetType, TIpcArgs(&aType) );
    }

// -----------------------------------------------------------------------------
// RTmServerSession::GetAll()
// 
// -----------------------------------------------------------------------------
//
EXPORT_C void RTmServerSession::GetAll(TDes& anAddress, 
    TDes& aPort, TDes& aType) const
    {
    // This call waits for the server to complete the request before
    // proceeding. 
    SendReceive( ETmServRequestAll, TIpcArgs(&anAddress, &aPort, &aType) );
    }

// -----------------------------------------------------------------------------
// RTmServerSession::SetAll()
// 
// -----------------------------------------------------------------------------
//
EXPORT_C void RTmServerSession::SetAll(const TDesC& anAddress, 
    const TDesC& aPort, const TDesC& aType) const
    {
    // This call waits for the server to complete the request before
    // proceeding. 
    SendReceive( ETmServSetAll, TIpcArgs(&anAddress, &aPort, &aType) );
    }

// ============================= OTHER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// StartServer()
// Starts the server if it is not already running
// -----------------------------------------------------------------------------
//
TInt StartServer()
    {
    TInt res(KErrNone);
    // create server - if one of this name does not already exist
    TFindServer findServer(KTmServerName);
    TFullName name;
    if (findServer.Next(name)!=KErrNone) // we don't exist already
        {
        TRequestStatus status;
        RProcess server;
        // Create the server process
        res = server.Create(KTmServerFilename, KNullDesC);       

        if( res!=KErrNone ) // thread created ok - now start it going
            {
            return res;
            }

        // Process created successfully
        server.Resume(); // start it going
        server.Rendezvous( status );
        
        // Wait until the completion of the server creation
        User::WaitForRequest( status );
        if( status != KErrNone )
            {
            server.Close();
            return status.Int();
            }
        // Server created successfully
        server.Close(); // we're no longer interested in the other process
        }
    return res;
    }

// End of File

⌨️ 快捷键说明

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