2
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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 |
*
|
|
16 |
*/
|
|
17 |
#include <e32svr.h>
|
|
18 |
|
|
19 |
#include <stfeventsystemerrorcodes.h>
|
|
20 |
#include "eventsystemsession.h"
|
|
21 |
#include "eventsystemserver.h"
|
|
22 |
|
|
23 |
|
|
24 |
/**
|
|
25 |
Constructor
|
|
26 |
*/
|
|
27 |
CEventSystemSession::CEventSystemSession()
|
|
28 |
{
|
|
29 |
//RDebug::Print(_L("STF [ESS]: CEventSystemSession::CEventSystemSession"));
|
|
30 |
}
|
|
31 |
|
|
32 |
/**
|
|
33 |
Destructor
|
|
34 |
*/
|
|
35 |
CEventSystemSession::~CEventSystemSession()
|
|
36 |
{
|
|
37 |
//RDebug::Print(_L("STF [ESS]: CEventSystemSession::~CEventSystemSession"));
|
|
38 |
// Check if there is waiting event registered
|
|
39 |
if(iWaitingEvent)
|
|
40 |
{
|
|
41 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::~CEventSystemSession iWaitingEvent is defined, will be handled"));
|
|
42 |
TInt i;
|
|
43 |
|
|
44 |
for(i = 0; i < ((CEventSystemServer*)Server())->iWaitingEvents.Count(); i++)
|
|
45 |
{
|
|
46 |
CWaitingEvent* event = ((CEventSystemServer*)Server())->iWaitingEvents[i];
|
|
47 |
// Check if this event matches
|
|
48 |
if(event == iWaitingEvent)
|
|
49 |
{
|
|
50 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::~CEventSystemSession iWaitingEvent found in the array"));
|
|
51 |
if(event->IsWaiting())
|
|
52 |
{
|
|
53 |
// Complete event and remove it from list of waiting events
|
|
54 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::~CEventSystemSession iWaitingEvent in EEventWait state, cancelling"));
|
|
55 |
event->CancelEvent();
|
|
56 |
((CEventSystemServer*)Server())->iWaitingEvents.Remove(i);
|
|
57 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::~CEventSystemSession deleting iWaitingEvent"));
|
|
58 |
delete event;
|
|
59 |
event = NULL;
|
|
60 |
iWaitingEvent = NULL;
|
|
61 |
}
|
|
62 |
break;
|
|
63 |
}
|
|
64 |
}
|
|
65 |
}
|
|
66 |
|
|
67 |
// Close session if not closed properly
|
|
68 |
if(iContainer)
|
|
69 |
{
|
|
70 |
CloseSession();
|
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
|
|
75 |
/**
|
|
76 |
Called by client/server framework after
|
|
77 |
session has been successfully created.
|
|
78 |
|
|
79 |
In effect, a second-phase constructor.
|
|
80 |
|
|
81 |
Creates:
|
|
82 |
|
|
83 |
1. the object index
|
|
84 |
2. the object container for this session.
|
|
85 |
|
|
86 |
We are then ready for subsessions.
|
|
87 |
*/
|
|
88 |
void CEventSystemSession::CreateL()
|
|
89 |
{
|
|
90 |
// RDebug::Print(_L("STF [ESS]: CEventSystemSession::CreateL"));
|
|
91 |
// // Create new object index
|
|
92 |
// iTestCaseRunnerObjectIndex = CObjectIx::NewL();
|
|
93 |
|
|
94 |
// Initialize the object container
|
|
95 |
// using the object container index in the server.
|
|
96 |
iContainer = ((CEventSystemServer*)Server())->NewContainerL();
|
|
97 |
|
|
98 |
// Adds session (updates counter)
|
|
99 |
((CEventSystemServer*)Server())->AddSession();
|
|
100 |
}
|
|
101 |
|
|
102 |
|
|
103 |
/**
|
|
104 |
Closes the session.
|
|
105 |
|
|
106 |
It deletes the object index and object container.
|
|
107 |
|
|
108 |
This could be done in the destructor, but it seems neater to do it here.
|
|
109 |
*/
|
|
110 |
void CEventSystemSession::CloseSession()
|
|
111 |
{
|
|
112 |
// RDebug::Print(_L("STF [ESS]: CEventSystemSession::CloseSession"));
|
|
113 |
// Deletes the object index.
|
|
114 |
// delete iTestCaseRunnerObjectIndex;
|
|
115 |
// iTestCaseRunnerObjectIndex = NULL;
|
|
116 |
|
|
117 |
// Deletes the object container
|
|
118 |
((CEventSystemServer*)Server())->RemoveContainer(iContainer);
|
|
119 |
//delete iContainer; // RemoveContainer deletes the object
|
|
120 |
iContainer = NULL;
|
|
121 |
|
|
122 |
// Removes session
|
|
123 |
((CEventSystemServer*)Server())->RemoveSession();
|
|
124 |
}
|
|
125 |
|
|
126 |
/**
|
|
127 |
First line servicing of a client request.
|
|
128 |
|
|
129 |
This function dispatches requests to the appropriate handler.
|
|
130 |
Some messages are handled by the session itself, and are
|
|
131 |
implemented as CCountSession member functions, while
|
|
132 |
other messages are handled by the subsession, and are
|
|
133 |
implemented as CCountSubSession member functions.
|
|
134 |
*/
|
|
135 |
void CEventSystemSession::ServiceL(const RMessage2& aMessage)
|
|
136 |
{
|
|
137 |
// RDebug::Print(_L("STF [ESS]: CEventSystemSession::ServiceL"));
|
|
138 |
DispatchMessageL(aMessage);
|
|
139 |
}
|
|
140 |
|
|
141 |
|
|
142 |
/**
|
|
143 |
Called by ServiceL()
|
|
144 |
|
|
145 |
It tests the function code and then delegates to
|
|
146 |
the appropriate function.
|
|
147 |
*/
|
|
148 |
void CEventSystemSession::DispatchMessageL(const RMessage2& aMessage)
|
|
149 |
{
|
|
150 |
// RDebug::Print(_L("STF [ESS]: CEventSystemSession::DispatchMessageL function=[%d] message=[%x]"), aMessage.Function(), &aMessage);
|
|
151 |
TInt err;
|
|
152 |
|
|
153 |
// First check for session-relative requests
|
|
154 |
switch(aMessage.Function())
|
|
155 |
{
|
|
156 |
// Session relevant commands
|
|
157 |
case EEventSystemServCloseSession:
|
|
158 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::DispatchMessageL EEventSystemServCloseSession"));
|
|
159 |
CloseSession();
|
|
160 |
RDebug::Print(_L("STF [ESS]: Completing message EEventSystemServCloseSession"));
|
|
161 |
aMessage.Complete(KErrNone);
|
|
162 |
break;
|
|
163 |
|
|
164 |
case EEventSystemSetEvent:
|
|
165 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::DispatchMessageL EEventSystemSetEvent"));
|
|
166 |
TRAP(err, SetStateEventL(aMessage));
|
|
167 |
RDebug::Print(_L("STF [ESS]: Completing message EEventSystemSetEvent with [%d]"), err);
|
|
168 |
aMessage.Complete(err);
|
|
169 |
break;
|
|
170 |
|
|
171 |
case EEventSystemUnsetEvent:
|
|
172 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::DispatchMessageL EEventSystemUnsetEvent"));
|
|
173 |
TRAP(err, UnsetStateEventL(aMessage));
|
|
174 |
RDebug::Print(_L("STF [ESS]: Completing message EEventSystemUnsetEvent with [%d]"), err);
|
|
175 |
aMessage.Complete(err);
|
|
176 |
break;
|
|
177 |
|
|
178 |
case EEventSystemSetIndicationEvent:
|
|
179 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::DispatchMessageL EEventSystemSetIndicationEvent"));
|
|
180 |
TRAP(err, SetIndicationEventL(aMessage));
|
|
181 |
RDebug::Print(_L("STF [ESS]: Completing message EEventSystemSetIndicationEvent with [%d]"), err);
|
|
182 |
aMessage.Complete(err);
|
|
183 |
break;
|
|
184 |
|
|
185 |
case EEventSystemWaitEvent:
|
|
186 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::DispatchMessageL EEventSystemWaitEvent"));
|
|
187 |
TRAP(err, WaitForEventL(aMessage));
|
|
188 |
if(err != KErrNone)
|
|
189 |
{
|
|
190 |
RDebug::Print(_L("STF [ESS]: Completing message EEventSystemWaitEvent with [%d]"), err);
|
|
191 |
aMessage.Complete(err);
|
|
192 |
}
|
|
193 |
break;
|
|
194 |
|
|
195 |
case EEventSystemCancelWaitEvent:
|
|
196 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::DispatchMessageL EEventSystemCancelWaitEvent"));
|
|
197 |
TRAP(err, CancelWaitingEventL(aMessage));
|
|
198 |
if(err != KErrNone)
|
|
199 |
{
|
|
200 |
RDebug::Print(_L("STF [ESS]: Completing message EEventSystemCancelWaitEvent with [%d]"), err);
|
|
201 |
aMessage.Complete(err);
|
|
202 |
}
|
|
203 |
break;
|
|
204 |
|
|
205 |
case EEventSystemRequestEvent:
|
|
206 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::DispatchMessageL EEventSystemRequestEvent"));
|
|
207 |
TRAP(err, RequestEventL(aMessage));
|
|
208 |
RDebug::Print(_L("STF [ESS]: Completing message EEventSystemRequestEvent with [%d]"), err);
|
|
209 |
aMessage.Complete(err);
|
|
210 |
break;
|
|
211 |
|
|
212 |
case EEventSystemReleaseEvent:
|
|
213 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::DispatchMessageL EEventSystemReleaseEvent"));
|
|
214 |
TRAP(err, ReleaseEventL(aMessage));
|
|
215 |
RDebug::Print(_L("STF [ESS]: Completing message EEventSystemReleaseEvent with [%d]"), err);
|
|
216 |
aMessage.Complete(err);
|
|
217 |
break;
|
|
218 |
|
|
219 |
case EEventSystemRemoveInRequestedState:
|
|
220 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::DispatchMessageL EEventSystemRemoveInRequestedState"));
|
|
221 |
TRAP(err, RemoveInRequestedStateL(aMessage));
|
|
222 |
RDebug::Print(_L("STF [ESS]: Completing message EEventSystemRemoveInRequestedState with [%d]"), err);
|
|
223 |
aMessage.Complete(err);
|
|
224 |
break;
|
|
225 |
|
|
226 |
|
|
227 |
default:
|
|
228 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::DispatchMessageL unknown function"));
|
|
229 |
PanicClient(aMessage, EEventSystemSessionUnknownMessage);
|
|
230 |
}
|
|
231 |
}
|
|
232 |
|
|
233 |
/**
|
|
234 |
Panics the client
|
|
235 |
*/
|
|
236 |
void CEventSystemSession::PanicClient(const RMessage2& aMessage, const TInt aPanic) const
|
|
237 |
{
|
|
238 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::PanicClient"));
|
|
239 |
_LIT(KMessage, "CEventSystemSession");
|
|
240 |
aMessage.Panic(KMessage, aPanic);
|
|
241 |
}
|
|
242 |
|
|
243 |
|
|
244 |
/**
|
|
245 |
Set indication event
|
|
246 |
*/
|
|
247 |
void CEventSystemSession::SetIndicationEventL(const RMessage2& aMessage)
|
|
248 |
{
|
|
249 |
// Get event data
|
|
250 |
RBuf eventName;
|
|
251 |
eventName.CreateL(KMaxEventName);
|
|
252 |
eventName.CleanupClosePushL();
|
|
253 |
aMessage.ReadL(0, eventName);
|
|
254 |
|
|
255 |
RDebug::Print(_L("STF [ESS]: setting indication event [%S]"), &eventName);
|
|
256 |
|
|
257 |
// Notify requested events
|
|
258 |
NotifyRequestedEventsL(eventName);
|
|
259 |
|
|
260 |
// Complete waiting events
|
|
261 |
CompleteWaitingEventsL(eventName);
|
|
262 |
|
|
263 |
// Clean data
|
|
264 |
CleanupStack::PopAndDestroy(&eventName);
|
|
265 |
}
|
|
266 |
|
|
267 |
/**
|
|
268 |
Request event
|
|
269 |
*/
|
|
270 |
void CEventSystemSession::RequestEventL(const RMessage2& aMessage)
|
|
271 |
{
|
|
272 |
// Get event data
|
|
273 |
RBuf eventName;
|
|
274 |
eventName.CreateL(KMaxEventName);
|
|
275 |
eventName.CleanupClosePushL();
|
|
276 |
aMessage.ReadL(0, eventName);
|
|
277 |
|
|
278 |
TInt ownerId = aMessage.Int1();
|
|
279 |
|
|
280 |
// Check if event is not already requested
|
|
281 |
TInt i = 0;
|
|
282 |
if(((CEventSystemServer*)Server())->SearchForWaiting(eventName, ownerId, i))
|
|
283 |
{
|
|
284 |
RDebug::Print(_L("STF [ESS]: Requested event [%S] already exists, leaving"), &eventName);
|
|
285 |
User::Leave(KErrAlreadyExists);
|
|
286 |
}
|
|
287 |
|
|
288 |
// Create waiting event - it's first state will be EEventRequested
|
|
289 |
RDebug::Print(_L("STF [ESS]: Waiting event registered [%S]"), &eventName);
|
|
290 |
iWaitingEvent = CWaitingEvent::NewL(eventName, ownerId);
|
|
291 |
((CEventSystemServer*)Server())->iWaitingEvents.Append(iWaitingEvent);
|
|
292 |
|
|
293 |
// Clean data
|
|
294 |
CleanupStack::PopAndDestroy(&eventName);
|
|
295 |
}
|
|
296 |
|
|
297 |
/**
|
|
298 |
Release event
|
|
299 |
*/
|
|
300 |
void CEventSystemSession::ReleaseEventL(const RMessage2& aMessage)
|
|
301 |
{
|
|
302 |
// Get event data
|
|
303 |
RBuf eventName;
|
|
304 |
eventName.CreateL(KMaxEventName);
|
|
305 |
eventName.CleanupClosePushL();
|
|
306 |
aMessage.ReadL(0, eventName);
|
|
307 |
|
|
308 |
TInt ownerId = aMessage.Int1();
|
|
309 |
|
|
310 |
// Check if event is requested
|
|
311 |
TInt i = 0;
|
|
312 |
if(((CEventSystemServer*)Server())->SearchForWaiting(eventName, ownerId, i))
|
|
313 |
{
|
|
314 |
CWaitingEvent* event = ((CEventSystemServer*)Server())->iWaitingEvents[i];
|
|
315 |
|
|
316 |
// If event is waiting, cancel it
|
|
317 |
if(event->IsWaiting())
|
|
318 |
{
|
|
319 |
event->CancelEvent();
|
|
320 |
}
|
|
321 |
|
|
322 |
// Check if there is any candidate to be unset
|
|
323 |
TInt j = ((CEventSystemServer*)Server())->SearchForState(eventName);
|
|
324 |
if(j != KErrNotFound)
|
|
325 |
{
|
|
326 |
CStateEvent* state = ((CEventSystemServer*)Server())->iStateEvents[j];
|
|
327 |
if(state->IsToBeUnset())
|
|
328 |
{
|
|
329 |
((CEventSystemServer*)Server())->iStateEvents.Remove(j);
|
|
330 |
delete state;
|
|
331 |
state = NULL;
|
|
332 |
}
|
|
333 |
}
|
|
334 |
|
|
335 |
|
|
336 |
// Delete waiting event
|
|
337 |
((CEventSystemServer*)Server())->iWaitingEvents.Remove(i);
|
|
338 |
delete event;
|
|
339 |
event = NULL;
|
|
340 |
}
|
|
341 |
else // Event was not requested
|
|
342 |
{
|
|
343 |
RDebug::Print(_L("STF [ESS]: Event [%S] to be releases doesn't exist, leaving"), &eventName);
|
|
344 |
User::Leave(KErrNotFound);
|
|
345 |
}
|
|
346 |
|
|
347 |
// Clean data
|
|
348 |
CleanupStack::PopAndDestroy(&eventName);
|
|
349 |
}
|
|
350 |
|
|
351 |
/**
|
|
352 |
Wait for event
|
|
353 |
*/
|
|
354 |
void CEventSystemSession::WaitForEventL(const RMessage2& aMessage)
|
|
355 |
{
|
|
356 |
__ASSERT_ALWAYS(iWaitingEvent == NULL, PanicClient(aMessage, EEventSystemSessionAlreadyWaiting));
|
|
357 |
|
|
358 |
// Get event data
|
|
359 |
RBuf eventName;
|
|
360 |
eventName.CreateL(KMaxEventName);
|
|
361 |
eventName.CleanupClosePushL();
|
|
362 |
aMessage.ReadL(0, eventName);
|
|
363 |
|
|
364 |
TInt ownerId = aMessage.Int1();
|
|
365 |
|
|
366 |
// Check if event is requested
|
|
367 |
TInt i = 0;
|
|
368 |
if(((CEventSystemServer*)Server())->SearchForWaiting(eventName, ownerId, i))
|
|
369 |
{
|
|
370 |
CWaitingEvent* event = ((CEventSystemServer*)Server())->iWaitingEvents[i];
|
|
371 |
|
|
372 |
// Set in waiting state
|
|
373 |
iWaitingEvent = event;
|
|
374 |
event->WaitL(aMessage, this);
|
|
375 |
CompleteFromStateEventL(event);
|
|
376 |
}
|
|
377 |
else
|
|
378 |
{
|
|
379 |
RDebug::Print(_L("STF [ESS]: Event [%S] not requested"), &eventName);
|
|
380 |
User::Leave(EEventSystemNotRequested);
|
|
381 |
}
|
|
382 |
|
|
383 |
// Clean data
|
|
384 |
CleanupStack::PopAndDestroy(&eventName);
|
|
385 |
}
|
|
386 |
|
|
387 |
/**
|
|
388 |
Cancel waiting message from the same session
|
|
389 |
*/
|
|
390 |
void CEventSystemSession::CancelWaitingEventL(const RMessage2& aMessage)
|
|
391 |
{
|
|
392 |
// Get event data
|
|
393 |
RBuf eventName;
|
|
394 |
eventName.CreateL(KMaxEventName);
|
|
395 |
eventName.CleanupClosePushL();
|
|
396 |
aMessage.ReadL(0, eventName);
|
|
397 |
|
|
398 |
TInt ownerId = aMessage.Int1();
|
|
399 |
|
|
400 |
// Search for waiting events
|
|
401 |
TInt i = 0;
|
|
402 |
while(((CEventSystemServer*)Server())->SearchForWaiting(eventName, ownerId, i))
|
|
403 |
{
|
|
404 |
CWaitingEvent* event = ((CEventSystemServer*)Server())->iWaitingEvents[i];
|
|
405 |
if(event->IsMatchingSession(this))
|
|
406 |
{
|
|
407 |
// Complete event and remove it from list of waiting events
|
|
408 |
event->CancelEvent();
|
|
409 |
((CEventSystemServer*)Server())->iWaitingEvents.Remove(i);
|
|
410 |
// Delete waiting event
|
|
411 |
delete event;
|
|
412 |
event = NULL;
|
|
413 |
break;
|
|
414 |
}
|
|
415 |
//Increase index, so SearchForWaiting will start searching with following entries
|
|
416 |
i++;
|
|
417 |
}
|
|
418 |
aMessage.Complete(KErrNone);
|
|
419 |
|
|
420 |
// Clean data
|
|
421 |
CleanupStack::PopAndDestroy(&eventName);
|
|
422 |
}
|
|
423 |
|
|
424 |
/**
|
|
425 |
Check list of waiting events. If any of them is found, complete it.
|
|
426 |
*/
|
|
427 |
void CEventSystemSession::CompleteWaitingEventsL(const TDesC& aEventName)
|
|
428 |
{
|
|
429 |
TInt i = 0;
|
|
430 |
while(((CEventSystemServer*)Server())->SearchForWaiting(aEventName, i))
|
|
431 |
{
|
|
432 |
CWaitingEvent* event = ((CEventSystemServer*)Server())->iWaitingEvents[i];
|
|
433 |
// Check if this event matches
|
|
434 |
if(event->IsWaiting())
|
|
435 |
{
|
|
436 |
// Complete event
|
|
437 |
event->CompleteEventL();
|
|
438 |
}
|
|
439 |
//Increase index, so SearchForWaiting will start searching with following entries
|
|
440 |
i++;
|
|
441 |
}
|
|
442 |
}
|
|
443 |
|
|
444 |
/**
|
|
445 |
Check list of requested events. If any of them is found, notify about event.
|
|
446 |
*/
|
|
447 |
void CEventSystemSession::NotifyRequestedEventsL(const TDesC& aEventName)
|
|
448 |
{
|
|
449 |
TInt i = 0;
|
|
450 |
while(((CEventSystemServer*)Server())->SearchForWaiting(aEventName, i))
|
|
451 |
{
|
|
452 |
CWaitingEvent* event = ((CEventSystemServer*)Server())->iWaitingEvents[i];
|
|
453 |
// Check if this event matches
|
|
454 |
if(event->IsRequested())
|
|
455 |
{
|
|
456 |
// Complete event
|
|
457 |
event->NotifyRequestedEventL();
|
|
458 |
}
|
|
459 |
//Increase index, so SearchForWaiting will start searching with following entries
|
|
460 |
i++;
|
|
461 |
}
|
|
462 |
}
|
|
463 |
|
|
464 |
/**
|
|
465 |
Check list of state events. If any of them matches current waiting event, complete waiting event.
|
|
466 |
*/
|
|
467 |
void CEventSystemSession::CompleteFromStateEventL(CWaitingEvent* aEvent)
|
|
468 |
{
|
|
469 |
TInt i = ((CEventSystemServer*)Server())->SearchForState(aEvent->EventName());
|
|
470 |
if(i != KErrNotFound)
|
|
471 |
{
|
|
472 |
RDebug::Print(_L("STF [ESS]: CEventSystemSession::CompleteFromStateEventL event [%S]"), &aEvent->EventName());
|
|
473 |
aEvent->CompleteEventL();
|
|
474 |
}
|
|
475 |
}
|
|
476 |
|
|
477 |
/**
|
|
478 |
Set state event
|
|
479 |
*/
|
|
480 |
void CEventSystemSession::SetStateEventL(const RMessage2& aMessage)
|
|
481 |
{
|
|
482 |
// Get event data
|
|
483 |
RBuf eventName;
|
|
484 |
eventName.CreateL(KMaxEventName);
|
|
485 |
eventName.CleanupClosePushL();
|
|
486 |
aMessage.ReadL(0, eventName);
|
|
487 |
|
|
488 |
// Setting state event
|
|
489 |
RDebug::Print(_L("STF [ESS]: setting state event [%S]"), &eventName);
|
|
490 |
AddStateEventL(eventName);
|
|
491 |
|
|
492 |
// Complete waiting events
|
|
493 |
CompleteWaitingEventsL(eventName);
|
|
494 |
|
|
495 |
// Clean data
|
|
496 |
CleanupStack::PopAndDestroy(&eventName);
|
|
497 |
}
|
|
498 |
|
|
499 |
/**
|
|
500 |
Unset state event
|
|
501 |
*/
|
|
502 |
void CEventSystemSession::UnsetStateEventL(const RMessage2& aMessage)
|
|
503 |
{
|
|
504 |
// Get event data
|
|
505 |
RBuf eventName;
|
|
506 |
eventName.CreateL(KMaxEventName);
|
|
507 |
eventName.CleanupClosePushL();
|
|
508 |
aMessage.ReadL(0, eventName);
|
|
509 |
|
|
510 |
// Search for state event
|
|
511 |
TBool cannotBeUnset = EFalse;
|
|
512 |
CStateEvent* event = NULL;
|
|
513 |
|
|
514 |
TInt i = ((CEventSystemServer*)Server())->SearchForState(eventName);
|
|
515 |
if(i != KErrNotFound)
|
|
516 |
{
|
|
517 |
// State event found, do further checking with requested events
|
|
518 |
event = ((CEventSystemServer*)Server())->iStateEvents[i];
|
|
519 |
TInt j = 0;
|
|
520 |
while(((CEventSystemServer*)Server())->SearchForWaiting(eventName, j))
|
|
521 |
{
|
|
522 |
CWaitingEvent* waiting = ((CEventSystemServer*)Server())->iWaitingEvents[j];
|
|
523 |
// If waiting event is in requested state, we can't unset our event, we can only mark it to be unset later
|
|
524 |
if(waiting->IsRequested())
|
|
525 |
{
|
|
526 |
// Set the flag
|
|
527 |
event->NotifyToBeUnset(ETrue);
|
|
528 |
cannotBeUnset = ETrue;
|
|
529 |
}
|
|
530 |
//Increase index, so SearchForWaiting will start searching with following entries
|
|
531 |
j++;
|
|
532 |
}
|
|
533 |
}
|
|
534 |
else
|
|
535 |
{
|
|
536 |
// State event was not found
|
|
537 |
RDebug::Print(_L("STF [ESS]: unset: state event [%S] not set, leaving with [%d]"), &eventName, KErrNotFound);
|
|
538 |
User::Leave(KErrNotFound);
|
|
539 |
}
|
|
540 |
|
|
541 |
// Unsetting event because we have no found any requested events
|
|
542 |
if(!cannotBeUnset)
|
|
543 |
{
|
|
544 |
// Unsetting state event
|
|
545 |
RDebug::Print(_L("STF [ESS]: unsetting state event [%S]"), &eventName);
|
|
546 |
((CEventSystemServer*)Server())->iStateEvents.Remove(i);
|
|
547 |
delete event;
|
|
548 |
event = NULL;
|
|
549 |
}
|
|
550 |
|
|
551 |
// Clean data
|
|
552 |
CleanupStack::PopAndDestroy(&eventName);
|
|
553 |
}
|
|
554 |
|
|
555 |
/**
|
|
556 |
Add state event in the state events array
|
|
557 |
*/
|
|
558 |
void CEventSystemSession::AddStateEventL(const TDesC& aEventName)
|
|
559 |
{
|
|
560 |
CStateEvent *event;
|
|
561 |
|
|
562 |
TInt i = ((CEventSystemServer*)Server())->SearchForState(aEventName);
|
|
563 |
if(i != KErrNotFound)
|
|
564 |
{
|
|
565 |
event = ((CEventSystemServer*)Server())->iStateEvents[i];
|
|
566 |
// Event found, leave (or not, if event was unset but could not be due to some not released wait)
|
|
567 |
if(event->IsToBeUnset())
|
|
568 |
{
|
|
569 |
// Reset the flag (equivalent to situation when theoretically unset event is set again)
|
|
570 |
event->NotifyToBeUnset(EFalse);
|
|
571 |
}
|
|
572 |
else
|
|
573 |
{
|
|
574 |
// Leave
|
|
575 |
RDebug::Print(_L("STF [ESS]: set: state event [%S] already set, leaving with [%d]"), &aEventName, KErrAlreadyExists);
|
|
576 |
User::Leave(KErrAlreadyExists);
|
|
577 |
}
|
|
578 |
}
|
|
579 |
else
|
|
580 |
{
|
|
581 |
// Event not found, add it
|
|
582 |
event = CStateEvent::NewL(aEventName);
|
|
583 |
((CEventSystemServer*)Server())->iStateEvents.Append(event);
|
|
584 |
}
|
|
585 |
}
|
|
586 |
|
|
587 |
|
|
588 |
/**
|
|
589 |
Remove (like would be released) all requested events.
|
|
590 |
Waiting events will be handled via destructor of opened session
|
|
591 |
*/
|
|
592 |
void CEventSystemSession::RemoveInRequestedStateL(const RMessage2& aMessage)
|
|
593 |
{
|
|
594 |
// Get event data
|
|
595 |
TInt ownerId = aMessage.Int0();
|
|
596 |
RDebug::Print(_L("STF [ESS]: Removing all requested events of owner [%d], count=[%d]"), ownerId, ((CEventSystemServer*)Server())->iWaitingEvents.Count());
|
|
597 |
|
|
598 |
// Check if event is requested
|
|
599 |
TInt i = 0;
|
|
600 |
while(i < ((CEventSystemServer*)Server())->iWaitingEvents.Count())
|
|
601 |
{
|
|
602 |
CWaitingEvent* event = ((CEventSystemServer*)Server())->iWaitingEvents[i];
|
|
603 |
|
|
604 |
if(event->OwnerId() == ownerId && event->IsRequested())
|
|
605 |
{
|
|
606 |
// Check if there is any candidate to be unset
|
|
607 |
TInt j = ((CEventSystemServer*)Server())->SearchForState(event->EventName());
|
|
608 |
if(j != KErrNotFound)
|
|
609 |
{
|
|
610 |
CStateEvent* state = ((CEventSystemServer*)Server())->iStateEvents[j];
|
|
611 |
if(state->IsToBeUnset())
|
|
612 |
{
|
|
613 |
((CEventSystemServer*)Server())->iStateEvents.Remove(j);
|
|
614 |
delete state;
|
|
615 |
state = NULL;
|
|
616 |
}
|
|
617 |
}
|
|
618 |
|
|
619 |
// And remove and delete
|
|
620 |
((CEventSystemServer*)Server())->iWaitingEvents.Remove(i);
|
|
621 |
delete event;
|
|
622 |
event = NULL;
|
|
623 |
}
|
|
624 |
else
|
|
625 |
{
|
|
626 |
i++;
|
|
627 |
}
|
|
628 |
}
|
|
629 |
}
|
|
630 |
// EOF
|
|
631 |
|