bluetoothengine/btsac/src/btsacStateSuspended.cpp
changeset 0 f63038272f30
child 1 6a1fe72036e3
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  In this state, BTSAC is waiting for open audio request.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "btsacStateSuspended.h"
       
    23 #include "btsacStateListening.h"
       
    24 #include "btsacStateStreaming.h"
       
    25 #include "btsacStateConnected.h"
       
    26 #include "btsacStateAborting.h"
       
    27 #include "btsacactive.h"
       
    28 #include "btsacSEPManager.h"
       
    29 #include "btsacStreamerController.h"
       
    30 #include "btsacGavdp.h"
       
    31 #include "debug.h"
       
    32 #include <e32property.h>
       
    33 #include "btaudioremconpskeys.h"
       
    34 
       
    35 // A2DP codec-specific element definitions
       
    36 // in bluetoothAV.h
       
    37 using namespace SymbianBluetoothAV;
       
    38 
       
    39 
       
    40 // ================= MEMBER FUNCTIONS =======================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CBtsacSuspended::NewL
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CBtsacSuspended* CBtsacSuspended::NewL(CBTSAController& aParent)
       
    47     {
       
    48     CBtsacSuspended* self = new( ELeave ) CBtsacSuspended(aParent);
       
    49     return self;
       
    50     }    
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CBtsacSuspended::CBtsacSuspended
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CBtsacSuspended::CBtsacSuspended(CBTSAController& aParent)
       
    57 :   CBtsacState(aParent, EStateSuspended), iOpenAudioReq(EFalse)
       
    58     {
       
    59     }
       
    60   
       
    61 // -----------------------------------------------------------------------------
       
    62 // CBtsacSuspended::~CBtsacSuspended
       
    63 // -----------------------------------------------------------------------------
       
    64 //    
       
    65 CBtsacSuspended::~CBtsacSuspended()
       
    66     {
       
    67     TRACE_FUNC
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CBtsacSuspended::EnterL
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CBtsacSuspended::EnterL()
       
    75     {
       
    76 	TRACE_STATE(_L("[BTSAC State] Suspended"))
       
    77 	_LIT(KName, "CBtsacStateSuspended");
       
    78 	const TDesC& Name = KName;
       
    79 	Parent().iGavdp->RegisterObserver(this, Name);
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CBtsacSuspended::CancelActionL
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CBtsacSuspended::CancelActionL(TInt aError, TBTSACGavdpResetReason aGavdpReset)
       
    87 	{
       
    88 	TRACE_FUNC
       
    89 	Parent().CompletePendingRequests(KOpenAudioReq, aError);
       
    90 	Parent().ChangeStateL(CBtsacListening::NewL(Parent(), aGavdpReset, aError));
       
    91 	}
       
    92     
       
    93 // -----------------------------------------------------------------------------
       
    94 // CBtsacSuspended::OpenAudioLinkL
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CBtsacSuspended::OpenAudioLinkL(const TBTDevAddr& aAddr)
       
    98 	{  
       
    99 	TRACE_FUNC
       
   100 	TAvdtpSEPInfo SEPInfo;
       
   101 	if (Parent().iRemoteSEPs->GetInfo(Parent().GetSEPIndex(), SEPInfo) || (aAddr != Parent().GetRemoteAddr()))
       
   102 		{
       
   103 		TRACE_INFO((_L("CBtsacSuspended::OpenAudioLinkL() Couldn't retrieve SEP Info!")))
       
   104 		Parent().CompletePendingRequests(KOpenAudioReq, KErrGeneral);
       
   105        	return;
       
   106 		}
       
   107 	iOpenAudioReq = ETrue;
       
   108 	Parent().SetRemoteAddr(aAddr);
       
   109 	TSEID remoteSEPid = SEPInfo.SEID();
       
   110 	Parent().iGavdp->StartStreams(remoteSEPid);
       
   111 	}
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CBtsacSuspended::CancelOpenAudioL
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CBtsacSuspended::CancelOpenAudioL(const TBTDevAddr& /*aAddr*/)
       
   118     {
       
   119     TRACE_FUNC
       
   120 	CancelActionL(KErrCancel, EGavdpResetReasonGeneral);
       
   121     }
       
   122     
       
   123 // -----------------------------------------------------------------------------
       
   124 // CBtsacSuspended::DisconnectL
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CBtsacSuspended::DisconnectL()
       
   128 	{
       
   129 	TRACE_FUNC
       
   130 	Parent().CompletePendingRequests(KDisconnectReq, KErrNone);
       
   131 	CancelActionL(KErrCancel, EGavdpResetReasonGeneral);
       
   132 	}
       
   133 	
       
   134 // -----------------------------------------------------------------------------
       
   135 // CBtsacSuspended::GAVDP_StartStreamsConfirm()
       
   136 // -----------------------------------------------------------------------------
       
   137 //    
       
   138 void CBtsacSuspended::GAVDP_StartStreamsConfirm()
       
   139 	{
       
   140 	TRACE_FUNC
       
   141 	if ( Parent().iStreamer->StartStream(Parent().iStreamingSockets[0], Parent().iStreamer->FrameLength()) != KErrNone ) 
       
   142 	 	{
       
   143 		TRACE_INFO((_L("CBtsacSuspended::GAVDP_StartStreamsConfirm() [ERR] Could not start streaming!")))
       
   144 		TInt err = Parent().AbortStream();
       
   145 		if(err)
       
   146 			{
       
   147 			TRACE_INFO((_L("CBtsacSuspended::GAVDP_StartStreamsConfirm() Couldn't abort stream.")))
       
   148 			}
       
   149 		TRAP_IGNORE(CancelActionL(KErrCancel, EGavdpResetReasonGeneral));
       
   150 	 	}
       
   151 	 else
       
   152 	 	{
       
   153 	 	Parent().CompletePendingRequests(KOpenAudioReq, KErrNone);
       
   154 		TRAP_IGNORE(Parent().ChangeStateL(CBtsacStreaming::NewL(Parent(), EAudioOpenedByAFW, EFalse)));
       
   155 	 	}
       
   156 	}
       
   157 	
       
   158 // -----------------------------------------------------------------------------
       
   159 // CBtsacSuspended::GAVDP_StartIndication
       
   160 // -----------------------------------------------------------------------------
       
   161 //      
       
   162 TInt CBtsacSuspended::GAVDP_StartIndication(TSEID aLocalSEID)
       
   163 	{
       
   164 	TRACE_INFO((_L("CBtsacSuspended::GAVDP_StartIndication() aLocalSEID: %d"), aLocalSEID.SEID()))	
       
   165 	(void)aLocalSEID;
       
   166 	// Accessory has send this indication.
       
   167 	// TStateStreaming state can use this indication to start audio automatically then later.
       
   168 	RProperty::Set(KBTAudioRemCon, KBTAudioPlayerControl, EBTAudioResumePlayer);
       
   169 	TRAPD(err, Parent().ChangeStateL(CBtsacStreaming::NewL(Parent(), EAudioOpenedByAcc, EFalse)));
       
   170 	if(err)
       
   171 		{
       
   172 		return KErrNoMemory;
       
   173 		}
       
   174 	return KErrNone;
       
   175 	}
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CBtsacSuspended::GAVDP_ReleaseIndication
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CBtsacSuspended::GAVDP_ReleaseIndication(TSEID aSEID)
       
   182 	{
       
   183 	TRACE_INFO((_L("CBtsacSuspended::GAVDP_ReleaseIndication() aSEID:%d"), aSEID.SEID()))	
       
   184 	(void)aSEID; 
       
   185 	Parent().AccessoryClosedAudio(Parent().GetRemoteAddr());
       
   186 	Parent().CleanSockets();
       
   187 	Parent().CompletePendingRequests(KOpenAudioReq, KErrCancel);
       
   188 	TRAP_IGNORE(Parent().ChangeStateL(CBtsacConnected::NewL(Parent(), EConnExists)));
       
   189 	}
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CBtsacSuspended::HandleGavdpErrorL
       
   193 // -----------------------------------------------------------------------------
       
   194 //	
       
   195 void CBtsacSuspended::HandleGavdpErrorL(TInt aError)
       
   196 	{
       
   197 	TRACE_FUNC
       
   198 	TInt err = KErrNone;
       
   199 	
       
   200 	switch (aError)
       
   201 		{
       
   202 		case KErrAvdtpRequestTimeout: // -18005
       
   203 			{
       
   204 			TRACE_INFO((_L("CBtsacSuspended::HandleGavdpErrorL() Request TIMEOUT")))
       
   205 			err = Parent().AbortStream();
       
   206 			if(!err)
       
   207 				{
       
   208 				// Complete pending request(s) in Aborting state
       
   209 				Parent().ChangeStateL(CBtsacAborting::NewL(Parent()));
       
   210 				}
       
   211 			else
       
   212 				{
       
   213 				CancelActionL(KErrDisconnected, EGavdpResetReasonGeneral);
       
   214 				}
       
   215 			break;
       
   216 			}
       
   217 		case (KErrAvdtpSignallingErrorBase - EAvdtpBadState): // -18094
       
   218 			{
       
   219 			if(iOpenAudioReq)
       
   220 				{
       
   221 				err = Parent().AbortStream();
       
   222 				if(!err)
       
   223 					{
       
   224 					// Complete Audio request in Aborting state
       
   225 					Parent().ChangeStateL(CBtsacAborting::NewL(Parent()));
       
   226 					}
       
   227 				else
       
   228 					{
       
   229 					CancelActionL(KErrDisconnected, EGavdpResetReasonGeneral);
       
   230 					}
       
   231 				}
       
   232 			else
       
   233 				{					
       
   234 				// For some reason remote rejected our suspend command (which was initiated in streaming state).
       
   235 				// According to the specification it is acceptor's responsibilty to cope with this situation,
       
   236 				// so we can stay in suspended state.
       
   237 				// For safety's sake complete close audio request if any.
       
   238 		        Parent().CompletePendingRequests(KCloseAudioReq, KErrNone);
       
   239 				}
       
   240 		    break;
       
   241 			}
       
   242 		case KErrHCILinkDisconnection: // -6305
       
   243 		case KErrDisconnected: // -36
       
   244 			{
       
   245 			TRACE_INFO((_L("CBtsacSuspended::HandleGavdpErrorL() Signalling disconnected.")))
       
   246 			CancelActionL(aError, EGavdpResetReasonNone);
       
   247 			break;
       
   248 			}
       
   249 		default:
       
   250 			{
       
   251 			// Unknown error. For safety's sake let's disconnect a2dp link and inform btaudioman
       
   252 			TRACE_INFO((_L("CBtsacSuspended::HandleGavdpErrorL() Unknown error, goes to listening")))
       
   253 			CancelActionL(KErrDisconnected, EGavdpResetReasonGeneral);
       
   254 			break;
       
   255 			}
       
   256 		}
       
   257 	}
       
   258 
       
   259 //  End of File