|
1 /* |
|
2 * Copyright (c) 2002-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: Base Document for the General Settings Application |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "GSBaseDocument.h" |
|
19 |
|
20 // User includes |
|
21 #include "GSPluginWrapper.h" |
|
22 #include "GSPluginAndViewIdCache.h" |
|
23 #include "GSWatchDog.h" |
|
24 #include "gsplugininterface.h" |
|
25 #include "GsLogger.h" |
|
26 |
|
27 // Constants |
|
28 const TInt KGSPluginWrapperObjectGranularity = 10; |
|
29 |
|
30 |
|
31 // ================= MEMBER FUNCTIONS ======================= |
|
32 |
|
33 // ---------------------------------------------------- |
|
34 // CGSBaseDocument::CGSBaseDocument() |
|
35 // constructor |
|
36 // |
|
37 // ---------------------------------------------------- |
|
38 // |
|
39 EXPORT_C CGSBaseDocument::CGSBaseDocument( CEikApplication& aApp ) |
|
40 : CAknDocument( aApp ), |
|
41 iUnloadWrapperObjects( KGSPluginWrapperObjectGranularity ) |
|
42 { |
|
43 } |
|
44 |
|
45 |
|
46 // ---------------------------------------------------- |
|
47 // CGSBaseDocument::~CGSBaseDocument() |
|
48 // destructor |
|
49 // |
|
50 // ---------------------------------------------------- |
|
51 // |
|
52 EXPORT_C CGSBaseDocument::~CGSBaseDocument() |
|
53 { |
|
54 // This physically unloads the plugin dlls if their ECOM |
|
55 // reference count is zero. This must be the last thing to |
|
56 // occur to any plugin object (i.e. all of its code must have |
|
57 // finished running by the time this next line takes place). |
|
58 const TInt count = iUnloadWrapperObjects.Count(); |
|
59 for( TInt i=count-1; i>=0; i-- ) |
|
60 { |
|
61 CGSPluginWrapper* object = iUnloadWrapperObjects[ i ]; |
|
62 (void) object; |
|
63 delete object; |
|
64 } |
|
65 |
|
66 iUnloadWrapperObjects.Close(); |
|
67 delete iPluginViewIdCache; |
|
68 delete iWatchDog; |
|
69 |
|
70 iImplInfoArray.ResetAndDestroy();// This is needed |
|
71 iImplInfoArray.Close(); |
|
72 } |
|
73 |
|
74 |
|
75 // ---------------------------------------------------- |
|
76 // CGSBaseDocument::ConstructL() |
|
77 // Symbian OS second phase constructor |
|
78 // |
|
79 // ---------------------------------------------------- |
|
80 // |
|
81 EXPORT_C void CGSBaseDocument::ConstructL() |
|
82 { |
|
83 iWatchDog = CGSWatchDog::NewL(); |
|
84 |
|
85 REComSession::ListImplementationsL( |
|
86 KGSPluginInterfaceUid, |
|
87 iImplInfoArray ); |
|
88 #ifdef _DEBUG |
|
89 PrintImplInfoArray( iImplInfoArray ); |
|
90 #endif //_DEBUG |
|
91 |
|
92 __GSLOGSTRING1( |
|
93 "[CGSBaseDocument::ConstructL] iImplInfoArray count:%d", |
|
94 iImplInfoArray.Count() ); |
|
95 } |
|
96 |
|
97 |
|
98 // ---------------------------------------------------- |
|
99 // CGSBaseDocument::NewPluginUnloadWrapperLC() |
|
100 // |
|
101 // |
|
102 // ---------------------------------------------------- |
|
103 // |
|
104 EXPORT_C CGSPluginWrapper* CGSBaseDocument::NewPluginUnloadWrapperLC() |
|
105 { |
|
106 CGSPluginWrapper* wrapper = new(ELeave) CGSPluginWrapper( *this ); |
|
107 TCleanupItem wrapperCleanupItem( CleanupPluginWrapperObject, wrapper ); |
|
108 CleanupStack::PushL( wrapperCleanupItem ); |
|
109 iUnloadWrapperObjects.AppendL( wrapper ); |
|
110 // |
|
111 return wrapper; |
|
112 } |
|
113 |
|
114 |
|
115 // ---------------------------------------------------- |
|
116 // CGSBaseDocument::PreparePluginCacheL() |
|
117 // |
|
118 // |
|
119 // ---------------------------------------------------- |
|
120 // |
|
121 EXPORT_C void CGSBaseDocument::PreparePluginCacheL( CEikAppUi& aAppUi ) |
|
122 { |
|
123 iPluginViewIdCache = CGSPluginAndViewIdCache::NewL( aAppUi ); |
|
124 } |
|
125 |
|
126 |
|
127 // ---------------------------------------------------- |
|
128 // CGSBaseDocument::PrepareForUIDestruction() |
|
129 // |
|
130 // |
|
131 // ---------------------------------------------------- |
|
132 // |
|
133 EXPORT_C void CGSBaseDocument::PrepareForUIDestruction() |
|
134 { |
|
135 if ( iPluginViewIdCache ) |
|
136 { |
|
137 iPluginViewIdCache->PrepareForUIDestruction(); |
|
138 } |
|
139 } |
|
140 |
|
141 |
|
142 // ---------------------------------------------------- |
|
143 // CGSBaseDocument::CleanupPluginWrapperObject() |
|
144 // Cleanup support |
|
145 // |
|
146 // ---------------------------------------------------- |
|
147 // |
|
148 void CGSBaseDocument::CleanupPluginWrapperObject( TAny* aWrapper ) |
|
149 { |
|
150 CGSPluginWrapper* wrapper = |
|
151 reinterpret_cast< CGSPluginWrapper* >( aWrapper ); |
|
152 CGSBaseDocument& document = wrapper->Document(); |
|
153 document.DoCleanupPluginWrapper( wrapper ); |
|
154 } |
|
155 |
|
156 |
|
157 // ---------------------------------------------------- |
|
158 // CGSBaseDocument::DoCleanupPluginWrapper() |
|
159 // Cleanup support - called when loading a plugin fails |
|
160 // |
|
161 // ---------------------------------------------------- |
|
162 // |
|
163 void CGSBaseDocument::DoCleanupPluginWrapper( CGSPluginWrapper* aWrapper ) |
|
164 { |
|
165 const TInt index = iUnloadWrapperObjects.Find( aWrapper ); |
|
166 if ( index >= 0 && index < iUnloadWrapperObjects.Count() ) |
|
167 { |
|
168 iUnloadWrapperObjects.Remove( index ); |
|
169 delete aWrapper; |
|
170 } |
|
171 } |
|
172 |
|
173 |
|
174 // ---------------------------------------------------- |
|
175 // CGSBaseDocument::PluginViewIdCache() |
|
176 // |
|
177 // |
|
178 // ---------------------------------------------------- |
|
179 // |
|
180 CGSPluginAndViewIdCache& CGSBaseDocument::PluginViewIdCache() |
|
181 { |
|
182 ASSERT( iPluginViewIdCache ); |
|
183 return *iPluginViewIdCache; |
|
184 } |
|
185 |
|
186 |
|
187 // ---------------------------------------------------- |
|
188 // CGSBaseDocument::PluginViewIdCache() |
|
189 // |
|
190 // |
|
191 // ---------------------------------------------------- |
|
192 // |
|
193 const CGSPluginAndViewIdCache& CGSBaseDocument::PluginViewIdCache() const |
|
194 { |
|
195 ASSERT( iPluginViewIdCache ); |
|
196 return *iPluginViewIdCache; |
|
197 } |
|
198 |
|
199 |
|
200 |
|
201 // ---------------------------------------------------- |
|
202 // CGSBaseDocument::WatchDog() |
|
203 // |
|
204 // |
|
205 // ---------------------------------------------------- |
|
206 // |
|
207 EXPORT_C MGSWatchDog* CGSBaseDocument::WatchDog() |
|
208 { |
|
209 return iWatchDog; |
|
210 } |
|
211 |
|
212 // ---------------------------------------------------- |
|
213 // CGSBaseDocument::GetImplInfos() |
|
214 // |
|
215 // |
|
216 // ---------------------------------------------------- |
|
217 // |
|
218 EXPORT_C RImplInfoPtrArray CGSBaseDocument::GetImplInfo() |
|
219 { |
|
220 return iImplInfoArray; |
|
221 } |
|
222 |
|
223 EXPORT_C void CGSBaseDocument::CreateShimmedViewL(const TUid aViewUid) |
|
224 { |
|
225 ASSERT(iPluginViewIdCache); |
|
226 if ( !iPluginViewIdCache->PluginInstance(aViewUid) ) |
|
227 { |
|
228 iPluginViewIdCache->RegisterViewAndImplementationAssociationL(aViewUid, aViewUid, ETrue); |
|
229 } |
|
230 } |
|
231 |
|
232 void CGSBaseDocument::PrintImplInfoArray( const RImplInfoPtrArray& aImplInfoArray ) |
|
233 { |
|
234 for( TInt i = 0; i < aImplInfoArray.Count(); i++ ) |
|
235 { |
|
236 PrintImplInfo( *aImplInfoArray[ i ] ); |
|
237 } |
|
238 } |
|
239 |
|
240 |
|
241 void CGSBaseDocument::PrintImplInfo( const CImplementationInformation& aInfo ) |
|
242 { |
|
243 __GSLOGSTRING1( "[CGSBaseDocument] --Plugin 0x%X info--", &aInfo); |
|
244 __GSLOGSTRING1( "[CGSBaseDocument] DisplayName:%S", &aInfo.DisplayName() ); |
|
245 __GSLOGSTRING1( "[CGSBaseDocument] ImplementationUid:0x%X", |
|
246 aInfo.ImplementationUid() ); |
|
247 |
|
248 const TInt KMaxEComDataLength = 256; |
|
249 |
|
250 HBufC* dataType = HBufC::New( KMaxEComDataLength ); |
|
251 HBufC* opaqueData = HBufC::New( KMaxEComDataLength ); |
|
252 |
|
253 dataType->Des().Copy( aInfo.DataType() ); |
|
254 opaqueData->Des().Copy( aInfo.OpaqueData() ); |
|
255 __GSLOGSTRING1( "[CGSBaseDocument] DataType:%S", dataType ); |
|
256 __GSLOGSTRING1( "[CGSBaseDocument] OpaqueData:%S", opaqueData ); |
|
257 |
|
258 delete opaqueData; |
|
259 delete dataType; |
|
260 } |
|
261 |
|
262 |
|
263 |
|
264 // End of File |