|
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 SEP cache |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include <bluetooth/logger.h> |
|
24 #include <bluetoothav.h> |
|
25 #include "avdtpSEPCache.h" |
|
26 #include "gavdpinterface.h" |
|
27 #include "avdtpSignallingMessages.h" |
|
28 #include "avdtputil.h" |
|
29 |
|
30 #ifdef __FLOG_ACTIVE |
|
31 _LIT8(KLogComponent, LOG_COMPONENT_AVDTP); |
|
32 #endif |
|
33 |
|
34 CRemoteSEP* CRemoteSEP::NewL(const TBTDevAddr& aAddr, const TAvdtpSEPInfo& aInfo) |
|
35 { |
|
36 LOG_STATIC_FUNC |
|
37 CRemoteSEP* s = new (ELeave) CRemoteSEP(aAddr, aInfo); |
|
38 CleanupStack::PushL(s); |
|
39 s->ConstructL(); |
|
40 CleanupStack::Pop(s); |
|
41 return s; |
|
42 } |
|
43 |
|
44 CRemoteSEP::CRemoteSEP(const TBTDevAddr& aAddr, const TAvdtpSEPInfo& aInfo) |
|
45 : iRemoteDev(aAddr), iInfo(aInfo) |
|
46 { |
|
47 LOG_FUNC |
|
48 // age already set to zero |
|
49 // only store remote sep details in the cache |
|
50 __ASSERT_DEBUG(!aInfo.SEID().IsLocal(), Panic(EAvdtpSEIDHasWrongDomain)); |
|
51 } |
|
52 |
|
53 CRemoteSEP::~CRemoteSEP() |
|
54 { |
|
55 LOG_FUNC |
|
56 delete iCapabilitiesBuf; |
|
57 } |
|
58 |
|
59 |
|
60 void CRemoteSEP::ConstructL() |
|
61 { |
|
62 LOG_FUNC |
|
63 } |
|
64 |
|
65 void CRemoteSEP::UpdateInfo(const TAvdtpSEPInfo& aInfo) |
|
66 { |
|
67 iInfo = aInfo; |
|
68 } |
|
69 |
|
70 TBool CRemoteSEP::HasCapability(TAvdtpServiceCategory aCat) |
|
71 { |
|
72 LOG_FUNC |
|
73 TBool ret = EFalse; |
|
74 |
|
75 if (iCapabilitiesBuf) |
|
76 { |
|
77 CCapabilityPresentVisitor* presVisitor = new CCapabilityPresentVisitor(aCat); |
|
78 |
|
79 if (presVisitor) |
|
80 { |
|
81 TPtr8 ptr = iCapabilitiesBuf->Des(); |
|
82 presVisitor->Process(ptr); |
|
83 ret = presVisitor->IsPresent(); |
|
84 delete presVisitor; |
|
85 } |
|
86 } |
|
87 return ret; |
|
88 } |
|
89 |
|
90 |
|
91 /* |
|
92 Returns a pointer descriptor to SEP capability *in the protocol domain* |
|
93 It is upto a client to get this parsed as needed |
|
94 Motivation - to push more easilythrough ESOCK AND save unneccasry parsing |
|
95 */ |
|
96 TPtrC8 CRemoteSEP::GetCapabilityL(TAvdtpServiceCategory aCat) |
|
97 { |
|
98 LOG_FUNC |
|
99 // use visitor to extract relevant bit |
|
100 CCapabilityExtractorVisitor* extractor = new (ELeave) CCapabilityExtractorVisitor(aCat); |
|
101 TPtr8 ptr = iCapabilitiesBuf->Des(); |
|
102 extractor->Process(ptr); |
|
103 |
|
104 TPtrC8 cap = extractor->GetCapability(); |
|
105 delete extractor; |
|
106 return cap; |
|
107 } |
|
108 |
|
109 |
|
110 void CRemoteSEP::SetCapabilities(HBufC8* aCapsAsProtocol) |
|
111 { |
|
112 LOG_FUNC |
|
113 delete iCapabilitiesBuf; |
|
114 iCapabilitiesBuf = aCapsAsProtocol; // takes ownership |
|
115 |
|
116 // set a visitor on it now to summarise caps |
|
117 CCapabilitySummaryVisitor* summariser = new CCapabilitySummaryVisitor; |
|
118 if (summariser) |
|
119 { |
|
120 TPtr8 des = iCapabilitiesBuf->Des(); |
|
121 summariser->Process(des); |
|
122 iKnownCaps = summariser->CapabilitiesPresent(); |
|
123 delete summariser; |
|
124 } |
|
125 } |
|
126 |
|
127 CRemoteSEPCache* CRemoteSEPCache::NewL() |
|
128 { |
|
129 LOG_STATIC_FUNC |
|
130 CRemoteSEPCache* s = new (ELeave) CRemoteSEPCache(); |
|
131 return s; |
|
132 } |
|
133 |
|
134 /** |
|
135 Modifies SEP if already exists |
|
136 */ |
|
137 TInt CRemoteSEPCache::AddSEP(const TBTDevAddr& aAddr, const TAvdtpSEPInfo& aInfo) |
|
138 { |
|
139 LOG_FUNC |
|
140 TInt err = KErrNone; |
|
141 |
|
142 CRemoteSEP* sep = FindSEP(aAddr, aInfo.SEID()); |
|
143 if (!sep) |
|
144 { |
|
145 TRAP(err, sep = CRemoteSEP::NewL(aAddr, aInfo)); |
|
146 if (!err) |
|
147 { |
|
148 err = iRemoteSEPs.Append(sep); |
|
149 if (err) |
|
150 { |
|
151 delete sep; |
|
152 } |
|
153 } |
|
154 } |
|
155 else |
|
156 { |
|
157 // modify the one there |
|
158 sep->UpdateInfo(aInfo); |
|
159 } |
|
160 return err; |
|
161 } |
|
162 |
|
163 TPtrC8 CRemoteSEPCache::GetCapabilityL(const TBTDevAddr& aAddr, TSEID aSEID, TAvdtpServiceCategory aCat) |
|
164 { |
|
165 LOG_FUNC |
|
166 CRemoteSEP* sep = FindSEP(aAddr, aSEID); |
|
167 |
|
168 if (sep) |
|
169 { |
|
170 return sep->GetCapabilityL(aCat); |
|
171 } |
|
172 |
|
173 User::Leave(KErrNotFound); |
|
174 return KNullDesC8();// never reached |
|
175 } |
|
176 |
|
177 |
|
178 TAvdtpServiceCategories CRemoteSEPCache::GetCapabilitiesL(const TBTDevAddr& aAddr, TSEID aSEID) const |
|
179 { |
|
180 LOG_FUNC |
|
181 CRemoteSEP* sep = FindSEP(aAddr, aSEID); |
|
182 |
|
183 if (sep) |
|
184 { |
|
185 return sep->GetCapabilities(); |
|
186 } |
|
187 |
|
188 User::Leave(KErrNotFound); |
|
189 return TAvdtpServiceCategories(); |
|
190 } |
|
191 |
|
192 |
|
193 TBool CRemoteSEPCache::HasCapability(const TBTDevAddr& aAddr, TSEID aSEID, TAvdtpServiceCategory aCat) |
|
194 { |
|
195 LOG_FUNC |
|
196 CRemoteSEP* sep = FindSEP(aAddr, aSEID); |
|
197 |
|
198 if (sep) |
|
199 { |
|
200 return sep->HasCapability(aCat); |
|
201 } |
|
202 |
|
203 return EFalse; // unknown => false |
|
204 } |
|
205 |
|
206 |
|
207 |
|
208 void CRemoteSEPCache::SetCapabilities(const TBTDevAddr& aAddr, TSEID aSEID, HBufC8* aCapabilitiesAsProtocol) |
|
209 /** |
|
210 Sets capabilites from the RMBufChain passed in on the relevant CRemoteSEP in our |
|
211 cache. |
|
212 |
|
213 @return a bitmask of the service categories we saw. |
|
214 */ |
|
215 { |
|
216 LOG_FUNC |
|
217 CRemoteSEP* sep = FindSEP(aAddr, aSEID); |
|
218 |
|
219 if (sep) |
|
220 { |
|
221 sep->SetCapabilities(aCapabilitiesAsProtocol); |
|
222 } |
|
223 else |
|
224 { |
|
225 // would be nice to cache this, but if we don't know the SEP at this point |
|
226 // the user hadn't done a Discover - which is ok for them, but for us we don't know if the |
|
227 // SEP is in use or Audio/Video etc....We keep the capabilities as the stack finds |
|
228 // them useful later |
|
229 TAvdtpSEPInfo info; |
|
230 info.SetSEID(aSEID); |
|
231 if (AddSEP(aAddr, info)==KErrNone) |
|
232 { |
|
233 SetCapabilities(aAddr, aSEID, aCapabilitiesAsProtocol); |
|
234 } |
|
235 } |
|
236 } |
|
237 |
|
238 CRemoteSEPCache::~CRemoteSEPCache() |
|
239 { |
|
240 LOG_FUNC |
|
241 iRemoteSEPs.ResetAndDestroy(); |
|
242 } |
|
243 |
|
244 TBool CRemoteSEPCache::Exists(const TBTDevAddr& aAddr, TSEID aSEID) const |
|
245 { |
|
246 LOG_FUNC |
|
247 return (FindSEP(aAddr, aSEID)!=NULL); |
|
248 } |
|
249 |
|
250 CRemoteSEP* CRemoteSEPCache::FindSEP(const TBTDevAddr& aAddr, TSEID aSEID) const |
|
251 { |
|
252 LOG_FUNC |
|
253 __ASSERT_DEBUG(!aSEID.IsLocal(), Panic(EAvdtpSEIDHasWrongDomain)); |
|
254 |
|
255 for (TInt i=0; i<iRemoteSEPs.Count(); i++) |
|
256 { |
|
257 CRemoteSEP& sep = *iRemoteSEPs[i]; |
|
258 if (sep.iInfo.SEID() == aSEID && sep.iRemoteDev == aAddr) |
|
259 { |
|
260 return iRemoteSEPs[i]; // does not transfer ownership |
|
261 } |
|
262 } |
|
263 return NULL; |
|
264 } |
|
265 |
|
266 void CRemoteSEPCache::InvalidateSEPs(const TBTDevAddr& aAddr) |
|
267 { |
|
268 LOG_FUNC |
|
269 // typically called when signalling channel has gone down |
|
270 // in future we could age the seps and save doing a GetCaps, but this does |
|
271 // risk the use of invalid capabilities (but would still be compliant with GAVDP) |
|
272 CRemoteSEP* sep = NULL; |
|
273 for (TInt i=0; i<iRemoteSEPs.Count(); i++) |
|
274 { |
|
275 sep = iRemoteSEPs[i]; |
|
276 if (sep->iRemoteDev == aAddr) |
|
277 { |
|
278 iRemoteSEPs.Remove(i); |
|
279 delete sep; |
|
280 sep = NULL; |
|
281 } |
|
282 } |
|
283 } |
|
284 |