internetradio2.0/streamsourceinc/irstationconnection.h
changeset 14 896e9dbc5f19
parent 12 608f67c22514
child 15 065198191975
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
     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:  Represents a connection to a radio station.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MIRSTATIONCONNECTIONOBSERVER_H
       
    20 #define MIRSTATIONCONNECTIONOBSERVER_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <es_sock.h>
       
    24 
       
    25 class CIRStationConnection;
       
    26 class MIRStationDataObserver;
       
    27 class CIRSocketOpener;
       
    28 class CIRIcyFlowInitiator;
       
    29 class CIRIcyFlowReader;
       
    30 class TChannelInfo;
       
    31 
       
    32 /**
       
    33  * Observer interface for the CIRStationConnection.
       
    34  */
       
    35 class MIRStationConnectionObserver
       
    36 	{
       
    37 public:	
       
    38 	/**
       
    39 	 * Called to indicate sucessful connection
       
    40 	 *
       
    41 	 * @param aConnection Pointer to successful connection.
       
    42 	 */	
       
    43 	virtual void ConnectionSuccessful( CIRStationConnection* aConnection ) = 0;
       
    44 	
       
    45 	/*
       
    46 	 * Called to indicate failure in connection.
       
    47 	 *
       
    48 	 * @param aConnection The connection that failed.
       
    49 	 * @param aErrorCode Error code indicating the type of the error
       
    50 	 */
       
    51 	virtual void ConnectionError( CIRStationConnection* aConnection, TInt aErrorCode ) = 0;
       
    52     };
       
    53 
       
    54 
       
    55 const TInt KMAXMETABUFLENGTH = 256;
       
    56 /**
       
    57  * Holds the meta data information 
       
    58  */
       
    59 class TChannelInfo
       
    60 	{
       
    61 public:
       
    62 	TBuf8<KMAXMETABUFLENGTH>	iStationName;
       
    63 	TBuf8<KMAXMETABUFLENGTH>	iGenre;
       
    64 	TBuf8<KMAXMETABUFLENGTH>	iBitRate;
       
    65 	TBuf8<KMAXMETABUFLENGTH>	iContentType;
       
    66 	TBuf8<KMAXMETABUFLENGTH> 	iSongTitle;
       
    67 	TBuf8<KMAXMETABUFLENGTH> 	iArtistName;
       
    68 	TInt iMetaInterval;
       
    69 	TInt iMetaDataTracker;
       
    70 	TInt iReadSize;
       
    71 	TInt iAudioDataOffset;
       
    72 	};
       
    73 
       
    74 /**
       
    75  * Instance of the class encompasses the connection establishment, error handling and
       
    76  * audio/meta data reading from the stream. 
       
    77  *
       
    78  *
       
    79  */
       
    80 NONSHARABLE_CLASS ( CIRStationConnection ): public CBase
       
    81 	{
       
    82 public:
       
    83     /**
       
    84      * The type of the connection
       
    85      */
       
    86     enum TIRStationConnectionType
       
    87 		{
       
    88 		EIRUndefined,
       
    89 		EIRPermanent,
       
    90 		EIRCandidate,
       
    91 		EIRDying
       
    92 		};
       
    93 	
       
    94 public:
       
    95 
       
    96 
       
    97 	/** 
       
    98 	 * Creates an instance of CIRStationConnection
       
    99 	 *
       
   100 	 * @param aConnectionObserver   Observer for connection related events.
       
   101 	 * @param aDataObserver         Observer for the audio/meta data.
       
   102 	 * @return Instance of CIRStationConnection
       
   103 	 */	
       
   104     static CIRStationConnection* NewL( MIRStationConnectionObserver& aConnectionObserver,
       
   105     			 MIRStationDataObserver& aDataObserver );
       
   106 
       
   107 	/** 
       
   108 	 *  Initiates a connection to internet radio station specified by the URI.
       
   109      *
       
   110 	 *  @param aUri URI of the radio station server.
       
   111 	 */
       
   112     void ConnectL( const TDesC& aUri );
       
   113 
       
   114     /**
       
   115      * Closes the connection. First cancels any pending asynchronous request and 
       
   116      * then closes the socket.
       
   117      */
       
   118     void Close();
       
   119 
       
   120     /**
       
   121      * Sets the connection type.
       
   122      *
       
   123      * @param aType New connection type 
       
   124      */
       
   125     void SetConnectionType( TIRStationConnectionType aType );
       
   126     
       
   127     /**
       
   128      * Gets the connection type.
       
   129      *
       
   130      * @return The type of the connection.
       
   131      */    
       
   132     TIRStationConnectionType ConnectionType() const;
       
   133     
       
   134     /**
       
   135      * Gets the URI associated with the connection.
       
   136      *
       
   137      * @return URI associated with the connection.
       
   138      */
       
   139     const TDesC& Uri() const;
       
   140 
       
   141     /**
       
   142      * Gets the content type of the connected stream.
       
   143      *
       
   144      * @return The content type of the connected stream.
       
   145      */
       
   146     const TDesC8& ContentType() const;
       
   147     
       
   148 	/** 
       
   149 	 *  Fills the buffer with the data from the stream.
       
   150 	 *
       
   151 	 *  @param aInputBuffer Buffer into which the data is copied.
       
   152 	 */	
       
   153     void FillBuffer( TDes8& aInputBuffer );
       
   154 
       
   155 	/** 
       
   156 	 *  Default C++ Destructor
       
   157 	 */
       
   158 	~CIRStationConnection();
       
   159 	
       
   160 public:
       
   161     // Methods for composite parts to call
       
   162     /**
       
   163      * Called by a composite part when the transport layer session is ready.
       
   164      */
       
   165 	void ConnectionReady();
       
   166 	
       
   167 	/**
       
   168 	 * Called by a composite part when the application layer session is ready.
       
   169 	 */
       
   170 	void FlowReady();		
       
   171 	
       
   172 	/*
       
   173      * Called by a composite part to report an error in connection.
       
   174      *
       
   175 	 * @param aErrorCode type of error
       
   176 	 */
       
   177 	void ConnectionError( TInt aErrorCode );
       
   178 
       
   179 private:
       
   180 
       
   181 	/** 
       
   182 	 *  Default Constructor
       
   183 	 * @param aConnectionObserver   Observer for connection related events.
       
   184 	 * @param aDataObserver         Observer for the audio/meta data.
       
   185 	 * @return Instance of CIRStationConnection
       
   186      */
       
   187 	CIRStationConnection( MIRStationConnectionObserver& aStationConnectionObserver,
       
   188 					 MIRStationDataObserver& aDataObserver );
       
   189 
       
   190 	/** 
       
   191 	 *  2nd Phase construction.
       
   192 	 */
       
   193 	void ConstructL();
       
   194 
       
   195 
       
   196 private:
       
   197 
       
   198 	/**
       
   199 	 * Starts the TCP connection. 
       
   200 	 * Owned.
       
   201 	 */
       
   202 	CIRSocketOpener* iSocketOpener;
       
   203 
       
   204     /**
       
   205      * Starts the ICY session. 
       
   206      * Owned.
       
   207      */
       
   208     CIRIcyFlowInitiator* iIcyFlowInitiator;
       
   209 
       
   210 	/**
       
   211 	 * Reads the ICY session. 
       
   212 	 * Owned.
       
   213 	 */
       
   214 	CIRIcyFlowReader* iIcyFlowReader;
       
   215 
       
   216     /** 
       
   217      * The socket. 
       
   218      * Owned.
       
   219      */
       
   220 	RSocket iSocket;
       
   221 	
       
   222     /**
       
   223      * URI of the radio channel. 
       
   224      * Owned.
       
   225      */
       
   226     RBuf iUri;
       
   227 
       
   228     /**
       
   229      * The connection event observer 
       
   230      */
       
   231 	MIRStationConnectionObserver& iConnectionObserver;
       
   232 	
       
   233 	/**
       
   234 	 * Audio/metadata observer.
       
   235 	 */
       
   236 	MIRStationDataObserver& iDataObserver;
       
   237 
       
   238     /**
       
   239      * Information related to connected ICY channel.
       
   240      */
       
   241     TChannelInfo iChannelInfo;
       
   242 
       
   243     /**
       
   244      * Type of the connection.
       
   245      */    
       
   246     TIRStationConnectionType iConnectionType;
       
   247 	};
       
   248 
       
   249 #endif // MIRSTATIONCONNECTIONOBSERVER_H