|
1 /* |
|
2 * Copyright (c) 2004 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: Generic event and message channel for Connection UI. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <E32std.h> |
|
21 #include <bldvariant.hrh> |
|
22 |
|
23 #include "CCnUiGroupChannel.h" |
|
24 #include "ChatNGCommonUIDs.h" |
|
25 #include "IMPSCommonUiDebugPrint.h" |
|
26 #include "IMPSSharedDataDefs.h" |
|
27 #include "CIMPSSharedDataFactory.h" |
|
28 #include "IMPSUIDDefs.h" |
|
29 |
|
30 |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CCnUiGroupChannel::NewLC |
|
36 // Two-phased constructor. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CCnUiGroupChannel* CCnUiGroupChannel::NewLC( TInt aGroupId, |
|
40 TGCChannelID aChannelId, |
|
41 TBool aTemporary ) |
|
42 { |
|
43 CCnUiGroupChannel* self = new ( ELeave ) CCnUiGroupChannel( aGroupId, |
|
44 aChannelId ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL( aTemporary ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CCnUiGroupChannel::NewL |
|
53 // Two-phased constructor. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CCnUiGroupChannel* CCnUiGroupChannel::NewL( TInt aGroupId, |
|
57 TGCChannelID aChannelId, |
|
58 TBool aTemporary ) |
|
59 { |
|
60 CCnUiGroupChannel* self = CCnUiGroupChannel::NewLC( aGroupId, aChannelId, aTemporary ); |
|
61 CleanupStack::Pop( self ); //self |
|
62 return self; |
|
63 } |
|
64 |
|
65 |
|
66 |
|
67 // Destructor |
|
68 CCnUiGroupChannel::~CCnUiGroupChannel() |
|
69 { |
|
70 CancelListen(); |
|
71 iKeys.Close(); |
|
72 delete iSharedData; |
|
73 } |
|
74 |
|
75 |
|
76 // C++ default constructor can NOT contain any code, that |
|
77 // might leave. |
|
78 // |
|
79 CCnUiGroupChannel::CCnUiGroupChannel( TInt aGroupId, |
|
80 TGCChannelID aChannelId ) |
|
81 : iGroupId( aGroupId ), |
|
82 iChannelId( aChannelId ), |
|
83 iChannelSignaled( EFalse ) |
|
84 { |
|
85 } |
|
86 |
|
87 |
|
88 // EPOC default constructor can leave. |
|
89 void CCnUiGroupChannel::ConstructL( TBool aTemporary ) |
|
90 { |
|
91 __ASSERT_DEBUG( ( iChannelId >= 0 ), User::Leave( KErrArgument ) ); |
|
92 __ASSERT_DEBUG( ( iChannelId <= KMaxChannelIdValue ), User::Leave( KErrArgument ) ); |
|
93 |
|
94 __ASSERT_DEBUG( ( iGroupId >= 0 ), User::Leave( KErrArgument ) ); |
|
95 __ASSERT_DEBUG( ( iGroupId <= KMaxChannelIdValue ), User::Leave( KErrArgument ) ); |
|
96 |
|
97 //make channel keys based the global / local mode |
|
98 if ( aTemporary == ECnUiGlobalGroup ) |
|
99 { |
|
100 //global ones |
|
101 iChannelKey.Format( KGlobalChannelKeyNameFormatter, iChannelId ); |
|
102 iChannelDataKey.Format( KGlobalChannelDataKeyNameFormatter, iChannelId ); |
|
103 |
|
104 iSharedData = CIMPSSharedDataFactory::CreatePermanentKeyHandlerL( |
|
105 this, KIMPSConnUiPermanentUid ); |
|
106 iUid = KIMPSConnUiPermanentUid; |
|
107 } |
|
108 |
|
109 else |
|
110 { |
|
111 //group ones |
|
112 iChannelKey.Format( KGroupChannelKeyNameFormatter, iGroupId, iChannelId ); |
|
113 iChannelDataKey.Format( KGroupChannelDataKeyNameFormatter, iGroupId, iChannelId ); |
|
114 iSharedData = CIMPSSharedDataFactory::CreateTemporaryKeyHandlerL( |
|
115 this, KIMPSConnUiTemporaryUid ); |
|
116 iUid = KIMPSConnUiTemporaryUid; |
|
117 } |
|
118 |
|
119 //insert permanent / temporary identifier |
|
120 if ( aTemporary ) |
|
121 { |
|
122 iChannelKey.Insert( KGlobalChannelTypeIdPosition, |
|
123 KGlobalChannelTemporaryKeyIdentifier ); |
|
124 |
|
125 iChannelDataKey.Insert( KGlobalChannelTypeIdPosition, |
|
126 KGlobalChannelTemporaryKeyIdentifier ); |
|
127 } |
|
128 else |
|
129 { |
|
130 iChannelKey.Insert( KGlobalChannelTypeIdPosition, |
|
131 KGlobalChannelPermanentKeyIdentifier ); |
|
132 |
|
133 iChannelDataKey.Insert( KGlobalChannelTypeIdPosition, |
|
134 KGlobalChannelPermanentKeyIdentifier ); |
|
135 } |
|
136 |
|
137 User::LeaveIfError( iSharedData->ConvertSharedDataKey( iChannelKey, iKey ) ); |
|
138 User::LeaveIfError( iSharedData->ConvertSharedDataKey( iChannelDataKey, iDataKey ) ); |
|
139 |
|
140 // initialize "channel signalled"-flag properly |
|
141 TInt current = 0; |
|
142 TInt err = iSharedData->GetIntKey( iKey, current ); |
|
143 if ( err == KErrNotFound ) |
|
144 { |
|
145 // if it was not found, correct value is 0 |
|
146 err = KErrNone; |
|
147 } |
|
148 |
|
149 User::LeaveIfError( err ); |
|
150 iChannelSignaled = current > 0; |
|
151 } |
|
152 |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CCnUiGroupChannel::WriteL() |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 void CCnUiGroupChannel::WriteL( TInt aMsg ) |
|
159 { |
|
160 User::LeaveIfError( iSharedData->SetIntKey( iKey, aMsg ) ); |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CCnUiGroupChannel::WriteL() |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CCnUiGroupChannel::WriteL( TInt aMsg, const TDesC& aExtraData ) |
|
168 { |
|
169 //write first the extra data |
|
170 WriteExtraDataL( aExtraData ); |
|
171 |
|
172 //and then signal the channel with message |
|
173 WriteL( aMsg ); |
|
174 } |
|
175 |
|
176 |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CCnUiGroupChannel::Read() |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 TInt CCnUiGroupChannel::Read( TInt& aMsg ) |
|
183 { |
|
184 TInt msg = 0; |
|
185 |
|
186 if ( iSharedData->GetIntKey( iKey, msg ) == KErrNone ) |
|
187 { |
|
188 aMsg = msg; |
|
189 IMPSCUI_DP( D_IMPSCUI_LIT( "CCnUiGroupChannel msg[%d] <== [%S]" ), |
|
190 aMsg, &iChannelKey ); |
|
191 return KErrNone; |
|
192 } |
|
193 |
|
194 IMPSCUI_DP( D_IMPSCUI_LIT( "CCnUiGroupChannel [msg not found] <== [%S]" ), |
|
195 &iChannelKey ); |
|
196 return KErrNotFound; |
|
197 } |
|
198 |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CCnUiGroupChannel::ReadL() |
|
202 // ----------------------------------------------------------------------------- |
|
203 // |
|
204 void CCnUiGroupChannel::ReadL( HBufC*& aExtraData ) |
|
205 { |
|
206 //read the extra data |
|
207 |
|
208 HBufC* shBuffer = HBufC::NewLC( KMaxValueSize ); |
|
209 TPtr ptr = shBuffer->Des(); |
|
210 TInt err = iSharedData->GetStringKey( iDataKey, ptr ); |
|
211 |
|
212 if ( err != KErrNone ) |
|
213 { |
|
214 shBuffer->Des().Copy( KNullDesC() ); |
|
215 } |
|
216 |
|
217 aExtraData = shBuffer->AllocL(); |
|
218 |
|
219 CleanupStack::PopAndDestroy( shBuffer ); |
|
220 |
|
221 } |
|
222 |
|
223 |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CCnUiGroupChannel::SignalL() |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 TInt CCnUiGroupChannel::SignalL() |
|
230 { |
|
231 if ( iChannelSignaled ) |
|
232 { |
|
233 return KErrInUse; |
|
234 } |
|
235 |
|
236 User::LeaveIfError( iSharedData->Signal( iKey ) ); |
|
237 |
|
238 iChannelSignaled = ETrue; |
|
239 |
|
240 return KErrNone; |
|
241 } |
|
242 |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CCnUiGroupChannel::SignalL() |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 TInt CCnUiGroupChannel::SignalL( const TDesC& aExtraData ) |
|
249 { |
|
250 if ( iChannelSignaled ) |
|
251 { |
|
252 return KErrInUse; |
|
253 } |
|
254 |
|
255 //write first the extra data |
|
256 WriteExtraDataL( aExtraData ); |
|
257 |
|
258 //and then signal the channel |
|
259 return SignalL(); |
|
260 } |
|
261 |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CCnUiGroupChannel::CancelSignal() |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 void CCnUiGroupChannel::CancelSignal() |
|
268 { |
|
269 if ( iChannelSignaled ) |
|
270 { |
|
271 // we can't do anything else except ignore this error |
|
272 iSharedData->CancelSignal( iKey ); |
|
273 iChannelSignaled = EFalse; |
|
274 } |
|
275 } |
|
276 |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CCnUiGroupChannel::ListenL() |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 void CCnUiGroupChannel::ListenL( MCnUiGroupChannelListener* aListener ) |
|
283 { |
|
284 __ASSERT_ALWAYS( !iListener, User::Leave( KErrInUse ) ); |
|
285 __ASSERT_ALWAYS( aListener, User::Leave( KErrArgument ) ); |
|
286 |
|
287 User::LeaveIfError( iSharedData->SubscribeSet( iUid, iKey ) ); |
|
288 iListener = aListener; |
|
289 } |
|
290 |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CCnUiGroupChannel::CancelListen() |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 void CCnUiGroupChannel::CancelListen() |
|
297 { |
|
298 if ( iSharedData ) |
|
299 { |
|
300 iSharedData->UnSubscribe( iUid, iKey ); |
|
301 } |
|
302 iListener = NULL; |
|
303 } |
|
304 |
|
305 |
|
306 // ----------------------------------------------------------------------------- |
|
307 // CCnUiGroupChannel::GroupID() |
|
308 // ----------------------------------------------------------------------------- |
|
309 // |
|
310 TInt CCnUiGroupChannel::GroupID() |
|
311 { |
|
312 return iGroupId; |
|
313 } |
|
314 |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CCnUiGroupChannel::ChannelId() |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 TGCChannelID CCnUiGroupChannel::ChannelId() |
|
321 { |
|
322 return iChannelId; |
|
323 } |
|
324 |
|
325 |
|
326 // ----------------------------------------------------------------------------- |
|
327 // CCnUiGroupChannel::WriteExtraDataL() |
|
328 // ----------------------------------------------------------------------------- |
|
329 // |
|
330 void CCnUiGroupChannel::WriteExtraDataL( const TDesC& aExtraData ) |
|
331 { |
|
332 User::LeaveIfError( iSharedData->SetStringKey( iDataKey, aExtraData ) ); |
|
333 } |
|
334 |
|
335 |
|
336 // --------------------------------------------------------- |
|
337 // CCnUiGroupChannel::HandleTemporaryKeyNotifyL() |
|
338 // |
|
339 // (other items were commented in a header). |
|
340 // --------------------------------------------------------- |
|
341 // |
|
342 void CCnUiGroupChannel::HandleTemporaryKeyNotifyL( const TUid aUid, |
|
343 const TIMPSSharedKeys aKey ) |
|
344 { |
|
345 if ( ( aUid != iUid ) || ( aKey != iKey ) ) |
|
346 { |
|
347 return; |
|
348 } |
|
349 |
|
350 //Notify came trough the channel key |
|
351 //ignore key value corruptions, key value will be |
|
352 //rewritten on next client specific change |
|
353 |
|
354 TInt receivedMsg( 0 ); |
|
355 TInt error = iSharedData->GetIntKey( aKey, receivedMsg ); |
|
356 |
|
357 if ( error == KErrNone ) |
|
358 { |
|
359 IMPSCUI_DP( D_IMPSCUI_LIT( "CCnUiGroupChannel [%S] ==> event[%d] " ), |
|
360 &iChannelKey, receivedMsg ); |
|
361 |
|
362 if ( iListener ) |
|
363 { |
|
364 iListener->HandleChannelMsg( iGroupId, iChannelId, receivedMsg ); |
|
365 } |
|
366 } |
|
367 |
|
368 #ifdef IMPSCUI_ENABLE_DEBUG_PRINT |
|
369 else |
|
370 { |
|
371 IMPSCUI_DP( D_IMPSCUI_LIT( "CCnUiGroupChannel [%S] ==> event conversion error [%d] " ), |
|
372 &iChannelKey, error ); |
|
373 } |
|
374 #endif //IMPSCUI_ENABLE_DEBUG_PRINT |
|
375 } |
|
376 |
|
377 // --------------------------------------------------------- |
|
378 // CCnUiGroupChannel::HandlePermanentKeyNotifyL() |
|
379 // |
|
380 // (other items were commented in a header). |
|
381 // --------------------------------------------------------- |
|
382 // |
|
383 void CCnUiGroupChannel::HandlePermanentKeyNotifyL( const TUid aUid, |
|
384 const TIMPSSharedKeys aKey ) |
|
385 { |
|
386 if ( ( aUid != iUid ) || ( aKey != iKey ) ) |
|
387 { |
|
388 return; |
|
389 } |
|
390 |
|
391 //Notify came trough the channel key |
|
392 //ignore key value corruptions, key value will be |
|
393 //rewritten on next client specific change |
|
394 |
|
395 TInt receivedMsg( 0 ); |
|
396 TInt error = iSharedData->GetIntKey( aKey, receivedMsg ); |
|
397 |
|
398 if ( error == KErrNone ) |
|
399 { |
|
400 IMPSCUI_DP( D_IMPSCUI_LIT( "CCnUiGroupChannel [%S] ==> event[%d] " ), |
|
401 &iChannelKey, receivedMsg ); |
|
402 |
|
403 if ( iListener ) |
|
404 { |
|
405 iListener->HandleChannelMsg( iGroupId, iChannelId, receivedMsg ); |
|
406 } |
|
407 } |
|
408 |
|
409 #ifdef IMPSCUI_ENABLE_DEBUG_PRINT |
|
410 else |
|
411 { |
|
412 IMPSCUI_DP( D_IMPSCUI_LIT( "CCnUiGroupChannel [%S] ==> event conversion error [%d] " ), |
|
413 &iChannelKey, error ); |
|
414 } |
|
415 #endif //IMPSCUI_ENABLE_DEBUG_PRINT |
|
416 } |
|
417 |
|
418 // end of file |