S60 3rd Edition SDK for Symbian OS
Example Applications Guide

SIPExSocketEngine.h

00001 /*
00002 * ==============================================================================
00003 *  Name        : SIPExSocketEngine.h
00004 *  Part of     : SIPExSocketEngine
00005 *  Interface   : 
00006 *  Description : 
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2004-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 #ifndef __CSIPEXSOCKETENGINE_H__
00017 #define __CSIPEXSOCKETENGINE_H__
00018 
00019 // INCLUDES
00020 #include    "SIPExTimeOutTimer.h"
00021 #include    "SIPExSocketEngineObserver.h"
00022 #include    "SIPExReaderNotifier.h"
00023 #include    "SIPExWriterNotifier.h"
00024 #include    "SIPExTimeOutNotify.h"
00025 #include    <in_sock.h>     // SInetAddr
00026 
00027 
00028 // FORWARD DECLARATIONS
00029 class MSIPExSocketEngineObserver;
00030 class CSIPExSocketReader;
00031 class CSIPExSocketWriter;
00032 class CSIPExTimeOutTimer;
00033 
00034 // CLASS DECLARATIONS
00035 /**
00036 * Implements socket connections.
00037 */
00038 class CSIPExSocketEngine 
00039 :   public CActive, 
00040     public MSIPExTimeOutNotify,
00041     public MSIPExReaderNotifier,
00042     public MSIPExWriterNotifier
00043     {
00044     public:
00045 
00046         /**
00047         * Static constructor
00048         * @param aObserver A reference to the socket engine observer.
00049         */
00050         IMPORT_C static CSIPExSocketEngine* NewL( MSIPExSocketEngineObserver& aObserver );
00051 
00052         /**
00053         * Static constructor. On return the instance is left to the CleanupStack
00054         * @param aObserver A reference to the socket engine observer.
00055         */
00056         IMPORT_C static CSIPExSocketEngine* NewLC( MSIPExSocketEngineObserver& aObserver );
00057 
00058         /**
00059         * Destructor
00060         */
00061         IMPORT_C ~CSIPExSocketEngine();
00062 
00063     public: // From base classes
00064 
00065         /**
00066         * Connecting the socket to the aIPAddress.
00067         * @param aIapId An iap id used for connection
00068         * @param aIPAddress An ip address where to connect.
00069         */
00070         IMPORT_C void ConnectL( const TUint32 aIapId, const TInetAddr& aIPAddress );
00071         
00072         /**
00073         * Writes to the socket.
00074         * @param aTxt A text to write to the socket.
00075         */
00076         IMPORT_C void Write( const TDesC8& aTxt );
00077 
00078         /**
00079         * Reads from the socket.
00080         */
00081         IMPORT_C void Read();
00082 
00083         /**
00084         * Closing the socket.
00085         */
00086         IMPORT_C void Stop();
00087 
00088         /**
00089         * Starts listening local game port
00090         * @param aIapId The IAP id of the active accesspoint. 
00091         * @return A local address
00092         */
00093         IMPORT_C TInetAddr& StartListeningL( const TUint32 aIapId );
00094 
00095     public: 
00096 
00097         /**
00098         * Socket engine state enumerations.
00099         */
00100         enum TSocketEngineState
00101             {
00102             ENotConnected,
00103             EConnecting,
00104             EConnected,
00105             EListening,
00106             ETimedOut
00107             };
00108 
00109     protected: // From base classes
00110 
00111         // From MSIPExTimeOutNotify
00112         /**
00113         * From MSIPExTimeOutNotify
00114         * Destructor
00115         */
00116         void TimerExpired();
00117 
00118         // From MSIPExReaderNotifier
00119 
00120         /**
00121         * From MSIPExReaderNotifier
00122         */
00123         void MessageReceived( TDesC8& aBuffer );
00124 
00125         /**
00126         * From MSIPExReaderNotifier
00127         */
00128         void ErrorInReading( TInt aError );
00129 
00130         // From MSIPExWriterNotifier
00131 
00132         /**
00133         * From MSIPExWriterNotifier
00134         */
00135         void WriteDone();
00136         
00137         /**
00138         * From MSIPExWriterNotifier
00139         */
00140         void ErrorInWriting( TInt aError );
00141 
00142     protected: // From base classes
00143         
00144         /**
00145         * From CActive
00146         * Cancels any outstanding request.
00147         */
00148         void DoCancel();
00149         
00150         /**
00151         * From CActive
00152         * Handles the completion of the active request.
00153         */
00154         void RunL();
00155 
00156     private: // New functions
00157 
00158         /**
00159         * Changes the new state to iState and notifies observer.
00160         * @param aNewState A new state of socket engine
00161         */
00162         void ChangeStateAndNotify( TSocketEngineState aNewState );
00163 
00164          /**
00165         * Activates PDP ctx of passed iap
00166         * @param aIapId The IAP id of the activated accesspoint.
00167         */
00168         void StartInterfaceL( const TUint32 aIapId );
00169         
00170         /**
00171         * Gets the local IP address with host resolver.
00172         * The address is set to the iAddress variable.
00173         */
00174         void ResolveLocalIPAddressL();
00175 
00176     private:
00177 
00178         /**
00179         * Destructor
00180         */
00181         CSIPExSocketEngine( MSIPExSocketEngineObserver& aObserver );
00182 
00183         /**
00184         * Destructor
00185         */
00186         void ConstructL();
00187 
00188     private:
00189         // Member variables
00190 
00191         // The reference to the socket engine observer
00192         MSIPExSocketEngineObserver&  iObserver;
00193 
00194         // Sockets
00195         RSocketServ     iSocketServer;
00196         RConnection     iConnection;
00197         RSocket         iDataSocket;
00198         RSocket         iListenSocket;        
00199         
00200 
00201         // 
00202         CSIPExSocketReader*  iReader;
00203         CSIPExSocketWriter*  iWriter;
00204         CSIPExTimeOutTimer*  iTimer;
00205 
00206         // Socket engine's state
00207         TSocketEngineState  iState;
00208 
00209         // The remote address
00210         TInetAddr   iAddress;
00211     };
00212 
00213 #endif // __CSIPEXSOCKETENGINE_H__
00214 
00215 // End of file

© Nokia 2006

Back to top