|
1 /* |
|
2 * Copyright (c) 2004-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CBTOBJECTSERVER_H |
|
20 #define CBTOBJECTSERVER_H |
|
21 |
|
22 #include <coecntrl.h> |
|
23 #include <obexserver.h> |
|
24 #include <bttypes.h> |
|
25 #include <obexobjects.h> |
|
26 |
|
27 #include "cxhtmlfilecomposer.h" |
|
28 #include "btprotocolconsts.h" |
|
29 #include "cbtdprserviceadvertiser.h" |
|
30 |
|
31 |
|
32 /** |
|
33 * MBtObjectServerObserver |
|
34 * |
|
35 * @brief Interface to observe bluetooth object server's state |
|
36 */ |
|
37 class MBtObjectServerObserver |
|
38 { |
|
39 public: |
|
40 enum TStatusMessages |
|
41 { |
|
42 KObjectServerPackageSent = 10, ///@brief a requested chunk of data sent |
|
43 KObjectServerFileSent, ///@brief a requested file sent |
|
44 KObjectServerAllFilesSent, ///@brief not used... cannot know when done! |
|
45 KObjectServerStopped, ///@brief server stopped |
|
46 KObjectServerStarted, ///@brief server started |
|
47 KObjectServerBTDeviceMismatch, ///@brief remote device isn't correct |
|
48 KObjectServerConnected, ///@brief remote device connected |
|
49 KObjectServerDisconnected, ///@brief remote device disconnected |
|
50 KObjectServerTransportUp, ///@brief transportation up with remote device |
|
51 KObjectServerTransportDown, ///@brief transportation down with remote device |
|
52 KObjectServerError ///@brief Error indication for any occured error |
|
53 }; |
|
54 |
|
55 public: |
|
56 |
|
57 /** |
|
58 * OperationStatus |
|
59 * |
|
60 * A callback function to observe bluetooth object server's state |
|
61 * @param aStatus TStatusMessages status or error code occured |
|
62 * @param aInfo Explaining information of the status |
|
63 */ |
|
64 virtual void HandleObjectServerEvent(TInt aStatus, TInt aInfo = 0) = 0; |
|
65 }; |
|
66 /*! |
|
67 @class CBtObjectServer |
|
68 |
|
69 @discussion An instance of the Obex File Server object for the obexfileserver |
|
70 example application |
|
71 */ |
|
72 NONSHARABLE_CLASS(CBtObjectServer) : public CBase, public MObexServerNotify |
|
73 { |
|
74 public: |
|
75 |
|
76 /** |
|
77 * NewL() |
|
78 * Construct a CBtObjectServer |
|
79 * @param aDevice Device (printer) which should be contacted over Bluetooth |
|
80 * @param aImgArray Images that will be sent over OBEX (if printer asks them) |
|
81 * @return a pointer to the created instance of CBtObjectServer |
|
82 */ |
|
83 static CBtObjectServer* NewL(const TBTDevAddr& aDeviceAddress, RArray<CImageInfo> &aImgArray, MBtObjectServerObserver& aObs); |
|
84 |
|
85 /** |
|
86 * NewLC() |
|
87 * Construct a CBtObjectServer |
|
88 * @param aDevice Device which should be contacted over Bluetooth |
|
89 * @param aImgArray Images that will be sent over OBEX (if printer asks them) |
|
90 * @return a pointer to the created instance of CBtObjectServer |
|
91 */ |
|
92 static CBtObjectServer* NewLC(const TBTDevAddr& aDeviceAddress, RArray<CImageInfo> &aImgArray, MBtObjectServerObserver& aObs); |
|
93 |
|
94 /** |
|
95 * ~CBtObjectServer() |
|
96 * Destructor for the class |
|
97 */ |
|
98 ~CBtObjectServer(); |
|
99 |
|
100 /** |
|
101 * CreateObexObject() |
|
102 * For creating an OBEX object that will be send through bluetooth |
|
103 */ |
|
104 CObexBufObject* CreateObexObjectL(const TDesC& aUri); |
|
105 |
|
106 /** |
|
107 * StartL() |
|
108 * Starts the server |
|
109 */ |
|
110 void StartL(); |
|
111 |
|
112 /** |
|
113 * Stop() |
|
114 * Stops the server |
|
115 */ |
|
116 void Stop(); |
|
117 |
|
118 /** |
|
119 * Cancel() |
|
120 * For stopping server action nicely - will continue to send the current file to |
|
121 * the BT device |
|
122 */ |
|
123 void Cancel(); |
|
124 |
|
125 |
|
126 /** |
|
127 * IsConnected() |
|
128 * @return ETrue if the server is connected. |
|
129 */ |
|
130 TBool IsConnected(); |
|
131 |
|
132 /** |
|
133 * IsTransporting() |
|
134 * @return ETrue if the transport connection is up. |
|
135 */ |
|
136 TBool IsTransporting(); |
|
137 |
|
138 /** |
|
139 * IsSendingData() |
|
140 * @return ETrue if the server is sending data to a Bluetooth device |
|
141 */ |
|
142 TBool IsSendingData(); |
|
143 |
|
144 /** |
|
145 * IsFinished() |
|
146 * @return ETrue if the server is finished and can be deleted |
|
147 */ |
|
148 TBool IsFinished(); |
|
149 |
|
150 protected: |
|
151 |
|
152 /** |
|
153 * ConstructL() |
|
154 * Method that constucts the classes possibly leaving parts |
|
155 */ |
|
156 void ConstructL( RArray<CImageInfo> &aImgArray ); |
|
157 |
|
158 |
|
159 private: |
|
160 |
|
161 /** |
|
162 * CBtObjectServer() |
|
163 * @param aDevice Device (printer) which should be contacted over Bluetooth |
|
164 * @param aImgArray Images that will be sent over OBEX (if printer asks them) |
|
165 * Private constructor |
|
166 */ |
|
167 CBtObjectServer( const TBTDevAddr& aDeviceAddress, MBtObjectServerObserver& aObs ); |
|
168 |
|
169 /** |
|
170 * InitialiseServerL |
|
171 * Initialises the server |
|
172 */ |
|
173 void InitialiseServerL(); |
|
174 |
|
175 /** |
|
176 * InitTransferData |
|
177 * Initialises the data used to transfer and process a file |
|
178 */ |
|
179 void InitTransferData(); |
|
180 |
|
181 /** |
|
182 * InitHeaderVariables |
|
183 * Initialises the requested header data members |
|
184 */ |
|
185 void InitHeaderVariables(); |
|
186 |
|
187 TBool AllowConnection(); |
|
188 |
|
189 /** |
|
190 * HandleGetRequestL |
|
191 * Method to go through to trap leaves for GetRequestIndication |
|
192 */ |
|
193 CObexBufObject* HandleGetRequestL( CObexBaseObject* aRequestedObject ); |
|
194 |
|
195 void GetAppHeaderL(CObexBaseObject* aRequestedObject); |
|
196 void GetDataSequenceL(const TFileName& aFileName, TInt& aFileSize); |
|
197 void SetCompleted(); |
|
198 |
|
199 /** |
|
200 * SetSecurityWithChannelL |
|
201 * Sets the security on the channel port |
|
202 * And returns the channel available. |
|
203 * @param aAuthentication is authentication used |
|
204 * @param aEncryption is encryption used |
|
205 * @param aAuthorisation is authorisation used |
|
206 * @param aDenied is denied used |
|
207 * @return an available channel |
|
208 */ |
|
209 TInt SetSecurityWithChannelL ( TBool aAuthentication, |
|
210 TBool aEncryption, |
|
211 TBool aAuthorisation, |
|
212 TBool aDenied ); |
|
213 private: |
|
214 |
|
215 /** |
|
216 * Following private methods implement the MObexServerNotify class |
|
217 * - these methods (together with CObexServer) implement the observer |
|
218 * for the OBEX data handling |
|
219 * - Methods are called every time server receives something over the bluetooth |
|
220 */ |
|
221 |
|
222 /** |
|
223 * ErrorIndication |
|
224 * Receive error indication |
|
225 * @param aError the error code |
|
226 */ |
|
227 void ErrorIndication( TInt aError ); |
|
228 |
|
229 /** |
|
230 * TransportUpIndication |
|
231 * Called when the underlying socket transport connection is made from |
|
232 * a remote client to the server |
|
233 */ |
|
234 void TransportUpIndication(); |
|
235 |
|
236 /** |
|
237 * TransportDownIndication |
|
238 * Transport connection is dropped |
|
239 */ |
|
240 void TransportDownIndication(); |
|
241 |
|
242 /** |
|
243 * ObexConnectIndication |
|
244 * Invoked when an OBEX connection is made from a remote client |
|
245 * @param aRemoteInfo connection information supplied by |
|
246 * the remote machine |
|
247 * @param aInfo holds further information about the |
|
248 * requested connection |
|
249 * @return system wide error code |
|
250 */ |
|
251 TInt ObexConnectIndication( const TObexConnectInfo& aRemoteInfo, |
|
252 const TDesC8& aInfo ); |
|
253 |
|
254 /** |
|
255 * ObexDisconnectIndication |
|
256 * OBEX server has been disconnected |
|
257 * @param aInfo contains information about the disconnection |
|
258 */ |
|
259 void ObexDisconnectIndication( const TDesC8& aInfo ); |
|
260 |
|
261 /** |
|
262 * PutRequestIndication |
|
263 * @return the CObexBufObject in which to store |
|
264 * the transferred object |
|
265 */ |
|
266 CObexBufObject* PutRequestIndication(); |
|
267 |
|
268 /** |
|
269 * PutPacketIndication |
|
270 * @return system wide error code |
|
271 */ |
|
272 TInt PutPacketIndication(); |
|
273 |
|
274 /** |
|
275 * PutCompleteIndication |
|
276 * @return system wide error code |
|
277 */ |
|
278 TInt PutCompleteIndication(); |
|
279 |
|
280 /** |
|
281 * GetRequestIndication |
|
282 * Called when a full get request has been received from the client |
|
283 * @param aRequestedObject holds details about the requested object |
|
284 * @return the CObexBufObject in which return to the client |
|
285 */ |
|
286 CObexBufObject* GetRequestIndication( CObexBaseObject* |
|
287 aRequestedObject ); |
|
288 |
|
289 /** |
|
290 * GetPacketIndication |
|
291 * @return system wide error code |
|
292 */ |
|
293 TInt GetPacketIndication(); |
|
294 |
|
295 /** |
|
296 * GetCompleteIndication |
|
297 * @return system wide error code |
|
298 */ |
|
299 TInt GetCompleteIndication(); |
|
300 |
|
301 /** |
|
302 * SetPathIndication |
|
303 * @param aPathInfo the information received in a SETPATH command |
|
304 * @return system wide error code |
|
305 */ |
|
306 TInt SetPathIndication( const CObex::TSetPathInfo& aPathInfo, |
|
307 const TDesC8& aInfo ); |
|
308 |
|
309 /** |
|
310 * AbortIndication |
|
311 * Server has been aborted |
|
312 */ |
|
313 void AbortIndication(); |
|
314 |
|
315 /** |
|
316 * End of the Obex Observer methods |
|
317 * |
|
318 */ |
|
319 |
|
320 private: |
|
321 |
|
322 /** |
|
323 * State of the server |
|
324 * Owned by CBtObjectServer |
|
325 */ |
|
326 enum TServerState |
|
327 { |
|
328 EStateDisconnected = 0, |
|
329 EStateConnected, |
|
330 EStateStop |
|
331 }; |
|
332 |
|
333 /** |
|
334 * Current operation of the server |
|
335 * Owned by CBtObjectServer |
|
336 */ |
|
337 enum TServerOperation |
|
338 { |
|
339 ETerminating = 0, |
|
340 ESending, |
|
341 EIdle |
|
342 }; |
|
343 |
|
344 /** |
|
345 * The bluetooth device where the images will be sent |
|
346 * Owned by CBtObjectServer |
|
347 */ |
|
348 const TBTDevAddr& iAllowedAddress; |
|
349 |
|
350 /** |
|
351 * The bluetooth device requested the data |
|
352 * Owned by CBtObjectServer |
|
353 */ |
|
354 TBTDevAddr iRemoteAddress; |
|
355 |
|
356 /** |
|
357 * The images that will be printed if printer asks for them |
|
358 * Owned by CBtObjectServer |
|
359 */ |
|
360 RArray<CImageInfo> iImgArray; |
|
361 |
|
362 MBtObjectServerObserver& iObs; |
|
363 |
|
364 /** |
|
365 * iObexServer manages the OBEX client connection |
|
366 * Owned by CBtObjectServer |
|
367 */ |
|
368 CObexServer* iObexServer; |
|
369 |
|
370 /** |
|
371 * iObexBufData the raw data that has been transferred |
|
372 * Owned by CBtObjectServer |
|
373 */ |
|
374 CBufFlat* iObexBody; |
|
375 |
|
376 /** |
|
377 * iCurrObject the OBEX object that has been transferred |
|
378 * Owned by CBtObjectServer |
|
379 */ |
|
380 CObexBufObject* iObexBufObject; |
|
381 |
|
382 /** |
|
383 * iAdvertiser used to advertise this service |
|
384 * Owned by CBtObjectServer |
|
385 */ |
|
386 CBtDprServiceAdvertiser* iAdvertiser; |
|
387 |
|
388 /** |
|
389 * Current operation |
|
390 */ |
|
391 TServerOperation iOperation; |
|
392 |
|
393 RFs iFs; |
|
394 |
|
395 TBool iStarted; |
|
396 TBool iConnected; |
|
397 TBool iTransportUp; |
|
398 |
|
399 TUint iOffset; |
|
400 TInt iCount; |
|
401 TInt iSize; |
|
402 TInt iProgress; // proggress in percents of currently printed file |
|
403 |
|
404 }; |
|
405 |
|
406 #endif // CBTOBJECTSERVER_H |
|
407 |
|
408 // End of File |