|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // The implementation of a some classes |
|
15 // to be provided by ECom. |
|
16 // 1. Using the CExampleInterface class as a base. |
|
17 // |
|
18 // |
|
19 |
|
20 #include "Interface.h" |
|
21 #include "ImplementationProxy.h" |
|
22 #include "ExampleResolver.h" |
|
23 #include "TestUtilities.h" // For __FILE__LINE__ |
|
24 |
|
25 // ____________________________________________________________________________ |
|
26 // |
|
27 /** Intended usage: This class implements the functionality promised by |
|
28 the CExampleInterface defintion class. It does little apart from provides a test instance |
|
29 which may be retrieved and run for testing purposes. |
|
30 Its resolution is based upon its registered default data string that |
|
31 advertises this class as being able to handle 'text\wml' data. |
|
32 @since 7.0 |
|
33 */ |
|
34 class CImplementationClassOne : public CExampleInterface |
|
35 { |
|
36 // Methods |
|
37 public: |
|
38 /** |
|
39 @fn NewL(TAny* aInitParams) |
|
40 Intended Usage : Standardised safe construction which leaves nothing the cleanup stack. |
|
41 Error Condition : Leaves with error code. |
|
42 @leave KErrNoMemory. |
|
43 @since 7.0 |
|
44 @param aInitParams The parameter struct used for initialising this object |
|
45 @return CImplementationClassOne* The class instance. |
|
46 @pre None |
|
47 @post CImplementationClassOne has been constructed, |
|
48 and initialised. |
|
49 */ |
|
50 static CImplementationClassOne* NewL(TAny* aInitParams); |
|
51 |
|
52 /** |
|
53 @fn ~CImplementationClassOne() |
|
54 Intended Usage : Default Destructor |
|
55 Error Condition : None |
|
56 @since 7.0 |
|
57 @pre CImplementationClassOne has been constructed |
|
58 @post CImplementationClassOne has been completely destroyed. |
|
59 */ |
|
60 virtual ~CImplementationClassOne(); |
|
61 |
|
62 /** |
|
63 @fn DoMethodL() |
|
64 Intended Usage : Overload of the pure interface method |
|
65 Representative of a method provided on |
|
66 the interface by the interface definer. |
|
67 Error Condition : Leaves with an error code. |
|
68 @leave KErrNoMemory, KErrNotSupported. |
|
69 @since 7.0 |
|
70 @return None |
|
71 @pre CImplementationClassOne has been constructed |
|
72 @post Unspecified |
|
73 */ |
|
74 void DoMethodL(); |
|
75 |
|
76 /** |
|
77 @fn FireAndForget() |
|
78 Intended Usage : Overload of the pure interface method |
|
79 asynchronous function which |
|
80 an interface definer could specify. |
|
81 It allows the client to call the function in the knowledge |
|
82 that the object will commit suicide when the |
|
83 function completes. |
|
84 Error Condition : None. |
|
85 @since 7.0 |
|
86 @return TInt KErrNone for success. |
|
87 @pre CImplementationClassOne has been constructed |
|
88 @post Unspecified |
|
89 */ |
|
90 TInt FireAndForget(); |
|
91 |
|
92 /** |
|
93 @fn ImplId() |
|
94 Intended Usage : To verify the object returned by ECOM. |
|
95 Error Condition : None. |
|
96 @since 7.0s |
|
97 @return TUid (ECOM's Implementation Uid for this class.) |
|
98 @pre CImplementationClassThree has been constructed |
|
99 @post Unspecified |
|
100 */ |
|
101 TUid ImplId(); |
|
102 |
|
103 private: |
|
104 /** |
|
105 @fn CImplementationClassOne() |
|
106 Intended Usage : Default Constructor : usable only by derived classes |
|
107 Error Condition : None |
|
108 @since 7.0 |
|
109 @pre None |
|
110 @post CImplementationClassOne has been constructed |
|
111 */ |
|
112 CImplementationClassOne(); |
|
113 |
|
114 /** |
|
115 @fn ConstructL(TAny* aInitParams) |
|
116 Intended Usage : Completes the safe construction of the CImplementationClassOne object |
|
117 Error Condition : Leaves with the error code. |
|
118 @leave KErrNoMemory. |
|
119 @since 7.0 |
|
120 @param aInitParams The parameter struct used for initialising this object |
|
121 @pre CImplementationClassOne has been constructed |
|
122 @post CImplementationClassOne has been fully initialised. |
|
123 */ |
|
124 void ConstructL(TAny* aInitParams); |
|
125 |
|
126 // Provide the CActive overloads |
|
127 void RunL(); |
|
128 void DoCancel(); |
|
129 TInt RunError(TInt aError); |
|
130 |
|
131 private: |
|
132 /** A place for allocating some memory in the ConstructL */ |
|
133 HBufC* iInternalDescriptor; |
|
134 /** An int to be stored in TLS to test its useage */ |
|
135 TInt iTLSInt; |
|
136 |
|
137 }; // End of CImplementationClassOne definition |
|
138 |
|
139 // __________________________________________________________________________ |
|
140 // Implementation |
|
141 |
|
142 CImplementationClassOne* CImplementationClassOne::NewL(TAny* aInitParams) |
|
143 // Intended Usage : Safe construction which leaves nothing upon the cleanup stack |
|
144 // Error Condition : Will leave with an appropriate error code |
|
145 // Dependencies : CBase |
|
146 // @param " " |
|
147 // @return CImplementationClassOne* a pointer to the fully instantiated CImplementationClassOne object |
|
148 // @pre None |
|
149 // @post The object has been fully instantiated |
|
150 // Static member |
|
151 { |
|
152 CImplementationClassOne* self=new(ELeave) CImplementationClassOne(); // calls c'tor |
|
153 CleanupStack::PushL(self); // Make the construction safe by using the cleanup stack |
|
154 self->ConstructL(aInitParams); // Complete the 'construction'. |
|
155 CleanupStack::Pop(self); |
|
156 return self; |
|
157 } |
|
158 |
|
159 CImplementationClassOne::~CImplementationClassOne() |
|
160 // Default virtual d'tor |
|
161 { |
|
162 delete iInternalDescriptor; |
|
163 } |
|
164 |
|
165 CImplementationClassOne::CImplementationClassOne() |
|
166 // Default c'tor for use by derived and |
|
167 // static construction methods only |
|
168 : CExampleInterface() |
|
169 { |
|
170 // Deliberately do nothing here : See ConstructL() for initialisation completion. |
|
171 } |
|
172 |
|
173 void CImplementationClassOne::ConstructL(TAny* aInitParams) |
|
174 // Intended Usage : Safely complete the initialization of the constructed object |
|
175 // Error Condition : Will leave with an appropriate error code |
|
176 // Dependencies : CBase |
|
177 // @return void |
|
178 // @pre CImplementationClassOne has been constructed |
|
179 // @post The CImplementationClassOne object has been fully instantiated |
|
180 // |
|
181 { |
|
182 TExampleInterfaceInitParams* params = REINTERPRET_CAST(TExampleInterfaceInitParams*, |
|
183 aInitParams); |
|
184 if(params->descriptor) |
|
185 iInternalDescriptor = params->descriptor->AllocL(); |
|
186 |
|
187 Dll::SetTls(&iTLSInt); |
|
188 } |
|
189 |
|
190 void CImplementationClassOne::DoMethodL() |
|
191 { |
|
192 // Access TLS to ensure it has been set properly |
|
193 REINTERPRET_CAST(TInt*, Dll::Tls()); |
|
194 } |
|
195 |
|
196 TInt CImplementationClassOne::FireAndForget() |
|
197 { |
|
198 TRAPD(error,DoMethodL()); |
|
199 return error; // Always KErrNotSupported |
|
200 } |
|
201 |
|
202 // Provide the CActive overloads |
|
203 void CImplementationClassOne::RunL() |
|
204 { |
|
205 // Do nothing : should never be called |
|
206 __ASSERT_DEBUG(EFalse,User::Invariant()); |
|
207 } |
|
208 |
|
209 void CImplementationClassOne::DoCancel() |
|
210 { |
|
211 // Do nothing |
|
212 } |
|
213 |
|
214 TInt CImplementationClassOne::RunError(TInt aError) |
|
215 { |
|
216 return aError; |
|
217 } |
|
218 |
|
219 TUid CImplementationClassOne::ImplId() |
|
220 { |
|
221 TUid idVal = {0x10009DC3}; |
|
222 return (idVal); |
|
223 } |
|
224 |
|
225 // ____________________________________________________________________________ |
|
226 // |
|
227 /** Intended usage: This class implements the functionality promised by |
|
228 the CExampleInterface defintion class. It does little apart from provides a test instance |
|
229 which may be retrieved and run for testing purposes. |
|
230 Its resolution is based upon its registered default data string that |
|
231 advertises this class as being able to handle 'text\*' data. |
|
232 I.e. it should be 'found' by wildcard matching for any text handling type. |
|
233 @since 7.0 |
|
234 |
|
235 */ |
|
236 class CImplementationClassTwo : public CExampleInterface |
|
237 { |
|
238 // Methods |
|
239 public: |
|
240 /** |
|
241 @fn NewL(TAny* aParams) |
|
242 Intended Usage : Standardised safe construction which leaves nothing the cleanup stack. |
|
243 Error Condition : Leaves with error code. |
|
244 @leave KErrNoMemory. |
|
245 @since 7.0 |
|
246 @return CImplementationClassTwo* The class instance. |
|
247 @pre None |
|
248 @post CImplementationClassTwo has been constructed, |
|
249 and initialised. |
|
250 */ |
|
251 static CImplementationClassTwo* NewL(TAny* aParams); |
|
252 |
|
253 /** |
|
254 @fn ~CImplementationClassTwo() |
|
255 Intended Usage : Default Destructor |
|
256 Error Condition : None |
|
257 @since 7.0 |
|
258 @pre CImplementationClassTwo has been constructed |
|
259 @post CImplementationClassTwo has been completely destroyed. |
|
260 */ |
|
261 virtual ~CImplementationClassTwo(); |
|
262 |
|
263 /** |
|
264 @fn DoMethodL() |
|
265 Intended Usage : Overload of the pure interface method |
|
266 Representative of a method provided on |
|
267 the interface by the interface definer. |
|
268 Error Condition : Leaves with an error code. |
|
269 @leave KErrNoMemory, KErrNotSupported. |
|
270 @since 7.0 |
|
271 @return None |
|
272 @pre CImplementationClassTwo has been constructed |
|
273 @post Unspecified |
|
274 */ |
|
275 void DoMethodL(); |
|
276 |
|
277 /** |
|
278 @fn FireAndForget() |
|
279 Intended Usage : Overload of the pure interface method |
|
280 asynchronous function which |
|
281 an interface definer could specify. |
|
282 It allows the client to call the function in the knowledge |
|
283 that the object will commit suicide when the |
|
284 function completes. |
|
285 Error Condition : None. |
|
286 @since 7.0 |
|
287 @return TInt KErrNone for success. |
|
288 @pre CImplementationClassTwo has been constructed |
|
289 @post Unspecified |
|
290 */ |
|
291 TInt FireAndForget(); |
|
292 |
|
293 /** |
|
294 @fn ImplId() |
|
295 Intended Usage : To verify the object returned by ECOM. |
|
296 Error Condition : None. |
|
297 @since 7.0s |
|
298 @return TUid (ECOM's Implementation Uid for this class.) |
|
299 @pre CImplementationClassThree has been constructed |
|
300 @post Unspecified |
|
301 */ |
|
302 TUid ImplId(); |
|
303 |
|
304 private: |
|
305 /** |
|
306 @fn CImplementationClassTwo() |
|
307 Intended Usage : Default Constructor : usable only by derived classes |
|
308 Error Condition : None |
|
309 @since 7.0 |
|
310 @pre None |
|
311 @post CImplementationClassTwo has been constructed |
|
312 */ |
|
313 CImplementationClassTwo(); |
|
314 |
|
315 /** |
|
316 @fn ConstructL() |
|
317 Intended Usage : Completes the safe construction of the CImplementationClassTwo object |
|
318 Error Condition : Leaves with the error code. |
|
319 @leave KErrNoMemory. |
|
320 @since 7.0 |
|
321 @pre CImplementationClassTwo has been constructed |
|
322 @post CImplementationClassTwo has been fully initialised. |
|
323 */ |
|
324 void ConstructL(); |
|
325 |
|
326 // Provide the CActive overloads |
|
327 void RunL(); |
|
328 void DoCancel(); |
|
329 TInt RunError(TInt aError); |
|
330 }; // End of CImplementationClassTwo definition |
|
331 |
|
332 // __________________________________________________________________________ |
|
333 // Implementation |
|
334 |
|
335 CImplementationClassTwo* CImplementationClassTwo::NewL(TAny* /* aParams */) |
|
336 // Intended Usage : Safe construction which leaves nothing upon the cleanup stack |
|
337 // Error Condition : Will leave with an appropriate error code |
|
338 // Dependencies : CBase |
|
339 // @param " " |
|
340 // @return CImplementationClassTwo* a pointer to the fully instantiated CImplementationClassTwo object |
|
341 // @pre None |
|
342 // @post The object has been fully instantiated |
|
343 // Static member |
|
344 { |
|
345 CImplementationClassTwo* self=new(ELeave) CImplementationClassTwo(); // calls c'tor |
|
346 CleanupStack::PushL(self); // Make the construction safe by using the cleanup stack |
|
347 self->ConstructL(); // Complete the 'construction'. |
|
348 CleanupStack::Pop(self); |
|
349 return self; |
|
350 } |
|
351 |
|
352 CImplementationClassTwo::~CImplementationClassTwo() |
|
353 // Default virtual d'tor |
|
354 { |
|
355 // Do Nothing |
|
356 } |
|
357 |
|
358 CImplementationClassTwo::CImplementationClassTwo() |
|
359 // Default c'tor for use by derived and |
|
360 // static construction methods only |
|
361 : CExampleInterface() |
|
362 { |
|
363 CActiveScheduler::Add(this); |
|
364 } |
|
365 |
|
366 void CImplementationClassTwo::ConstructL() |
|
367 // Intended Usage : Safely complete the initialization of the constructed object |
|
368 // Error Condition : Will leave with an appropriate error code |
|
369 // Dependencies : CBase |
|
370 // @return void |
|
371 // @pre CImplementationClassTwo has been constructed |
|
372 // @post The CImplementationClassTwo object has been fully instantiated |
|
373 // |
|
374 { |
|
375 // Do Nothing |
|
376 } |
|
377 |
|
378 void CImplementationClassTwo::DoMethodL() |
|
379 { |
|
380 // Do nothing |
|
381 } |
|
382 |
|
383 TInt CImplementationClassTwo::FireAndForget() |
|
384 { |
|
385 TInt error = KErrNone; |
|
386 TRAP(error,DoMethodL()); |
|
387 if(!IsActive()) |
|
388 { |
|
389 SetActive(); |
|
390 iStatus = KRequestPending; |
|
391 TRequestStatus* status = &iStatus; |
|
392 User::RequestComplete(status, KErrNone); |
|
393 } |
|
394 return error; |
|
395 } |
|
396 |
|
397 // Provide the CActive overloads |
|
398 void CImplementationClassTwo::RunL() |
|
399 { |
|
400 delete this; // AAARGH : Scary!!!! |
|
401 } |
|
402 |
|
403 void CImplementationClassTwo::DoCancel() |
|
404 { |
|
405 // Do nothing |
|
406 } |
|
407 |
|
408 TInt CImplementationClassTwo::RunError(TInt aError) |
|
409 { |
|
410 return aError; |
|
411 } |
|
412 |
|
413 TUid CImplementationClassTwo::ImplId() |
|
414 { |
|
415 TUid idVal = {0x10009DC4}; |
|
416 return (idVal); |
|
417 } |
|
418 |
|
419 // __________________________________________________________________________ |
|
420 // Exported proxy for instantiation method resolution |
|
421 // Define the interface UIDs |
|
422 const TImplementationProxy ImplementationTable[] = |
|
423 { |
|
424 IMPLEMENTATION_PROXY_ENTRY(0x10009DC3, CImplementationClassOne::NewL), |
|
425 IMPLEMENTATION_PROXY_ENTRY(0x10009DC4, CImplementationClassTwo::NewL), |
|
426 IMPLEMENTATION_PROXY_ENTRY(0x10009DD0, CExampleResolver::NewL) |
|
427 }; |
|
428 |
|
429 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
430 { |
|
431 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
432 |
|
433 return ImplementationTable; |
|
434 } |
|
435 |