82 void CSimReduceTimers::SimPSEvent(const CSimPubSub::TPubSubProperty aProperty, TInt aStatus) |
88 void CSimReduceTimers::SimPSEvent(const CSimPubSub::TPubSubProperty aProperty, TInt aStatus) |
83 { |
89 { |
84 if (aProperty == iPSProperty && // Condition for correct property |
90 if (aProperty == iPSProperty && // Condition for correct property |
85 (aStatus == ETimerIdAllTimers)) // and correct value for signal |
91 (aStatus == ETimerIdAllTimers)) // and correct value for signal |
86 { |
92 { |
87 LOGMISC1(">>CSimReduceTimers.cpp: Reduce Timer event fired for all timers"); |
93 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_SIMPSEVENT_1, ">>CSimReduceTimers.cpp: Reduce Timer event fired for all timers"); |
88 Notify(); |
94 Notify(); |
89 } |
95 } |
90 else if(aProperty == iPSProperty && aStatus > 0) |
96 else if(aProperty == iPSProperty && aStatus > 0) |
91 { |
97 { |
92 LOGMISC2(">>CSimReduceTimers.cpp: Reduce Timer event fired for event ID %d", aStatus); |
98 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_SIMPSEVENT_2, ">>CSimReduceTimers.cpp: Reduce Timer event fired for event ID %d", aStatus); |
93 Notify(aStatus); |
99 Notify(aStatus); |
94 } |
100 } |
95 } |
101 } |
96 |
102 |
97 void CSimReduceTimers::AttachL(MSimTimerUpdateObserver* aObserver) |
103 void CSimReduceTimers::AttachL(MSimTimerUpdateObserver* aObserver) |
98 { |
104 { |
99 LOGMISC1("CSimReduceTimers::AttachL"); |
105 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_ATTACHL_1, "CSimReduceTimers::AttachL"); |
100 User::LeaveIfError(iObservers.Append(aObserver)); |
106 User::LeaveIfError(iObservers.Append(aObserver)); |
101 } |
107 } |
102 |
108 |
103 void CSimReduceTimers::DetachL(MSimTimerUpdateObserver* aObserver) |
109 void CSimReduceTimers::DetachL(MSimTimerUpdateObserver* aObserver) |
104 { |
110 { |
105 TInt pos = iObservers.Find(aObserver); |
111 TInt pos = iObservers.Find(aObserver); |
106 LOGMISC2("CSimReduceTimers::DetachL, from position %d", pos); |
112 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_DETACHL_1, "CSimReduceTimers::DetachL, from position %d", pos); |
107 User::LeaveIfError(pos); |
113 User::LeaveIfError(pos); |
108 iObservers.Remove(pos); |
114 iObservers.Remove(pos); |
109 } |
115 } |
110 |
116 |
111 void CSimReduceTimers::Notify() |
117 void CSimReduceTimers::Notify() |
112 { |
118 { |
113 TInt totalItems = iObservers.Count(); |
119 TInt totalItems = iObservers.Count(); |
114 LOGMISC2("CSimReduceTimers::Notify, %d observers registered", totalItems); |
120 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_NOTIFY_1, "CSimReduceTimers::Notify, %d observers registered", totalItems); |
115 if (totalItems <= 0) |
121 if (totalItems <= 0) |
116 { |
122 { |
117 LOGMISC1("CSimReduceTimers::Notify, No timers to reduce."); |
123 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_NOTIFY_2, "CSimReduceTimers::Notify, No timers to reduce."); |
118 return; |
124 return; |
119 } |
125 } |
120 |
126 |
121 TInt minTimeReduce = KMaxTInt; |
127 TInt minTimeReduce = KMaxTInt; |
122 TInt num; |
128 TInt num; |
123 for (num = 0; num < totalItems; num++) |
129 for (num = 0; num < totalItems; num++) |
124 { |
130 { |
125 TInt temp = iObservers[num]->GetRemainingSeconds(); |
131 TInt temp = iObservers[num]->GetRemainingSeconds(); |
126 LOGMISC3("CSimReduceTimers::Notify, iObservers[%d] remaining time = %d", num, temp); |
132 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_NOTIFY_3, "CSimReduceTimers::Notify, iObservers[%d] remaining time = %d", num, temp); |
127 |
133 |
128 // Ensure no error is returned and check if the current itteration gives a lower time remaining. |
134 // Ensure no error is returned and check if the current itteration gives a lower time remaining. |
129 if (temp > 0 && temp < minTimeReduce) |
135 if (temp > 0 && temp < minTimeReduce) |
130 { |
136 { |
131 minTimeReduce = temp; |
137 minTimeReduce = temp; |
132 } |
138 } |
133 } |
139 } |
134 |
140 |
135 if (minTimeReduce == KMaxTInt) |
141 if (minTimeReduce == KMaxTInt) |
136 { |
142 { |
137 LOGMISC1("CSimReduceTimers::Notify, No running timers."); |
143 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_NOTIFY_4, "CSimReduceTimers::Notify, No running timers."); |
138 return; |
144 return; |
139 } |
145 } |
140 |
146 |
141 LOGMISC2("CSimReduceTimers::Notify, Min time to reduce all timers: %d", minTimeReduce); |
147 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_NOTIFY_5, "CSimReduceTimers::Notify, Min time to reduce all timers: %d", minTimeReduce); |
142 // Ensure that reducing timers by minTimeReduce does not reduce any timer to less than KTimerDelayOnReduceTimeSignal. |
148 // Ensure that reducing timers by minTimeReduce does not reduce any timer to less than KTimerDelayOnReduceTimeSignal. |
143 minTimeReduce -= KTimerDelayOnReduceTimeSignal; |
149 minTimeReduce -= KTimerDelayOnReduceTimeSignal; |
144 if (minTimeReduce <= 0) |
150 if (minTimeReduce <= 0) |
145 { |
151 { |
146 LOGMISC1("CSimReduceTimers::Notify, Min time to reduce <= KTimerDelayOnReduceTimeSignal, no change to timers."); |
152 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_NOTIFY_6, "CSimReduceTimers::Notify, Min time to reduce <= KTimerDelayOnReduceTimeSignal, no change to timers."); |
147 return; |
153 return; |
148 } |
154 } |
149 |
155 |
150 for (num = 0; num < totalItems; num++) |
156 for (num = 0; num < totalItems; num++) |
151 { |
157 { |
180 } |
186 } |
181 } |
187 } |
182 |
188 |
183 if(indexOfLowest == KErrNotFound) |
189 if(indexOfLowest == KErrNotFound) |
184 { |
190 { |
185 LOGMISC2(">>CSimReduceTimers::Notify, No observers with event ID %d found", |
191 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_NOTIFY1_3, ">>CSimReduceTimers::Notify, No observers with event ID %d found", aTimerEventId); |
186 aTimerEventId); |
|
187 return; |
192 return; |
188 } |
193 } |
189 |
194 |
190 //Check that reducing the timer of the selected observer is acceptable |
195 //Check that reducing the timer of the selected observer is acceptable |
191 TInt reduceBy = lowestTime - KTimerDelayOnReduceTimeSignal; |
196 TInt reduceBy = lowestTime - KTimerDelayOnReduceTimeSignal; |
192 if(reduceBy >= lowestTime) |
197 if(reduceBy >= lowestTime) |
193 { |
198 { |
194 LOGMISC3("CSimReduceTimers::Notify, Lowest timer for event ID %d already less than %d sec. No timer reduced.", |
199 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_NOTIFY1_4, "CSimReduceTimers::Notify, Lowest timer for event ID %d already less than %d sec. No timer reduced.",KTimerDelayOnReduceTimeSignal, aTimerEventId); |
195 KTimerDelayOnReduceTimeSignal, aTimerEventId); |
|
196 } |
200 } |
197 else |
201 else |
198 { |
202 { |
199 LOGMISC3(">>CSimReduceTimers::Notify, Timer for observer with event ID %d, reduced by %d sec", |
203 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSIMREDUCETIMERS_NOTIFY1_5, ">>CSimReduceTimers::Notify, Timer for observer with event ID %d, reduced by %d sec", aTimerEventId, reduceBy); |
200 aTimerEventId, reduceBy); |
|
201 iObservers[indexOfLowest]->Update(reduceBy); |
204 iObservers[indexOfLowest]->Update(reduceBy); |
202 } |
205 } |
203 } |
206 } |