email/imap4mtm/imaptransporthandler/inc/csocketconnector.h
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2006-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 
       
    22 #include "msocketconnector.h"
       
    23 
       
    24 // Forward declarations
       
    25 class CSocket;
       
    26 class MSocketConnectorStore;
       
    27 class MSocketConnectObserver;
       
    28 class MSocketControllerFactory;
       
    29 class MCommsInfoProvider;
       
    30 
       
    31 /**	
       
    32 The CSocketConnector class provides socket connecting behaviour. Once the
       
    33 socket connector object has been started (ConnectL() API) it will notify its
       
    34 observer when it has established a connection with the specified remote host.
       
    35 
       
    36 The socket connector initially does a DNS lookup for the host name provided
       
    37 in the ConnectL() API. Once the IP address has been found for the host name
       
    38 the socket connector will attempt to establish a TCP connection with the 
       
    39 remote host.
       
    40 
       
    41 When a connection has been established a socket controller object is created
       
    42 by the socket controller factory to encapsulate the connected socket. This
       
    43 provides the input and output streams for the socket.
       
    44 
       
    45 The observer, an MSocketConnectObserver object, is notified of a connection
       
    46 using the MSocketConnectObserver::ConnectionMadeL() API. The input and output
       
    47 streams that encapsulate the connected socket are passed to the observer.
       
    48 
       
    49 The connected socket is then placed in the socket controller store by the 
       
    50 socket controller factory. This transfers the ownership of the socket
       
    51 controller object to the store.
       
    52 
       
    53 After the socket controller ownership has been transferred, the socket 
       
    54 connector removes itself from the socket connector store and then suicides.
       
    55 
       
    56 If the socket connector encounters any problems it notifies its observer using
       
    57 the MSocketConnectObserver::HandleConnectError(TInt aError) API. If a problem 
       
    58 does occur the socket connector will suicide after handling the error.
       
    59 
       
    60 @internalTechnology
       
    61 @prototype
       
    62 */
       
    63 
       
    64 class CSocketConnector : public CActive,
       
    65 						 public	MSocketConnector
       
    66 	{
       
    67 public:
       
    68 	static CSocketConnector* NewL(MSocketConnectorStore& aStore, MSocketControllerFactory& aSocketControllerFactory,MCommsInfoProvider& aCommsInfoProvider);
       
    69 	virtual ~CSocketConnector();
       
    70 	void ConnectL(MSocketConnectObserver& aObserver, const TDesC8& aRemoteHost, TUint16 aRemotePort);
       
    71 
       
    72 private:
       
    73 	CSocketConnector(MSocketConnectorStore& aStore, MSocketControllerFactory& aSocketControllerFactory, MCommsInfoProvider&	aCommsInfoProvider);
       
    74 	void CompleteSelf();
       
    75 	void Suicide();
       
    76 
       
    77 	// from MSocketConnector
       
    78 	virtual void StopConnect();
       
    79 
       
    80 	// from CActive
       
    81 	virtual void RunL();
       
    82 	virtual void DoCancel();
       
    83 	virtual TInt RunError(TInt aError);
       
    84 
       
    85 private:
       
    86 	/**
       
    87 	The state machine for the socket connector.
       
    88 	*/
       
    89 	enum TConnectState
       
    90 		{
       
    91 		/** The socket connector is idle. */
       
    92 		EIdle = 0,
       
    93 		/** A connection has been requested. The DNS lookup needs to be initiated
       
    94 			to find the IP address of the remote host. 
       
    95 		*/
       
    96 		EPendingDNSLookup,
       
    97 		/**	The IP address of the remote host has been found. Initiated a TCP
       
    98 			connection to that remote host.
       
    99 		*/
       
   100 		EConnecting,
       
   101 		/**	The connection has been established. Ownership of the connected socket
       
   102 			must be passed to the observer.
       
   103 		*/
       
   104 		EConnected,
       
   105 		/**	The socket connector has completed - need to self-destruct. */
       
   106 		ESuicide
       
   107 		};
       
   108 
       
   109 private:
       
   110 	/** The socket connector store. */
       
   111 	MSocketConnectorStore&		iStore;
       
   112 	/**	The socket controller factory.*/
       
   113 	MSocketControllerFactory&	iSocketControllerFactory;
       
   114 	/** The comms info provider. */
       
   115 	MCommsInfoProvider&			iCommsInfoProvider;
       
   116 	/** The state of the socket connector. */
       
   117 	TConnectState				iState;
       
   118 	/** The host resolver session. */
       
   119 	RHostResolver				iHostResolver;
       
   120 	/** The socket connect observer. */
       
   121 	MSocketConnectObserver*		iObserver;
       
   122 	/**	The host name/IP address for the remote client.*/
       
   123 	HBufC*						iHost;
       
   124 	/**	The port number on remote host with which to connect to */
       
   125 	TUint16						iPort;
       
   126 	/** The DNS entry object for the remote client */
       
   127 	TNameEntry					iHostDnsEntry;
       
   128 	/** The IP address */
       
   129 	TInetAddr					iAddress;
       
   130 	/**	The socket object that is connecting to the remote client */
       
   131 	CSocket*					iConnectingSocket;
       
   132 	};
       
   133 
       
   134 #endif	// __CSOCKETCONNECTOR_H__