|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 #include "simplepairingresult.h" |
|
17 |
|
18 #include <bluetooth/logger.h> |
|
19 #ifdef __FLOG_ACTIVE |
|
20 _LIT8(KLogComponent, LOG_COMPONENT_PAIRING_SERVER); |
|
21 #endif |
|
22 |
|
23 |
|
24 |
|
25 CSimplePairingResultList* CSimplePairingResultList::NewL() |
|
26 { |
|
27 LOG_STATIC_FUNC |
|
28 CSimplePairingResultList* self = new(ELeave) CSimplePairingResultList(); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 CSimplePairingResultList::CSimplePairingResultList() |
|
36 : CBluetoothSecurityResultList(KSimplePairingResultListMaxSize) |
|
37 { |
|
38 LOG_FUNC |
|
39 } |
|
40 |
|
41 CAuthenticationResultList* CAuthenticationResultList::NewL() |
|
42 { |
|
43 LOG_STATIC_FUNC |
|
44 CAuthenticationResultList* self = new(ELeave) CAuthenticationResultList(); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CAuthenticationResultList::CAuthenticationResultList() |
|
52 : CBluetoothSecurityResultList(KAuthenticationResultListMaxSize) |
|
53 { |
|
54 LOG_FUNC |
|
55 } |
|
56 |
|
57 CBluetoothSecurityResultList::CBluetoothSecurityResultList(TInt aMaxListCount) |
|
58 : iResultList(_FOFF(TBluetoothSecurityResult, iLink)) |
|
59 , iListCount(0) |
|
60 , iMaxListCount(aMaxListCount) |
|
61 { |
|
62 LOG_FUNC |
|
63 } |
|
64 |
|
65 void CBluetoothSecurityResultList::ConstructL() |
|
66 { |
|
67 LOG_FUNC |
|
68 } |
|
69 |
|
70 CBluetoothSecurityResultList::~CBluetoothSecurityResultList() |
|
71 { |
|
72 LOG_FUNC |
|
73 while(!iResultList.IsEmpty()) |
|
74 { |
|
75 TBluetoothSecurityResult* entry = iResultList.First(); |
|
76 entry->iLink.Deque(); |
|
77 delete entry; |
|
78 } |
|
79 } |
|
80 |
|
81 void CBluetoothSecurityResultList::NewResult(const TBTDevAddr& aDevAddr, TInt aResult) |
|
82 { |
|
83 LOG_FUNC |
|
84 if(iObserver) |
|
85 { |
|
86 // Add the new entry. |
|
87 TBluetoothSecurityResult* entry = new TBluetoothSecurityResult(aDevAddr, aResult); |
|
88 if(!entry) |
|
89 { |
|
90 // OOM so we've lost a result - oh well we did our best. |
|
91 return; |
|
92 } |
|
93 iResultList.AddLast(*entry); |
|
94 ++iListCount; |
|
95 |
|
96 // Trim the list if needed |
|
97 while(iListCount > iMaxListCount) |
|
98 { |
|
99 entry = iResultList.First(); |
|
100 entry->iLink.Deque(); |
|
101 --iListCount; |
|
102 delete entry; |
|
103 } |
|
104 |
|
105 // Complete any outstanding notifications. |
|
106 if(iOutstandingNotification) |
|
107 { |
|
108 iOutstandingNotification = EFalse; |
|
109 ReturnResult(); |
|
110 } |
|
111 } |
|
112 |
|
113 } |
|
114 |
|
115 void CBluetoothSecurityResultList::RegisterObserverL(MBluetoothSecurityResultObserver& aObserver) |
|
116 { |
|
117 LOG_FUNC |
|
118 if(iObserver) |
|
119 { |
|
120 LEAVEL(KErrAlreadyExists); |
|
121 } |
|
122 iObserver = &aObserver; |
|
123 } |
|
124 |
|
125 void CBluetoothSecurityResultList::ReleaseObserver(MBluetoothSecurityResultObserver& aObserver) |
|
126 { |
|
127 LOG_FUNC |
|
128 if(iObserver == &aObserver) |
|
129 { |
|
130 iObserver = NULL; |
|
131 //Clear the list so that any queued results are not returned to the observer during the next session |
|
132 //(not doing this can cause results for a previous pairing request to be returned to a client-side app during the next pairing request). |
|
133 while (!iResultList.IsEmpty()) |
|
134 { |
|
135 TBluetoothSecurityResult* entry = iResultList.First(); |
|
136 entry->iLink.Deque(); |
|
137 delete entry; |
|
138 } |
|
139 |
|
140 //Set iListCount to zero. |
|
141 iListCount=0; |
|
142 } |
|
143 } |
|
144 |
|
145 void CBluetoothSecurityResultList::ReturnResult() |
|
146 { |
|
147 LOG_FUNC |
|
148 if(iListCount > 0) |
|
149 { |
|
150 __ASSERT_DEBUG(!iResultList.IsEmpty(), PANIC(KBluetoothSecListFaultCat, EResultListCountMismatch)); |
|
151 __ASSERT_DEBUG(iObserver, PANIC(KBluetoothSecListFaultCat, ENoBoundObserver)); |
|
152 TBluetoothSecurityResult* entry = iResultList.First(); |
|
153 __ASSERT_DEBUG(entry, PANIC(KBluetoothSecListFaultCat, ENullResultListEntry)); |
|
154 TInt err = iObserver->MbsroResult(entry->DeviceAddress(), entry->Result()); |
|
155 if(err == KErrNone) |
|
156 { |
|
157 entry->iLink.Deque(); |
|
158 --iListCount; |
|
159 delete entry; |
|
160 } |
|
161 } |
|
162 else |
|
163 { |
|
164 __ASSERT_DEBUG(!iOutstandingNotification, PANIC(KBluetoothSecListFaultCat, ENotificationAlreadyOutstanding)); |
|
165 iOutstandingNotification = ETrue; |
|
166 } |
|
167 } |
|
168 |
|
169 void CBluetoothSecurityResultList::CancelReturn() |
|
170 { |
|
171 LOG_FUNC |
|
172 iOutstandingNotification = EFalse; |
|
173 } |
|
174 |
|
175 |
|
176 // |
|
177 // TBluetoothSecurityResult |
|
178 // |
|
179 |
|
180 |
|
181 TBluetoothSecurityResult::TBluetoothSecurityResult(const TBTDevAddr& aDevAddr, TInt aResult) |
|
182 : iDeviceAddress(aDevAddr) |
|
183 , iResult(aResult) |
|
184 { |
|
185 LOG_FUNC |
|
186 } |
|
187 |
|
188 const TBTDevAddr& TBluetoothSecurityResult::DeviceAddress() const |
|
189 { |
|
190 LOG_FUNC |
|
191 return iDeviceAddress; |
|
192 } |
|
193 |
|
194 TInt TBluetoothSecurityResult::Result() const |
|
195 { |
|
196 LOG_FUNC |
|
197 return iResult; |
|
198 } |
|
199 |