internetradio2.0/streamsourcesrc/irstationconnection.cpp
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:  Station connection implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "irstationconnection.h"
       
    20 #include "irdebug.h"
       
    21 #include "iricyflowinitiator.h"
       
    22 #include "iricyflowreader.h"
       
    23 #include "irsocketopener.h"
       
    24 #include "irstationdataobserver.h"
       
    25 
       
    26 // --------------------------------------------------------------------------- 
       
    27 //  CIRStationConnection::NewL
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CIRStationConnection* CIRStationConnection::NewL( 
       
    31 												MIRStationConnectionObserver& aConnectionObserver, 
       
    32                                                   MIRStationDataObserver& aDataObserver )
       
    33     {
       
    34 	CIRStationConnection* self = new ( ELeave ) CIRStationConnection( aConnectionObserver, 
       
    35 																	aDataObserver );
       
    36 	CleanupStack::PushL(self);
       
    37 	self->ConstructL();
       
    38     CleanupStack::Pop(self);
       
    39 	return self;
       
    40     }
       
    41 
       
    42 // --------------------------------------------------------------------------- 
       
    43 //  CIRStationConnection::~CIRStationConnection
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CIRStationConnection::~CIRStationConnection()
       
    47     {
       
    48     delete iSocketOpener;
       
    49     
       
    50     delete iIcyFlowInitiator;
       
    51     
       
    52     delete iIcyFlowReader;
       
    53     
       
    54     iSocket.Close();
       
    55     iUri.Close();
       
    56     }
       
    57 
       
    58 // --------------------------------------------------------------------------- 
       
    59 //  CIRStationConnection::CIRStationConnection
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CIRStationConnection::CIRStationConnection( MIRStationConnectionObserver& aConnectionObserver, 
       
    63 											MIRStationDataObserver& aDataObserver ) :
       
    64     iConnectionObserver( aConnectionObserver ), iDataObserver( aDataObserver )
       
    65     {
       
    66     }
       
    67 
       
    68 // --------------------------------------------------------------------------- 
       
    69 //  CIRStationConnection::ConstructL
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CIRStationConnection::ConstructL()
       
    73     {
       
    74 	IRLOG_DEBUG( "CIRStationConnection::ConstructL" );    
       
    75     iConnectionType = EIRUndefined;
       
    76     }
       
    77     
       
    78 // --------------------------------------------------------------------------- 
       
    79 //  CIRStationConnection::ConnectL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 void CIRStationConnection::ConnectL( const TDesC& aUri )
       
    83     {
       
    84 	IRLOG_DEBUG( "CIRStationConnection::ConnectL" );        
       
    85     iUri.Close();
       
    86     iUri.CreateL( aUri );
       
    87     
       
    88     iConnectionType = EIRCandidate;
       
    89 
       
    90     delete iSocketOpener;	
       
    91     iSocketOpener = NULL;
       
    92     
       
    93     iSocketOpener = CIRSocketOpener::NewL( iSocket, *this );
       
    94     iSocketOpener->ConnectL( iUri );
       
    95 	IRLOG_DEBUG( "CIRStationConnection::ConnectL - Exiting" );            
       
    96     }
       
    97 
       
    98 // --------------------------------------------------------------------------- 
       
    99 //  CIRStationConnection::Close
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 void CIRStationConnection::Close()
       
   103     {
       
   104 	IRLOG_DEBUG( "CIRStationConnection::Close" );    
       
   105     if ( iSocketOpener )
       
   106         {
       
   107         iSocketOpener->Cancel();
       
   108         }
       
   109 
       
   110     if ( iIcyFlowInitiator )
       
   111         {
       
   112         iIcyFlowInitiator->Cancel();
       
   113         }
       
   114     
       
   115 	iChannelInfo.iStationName.Zero();
       
   116 	iChannelInfo.iGenre.Zero();
       
   117     iChannelInfo.iBitRate.Zero();
       
   118     iChannelInfo.iContentType.Zero();
       
   119     iChannelInfo.iSongTitle.Zero();
       
   120     iChannelInfo.iArtistName.Zero();
       
   121     iChannelInfo.iMetaInterval = 0;
       
   122     iChannelInfo.iMetaDataTracker = 0;
       
   123     iChannelInfo.iReadSize = 0;
       
   124     iChannelInfo.iAudioDataOffset = 0;
       
   125     
       
   126     if ( iIcyFlowReader )
       
   127         {
       
   128         iIcyFlowReader->Cancel();
       
   129         }
       
   130         
       
   131     iSocket.Close(); 
       
   132 	IRLOG_DEBUG( "CIRStationConnection::Close - Exiting." );           
       
   133     }
       
   134 
       
   135 // --------------------------------------------------------------------------- 
       
   136 //  CIRStationConnection::SetConnectionType
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void CIRStationConnection::SetConnectionType( TIRStationConnectionType aType )
       
   140     {
       
   141     iConnectionType = aType;
       
   142     }
       
   143 
       
   144 // --------------------------------------------------------------------------- 
       
   145 //  CIRStationConnection::ConnectionType
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 CIRStationConnection::TIRStationConnectionType CIRStationConnection::ConnectionType() const
       
   149     {
       
   150     return iConnectionType;
       
   151     }
       
   152 
       
   153 // --------------------------------------------------------------------------- 
       
   154 //  CIRStationConnection::Uri
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 const TDesC& CIRStationConnection::Uri() const
       
   158     {
       
   159     return iUri;
       
   160     }
       
   161 
       
   162 // --------------------------------------------------------------------------- 
       
   163 //  CIRStationConnection::ContentType
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 const TDesC8& CIRStationConnection::ContentType() const
       
   167 	{
       
   168 	return iChannelInfo.iContentType;
       
   169 	}
       
   170 
       
   171 // --------------------------------------------------------------------------- 
       
   172 //  CIRStationConnection::FillBuffer
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 void CIRStationConnection::FillBuffer( TDes8& aInputBuffer )
       
   176     {
       
   177 	__ASSERT_DEBUG( iIcyFlowReader, User::Invariant() );				    
       
   178 
       
   179 /*lint -save -e774 (Info -- Boolean within 'if' always evaluates to True )*/
       
   180     if ( iIcyFlowReader )    
       
   181         {
       
   182         iIcyFlowReader->FillBuffer( aInputBuffer );
       
   183         }
       
   184 /*lint -restore*/        
       
   185     }
       
   186 
       
   187 // --------------------------------------------------------------------------- 
       
   188 //  CIRStationConnection::ConnectionReady
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void CIRStationConnection::ConnectionReady()
       
   192     {
       
   193 	IRLOG_INFO2( "CIRStationConnection::ConnectionReady (%d).", this );
       
   194     delete iIcyFlowInitiator;    
       
   195     iIcyFlowInitiator = NULL;
       
   196     TRAPD( err, iIcyFlowInitiator = CIRIcyFlowInitiator::NewL( iSocket, iUri, *this, 
       
   197     															iChannelInfo ) )
       
   198     if ( err == KErrNone )
       
   199         {
       
   200         iIcyFlowInitiator->RequestFlow();           
       
   201         }
       
   202     else
       
   203         {
       
   204         ConnectionError( err );
       
   205         }
       
   206 	IRLOG_DEBUG( "CIRStationConnection::ConnectionReady - Exiting." );
       
   207     }
       
   208     
       
   209 // --------------------------------------------------------------------------- 
       
   210 //  CIRStationConnection::FlowReady
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 void CIRStationConnection::FlowReady()    
       
   214     {
       
   215 	IRLOG_INFO2( "CIRStationConnection::FlowReady (conn=%d).", this );    
       
   216     delete iIcyFlowReader;
       
   217     iIcyFlowReader = NULL;
       
   218     TRAPD( err, iIcyFlowReader = CIRIcyFlowReader::NewL( iSocket, *this, iDataObserver,
       
   219     																 iChannelInfo ) )
       
   220     if ( err == KErrNone )
       
   221         {
       
   222         iIcyFlowReader->Start();        
       
   223         iConnectionObserver.ConnectionSuccessful( this );        
       
   224         }
       
   225     else
       
   226         {
       
   227         ConnectionError( err );
       
   228         }
       
   229 	IRLOG_DEBUG( "CIRStationConnection::FlowReady - Exiting." );        
       
   230     }
       
   231 
       
   232 // --------------------------------------------------------------------------- 
       
   233 //  CIRStationConnection::ConnectionError
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 void CIRStationConnection::ConnectionError( TInt aErrorCode )
       
   237     {
       
   238 	IRLOG_ERROR3( "CIRStationConnection::ConnectionError - err=%d, conn=%d.", aErrorCode, this );            
       
   239     Close();
       
   240     iConnectionObserver.ConnectionError( this, aErrorCode );
       
   241 	IRLOG_DEBUG( "CIRStationConnection::ConnectionError - Exiting." ); 
       
   242     }