|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Implements the avdtp signalling transaction |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include <bluetooth/logger.h> |
|
24 #include "btsockettimer.h" |
|
25 #include "avdtpSignallingTransaction.h" |
|
26 #include "avdtpSignallingChannel.h" |
|
27 #include "avdtpServiceInterface.h" |
|
28 #include "avdtputil.h" |
|
29 |
|
30 #ifdef __FLOG_ACTIVE |
|
31 _LIT8(KLogComponent, LOG_COMPONENT_AVDTP); |
|
32 #endif |
|
33 |
|
34 #ifdef _DEBUG |
|
35 PANICCATEGORY("avdtpsigtr"); |
|
36 #endif |
|
37 |
|
38 CSignallingTransaction::CSignallingTransaction(CSignallingChannel& aSignallingChannel, |
|
39 TAvdtpMessage aSignal) |
|
40 : iSignal(aSignal), iSigCh(aSignallingChannel), |
|
41 iTimerSet(EFalse), iPostSendAction(EDiscard) |
|
42 { |
|
43 LOG_FUNC |
|
44 } |
|
45 |
|
46 /*static*/ CSignallingTransaction* CSignallingTransaction::New(CSignallingChannel& aSignallingChannel, |
|
47 TAvdtpMessage aSignal, |
|
48 TAvdtpMessageType aMessageType) |
|
49 { |
|
50 LOG_STATIC_FUNC |
|
51 CSignallingTransaction* self = new CSignallingTransaction(aSignallingChannel, aSignal); |
|
52 if (self) |
|
53 { |
|
54 TInt res = self->Construct(aMessageType); |
|
55 if (res!=KErrNone) |
|
56 { |
|
57 delete self; |
|
58 self = NULL; |
|
59 } |
|
60 } |
|
61 return self; |
|
62 } |
|
63 |
|
64 TInt CSignallingTransaction::Construct(TAvdtpMessageType aMessageType) |
|
65 { |
|
66 LOG_FUNC |
|
67 iMessage = new CAvdtpOutboundSignallingMessage(); |
|
68 if (iMessage) |
|
69 { |
|
70 iMessage->SetType(aMessageType, iSignal); |
|
71 } |
|
72 return iMessage ? KErrNone : KErrNoMemory; |
|
73 } |
|
74 |
|
75 CSignallingTransaction::~CSignallingTransaction() |
|
76 { |
|
77 LOG_FUNC |
|
78 // might be on queue, so dequeue (safe for double queues) |
|
79 iLink.Deque(); |
|
80 CancelTimer(); |
|
81 delete iMessage; |
|
82 } |
|
83 |
|
84 void CSignallingTransaction::StartTimer() |
|
85 { |
|
86 LOG_FUNC |
|
87 CancelTimer(); |
|
88 |
|
89 TCallBack cb(TimerExpired, this); |
|
90 iTimerEntry.Set(cb); |
|
91 BTSocketTimer::Queue(KAvdtpSigRTXTimeout, iTimerEntry); |
|
92 iTimerSet=ETrue; |
|
93 } |
|
94 |
|
95 void CSignallingTransaction::CancelTimer() |
|
96 { |
|
97 LOG_FUNC |
|
98 if (iTimerSet) |
|
99 { |
|
100 BTSocketTimer::Remove(iTimerEntry); |
|
101 iTimerSet = EFalse; |
|
102 } |
|
103 } |
|
104 |
|
105 /*static*/ TInt CSignallingTransaction::TimerExpired(TAny* aTransaction) |
|
106 { |
|
107 LOG_STATIC_FUNC |
|
108 CSignallingTransaction* transaction = reinterpret_cast<CSignallingTransaction*>(aTransaction); |
|
109 ASSERT_DEBUG(transaction->SentAction()==EKeepSetRTX); |
|
110 transaction->Error(KErrAvdtpRequestTimeout); |
|
111 return EFalse; |
|
112 } |
|
113 |
|
114 // error the transaction => tell user |
|
115 // will be due to timeout or signalling channel error etc |
|
116 void CSignallingTransaction::Error(TInt aError) |
|
117 { |
|
118 // remove this transaction from the pending queue |
|
119 iLink.Deque(); |
|
120 |
|
121 // get acp seid from cookie - all cookies are the same at the moment |
|
122 TSEID seid(reinterpret_cast<TUint>(Cookie())); |
|
123 |
|
124 switch (Signal()) |
|
125 { |
|
126 case EAvdtpDiscover: |
|
127 { |
|
128 // no timeout specified in avdtp for Discover |
|
129 __ASSERT_DEBUG(aError!=KErrAvdtpRequestTimeout, Panic(EAvdtpInvalidTimeout)); |
|
130 User()->DiscoverConfirm(aError, NULL); |
|
131 break; |
|
132 } |
|
133 case EAvdtpGetCapabilities: |
|
134 { |
|
135 // no timeout specified in avdtp for GetCaps |
|
136 __ASSERT_DEBUG(aError!=KErrAvdtpRequestTimeout, Panic(EAvdtpInvalidTimeout)); |
|
137 User()->GetCapsConfirm(aError, seid, NULL); |
|
138 break; |
|
139 } |
|
140 case EAvdtpSecurityControl: |
|
141 { |
|
142 // no timeout specified in avdtp for SecurityControl |
|
143 __ASSERT_DEBUG(aError!=KErrAvdtpRequestTimeout, Panic(EAvdtpInvalidTimeout)); |
|
144 User()->SecurityControlConfirm(aError, seid, KNullDesC8); |
|
145 break; |
|
146 } |
|
147 case EAvdtpAbort: |
|
148 { |
|
149 // Abort is special as the spec doesn't allow errors in the Confirm, |
|
150 // so signal anyway = assume it worked as semantics of Abort allow this |
|
151 User()->AbortConfirm(seid); |
|
152 break; |
|
153 } |
|
154 case EAvdtpSetConfiguration: |
|
155 { |
|
156 User()->SetConfigConfirm(aError, seid, EServiceCategoryNull); |
|
157 break; |
|
158 } |
|
159 case EAvdtpOpen: |
|
160 { |
|
161 User()->OpenConfirm(aError, seid); |
|
162 break; |
|
163 } |
|
164 case EAvdtpReconfigure: |
|
165 { |
|
166 User()->ReconfigConfirm(aError, seid, EServiceCategoryNull); |
|
167 break; |
|
168 } |
|
169 case EAvdtpSuspend: |
|
170 { |
|
171 User()->SuspendConfirm(aError, seid); |
|
172 break; |
|
173 } |
|
174 case EAvdtpStart: |
|
175 { |
|
176 User()->StartConfirm(aError, seid); |
|
177 break; |
|
178 } |
|
179 case EAvdtpRelease: |
|
180 { |
|
181 User()->ReleaseConfirm(aError, seid); |
|
182 break; |
|
183 } |
|
184 default: |
|
185 { |
|
186 // note we never send GetConfiguration |
|
187 __DEBUGGER(); |
|
188 } |
|
189 } |
|
190 // will delete us: |
|
191 SignallingChannel().RemoveTransaction(*this); |
|
192 } |
|
193 |
|
194 void CSignallingTransaction::SetSentAction() |
|
195 { |
|
196 iPostSendAction = Message().PostSendAction(); |
|
197 } |