internetradio2.0/streamsourceinc/irstreamsource.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:  Manages the entire connection.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef IRSTREAMSOURCE_H
       
    20 #define IRSTREAMSOURCE_H
       
    21 
       
    22 #include <e32base.h>
       
    23 
       
    24 #include "irctrlcommand.h"
       
    25 #include "irsockettimeouttimer.h"
       
    26 #include "irstationconnection.h"
       
    27 #include "irstationdataobserver.h"
       
    28 
       
    29 
       
    30 // Constants
       
    31 const TInt KBufferingTimeOut = 60000000;
       
    32 
       
    33 class CIRMetadataHandler;
       
    34 class CIRNetworkController;
       
    35 class MIRStreamSourceObserver;
       
    36 
       
    37 /**
       
    38  * This class acts as a manager class for the streamsource component
       
    39  *
       
    40  * @code
       
    41  *
       
    42  * // Create a stream source object which is used for streaming data
       
    43  * // iObserver is the reference of the observer object which is called
       
    44  * // for issuing call backs.
       
    45  * CIRStreamSource iStreamSource = CIRStreamSource::NewL(iObserver);
       
    46  *
       
    47  * // Called to connect to the channel server iUrl specifying the 
       
    48  * // url to be connect to.
       
    49  * iStreamSource->ConnectToServerL(iUrl);
       
    50  *
       
    51  * // Called by the media engine to indicate that its buffers are to
       
    52  * // to be filled and iInputBuffer is the reference of the buffer to
       
    53  * // which data is to be copied
       
    54  * iStreamSource->FilltheBuffer(iInputbuffer);
       
    55  *
       
    56  * // Called to cancel a channel server connection request
       
    57  * iStreamSource->CancelRequest();
       
    58  *
       
    59  * // Called by the mediaclient to know the content-type
       
    60  * // of the audio stream
       
    61  * iStreamSource->ContentType();
       
    62  *
       
    63  * @endcode
       
    64  */ 
       
    65 
       
    66 NONSHARABLE_CLASS ( CIRStreamSource ): public CBase, public MIRStreamFill,
       
    67 	public MIRSocketTimeoutNotifier, public MIRStationConnectionObserver,
       
    68 	 public MIRStationDataObserver
       
    69 	{
       
    70 public:
       
    71 
       
    72 	/** 
       
    73 	 *  Initiates a connection to the url.
       
    74 	 *
       
    75 	 *  @param aUrl Url of the channel server to connect to.
       
    76 	 */
       
    77 	IMPORT_C void ConnectToServerL(const TDesC& aUrl);
       
    78 
       
    79 	/** 
       
    80 	 *  Reinitiates a connection to the url by
       
    81      *
       
    82 	 *  @param aUrl Url of the channel server to connect to.
       
    83 	 */
       
    84 	IMPORT_C void ReconnectL(const TDesC& aUrl );
       
    85 
       
    86 	/** 
       
    87 	 *  Creates an Instance of CIRStreamSource
       
    88 	 *  @param aObserver Reference to the StreamSource Observer
       
    89 	 *  @return CIRStreamSource* pointer to the created CIRStreamSource object
       
    90 	 */	
       
    91 	IMPORT_C static CIRStreamSource* NewL(MIRStreamSourceObserver& aObserver);
       
    92 
       
    93 	/** 
       
    94 	 *  Fills the buffer with the data from the stream
       
    95 	 *  @param aInputBuffer Reference to the Input Buffer
       
    96 	 */	
       
    97 	IMPORT_C void FilltheBuffer(TDes8& aInputBuffer);
       
    98 
       
    99 	/** 
       
   100 	 *  Cancels the connection request
       
   101 	 */	
       
   102 	IMPORT_C void CancelRequest();
       
   103 
       
   104 	/** 
       
   105 	 *  Returns the content type header information of the channel
       
   106 	 *  @return const TDesC8& content type header information of the channel
       
   107 	 */	
       
   108 	IMPORT_C const TDesC8& ContentTypeL();
       
   109 
       
   110 	/** 
       
   111 	 *  Default C++ Destructor
       
   112 	 */
       
   113 	virtual ~CIRStreamSource();
       
   114 
       
   115 private:
       
   116 
       
   117 	/** 
       
   118 	 *  Creates a connection object and initiates the connection
       
   119 	 *  to channel server
       
   120 	 */	
       
   121 	void DoConnectL(const TDesC& aUrl);
       
   122 
       
   123 	/** 
       
   124 	 *  Default Constructor
       
   125 	 *  @param aObserver Reference to StreamSource observer
       
   126 	 */
       
   127 	CIRStreamSource(MIRStreamSourceObserver& aObserver);
       
   128 
       
   129 	/** 
       
   130 	 *  2nd Phase construction.
       
   131 	 */
       
   132 	void ConstructL();
       
   133 
       
   134 //from base class MIRStationConnectionObserver
       
   135 
       
   136     /**
       
   137      * From base class MIRStationConnectionObserver.
       
   138      *
       
   139      * @see MIRStationConnectionObserver::ConnectionSuccessful()
       
   140      */
       
   141 	void ConnectionSuccessful( CIRStationConnection* aConnection );
       
   142 
       
   143     /**
       
   144      * From base class MIRStationConnectionObserver.
       
   145      *
       
   146      * @see MIRStationConnectionObserver::ConnectionError()
       
   147      */
       
   148 	void ConnectionError( CIRStationConnection* aConnection, TInt aErrorCode );
       
   149 
       
   150 //	from base class MIRSocketTimeoutNotifier
       
   151      
       
   152     /**
       
   153      * From base class MIRSocketTimeoutNotifier.
       
   154      *
       
   155      * @see MIRSocketTimeoutNotifier::TimerExpired()
       
   156      */
       
   157 	void TimerExpired();	
       
   158 
       
   159 // from base class MIRStationDataObserver
       
   160 
       
   161     /**
       
   162      * From base class MIRStationDataObserver.
       
   163      *
       
   164      * @see MIRStationDataObserver::MetadataReceived()
       
   165      */
       
   166     void MetadataReceived( const CIRMetaData& aMetaData );
       
   167 
       
   168     /**
       
   169      * From base class MIRStationDataObserver.
       
   170      *
       
   171      * @see MIRStationDataObserver::AudioDataEvent()
       
   172      */
       
   173     void AudioDataEvent( const TInt aResponseCode,	TInt aValue );
       
   174 
       
   175     /**
       
   176      * Schedules an asynchronous cleanup for given connection.
       
   177      *
       
   178      * @param aConnection The connection to be deleted.
       
   179      */
       
   180     void AsyncCleanupConnection( CIRStationConnection* aConnection );
       
   181 
       
   182     /**
       
   183      * Callback method that performs the actual deletion of connections.
       
   184      *
       
   185      * @param aSelfPtr Pointer argument given when the callback/timer is created.
       
   186      * @return KErrNone Specified in the function pointer declaration.
       
   187      */	
       
   188     static TInt StaticConnectionCleanupCallback( TAny* aSelfPtr );	
       
   189 
       
   190 private:
       
   191 
       
   192 	/**
       
   193 	 * Handle to the Network controller used to get the reference
       
   194 	 * of the RSocketServ and RConnection. 
       
   195 	 * Not owned.
       
   196 	 */
       
   197     CIRNetworkController* iNetworkControllerHandle;
       
   198 
       
   199 	/**
       
   200 	 * Timer for handling timeouts. 
       
   201 	 * Owned
       
   202 	 */
       
   203     CIRSocketTimeOutTimer* iSocketTimer;
       
   204 
       
   205 	/**
       
   206 	 * Pointer to the connection to current channel server. 
       
   207 	 * Not owned.
       
   208 	 */
       
   209     CIRStationConnection* iCurrentConnection;
       
   210 
       
   211 	/**
       
   212 	 * Pointer to the connection to previous channel server. 
       
   213 	 * Not owned.
       
   214 	 */
       
   215     CIRStationConnection* iNewConnection;
       
   216 
       
   217 	/**
       
   218 	 * Array of pointers to connections. 
       
   219 	 * Owned.
       
   220 	 */
       
   221     RPointerArray<CIRStationConnection> iConnections;
       
   222     
       
   223     /**
       
   224      * Timer for delayed cleanup of connections. 
       
   225      * Owned.
       
   226      */	 
       
   227     CPeriodic* iConnectionCleanupTimer;
       
   228 
       
   229 	/**
       
   230 	 * Reference of the Stream source observer
       
   231 	 */
       
   232     MIRStreamSourceObserver& iStreamSourceObserver;
       
   233 	
       
   234 	/**
       
   235 	 * Is set when reconnecting to a channel and reset 
       
   236 	 * when connecting for the first time
       
   237 	 */
       
   238     TBool iReConnecting;
       
   239 
       
   240 	};
       
   241 
       
   242 #endif //IRSTREAMSOURCE_H
       
   243 
       
   244 
       
   245