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

📄 messageserver.h

📁 Symbian下的p2p工程
💻 H
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */


#ifndef __MESSAGESERVER_H__
#define __MESSAGESERVER_H__

// INCLUDES
#include <e32base.h>
#include <es_sock.h>
#include <btsdp.h>
#include <btmanclient.h>

// CONSTANTS
_LIT( KServerTransportName,"RFCOMM" );
const TInt KMaximumMessageLength = 32;  // The maximum length of any message
                                        // that can be read

// FORWARD DECLARATIONS
class CMessageServiceAdvertiser;
class MLog;

// CLASS DECLARATIONS
/**
* CMessageServer
* Provides a simple messaging service.
*/
class CMessageServer : public CActive
    {
    public:     // Constructors and destructor

        /**
        * NewL()
        * Construct a CMessageServer
        * @param aLog the log to send output to
        * @return a pointer to the created instance of CMessageServer
        */
        static CMessageServer* NewL( MLog& aLog );

        /**
        * NewLC
        * Construct a CMessageServer
        * @param aLog the log to send output to
        * @return a pointer to the created instance of CMessageServer
        */
        static CMessageServer* NewLC( MLog& aLog );

        /**
        * ~CMessageServer()
        * Destroy the object and release all memory objects.
        * Close any open sockets
        */
        virtual ~CMessageServer();

    public:     // New functions
        /**
        * IsConnected()
        * Determines whether the server is connected
        * @return ETrue if the server is connected
        */
        TBool IsConnected();


        /**
        * StartL()
        * Start the server
        */
        void StartL();

        /**
        * StopL()
        * Stop the server
        */
        void StopL();

    protected:    // from CActive

        /**
        * DoCancel()
        * Cancel any outstanding requests
        */
        void DoCancel();

        /**
        * RunL()
        * Respond to an event
        */
        void RunL();

    private:    // Constructors

        /**
        * CMessageServer()
        * Constructs this object
		* @param aLog the log to send output to
        */
        CMessageServer( MLog& aLog );

        /**
        * ConstructL()
        * 2nd phase construction of this object
        */
        void ConstructL();

    private:    // New functions

        /**
        * RequestData()
        * Request data from the client, this object is notified
        * when data becomes available
        */
        void RequestData();


		/**
        * SetSecurityWithChannelL
		* Sets the security on the channel port 
		* And returns the channel available.
  		* @param aAuthentication is authentication used
		* @param aEncryption is encryption used
		* @param aAuthorisation is authorisation used
		* @param aDenied is denied used
		* @return an available channel
        */
        TInt SetSecurityWithChannelL( TBool aAuthentication,
                                      TBool aEncryption,
                                      TBool aAuthorisation,
                                      TBool aDenied );


        /**
        * SetSecurityOnChannelL()
        * Sets the security on the channel port

		* @param aChannel used channel ID
        */
        static void SetSecurityOnChannelL( TBool aAuthentication,
                                           TBool aEncryption,
                                           TBool aAuthorisation,
                                           TInt aChannel );

    private:    // Enumerations

        /**
        * TReceiverState
        * The current state of the receiver
        * EDisconnected server not connected
        * EConnecting not fully constructed
        * EWaitingForMessage connected to a client and waiting for data
        */
        enum TState
            {
                EDisconnected,
                EConnecting,
                EWaitingForMessage
            };

    private:    // data

        /** iLog the log to send output to */
        MLog& iLog;

        /**
        * iAdvertiser used to advertise this service
        * Owned by CMessageServer
        */
        CMessageServiceAdvertiser* iAdvertiser;

        /** iSocketServer a connection to the socket server */
        RSocketServ iSocketServer;

        /** iListeningSocket the listening socket */
        RSocket iListeningSocket;

        /** iAcceptedSocket the socket that connections are accepted to */
        RSocket iAcceptedSocket;

        /** iLen length of data read */
        TSockXfrLength iLen;

        /** iBuffer the buffer to read data to */
        TBuf8<KMaximumMessageLength> iBuffer;

        /** iSecManager a connection to the security manager */
        RBTMan iSecManager;

        /** iReceiverState the state of the server */
        TState iState;
    };

#endif // __MESSAGESERVER_H__

// End of File

⌨️ 快捷键说明

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