|
1 // Copyright (c) 2001-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 // $Workfile: btsendop.cpp $ |
|
15 // $Author: Stevep $ |
|
16 // $Revision: 10 $ |
|
17 // $Date: 25/03/02 9:32 $ |
|
18 // |
|
19 // |
|
20 |
|
21 //class include |
|
22 #include "btsendop.h" |
|
23 |
|
24 //system includes |
|
25 #include <btmsgtypeuid.h> //KUidMsgTypeBt |
|
26 #include "btmtmcmds.h" //EBtMtmCmdSend |
|
27 //#include <bttypes.h> |
|
28 |
|
29 //user includes |
|
30 //#include "btcmtm.h" //EBtcCmdSend |
|
31 //#include "btmsgtypeuid.h" //KUidMsgTypeBt |
|
32 |
|
33 const TInt KPacketBufferSize=20000; // Packet buffer size |
|
34 |
|
35 CBtServerSendOperation* CBtServerSendOperation::NewL(CMsvServerEntry& aSendObj, const TObexBluetoothProtocolInfo& aBtProtocolInfo, TInt aConnectTimeoutMicroSeconds, TInt aPutTimeoutMicroseconds, const TDesC* aConnectPassword, TRequestStatus& aObserverRequestStatus) |
|
36 /** |
|
37 * Second phase constructor. |
|
38 * |
|
39 * @param aSendObj Reference to the object to send. |
|
40 * @param aBtProtocolInfo Protocol info to initialise the CObexCleint |
|
41 * @param aConnectTimeoutMicroSeconds Timeout period for Connect operation in microseconds. |
|
42 * @param aPutTimeoutMicroseconds Timeout period for Put operation in microseconds. |
|
43 * @param aConnectPassword Pointer to the password for Bluetooth validation. |
|
44 * @param aObserverRequestStatus Canonical TRequestStatus for control of active object. |
|
45 * @leave KErrXXX System-wide error codes |
|
46 */ |
|
47 { |
|
48 CBtServerSendOperation* self=new(ELeave) CBtServerSendOperation(aSendObj, aBtProtocolInfo, aConnectTimeoutMicroSeconds, aPutTimeoutMicroseconds, aObserverRequestStatus); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(aConnectPassword); |
|
51 CleanupStack::Pop(); //self |
|
52 return self; |
|
53 } |
|
54 |
|
55 CBtServerSendOperation::CBtServerSendOperation(CMsvServerEntry& aSendObj, const TObexBluetoothProtocolInfo& aBtProtocolInfo, TInt aConnectTimeoutMicroSeconds, TInt aPutTimeoutMicroSeconds, TRequestStatus& aObserverRequestStatus) |
|
56 :CObexServerSendOperation(KUidMsgTypeBt, aSendObj, aConnectTimeoutMicroSeconds, aPutTimeoutMicroSeconds, aObserverRequestStatus), |
|
57 iBtProtocolInfo(aBtProtocolInfo),iBTObexPortNumber(0) //default bitwise copy constructor should suffice |
|
58 /** |
|
59 * Constructor. |
|
60 * |
|
61 * @param aSendObj Reference to the object to send. |
|
62 * @param aBtProtocolInfo Protocol info to initialise the CObexCleint |
|
63 * @param aConnectTimeoutMicroSeconds Timeout period for Connect operation in microseconds. |
|
64 * @param aPutTimeoutMicroseconds Timeout period for Put operation in microseconds. |
|
65 * @param aConnectPassword Pointer to the password for Bluetooth validation. |
|
66 * @param aTargetID Unsigned Int32 containing target ID if present. |
|
67 * @param aSendTargetID TBool for flag to send target ID or not. |
|
68 * @param aObserverRequestStatus Canonical TRequestStatus for control of active object. |
|
69 */ |
|
70 { |
|
71 } |
|
72 |
|
73 CBtServerSendOperation::~CBtServerSendOperation() |
|
74 { |
|
75 delete iSdpUtils; |
|
76 |
|
77 iLinkAdapter.Close(); |
|
78 iSocketServ.Close(); |
|
79 } |
|
80 |
|
81 void CBtServerSendOperation::InitialiseObexClientL() |
|
82 /** |
|
83 * Initialises the Obex client to use Bluetooth as the transport mechanism with the parameters as specified in the |
|
84 * constructor. |
|
85 * |
|
86 * @leave KErrXXX System-wide error codes |
|
87 */ |
|
88 |
|
89 { |
|
90 //Prevent the link from going into low power modes before the SDP query takes place. |
|
91 PreventLowPowerModes(); |
|
92 |
|
93 // trigger SDP Lookup |
|
94 iSdpUtils = CObexSdpUtils::NewL(*this); |
|
95 |
|
96 User::LeaveIfError(iSdpUtils != NULL); |
|
97 |
|
98 TBTDevAddr devAddr = iBtProtocolInfo.iAddr.BTAddr(); |
|
99 iSdpUtils->RemoteBtObexQueryL(devAddr); |
|
100 |
|
101 // tell the obex server module we're async |
|
102 iAsyncInit = ETrue; |
|
103 } |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 void CBtServerSendOperation::RemoteBtObexQueryResult(TInt aError, TInt aPortNumber, TBool /*aObexObjectPushProfileSupported*/, |
|
109 TInt /*aObexObjectPushProfileVersion*/, TObexSupportedFormatsList /*aSupportedFormats*/) |
|
110 /** |
|
111 * SDP Query result, parameters have the following meaning: |
|
112 * |
|
113 * @param aError If this is anything but KErrNone then the query has not completed correctly and all other parameters are meaningless. |
|
114 * @param aPortNumber - The RFCOMM port number that the remote device supports OBEX on |
|
115 * @param aObexObjectPushProfileSupported - ETrue if the remote device supports the Bluetooth OBEX Push Profile |
|
116 * @param aObexObjectPushProfileVersion - Version of Bluetooth OBEX Push Profile supported (only valid if aObexObjectPushProfileSupported == ETrue) |
|
117 * @param aSupportedFormats - Structure containing a list of the OBEX Object formats supported by the remote device |
|
118 */ |
|
119 { |
|
120 |
|
121 if(aError) |
|
122 { |
|
123 // finish the async init at this point |
|
124 TRequestStatus* status = &iStatus; |
|
125 User::RequestComplete(status, aError); |
|
126 } |
|
127 else |
|
128 { |
|
129 // remember the port number |
|
130 iBTObexPortNumber = aPortNumber; |
|
131 |
|
132 // finish the async init at this point |
|
133 TRequestStatus* status = &iStatus; |
|
134 User::RequestComplete(status, KErrNone); |
|
135 } |
|
136 } |
|
137 |
|
138 void CBtServerSendOperation::SecondPhaseObexClientInitL() |
|
139 /** |
|
140 * Fills in the iBtProtocolInfo structure with the results of the SDP Lookup. |
|
141 */ |
|
142 { |
|
143 delete iSdpUtils; |
|
144 iSdpUtils = NULL; |
|
145 |
|
146 // use the port number to complete initialisation |
|
147 TRfcommSockAddr& sockAddr = iBtProtocolInfo.iAddr; |
|
148 sockAddr.SetPort(iBTObexPortNumber); |
|
149 |
|
150 // setting of receive & transmit packet buffer size. |
|
151 TObexProtocolPolicy obexProtocolPolicy; |
|
152 obexProtocolPolicy.SetReceiveMtu(KPacketBufferSize); |
|
153 obexProtocolPolicy.SetTransmitMtu(KPacketBufferSize); |
|
154 |
|
155 // Initialise Obex client object. |
|
156 iObexClient = CObexClient::NewL(iBtProtocolInfo,obexProtocolPolicy); |
|
157 } |
|
158 |
|
159 void CBtServerSendOperation::PreConnectOperations() |
|
160 { |
|
161 } |
|
162 |
|
163 void CBtServerSendOperation::PostConnectOperations() |
|
164 { |
|
165 // If the connection attempt has failed and we are not going to retry the connection, |
|
166 // make sure that the link is allowed to go into low power modes. |
|
167 |
|
168 const TDesC8* progressDes; |
|
169 TRAPD(error, progressDes = &ProgressL()); |
|
170 |
|
171 if (error == KErrNone) |
|
172 { |
|
173 TPckgBuf<TObexMtmProgress> package; |
|
174 package.Copy(*progressDes); |
|
175 |
|
176 if (package().iSendState == TObexMtmProgress::ESendError) |
|
177 { |
|
178 AllowLowPowerModes(); |
|
179 } |
|
180 } |
|
181 } |
|
182 |
|
183 void CBtServerSendOperation::PreSendOperations() |
|
184 { |
|
185 // Try to ensure the link does not go into a low power mode. |
|
186 // Note that we may already be preventing low power modes as a result of attempting |
|
187 // to do this prior to the connection setup. In this case, calling it again does |
|
188 // nothing. |
|
189 // Note that as the obex connection is setup, this should not fail. If for some reason |
|
190 // it does, this would result in a slower file transfer. |
|
191 PreventLowPowerModes(); |
|
192 } |
|
193 |
|
194 void CBtServerSendOperation::PostSendOperations() |
|
195 { |
|
196 // Allow the link to go into low power modes |
|
197 AllowLowPowerModes(); |
|
198 } |
|
199 |
|
200 void CBtServerSendOperation::DoCancel() |
|
201 { |
|
202 // As the transfer is being cancelled, allow the link to go into low power modes |
|
203 AllowLowPowerModes(); |
|
204 |
|
205 delete iSdpUtils; |
|
206 iSdpUtils = NULL; |
|
207 |
|
208 CObexServerSendOperation::DoCancel(); |
|
209 } |
|
210 |
|
211 void CBtServerSendOperation::AllowLowPowerModes() |
|
212 { |
|
213 // Allow the link to go into low power modes |
|
214 if (iPreventingLowPowerModes) |
|
215 { |
|
216 iLinkAdapter.AllowLowPowerModes(EAnyLowPowerMode); |
|
217 iPreventingLowPowerModes = EFalse; |
|
218 } |
|
219 |
|
220 iLinkAdapter.Close(); |
|
221 iSocketServ.Close(); |
|
222 } |
|
223 |
|
224 void CBtServerSendOperation::PreventLowPowerModes() |
|
225 { |
|
226 // Prevent the link from going into low power modes. This means the connect and send |
|
227 // operations will be much quicker. |
|
228 |
|
229 if (iPreventingLowPowerModes) |
|
230 { |
|
231 return; |
|
232 } |
|
233 |
|
234 // Connect to the socket server |
|
235 if (!iSocketServ.Handle()) |
|
236 { |
|
237 if (iSocketServ.Connect() != KErrNone) |
|
238 { |
|
239 return; |
|
240 } |
|
241 } |
|
242 |
|
243 // Open the bluetooth link adapter |
|
244 if (!iLinkAdapter.IsOpen()) |
|
245 { |
|
246 TBTDevAddr devAddr = iBtProtocolInfo.iAddr.BTAddr(); |
|
247 |
|
248 if (iLinkAdapter.Open(iSocketServ, devAddr) != KErrNone) |
|
249 { |
|
250 return; |
|
251 } |
|
252 } |
|
253 |
|
254 if (iLinkAdapter.PreventLowPowerModes(EAnyLowPowerMode) == KErrNone) |
|
255 { |
|
256 iPreventingLowPowerModes = ETrue; |
|
257 } |
|
258 } |