|
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 implements the dps script sending function. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32debug.h> |
|
20 #include <f32file.h> |
|
21 #include "dpsscriptsender.h" |
|
22 #include "dpsstatemachine.h" |
|
23 #include "pictbridge.h" |
|
24 #include "dpstransaction.h" |
|
25 #include "dpsfile.h" |
|
26 |
|
27 #ifdef _DEBUG |
|
28 # define IF_DEBUG(t) {RDebug::t;} |
|
29 #else |
|
30 # define IF_DEBUG(t) |
|
31 #endif |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CDpsScriptSender* CDpsScriptSender::NewL(CDpsStateMachine* aOperator) |
|
38 { |
|
39 IF_DEBUG(Print(_L("CDpsScriptSender::NewL"))); |
|
40 CDpsScriptSender* self = new(ELeave) CDpsScriptSender(aOperator); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CDpsScriptSender::CDpsScriptSender(CDpsStateMachine* aOperator) : |
|
49 CActive(EPriorityNormal), iOperator(aOperator), |
|
50 iReply(EFalse) |
|
51 { |
|
52 IF_DEBUG(Print(_L(">>>CDpsScriptSender::Ctor"))); |
|
53 CActiveScheduler::Add(this); |
|
54 IF_DEBUG(Print(_L("<<<CDpsScriptSender::Ctor"))); |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CDpsScriptSender::~CDpsScriptSender() |
|
62 { |
|
63 IF_DEBUG(Print(_L(">>>~CDpsScriptSender"))); |
|
64 Cancel(); |
|
65 IF_DEBUG(Print(_L("<<<~CDpsScriptSender"))); |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 TInt CDpsScriptSender::SendScript(TBool aReply) |
|
73 { |
|
74 IF_DEBUG(Print(_L(">>>CDpsScriptSender::SendScript"))); |
|
75 if (!IsActive()) |
|
76 { |
|
77 iReply = aReply; |
|
78 TFileName file(iOperator->DpsEngine()->DpsFolder()); |
|
79 RFile script; |
|
80 if (aReply) |
|
81 { |
|
82 file.Append(KDpsDeviceResponseFileName); |
|
83 } |
|
84 else |
|
85 { |
|
86 file.Append(KDpsDeviceRequestFileName); |
|
87 } |
|
88 TInt err = script.Open(iOperator->Trader()-> |
|
89 FileHandle()->FileSession(), file, EFileRead); |
|
90 if (err != KErrNone) |
|
91 { |
|
92 return err; |
|
93 } |
|
94 TInt size; |
|
95 script.Size(size); |
|
96 script.Close(); |
|
97 if (aReply) |
|
98 { |
|
99 iOperator->DpsEngine()-> |
|
100 Ptp().SendObject(file, iStatus, EFalse, size); |
|
101 } |
|
102 else |
|
103 { |
|
104 iOperator->DpsEngine()-> |
|
105 Ptp().SendObject(file, iStatus, ETrue, size); |
|
106 } |
|
107 SetActive(); |
|
108 IF_DEBUG(Print(_L("<<<CDpsScriptSender::SendScript"))); |
|
109 return KErrNone; |
|
110 } |
|
111 else |
|
112 { |
|
113 return KErrInUse; |
|
114 } |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 void CDpsScriptSender::RunL() |
|
122 { |
|
123 IF_DEBUG(Print(_L(">>>CDpsScriptSender::RunL"))); |
|
124 |
|
125 if (KErrNone == iStatus.Int()) |
|
126 { |
|
127 // the device request is sent |
|
128 if (!iReply) |
|
129 { |
|
130 iOperator->ScriptSentNotifyL(EFalse); |
|
131 } |
|
132 // the device response is sent |
|
133 else |
|
134 { |
|
135 iOperator->ScriptSentNotifyL(ETrue); |
|
136 } |
|
137 } |
|
138 else |
|
139 { |
|
140 IF_DEBUG(Print(_L("the iStatus is wrong %d!!!"), iStatus.Int())); |
|
141 iOperator->Error(iStatus.Int()); |
|
142 } |
|
143 IF_DEBUG(Print(_L("<<<CDpsScriptSender::RunL"))); |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 void CDpsScriptSender::DoCancel() |
|
151 { |
|
152 IF_DEBUG(Print(_L(">>>CDpsScriptSender::DoCancel"))); |
|
153 iOperator->DpsEngine()->Ptp().CancelSendObject(); |
|
154 IF_DEBUG(Print(_L("<<<CDpsScriptSender::DoCancel"))); |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 TInt CDpsScriptSender::RunError(TInt aError) |
|
162 { |
|
163 IF_DEBUG(Print(_L(">>>CDpsScriptSender::RunError is %d"), aError)); |
|
164 Cancel(); |
|
165 iOperator->Error(aError); |
|
166 IF_DEBUG(Print(_L("<<<CDpsScriptSender::RunError"))); |
|
167 return KErrNone; |
|
168 } |