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