|
1 // Copyright (c) 2004-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 "sessnotf.h" |
|
17 |
|
18 CSessionNotifier::CSessionNotifier() : |
|
19 iIdReportingOn(ETrue), iRequests(KArrayGranularity, _FOFF(SRequest, id)) |
|
20 { |
|
21 } |
|
22 |
|
23 CSessionNotifier::~CSessionNotifier() |
|
24 { |
|
25 CancelAllRequests(); |
|
26 } |
|
27 |
|
28 void CSessionNotifier::Notify(TUint32 aId) |
|
29 { |
|
30 SRequest s; |
|
31 s.id = aId; |
|
32 |
|
33 // Check if iIdReportingOn is True. If it's false return KUnspecifiedKey, otherwise return |
|
34 // the individual key. One exception to this is where the individual key is KRequestPending. |
|
35 // To prevent problems in AO's using key notifications KUnspecifiedKey will be returned to |
|
36 // notify for changes to this key. |
|
37 TUint32 reportedId = (iIdReportingOn && (aId != static_cast<TUint32>(KRequestPending))) ? aId : KUnspecifiedKey; |
|
38 |
|
39 TInt i = iRequests.FindInUnsignedKeyOrder(s); |
|
40 if(i>=0) |
|
41 { |
|
42 iRequests[i].msg.Complete(reportedId); |
|
43 iRequests.Remove(i); |
|
44 } |
|
45 |
|
46 for(i=iGroupRequests.Count()-1; i>=0; i--) |
|
47 { |
|
48 SGroupRequest& s = iGroupRequests[i]; |
|
49 if((aId & s.idMask)==(s.partialId & s.idMask)) |
|
50 { |
|
51 s.msg.Complete(reportedId); |
|
52 iGroupRequests.Remove(i); |
|
53 } |
|
54 } |
|
55 } |
|
56 |
|
57 TInt CSessionNotifier::AddRequest(TUint32 aId, TClientRequest aMessage) |
|
58 { |
|
59 SRequest s; |
|
60 s.id = aId; |
|
61 s.msg = aMessage; |
|
62 |
|
63 return iRequests.InsertInUnsignedKeyOrder(s); |
|
64 } |
|
65 |
|
66 TInt CSessionNotifier::AddRequest(TUint32 aPartialId, TUint32 aIdMask, TClientRequest aMessage) |
|
67 { |
|
68 SGroupRequest s; |
|
69 s.partialId = aPartialId;; |
|
70 s.idMask = aIdMask; |
|
71 s.msg = aMessage; |
|
72 |
|
73 return iGroupRequests.Append(s); |
|
74 } |
|
75 |
|
76 TInt CSessionNotifier::CancelRequest(TUint32 aId) |
|
77 { |
|
78 SRequest s; |
|
79 s.id = aId; |
|
80 |
|
81 TInt r = iRequests.FindInUnsignedKeyOrder(s); |
|
82 if(r>=0) |
|
83 { |
|
84 iRequests[r].msg.Complete(KUnspecifiedKey); |
|
85 iRequests.Remove(r); |
|
86 } |
|
87 |
|
88 return r>=0 ? KErrNone : KErrNotFound; |
|
89 } |
|
90 |
|
91 TInt CSessionNotifier::CancelRequest(TUint32 aPartialId, TUint32 aIdMask) |
|
92 { |
|
93 TInt n = 0; |
|
94 for(TInt i=iGroupRequests.Count()-1; i>=0; i--) |
|
95 { |
|
96 SGroupRequest& s = iGroupRequests[i]; |
|
97 if(aPartialId==s.partialId && aIdMask==s.idMask) |
|
98 { |
|
99 n++; |
|
100 s.msg.Complete(KUnspecifiedKey); |
|
101 iGroupRequests.Remove(i); |
|
102 } |
|
103 } |
|
104 |
|
105 return n>0 ? KErrNone : KErrNotFound; |
|
106 } |
|
107 |
|
108 TInt CSessionNotifier::CancelAllRequests() |
|
109 { |
|
110 TInt n = iRequests.Count(); |
|
111 while(n-->0) |
|
112 iRequests[n].msg.Complete(KUnspecifiedKey); |
|
113 |
|
114 iRequests.Reset(); |
|
115 |
|
116 n = iGroupRequests.Count(); |
|
117 while(n-->0) |
|
118 iGroupRequests[n].msg.Complete(KUnspecifiedKey); |
|
119 |
|
120 iGroupRequests.Reset(); |
|
121 |
|
122 return KErrNone; |
|
123 } |
|
124 |
|
125 void CSessionNotifier::IdReportingOn() |
|
126 { |
|
127 iIdReportingOn = ETrue; |
|
128 } |
|
129 |
|
130 void CSessionNotifier::IdReportingOff() |
|
131 { |
|
132 iIdReportingOn = EFalse; |
|
133 } |