10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * Private implementation of wrapper for Symbian Esock library. |
16 */ |
16 */ |
17 |
17 |
18 // INCLUDE FILES |
18 // System includes |
|
19 |
19 #include <e32base.h> |
20 #include <e32base.h> |
20 #include <es_sock.h> |
21 #include <es_sock.h> |
21 #include <in_sock.h> |
22 #include <in_sock.h> |
22 #include <commdbconnpref.h> |
23 #include <extendedconnpref.h> |
|
24 |
|
25 // User includes |
|
26 |
23 #include "wlanqtutilsesockwrapper.h" |
27 #include "wlanqtutilsesockwrapper.h" |
24 #include "wlanqtutilsesockwrapper_s60_p.h" |
28 #include "wlanqtutilsesockwrapper_s60_p.h" |
25 |
29 |
26 #ifdef WLANQTUTILS_NO_OST_TRACES_FLAG |
|
27 #include <opensystemtrace.h> |
|
28 #else |
|
29 #include "OstTraceDefinitions.h" |
30 #include "OstTraceDefinitions.h" |
30 #endif |
|
31 #ifdef OST_TRACE_COMPILER_IN_USE |
31 #ifdef OST_TRACE_COMPILER_IN_USE |
32 #include "wlanqtutilsesockwrapper_s60Traces.h" |
32 #include "wlanqtutilsesockwrapper_s60Traces.h" |
33 #endif |
33 #endif |
34 |
34 |
|
35 /*! |
|
36 \class WlanQtUtilsWlanQtUtilsEsockWrapperPrivate |
|
37 \brief Private implementation of wrapper for Symbian Esock library. |
35 |
38 |
36 // =========== PRIVATE CLASS MEMBER FUNCTIONS =============== |
39 Provides functionality to connect and disconnect IAPs. |
37 // |
40 */ |
38 // --------------------------------------------------------- |
41 |
39 // EsockWrapperPrivate::EsockWrapperPrivate() |
42 // External function prototypes |
40 // Constructor |
43 |
41 // --------------------------------------------------------- |
44 // Local constants |
42 // |
45 |
43 EsockWrapperPrivate::EsockWrapperPrivate(EsockWrapper *aWrapper) |
46 // ======== LOCAL FUNCTIONS ======== |
44 : CActive(EPriorityStandard), q_ptr(aWrapper) |
47 |
45 { |
48 // ======== MEMBER FUNCTIONS ======== |
46 OstTraceFunctionEntryExt( ESOCKWRAPPERPRIVATE_ESOCKWRAPPERPRIVATE_ENTRY, this ); |
49 |
|
50 /*! |
|
51 Constructor. |
47 |
52 |
|
53 @param [in] wrapper Wrapper to report progress to. |
|
54 */ |
|
55 |
|
56 WlanQtUtilsEsockWrapperPrivate::WlanQtUtilsEsockWrapperPrivate( |
|
57 WlanQtUtilsEsockWrapper *wrapper) : |
|
58 CActive(EPriorityStandard), |
|
59 iConnectionActive(EFalse), |
|
60 q_ptr(wrapper) |
|
61 { |
|
62 OstTraceFunctionEntry1(WLANQTUTILSESOCKWRAPPERPRIVATE_WLANQTUTILSESOCKWRAPPERPRIVATE_ENTRY, this); |
|
63 |
48 CActiveScheduler::Add(this); |
64 CActiveScheduler::Add(this); |
49 |
65 |
50 iSocketServer.Connect(); |
66 // Establish a session to Socket Server. Errors in Socket Server |
51 |
67 // connection are fatal so just throw them as exceptions |
52 OstTraceFunctionExit1( ESOCKWRAPPERPRIVATE_ESOCKWRAPPERPRIVATE_EXIT, this ); |
68 qt_symbian_throwIfError(iSocketServer.Connect()); |
53 } |
|
54 |
69 |
55 // --------------------------------------------------------- |
70 OstTraceFunctionExit1(WLANQTUTILSESOCKWRAPPERPRIVATE_WLANQTUTILSESOCKWRAPPERPRIVATE_EXIT, this); |
56 // EsockWrapperPrivate::EsockWrapperPrivate() |
71 } |
57 // Destructor |
72 |
58 // --------------------------------------------------------- |
73 /*! |
59 // |
74 Destructor. |
60 EsockWrapperPrivate::~EsockWrapperPrivate() |
75 */ |
61 { |
76 |
62 OstTraceFunctionEntry1( ESOCKWRAPPERPRIVATE_ESOCKWRAPPERPRIVATEDESTR_ENTRY, this ); |
77 WlanQtUtilsEsockWrapperPrivate::~WlanQtUtilsEsockWrapperPrivate() |
63 |
78 { |
|
79 OstTraceFunctionEntry1(DUP1_WLANQTUTILSESOCKWRAPPERPRIVATE_WLANQTUTILSESOCKWRAPPERPRIVATE_ENTRY, this); |
|
80 |
|
81 // Close any possibly ongoing connection |
64 Cancel(); |
82 Cancel(); |
65 // Closing active RConnection is not mandatory, but is recommended. |
83 // Close Socket Server session |
66 // ==> add checking here when implementing cancel/error cases. |
|
67 iSocketServer.Close(); |
84 iSocketServer.Close(); |
68 |
85 |
69 OstTraceFunctionExit1( ESOCKWRAPPERPRIVATE_ESOCKWRAPPERPRIVATEDESTR_EXIT, this ); |
86 OstTraceFunctionExit1(DUP1_WLANQTUTILSESOCKWRAPPERPRIVATE_WLANQTUTILSESOCKWRAPPERPRIVATE_EXIT, this); |
70 } |
87 } |
71 |
88 |
72 // --------------------------------------------------------- |
89 /*! |
73 // EsockWrapperPrivate::connectIap() |
90 Starts connection creation to given IAP. |
74 // Start connection creation to given IAP. |
91 |
75 // --------------------------------------------------------- |
92 @param [in] iapId IAP ID to connect. |
76 // |
93 */ |
77 void EsockWrapperPrivate::connectIap(int aIapId) |
94 |
78 { |
95 void WlanQtUtilsEsockWrapperPrivate::ConnectIap(int iapId) |
79 OstTraceFunctionEntryExt( ESOCKWRAPPERPRIVATE_CONNECTIAP_ENTRY, this ); |
96 { |
|
97 OstTraceFunctionEntry1(WLANQTUTILSESOCKWRAPPERPRIVATE_CONNECTIAP_ENTRY, this); |
80 |
98 |
81 // Open an RConnection object. |
99 // Cancel a (possibly) ongoing previous request |
82 iConnection.Open(iSocketServer); |
100 Cancel(); |
83 |
101 |
84 // Create overrides to force opening of the given IAP without any user prompts. |
102 OstTrace1( |
85 TCommDbConnPref prefs; |
103 TRACE_NORMAL, |
86 prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
104 WLANQTUTILSESOCKWRAPPERPRIVATE_CONNECTIAP, |
87 prefs.SetDirection(ECommDbConnectionDirectionOutgoing); |
105 "WlanQtUtilsEsockWrapperPrivate::connectIap;iapId=%d", |
88 prefs.SetIapId(aIapId); |
106 iapId ); |
89 |
107 |
90 // Start the Connection with overrides |
108 // Open an RConnection object. Errors in RConnection opening are |
91 iConnection.Start(prefs, iStatus); |
109 // fatal so just throw them as exceptions |
|
110 qt_symbian_throwIfError(iConnection.Open(iSocketServer)); |
92 |
111 |
93 // TODO: Currently SetActive Panics when connecting "furiously" in Visual view... |
112 // Create overrides for connection preferences to force opening of the |
94 // Panicking line in SetActive was this: |
113 // given IAP without any user prompts. |
95 // __ASSERT_ALWAYS(!(iStatus.iFlags&TRequestStatus::EActive),Panic(EReqAlreadyActive)); |
114 TConnPrefList prefList; |
|
115 TExtendedConnPref prefs; |
|
116 prefs.SetIapId(iapId); |
|
117 prefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourConnSilent); |
|
118 QT_TRAP_THROWING(prefList.AppendL(&prefs)); |
|
119 |
|
120 // Start a connection with connection preferences |
|
121 iConnection.Start(prefList, iStatus); |
|
122 |
|
123 iConnectionActive = ETrue; |
|
124 |
96 SetActive(); |
125 SetActive(); |
97 |
126 |
98 OstTraceFunctionExit1( ESOCKWRAPPERPRIVATE_CONNECTIAP_EXIT, this ); |
127 OstTraceFunctionExit1(WLANQTUTILSESOCKWRAPPERPRIVATE_CONNECTIAP_EXIT, this); |
|
128 } |
|
129 |
|
130 /*! |
|
131 Disconnects connection, if one is active. |
|
132 */ |
|
133 |
|
134 void WlanQtUtilsEsockWrapperPrivate::DisconnectIap() |
|
135 { |
|
136 OstTraceFunctionEntry1(WLANQTUTILSESOCKWRAPPERPRIVATE_DISCONNECTIAP_ENTRY, this); |
|
137 |
|
138 if (iConnectionActive) { |
|
139 OstTrace0( |
|
140 TRACE_NORMAL, |
|
141 WLANQTUTILSESOCKWRAPPERPRIVATE_DISCONNECTIAP_DISCONNECT, |
|
142 "WlanQtUtilsEsockWrapperPrivate::disconnectIap Disconnecting connection"); |
|
143 |
|
144 iConnectionActive = EFalse; |
|
145 iConnection.Close(); |
|
146 } else { |
|
147 OstTrace0( |
|
148 TRACE_NORMAL, |
|
149 WLANQTUTILSESOCKWRAPPERPRIVATE_DISCONNECTIAP_IGNORED, |
|
150 "WlanQtUtilsEsockWrapperPrivate::disconnectIap Ignored since no active connection"); |
99 } |
151 } |
|
152 |
|
153 OstTraceFunctionExit1(WLANQTUTILSESOCKWRAPPERPRIVATE_DISCONNECTIAP_EXIT, this); |
|
154 } |
100 |
155 |
101 // --------------------------------------------------------- |
156 /*! |
102 // EsockWrapperPrivate::disconnectIap() |
157 From CActive: called when async request (RConnection::Start()) |
103 // Stop connection. |
158 has been completed. |
104 // --------------------------------------------------------- |
159 */ |
105 // |
160 |
106 void EsockWrapperPrivate::disconnectIap() |
161 void WlanQtUtilsEsockWrapperPrivate::RunL() |
107 { |
162 { |
108 OstTraceFunctionEntry1( ESOCKWRAPPERPRIVATE_DISCONNECTIAP_ENTRY, this ); |
163 OstTraceFunctionEntry1(WLANQTUTILSESOCKWRAPPERPRIVATE_RUNL_ENTRY, this); |
|
164 |
|
165 OstTrace1( |
|
166 TRACE_NORMAL, |
|
167 WLANQTUTILSESOCKWRAPPERPRIVATE_RUNL, |
|
168 "WlanQtUtilsEsockWrapperPrivate::RunL;iStatus=%d", iStatus.Int()); |
109 |
169 |
110 // TODO: Error checking |
170 bool success; |
111 iConnection.Close(); |
171 if (iStatus == KErrNone) { |
|
172 success = true; |
|
173 } else { |
|
174 success = false; |
|
175 iConnectionActive = EFalse; |
|
176 } |
112 |
177 |
113 OstTraceFunctionExit1( ESOCKWRAPPERPRIVATE_DISCONNECTIAP_EXIT, this ); |
178 // Report to public wrapper |
114 } |
179 q_ptr->updateConnection(success, iStatus.Int()); |
|
180 |
|
181 OstTraceFunctionExit1(WLANQTUTILSESOCKWRAPPERPRIVATE_RUNL_EXIT, this); |
|
182 } |
115 |
183 |
116 // --------------------------------------------------------- |
184 /*! |
117 // EsockWrapperPrivate::RunL() |
185 From CActive: called when active object is cancelled. |
118 // Called when connection creation has finished. |
186 */ |
119 // --------------------------------------------------------- |
187 |
120 // |
188 void WlanQtUtilsEsockWrapperPrivate::DoCancel() |
121 void EsockWrapperPrivate::RunL() |
189 { |
122 { |
190 OstTraceFunctionEntry1(WLANQTUTILSESOCKWRAPPERPRIVATE_DOCANCEL_ENTRY, this); |
123 OstTraceFunctionEntry1( ESOCKWRAPPERPRIVATE_RUNL_ENTRY, this ); |
|
124 OstTrace1( TRACE_NORMAL, ESOCKWRAPPERPRIVATE_RUNL, "EsockWrapperPrivate::RunL;iStatus.Int()=%d", iStatus.Int() ); |
|
125 |
191 |
126 bool success = false; |
192 // Disconnect, if needed. |
|
193 DisconnectIap(); |
127 |
194 |
128 if (iStatus == KErrNone) |
195 OstTraceFunctionExit1(WLANQTUTILSESOCKWRAPPERPRIVATE_DOCANCEL_EXIT, this); |
129 { |
196 } |
130 success = true; |
|
131 } |
|
132 |
|
133 q_ptr->updateConnection(success); |
|
134 |
|
135 OstTraceFunctionExit1( ESOCKWRAPPERPRIVATE_RUNL_EXIT, this ); |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------- |
|
139 // EsockWrapperPrivate::DoCancel() |
|
140 // |
|
141 // --------------------------------------------------------- |
|
142 // |
|
143 void EsockWrapperPrivate::DoCancel() |
|
144 { |
|
145 OstTraceFunctionEntry1( ESOCKWRAPPERPRIVATE_DOCANCEL_ENTRY, this ); |
|
146 OstTraceFunctionExit1( ESOCKWRAPPERPRIVATE_DOCANCEL_EXIT, this ); |
|
147 } |
|
148 |
|
149 //end of file |
|