|
1 /* |
|
2 * Copyright (c) 2002 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: Server part of basic printing profile |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "BTServiceUtils.h" |
|
22 #include "BTSBPPObjectServer.h" |
|
23 #include "BTSBPPObjectRequest.h" |
|
24 #include "BTSUDebug.h" |
|
25 |
|
26 // CONSTANTS |
|
27 const TInt KBTSBPPObjectChannelStart = 15; // Start looking for free RFCOMM channel |
|
28 const TInt KBTSBPPObjectChannelStop = 30; // Last free RFCOMM channel |
|
29 |
|
30 _LIT8( KBTSBPPReferencedObjectsUUID, "\x00\x00\x11\x20\x00\x00\x10\x00\x80\x00\x00\x80\x5F\x9B\x34\xFB" ); |
|
31 |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CBTSBPPObjectServer::CBTSBPPObjectServer |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CBTSBPPObjectServer::CBTSBPPObjectServer( |
|
42 MBTSBPPObjectServerObserver* aObserver, CBTEngDiscovery* aBTEngDiscoveryPtr, |
|
43 const TBTDevAddr& aExpectedClient ) : iExpectedClientPtr( &aExpectedClient ), |
|
44 iBTEngDiscoveryPtr( aBTEngDiscoveryPtr ), |
|
45 iObserverPtr( aObserver ) |
|
46 { |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CBTSBPPObjectServer::ConstructL |
|
51 // Symbian 2nd phase constructor can leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void CBTSBPPObjectServer::ConstructL() |
|
55 { |
|
56 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::ConstructL()")); |
|
57 |
|
58 __ASSERT_DEBUG( iObserverPtr != NULL, BTSUPanic( EBTSUPanicNullPointer ) ); |
|
59 __ASSERT_DEBUG( iBTEngDiscoveryPtr != NULL, BTSUPanic( EBTSUPanicNullPointer ) ); |
|
60 __ASSERT_DEBUG( iExpectedClientPtr != NULL, BTSUPanic( EBTSUPanicNullPointer ) ); |
|
61 |
|
62 TObexBluetoothProtocolInfo info; |
|
63 info.iTransport = KBTSProtocol; |
|
64 |
|
65 iObjectChannel = KBTSBPPObjectChannelStart; |
|
66 for ( ; iObjectChannel < KBTSBPPObjectChannelStop; iObjectChannel++ ) |
|
67 { |
|
68 // Register security settings |
|
69 // |
|
70 TBTServiceSecurity sec; |
|
71 sec.SetAuthentication( EFalse ); |
|
72 sec.SetAuthorisation( EFalse ); |
|
73 sec.SetEncryption( EFalse ); |
|
74 |
|
75 info.iAddr.SetSecurity( sec ); |
|
76 info.iAddr.SetPort( iObjectChannel ); |
|
77 |
|
78 // Try to start Obex Server on selected channel |
|
79 // |
|
80 TRAPD( error, iServer = CObexServer::NewL ( info ) ); |
|
81 |
|
82 if ( !error ) |
|
83 { |
|
84 error = iServer->Start( this ); |
|
85 |
|
86 if ( !error ) |
|
87 { |
|
88 // Initialize server |
|
89 // |
|
90 iServer->SetCallBack( *this ); |
|
91 User::LeaveIfError ( iServer->SetLocalWho( KBTSBPPReferencedObjectsUUID ) ); |
|
92 |
|
93 // Register SDP settings |
|
94 // |
|
95 User::LeaveIfError ( iBTEngDiscoveryPtr->RegisterSdpRecord( |
|
96 TUUID(KBTSdpBasicPrinting), iObjectChannel, iSDPHandle )); |
|
97 |
|
98 FTRACE(FPrint(_L("[BTSU]\t CBTSBPPObjectServer::ConstructL() services running on channel %d"), iObjectChannel )); |
|
99 break; |
|
100 } |
|
101 else |
|
102 { |
|
103 // Failed to start Obex server. Delete server and try again |
|
104 // |
|
105 delete iServer; |
|
106 iServer = NULL; |
|
107 } |
|
108 } |
|
109 } |
|
110 |
|
111 if ( !iServer ) |
|
112 { |
|
113 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::ConstructL() ERROR, server did not start.")); |
|
114 User::Leave( KErrGeneral ); |
|
115 } |
|
116 |
|
117 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::ConstructL() completed")); |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CBTSBPPObjectServer::NewL |
|
122 // Two-phased constructor. |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 CBTSBPPObjectServer* CBTSBPPObjectServer::NewL( |
|
126 MBTSBPPObjectServerObserver* aObserver, CBTEngDiscovery* aBTEngDiscoveryPtr, |
|
127 const TBTDevAddr& aExpectedClient ) |
|
128 { |
|
129 CBTSBPPObjectServer* self = new( ELeave ) |
|
130 CBTSBPPObjectServer( aObserver, aBTEngDiscoveryPtr, aExpectedClient ); |
|
131 CleanupStack::PushL( self ); |
|
132 self->ConstructL(); |
|
133 CleanupStack::Pop(); |
|
134 return self; |
|
135 } |
|
136 |
|
137 |
|
138 // Destructor |
|
139 CBTSBPPObjectServer::~CBTSBPPObjectServer() |
|
140 { |
|
141 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::~CBTSBPPObjectServer()")); |
|
142 |
|
143 if ( iServer ) |
|
144 { |
|
145 iServer->Stop(); |
|
146 delete iServer; |
|
147 iServer = NULL; |
|
148 } |
|
149 |
|
150 delete iObjectRequest; |
|
151 //delete iPasskeyRequest; |
|
152 |
|
153 if ( iBTEngDiscoveryPtr ) |
|
154 { |
|
155 iBTEngDiscoveryPtr->DeleteSdpRecord( iSDPHandle ); |
|
156 } |
|
157 |
|
158 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::~CBTSBPPObjectServer() completed")); |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CBTSBPPObjectServer::SetReferencedObjectList |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 void CBTSBPPObjectServer::SetReferencedObjectList( const CDesCArray* aRefObjectList ) |
|
166 { |
|
167 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::SetReferencedObjectList()")); |
|
168 |
|
169 __ASSERT_DEBUG( aRefObjectList != NULL, BTSUPanic( EBTSUPanicNullPointer ) ); |
|
170 |
|
171 iObjectListPtr = aRefObjectList; |
|
172 |
|
173 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::SetReferencedObjectList() completed")); |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CBTSBPPObjectServer::HasReferencedObjects |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 TBool CBTSBPPObjectServer::HasReferencedObjects() |
|
181 { |
|
182 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::HasReferencedObjects()")); |
|
183 __ASSERT_DEBUG( iObjectListPtr != NULL, BTSUPanic( EBTSUPanicNullPointer ) ); |
|
184 |
|
185 return iObjectListPtr->MdcaCount() > 0; |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CBTSBPPObjectServer::GetUserPasswordL |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 void CBTSBPPObjectServer::GetUserPasswordL( const TDesC& /*aRealm*/ ) |
|
193 { |
|
194 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::GetUserPasswordL() NOT NEEDED")); |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CBTSBPPObjectServer::ErrorIndication |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CBTSBPPObjectServer::ErrorIndication( TInt aError ) |
|
202 { |
|
203 FTRACE(FPrint(_L("[BTSU]\t CBTSBPPObjectServer::ErrorIndication() error %d"), aError )); |
|
204 |
|
205 iObserverPtr->ServerError( aError ); |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CBTSBPPObjectServer::TransportUpIndication |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void CBTSBPPObjectServer::TransportUpIndication() |
|
213 { |
|
214 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::TransportUpIndication()")); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CBTSBPPObjectServer::TransportDownIndication |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 void CBTSBPPObjectServer::TransportDownIndication() |
|
222 { |
|
223 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::TransportDownIndication()")); |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CBTSBPPObjectServer::ObexConnectIndication |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 TInt CBTSBPPObjectServer::ObexConnectIndication( |
|
231 const TObexConnectInfo& /*aRemoteInfo*/, const TDesC8& /*aInfo*/ ) |
|
232 { |
|
233 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::ObexConnectIndication()")); |
|
234 |
|
235 TInt error = KErrAccessDenied; |
|
236 |
|
237 // Check that remote device is the expected one. |
|
238 // |
|
239 TBTSockAddr remoteAddr; |
|
240 iServer->RemoteAddr( remoteAddr ); |
|
241 if ( remoteAddr.BTAddr() == *iExpectedClientPtr ) |
|
242 { |
|
243 error = KErrNone; |
|
244 iObserverPtr->ServerConnectionEstablished(); |
|
245 } |
|
246 |
|
247 FTRACE(FPrint(_L("[BTSU]\t CBTSBPPObjectServer::ObexConnectIndication() completed with %d"), error )); |
|
248 return error; |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CBTSBPPObjectServer::ObexDisconnectIndication |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CBTSBPPObjectServer::ObexDisconnectIndication( const TDesC8& /*aInfo*/ ) |
|
256 { |
|
257 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::ObexDisconnectIndication()")); |
|
258 |
|
259 iObserverPtr->ServerConnectionClosed(); |
|
260 |
|
261 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::ObexDisconnectIndication() completed")); |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CBTSBPPObjectServer::PutRequestIndication |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 CObexBufObject* CBTSBPPObjectServer::PutRequestIndication() |
|
269 { |
|
270 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::PutRequestIndication()")); |
|
271 |
|
272 return NULL; |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CBTSBPPObjectServer::PutPacketIndication |
|
277 // ----------------------------------------------------------------------------- |
|
278 // |
|
279 TInt CBTSBPPObjectServer::PutPacketIndication() |
|
280 { |
|
281 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::PutPacketIndication()")); |
|
282 |
|
283 return KErrNotSupported; |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CBTSBPPObjectServer::PutCompleteIndication |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 TInt CBTSBPPObjectServer::PutCompleteIndication() |
|
291 { |
|
292 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::PutCompleteIndication()")); |
|
293 |
|
294 return KErrNotSupported; |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CBTSBPPObjectServer::GetRequestIndication |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 CObexBufObject* CBTSBPPObjectServer::GetRequestIndication( |
|
302 CObexBaseObject* aRequiredObject ) |
|
303 { |
|
304 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::GetRequestIndication()")); |
|
305 __ASSERT_DEBUG( iObjectRequest == NULL, BTSUPanic( EBTSUPanicExistingObject ) ); |
|
306 |
|
307 TInt error = KErrNone; |
|
308 CObexBufObject* object = NULL; |
|
309 |
|
310 TRAP( error, iObjectRequest = CBTSBPPObjectRequest::NewL( aRequiredObject, iObjectListPtr ) ); |
|
311 |
|
312 if ( !error ) |
|
313 { |
|
314 object = iObjectRequest->GetResponse(); |
|
315 } |
|
316 |
|
317 FTRACE(FPrint(_L("[BTSU]\t CBTSBPPObjectServer::GetRequestIndication() completed with %d"), error ) ); |
|
318 |
|
319 return object; |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // CBTSBPPObjectServer::GetPacketIndication |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 TInt CBTSBPPObjectServer::GetPacketIndication() |
|
327 { |
|
328 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::GetPacketIndication()")); |
|
329 |
|
330 return KErrNone; |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // CBTSBPPObjectServer::GetCompleteIndication |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 TInt CBTSBPPObjectServer::GetCompleteIndication() |
|
338 { |
|
339 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::GetCompleteIndication()")); |
|
340 |
|
341 delete iObjectRequest; |
|
342 iObjectRequest = NULL; |
|
343 |
|
344 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::GetCompleteIndication() completed")); |
|
345 |
|
346 return KErrNone; |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // CBTSBPPObjectServer::SetPathIndication |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 TInt CBTSBPPObjectServer::SetPathIndication( const CObex::TSetPathInfo& /*aPathInfo*/, |
|
354 const TDesC8& /*aInfo*/ ) |
|
355 { |
|
356 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::SetPathIndication()")); |
|
357 |
|
358 return KErrNotSupported; |
|
359 } |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // CBTSBPPObjectServer::AbortIndication |
|
363 // ----------------------------------------------------------------------------- |
|
364 // |
|
365 void CBTSBPPObjectServer::AbortIndication() |
|
366 { |
|
367 FLOG(_L("[BTSU]\t CBTSBPPObjectServer::AbortIndication()")); |
|
368 |
|
369 iObserverPtr->ServerError( KErrCancel ); |
|
370 } |
|
371 |
|
372 // End of File |