80
|
1 |
/*
|
|
2 |
* Copyright (c) 2006, 2007 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: This class defines and implements the API for UI engine.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <e32debug.h>
|
|
21 |
#include <dps.rsg>
|
|
22 |
#include <f32file.h>
|
|
23 |
#include <barsc.h>
|
|
24 |
#include <barsread.h>
|
|
25 |
#include <bautils.h>
|
|
26 |
#include <pathinfo.h>
|
|
27 |
|
|
28 |
#include "pictbridge.h"
|
|
29 |
#include "dpsdefs.h"
|
|
30 |
#include "dpsxmlstring.h"
|
|
31 |
#include "dpsconst.h"
|
|
32 |
#include "dpsstatemachine.h"
|
|
33 |
#include "dpsscriptreceiver.h"
|
|
34 |
#include "dpsusbnotifier.h"
|
|
35 |
#include "dpsparam.h"
|
|
36 |
#include "dpsscriptsender.h"
|
|
37 |
#include "dpstransaction.h"
|
|
38 |
#include "dpsfile.h"
|
|
39 |
|
|
40 |
#ifdef _DEBUG
|
|
41 |
# define IF_DEBUG(t) {RDebug::t;}
|
|
42 |
#else
|
|
43 |
# define IF_DEBUG(t)
|
|
44 |
#endif
|
|
45 |
|
|
46 |
const TInt KResource = 32;
|
|
47 |
const TInt KDriver = 3;
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
// ---------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
EXPORT_C CDpsEngine* CDpsEngine::GetEngineL()
|
|
53 |
{
|
|
54 |
IF_DEBUG(Print(_L("CDpsEngine::GetEngineL")));
|
|
55 |
CDpsEngine* me;
|
|
56 |
me = static_cast<CDpsEngine*>(Dll::Tls());
|
|
57 |
if (!me)
|
|
58 |
{
|
|
59 |
CDpsEngine* self = new(ELeave) CDpsEngine();
|
|
60 |
|
|
61 |
CleanupStack::PushL(self);
|
|
62 |
self->ConstructL();
|
|
63 |
CleanupStack::Pop();
|
|
64 |
User::LeaveIfError(Dll::SetTls(self));
|
|
65 |
return self;
|
|
66 |
}
|
|
67 |
else
|
|
68 |
{
|
|
69 |
return me;
|
|
70 |
}
|
|
71 |
}
|
|
72 |
|
|
73 |
// ---------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
// ---------------------------------------------------------------------------
|
|
76 |
//
|
|
77 |
EXPORT_C void CDpsEngine::Delete()
|
|
78 |
{
|
|
79 |
IF_DEBUG(Print(_L(">>>DpsEngine::Delete")));
|
|
80 |
CDpsEngine *me; me = static_cast<CDpsEngine*>(Dll::Tls());
|
|
81 |
if (me)
|
|
82 |
{
|
|
83 |
delete me;
|
|
84 |
Dll::SetTls(NULL);
|
|
85 |
}
|
|
86 |
IF_DEBUG(Print(_L("<<<DpsEngine::Delete")));
|
|
87 |
}
|
|
88 |
|
|
89 |
// ---------------------------------------------------------------------------
|
|
90 |
//
|
|
91 |
// ---------------------------------------------------------------------------
|
|
92 |
//
|
|
93 |
void CDpsEngine::ConstructL()
|
|
94 |
{
|
|
95 |
IF_DEBUG(Print(_L(">>>CDpsEngine::ConstructL")));
|
|
96 |
iDpsParameters = TDpsXmlString::NewL();
|
|
97 |
User::LeaveIfError(iPtp.Connect());
|
|
98 |
iDpsOperator = CDpsStateMachine::NewL(this);
|
|
99 |
iUsbNotifier = CDpsUsbNotifier::NewL(this);
|
|
100 |
IF_DEBUG(Print(_L("<<<DpsEngine::ConstructL")));
|
|
101 |
}
|
|
102 |
|
|
103 |
// ---------------------------------------------------------------------------
|
|
104 |
//
|
|
105 |
// ---------------------------------------------------------------------------
|
|
106 |
//
|
|
107 |
CDpsEngine::~CDpsEngine()
|
|
108 |
{
|
|
109 |
IF_DEBUG(Print(_L(">>>~CDpsEngine")));
|
|
110 |
|
|
111 |
delete iDpsOperator;
|
|
112 |
iDpsOperator = NULL;
|
|
113 |
|
|
114 |
delete iUsbNotifier;
|
|
115 |
iUsbNotifier = NULL;
|
|
116 |
|
|
117 |
if (iDpsOperationRequest)
|
|
118 |
{
|
|
119 |
User::RequestComplete(iDpsOperationRequest, KErrCancel);
|
|
120 |
}
|
|
121 |
if (iDpsEventRequest)
|
|
122 |
{
|
|
123 |
User::RequestComplete(iDpsEventRequest, KErrCancel);
|
|
124 |
}
|
|
125 |
if (iPrinterConnectRequest)
|
|
126 |
{
|
|
127 |
User::RequestComplete(iPrinterConnectRequest, KErrCancel);
|
|
128 |
}
|
|
129 |
delete iDpsParameters;
|
|
130 |
iDpsParameters = NULL;
|
|
131 |
iPtp.Close();
|
|
132 |
IF_DEBUG(Print(_L("<<<~CDpsEngine")));
|
|
133 |
}
|
|
134 |
|
|
135 |
// ---------------------------------------------------------------------------
|
|
136 |
//
|
|
137 |
// ---------------------------------------------------------------------------
|
|
138 |
//
|
|
139 |
EXPORT_C void CDpsEngine::SetPrintMode(TRequestStatus& aStatus)
|
|
140 |
{
|
|
141 |
IF_DEBUG(Print(_L(">>>DpsEngine::SearchPrinter")));
|
|
142 |
|
|
143 |
iPrinterConnectRequest = &aStatus;
|
|
144 |
*iPrinterConnectRequest = KRequestPending;
|
|
145 |
iUsbNotifier->WaitForPrinterNotify();
|
|
146 |
IF_DEBUG(Print(_L("<<<DpsEngine::SearchPrinter")));
|
|
147 |
}
|
|
148 |
|
|
149 |
// ---------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
// ---------------------------------------------------------------------------
|
|
152 |
//
|
|
153 |
EXPORT_C void CDpsEngine::CancelPrintMode()
|
|
154 |
{
|
|
155 |
IF_DEBUG(Print(_L(">>>DpsEngine::CancelSearchPrinter")));
|
|
156 |
iUsbNotifier->CancelPrinterNotify();
|
|
157 |
IF_DEBUG(Print(_L("<<<DpsEngine::CancelSearchPrinter")));
|
|
158 |
}
|
|
159 |
|
|
160 |
// ---------------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
// ---------------------------------------------------------------------------
|
|
163 |
//
|
|
164 |
EXPORT_C void CDpsEngine::ConnectStateNotify(TRequestStatus& aStatus)
|
|
165 |
{
|
|
166 |
IF_DEBUG(Print(_L(">>>DpsEngine::ConnectStateNotifyL")));
|
|
167 |
// SetPrintMode must be finished
|
|
168 |
if (!iUsbNotifier->IsSetPrintModeIssued())
|
|
169 |
{
|
|
170 |
TRequestStatus* status = &aStatus;
|
|
171 |
User::RequestComplete(status, KErrNotReady);
|
|
172 |
return;
|
|
173 |
}
|
|
174 |
|
|
175 |
iPrinterConnectRequest = &aStatus;
|
|
176 |
*iPrinterConnectRequest = KRequestPending;
|
|
177 |
iUsbNotifier->ConnectNotify();
|
|
178 |
IF_DEBUG(Print(_L("<<<DpsEngine::ConnecStatetNotifyL")));
|
|
179 |
}
|
|
180 |
|
|
181 |
// ---------------------------------------------------------------------------
|
|
182 |
//
|
|
183 |
// ---------------------------------------------------------------------------
|
|
184 |
//
|
|
185 |
EXPORT_C void CDpsEngine::DoDpsRequestL(TMDpsOperation* aRequest,
|
|
186 |
TRequestStatus& aStatus)
|
|
187 |
{
|
|
188 |
IF_DEBUG(Print(_L(">>>DpsEngine::DoDpsRequestL")));
|
|
189 |
// the ptp printer must be connected and registered for the dps event
|
|
190 |
if (!iUsbNotifier->IsConfigured() || !iDpsEventRequest)
|
|
191 |
{
|
|
192 |
TRequestStatus* status = &aStatus;
|
|
193 |
User::RequestComplete(status, KErrNotReady);
|
|
194 |
return;
|
|
195 |
}
|
|
196 |
|
|
197 |
// there is a request from the host received and the reply has been
|
|
198 |
// sending out, but the host has not received it yet. we can not send
|
|
199 |
// the device request now
|
|
200 |
IF_DEBUG(Print(_L("curState is %x, idleState is %x"),
|
|
201 |
iDpsOperator->CurState(), iDpsOperator->IdleState()));
|
|
202 |
if (iDpsOperator->CurState() != iDpsOperator->IdleState())
|
|
203 |
{
|
|
204 |
TRequestStatus* status = &aStatus;
|
|
205 |
User::RequestComplete(status, KErrInUse);
|
|
206 |
return;
|
|
207 |
}
|
|
208 |
|
|
209 |
iDpsOperator->StartTransactionL(aRequest);
|
|
210 |
iDpsOperationRequest = &aStatus;
|
|
211 |
*iDpsOperationRequest = KRequestPending;
|
|
212 |
IF_DEBUG(Print(_L("<<<DpsEngine::DoDpsRequestL")));
|
|
213 |
}
|
|
214 |
|
|
215 |
// ---------------------------------------------------------------------------
|
|
216 |
//
|
|
217 |
// ---------------------------------------------------------------------------
|
|
218 |
//
|
|
219 |
EXPORT_C void CDpsEngine::CancelDpsRequest()
|
|
220 |
{
|
|
221 |
IF_DEBUG(Print(_L(">>>DpsEngine::CancelDpsOperation")));
|
|
222 |
if (iDpsOperationRequest)
|
|
223 |
{
|
|
224 |
iDpsOperator->ScriptSender()->Cancel();
|
|
225 |
User::RequestComplete(iDpsOperationRequest, KErrCancel);
|
|
226 |
}
|
|
227 |
iDpsOperator->Initialize();
|
|
228 |
IF_DEBUG(Print(_L("<<<DpsEngine::CancelDpsOperation")));
|
|
229 |
}
|
|
230 |
|
|
231 |
// ---------------------------------------------------------------------------
|
|
232 |
//
|
|
233 |
// ---------------------------------------------------------------------------
|
|
234 |
//
|
|
235 |
EXPORT_C void CDpsEngine::DpsEventNotify(TDpsEvents& aParam,
|
|
236 |
TRequestStatus& aStatus)
|
|
237 |
{
|
|
238 |
IF_DEBUG(Print(_L(">>>DpsEngine::DpsEventNotify")));
|
|
239 |
// the PTP printer must be connected and registered for the disconnect
|
|
240 |
if (!iUsbNotifier->IsConfigured() || !iPrinterConnectRequest)
|
|
241 |
{
|
|
242 |
TRequestStatus* status = &aStatus;
|
|
243 |
User::RequestComplete(status, KErrNotReady);
|
|
244 |
return;
|
|
245 |
}
|
|
246 |
|
|
247 |
iOutEvent = &aParam;
|
|
248 |
iDpsEventRequest = &aStatus;
|
|
249 |
*iDpsEventRequest = KRequestPending;
|
|
250 |
iDpsOperator->ScriptReceiver()->WaitForReceive();
|
|
251 |
IF_DEBUG(Print(_L("<<<DpsEngine::DpsEventNotify")));
|
|
252 |
}
|
|
253 |
|
|
254 |
// ---------------------------------------------------------------------------
|
|
255 |
//
|
|
256 |
// ---------------------------------------------------------------------------
|
|
257 |
//
|
|
258 |
EXPORT_C void CDpsEngine::CancelDpsEventNotify()
|
|
259 |
{
|
|
260 |
IF_DEBUG(Print(_L("DpsEngine::CancelDpsEventNotify")));
|
|
261 |
if (iDpsEventRequest)
|
|
262 |
{
|
|
263 |
User::RequestComplete(iDpsEventRequest, KErrCancel);
|
|
264 |
iDpsOperator->ScriptReceiver()->Cancel();
|
|
265 |
}
|
|
266 |
}
|
|
267 |
|
|
268 |
// ---------------------------------------------------------------------------
|
|
269 |
//
|
|
270 |
// ---------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
EXPORT_C void CDpsEngine::GetDpsConfigL(TDpsConfigPrintReq& aConfig)
|
|
273 |
{
|
|
274 |
IF_DEBUG(Print(_L(">>>DpsEngine::GetDpsConfigL")));
|
|
275 |
|
|
276 |
RFs fs = iDpsOperator->Trader()->FileHandle()->FileSession();
|
|
277 |
RResourceFile resource;
|
|
278 |
|
|
279 |
TBuf<KResource> resourceFile(PathInfo::RomRootPath());
|
|
280 |
TBuf<KResource> length(KDpsResource);
|
|
281 |
resourceFile.SetLength(KDriver + length.Length());
|
|
282 |
resourceFile.Replace(KDriver, length.Length(), KDpsResource);
|
|
283 |
IF_DEBUG(Print(_L("file is %S"), &resourceFile));
|
|
284 |
resource.OpenL(fs, resourceFile);
|
|
285 |
CleanupClosePushL(resource);
|
|
286 |
resource.ConfirmSignatureL(KDpsResourceVersion);
|
|
287 |
HBufC8* id = resource.AllocReadLC(DPS_CONFIG);
|
|
288 |
TResourceReader reader;
|
|
289 |
reader.SetBuffer(id);
|
|
290 |
TInt count = static_cast<TInt>(reader.ReadUint8());
|
|
291 |
for (TInt i = 0; i < count; i++)
|
|
292 |
{
|
|
293 |
TDpsVersion version;
|
|
294 |
version.iMajor = static_cast<TInt>(reader.ReadUint8());
|
|
295 |
version.iMinor = static_cast<TInt>(reader.ReadUint8());
|
|
296 |
aConfig.iDpsVersions.AppendL(version);
|
|
297 |
}
|
|
298 |
TPtrC vendorString = reader.ReadTPtrC();
|
|
299 |
aConfig.iVendorName.Copy(vendorString);
|
|
300 |
TDpsVersion vendorVersion;
|
|
301 |
vendorVersion.iMajor = static_cast<TInt>(reader.ReadUint8());
|
|
302 |
vendorVersion.iMinor = static_cast<TInt>(reader.ReadUint8());
|
|
303 |
aConfig.iVendorVersion = vendorVersion;
|
|
304 |
TPtrC productString = reader.ReadTPtrC();
|
|
305 |
aConfig.iProductName.Copy(productString);
|
|
306 |
TPtrC SerialNo = reader.ReadTPtrC();
|
|
307 |
aConfig.iSerialNo.Copy(SerialNo);
|
|
308 |
CleanupStack::PopAndDestroy(id);
|
|
309 |
CleanupStack::PopAndDestroy(&resource);
|
|
310 |
IF_DEBUG(Print(_L("<<<DpsEngine::GetDpsConfigL")));
|
|
311 |
}
|
|
312 |
|
|
313 |
// ---------------------------------------------------------------------------
|
|
314 |
//
|
|
315 |
// ---------------------------------------------------------------------------
|
|
316 |
//
|
|
317 |
EXPORT_C const TDesC& CDpsEngine::DpsFolder() const
|
|
318 |
{
|
|
319 |
return iDpsFolder;
|
|
320 |
}
|
|
321 |
|
|
322 |
// ---------------------------------------------------------------------------
|
|
323 |
//
|
|
324 |
// ---------------------------------------------------------------------------
|
|
325 |
//
|
|
326 |
TDpsEvents* CDpsEngine::Event() const
|
|
327 |
{
|
|
328 |
return iOutEvent;
|
|
329 |
}
|
|
330 |
|
|
331 |
// ---------------------------------------------------------------------------
|
|
332 |
//
|
|
333 |
// ---------------------------------------------------------------------------
|
|
334 |
//
|
|
335 |
RPtp& CDpsEngine::Ptp()
|
|
336 |
{
|
|
337 |
return iPtp;
|
|
338 |
}
|
|
339 |
|
|
340 |
// ---------------------------------------------------------------------------
|
|
341 |
//
|
|
342 |
// ---------------------------------------------------------------------------
|
|
343 |
//
|
|
344 |
TDpsXmlString* CDpsEngine::DpsParameters() const
|
|
345 |
{
|
|
346 |
return iDpsParameters;
|
|
347 |
}
|
|
348 |
|
|
349 |
// ---------------------------------------------------------------------------
|
|
350 |
//
|
|
351 |
// ---------------------------------------------------------------------------
|
|
352 |
//
|
|
353 |
TRequestStatus*& CDpsEngine::EventRequest()
|
|
354 |
{
|
|
355 |
return iDpsEventRequest;
|
|
356 |
}
|
|
357 |
|
|
358 |
// ---------------------------------------------------------------------------
|
|
359 |
//
|
|
360 |
// ---------------------------------------------------------------------------
|
|
361 |
//
|
|
362 |
TRequestStatus*& CDpsEngine::OperationRequest()
|
|
363 |
{
|
|
364 |
return iDpsOperationRequest;
|
|
365 |
}
|
|
366 |
|
|
367 |
// ---------------------------------------------------------------------------
|
|
368 |
//
|
|
369 |
// ---------------------------------------------------------------------------
|
|
370 |
//
|
|
371 |
TRequestStatus*& CDpsEngine::PrinterConnectRequest()
|
|
372 |
{
|
|
373 |
return iPrinterConnectRequest;
|
|
374 |
}
|
|
375 |
|
|
376 |
// ---------------------------------------------------------------------------
|
|
377 |
//
|
|
378 |
// ---------------------------------------------------------------------------
|
|
379 |
//
|
|
380 |
void CDpsEngine::SetDpsFolder(const TDesC& aFolder)
|
|
381 |
{
|
|
382 |
iDpsFolder.Copy(aFolder);
|
|
383 |
}
|
|
384 |
|