1 /* |
|
2 * Copyright (c) 2002-2007 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: Capsulates the observer and events. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "TSatEventsObserver.h" |
|
22 //lint -e766 Used inside TRAP macro, lint misfunction. |
|
23 #include "EnginePanic.h" |
|
24 #include "SatLog.h" |
|
25 |
|
26 // FORWARD DECLARE |
|
27 class MSatEventObserver; |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // TSatEventsObserver::TSatEventsObserver |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 TSatEventsObserver::TSatEventsObserver( |
|
38 MSatEventObserver* aObserver ) // Observer of events. |
|
39 : |
|
40 iEvents(), |
|
41 iObserver( aObserver ), |
|
42 iMarkedForDelete( EFalse ) // This observer is not marked for delete, yet. |
|
43 { |
|
44 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::TSatEventsObserver calling" ) |
|
45 |
|
46 __ASSERT_ALWAYS( aObserver, PanicSatEngine( ESatEngineNullPointer ) ); |
|
47 |
|
48 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::TSatEventsObserver exiting" ) |
|
49 } |
|
50 |
|
51 // Destructor |
|
52 TSatEventsObserver::~TSatEventsObserver() |
|
53 { |
|
54 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::~TSatEventsObserver calling" ) |
|
55 |
|
56 iEvents.Reset(); |
|
57 iEvents.Close(); |
|
58 iObserver = NULL; |
|
59 |
|
60 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::~TSatEventsObserver exiting" ) |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // TSatEventsObserver::AddEventL |
|
65 // Adds event to the list of events. If aEvent is already in the list, it will |
|
66 // not be added to the list. |
|
67 // (other items were commented in a header). |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void TSatEventsObserver::AddEventL( |
|
71 TInt aEvent ) // Event to be added to list. |
|
72 { |
|
73 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::AddEventL calling" ) |
|
74 |
|
75 // Check if the event is already added to the list. |
|
76 if ( !ObservingEvent( aEvent ) ) |
|
77 { |
|
78 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::AddEventL add event" ) |
|
79 User::LeaveIfError( iEvents.Append( aEvent ) ); |
|
80 } |
|
81 |
|
82 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::AddEventL exiting" ) |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // TSatEventsObserver::RemoveEvent |
|
87 // Removes aEvent from the iEvents list, if aEvent is in the list. |
|
88 // (other items were commented in a header). |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void TSatEventsObserver::RemoveEvent( TInt aEvent ) |
|
92 { |
|
93 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::RemoveEvent calling" ) |
|
94 |
|
95 const TInt index( iEvents.Find( aEvent ) ); |
|
96 LOG2( SIMPLE, "SATENGINE: TSatEventsObserver::RemoveEvent index: %d", |
|
97 index ) |
|
98 |
|
99 // KErrNotFound in index means that aEvent is not in the list. |
|
100 if ( KErrNotFound != index ) |
|
101 { |
|
102 iEvents.Remove( index ); |
|
103 iEvents.GranularCompress(); |
|
104 } |
|
105 |
|
106 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::RemoveEvent exiting" ) |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // TSatEventsObserver::ObservingEvents |
|
111 // Checks wether aEvent is in the iEvents list. |
|
112 // (other items were commented in a header). |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 TBool TSatEventsObserver::ObservingEvent( |
|
116 TInt aEvent ) const // Event to be checked |
|
117 { |
|
118 LOG( DETAILED, "SATENGINE: TSatEventsObserver::ObservingEvent calling" ) |
|
119 |
|
120 TBool result( ETrue ); |
|
121 if ( KErrNotFound == iEvents.Find( aEvent ) ) |
|
122 { |
|
123 LOG( DETAILED, "SATENGINE: TSatEventsObserver::ObservingEvent \ |
|
124 find event" ) |
|
125 result = EFalse; |
|
126 } |
|
127 |
|
128 LOG2( DETAILED, "SATENGINE: TSatEventsObserver::ObservingEvent exiting, \ |
|
129 result: %d", result ) |
|
130 return result; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // TSatEventsObserver::Observer |
|
135 // Getter for the observer. |
|
136 // (other items were commented in a header). |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 MSatEventObserver* TSatEventsObserver::Observer() |
|
140 { |
|
141 LOG( DETAILED, "SATENGINE: TSatEventsObserver::Observer calling-exiting" ) |
|
142 return iObserver; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // TSatEventsObserver::EventCount |
|
147 // Getter for the event cound |
|
148 // (other items were commented in a header). |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 TInt TSatEventsObserver::EventCount() const |
|
152 { |
|
153 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::EventCount calling-exiting" ) |
|
154 return iEvents.Count(); |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // TSatEventsObserver::IsMarkedForDelete |
|
159 // Getter for deletion mark |
|
160 // (other items were commented in a header). |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 TBool TSatEventsObserver::IsMarkedForDelete() const |
|
164 { |
|
165 LOG( SIMPLE, |
|
166 "SATENGINE: TSatEventsObserver::IsMarkedForDelete calling-exiting" ) |
|
167 return iMarkedForDelete; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // TSatEventsObserver::MarkForDelete |
|
172 // Marks this observer to be deleted |
|
173 // (other items were commented in a header). |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void TSatEventsObserver::MarkForDelete() |
|
177 { |
|
178 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::MarkForDelete calling" ) |
|
179 |
|
180 iMarkedForDelete = ETrue; |
|
181 |
|
182 LOG( SIMPLE, "SATENGINE: TSatEventsObserver::MarkForDelete exiting" ) |
|
183 } |
|
184 |
|
185 // End of File |
|