1 /* |
|
2 * Copyright (c) 2006 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: IETF SIMPLE Protocol implementation for XIMP Framework |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <badesca.h> |
|
20 #include <ecom/implementationproxy.h> |
|
21 #include <ximpserviceinfo.h> |
|
22 #include <ximpbase.h> |
|
23 #include <ximpidentity.h> |
|
24 #include <presenceinfo.h> |
|
25 #include <ximpprotocolconnectionhost.h> |
|
26 #include <ximpprotocolconnection.h> |
|
27 #include <ximpserviceinfo.h> |
|
28 #include <ximpcontextclientinfo.h> |
|
29 |
|
30 #include "presenceplugin.h" |
|
31 #include "presenceplugindef.h" |
|
32 #include "presencepluginconnection.h" |
|
33 #include "presenceplugincommon.h" |
|
34 #include "presenceplugin_resource.hrh" |
|
35 #include "presenceconnectioninfo.h" |
|
36 |
|
37 #include <spsettings.h> |
|
38 #include <spentry.h> |
|
39 #include <spproperty.h> |
|
40 #include <spdefinitions.h> |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // Key value pair table to identify correct constructor |
|
46 // function for the requested interface. |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 const TImplementationProxy ImplementationTable[] = |
|
50 { |
|
51 //Warning in Lint 611 |
|
52 IMPLEMENTATION_PROXY_ENTRY( PRESENCEPLUGIN_1_IMPLEMENTATION_UID, |
|
53 CPresencePlugin::NewL ) |
|
54 }; |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // Exported function to return the implementation proxy table |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( |
|
61 TInt& aTableCount ) |
|
62 { |
|
63 aTableCount = sizeof( ImplementationTable ) / |
|
64 sizeof( TImplementationProxy ); |
|
65 return ImplementationTable; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // CPresencePlugin::CPresencePlugin() |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CPresencePlugin::CPresencePlugin() |
|
73 { |
|
74 //empty |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CPresencePlugin::NewLC() |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 CPresencePlugin* CPresencePlugin::NewLC() |
|
82 { |
|
83 CPresencePlugin* self = new( ELeave ) CPresencePlugin(); |
|
84 CleanupStack::PushL( self ); |
|
85 return self; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CPresencePlugin::NewL() |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 CPresencePlugin* CPresencePlugin::NewL() |
|
93 { |
|
94 CPresencePlugin* self = CPresencePlugin::NewLC(); |
|
95 CleanupStack::Pop( self ); |
|
96 return self; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CPresencePlugin::~CPresencePlugin() |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 CPresencePlugin::~CPresencePlugin() |
|
104 { |
|
105 DP_SDA("CPresencePlugin::~CPresencePlugin"); |
|
106 iConnections.ResetAndDestroy(); |
|
107 iConnectionArray.ResetAndDestroy(); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CPresencePlugin::~CPresencePlugin() |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 void CPresencePlugin::PrimeHost( MXIMPProtocolPluginHost& aHost ) |
|
115 { |
|
116 DP_SDA("CPresencePlugin::PrimeHost"); |
|
117 iHost = &aHost; |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CPresencePlugin::AcquireConnectionL() |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 MXIMPProtocolConnection& CPresencePlugin::AcquireConnectionL( |
|
125 const MXIMPServiceInfo& aServiceInfo, |
|
126 const MXIMPContextClientInfo& aContextClient ) |
|
127 { |
|
128 DP_SDA("CPresencePlugin::AcquireConnectionL"); |
|
129 MXIMPProtocolConnection* tmp = NULL; |
|
130 CPresenceConnectionInfo* connectionArray = NULL; |
|
131 TBool connected = EFalse; |
|
132 |
|
133 //Check if presence is allready connected to id |
|
134 //!!!! IN this adapter that IapID is service id ID!!!! |
|
135 |
|
136 DP_SDA2("CPresencePlugin::AcquireConnectionL - service id: %d", |
|
137 aServiceInfo.IapId() ); |
|
138 |
|
139 TInt presenceId = KErrNotFound; |
|
140 CSPSettings* spSettings = CSPSettings::NewL(); |
|
141 CleanupStack::PushL( spSettings ); |
|
142 |
|
143 CSPProperty* property = CSPProperty::NewLC(); |
|
144 spSettings->FindPropertyL( aServiceInfo.IapId(), |
|
145 ESubPropertyPresenceSettingsId, |
|
146 *property ); |
|
147 if ( property ) |
|
148 { |
|
149 property->GetValue( presenceId ); |
|
150 } |
|
151 CleanupStack::PopAndDestroy( property ); |
|
152 CleanupStack::PopAndDestroy( spSettings ); |
|
153 |
|
154 DP_SDA2(" -> presence settings id: %d",presenceId ); |
|
155 __ASSERT_ALWAYS( presenceId > 0, User::Leave( KErrArgument ) ); |
|
156 |
|
157 TInt connectionsCount = iConnections.Count(); |
|
158 DP_SDA2("AcquireConnectionL : connectionsCount =%d ", connectionsCount ); |
|
159 |
|
160 for( TInt i( connectionsCount - 1 ); i >= 0; i-- ) |
|
161 { |
|
162 DP_SDA2("AcquireConnectionL connection count %d", connectionsCount); |
|
163 if( iConnections[i]->GetPresenceSetId() == presenceId ) |
|
164 { |
|
165 DP_SDA2("AcquireConnectionL RETURN OLD CONNECTION : i = %d " , i ); |
|
166 //Check connection status |
|
167 tmp = iConnections[i]; |
|
168 connectionArray = iConnections[i]->GetConnectionArray(); |
|
169 |
|
170 //Check connection status from connectionArray |
|
171 CPresencePluginConnection::TConnectionStatus status = |
|
172 connectionArray->GetConnectionStatus(); |
|
173 |
|
174 if( CPresencePluginConnection::ENotActive == status ) |
|
175 { |
|
176 DP_SDA("AcquireConnectionL ENotActive "); |
|
177 DP_SDA("AcquireConnectionL Del old inactive connection"); |
|
178 //Call session CLOSE here!!!!! |
|
179 //Ensure there is no any client to bind this connect |
|
180 //Release this failed connection |
|
181 DeleteConnection(i); |
|
182 } |
|
183 else if ( CPresencePluginConnection::ETerminated == status ) |
|
184 { |
|
185 DP_SDA("AcquireConnectionL ETerminated CREATE NEW CONNECTION "); |
|
186 //Roamning try use lates ETag |
|
187 //Delete old terminaded connection and create new with old ETag |
|
188 CPresencePluginConnection* connection = |
|
189 CPresencePluginConnection::NewL( |
|
190 aServiceInfo, aContextClient, |
|
191 *iConnectionArray[i]->GetConnectionEtag() ); |
|
192 CleanupStack::PushL( connection ); |
|
193 |
|
194 DeleteConnection( i ); |
|
195 |
|
196 //Add this new connection to connectionArray |
|
197 CPresenceConnectionInfo* connectionInfo = |
|
198 CPresenceConnectionInfo::NewL( connection ); |
|
199 iConnectionArray.Append( connectionInfo ); |
|
200 connection->SetConnectionArray( connectionInfo ); |
|
201 iConnections.AppendL( connection ); |
|
202 CleanupStack::Pop( connection ); |
|
203 tmp = connection; |
|
204 connected = ETrue; |
|
205 } |
|
206 else if ( CPresencePluginConnection::EActive == status ) |
|
207 { |
|
208 DP_SDA("AcquireConnectionL EActive"); |
|
209 // NOTE: Incase there is no reply from XIMP before client is |
|
210 // shutdown , then closeconnection wouldnt be called, reopening |
|
211 // client will increase clientCount which is wrong. ClientCount |
|
212 // should be checked for validity before increasing? |
|
213 // If already connected |
|
214 iConnectionArray[i]->IncreaseClientCount(); |
|
215 connected = ETrue; |
|
216 tmp = iConnections[i]; |
|
217 DP_SDA("AcquireConnectionL RETURN OLD CONNECTION done"); |
|
218 } |
|
219 break; |
|
220 } |
|
221 } |
|
222 if( !connected ) |
|
223 { |
|
224 DP_SDA("CPresencePlugin::AcquireConnectionL CREATE NEW CONNECTION"); |
|
225 // If not already connected |
|
226 CPresencePluginConnection* connection = CPresencePluginConnection::NewL( |
|
227 aServiceInfo, aContextClient ); |
|
228 CleanupStack::PushL( connection ); |
|
229 |
|
230 //Add this new connection to connectionArray |
|
231 CPresenceConnectionInfo* connectionInfo = |
|
232 CPresenceConnectionInfo::NewL( connection ); |
|
233 iConnectionArray.Append( connectionInfo ); |
|
234 connection->SetConnectionArray( connectionInfo ); |
|
235 //Add on binded client |
|
236 connectionInfo->IncreaseClientCount(); |
|
237 |
|
238 iConnections.AppendL( connection ); |
|
239 CleanupStack::Pop( connection ); |
|
240 tmp = connection; |
|
241 DP_SDA("AcquireConnectionL CREATE NEW CONNECTION DONE"); |
|
242 } |
|
243 DP_SDA("CPresencePlugin::AcquireConnectionL ret"); |
|
244 return *tmp; |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // CPresencePlugin::ReleaseConnection() |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 void CPresencePlugin::ReleaseConnection( MXIMPProtocolConnection& aConnection ) |
|
252 { |
|
253 DP_SDA("CPresencePlugin::ReleaseConnection"); |
|
254 TInt connectionsCount = iConnections.Count(); |
|
255 |
|
256 DP_SDA2("ReleaseConnection : connectionsCount =%d ", connectionsCount ); |
|
257 |
|
258 for ( TInt i=0; i < connectionsCount; i++ ) |
|
259 { |
|
260 DP_SDA("CPresencePlugin::ReleaseConnection for start"); |
|
261 if ( iConnectionArray[i]->GetConnection() == &aConnection ) |
|
262 { |
|
263 //Check how many client is using this connection |
|
264 TInt clientCount = iConnectionArray[i]->ClientCount(); |
|
265 |
|
266 DP_SDA2("ReleaseConnection : clientCount = %d ", clientCount ); |
|
267 DP_SDA2("CPresencePlugin::ReleaseConnection : i = %d", i ); |
|
268 |
|
269 if ( connectionsCount == 1 && clientCount <= 0 ) |
|
270 { |
|
271 DP_SDA("CPresencePlugin::ReleaseConnection Lets start to check"); |
|
272 DP_SDA2("CPresencePlugin::ReleaseConnection connect status %d,", iConnections[i]->GetSessionStatus()); |
|
273 //Check this connection status |
|
274 if( !(CPresencePluginConnection::ENotActive == |
|
275 iConnectionArray[i]->GetConnectionStatus() )) |
|
276 { |
|
277 DP_SDA("CPresencePlugin::ReleaseConnection not have clients"); |
|
278 DeleteConnection(i); |
|
279 break; |
|
280 } |
|
281 DP_SDA("connectionsCount == 1 && i == 0 && clientCount == 0 "); |
|
282 DP_SDA("ReleaseConnection : Don't delete this connection "); |
|
283 break; //don't delete first connection |
|
284 } |
|
285 DP_SDA("CPresencePlugin::ReleaseConnection for end"); |
|
286 } |
|
287 } |
|
288 DP_SDA("CPresencePlugin::ReleaseConnection end"); |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // CPresencePlugin::GetInterface() |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 TAny* CPresencePlugin::GetInterface( |
|
296 TInt32 aInterfaceId, |
|
297 TIfGetOps aOptions ) |
|
298 { |
|
299 if ( aInterfaceId == GetInterfaceId() ) |
|
300 { |
|
301 // caller wants this interface |
|
302 return this; |
|
303 } |
|
304 if ( aOptions == MXIMPBase::EPanicIfUnknown ) |
|
305 { |
|
306 User::Panic( KPluginName, KErrExtensionNotSupported ); |
|
307 } |
|
308 return NULL; |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // CPresencePlugin::GetInterface() |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 const TAny* CPresencePlugin::GetInterface( |
|
316 TInt32 aInterfaceId, |
|
317 TIfGetOps aOptions ) const |
|
318 { |
|
319 DP_SDA("CPresencePlugin::GetInterface"); |
|
320 if ( aInterfaceId == GetInterfaceId() ) |
|
321 { |
|
322 // caller wants this interface |
|
323 return const_cast<CPresencePlugin*>(this); |
|
324 } |
|
325 if ( aOptions == MXIMPBase::EPanicIfUnknown ) |
|
326 { |
|
327 User::Panic( KPluginName, KErrExtensionNotSupported ); |
|
328 } |
|
329 return NULL; |
|
330 } |
|
331 |
|
332 // --------------------------------------------------------------------------- |
|
333 // CPresencePlugin::GetInterfaceId() |
|
334 // --------------------------------------------------------------------------- |
|
335 // |
|
336 TInt32 CPresencePlugin::GetInterfaceId() const |
|
337 { |
|
338 return MXIMPProtocolPlugin::KInterfaceId; |
|
339 } |
|
340 |
|
341 // --------------------------------------------------------------------------- |
|
342 // CPresencePlugin::DeleteConnection() |
|
343 // --------------------------------------------------------------------------- |
|
344 // |
|
345 void CPresencePlugin::DeleteConnection( TInt aIndex ) |
|
346 { |
|
347 //First delete connectionArray where connection is same at connection |
|
348 DP_SDA("CPresencePlugin::DeleteConnection"); |
|
349 |
|
350 TInt connectionArrayCount = iConnectionArray.Count(); |
|
351 |
|
352 for ( TInt i=0; i < connectionArrayCount; i++ ) |
|
353 { |
|
354 DP_SDA2("CPresencePlugin::DeleteConnection FINDING, con status %d", iConnectionArray[i]->GetConnectionStatus() ); |
|
355 if( (iConnections[aIndex] == iConnectionArray[i]->GetConnection()) && |
|
356 !(CPresencePluginConnection::EActive == |
|
357 iConnectionArray[i]->GetConnectionStatus() ) ) |
|
358 { |
|
359 DP_SDA("CPresencePlugin::DeleteConnection connection Match"); |
|
360 delete iConnectionArray[i]; |
|
361 iConnectionArray.Remove( i ); |
|
362 iConnectionArray.Compress(); |
|
363 break; |
|
364 } |
|
365 } |
|
366 delete iConnections[aIndex]; |
|
367 iConnections.Remove( aIndex ); |
|
368 iConnections.Compress(); |
|
369 DP_SDA("CPresencePlugin::DeleteConnection end"); |
|
370 } |
|
371 |
|
372 // End of file |
|