|
1 // Copyright (c) 2001-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 |
|
17 // INCLUDES |
|
18 #include "CContactViewEventQueue.h" |
|
19 |
|
20 namespace { |
|
21 |
|
22 // LOCAL CONSTANTS |
|
23 enum TPanicCode |
|
24 { |
|
25 EPanicPreCond_HandleContactViewEvent = 1, |
|
26 EPanicEventQueueFull |
|
27 }; |
|
28 |
|
29 // LOCAL FUNCTIONS |
|
30 void Panic(TPanicCode aReason) |
|
31 { |
|
32 _LIT(KPanicText, "CContactViewEventQueue"); |
|
33 User::Panic(KPanicText,aReason); |
|
34 } |
|
35 |
|
36 void ResetEvent(TContactViewEvent& aEvent) |
|
37 { |
|
38 aEvent.iEventType = TContactViewEvent::TEventType(-1); |
|
39 aEvent.iInt = -1; |
|
40 aEvent.iContactId = KNullContactId; |
|
41 } |
|
42 |
|
43 } |
|
44 |
|
45 |
|
46 // ================= MEMBER FUNCTIONS ======================= |
|
47 |
|
48 CContactViewEventQueue* CContactViewEventQueue::NewL |
|
49 (CContactViewBase* aView, TInt aMaxQueueSize) |
|
50 { |
|
51 CContactViewEventQueue* self = new(ELeave) CContactViewEventQueue; |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(aView,aMaxQueueSize); |
|
54 CleanupStack::Pop(self); |
|
55 return self; |
|
56 } |
|
57 |
|
58 CContactViewEventQueue::~CContactViewEventQueue() |
|
59 { |
|
60 CTimer::Cancel(); |
|
61 if (iView) |
|
62 { |
|
63 iView->Close(*this); |
|
64 } |
|
65 } |
|
66 |
|
67 TBool CContactViewEventQueue::ListenForEvent(TTimeIntervalSeconds aTimeOut, TContactViewEvent& aEvent) |
|
68 { |
|
69 ResetEvent(aEvent); |
|
70 CTimer::Cancel(); |
|
71 |
|
72 if (iQueue.IsEmpty()) |
|
73 { |
|
74 CTimer::After(aTimeOut.Int() * 1000000); |
|
75 // wait for event or for the timer to expire |
|
76 CActiveScheduler::Start(); |
|
77 } |
|
78 |
|
79 if (!iQueue.IsEmpty()) |
|
80 { |
|
81 aEvent = iQueue.Head(); |
|
82 iQueue.PopHead(); |
|
83 return ETrue; |
|
84 } |
|
85 else |
|
86 { |
|
87 return EFalse; |
|
88 } |
|
89 } |
|
90 |
|
91 void CContactViewEventQueue::RunL() |
|
92 { |
|
93 // Timer expired |
|
94 CActiveScheduler::Stop(); |
|
95 } |
|
96 |
|
97 void CContactViewEventQueue::HandleContactViewEvent |
|
98 (const CContactViewBase& aView, const TContactViewEvent& aEvent) |
|
99 { |
|
100 __ASSERT_ALWAYS(!iView || iView == &aView, Panic(EPanicPreCond_HandleContactViewEvent)); |
|
101 |
|
102 TBool eventPushed = iQueue.Push(aEvent); |
|
103 __ASSERT_ALWAYS(eventPushed,Panic(EPanicEventQueueFull)); |
|
104 |
|
105 // If we receive item removed event, it is a signal for the this |
|
106 // view observer to stop observing. |
|
107 // The observer could have been for example a memory entry representation |
|
108 // and the memory entry has now been deleted -> the observer must close and exit. |
|
109 if(iCloseOnItemRemoved && (aEvent.iEventType == TContactViewEvent::EItemRemoved)) |
|
110 { |
|
111 iView->Close(*this); |
|
112 } |
|
113 |
|
114 if (IsActive()) |
|
115 { |
|
116 CTimer::Cancel(); |
|
117 CActiveScheduler::Stop(); |
|
118 } |
|
119 } |
|
120 |
|
121 CContactViewEventQueue::CContactViewEventQueue() |
|
122 : CTimer(CActive::EPriorityStandard) |
|
123 { |
|
124 } |
|
125 |
|
126 void CContactViewEventQueue::ConstructL |
|
127 (CContactViewBase* aView, TInt aMaxQueueSize) |
|
128 { |
|
129 iCloseOnItemRemoved = EFalse; |
|
130 CTimer::ConstructL(); |
|
131 iQueue.ConstructL(aMaxQueueSize); |
|
132 CActiveScheduler::Add(this); |
|
133 if (aView) |
|
134 { |
|
135 aView->OpenL(*this); |
|
136 iView = aView; |
|
137 } |
|
138 } |
|
139 |
|
140 |
|
141 // End of File |