applayerpluginsandutils/httptransportplugins/httptransporthandler/csocketconnector.h
changeset 0 b16258d2340f
child 22 26ce6fb6aee2
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __CSOCKETCONNECTOR_H__
       
    17 #define __CSOCKETCONNECTOR_H__
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <in_sock.h>
       
    21 #include <http/framework/logging.h>
       
    22 
       
    23 #include "msocketconnector.h"
       
    24 
       
    25 class CSocket;
       
    26 class MSocketConnectorStore;
       
    27 class MSocketConnectObserver;
       
    28 class MSocketControllerFactory;
       
    29 class MCommsInfoProvider;
       
    30 
       
    31 
       
    32 class CSocketConnector : public CActive,
       
    33 						 public	MSocketConnector
       
    34 /**	
       
    35 	The CSocketConnector class provides socket connecting behaviour. Once the
       
    36 	socket connector object has been started (ConnectL() API) it will notify its
       
    37 	observer when it has established a connection with the specified remote host.
       
    38 
       
    39 	The socket connector initially does a DNS lookup for the host name provided
       
    40 	in the ConnectL() API. Once the IP address has been found for the host name
       
    41 	the socket connector will attempt to establish a TCP connection with the 
       
    42 	remote host.
       
    43 
       
    44 	When a connection has been established a socket controller object is created
       
    45 	by the socket controller factory to encapsulate the connected socket. This
       
    46 	provides the input and output streams for the socket.
       
    47 
       
    48 	The observer, an MSocketConnectObserver object, is notified of a connection
       
    49 	using the MSocketConnectObserver::ConnectionMadeL() API. The input and output
       
    50 	streams that encapsulate the connected socket are passed to the observer.
       
    51 
       
    52 	The connected socket is then placed in the socket controller store by the 
       
    53 	socket controller factory. This transfers the ownership of the socket
       
    54 	controller object to the store.
       
    55 
       
    56 	After the socket controller ownership has been transferred, the socket 
       
    57 	connector removes itself from the socket connector store and then suicides.
       
    58 
       
    59 	If the socket connector encounters any problems it notifies its observer using
       
    60 	the MSocketConnectObserver::HandleConnectError(TInt aError) API. If a problem 
       
    61 	does occur the socket connector will suicide after handling the error.
       
    62 	@internalComponent
       
    63 */
       
    64 	{
       
    65 public:	// methods
       
    66 
       
    67 	static CSocketConnector* NewL(
       
    68 								 MSocketConnectorStore&		aStore,
       
    69 								 MSocketControllerFactory&	aSocketControllerFactory,
       
    70 								 MCommsInfoProvider&		aCommsInfoProvider,
       
    71 								 TBool aPriority
       
    72 								 );
       
    73 
       
    74 	virtual ~CSocketConnector();
       
    75 
       
    76 	void ConnectL(MSocketConnectObserver& aObserver, const TDesC8& aRemoteHost, TUint16 aRemotePort, TInetAddr* aRemoteAddress);
       
    77 
       
    78 private:	// methods from MSocketConnector
       
    79 
       
    80 	virtual void StopConnect();
       
    81 
       
    82 	virtual void MSocketConnector_Reserved();
       
    83 
       
    84 private:	// methods from CActive
       
    85 
       
    86 	virtual void RunL();
       
    87 	
       
    88 	virtual void DoCancel();
       
    89 	
       
    90 	virtual TInt RunError(TInt aError);
       
    91 
       
    92 private:	// methods
       
    93 
       
    94 	CSocketConnector(
       
    95 					MSocketConnectorStore&		aStore,
       
    96 					MSocketControllerFactory&	aSocketControllerFactory,
       
    97 					MCommsInfoProvider&			aCommsInfoProvider,
       
    98 					TBool aPriority
       
    99 					);
       
   100 
       
   101 	void CompleteSelf();
       
   102 
       
   103 	void Suicide();
       
   104 
       
   105 private:	// enums
       
   106 
       
   107 /**	
       
   108 	The state machine for the socket connector.
       
   109 */
       
   110 	enum TConnectState
       
   111 		{
       
   112 		/** The socket connector is idle.
       
   113 		*/
       
   114 		EIdle				= 0,
       
   115 		/** A connection has been requested. The DNS lookup needs to be initiated
       
   116 			to find the IP address of the remote host.
       
   117 		*/
       
   118 		EPendingDNSLookup,
       
   119 		/**	The IP address of the remote host has been found. Initiated a TCP
       
   120 			connection to that remote host.
       
   121 		*/
       
   122 		EConnecting,
       
   123 		/**	The connection has been established. Ownership of the connected socket
       
   124 			must be passed to the observer.
       
   125 		*/
       
   126 		EConnected,
       
   127 		};
       
   128 
       
   129 private:	// attributes
       
   130 
       
   131 /** The socket connector store.
       
   132 */
       
   133 	MSocketConnectorStore&		iStore;
       
   134 
       
   135 /**	The socket controller factory.
       
   136 */
       
   137 	MSocketControllerFactory&	iSocketControllerFactory;
       
   138 
       
   139 /** The comms info provider.
       
   140 */
       
   141 	MCommsInfoProvider&			iCommsInfoProvider;
       
   142 
       
   143 /** The state of the socket connector.
       
   144 */
       
   145 	TConnectState				iState;
       
   146 
       
   147 /** The host resolver session.
       
   148 */
       
   149 	RHostResolver				iHostResolver;
       
   150 
       
   151 /** The socket connect observer.
       
   152 */
       
   153 	MSocketConnectObserver*		iObserver;
       
   154 
       
   155 /**	The host name/IP address for the remote client.
       
   156 */
       
   157 	HBufC*						iHost;
       
   158 
       
   159 /**	The port number on remote host with which to connect to
       
   160 */
       
   161 	TUint16						iPort;
       
   162 
       
   163 /** The DNS entry object for the remote client
       
   164 */
       
   165 	TNameEntry					iHostDnsEntry;
       
   166 	
       
   167 /** The address of the remote host
       
   168 */
       
   169 	TInetAddr					iAddress;
       
   170 
       
   171 /**	The socket object that is connecting to the remote client
       
   172 */
       
   173 	CSocket*					iConnectingSocket;
       
   174 
       
   175 public:	// attributes
       
   176 
       
   177 /** Logger handle
       
   178 */
       
   179 	__FLOG_DECLARATION_MEMBER2
       
   180 
       
   181 	};
       
   182 
       
   183 #endif	// __CSOCKETCONNECTOR_H__