|
1 // Copyright (c) 2005-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 @file |
|
18 @internalComponent |
|
19 @released |
|
20 */ |
|
21 |
|
22 |
|
23 #include "CCntEventQueue.h" |
|
24 #include "CCntServer.h" |
|
25 #include "CCntLogger.h" |
|
26 |
|
27 |
|
28 extern void DebugLogNotification(const TDesC& aMethod, const TContactDbObserverEvent &aEvent); |
|
29 |
|
30 |
|
31 CEventQueue::CEventQueue() |
|
32 : iEvents(KCntEventGranularity) |
|
33 { |
|
34 } |
|
35 |
|
36 |
|
37 CEventQueue::~CEventQueue() |
|
38 { |
|
39 iEvents.Close(); |
|
40 } |
|
41 |
|
42 |
|
43 void CEventQueue::QueueEvent(const TContactDbObserverEvent &aEvent) |
|
44 { |
|
45 // Flush the queue - there's no point in sending out all the preceeding |
|
46 // events when the an Unknown Changes event is being sent. |
|
47 // Unknown changes means that there are too many events to propagate and |
|
48 // the client should resync all its cached data. |
|
49 if (aEvent.iType == EContactDbObserverEventUnknownChanges) |
|
50 { |
|
51 Flush(); |
|
52 } |
|
53 |
|
54 // Is the queue in order, if not then return (no event will be sent) |
|
55 if (Flag(EQueueError)) |
|
56 { |
|
57 return; |
|
58 } |
|
59 |
|
60 // Can we send the event right away, i.e. do we have an outstanding request |
|
61 if (Flag(EValidEventMsg)) |
|
62 { |
|
63 SendEvent(aEvent); |
|
64 }// Is the queue full? If so set flag EQueueError and return |
|
65 else if (iEvents.Count() > KMaxNumberOfEventsInEventQueue) |
|
66 { |
|
67 |
|
68 DEBUG_PRINTDN2(__VERBOSE_DEBUG__,_L("[CNTMODEL] ->X"), aEvent); |
|
69 |
|
70 Flush(); |
|
71 SetFlag(EQueueError); |
|
72 }// Otherwise can we add the request to the queue |
|
73 else if (iEvents.Append(aEvent)!=KErrNone) |
|
74 { |
|
75 SetFlag(EQueueError); |
|
76 } |
|
77 #if defined(__VERBOSE_DEBUG__) |
|
78 else |
|
79 { |
|
80 // If added then add it to log |
|
81 DebugLogNotification(_L("[CNTMODEL] ->Q"), aEvent); |
|
82 } |
|
83 #endif |
|
84 } |
|
85 |
|
86 |
|
87 void CEventQueue::Flush() |
|
88 { |
|
89 iEvents.Reset(); |
|
90 } |
|
91 |
|
92 |
|
93 void CEventQueue::RequestEvent(const RMessage2& aMessage) |
|
94 { |
|
95 __ASSERT_DEBUG(!Flag(EValidEventMsg),User::Leave(KErrCompletion)); |
|
96 if (!Flag(EValidEventMsg)) |
|
97 { |
|
98 iEventMsg=aMessage; |
|
99 SetFlag(EValidEventMsg); |
|
100 if (Flag(EQueueError)) |
|
101 { |
|
102 TContactDbObserverEvent errorEvent; |
|
103 //EContactDbObserverEventUnknownChanges is indicating that the event queue is full |
|
104 errorEvent.iType = EContactDbObserverEventUnknownChanges; |
|
105 errorEvent.iContactId = KNullContactId; |
|
106 errorEvent.iConnectionId = KCntNullConnectionId; |
|
107 ClearFlag(EQueueError); |
|
108 SendEvent(errorEvent); |
|
109 } |
|
110 else if (iEvents.Count()>0) |
|
111 { |
|
112 SendEvent(iEvents[0]); |
|
113 iEvents.Remove(0); |
|
114 } |
|
115 else |
|
116 { |
|
117 //No events has happened, so there is nothing to tell the client, |
|
118 //But to be able to test the API policing we will complete the message |
|
119 //if it contains the ApiPolicingTest flag and that the message is sent by the |
|
120 //API policing test process sid(0x101F7784) |
|
121 TInt isApiPolicingTest = aMessage.Int1(); |
|
122 if (isApiPolicingTest == 666 && aMessage.SecureId() == 0x101F7784) |
|
123 { |
|
124 TContactDbObserverEvent nullEvent; |
|
125 nullEvent.iType = EContactDbObserverEventNull; |
|
126 nullEvent.iConnectionId = 0; |
|
127 SendEvent(nullEvent); |
|
128 } |
|
129 } |
|
130 } |
|
131 } |
|
132 |
|
133 |
|
134 void CEventQueue::CancelEventRequest() |
|
135 { |
|
136 if (Flag(EValidEventMsg)) |
|
137 { |
|
138 iEventMsg.Complete(KErrCancel); |
|
139 ClearFlag(EValidEventMsg); |
|
140 } |
|
141 } |
|
142 |
|
143 |
|
144 void CEventQueue::SendEvent(const TContactDbObserverEvent &aEvent) |
|
145 { |
|
146 DEBUG_PRINTDN2(__VERBOSE_DEBUG__,_L("[CNTMODEL] Q->"), aEvent); |
|
147 |
|
148 TPckgC<TContactDbObserverEvent> event(aEvent); |
|
149 TInt err = iEventMsg.Write(0, event); |
|
150 if (err != KErrNone) |
|
151 { |
|
152 // If there is an error caused, for example, by the client dying, just log the error code. |
|
153 DEBUG_PRINT2(__VERBOSE_DEBUG__, _L("[CNTMODEL] iEventMsg.Write() error: %d"), err); |
|
154 } |
|
155 else |
|
156 { |
|
157 iEventMsg.Complete(KErrNone); |
|
158 } |
|
159 ClearFlag(EValidEventMsg); |
|
160 } |
|
161 |
|
162 |
|
163 TBool CEventQueue::Flag(TFlag aFlag) |
|
164 { |
|
165 return iFlags&aFlag; |
|
166 } |
|
167 |
|
168 |
|
169 void CEventQueue::SetFlag(TFlag aFlag) |
|
170 { |
|
171 iFlags|=aFlag; |
|
172 } |
|
173 |
|
174 |
|
175 void CEventQueue::ClearFlag(TFlag aFlag) |
|
176 { |
|
177 iFlags&=(~aFlag); |
|
178 } |