|
1 // Copyright (c) 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 // |
|
15 |
|
16 #include <mtp/cmtptypeobjectinfo.h> |
|
17 #include <mtp/mmtpconnection.h> |
|
18 #include <mtp/mtpprotocolconstants.h> |
|
19 |
|
20 #include "cptpserver.h" |
|
21 #include "cptpsession.h" |
|
22 #include "cptpreceivedmsghandler.h" |
|
23 #include "cmtppictbridgeprinter.h" |
|
24 #include "mtppictbridgedpconst.h" |
|
25 #include "cmtppictbridgeusbconnection.h" |
|
26 |
|
27 // -------------------------------------------------------------------------- |
|
28 // |
|
29 // -------------------------------------------------------------------------- |
|
30 // |
|
31 CMTPPictBridgePrinter* CMTPPictBridgePrinter::NewL(CPtpServer& aServer) |
|
32 { |
|
33 CMTPPictBridgePrinter* selfP = new (ELeave) CMTPPictBridgePrinter(aServer); |
|
34 CleanupStack::PushL(selfP); |
|
35 selfP->ConstructL(); |
|
36 CleanupStack::Pop(selfP); |
|
37 return selfP; |
|
38 } |
|
39 |
|
40 // -------------------------------------------------------------------------- |
|
41 // |
|
42 // -------------------------------------------------------------------------- |
|
43 // |
|
44 void CMTPPictBridgePrinter::ConstructL() |
|
45 { |
|
46 __FLOG_OPEN(KMTPSubsystem, KPtpServerLog); |
|
47 iMsgHandlerP = CPtpReceivedMsgHandler::NewL(&iServer); |
|
48 iUsbConnectionP = CMTPPictBridgeUsbConnection::NewL(*this); |
|
49 } |
|
50 |
|
51 // -------------------------------------------------------------------------- |
|
52 // |
|
53 // -------------------------------------------------------------------------- |
|
54 // |
|
55 CMTPPictBridgePrinter::CMTPPictBridgePrinter(CPtpServer& aServer):iServer(aServer), iPrinterStatus(ENotConnected) |
|
56 { |
|
57 } |
|
58 |
|
59 // -------------------------------------------------------------------------- |
|
60 // |
|
61 // -------------------------------------------------------------------------- |
|
62 // |
|
63 CMTPPictBridgePrinter::~CMTPPictBridgePrinter() |
|
64 { |
|
65 delete iMsgHandlerP; |
|
66 delete iUsbConnectionP; |
|
67 __FLOG_CLOSE; |
|
68 } |
|
69 |
|
70 // -------------------------------------------------------------------------- |
|
71 // |
|
72 // -------------------------------------------------------------------------- |
|
73 // |
|
74 void CMTPPictBridgePrinter::ConnectionClosed() |
|
75 { |
|
76 iPrinterConnectionP=NULL; |
|
77 iPrinterStatus=ENotConnected; |
|
78 iMsgHandlerP->Initialize(); |
|
79 iServer.RemoveTemporaryObjects(); |
|
80 CancelSendDpsFile(); // we rely on the client to get notification on |
|
81 // disconnectrion from elsewhere. If not the timer |
|
82 // will expire and handle completing the message |
|
83 } |
|
84 |
|
85 // -------------------------------------------------------------------------- |
|
86 // |
|
87 // -------------------------------------------------------------------------- |
|
88 // |
|
89 CMTPPictBridgePrinter::TPrinterStatus CMTPPictBridgePrinter::Status() const |
|
90 { |
|
91 return iPrinterStatus; |
|
92 } |
|
93 |
|
94 // -------------------------------------------------------------------------- |
|
95 // |
|
96 // -------------------------------------------------------------------------- |
|
97 // |
|
98 void CMTPPictBridgePrinter::NoDpsDiscovery() |
|
99 { |
|
100 if (iPrinterStatus != EConnected) |
|
101 { |
|
102 iPrinterStatus=ENotPrinter; |
|
103 } |
|
104 else |
|
105 { |
|
106 __FLOG(_L8("WARNING! CMTPPictBridgePrinter::NoDpsDiscovery trying to say no printer even though already discovered")); |
|
107 } |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // |
|
112 // -------------------------------------------------------------------------- |
|
113 // |
|
114 void CMTPPictBridgePrinter::DpsObjectReceived(TUint32 aHandle) |
|
115 { |
|
116 __FLOG(_L8("CMTPPictBridgePrinter::DpsObjectReceived")); |
|
117 if(iPrinterStatus==EConnected) // we only handle the object when we are connected to the printer |
|
118 { |
|
119 iMsgHandlerP->ObjectReceived(aHandle); |
|
120 } |
|
121 else |
|
122 { |
|
123 __FLOG(_L8("!!!!WARNING: CMTPPictBridgePrinter::DpsObjectReceived Rx dps file when printer not connected!")); |
|
124 } |
|
125 } |
|
126 |
|
127 // -------------------------------------------------------------------------- |
|
128 // |
|
129 // -------------------------------------------------------------------------- |
|
130 // |
|
131 void CMTPPictBridgePrinter::DpsDiscovery(const TFileName& aFileName, MMTPConnection* aConnectionP) |
|
132 { |
|
133 __FLOG_VA(_L8(">> CMTPPictBridgePrinter::DpsDiscovery")); |
|
134 if ( iPrinterStatus != EConnected ) |
|
135 { |
|
136 if (KErrNotFound!=aFileName.Find(KHostDiscovery)) |
|
137 { |
|
138 __FLOG(_L8("***Dps printer Discovered.")); |
|
139 iPrinterConnectionP=aConnectionP; |
|
140 iPrinterStatus=EConnected; |
|
141 iUsbConnectionP->Listen(); |
|
142 if(iDpsPrinterNotifyCbP) |
|
143 { |
|
144 iDpsPrinterNotifyCbP->IsDpsPrinterCompleted(EPrinterAvailable); |
|
145 } |
|
146 } |
|
147 } |
|
148 __FLOG_VA((_L16("<< CMTPPictBridgePrinter::DpsDiscovery received file %S"), &aFileName)); |
|
149 } |
|
150 // -------------------------------------------------------------------------- |
|
151 // |
|
152 // -------------------------------------------------------------------------- |
|
153 // |
|
154 void CMTPPictBridgePrinter::DeRegisterDpsPrinterNotify(CPtpSession* /*aSessionP*/ ) |
|
155 { |
|
156 __FLOG(_L8(">>>CMTPPictBridgePrinter::DeRegisterDpsPrinterNotify")); |
|
157 iDpsPrinterNotifyCbP=NULL; |
|
158 __FLOG(_L8("<<<CMTPPictBridgePrinter::DeRegisterDpsPrinterNotify")); |
|
159 } |
|
160 |
|
161 // -------------------------------------------------------------------------- |
|
162 // |
|
163 // -------------------------------------------------------------------------- |
|
164 // |
|
165 void CMTPPictBridgePrinter::RegisterDpsPrinterNotify(CPtpSession* aSessionP) |
|
166 { |
|
167 __FLOG_VA((_L8(">>>CMTPPictBridgePrinter::RegisterDpsPrinterNotify 0x%x (old) 0x%x (new)"), iDpsPrinterNotifyCbP, aSessionP)); |
|
168 __ASSERT_DEBUG(iDpsPrinterNotifyCbP==NULL, User::Invariant()); |
|
169 iDpsPrinterNotifyCbP=aSessionP; |
|
170 __FLOG(_L8("<<<CMTPPictBridgePrinter::RegisterDpsPrinterNotify")); |
|
171 } |
|
172 |
|
173 |
|
174 // -------------------------------------------------------------------------- |
|
175 // CPtpEventSender::SendL() |
|
176 // Adds Object To List PTP Stack Object List,Sends RequestObjectTransfer Event |
|
177 // and registers observer for object sent notification |
|
178 // -------------------------------------------------------------------------- |
|
179 // |
|
180 void CMTPPictBridgePrinter::SendDpsFileL(const TDesC& aFile, TBool /*aTimeout*/, TInt /*aSize*/) |
|
181 { |
|
182 __FLOG_VA((_L16(">> CMTPPictBridgePrinter::SendDpsFileL %S"), &aFile)); |
|
183 |
|
184 TUint32 handle(0); |
|
185 TRAPD(err, iServer.GetObjectHandleByNameL(aFile, handle)); |
|
186 if(err!=KErrNone || handle==0) |
|
187 { |
|
188 __FLOG_VA((_L8(" Object does not exist, adding it, errorcode = %d"), err)); |
|
189 iServer.AddTemporaryObjectL(aFile, handle); |
|
190 } |
|
191 |
|
192 CreateRequestObjectTransfer(handle, iEvent); |
|
193 iServer.SendEventL(iEvent); |
|
194 iOutgoingObjectHandle=handle; |
|
195 __FLOG_VA((_L8("<< CMTPPictBridgePrinter::SendDpsFileL handle 0x%x"),iOutgoingObjectHandle)); |
|
196 } |
|
197 |
|
198 // -------------------------------------------------------------------------- |
|
199 // CPtpServer::CancelSendDpsFile() |
|
200 // Cancels Object sedn and call for deregister object sent notification |
|
201 // -------------------------------------------------------------------------- |
|
202 // |
|
203 void CMTPPictBridgePrinter::CancelSendDpsFile() |
|
204 { |
|
205 __FLOG(_L8(">>>CMTPPictBridgePrinter::CancelSendObject")); |
|
206 iOutgoingObjectHandle=0; |
|
207 __FLOG(_L8("<<<CMTPPictBridgePrinter::CancelSendObject")); |
|
208 } |
|
209 |
|
210 // -------------------------------------------------------------------------- |
|
211 // -------------------------------------------------------------------------- |
|
212 // |
|
213 TBool CMTPPictBridgePrinter::SendObjectPending() const |
|
214 { |
|
215 return (iOutgoingObjectHandle!=0); |
|
216 } |
|
217 |
|
218 // -------------------------------------------------------------------------- |
|
219 // CPtpEventSender::CreateRequestObjectTransfer |
|
220 // Creates PTP event RequestObjectTransfer |
|
221 // -------------------------------------------------------------------------- |
|
222 // |
|
223 void CMTPPictBridgePrinter::CreateRequestObjectTransfer(TUint32 aHandle, |
|
224 TMTPTypeEvent& aEvent ) |
|
225 { |
|
226 __FLOG_VA((_L8("CMTPPictBridgePrinter::CreateRequestEventTransfer for 0x%x"), aHandle)); |
|
227 |
|
228 aEvent.Reset(); |
|
229 |
|
230 aEvent.SetUint16(TMTPTypeEvent::EEventCode, EMTPEventCodeRequestObjectTransfer); |
|
231 aEvent.SetUint32(TMTPTypeEvent::EEventSessionID, KMTPSessionAll); |
|
232 aEvent.SetUint32(TMTPTypeEvent::EEventTransactionID, KMTPNotSpecified32); |
|
233 |
|
234 aEvent.SetUint32(TMTPTypeEvent::EEventParameter1, aHandle); |
|
235 aEvent.SetUint32(TMTPTypeEvent::EEventParameter2, KPtpNoValue); |
|
236 aEvent.SetUint32(TMTPTypeEvent::EEventParameter3, KPtpNoValue); |
|
237 } |
|
238 |
|
239 // -------------------------------------------------------------------------- |
|
240 // CPtpServer::ObjectReceived |
|
241 // Notifies of object received |
|
242 // -------------------------------------------------------------------------- |
|
243 // |
|
244 void CMTPPictBridgePrinter::ObjectReceived(TDes& aFile) |
|
245 { |
|
246 __FLOG(_L8("CMTPPictBridgePrinter::ObjectReceived")); |
|
247 iObserverP->ReceivedObjectCompleted(aFile); |
|
248 } |
|
249 |
|
250 // -------------------------------------------------------------------------- |
|
251 // -------------------------------------------------------------------------- |
|
252 // |
|
253 void CMTPPictBridgePrinter::DpsFileSent(TInt aError) |
|
254 { |
|
255 __FLOG_VA((_L8("CMTPPictBridgePrinter::DpsFileSent error %d handle 0x%x"), aError, iOutgoingObjectHandle)); |
|
256 if( SendObjectPending() ) |
|
257 { |
|
258 iObserverP->SendObjectCompleted(aError); |
|
259 iOutgoingObjectHandle=0; |
|
260 } |
|
261 } |
|
262 |
|
263 // -------------------------------------------------------------------------- |
|
264 // -------------------------------------------------------------------------- |
|
265 // |
|
266 void CMTPPictBridgePrinter::RegisterObserver(MServiceHandlerObserver* aObserverP) |
|
267 { |
|
268 iObserverP = aObserverP; |
|
269 } |
|
270 |
|
271 MMTPConnection* CMTPPictBridgePrinter::ConnectionP() const |
|
272 { |
|
273 return iPrinterConnectionP; |
|
274 } |
|
275 |
|
276 CPtpReceivedMsgHandler* CMTPPictBridgePrinter::MsgHandlerP() const |
|
277 { |
|
278 return iMsgHandlerP; |
|
279 } |