|
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 Device Management |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __NSMLOBEXDMPLUGIN__ |
|
20 #define __NSMLOBEXDMPLUGIN__ |
|
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 |
|
33 #include "nsmltransport.h" |
|
34 #include "NSmlObexDMpluginConstants.h" |
|
35 #include "nsmlobexserversession.h" |
|
36 #include "nsmlobexcommserver.h" |
|
37 #include "nsmlobexdefs.h" |
|
38 |
|
39 #ifdef __NSML_DEBUG__ |
|
40 #include "wbxml2xmlconverter.h" |
|
41 #endif // __NSML_DEBUG__ |
|
42 |
|
43 |
|
44 const TInt KPluginTimeOutValue = 180000000;// Time (in milliseconds) for the timer |
|
45 |
|
46 class CDisListener; |
|
47 class CNSmlObexServerSession; |
|
48 class CPluginServiceTimer; |
|
49 class CThreadObserver; |
|
50 class CNSmlObexPacketWaiter; |
|
51 |
|
52 enum TNSmlObexContent |
|
53 { |
|
54 ENSmlDataSync, |
|
55 ENSmlDeviceManagement |
|
56 }; |
|
57 |
|
58 |
|
59 |
|
60 class CNSmlObexDMplugin : public CSrcsInterface, public MObexServerNotify |
|
61 { |
|
62 friend class CDisListener; |
|
63 |
|
64 public: |
|
65 IMPORT_C static CNSmlObexDMplugin* NewL(); |
|
66 IMPORT_C static CNSmlObexDMplugin* NewLC(); |
|
67 ~CNSmlObexDMplugin(); |
|
68 |
|
69 // Get MObexServerNotify object to bind to CObexServer |
|
70 MObexServerNotify* GetServerCallback(); |
|
71 TBool IsOBEXActive(); |
|
72 |
|
73 public: |
|
74 TPtr8 iPtr; |
|
75 TPtr8 iSendPtr; |
|
76 HBufC8* iData; |
|
77 RNSmlDMObexServerSession iSs; |
|
78 TBool iStopped; |
|
79 |
|
80 private: |
|
81 void ConstructL(); |
|
82 CNSmlObexDMplugin(); |
|
83 |
|
84 static TInt CreateServer( TAny* aPtr ); |
|
85 static void StartServerL( TAny* aPtr ); |
|
86 void TrimRightSpaceAndNull( TDes8& aDes ) const; |
|
87 TInt ForwardZeroPkgL( TNSmlObexContent aSyncSelection ); |
|
88 TInt CheckMimeType(); |
|
89 void Disconnect(); |
|
90 TInt ConvertError( TInt aError ); |
|
91 |
|
92 private: // from CSrcsInterface |
|
93 void ErrorIndication( TInt aError ); |
|
94 void TransportUpIndication(); |
|
95 void TransportDownIndication(); |
|
96 TInt ObexConnectIndication( const TObexConnectInfo& aRemoteInfo, const TDesC8& aInfo ); |
|
97 void ObexDisconnectIndication( const TDesC8& aInfo ); |
|
98 CObexBufObject* PutRequestIndication(); |
|
99 TInt PutPacketIndication(); |
|
100 TInt PutCompleteIndication(); |
|
101 CObexBufObject* GetRequestIndication( CObexBaseObject* aRequestedObject ); |
|
102 TInt GetPacketIndication(); |
|
103 TInt GetCompleteIndication(); |
|
104 TInt SetPathIndication( const CObex::TSetPathInfo& aPathInfo, const TDesC8& aInfo ); |
|
105 void AbortIndication(); |
|
106 void SetMediaType( TSrcsMediaType aMediaType ); |
|
107 TInt SetObexServer( CObexServer* aObexServer ); |
|
108 private: |
|
109 enum TState |
|
110 { |
|
111 EIdle, |
|
112 EGetSendPacket |
|
113 }; |
|
114 |
|
115 TBool iZeroPkg; |
|
116 TNSmlObexContent iObexContent; |
|
117 CBufFlat* iObexBufData; |
|
118 CObexBufObject* iObexBufObject; |
|
119 CDisListener* iListener; |
|
120 TState iState; |
|
121 TBool iSessCancelled; |
|
122 TBool iSessionActive; |
|
123 CObexServer* iObexServer; |
|
124 CPluginServiceTimer* iServiceTimer; |
|
125 TBool iStartTimer; |
|
126 TSrcsMediaType iMediaType; |
|
127 |
|
128 private: |
|
129 friend class CPluginServiceTimer; |
|
130 CNSmlObexPacketWaiter* iGetPacketWaiter; |
|
131 |
|
132 }; |
|
133 |
|
134 |
|
135 class CDisListener : public CActive |
|
136 { |
|
137 public: |
|
138 CDisListener( RNSmlDMObexServerSession& aSs, CNSmlObexDMplugin* aPlugin ) : CActive(0), iSessCancelled(EFalse), iSs(aSs), iPlugin( aPlugin ) { CActiveScheduler::Add(this); }; |
|
139 ~CDisListener(); |
|
140 void RunL(); |
|
141 void DoCancel(); |
|
142 void ListenDisconnect(); |
|
143 TBool iSessCancelled; |
|
144 |
|
145 private: |
|
146 enum TState |
|
147 { |
|
148 EIdle, |
|
149 EListening |
|
150 }; |
|
151 TState iState; |
|
152 RNSmlDMObexServerSession& iSs; |
|
153 CNSmlObexDMplugin* iPlugin; |
|
154 }; |
|
155 |
|
156 |
|
157 //============================================================ |
|
158 // Class CPluginServiceTimer declaration |
|
159 //============================================================ |
|
160 |
|
161 class CPluginServiceTimer : public CActive |
|
162 { |
|
163 public: |
|
164 CPluginServiceTimer( CNSmlObexDMplugin* aEngine, TInt aValue ); |
|
165 void ConstructL(); |
|
166 ~CPluginServiceTimer(); |
|
167 void StartTimer(); |
|
168 void StopTimer(); |
|
169 |
|
170 private: |
|
171 void DoCancel(); |
|
172 void RunL(); |
|
173 |
|
174 private: |
|
175 RTimer iTimer; |
|
176 CNSmlObexDMplugin* iEngine; |
|
177 TInt iValue; |
|
178 }; |
|
179 |
|
180 //============================================================ |
|
181 // CNSmlObexPacketWaiter |
|
182 // |
|
183 //============================================================ |
|
184 class CNSmlObexPacketWaiter : public CBase |
|
185 { |
|
186 public: |
|
187 CNSmlObexPacketWaiter(RNSmlDMObexServerSession& aSession); |
|
188 ~CNSmlObexPacketWaiter(); |
|
189 void ConstructL(); |
|
190 |
|
191 public: |
|
192 TInt WaitForGetData(); |
|
193 inline const TDesC8& Data() const { return *iData; } |
|
194 |
|
195 private: |
|
196 HBufC8* iData; |
|
197 RNSmlDMObexServerSession& iSession; |
|
198 TPtr8 iPtr; |
|
199 }; |
|
200 |
|
201 #endif // __NSMLOBEXDMPLUGIN__ |
|
202 |