upnp/upnpstack/dlnawebserver/inc/upnptcpserver.h
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2005-2006 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:  Declares main application classes
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CUPNPTCPSERVER_H
       
    20 #define C_CUPNPTCPSERVER_H
       
    21 
       
    22 // INCLUDES
       
    23 #include "upnpcompvariant.hrh"
       
    24 
       
    25 #include <e32base.h>
       
    26 #include <es_sock.h>
       
    27 #include <in_sock.h>
       
    28 #include <commdbconnpref.h>
       
    29 
       
    30 #include "upnpnotifytimer.h"
       
    31 #include "upnpconnectionmanagerproxy.h"
       
    32 
       
    33 // FORWARD DECLARATIONS
       
    34 class CUpnpTcpSession;
       
    35 class MUpnpHttpServerTransactionCreator;
       
    36 class CUpnpDlnaFilter;
       
    37 
       
    38 
       
    39 #ifdef RD_UPNP_REMOTE_ACCESS
       
    40 class CUpnpIPFilterManager;
       
    41 #endif
       
    42 
       
    43 // CONSTANTS
       
    44 static const TInt KMaxConnectionCount = 16;
       
    45 const TInt KRetryTime = 1000000;
       
    46 static const TInt KDefaultHttpPort = 50001; // HTTP default port number
       
    47 // A Category value for a property of Publish and Subscribe
       
    48 const TUid KdlnawebserverCat={0x10204165};
       
    49 enum TdlnawebserverKeys {EdlnawebserverCounter};
       
    50 
       
    51 // CLASS DECLARATION
       
    52 
       
    53 /**
       
    54 * A virtual base class for TCP servers. Includes a server socket and methods
       
    55 * starting server socket, accepting connections and creating CUpnpTcpSessions for
       
    56 * incoming connections. After creating tcp session and adding it to
       
    57 * active sessions' tableserver returns to listening for new connections and
       
    58 * the tcp session takes care about whole communication with remote host.
       
    59 * After handling connection the session is destroyed and removed from sessions' list.
       
    60 *
       
    61 * @lib DLNAwebserver.lib
       
    62 * @since Series60 2.6
       
    63 */
       
    64 NONSHARABLE_CLASS (CUpnpTcpServer) : public CActive, public MUpnpNotifyTimerObserver
       
    65     {
       
    66 public: // Enumerations
       
    67 
       
    68     /**
       
    69     * Enum for state of server.
       
    70     */
       
    71     enum TState
       
    72         {
       
    73         // Server is not listetnig for connections.
       
    74         ENotListening,
       
    75         // Server is listening and accepting incoming connections.
       
    76         EAccepting
       
    77         };
       
    78 
       
    79 public: // Constructor and destructor
       
    80 
       
    81     /**
       
    82     * Constructor function. This constructor is used when connection is
       
    83     * iniatiated from network.
       
    84     * @since Series60 2.6
       
    85     * @param aSocketServ Pointer to Socket Server.
       
    86     * @param aPort Number of listening port.
       
    87     * @param aIap Number of active Iap to use with connections.
       
    88     * @return A new CUpnpTcpServer instance.
       
    89     **/
       
    90     CUpnpTcpServer( RSocketServ* aSocketServ,
       
    91                     TInt aPort,
       
    92                     TInt aIap );
       
    93 
       
    94     /**
       
    95     * TcpServer might-leave initialization method.
       
    96     * NOTE: Must be called by extending class
       
    97     * @since Series60 2.6
       
    98     **/
       
    99     void BaseConstructL();
       
   100 
       
   101     /**
       
   102     * Virtual destructor function.
       
   103     * @since Series60 2.6
       
   104     **/
       
   105     virtual ~CUpnpTcpServer();
       
   106 
       
   107 public: // From CActive
       
   108 
       
   109     /**
       
   110     * Do active object operations
       
   111     * Standard active object function
       
   112     * @since Series60 2.6
       
   113     */
       
   114     void RunL();
       
   115 
       
   116     /**
       
   117     * Do active object operations
       
   118     * Standard active object function
       
   119     * @since Series60 2.6
       
   120     * @param aError from RunL.
       
   121     * @return KErrNone.
       
   122     */
       
   123     TInt RunError( TInt aError );
       
   124 
       
   125     /**
       
   126     * Cancel active object requests
       
   127     * Standard active object function
       
   128     * @since Series60 2.6
       
   129     */
       
   130     void DoCancel();
       
   131 
       
   132 public: // From MUpnpNotifyTimerObserver
       
   133 
       
   134     /**
       
   135     * Callback from iRetrySocketTimer. This method tries to
       
   136     * open new socket again, because last time server
       
   137     * socket binding has failed.
       
   138     * @since Series60 2.6
       
   139     * @param aTimer Pointer to timer that has expired.
       
   140     **/
       
   141     void TimerEventL( CUpnpNotifyTimer* aTimer);
       
   142 
       
   143 public: // New functions
       
   144 
       
   145     /**
       
   146     * Deletes given session.
       
   147     * @since Series60 2.6
       
   148     * @param aSession Session to be deleted.
       
   149     **/
       
   150     void DeleteSession( CUpnpTcpSession* aSession );
       
   151 
       
   152     /**
       
   153     * Opening socket for listening
       
   154     * @since Series60 5.0
       
   155     **/
       
   156     void OpenSocketL();
       
   157 
       
   158     /**
       
   159     * Starts to listen for incoming connections.
       
   160     * @since Series60 5.0
       
   161     **/
       
   162     void BindRandomPortL();
       
   163 
       
   164     /**
       
   165     * Starts to listen for incoming connections.
       
   166     * @since Series60 5.0
       
   167     * @param aPort try to bind to port
       
   168     **/
       
   169     void BindL( const TInt aPort );
       
   170 
       
   171     /**
       
   172     * Stops TcpServer.
       
   173     * @since Series60 2.6
       
   174     */
       
   175     void StopTcpServerL();
       
   176         
       
   177     /**
       
   178     * Set the new IP address
       
   179     * @since Series60 5.0 HN
       
   180     * @param aAddr IP address to be set.
       
   181     **/
       
   182     void SetServerAddress( const TInetAddr& aAddr );
       
   183 
       
   184     /**
       
   185     * Returns the IP address of this server.
       
   186     * @since Series60 2.6
       
   187     * @param aAddr IP address of this server is returned to this reference.
       
   188     **/
       
   189     void ServerAddress( TInetAddr& aAddr );
       
   190 
       
   191     /**
       
   192     * Returns the port of this server.
       
   193     * @since Series60 2.6
       
   194     * @return Port of this server.
       
   195     **/
       
   196     TUint ServerPort();
       
   197 
       
   198     /**
       
   199     * Returns the Hardware address of active IAP.
       
   200     * @since Series60 2.6
       
   201     * @return HW address.
       
   202     **/
       
   203     TSockAddr* HWAddressL();
       
   204 
       
   205     /**
       
   206     * Returns a new available port number.
       
   207     * @since Series60 2.6
       
   208     * @return A new Port number.
       
   209     **/
       
   210     TInt NewPortNumberL(); 	
       
   211 
       
   212 	/**
       
   213     * Starts retrying accepting the new connection.
       
   214     * @since Series60 3.2
       
   215     **/
       
   216     void StartRetryTimer();
       
   217 
       
   218 	/**
       
   219     * Sets file write buffer size
       
   220     * @since Series60 2.6
       
   221     **/
       
   222 	void SetFileWriteBufferSize(TInt aSize);
       
   223 
       
   224 
       
   225 	/**
       
   226     * Returns file read buffer size
       
   227     * @since Series60 2.6
       
   228     **/
       
   229 	TInt FileWriteBufferSize();
       
   230 
       
   231 	/**
       
   232     * Sets file read buffer size
       
   233     * @since Series60 2.6
       
   234     **/
       
   235 	void SetFileReadBufferSize(TInt aSize);
       
   236 
       
   237 
       
   238 	/**
       
   239     * Returns file write buffer size
       
   240     * @since Series60 2.6
       
   241     **/
       
   242 	TInt FileReadBufferSize();
       
   243 
       
   244 
       
   245 protected: // New functions
       
   246 
       
   247     /**
       
   248     * Callback function for new connection creation.
       
   249     * @since Series60 2.6
       
   250     * @param aSocket Socket that is bound to new connection.
       
   251     * @return Pointer to new CUpnpTcpSession.
       
   252     **/
       
   253     virtual CUpnpTcpSession* ConnectionAcceptedL( RSocket aSocket ) = 0;
       
   254 
       
   255     /**
       
   256     * Starts to listen a socket.
       
   257     * @since Series60 2.6
       
   258     * @return error code if listening start fails.
       
   259     **/
       
   260     TInt StartToListenL();
       
   261 
       
   262     /**
       
   263     * Accepts new connection ans starts to listen for new connections.
       
   264     * @since Series60 2.6
       
   265     **/
       
   266     void AcceptConnectionL();
       
   267 
       
   268     /**
       
   269     * Gets the value of iServerAddress
       
   270     * @param aAddr
       
   271     * @since Series60 3.2
       
   272     **/
       
   273     TBool GetServerAddress(TInetAddr& aAddr);
       
   274 
       
   275     /**
       
   276      * Connects to the Connection Manager
       
   277      * @since Series60 5.0
       
   278      **/
       
   279     void CreateConnectionManagerSessionL();
       
   280     
       
   281     /**
       
   282      * Closes sockets
       
   283      * @since Series60 5.0
       
   284      **/
       
   285     void CloseSockets();
       
   286     
       
   287      /**
       
   288      * Prepares to close sockets
       
   289      * @since Series60 5.0
       
   290      **/
       
   291     void PrepareToCloseSockets();
       
   292     
       
   293      /**
       
   294      * Cancels retry timer
       
   295      * @since Series60 5.0
       
   296      **/
       
   297     void CancelRetryTimer();
       
   298 
       
   299 protected:
       
   300 
       
   301     // Connection that is used to bind the used socket server on
       
   302     // given interface.
       
   303     CUpnpConnectionManagerProxy *iConnectionManagerProxy;
       
   304 
       
   305     // State of server, owned
       
   306     TState iState;
       
   307 
       
   308     // Socket server that is used by TcpServer, owned
       
   309     RSocketServ* iSocketServ;
       
   310 
       
   311     // Listening socket, owned
       
   312     RSocket iServerSocket;
       
   313 
       
   314     // Socket that is used to bind new connections, owned
       
   315     RSocket iClientSocket;
       
   316 
       
   317     // List of sessions, owned
       
   318     RPointerArray<CUpnpTcpSession> iSessionList;
       
   319 
       
   320     // Listening port of this server, owned
       
   321     TUint iServerPort;
       
   322 
       
   323     // Address of this server, owned
       
   324     TInetAddr iServerAddress;
       
   325 
       
   326     // Used Iap, owned
       
   327     TInt iActiveIap;
       
   328 
       
   329     // Timer that is used when RSocket::Open() fails. This way
       
   330     // we try to bind listening server socket again later.
       
   331     CUpnpNotifyTimer* iRetrySocketTimer;
       
   332 
       
   333     // preference for connection
       
   334     TCommDbConnPref iCommDbPref;
       
   335 
       
   336   	// File write buffer size
       
   337   	TInt iFileWriteBufferSize;
       
   338 
       
   339   	// File read buffer size
       
   340   	TInt iFileReadBufferSize;
       
   341 
       
   342   	#ifdef RD_UPNP_REMOTE_ACCESS
       
   343     /*******IPFiltering *******/
       
   344     CUpnpIPFilterManager* iIPFilteringManager;
       
   345     /*******IPFiltering *******/
       
   346     #endif
       
   347     
       
   348     
       
   349     MUpnpHttpServerTransactionCreator* iTransactionCreator;
       
   350     
       
   351     };
       
   352 
       
   353 #endif // C_CUPNPTCPSERVER_H
       
   354 
       
   355 // End Of File