realtimenetprots/sipfw/SampleApp/socketengine/Inc/SIPExSocketEngine.h
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 
       
     2 /*
       
     3 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 * All rights reserved.
       
     5 * This component and the accompanying materials are made available
       
     6 * under the terms of "Eclipse Public License v1.0"
       
     7 * which accompanies this distribution, and is available
       
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 *
       
    10 * Initial Contributors:
       
    11 * Nokia Corporation - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 *
       
    15 * Description:
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __CSIPEXSOCKETENGINE_H__
       
    22 #define __CSIPEXSOCKETENGINE_H__
       
    23 
       
    24 // INCLUDES
       
    25 #include    "SIPExTimeOutTimer.h"
       
    26 #include    "SIPExSocketEngineObserver.h"
       
    27 #include    "SIPEXReaderNotifier.h"
       
    28 #include    "SIPExWriterNotifier.h"
       
    29 #include    "SIPExTimeOutNotify.h"
       
    30 #include    <in_sock.h>     // SInetAddr
       
    31 
       
    32 
       
    33 // FORWARD DECLARATIONS
       
    34 class MSIPExSocketEngineObserver;
       
    35 class CSIPExSocketReader;
       
    36 class CSIPExSocketWriter;
       
    37 class CSIPExTimeOutTimer;
       
    38 
       
    39 // CLASS DECLARATIONS
       
    40 /**
       
    41 * Implements socket connections.
       
    42 */
       
    43 class CSIPExSocketEngine 
       
    44 :   public CActive, 
       
    45     public MSIPExTimeOutNotify,
       
    46     public MSIPExReaderNotifier,
       
    47     public MSIPExWriterNotifier
       
    48     {
       
    49     public:
       
    50 
       
    51         /**
       
    52         * Static constructor
       
    53         * @param aObserver A reference to the socket engine observer.
       
    54         */
       
    55         IMPORT_C static CSIPExSocketEngine* NewL( MSIPExSocketEngineObserver& aObserver );
       
    56 
       
    57         /**
       
    58         * Static constructor. On return the instance is left to the CleanupStack
       
    59         * @param aObserver A reference to the socket engine observer.
       
    60         */
       
    61         IMPORT_C static CSIPExSocketEngine* NewLC( MSIPExSocketEngineObserver& aObserver );
       
    62 
       
    63         /**
       
    64         * Destructor
       
    65         */
       
    66         IMPORT_C ~CSIPExSocketEngine();
       
    67 
       
    68     public: // From base classes
       
    69 
       
    70         /**
       
    71         * Connecting the socket to the aIPAddress.
       
    72         * @param aIapId An iap id used for connection
       
    73         * @param aIPAddress An ip address where to connect.
       
    74         */
       
    75         IMPORT_C void ConnectL( const TUint32 aIapId, const TInetAddr& aIPAddress );
       
    76         
       
    77         /**
       
    78         * Writes to the socket.
       
    79         * @param aTxt A text to write to the socket.
       
    80         */
       
    81         IMPORT_C void Write( const TDesC8& aTxt );
       
    82 
       
    83         /**
       
    84         * Reads from the socket.
       
    85         */
       
    86         IMPORT_C void Read();
       
    87 
       
    88         /**
       
    89         * Closing the socket.
       
    90         */
       
    91         IMPORT_C void Stop();
       
    92 
       
    93         /**
       
    94         * Starts listening local game port
       
    95         * @param aIapId The IAP id of the active accesspoint. 
       
    96         * @return A local address
       
    97         */
       
    98         IMPORT_C TInetAddr& StartListeningL( const TUint32 aIapId );
       
    99 
       
   100     public: 
       
   101 
       
   102         /**
       
   103         * Socket engine state enumerations.
       
   104         */
       
   105         enum TSocketEngineState
       
   106             {
       
   107             ENotConnected,
       
   108             EConnecting,
       
   109             EConnected,
       
   110             EListening,
       
   111             ETimedOut
       
   112             };
       
   113 
       
   114     protected: // From base classes
       
   115 
       
   116         // From MSIPExTimeOutNotify
       
   117         /**
       
   118         * From MSIPExTimeOutNotify
       
   119         * Destructor
       
   120         */
       
   121         void TimerExpired();
       
   122 
       
   123         // From MSIPExReaderNotifier
       
   124 
       
   125         /**
       
   126         * From MSIPExReaderNotifier
       
   127         */
       
   128         void MessageReceived( TDesC8& aBuffer );
       
   129 
       
   130         /**
       
   131         * From MSIPExReaderNotifier
       
   132         */
       
   133         void ErrorInReading( TInt aError );
       
   134 
       
   135         // From MSIPExWriterNotifier
       
   136 
       
   137         /**
       
   138         * From MSIPExWriterNotifier
       
   139         */
       
   140         void WriteDone();
       
   141         
       
   142         /**
       
   143         * From MSIPExWriterNotifier
       
   144         */
       
   145         void ErrorInWriting( TInt aError );
       
   146 
       
   147     protected: // From base classes
       
   148         
       
   149         /**
       
   150         * From CActive
       
   151         * Cancels any outstanding request.
       
   152         */
       
   153         void DoCancel();
       
   154         
       
   155         /**
       
   156         * From CActive
       
   157         * Handles the completion of the active request.
       
   158         */
       
   159         void RunL();
       
   160 
       
   161     private: // New functions
       
   162 
       
   163         /**
       
   164         * Changes the new state to iState and notifies observer.
       
   165         * @param aNewState A new state of socket engine
       
   166         */
       
   167         void ChangeStateAndNotify( TSocketEngineState aNewState );
       
   168 
       
   169          /**
       
   170         * Activates PDP ctx of passed iap
       
   171         * @param aIapId The IAP id of the activated accesspoint.
       
   172         */
       
   173         void StartInterfaceL( const TUint32 aIapId );
       
   174         
       
   175         /**
       
   176         * Gets the local IP address with host resolver.
       
   177         * The address is set to the iAddress variable.
       
   178         */
       
   179         void ResolveLocalIPAddressL();
       
   180 
       
   181     private:
       
   182 
       
   183         /**
       
   184         * Destructor
       
   185         */
       
   186         CSIPExSocketEngine( MSIPExSocketEngineObserver& aObserver );
       
   187 
       
   188         /**
       
   189         * Destructor
       
   190         */
       
   191         void ConstructL();
       
   192 
       
   193     private:
       
   194         // Member variables
       
   195 
       
   196         // The reference to the socket engine observer
       
   197         MSIPExSocketEngineObserver&  iObserver;
       
   198 
       
   199         // Sockets
       
   200         RSocketServ     iSocketServer;
       
   201         RConnection     iConnection;
       
   202         RSocket         iDataSocket;
       
   203         RSocket         iListenSocket;        
       
   204         
       
   205 
       
   206         // 
       
   207         CSIPExSocketReader*  iReader;
       
   208         CSIPExSocketWriter*  iWriter;
       
   209         CSIPExTimeOutTimer*  iTimer;
       
   210 
       
   211         // Socket engine's state
       
   212         TSocketEngineState  iState;
       
   213 
       
   214         // The remote address
       
   215         TInetAddr   iAddress;
       
   216     };
       
   217 
       
   218 #endif // __CSIPEXSOCKETENGINE_H__
       
   219 
       
   220 // End of file