internetradio2.0/streamsourceinc/irsocketopener.h
changeset 0 09774dfdd46b
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Opens TCP connection.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef IRSOCKETOPENER_H
       
    20 #define IRSOCKETOPENER_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <es_sock.h>
       
    24 
       
    25 #include "irsockettimeouttimer.h"
       
    26 
       
    27 class RSocket;
       
    28 class TSockAddr;
       
    29 class CIRStationConnection;
       
    30 
       
    31 
       
    32 /**
       
    33  * Creates the socket connection a channel server
       
    34  */
       
    35 NONSHARABLE_CLASS ( CIRSocketOpener ) : public CActive,	public MIRSocketTimeoutNotifier
       
    36     {
       
    37 public:
       
    38     
       
    39     /**
       
    40      * Standard Symbian two-phase construction
       
    41      *
       
    42      * @param aSocket Socket to be opened.
       
    43      * @param aOwner The owner of this CIRSocketOpener
       
    44      * @return Instance of CIRSocketOpener
       
    45      */
       
    46     static CIRSocketOpener* NewL( RSocket& aSocket, CIRStationConnection& aOwner );
       
    47     
       
    48     /**
       
    49      * Default C++ destructor
       
    50      */
       
    51     ~CIRSocketOpener();
       
    52     
       
    53     /**
       
    54      * Called when the timer times out
       
    55      */
       
    56     void TimerExpired();
       
    57     
       
    58     /**
       
    59      * Connects to the channel server
       
    60      *
       
    61      * @param aUri URI of channel server.
       
    62      */
       
    63     void ConnectL( const TDesC& aUri );
       
    64 
       
    65 protected:
       
    66 	
       
    67 	 // from base class CActive
       
    68 	 
       
    69     /**
       
    70      * From base class CActive
       
    71      *
       
    72      * @see CActive::RunL();
       
    73      */
       
    74     void RunL();
       
    75     
       
    76     /**
       
    77      * From base class CActive
       
    78      *
       
    79      * @see CActive::DoCancel();
       
    80      */
       
    81     void DoCancel();
       
    82 
       
    83 private:
       
    84 
       
    85     /**
       
    86     * Constructor.
       
    87     */
       
    88     CIRSocketOpener( RSocket& aSocket, CIRStationConnection& aOwner );
       
    89 
       
    90     /**
       
    91     * Standard Symbian second-phase construction.
       
    92     */
       
    93     void ConstructL();
       
    94     
       
    95     /**
       
    96      * Issues asynchronous resolving of the DNS name to IP address
       
    97      */
       
    98     void ResolveAddress();
       
    99 	
       
   100 	/**
       
   101      * Issues asynchronous connecting to the channel server
       
   102      */
       
   103 	void ConnectToAddress();
       
   104 	
       
   105 	/**
       
   106      * Extracts the relevant URI components to member variables.
       
   107      *
       
   108      * @param aUri URI of the channel server
       
   109      */
       
   110     TBool ExtractUriComponentsL(const TDesC& aUri);
       
   111 
       
   112 private:
       
   113 	
       
   114 	/**
       
   115      * The states of CIRSocketOpener
       
   116      */
       
   117     enum TIRSocketOpenerState
       
   118 		{
       
   119 		EIRIdle,
       
   120 		EIRResolving,
       
   121 		EIRConnecting,
       
   122 		EIRReady
       
   123 		};
       
   124 
       
   125 private:
       
   126 		
       
   127 	/**
       
   128      * Used for timeout mechanism. 
       
   129      * Owned.
       
   130      */
       
   131 	CIRSocketTimeOutTimer* iSocketTimer;    
       
   132 
       
   133 	/**
       
   134      * Contains the host part of the URI. 
       
   135      * Owned.
       
   136      */
       
   137 	RBuf iHost;
       
   138 	
       
   139 	/**
       
   140      * For DNS resolving. 
       
   141      * Owned.
       
   142      */
       
   143 	RHostResolver iResolver;
       
   144     
       
   145 	/**
       
   146      * The current state of CIRSocketOpener
       
   147      */
       
   148 	TIRSocketOpenerState iState;
       
   149 
       
   150 	/**
       
   151      * The address of the server in the form understood by the socket. 
       
   152      * Contains the IP address and the port.
       
   153      */
       
   154 	TSockAddr iSockAddr;
       
   155 	
       
   156 	/**
       
   157      * Contains the resolved host information.
       
   158      */
       
   159 	TNameEntry iResolvedHostInfo;
       
   160 
       
   161     /**
       
   162      * Contains the port of the URI.
       
   163      */	
       
   164 	TInt iPort;
       
   165 	
       
   166 	/**
       
   167 	 * Socket to be opened.
       
   168 	 */
       
   169 	RSocket& iSocket;
       
   170 
       
   171     /**
       
   172      * The owner in the whole-part relation.
       
   173      */	
       
   174 	CIRStationConnection& iOwner;
       
   175     };
       
   176 
       
   177 #endif // IRSOCKETOPENER_H
       
   178