|
1 /* |
|
2 * Copyright (c) 2007-2008 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "dpdef.h" // dataport definitions |
|
22 #include "dpobserver.h" // abstract observer class |
|
23 #include "dplog.h" // dataport logging |
|
24 #include "osttracedefinitions.h" |
|
25 #ifdef OST_TRACE_COMPILER_IN_USE |
|
26 #include "dpobservertraces.h" |
|
27 #endif |
|
28 |
|
29 // EXTERNAL DATA STRUCTURES |
|
30 // none |
|
31 |
|
32 // EXTERNAL FUNCTION PROTOTYPES |
|
33 // none |
|
34 |
|
35 // CONSTANTS |
|
36 const TInt CDpObserver::iOffset = _FOFF(CDpObserver,iSlink); |
|
37 |
|
38 // MACROS |
|
39 // none |
|
40 |
|
41 // LOCAL CONSTANTS AND MACROS |
|
42 // none |
|
43 |
|
44 // MODULE DATA STRUCTURES |
|
45 // none |
|
46 |
|
47 // LOCAL FUNCTION PROTOTYPES |
|
48 // none |
|
49 |
|
50 // FORWARD DECLARATIONS |
|
51 // none |
|
52 |
|
53 // ============================= LOCAL FUNCTIONS =============================== |
|
54 |
|
55 // none |
|
56 |
|
57 |
|
58 // ============================ MEMBER FUNCTIONS =============================== |
|
59 |
|
60 // --------------------------------------------------------- |
|
61 // CDpObserver::CDpObserver |
|
62 // C++ default constructor. |
|
63 // --------------------------------------------------------- |
|
64 CDpObserver::CDpObserver() |
|
65 { |
|
66 OstTrace0( TRACE_NORMAL, CDPOBSERVER_CDPOBSERVER, "CDpObserver::CDpObserver" ); |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------- |
|
70 // CDpObserver::~CDpObserver |
|
71 // Destructor |
|
72 // --------------------------------------------------------- |
|
73 CDpObserver::~CDpObserver() |
|
74 { |
|
75 OstTrace0( TRACE_NORMAL, DUP1_CDPOBSERVER_CDPOBSERVER, "CDpObserver::~CDpObserver" ); |
|
76 iSlink.iNext = NULL; |
|
77 } |
|
78 |
|
79 //============================================================================= |
|
80 |
|
81 |
|
82 // ============================ MEMBER FUNCTIONS =============================== |
|
83 |
|
84 // --------------------------------------------------------- |
|
85 // CDpSubject::CDpSubject |
|
86 // C++ default constructor. |
|
87 // --------------------------------------------------------- |
|
88 CDpSubject::CDpSubject() : |
|
89 iObserverList( CDpObserver::iOffset ), |
|
90 iObserverIter( iObserverList ) |
|
91 { |
|
92 OstTrace0( TRACE_NORMAL, CDPSUBJECT_CDPSUBJECT, "CDpSubject::CDpSubject" ); |
|
93 LOGM(" CDpSubject::CDpSubject"); |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------- |
|
97 // CDpSubject::~CDpSubject |
|
98 // Destructor |
|
99 // --------------------------------------------------------- |
|
100 CDpSubject::~CDpSubject() |
|
101 { |
|
102 OstTrace0( TRACE_NORMAL, DUP1_CDPSUBJECT_CDPSUBJECT, "CDpSubject::~CDpSubject" ); |
|
103 LOGM(" CDpSubject::~CDpSubject"); |
|
104 |
|
105 CDpObserver* item= NULL; |
|
106 |
|
107 // set observer to first item in the list |
|
108 iObserverIter.SetToFirst(); |
|
109 |
|
110 while( NULL != (item = iObserverIter++) ) |
|
111 { |
|
112 iObserverList.Remove( *item ); |
|
113 } |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------- |
|
117 // CDpSubject::Attach |
|
118 // Attach observer to this subject |
|
119 // --------------------------------------------------------- |
|
120 // |
|
121 void CDpSubject::Attach( |
|
122 CDpObserver& aObserver) |
|
123 { |
|
124 OstTrace0( TRACE_NORMAL, CDPSUBJECT_ATTACH, "CDpSubject::Attach" ); |
|
125 LOGM(" CDpSubject::Attach"); |
|
126 iObserverList.AddLast( aObserver ); |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------- |
|
130 // CDpSubject::Detach |
|
131 // Detach observer from this subject |
|
132 // --------------------------------------------------------- |
|
133 // |
|
134 void CDpSubject::Detach( |
|
135 CDpObserver& aObserver) |
|
136 { |
|
137 OstTrace0( TRACE_NORMAL, CDPSUBJECT_DETACH, "CDpSubject::Detach" ); |
|
138 LOGM(" CDpSubject::Detach"); |
|
139 |
|
140 iObserverList.Remove( aObserver ); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------- |
|
144 // CDpSubject::Notify |
|
145 // Notify all observers of this subject object |
|
146 // i.e. call UpDate() in every observer object. |
|
147 // --------------------------------------------------------- |
|
148 // |
|
149 void CDpSubject::Notify() |
|
150 { |
|
151 OstTrace0( TRACE_NORMAL, CDPSUBJECT_NOTIFY, "CDpSubject::Notify" ); |
|
152 LOGM(" CDpSubject::Notify"); |
|
153 |
|
154 CDpObserver* item = NULL; |
|
155 iObserverIter.SetToFirst(); |
|
156 while( NULL != (item = iObserverIter++) ) |
|
157 { |
|
158 item->UpDate( this ); |
|
159 } |
|
160 } |
|
161 |
|
162 // ================= OTHER EXPORTED FUNCTIONS ============== |
|
163 // none |
|
164 |
|
165 // End of File |