sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// The implementation of a Suicidal class
|
sl@0
|
15 |
// to be provided by ECom.
|
sl@0
|
16 |
// 1. Using the CExampleInterface class as a base.
|
sl@0
|
17 |
//
|
sl@0
|
18 |
//
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "TestUtilities.h" // For __FILE__LINE__
|
sl@0
|
21 |
#include "Interface.h"
|
sl@0
|
22 |
#include "ImplementationProxy.h"
|
sl@0
|
23 |
|
sl@0
|
24 |
// ____________________________________________________________________________
|
sl@0
|
25 |
//
|
sl@0
|
26 |
/**
|
sl@0
|
27 |
Intended usage: This class implements the functionality promised by
|
sl@0
|
28 |
the CExampleInterface defintion class. It does little apart from provides a test instance
|
sl@0
|
29 |
which may be retrieved and run for testing purposes, and then commits suicide.
|
sl@0
|
30 |
Its resolution is based upon its registered default data string that
|
sl@0
|
31 |
advertises this class as being able to handle 'text\wml' data.
|
sl@0
|
32 |
@since 7.0
|
sl@0
|
33 |
*/
|
sl@0
|
34 |
class CSuicidalImplementation : public CExampleInterface
|
sl@0
|
35 |
{
|
sl@0
|
36 |
// Methods
|
sl@0
|
37 |
public:
|
sl@0
|
38 |
/**
|
sl@0
|
39 |
@fn NewL()
|
sl@0
|
40 |
Intended Usage : Standardised safe construction which leaves nothing the cleanup stack.
|
sl@0
|
41 |
Error Condition : Leaves with error code.
|
sl@0
|
42 |
@leave KErrNoMemory.
|
sl@0
|
43 |
@since 7.0
|
sl@0
|
44 |
@return CSuicidalImplementation* The class instance.
|
sl@0
|
45 |
@pre None
|
sl@0
|
46 |
@post CSuicidalImplementation has been constructed,
|
sl@0
|
47 |
and initialised.
|
sl@0
|
48 |
*/
|
sl@0
|
49 |
static CSuicidalImplementation* NewL();
|
sl@0
|
50 |
|
sl@0
|
51 |
/**
|
sl@0
|
52 |
@fn ~CSuicidalImplementation()
|
sl@0
|
53 |
Intended Usage : Default Destructor
|
sl@0
|
54 |
Error Condition : None
|
sl@0
|
55 |
@since 7.0
|
sl@0
|
56 |
@pre CSuicidalImplementation has been constructed
|
sl@0
|
57 |
@post CSuicidalImplementation has been completely destroyed,
|
sl@0
|
58 |
and is no longer registered with the scheduler.
|
sl@0
|
59 |
*/
|
sl@0
|
60 |
virtual ~CSuicidalImplementation();
|
sl@0
|
61 |
|
sl@0
|
62 |
/**
|
sl@0
|
63 |
@fn DoMethodL()
|
sl@0
|
64 |
Intended Usage : Overload of the pure interface method
|
sl@0
|
65 |
Representative of some method provided on
|
sl@0
|
66 |
the interface by the interface definer.
|
sl@0
|
67 |
Error Condition : Leaves with an error code.
|
sl@0
|
68 |
@leave KErrNoMemory, KErrNotSupported.
|
sl@0
|
69 |
@since 7.0
|
sl@0
|
70 |
@return None
|
sl@0
|
71 |
@pre CSuicidalImplementation has been constructed
|
sl@0
|
72 |
@post Unspecified
|
sl@0
|
73 |
*/
|
sl@0
|
74 |
void DoMethodL();
|
sl@0
|
75 |
|
sl@0
|
76 |
/**
|
sl@0
|
77 |
@fn FireAndForget()
|
sl@0
|
78 |
Intended Usage : Overload of the pure interface method
|
sl@0
|
79 |
asynchronous function which
|
sl@0
|
80 |
an interface definer could specify.
|
sl@0
|
81 |
It allows the client to call the function in the knowledge
|
sl@0
|
82 |
that the object will commit suicide when the
|
sl@0
|
83 |
function completes.
|
sl@0
|
84 |
Error Condition : None.
|
sl@0
|
85 |
@since 7.0
|
sl@0
|
86 |
@return TInt KErrNone for success.
|
sl@0
|
87 |
@pre CSuicidalImplementation has been constructed
|
sl@0
|
88 |
@post CSuicidalImplementation is active with a status of KRequestPending.
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
TInt FireAndForget();
|
sl@0
|
91 |
|
sl@0
|
92 |
/**
|
sl@0
|
93 |
@fn ImplId()
|
sl@0
|
94 |
Intended Usage : To verify the object returned by ECOM.
|
sl@0
|
95 |
Error Condition : None.
|
sl@0
|
96 |
@since 7.0s
|
sl@0
|
97 |
@return TUid (ECOM's Implementation Uid for this class.)
|
sl@0
|
98 |
@pre CImplementationClassThree has been constructed
|
sl@0
|
99 |
@post Unspecified
|
sl@0
|
100 |
*/
|
sl@0
|
101 |
TUid ImplId();
|
sl@0
|
102 |
|
sl@0
|
103 |
private:
|
sl@0
|
104 |
/**
|
sl@0
|
105 |
@fn CSuicidalImplementation()
|
sl@0
|
106 |
Intended Usage : Default Constructor : usable only by derived classes
|
sl@0
|
107 |
Error Condition : None
|
sl@0
|
108 |
@since 7.0
|
sl@0
|
109 |
@pre None
|
sl@0
|
110 |
@post CSuicidalImplementation has been constructed
|
sl@0
|
111 |
*/
|
sl@0
|
112 |
CSuicidalImplementation();
|
sl@0
|
113 |
|
sl@0
|
114 |
/**
|
sl@0
|
115 |
@fn ConstructL()
|
sl@0
|
116 |
Intended Usage : Completes the safe construction of the CSuicidalImplementation object
|
sl@0
|
117 |
Error Condition : Leaves with the error code.
|
sl@0
|
118 |
@leave KErrNoMemory.
|
sl@0
|
119 |
@since 7.0
|
sl@0
|
120 |
@pre CSuicidalImplementation has been constructed
|
sl@0
|
121 |
@post CSuicidalImplementation has been fully initialised.
|
sl@0
|
122 |
*/
|
sl@0
|
123 |
void ConstructL();
|
sl@0
|
124 |
|
sl@0
|
125 |
// Provide the CActive overloads
|
sl@0
|
126 |
/**
|
sl@0
|
127 |
@fn RunL()
|
sl@0
|
128 |
Intended Usage : When the object activates commit suicide.
|
sl@0
|
129 |
Error Condition : Not enough memory available to complete the scan.
|
sl@0
|
130 |
@leave KErrNoMemory
|
sl@0
|
131 |
@since 7.0
|
sl@0
|
132 |
@pre CSuicidalImplementation is fully constructed.
|
sl@0
|
133 |
@post CSuicidalImplementation has committed suicide,
|
sl@0
|
134 |
and deleted itself.
|
sl@0
|
135 |
*/
|
sl@0
|
136 |
void RunL();
|
sl@0
|
137 |
/**
|
sl@0
|
138 |
@fn DoCancel()
|
sl@0
|
139 |
Intended Usage : The cancel action called by CActive::Cancel().
|
sl@0
|
140 |
Error Condition : None
|
sl@0
|
141 |
@since 7.0
|
sl@0
|
142 |
@pre CSuicidalImplementation is fully constructed.
|
sl@0
|
143 |
@post CSuicidalImplementation behaviour is cancelled and
|
sl@0
|
144 |
it is no longer active on the current scheduler.
|
sl@0
|
145 |
*/
|
sl@0
|
146 |
void DoCancel();
|
sl@0
|
147 |
|
sl@0
|
148 |
/**
|
sl@0
|
149 |
@fn RunError(TInt aError)
|
sl@0
|
150 |
Intended Usage : Called by the RunL leaving.
|
sl@0
|
151 |
@since 7.0
|
sl@0
|
152 |
@param aError The error code that the RunL left with.
|
sl@0
|
153 |
@return TInt KErrNone.
|
sl@0
|
154 |
@pre CSuicidalImplementation is fully constructed.
|
sl@0
|
155 |
@post CSuicidalImplementation is returned to a
|
sl@0
|
156 |
sensible active state.
|
sl@0
|
157 |
*/
|
sl@0
|
158 |
TInt RunError(TInt aError);
|
sl@0
|
159 |
|
sl@0
|
160 |
}; // End of CSuicidalImplementation definition
|
sl@0
|
161 |
|
sl@0
|
162 |
// __________________________________________________________________________
|
sl@0
|
163 |
// Implementation
|
sl@0
|
164 |
const TInt KDefaultTestAllocSize = 8;
|
sl@0
|
165 |
|
sl@0
|
166 |
CSuicidalImplementation* CSuicidalImplementation::NewL()
|
sl@0
|
167 |
// Intended Usage : Safe construction which leaves nothing upon the cleanup stack
|
sl@0
|
168 |
// Error Condition : Will leave with an appropriate error code
|
sl@0
|
169 |
// Dependencies : CBase
|
sl@0
|
170 |
// @param " "
|
sl@0
|
171 |
// @return CSuicidalImplementation* a pointer to the fully instantiated CSuicidalImplementation object
|
sl@0
|
172 |
// @pre None
|
sl@0
|
173 |
// @post The object has been fully instantiated
|
sl@0
|
174 |
// Static member
|
sl@0
|
175 |
{
|
sl@0
|
176 |
CSuicidalImplementation* self=new(ELeave) CSuicidalImplementation(); // calls c'tor
|
sl@0
|
177 |
CleanupStack::PushL(self); // Make the construction safe by using the cleanup stack
|
sl@0
|
178 |
self->ConstructL(); // Complete the 'construction'.
|
sl@0
|
179 |
CleanupStack::Pop(self);
|
sl@0
|
180 |
return self;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
CSuicidalImplementation::~CSuicidalImplementation()
|
sl@0
|
184 |
// Default virtual d'tor
|
sl@0
|
185 |
{
|
sl@0
|
186 |
// Do Nothing
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
CSuicidalImplementation::CSuicidalImplementation()
|
sl@0
|
190 |
// Default c'tor for use by derived and
|
sl@0
|
191 |
// static construction methods only
|
sl@0
|
192 |
: CExampleInterface()
|
sl@0
|
193 |
{
|
sl@0
|
194 |
// Deliberately do nothing here : See ConstructL() for initialisation completion.
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
void CSuicidalImplementation::ConstructL()
|
sl@0
|
198 |
// Intended Usage : Safely complete the initialization of the constructed object
|
sl@0
|
199 |
// Error Condition : Will leave with an appropriate error code
|
sl@0
|
200 |
// Dependencies : CBase
|
sl@0
|
201 |
// @return void
|
sl@0
|
202 |
// @pre CSuicidalImplementation has been constructed
|
sl@0
|
203 |
// @post The CSuicidalImplementation object has been fully instantiated
|
sl@0
|
204 |
//
|
sl@0
|
205 |
{
|
sl@0
|
206 |
// Allocate and delete some memory
|
sl@0
|
207 |
// so that leave testing can check
|
sl@0
|
208 |
// for the correct handling.
|
sl@0
|
209 |
HBufC* temp = HBufC::NewL(KDefaultTestAllocSize);
|
sl@0
|
210 |
delete temp;
|
sl@0
|
211 |
}
|
sl@0
|
212 |
|
sl@0
|
213 |
void CSuicidalImplementation::DoMethodL()
|
sl@0
|
214 |
{
|
sl@0
|
215 |
CActiveScheduler::Add(this);
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
TInt CSuicidalImplementation::FireAndForget()
|
sl@0
|
219 |
{
|
sl@0
|
220 |
TInt error = KErrNone;
|
sl@0
|
221 |
TRAP(error,DoMethodL());
|
sl@0
|
222 |
if(!IsActive())
|
sl@0
|
223 |
{
|
sl@0
|
224 |
SetActive();
|
sl@0
|
225 |
iStatus = KRequestPending;
|
sl@0
|
226 |
TRequestStatus* status = &iStatus;
|
sl@0
|
227 |
User::RequestComplete(status, error);
|
sl@0
|
228 |
}
|
sl@0
|
229 |
return error;
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
// Provide the CActive overloads
|
sl@0
|
233 |
void CSuicidalImplementation::RunL()
|
sl@0
|
234 |
{
|
sl@0
|
235 |
User::LeaveIfError(iStatus.Int());
|
sl@0
|
236 |
delete this; // AAARGH : Scary self deletion!!!!
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
void CSuicidalImplementation::DoCancel()
|
sl@0
|
240 |
{
|
sl@0
|
241 |
// Do nothing
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
TInt CSuicidalImplementation::RunError(TInt)
|
sl@0
|
245 |
{
|
sl@0
|
246 |
delete this; // AAARGH : Scary self deletion!!!!
|
sl@0
|
247 |
return KErrNone; // Don't Panic
|
sl@0
|
248 |
}
|
sl@0
|
249 |
|
sl@0
|
250 |
TUid CSuicidalImplementation::ImplId()
|
sl@0
|
251 |
{
|
sl@0
|
252 |
TUid idVal = {0x10009DC5};
|
sl@0
|
253 |
return (idVal);
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
// __________________________________________________________________________
|
sl@0
|
257 |
// Exported proxy for instantiation method resolution
|
sl@0
|
258 |
// Define the interface UIDs
|
sl@0
|
259 |
const TImplementationProxy ImplementationTable[] =
|
sl@0
|
260 |
{
|
sl@0
|
261 |
IMPLEMENTATION_PROXY_ENTRY(0x10009DC5, CSuicidalImplementation::NewL) // SuicidalImplementationClass
|
sl@0
|
262 |
};
|
sl@0
|
263 |
|
sl@0
|
264 |
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
|
sl@0
|
265 |
{
|
sl@0
|
266 |
aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
|
sl@0
|
267 |
|
sl@0
|
268 |
return ImplementationTable;
|
sl@0
|
269 |
}
|