|
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: SyncML Obex server binding |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "nsmlobexserverbinding.h" |
|
20 #include "nsmlerror.h" |
|
21 |
|
22 // CONSTANTS |
|
23 _LIT( KInvalidState, "Invalid state" ); |
|
24 |
|
25 //============================================================ |
|
26 // CNSmlObexServerBinding definition |
|
27 //============================================================ |
|
28 |
|
29 //------------------------------------------------------------ |
|
30 // CNSmlObexServerBinding::NewL() |
|
31 //------------------------------------------------------------ |
|
32 CNSmlObexServerBinding* CNSmlObexServerBinding::NewL() |
|
33 { |
|
34 CNSmlObexServerBinding* self = new (ELeave) CNSmlObexServerBinding(); |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop(); //self |
|
38 return self; |
|
39 } |
|
40 //------------------------------------------------------------ |
|
41 // CNSmlObexServerBinding::CNSmlObexServerBinding() |
|
42 //------------------------------------------------------------ |
|
43 CNSmlObexServerBinding::CNSmlObexServerBinding() : CActive(0) |
|
44 { |
|
45 CActiveScheduler::Add( this ); |
|
46 } |
|
47 //------------------------------------------------------------ |
|
48 // CNSmlObexServerBinding::~CNSmlObexServerBinding() |
|
49 //------------------------------------------------------------ |
|
50 CNSmlObexServerBinding::~CNSmlObexServerBinding() |
|
51 { |
|
52 _DBG_FILE("CNSmlObexServerBinding::~CNSmlObexServerBinding() begin"); |
|
53 if( iContent == ENSmlDataSync && iSessionAlive ) |
|
54 { |
|
55 _DBG_FILE("Closing iCsDS"); |
|
56 iCsDS.Disconnect(); |
|
57 iCsDS.Close(); |
|
58 } |
|
59 if( iContent == ENSmlDeviceManagement && iSessionAlive ) |
|
60 { |
|
61 _DBG_FILE("Closing iCsDM"); |
|
62 iCsDM.Disconnect(); |
|
63 iCsDM.Close(); |
|
64 } |
|
65 Cancel(); |
|
66 _DBG_FILE("CNSmlObexServerBinding::~CNSmlObexServerBinding() end"); |
|
67 } |
|
68 //------------------------------------------------------------ |
|
69 // CNSmlObexServerBinding::ConstructL() |
|
70 // 2-phase |
|
71 //------------------------------------------------------------ |
|
72 void CNSmlObexServerBinding::ConstructL() |
|
73 { |
|
74 iSessionAlive = EFalse; |
|
75 } |
|
76 //------------------------------------------------------------ |
|
77 // CNSmlObexServerBinding* CreateCNsmlObexServerBindingL() |
|
78 // |
|
79 //------------------------------------------------------------ |
|
80 EXPORT_C CNSmlObexServerBinding* CreateCNsmlObexServerBindingL() |
|
81 { |
|
82 return CNSmlObexServerBinding::NewL(); |
|
83 } |
|
84 //------------------------------------------------------------ |
|
85 // CNSmlObexServerBinding::Connect( TNSmlObexTransport /*aTransport*/,TBool /*aServerAlerted*/, TDesC8& /*aMimeType*/, TRequestStatus &aStatus ) |
|
86 // |
|
87 //------------------------------------------------------------ |
|
88 void CNSmlObexServerBinding::Connect( TNSmlObexTransport /*aTransport*/,TBool /*aServerAlerted*/, TDesC8& aMimeType, TRequestStatus &aStatus ) |
|
89 { |
|
90 _DBG_FILE("CNSmlObexServerBinding::Connect"); |
|
91 TInt err ( KErrNone ); |
|
92 iCancelledByServer = EFalse; |
|
93 iAgentStatus = &aStatus; |
|
94 *iAgentStatus = KRequestPending; |
|
95 |
|
96 if( aMimeType.Compare( KDataSyncMIME ) == 0 ) |
|
97 { |
|
98 _DBG_FILE("Data sync MIME type"); |
|
99 iContent = ENSmlDataSync; |
|
100 } |
|
101 else |
|
102 { |
|
103 _DBG_FILE("Dev Man MIME type"); |
|
104 iContent = ENSmlDeviceManagement; |
|
105 } |
|
106 err = ConnectToServer(); |
|
107 DBG_FILE_CODE( err, _S8("ConnectToServer returned") ); |
|
108 if ( err ) |
|
109 { |
|
110 _DBG_FILE("ConnectToServer error converted to Server not responding"); |
|
111 err = TNSmlError::ESmlServerNotResponding; |
|
112 } |
|
113 User::RequestComplete( iAgentStatus, err ); |
|
114 } |
|
115 //------------------------------------------------------------ |
|
116 // CNSmlObexServerBinding::ConnectToServer() |
|
117 // |
|
118 //------------------------------------------------------------ |
|
119 TInt CNSmlObexServerBinding::ConnectToServer() |
|
120 { |
|
121 _DBG_FILE("CNSmlObexServerBinding::ConnectToServer"); |
|
122 TInt err( KErrNone ); |
|
123 if( iContent == ENSmlDataSync ) |
|
124 { |
|
125 _DBG_FILE("DS client session"); |
|
126 err = iCsDS.Connect(); |
|
127 if( err == KErrNone ) |
|
128 { |
|
129 iSessionAlive = ETrue; |
|
130 } |
|
131 } |
|
132 else |
|
133 { |
|
134 _DBG_FILE("DM client session"); |
|
135 err = iCsDM.Connect(); |
|
136 if( err == KErrNone ) |
|
137 { |
|
138 iSessionAlive = ETrue; |
|
139 } |
|
140 } |
|
141 return err; |
|
142 } |
|
143 //------------------------------------------------------------ |
|
144 // CNSmlObexServerBinding::DoCancel() |
|
145 // From CActive |
|
146 //------------------------------------------------------------ |
|
147 void CNSmlObexServerBinding::DoCancel() |
|
148 { |
|
149 _DBG_FILE("CNSmlObexServerBinding::DoCancel"); |
|
150 if( iState == EReceiving ) |
|
151 { |
|
152 _DBG_FILE("CNSmlObexServerBinding - Canceling receive"); |
|
153 if( iContent == ENSmlDataSync ) |
|
154 { |
|
155 _DBG_FILE("Canceling iCsDS"); |
|
156 iCsDS.CancelReceive(); |
|
157 } |
|
158 else |
|
159 { |
|
160 _DBG_FILE("Canceling iCsDM"); |
|
161 iCsDM.CancelReceive(); |
|
162 } |
|
163 if( iCancelledByServer ) |
|
164 { |
|
165 _DBG_FILE("iCancelledByServer"); |
|
166 User::RequestComplete( iAgentStatus, KErrCancel ); |
|
167 } |
|
168 else |
|
169 { |
|
170 _DBG_FILE("Cancelled by sync app"); |
|
171 User::RequestComplete( iAgentStatus, KErrNone ); |
|
172 } |
|
173 } |
|
174 } |
|
175 //------------------------------------------------------------ |
|
176 // CNSmlObexServerBinding::RunL() |
|
177 // From CActive |
|
178 //------------------------------------------------------------ |
|
179 void CNSmlObexServerBinding::RunL() |
|
180 { |
|
181 TState s = iState; |
|
182 iState = EIdle; |
|
183 if( iStatus.Int() != KErrNone ) |
|
184 { |
|
185 DBG_FILE_CODE( iStatus.Int(), _S8("error...") ); |
|
186 if( iContent == ENSmlDataSync ) |
|
187 { |
|
188 _DBG_FILE("Disconnecting iCsDS"); |
|
189 iCsDS.Disconnect(); |
|
190 iCsDS.Close(); |
|
191 iSessionAlive = EFalse; |
|
192 } |
|
193 else |
|
194 { |
|
195 _DBG_FILE("Disconnecting iCsDM"); |
|
196 iCsDM.Disconnect(); |
|
197 iCsDM.Close(); |
|
198 iSessionAlive = EFalse; |
|
199 } |
|
200 User::RequestComplete( iAgentStatus, iStatus.Int() ); |
|
201 } |
|
202 else |
|
203 { |
|
204 switch( s ) |
|
205 { |
|
206 case EIdle: |
|
207 if( iContent == ENSmlDataSync ) |
|
208 { |
|
209 _DBG_FILE("Disconnecting iCsDS"); |
|
210 iCsDS.Disconnect(); |
|
211 iCsDS.Close(); |
|
212 iSessionAlive = EFalse; |
|
213 } |
|
214 else |
|
215 { |
|
216 _DBG_FILE("Disconnecting iCsDM"); |
|
217 iCsDM.Disconnect(); |
|
218 iCsDM.Close(); |
|
219 iSessionAlive = EFalse; |
|
220 } |
|
221 break; |
|
222 case EConnecting: |
|
223 case ESending: |
|
224 case EReceiving: |
|
225 User::RequestComplete( iAgentStatus, iStatus.Int() ); |
|
226 iState = EIdle; |
|
227 break; |
|
228 default: |
|
229 User::Panic( KInvalidState, s ); |
|
230 } |
|
231 } |
|
232 } |
|
233 //------------------------------------------------------------ |
|
234 // CNSmlObexServerBinding::Send( TDesC8& aStartPtr, TBool /*aFinalPacket*/, TRequestStatus &aStatus ) |
|
235 // |
|
236 //------------------------------------------------------------ |
|
237 void CNSmlObexServerBinding::Send( const TDesC8& aStartPtr, TBool /*aFinalPacket*/, TRequestStatus &aStatus ) |
|
238 { |
|
239 _DBG_FILE("CNSmlObexServerBinding::Send"); |
|
240 iCancelledByServer = EFalse; |
|
241 iState = ESending; |
|
242 iAgentStatus = &aStatus; |
|
243 *iAgentStatus = KRequestPending; |
|
244 |
|
245 if( iContent == ENSmlDataSync ) |
|
246 { |
|
247 _DBG_FILE("iCsDS Send"); |
|
248 iCsDS.Send( aStartPtr ); |
|
249 } |
|
250 else |
|
251 { |
|
252 _DBG_FILE("iCsDM Send"); |
|
253 iCsDM.Send( aStartPtr ); |
|
254 } |
|
255 User::RequestComplete( iAgentStatus, KErrNone ); |
|
256 iState = EIdle; |
|
257 } |
|
258 //------------------------------------------------------------ |
|
259 // CNSmlObexServerBinding::Receive( TDes8& aStartPtr, TRequestStatus &aStatus ) |
|
260 // |
|
261 //------------------------------------------------------------ |
|
262 void CNSmlObexServerBinding::Receive( TDes8& aStartPtr, TRequestStatus &aStatus ) |
|
263 { |
|
264 _DBG_FILE("CNSmlObexServerBinding::Receive"); |
|
265 iCancelledByServer = EFalse; |
|
266 iState = EReceiving; |
|
267 iAgentStatus = &aStatus; |
|
268 *iAgentStatus = KRequestPending; |
|
269 |
|
270 if( iContent == ENSmlDataSync ) |
|
271 { |
|
272 _DBG_FILE("iCsDS Receive"); |
|
273 iCsDS.Receive( aStartPtr, iStatus ); |
|
274 } |
|
275 else |
|
276 { |
|
277 _DBG_FILE("iCsDM Receive"); |
|
278 iCsDM.Receive( aStartPtr, iStatus ); |
|
279 } |
|
280 SetActive(); |
|
281 } |
|
282 //------------------------------------------------------------ |
|
283 // CNSmlObexServerBinding::Disconnect() |
|
284 // |
|
285 //------------------------------------------------------------ |
|
286 void CNSmlObexServerBinding::Disconnect() |
|
287 { |
|
288 _DBG_FILE("CNSmlObexServerBinding::Disconnect"); |
|
289 if( iSessionAlive ) |
|
290 { |
|
291 if( iContent == ENSmlDataSync ) |
|
292 { |
|
293 _DBG_FILE("iCsDS Disconnect"); |
|
294 iCsDS.Disconnect(); |
|
295 iCsDS.Close(); |
|
296 iSessionAlive = EFalse; |
|
297 } |
|
298 else |
|
299 { |
|
300 _DBG_FILE("iCsDM Disconnect"); |
|
301 iCsDM.Disconnect(); |
|
302 iCsDM.Close(); |
|
303 iSessionAlive = EFalse; |
|
304 } |
|
305 } |
|
306 } |
|
307 |
|
308 //End of File |
|
309 |