|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * Implementation for the CDosEvent class |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <e32base.h> |
|
21 #include "dosevent.h" |
|
22 #include "doswaitingevent.h" |
|
23 #include "dos_debug.h" |
|
24 |
|
25 #define SECOND_GREATER_THAN_FIRST -1 |
|
26 #define FIRST_GREATER_THAN_SECOND 1 |
|
27 |
|
28 // |
|
29 // --------------------------------------------------------- |
|
30 // CDosEvent::NewL |
|
31 // --------------------------------------------------------- |
|
32 // |
|
33 |
|
34 CDosEvent* CDosEvent::NewL(TUint aEvent) |
|
35 { |
|
36 CDosEvent* result = new (ELeave) CDosEvent; |
|
37 CleanupStack::PushL(result); |
|
38 result->ConstructL(aEvent); |
|
39 CleanupStack::Pop(); |
|
40 |
|
41 return result; |
|
42 } |
|
43 |
|
44 // |
|
45 // --------------------------------------------------------- |
|
46 // CDosEvent::ConstructL |
|
47 // --------------------------------------------------------- |
|
48 // |
|
49 |
|
50 void CDosEvent::ConstructL(TUint aEvent) |
|
51 { |
|
52 iEventName = aEvent; |
|
53 } |
|
54 |
|
55 // |
|
56 // --------------------------------------------------------- |
|
57 // CDosEvent Destructor |
|
58 // --------------------------------------------------------- |
|
59 // |
|
60 |
|
61 CDosEvent::~CDosEvent() |
|
62 { |
|
63 //Destroys the list of Listeners |
|
64 if(!iListenerList.IsEmpty()) |
|
65 { |
|
66 iListenerList.Reset(); |
|
67 } |
|
68 } |
|
69 |
|
70 // |
|
71 // --------------------------------------------------------- |
|
72 // CDosEvent::Compare |
|
73 // --------------------------------------------------------- |
|
74 // |
|
75 |
|
76 TInt CDosEvent::Compare(const CDosEvent& aFirst,const CDosEvent& aSecond) |
|
77 { |
|
78 if(aFirst.iEventName < aSecond.iEventName) |
|
79 { |
|
80 return SECOND_GREATER_THAN_FIRST; |
|
81 } |
|
82 else if (aFirst.iEventName > aSecond.iEventName) |
|
83 { |
|
84 return FIRST_GREATER_THAN_SECOND; |
|
85 } |
|
86 return 0; |
|
87 } |
|
88 |
|
89 // |
|
90 // --------------------------------------------------------- |
|
91 // CDosEvent::AddListener |
|
92 // --------------------------------------------------------- |
|
93 // |
|
94 |
|
95 void CDosEvent::AddListener(CDosEventRcvService* aListener) |
|
96 { |
|
97 // The same listener can't be registered twice for the same event |
|
98 if(!ListenerRegistered(aListener)) |
|
99 { |
|
100 iListenerCount++; |
|
101 iListenerList.AddFirst(*aListener); |
|
102 } |
|
103 } |
|
104 |
|
105 // |
|
106 // --------------------------------------------------------- |
|
107 // CDosEvent::ListenerRegistered |
|
108 // --------------------------------------------------------- |
|
109 // |
|
110 |
|
111 TBool CDosEvent::ListenerRegistered(CDosEventRcvService* aListener) |
|
112 { |
|
113 CDosEventRcvService* item; |
|
114 |
|
115 iListenerIter.SetToFirst(); |
|
116 while((item = iListenerIter++) != NULL) |
|
117 { |
|
118 if(item==aListener) |
|
119 { |
|
120 return ETrue; |
|
121 } |
|
122 } |
|
123 return EFalse; |
|
124 } |
|
125 |
|
126 // |
|
127 // --------------------------------------------------------- |
|
128 // CDosEvent::RemoveListener |
|
129 // --------------------------------------------------------- |
|
130 // |
|
131 |
|
132 void CDosEvent::RemoveListener(CDosEventRcvService* aListener) |
|
133 { |
|
134 iListenerCount--; |
|
135 iListenerList.Remove(*aListener); |
|
136 } |
|
137 |
|
138 // |
|
139 // --------------------------------------------------------- |
|
140 // CDosEvent::InformListeners |
|
141 // --------------------------------------------------------- |
|
142 // |
|
143 |
|
144 void CDosEvent::InformListeners(CDosWaitingEvent* aEvent) |
|
145 { |
|
146 COM_TRACE_( "[DOSSERVER] CDosEvent::InformListeners()" ); |
|
147 |
|
148 CDosEventRcvService* item; |
|
149 TInt err(KErrNone); |
|
150 |
|
151 //Inform all the listeners in the list about the event |
|
152 iListenerIter.SetToFirst(); |
|
153 while((item = iListenerIter++) != NULL) |
|
154 { |
|
155 // create a new instance of CDosWaitingEvent & copy the parameters |
|
156 // we have to create another instance because the very same |
|
157 // object cannot reside on more than one queue. |
|
158 CDosWaitingEvent* copyEvent = new CDosWaitingEvent; |
|
159 if( copyEvent ) |
|
160 { |
|
161 if( aEvent->HasParameter() ) |
|
162 { |
|
163 TRAP( err, copyEvent->SetParameterL( (TAny*)aEvent->Parameter().Ptr(), |
|
164 aEvent->Parameter().Length() ) ); |
|
165 } |
|
166 if( KErrNone == err ) |
|
167 { |
|
168 item->InformListener(copyEvent); |
|
169 |
|
170 // if it hasn't queued, delete it |
|
171 if( !copyEvent->IsQueued() ) |
|
172 { |
|
173 delete copyEvent; |
|
174 copyEvent = NULL; |
|
175 } |
|
176 } |
|
177 else |
|
178 { |
|
179 //SetParameterL() leaves |
|
180 COM_TRACE_( "[DOSSERVER] CDosEvent::InformListeners - no memory for parameters - no events sent" ); |
|
181 delete copyEvent; |
|
182 copyEvent = NULL; |
|
183 err = KErrNone; |
|
184 } |
|
185 } |
|
186 else |
|
187 { |
|
188 //In no memory case no events are sent |
|
189 COM_TRACE_( "[DOSSERVER] CDosEvent::InformListeners - no memory for event - no events sent" ); |
|
190 } |
|
191 } |
|
192 |
|
193 COM_TRACE_( "[DOSSERVER] CDosEvent::InformListeners - return void" ); |
|
194 |
|
195 } |