|
1 /* |
|
2 * Copyright (c) 2005 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: Storage Id container |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32std.h> |
|
22 #include "CPEngSIdContainer.h" |
|
23 #include "CPEngObserverContainer.h" |
|
24 |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CPEngSIdContainer::CPEngSIdContainer |
|
30 // C++ default constructor can NOT contain any code, that might leave. |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CPEngSIdContainer::CPEngSIdContainer() |
|
34 : iObservers( 2 ) // usually 2 observers for same SID |
|
35 { |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CPEngSIdContainer::ConstructL |
|
40 // Symbian 2nd phase constructor can leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 void CPEngSIdContainer::ConstructL( |
|
44 const TDesC& aSId ) |
|
45 { |
|
46 iSId = aSId.AllocL(); |
|
47 // allocated some slots for observers |
|
48 User::LeaveIfError( AllocateSlots( 1 ) ); |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CPEngSIdContainer::NewLC |
|
53 // Two-phased constructor. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CPEngSIdContainer* CPEngSIdContainer::NewLC( |
|
57 const TDesC& aSId ) |
|
58 { |
|
59 CPEngSIdContainer* self = new( ELeave ) CPEngSIdContainer(); |
|
60 |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL( aSId ); |
|
63 |
|
64 return self; |
|
65 } |
|
66 |
|
67 |
|
68 // Destructor |
|
69 CPEngSIdContainer::~CPEngSIdContainer() |
|
70 { |
|
71 // remove SID from Observers |
|
72 TInt count ( iObservers.Count() ); |
|
73 for ( TInt x( 0 ) ; x < count; x++ ) |
|
74 { |
|
75 iObservers[ x ]->RemoveSIdContainer( this ); |
|
76 } |
|
77 iObservers.Reset(); |
|
78 delete iSId; |
|
79 } |
|
80 |
|
81 |
|
82 // ============================================================================= |
|
83 // Another function of the CPEngSIdContainer |
|
84 // ============================================================================= |
|
85 |
|
86 |
|
87 // ============================================================================= |
|
88 // New function of the MPEngSIDContainer class |
|
89 // ============================================================================= |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CPEngSIdContainer::SId() |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 const TDesC& CPEngSIdContainer::SId() const |
|
96 { |
|
97 return *iSId; |
|
98 } |
|
99 |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CPEngSIdContainer::AddObserverContainer() |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 TInt CPEngSIdContainer::AddObserverContainer( |
|
106 const CPEngObserverContainer* aObserver ) |
|
107 { |
|
108 TInt err ( iObservers.InsertInAddressOrder( aObserver ) ); |
|
109 if ( ( err == KErrNone ) || ( err == KErrAlreadyExists ) ) |
|
110 { |
|
111 |
|
112 return KErrNone; |
|
113 } |
|
114 return err; |
|
115 } |
|
116 |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CPEngSIdContainer::RemoveObserverContainer() |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void CPEngSIdContainer::RemoveObserverContainer( |
|
123 const CPEngObserverContainer* aObserver ) |
|
124 { |
|
125 TInt index ( iObservers.FindInAddressOrder( aObserver ) ); |
|
126 if ( index != KErrNotFound ) |
|
127 { |
|
128 iObservers.Remove( index ); |
|
129 } |
|
130 } |
|
131 |
|
132 |
|
133 // ============================================================================= |
|
134 // New function of the class |
|
135 // ============================================================================= |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CPEngSIdContainer::NotifySIdChangeL() |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CPEngSIdContainer::NotifySIdChangeL() |
|
142 { |
|
143 TInt count( iObservers.Count() ); |
|
144 for ( TInt x ( 0 ) ; x < count ; ++x ) |
|
145 { |
|
146 iObservers[ x ]->SIdHasChangedL( *iSId ); |
|
147 } |
|
148 } |
|
149 |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CPEngSIdContainer::SIdPublished() |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 TBool CPEngSIdContainer::SIdPublished() const |
|
156 { |
|
157 return iPublished; |
|
158 } |
|
159 |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CPEngSIdContainer::SetSIdPublished() |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 void CPEngSIdContainer::SetSIdPublished() |
|
166 { |
|
167 iPublished = ETrue; |
|
168 } |
|
169 |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CPEngSIdContainer::ObserverCount() |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 TInt CPEngSIdContainer::ObserverCount() const |
|
176 { |
|
177 return iObservers.Count(); |
|
178 } |
|
179 |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CPEngSIdContainer::AllocateSlots() |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 TInt CPEngSIdContainer::AllocateSlots( |
|
186 TInt aCount, |
|
187 TInt aDone ) |
|
188 { |
|
189 TInt err ( iObservers.Append( NULL ) ); |
|
190 |
|
191 if ( err != KErrNone ) |
|
192 { |
|
193 return err; |
|
194 } |
|
195 aDone++; |
|
196 if ( aCount < aDone ) |
|
197 { |
|
198 err = AllocateSlots( aCount, aDone ); |
|
199 } |
|
200 // remove last element from array = count minus 1 |
|
201 iObservers.Remove( iObservers.Count() - 1 ); |
|
202 return err; |
|
203 } |
|
204 |
|
205 // End of File |