|
1 /* |
|
2 * Copyright (c) 2006 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: Implements getting/setting notifier locks on BT devices |
|
15 * from/to P&S KBTNotifierLocks from btengprivatepskeys.h. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "btengprivatepskeys.h" |
|
20 #include <e32property.h> |
|
21 |
|
22 // ---------------------------------------------------------- |
|
23 // Initialize members to zero |
|
24 // ---------------------------------------------------------- |
|
25 // |
|
26 inline TBTNotifLock::TBTNotifLock() |
|
27 : iAddr(TBTDevAddr()), iLocks(EBTNotifierLockNone) |
|
28 { |
|
29 } |
|
30 |
|
31 // ---------------------------------------------------------- |
|
32 // initialize members to the specified values |
|
33 // ---------------------------------------------------------- |
|
34 // |
|
35 inline TBTNotifLock::TBTNotifLock(const TBTDevAddr& aAddr, TInt aLocks) |
|
36 : iAddr( aAddr ), iLocks( aLocks ) |
|
37 { |
|
38 } |
|
39 |
|
40 // ---------------------------------------------------------- |
|
41 // returns the address |
|
42 // ---------------------------------------------------------- |
|
43 // |
|
44 inline const TBTDevAddr& TBTNotifLock::Addr() const |
|
45 { |
|
46 return iAddr; |
|
47 } |
|
48 |
|
49 // ---------------------------------------------------------- |
|
50 // returns the lock as value |
|
51 // ---------------------------------------------------------- |
|
52 // |
|
53 inline TInt TBTNotifLock::Locks() const |
|
54 { |
|
55 return iLocks; |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------- |
|
59 // returns the lock as modifiable reference |
|
60 // ---------------------------------------------------------- |
|
61 // |
|
62 inline TInt& TBTNotifLock::Locks() |
|
63 { |
|
64 return iLocks; |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------- |
|
68 // Locally instantiate a RProperty and invoke GetNotifLocks |
|
69 // ---------------------------------------------------------- |
|
70 // |
|
71 inline void TBTNotifLockPublish::GetNotifLocks( TInt& aLocks, const TBTDevAddr& aAddr ) |
|
72 { |
|
73 RProperty property; |
|
74 TInt err = property.Attach( |
|
75 KPSUidBluetoothEnginePrivateCategory, KBTNotifierLocks ); |
|
76 if ( !err ) |
|
77 { |
|
78 GetNotifLocks( property, aLocks, aAddr ); |
|
79 } |
|
80 property.Close(); |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------- |
|
84 // Extracts from PS key and returns the lock value for |
|
85 // the specified device |
|
86 // ---------------------------------------------------------- |
|
87 // |
|
88 inline void TBTNotifLockPublish::GetNotifLocks(RProperty& aProperty, |
|
89 TInt& aLocks, const TBTDevAddr& aAddr ) |
|
90 { |
|
91 aLocks = EBTNotifierLockNone; |
|
92 TInt infoSize( sizeof( TBTNotifLock ) ); |
|
93 TBuf8<sizeof( TBTNotifLock ) * 8> infoDes; |
|
94 TInt err = aProperty.Get( infoDes ); |
|
95 if ( err || infoDes.Length() < infoSize ) |
|
96 { |
|
97 // zero length of the PS content indicates no lock set at all. |
|
98 return; |
|
99 } |
|
100 TInt infoCount = infoDes.Length() / infoSize; |
|
101 |
|
102 TPckgBuf<TBTNotifLock> tmpPckg; |
|
103 for ( TInt i = 0; i < infoCount; i++ ) |
|
104 { |
|
105 tmpPckg.Copy(infoDes.Mid( i * infoSize, infoSize )); |
|
106 if ( tmpPckg().Addr() == aAddr ) |
|
107 { |
|
108 // found the locks for the device, writes to client. |
|
109 aLocks = tmpPckg().Locks(); |
|
110 return; |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 // ---------------------------------------------------------- |
|
116 // Locally instantiate a RProperty and invoke AddNotifLocks |
|
117 // ---------------------------------------------------------- |
|
118 // |
|
119 inline void TBTNotifLockPublish::AddNotifLocks( TInt aLocks, const TBTDevAddr& aAddr ) |
|
120 { |
|
121 RProperty property; |
|
122 TInt err = property.Attach( |
|
123 KPSUidBluetoothEnginePrivateCategory, KBTNotifierLocks ); |
|
124 if ( !err ) |
|
125 { |
|
126 AddNotifLocks( property, aLocks, aAddr ); |
|
127 } |
|
128 property.Close(); |
|
129 } |
|
130 |
|
131 // ---------------------------------------------------------- |
|
132 // Find the lock for the device from PS key and updates its value if |
|
133 // needed. |
|
134 // ---------------------------------------------------------- |
|
135 // |
|
136 inline void TBTNotifLockPublish::AddNotifLocks( RProperty& aProperty, |
|
137 TInt aLocks, const TBTDevAddr& aAddr ) |
|
138 { |
|
139 TBuf8<sizeof( TBTNotifLock ) * 8> infoDes; |
|
140 TInt infoSize( sizeof( TBTNotifLock ) ); |
|
141 TInt err = aProperty.Get( infoDes ); |
|
142 if ( err ) |
|
143 { |
|
144 return; |
|
145 } |
|
146 TInt infoCount = infoDes.Length() / infoSize; |
|
147 TPckgBuf<TBTNotifLock> tmpPckg; |
|
148 |
|
149 for ( TInt i = 0; i < infoCount; i++ ) |
|
150 { |
|
151 tmpPckg.Copy(infoDes.Mid( i * infoSize, infoSize )); |
|
152 if ( tmpPckg().Addr() == aAddr ) |
|
153 { |
|
154 TInt newOps = tmpPckg().Locks() | aLocks; |
|
155 // update the value only if it is really changed: |
|
156 if ( tmpPckg().Locks() != newOps ) |
|
157 { |
|
158 tmpPckg().Locks() = newOps; |
|
159 infoDes.Replace( i * infoSize, infoSize, tmpPckg ); |
|
160 (void) aProperty.Set( infoDes ); |
|
161 } |
|
162 return; |
|
163 } |
|
164 } |
|
165 // no lock for the device so far, append it to the end: |
|
166 tmpPckg() = TBTNotifLock( aAddr, aLocks ); |
|
167 if ( infoCount ) |
|
168 { |
|
169 infoDes.Append( tmpPckg ); |
|
170 (void) aProperty.Set( infoDes ); |
|
171 } |
|
172 (void) aProperty.Set( tmpPckg ); |
|
173 } |
|
174 |
|
175 // ---------------------------------------------------------- |
|
176 // Locally instantiate a RProperty and invoke DeleteNotifLocks |
|
177 // ---------------------------------------------------------- |
|
178 // |
|
179 inline void TBTNotifLockPublish::DeleteNotifLocks( TInt aLocks, const TBTDevAddr& aAddr ) |
|
180 { |
|
181 RProperty property; |
|
182 TInt err = property.Attach( |
|
183 KPSUidBluetoothEnginePrivateCategory, KBTNotifierLocks ); |
|
184 if ( !err ) |
|
185 { |
|
186 DeleteNotifLocks( property, aLocks, aAddr ); |
|
187 } |
|
188 property.Close(); |
|
189 } |
|
190 |
|
191 // ---------------------------------------------------------- |
|
192 // Find the lock for the device from PS key and updates its value if |
|
193 // needed. |
|
194 // ---------------------------------------------------------- |
|
195 // |
|
196 inline void TBTNotifLockPublish::DeleteNotifLocks( RProperty& aProperty, |
|
197 TInt aLocks, const TBTDevAddr& aAddr ) |
|
198 { |
|
199 TBuf8<sizeof( TBTNotifLock ) * 8> infoDes; |
|
200 TInt infoSize( sizeof( TBTNotifLock ) ); |
|
201 TInt err = aProperty.Get( infoDes ); |
|
202 if ( err || infoDes.Length() < infoSize ) |
|
203 { |
|
204 return; |
|
205 } |
|
206 TInt infoCount = infoDes.Length() / infoSize; |
|
207 TPckgBuf<TBTNotifLock> tmpPckg; |
|
208 for ( TInt i = 0; i < infoCount; i++ ) |
|
209 { |
|
210 tmpPckg.Copy( infoDes.Mid( i * infoSize, infoSize ) ); |
|
211 if ( tmpPckg().Addr() == aAddr ) |
|
212 { |
|
213 TInt newOps = tmpPckg().Locks() & ~aLocks; |
|
214 // update PS only if the value is changed: |
|
215 if ( tmpPckg().Locks() != newOps ) |
|
216 { |
|
217 tmpPckg().Locks() = newOps; |
|
218 if ( tmpPckg().Locks() == 0) |
|
219 { |
|
220 // no lock for this device anymore, remove from PS: |
|
221 infoDes.Delete( i * infoSize, infoSize ); |
|
222 } |
|
223 else |
|
224 { |
|
225 // Update the lock value: |
|
226 infoDes.Replace( i * infoSize, infoSize, tmpPckg ); |
|
227 } |
|
228 (void) aProperty.Set( infoDes ); |
|
229 } |
|
230 return; |
|
231 } |
|
232 } |
|
233 } |
|
234 |