hti/HtiServicePlugins/HtiIpProxyServicePlugin/IPProxyEngine/Src/CLocalHostConnection.h
changeset 36 813b186005b6
parent 30 86a2e675b80a
child 41 838cdffd57ce
equal deleted inserted replaced
30:86a2e675b80a 36:813b186005b6
     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:  Local TCP connection for emulator testing
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CLOCALHOSTCONNECTION_H
       
    21 #define CLOCALHOSTCONNECTION_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <es_sock.h>
       
    26 //#include "MSocket.h"
       
    27 #include "MHostConnection.h"
       
    28 #include <in_sock.h>
       
    29 
       
    30 // DATA TYPES
       
    31 enum TLocalConnState
       
    32     {
       
    33     ELCStateDisconnected = 0,
       
    34     ELCStateConnecting,
       
    35     ELCStateConnected,
       
    36     ELCStateDisconnecting
       
    37     };
       
    38 
       
    39 
       
    40 // FORWARD DECLARATIONS
       
    41 class MHostConnectionObserver;
       
    42 
       
    43 // CLASS DECLARATION
       
    44 
       
    45 /**
       
    46 *  Local TCP connection for emulator testing.
       
    47 *  Due to problematic testing of bluetooth connections in emulator
       
    48 *  this class is used to simulate the connection to local TCP port instead.
       
    49 *  There must be running TCP port listener when connecting with this class.
       
    50 */
       
    51 NONSHARABLE_CLASS( CLocalHostConnection ) : public CActive,
       
    52     public MHostConnection
       
    53     {
       
    54     public:  // Constructors and destructor
       
    55 
       
    56         /**
       
    57         * Factory function.
       
    58         * @param aSocketServer Opened Socket server session
       
    59         * @param aPort Port to connect.
       
    60         * @return New CLocalHostConnection instance.
       
    61         */
       
    62         static CLocalHostConnection* NewL(
       
    63             RSocketServ& aSocketServer, TInt aPort );
       
    64 
       
    65         /**
       
    66         * Factory function.
       
    67         * @param aSocketServer Opened Socket server session
       
    68         * @param aPort Port to connect.
       
    69         * @return New CLocalHostConnection instance.
       
    70         */
       
    71         static CLocalHostConnection* NewLC(
       
    72             RSocketServ& aSocketServer, TInt aPort );
       
    73 
       
    74         /**
       
    75         * Destructor.
       
    76         */
       
    77         ~CLocalHostConnection();
       
    78 
       
    79     public: // Functions from MHostConnection
       
    80 
       
    81         /**
       
    82         * Starts connecting procedure to host.
       
    83         */
       
    84         void IssueConnectL();
       
    85 
       
    86         /**
       
    87         * Starts disconnection procedure.
       
    88         */
       
    89         void IssueDisconnect();
       
    90 
       
    91         /**
       
    92         * Sets observer.
       
    93         * @param aObserver Pointer to observer.
       
    94         */
       
    95         void SetObserver( MHostConnectionObserver* aObserver );
       
    96 
       
    97         /**
       
    98         * @return Connection state.
       
    99         */
       
   100         TBool IsConnected();
       
   101 
       
   102         /**
       
   103         * @return Pointer to current RSocket object. The ownership always
       
   104         * remains in this class.
       
   105         */
       
   106         RSocket* Socket();
       
   107 
       
   108     public: // Functions from base classes
       
   109 
       
   110         /**
       
   111         * From CActive. Pending request has been completed.
       
   112         */
       
   113         void RunL();
       
   114 
       
   115         /**
       
   116         * From CActive. Pending request has been cancelled.
       
   117         */
       
   118         void DoCancel();
       
   119 
       
   120         /**
       
   121         * From CActive. RunL has leaved.
       
   122         */
       
   123         TInt RunError( TInt aError );
       
   124 
       
   125     public: // New methods
       
   126 
       
   127         /**
       
   128         * Returns the port number of this connection
       
   129         * @return Port number
       
   130         */
       
   131         TInt Port();
       
   132 
       
   133     private:
       
   134 
       
   135         /**
       
   136         * Default constructor.
       
   137         */
       
   138         CLocalHostConnection( RSocketServ& aSocketServer, TInt aPort );
       
   139 
       
   140         /**
       
   141         * 2nd phase constructor.
       
   142         */
       
   143         void ConstructL();
       
   144 
       
   145     private:    // Data
       
   146         MHostConnectionObserver* iObserver;
       
   147         RSocketServ& iSocketServer;
       
   148         RSocket iClientSocket;
       
   149         TInetAddr iAddr;
       
   150         TLocalConnState iState;
       
   151     };
       
   152 
       
   153 #endif      // CLOCALHOSTCONNECTION_H
       
   154 
       
   155 // End of File