|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 #include "ss_legacyinterfaces.h" |
|
21 |
|
22 #include <comms-infras/api_ext_list.h> |
|
23 #include <comms-infras/api_ext_msg.h> |
|
24 #include <cdblen.h> |
|
25 #include <commdb.h> |
|
26 #include <ss_glob.h> |
|
27 #include <comms-infras/ss_connprov.h> |
|
28 #include <comms-infras/ss_connlegacy.h> |
|
29 #include <comms-infras/ss_thread.h> |
|
30 #include <comms-infras/metatype.h> |
|
31 #include <comms-infras/ss_datamon_apiext.h> |
|
32 #include <comms-infras/ss_connlegacy.h> |
|
33 #include "SS_conn.H" |
|
34 |
|
35 #include <comms-infras/ss_nodemessages_internal_esock.h> |
|
36 #include "ss_internal_activities.h" |
|
37 // although we don't need the XConnectionQueryBase::LoadL() method |
|
38 // including this header forces us to link against commsdataobjects.lib |
|
39 // when compiling with Armv5 |
|
40 #include <comms-infras/connectionqueryset.h> |
|
41 |
|
42 #include <comms-infras/ss_log.h> |
|
43 #include <comms-infras/ss_commsdataobject.h> |
|
44 #include <comms-infras/ss_roles.h> |
|
45 #include <ss_sock.h> |
|
46 #include "SS_rslv.H" |
|
47 #include <comms-infras/ss_subconnflow.h> |
|
48 #include <elements/responsemsg.h> |
|
49 |
|
50 using namespace ESock; |
|
51 using namespace Elements; |
|
52 using namespace Messages; |
|
53 using namespace MeshMachine; |
|
54 |
|
55 |
|
56 |
|
57 EXPORT_C ALegacySubConnectionActiveApiExt::~ALegacySubConnectionActiveApiExt() |
|
58 { |
|
59 iRequests.ResetAndDestroy(); |
|
60 } |
|
61 |
|
62 |
|
63 void ALegacySubConnectionActiveApiExt::IsSubConnectionActiveRequest(CLegacySubConnectionActiveResponder& aResponder) |
|
64 { |
|
65 // Create a request structure for this client. |
|
66 CClientRequest* request = new CClientRequest(aResponder.ClientId(), aResponder); |
|
67 if (!request) |
|
68 { |
|
69 aResponder.Error(KErrNoMemory); |
|
70 return; |
|
71 } |
|
72 |
|
73 // Find the data monitoring provider associated with the parent node. |
|
74 ADataMonitoringProvider* dmProvider = NULL; |
|
75 TRAP_IGNORE(dmProvider = static_cast<ADataMonitoringProvider*>(iParent->FetchNodeInterfaceL(EDataMonitoringApiExt))); |
|
76 if (!dmProvider) |
|
77 { |
|
78 // There's no way the ipproto CPR and SCPR can't be data monitoring providers |
|
79 aResponder.Error(KErrCorrupt); |
|
80 request->iResponder = NULL; |
|
81 delete request; |
|
82 return; |
|
83 } |
|
84 TDataVolumes* dmVolumes = dmProvider->DataVolumesPtr(); |
|
85 |
|
86 // Initialise the request structure with the current data counts for |
|
87 // comparison when the timer fires. |
|
88 request->iInitialSentVolume = dmVolumes->iSentBytes; |
|
89 request->iInitialReceivedVolume = dmVolumes->iReceivedBytes; |
|
90 |
|
91 // Create a new timer for this request and record it in the request structure. |
|
92 CActivityTimer* timer = NULL; |
|
93 TRAP_IGNORE(timer = CActivityTimer::NewL(*this, request, KActivityTimerPriority)); |
|
94 if (!timer) |
|
95 { |
|
96 aResponder.Error(KErrNoMemory); |
|
97 request->iResponder = NULL; |
|
98 delete request; |
|
99 return; |
|
100 } |
|
101 |
|
102 request->iTimer = timer; |
|
103 |
|
104 // Store the request and kick off the timer. |
|
105 TInt error = iRequests.Append(request); |
|
106 if (error!=KErrNone) |
|
107 { |
|
108 aResponder.Error(error); |
|
109 request->iResponder = NULL; |
|
110 delete request; |
|
111 return; |
|
112 } |
|
113 |
|
114 request->iTimer->After(request->iResponder->TimerPeriod() * KMicrosecondsInASecond); |
|
115 } |
|
116 |
|
117 void ALegacySubConnectionActiveApiExt::CancelIsSubConnectionActiveRequest(TSubSessionUniqueId aClientId) |
|
118 { |
|
119 // Find the outstanding request, remove it from the array, complete the client, delete the timer, delete the request. |
|
120 for(TInt i=0;i<iRequests.Count();i++) |
|
121 { |
|
122 if(iRequests[i]->iClientId == aClientId) |
|
123 { |
|
124 CClientRequest* request = iRequests[i]; |
|
125 iRequests.Remove(i); |
|
126 |
|
127 ASSERT(request); |
|
128 delete request; |
|
129 } |
|
130 } |
|
131 } |
|
132 |
|
133 EXPORT_C void ALegacySubConnectionActiveApiExt::CancelExtensionInterface(TSubSessionUniqueId aClientId) |
|
134 { |
|
135 CancelIsSubConnectionActiveRequest(aClientId); |
|
136 } |
|
137 |
|
138 void ALegacySubConnectionActiveApiExt::CheckSubConnectionActivityL(CClientRequest* aRequest) |
|
139 { |
|
140 ASSERT(aRequest); |
|
141 |
|
142 ADataMonitoringProvider* dmProvider = static_cast<ADataMonitoringProvider*>(iParent->FetchNodeInterfaceL(EDataMonitoringApiExt)); |
|
143 User::LeaveIfError(dmProvider ? KErrNone : KErrCorrupt); // There's no way the ipproto CPR and SCPR can't be data monitoring providers |
|
144 TDataVolumes* dmVolumes = dmProvider->DataVolumesPtr(); |
|
145 |
|
146 TUint newSentDataVolume = dmVolumes->iSentBytes; |
|
147 TUint newReceivedDataVolume = dmVolumes->iReceivedBytes; |
|
148 |
|
149 TBool dataTransferred = (newSentDataVolume != aRequest->iInitialSentVolume) || |
|
150 (newReceivedDataVolume != aRequest->iInitialReceivedVolume); |
|
151 |
|
152 // If the data transferred volumes haven't change but the client thinks the connection is active... |
|
153 if (aRequest->iResponder->ClientPerceivedState()) |
|
154 { |
|
155 if(dataTransferred) // ...and it is, so just start another timer cycle |
|
156 { |
|
157 aRequest->iInitialSentVolume = newSentDataVolume; |
|
158 aRequest->iInitialReceivedVolume = newReceivedDataVolume; |
|
159 |
|
160 aRequest->iTimer->After(aRequest->iResponder->TimerPeriod() * KMicrosecondsInASecond); |
|
161 } |
|
162 else // ...tell them it's not |
|
163 { |
|
164 aRequest->SubConnectionActive(dataTransferred); |
|
165 |
|
166 for(TInt i=0;i<iRequests.Count();i++) |
|
167 { |
|
168 if(iRequests[i]->iClientId == aRequest->iClientId) |
|
169 { |
|
170 CClientRequest* request = iRequests[i]; |
|
171 iRequests.Remove(i); |
|
172 delete request; |
|
173 } |
|
174 } |
|
175 } |
|
176 } |
|
177 else // client believes subconnection is idle... |
|
178 { |
|
179 if(dataTransferred) |
|
180 { |
|
181 aRequest->SubConnectionActive(dataTransferred); |
|
182 |
|
183 |
|
184 for(TInt i=0;i<iRequests.Count();i++) |
|
185 { |
|
186 if(iRequests[i]->iClientId == aRequest->iClientId) |
|
187 { |
|
188 CClientRequest* request = iRequests[i]; |
|
189 iRequests.Remove(i); |
|
190 delete request; |
|
191 } |
|
192 } |
|
193 } |
|
194 else // ...and it is, so just start another timer cycle |
|
195 { |
|
196 aRequest->iInitialSentVolume = newSentDataVolume; |
|
197 aRequest->iInitialReceivedVolume = newReceivedDataVolume; |
|
198 |
|
199 aRequest->iTimer->After(aRequest->iResponder->TimerPeriod() * KMicrosecondsInASecond); |
|
200 } |
|
201 } |
|
202 } |
|
203 |
|
204 |
|
205 CClientRequest::~CClientRequest() |
|
206 { |
|
207 delete iTimer; |
|
208 if (iResponder) |
|
209 { |
|
210 iResponder->Complete(KErrCancel); |
|
211 } |
|
212 } |
|
213 |
|
214 |
|
215 void CClientRequest::SubConnectionActive(TBool aState) |
|
216 { |
|
217 iResponder->SubConnectionActive(aState); |
|
218 iResponder = NULL; |
|
219 } |
|
220 |
|
221 /** |
|
222 Construct a new CActivityTimer() |
|
223 |
|
224 @param aOwner The owning ALegacySubConnectionActiveApiExt (on which we call methods upon timer completion) |
|
225 @param aPriority The priority of the active object underlying this timer object |
|
226 @return A pointer to the newly constructed CActivityTimer object |
|
227 |
|
228 @internalComponent |
|
229 */ |
|
230 ESock::CActivityTimer* ESock::CActivityTimer::NewL(ALegacySubConnectionActiveApiExt& aOwner, CClientRequest* aRequest, TInt aPriority) |
|
231 { |
|
232 ESock::CActivityTimer* newActivityTimer = |
|
233 new(ELeave) ESock::CActivityTimer(aOwner, aRequest, aPriority); |
|
234 |
|
235 CleanupStack::PushL(newActivityTimer); |
|
236 newActivityTimer->ConstructL(); |
|
237 CleanupStack::Pop(newActivityTimer); |
|
238 |
|
239 return newActivityTimer; |
|
240 } |
|
241 |
|
242 /** |
|
243 Call the owning object's check activity method. |
|
244 |
|
245 @internalComponent |
|
246 */ |
|
247 void ESock::CActivityTimer::RunL() |
|
248 { |
|
249 iOwner.CheckSubConnectionActivityL(iRequest); |
|
250 } |
|
251 |
|
252 |