|
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 plugin for data syncronization |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __NSMLOBEXDSPLUGIN__ |
|
20 #define __NSMLOBEXDSPLUGIN__ |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <e32base.h> |
|
24 #include <es_sock.h> |
|
25 #include <obex.h> |
|
26 #include <btsdp.h> |
|
27 #include <btmanclient.h> |
|
28 #include <SrcsInterface.h> |
|
29 #include <nsmldebug.h> |
|
30 #include <nsmlconstants.h> |
|
31 #include <nsmldefines.h> |
|
32 #include <nsmlsyncalerthandlerif.h> |
|
33 |
|
34 #include "nsmltransport.h" |
|
35 #include "NSmlObexDSpluginConstants.h" |
|
36 #include "nsmlobexserversession.h" |
|
37 #include "nsmlobexcommserver.h" |
|
38 #include "nsmlobexdefs.h" |
|
39 |
|
40 |
|
41 #ifdef __NSML_DEBUG__ |
|
42 #include "wbxml2xmlconverter.h" |
|
43 #endif // __NSML_DEBUG__ |
|
44 |
|
45 const TInt KPluginTimeOutValue = 180000000;// Time (in milliseconds) for the timer |
|
46 |
|
47 class CDisListener; |
|
48 class CNSmlObexServerSession; |
|
49 class CPluginServiceTimer; |
|
50 class CThreadObserver; |
|
51 class CNSmlObexPacketWaiterAsync; |
|
52 |
|
53 enum TNSmlObexContent |
|
54 { |
|
55 ENSmlDataSync, |
|
56 ENSmlDeviceManagement |
|
57 }; |
|
58 |
|
59 |
|
60 class CNSmlObexDSplugin : public CSrcsInterface, |
|
61 public MObexServerNotifyAsync, public MNSmlAlertObexPluginContext |
|
62 { |
|
63 friend class CDisListener; |
|
64 |
|
65 public: |
|
66 IMPORT_C static CNSmlObexDSplugin* NewL(); |
|
67 IMPORT_C static CNSmlObexDSplugin* NewLC(); |
|
68 ~CNSmlObexDSplugin(); |
|
69 |
|
70 // virtuals from MNSmlAlertObexPluginContext |
|
71 RLibrary& AlertLibrary(); |
|
72 TThreadId* AlertThreadId(); |
|
73 |
|
74 TBool IsOBEXActive(); |
|
75 |
|
76 public: |
|
77 TPtr8 iPtr; |
|
78 TPtr8 iSendPtr; |
|
79 HBufC8* iData; |
|
80 RNSmlDSObexServerSession iSs; |
|
81 TBool iStopped; |
|
82 |
|
83 private: |
|
84 void ConstructL(); |
|
85 CNSmlObexDSplugin(); |
|
86 |
|
87 static TInt CreateServerL( TAny* aPtr ); |
|
88 static void StartServerL( TAny* aPtr ); |
|
89 TInt ForwardZeroPkgL( TNSmlObexContent aSyncSelection ); |
|
90 TInt CheckMimeType(); |
|
91 void TrimRightSpaceAndNull( TDes8& aDes ) const; |
|
92 void Disconnect(); |
|
93 TInt ConvertError( TInt aError ); |
|
94 TInt SetObexServer( CObexServer* aObexServer ); |
|
95 void BluetoothNameByAddressL( TSockAddr aAddr ); |
|
96 |
|
97 private: // from CSrcsInterface |
|
98 void ErrorIndication( TInt aError ); |
|
99 void TransportUpIndication(); |
|
100 void TransportDownIndication(); |
|
101 void ObexDisconnectIndication( const TDesC8& aInfo ); |
|
102 TInt PutPacketIndication(); |
|
103 TInt GetPacketIndication(); |
|
104 void AbortIndication(); |
|
105 void SetMediaType( TSrcsMediaType aMediaType ); |
|
106 void GetCompleteIndication (); |
|
107 void GetRequestIndication (CObexBaseObject *aRequestedObject); |
|
108 void PutCompleteIndication (); |
|
109 void PutRequestIndication (); |
|
110 void SetPathIndication (const CObex::TSetPathInfo& aPathInfo, const TDesC8& aInfo); |
|
111 void ObexConnectIndication (const TObexConnectInfo& aRemoteInfo, const TDesC8& aInfo); |
|
112 void CancelIndicationCallback(); |
|
113 |
|
114 private: |
|
115 enum TState |
|
116 { |
|
117 EIdle, |
|
118 EGetSendPacket |
|
119 }; |
|
120 |
|
121 TBool iZeroPkg; |
|
122 TNSmlObexContent iObexContent; |
|
123 CBufFlat* iObexBufData; |
|
124 CObexBufObject* iObexBufObject; |
|
125 CDisListener* iListener; |
|
126 TState iState; |
|
127 TBool iSessCancelled; |
|
128 TBool iSessionActive; |
|
129 CObexServer* iObexServer; |
|
130 |
|
131 RLibrary iAlertLib; |
|
132 TThreadId iThreadId; |
|
133 |
|
134 TBTDevAddr iBtAddr; |
|
135 HBufC* iBtName; |
|
136 |
|
137 CPluginServiceTimer* iServiceTimer; |
|
138 TBool iStartTimer; |
|
139 TSrcsMediaType iMediaType; |
|
140 RThread* iServerThread; |
|
141 |
|
142 TBool iConnectionAlive; |
|
143 |
|
144 private: |
|
145 friend class CPluginServiceTimer; |
|
146 |
|
147 CNSmlObexPacketWaiterAsync* iGetPacketWaiterAo; |
|
148 |
|
149 TInt iResponseError; |
|
150 }; |
|
151 |
|
152 |
|
153 class CDisListener : public CActive |
|
154 { |
|
155 public: |
|
156 |
|
157 CDisListener( RNSmlDSObexServerSession& aSs, CNSmlObexDSplugin* aPlugin ) |
|
158 : CActive(0), iSessCancelled(EFalse), iSs(aSs), iPlugin( aPlugin ) |
|
159 { |
|
160 CActiveScheduler::Add(this); |
|
161 }; |
|
162 |
|
163 ~CDisListener(); |
|
164 void RunL(); |
|
165 void DoCancel(); |
|
166 void ListenDisconnect(); |
|
167 TBool iSessCancelled; |
|
168 |
|
169 private: |
|
170 enum TState |
|
171 { |
|
172 EIdle, |
|
173 EListening |
|
174 }; |
|
175 TState iState; |
|
176 RNSmlDSObexServerSession& iSs; |
|
177 CNSmlObexDSplugin* iPlugin; |
|
178 }; |
|
179 |
|
180 |
|
181 //============================================================ |
|
182 // Class CPluginServiceTimer declaration |
|
183 //============================================================ |
|
184 |
|
185 class CPluginServiceTimer : public CActive |
|
186 { |
|
187 public: |
|
188 CPluginServiceTimer( CNSmlObexDSplugin* aEngine, TInt aValue ); |
|
189 void ConstructL(); |
|
190 ~CPluginServiceTimer(); |
|
191 void StartTimer(); |
|
192 void StopTimer(); |
|
193 |
|
194 private: |
|
195 void DoCancel(); |
|
196 void RunL(); |
|
197 |
|
198 private: |
|
199 RTimer iTimer; |
|
200 CNSmlObexDSplugin* iEngine; |
|
201 TInt iValue; |
|
202 }; |
|
203 |
|
204 //============================================================ |
|
205 // CNSmlObexPacketWaiterAsync |
|
206 // |
|
207 //============================================================ |
|
208 class CNSmlObexPacketWaiterAsync : public CActive |
|
209 { |
|
210 public: |
|
211 static CNSmlObexPacketWaiterAsync* NewL (RNSmlDSObexServerSession& aSession, |
|
212 CBufFlat* aObexBufData, |
|
213 CObexBufObject* aObexBufObject); |
|
214 |
|
215 void WaitForGetData() ; |
|
216 inline const TDesC8& Data() const { return *iData; } |
|
217 |
|
218 void SetObexServer( CObexServer* aObexServer ); |
|
219 |
|
220 ~CNSmlObexPacketWaiterAsync(); |
|
221 |
|
222 private: |
|
223 CNSmlObexPacketWaiterAsync (RNSmlDSObexServerSession& aSession, |
|
224 CBufFlat* aObexBufData, |
|
225 CObexBufObject* aObexBufObject); |
|
226 |
|
227 void ConstructL(); |
|
228 void RunL(); |
|
229 void DoCancel(); |
|
230 |
|
231 private: |
|
232 |
|
233 enum TState |
|
234 { |
|
235 EIdle, |
|
236 EGetting |
|
237 }; |
|
238 |
|
239 RNSmlDSObexServerSession& iSession; |
|
240 CObexServer* iObexServer ; |
|
241 CBufFlat* iObexBufData; |
|
242 CObexBufObject* iObexBufObject; |
|
243 HBufC8* iData; |
|
244 TPtr8 iPtr; |
|
245 TState iState; |
|
246 }; |
|
247 |
|
248 #endif // __NSMLOBEXDSPLUGIN__ |
|
249 |