28
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2010 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: Base class of protocol profile handlers.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "scpservicehandlerbase.h"
|
|
20 |
#include "scpprofilehandler.h"
|
|
21 |
#include "scputility.h"
|
|
22 |
#include "scplogger.h"
|
|
23 |
#include "scpservicestorage.h"
|
|
24 |
#include "scpsubservice.h"
|
|
25 |
|
|
26 |
// If sub service disconnection fails a timeout for
|
|
27 |
// forced disabled is used.
|
|
28 |
const TInt KDisableTimeout = 5000000;
|
|
29 |
|
|
30 |
// -----------------------------------------------------------------------------
|
|
31 |
// CScpServiceHandlerBase::CScpServiceHandlerBase
|
|
32 |
// -----------------------------------------------------------------------------
|
|
33 |
//
|
|
34 |
CScpServiceHandlerBase::CScpServiceHandlerBase( CScpSubService& aSubService ) :
|
|
35 |
iSubService( aSubService )
|
|
36 |
{
|
|
37 |
SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::CScpServiceHandlerBase", this);
|
|
38 |
}
|
|
39 |
|
|
40 |
// -----------------------------------------------------------------------------
|
|
41 |
// CScpServiceHandlerBase::~CScpServiceHandlerBase
|
|
42 |
// -----------------------------------------------------------------------------
|
|
43 |
//
|
|
44 |
CScpServiceHandlerBase::~CScpServiceHandlerBase()
|
|
45 |
{
|
|
46 |
SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::~CScpServiceHandlerBase",this);
|
|
47 |
|
|
48 |
delete iDisableTimer;
|
|
49 |
|
|
50 |
CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
|
|
51 |
profileHandler.RemoveObserver( *this );
|
|
52 |
}
|
|
53 |
|
|
54 |
// -----------------------------------------------------------------------------
|
|
55 |
// CScpServiceHandlerBase::BaseConstructL
|
|
56 |
// -----------------------------------------------------------------------------
|
|
57 |
//
|
|
58 |
void CScpServiceHandlerBase::BaseConstructL()
|
|
59 |
{
|
|
60 |
SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::BaseConstructL", this );
|
|
61 |
|
|
62 |
CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
|
|
63 |
profileHandler.AddObserverL( *this );
|
|
64 |
|
|
65 |
iDisableTimer = CPeriodic::NewL( 0 );
|
|
66 |
}
|
|
67 |
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
// From base class MScpSipConnectionObserver
|
|
70 |
// CScpServiceHandlerBase::IsSipProfileAllowedToStartAlr
|
|
71 |
// -----------------------------------------------------------------------------
|
|
72 |
//
|
|
73 |
TBool CScpServiceHandlerBase::IsSipProfileAllowedToStartAlr()
|
|
74 |
{
|
|
75 |
return ETrue;
|
|
76 |
}
|
|
77 |
|
|
78 |
// -----------------------------------------------------------------------------
|
|
79 |
// CScpServiceHandlerBase::RegisterProfileL
|
|
80 |
// -----------------------------------------------------------------------------
|
|
81 |
//
|
|
82 |
void CScpServiceHandlerBase::RegisterProfileL()
|
|
83 |
{
|
|
84 |
SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::RegisterProfileL", this );
|
|
85 |
|
|
86 |
CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
|
|
87 |
profileHandler.RegisterProfileL( iSubService.SipProfileId() );
|
|
88 |
|
|
89 |
CScpSipConnection::TConnectionState currentState = CScpSipConnection::EUnknown;
|
|
90 |
TInt error = KErrNone;
|
|
91 |
|
|
92 |
profileHandler.GetCurrentState( iSubService.SipProfileId(),
|
|
93 |
currentState,
|
|
94 |
error );
|
|
95 |
|
|
96 |
__ASSERT_DEBUG( currentState != CScpSipConnection::EUnknown,
|
|
97 |
User::Panic( KNullDesC, KErrGeneral ) );
|
|
98 |
|
|
99 |
TScpConnectionEvent event = TScpUtility::ConvertToConnectionEvent( currentState,
|
|
100 |
error );
|
|
101 |
if ( event == EScpRegistered )
|
|
102 |
{
|
|
103 |
// Sip profile was already registered
|
|
104 |
HandleSipConnectionEvent( iSubService.SipProfileId(), EScpRegistered );
|
|
105 |
}
|
|
106 |
else
|
|
107 |
{
|
|
108 |
iSubService.HandleConnectionEvent( event );
|
|
109 |
}
|
|
110 |
}
|
|
111 |
|
|
112 |
// -----------------------------------------------------------------------------
|
|
113 |
// CScpServiceHandlerBase::DeregisterProfile
|
|
114 |
// -----------------------------------------------------------------------------
|
|
115 |
//
|
|
116 |
void CScpServiceHandlerBase::DeregisterProfile()
|
|
117 |
{
|
|
118 |
SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::DeregisterProfile", this );
|
|
119 |
|
|
120 |
// At this point all the service related disconnection operations
|
|
121 |
// have been finished. Now the SIP profile needs to be disabled
|
|
122 |
iSubService.SetSubServiceDisconnected( ETrue );
|
|
123 |
|
|
124 |
TInt sipProfileId = iSubService.SipProfileId();
|
|
125 |
CScpServiceStorage& storage = iSubService.ServiceStorage();
|
|
126 |
|
|
127 |
// The SIP profile can be only disabled if
|
|
128 |
// - None of the sub services are in enable state with the same profile
|
|
129 |
// - None of the sub services are doing disconnection with the same profile
|
|
130 |
if ( !storage.IsSubServiceEnabled( sipProfileId ) &&
|
|
131 |
storage.AreAllSubServicesDisconnected( sipProfileId ) )
|
|
132 |
{
|
|
133 |
CScpSipConnection::TConnectionState currentState =
|
|
134 |
CScpSipConnection::EUnknown;
|
|
135 |
TInt error( KErrNone );
|
|
136 |
|
|
137 |
CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
|
|
138 |
profileHandler.GetCurrentState( sipProfileId,
|
|
139 |
currentState,
|
|
140 |
error );
|
|
141 |
|
|
142 |
if ( currentState == CScpSipConnection::ERegistering )
|
|
143 |
{
|
|
144 |
profileHandler.CancelRegistration( sipProfileId );
|
|
145 |
}
|
|
146 |
else
|
|
147 |
{
|
|
148 |
error = profileHandler.UnregisterProfile( sipProfileId );
|
|
149 |
if ( KErrNotFound == error )
|
|
150 |
{
|
|
151 |
SCPLOGSTRING3(
|
|
152 |
"CScpServiceHandlerBase[0x%x]::DeregisterProfile - No profile with ID: %d",
|
|
153 |
this,
|
|
154 |
sipProfileId );
|
|
155 |
}
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
StartForcedDisableTimer( CScpServiceHandlerBase::ForceSipProfileDisable );
|
|
160 |
}
|
|
161 |
|
|
162 |
// -----------------------------------------------------------------------------
|
|
163 |
// CScpServiceHandlerBase::PerformInstantForceSipProfileDisable
|
|
164 |
// -----------------------------------------------------------------------------
|
|
165 |
//
|
|
166 |
void CScpServiceHandlerBase::PerformInstantForceSipProfileDisable()
|
|
167 |
{
|
|
168 |
SCPLOGSTRING2(
|
|
169 |
"CScpServiceHandlerBase[0x%x]::PerformInstantForceSipProfileDisable",
|
|
170 |
this );
|
|
171 |
HandleSipProfileForcedDisable( ETrue );
|
|
172 |
}
|
|
173 |
|
|
174 |
// -----------------------------------------------------------------------------
|
|
175 |
// CScpServiceHandlerBase::StartForcedDisableTimer
|
|
176 |
// -----------------------------------------------------------------------------
|
|
177 |
//
|
|
178 |
void CScpServiceHandlerBase::StartForcedDisableTimer( TInt (*aFunction)(TAny* aPtr) )
|
|
179 |
{
|
|
180 |
SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::StartForcedDisableTimer", this );
|
|
181 |
__ASSERT_DEBUG( !iDisableTimer->IsActive(),
|
|
182 |
User::Panic( KNullDesC, KErrGeneral ) );
|
|
183 |
|
|
184 |
if ( !iDisableTimer->IsActive() )
|
|
185 |
{
|
|
186 |
iDisableTimer->Start( KDisableTimeout,
|
|
187 |
0,
|
|
188 |
TCallBack( aFunction, this ) );
|
|
189 |
}
|
|
190 |
}
|
|
191 |
|
|
192 |
// -----------------------------------------------------------------------------
|
|
193 |
// CScpServiceHandlerBase::CancelDisableTimer
|
|
194 |
// -----------------------------------------------------------------------------
|
|
195 |
//
|
|
196 |
void CScpServiceHandlerBase::CancelDisableTimer()
|
|
197 |
{
|
|
198 |
SCPLOGSTRING2( "CScpServiceHandlerBase[0x%x]::CancelDisableTimer", this );
|
|
199 |
|
|
200 |
if ( iDisableTimer->IsActive() )
|
|
201 |
{
|
|
202 |
iDisableTimer->Cancel();
|
|
203 |
}
|
|
204 |
}
|
|
205 |
|
|
206 |
// -----------------------------------------------------------------------------
|
|
207 |
// CScpServiceHandlerBase::HandleSipProfileForcedDisable
|
|
208 |
// -----------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
void CScpServiceHandlerBase::HandleSipProfileForcedDisable(
|
|
211 |
TBool aForceDisableSipProfile )
|
|
212 |
{
|
|
213 |
SCPLOGSTRING2(
|
|
214 |
"CScpServiceHandlerBase[0x%x]::HandleSipProfileForcedDisable", this );
|
|
215 |
|
|
216 |
if ( aForceDisableSipProfile )
|
|
217 |
{
|
|
218 |
CScpProfileHandler& profileHandler = iSubService.ProfileHandler();
|
|
219 |
|
|
220 |
CScpSipConnection* sipConnection =
|
|
221 |
profileHandler.GetSipConnection( iSubService.SipProfileId() );
|
|
222 |
|
|
223 |
if ( sipConnection )
|
|
224 |
{
|
|
225 |
sipConnection->ForceDisable();
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
HandleSipConnectionEvent( iSubService.SipProfileId(), EScpDeregistered );
|
|
230 |
}
|
|
231 |
|
|
232 |
// -----------------------------------------------------------------------------
|
|
233 |
// CScpServiceHandlerBase::ForceSipProfileDisable
|
|
234 |
// -----------------------------------------------------------------------------
|
|
235 |
//
|
|
236 |
TInt CScpServiceHandlerBase::ForceSipProfileDisable( TAny* aSelf )
|
|
237 |
{
|
|
238 |
SCPLOGSTRING( "CScpServiceHandlerBase::ForceSipProfileDisable" );
|
|
239 |
|
|
240 |
CScpServiceHandlerBase* self = static_cast<CScpServiceHandlerBase*>( aSelf );
|
|
241 |
|
|
242 |
self->CancelDisableTimer();
|
|
243 |
self->HandleSipProfileForcedDisable( EFalse );
|
|
244 |
|
|
245 |
return 1;
|
|
246 |
}
|
|
247 |
|
|
248 |
|
|
249 |
// End of File
|