realtimenetprots/sipfw/ProfileAgent/Server/Src/SipProfileState.cpp
changeset 0 307788aac0a8
child 2 1e1cc61f56c3
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2008-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 // Name        : sipprofilestate.cpp
       
    15 // Part of     : Sip Profile Server
       
    16 // implementation
       
    17 // Version     : 1.0
       
    18 //
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "SipProfileState.h"
       
    24 #include "SipProfileCacheItem.h"
       
    25 #include "sipplugindirector.h"
       
    26 #include "SipProfileLog.h"
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CSIPProfileState::CSIPProfileState
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CSIPProfileState::CSIPProfileState(CSIPPluginDirector& aDirector) :
       
    35 	iPluginDirector(aDirector)
       
    36     {
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CSIPProfileState::~CSIPProfileState
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CSIPProfileState::~CSIPProfileState()
       
    44     {
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CSIPProfileState::EnterL
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void CSIPProfileState::EnterL(CSIPProfileCacheItem& /*aItem*/,
       
    52 							  TBool /*aMaySendRegStatusEvent*/,
       
    53 							  CSIPProfileServerCore& /*aServerCore*/)
       
    54 	{
       
    55 	PROFILE_DEBUG1("CSIPProfileState::EnterL")
       
    56 	}
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CSIPProfileState::RegisterL
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CSIPProfileState::RegisterL(CSIPProfileCacheItem& /*aItem*/)
       
    63 	{
       
    64     PROFILE_DEBUG1("CSIPProfileState::RegisterL")
       
    65 	User::Leave(KErrArgument);
       
    66 	}
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CSIPProfileState::RemoveL
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CSIPProfileState::RemoveL(CSIPProfileCacheItem& /*aItem*/)
       
    73 	{
       
    74 	PROFILE_DEBUG1("CSIPProfileState::RemoveL")
       
    75 	}
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CSIPProfileState::CanBePermanentlyRemoved
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 TBool CSIPProfileState::CanBePermanentlyRemoved(
       
    82 	const CSIPProfileCacheItem& /*aItem*/) const
       
    83 	{
       
    84 	PROFILE_DEBUG1("CSIPProfileState::CanBePermanentlyRemoved")
       
    85 	return EFalse;
       
    86 	}
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CSIPProfileState::UpdateRegistrationL
       
    90 // -----------------------------------------------------------------------------
       
    91 //			
       
    92 void CSIPProfileState::UpdateRegistrationL(
       
    93     CSIPProfileCacheItem& /*aItem*/,
       
    94 	const MSIPExtendedConcreteProfileObserver& /*aObserver*/)
       
    95     {
       
    96     PROFILE_DEBUG1("CSIPProfileState::UpdateRegistrationL")
       
    97     User::Leave(KErrArgument);
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CSIPProfileState::RegistrationStatusEventL
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CSIPProfileState::RegistrationStatusEventL(
       
   105 	CSIPProfileCacheItem& /*aItem*/,
       
   106 	CSIPConcreteProfile::TStatus /*aStatus*/)
       
   107 	{
       
   108 	PROFILE_DEBUG1("CSIPProfileState::RegistrationStatusEventL")
       
   109 	User::Leave(KErrArgument);
       
   110 	}
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CSIPProfileState::IapAvailableL
       
   114 // Migration is disallowed by default.
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CSIPProfileState::IapAvailableL(CSIPProfileCacheItem& aItem,
       
   118 									 TUint32 /*aSnapId*/,
       
   119 									 TUint32 aNewIapId)
       
   120 	{
       
   121 	PROFILE_DEBUG4("ProfileState::IapAvailableL(state,iap)",
       
   122 				   Name(),
       
   123 				   aNewIapId)
       
   124 
       
   125 	aItem.SetIAPRefreshReminder();
       
   126 	aItem.SetClientPermission(aNewIapId, NULL, EFalse);
       
   127 	}
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CSIPProfileState::ClientAllowsMigrationL
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CSIPProfileState::ClientAllowsMigrationL(
       
   134     CSIPProfileCacheItem& /*aItem*/,
       
   135 	TUint32 /*aIapId*/,
       
   136 	const MSIPExtendedConcreteProfileObserver& /*aObserver*/)
       
   137 	{
       
   138 	User::Leave(KErrArgument);
       
   139 	}
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CSIPProfileState::ClientDisallowsMigrationL
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CSIPProfileState::ClientDisallowsMigrationL(
       
   146     CSIPProfileCacheItem& /*aItem*/,
       
   147 	TUint32 /*aIapId*/,
       
   148 	const MSIPExtendedConcreteProfileObserver& /*aObserver*/)
       
   149 	{
       
   150 	User::Leave(KErrArgument);
       
   151 	}
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CSIPProfileState::MigrationIsAllowedL
       
   155 // By default, ignore the event.
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CSIPProfileState::MigrationIsAllowedL(CSIPProfileCacheItem& /*aItem*/,
       
   159 										   TUint32 /*aIapId*/)
       
   160 	{
       
   161 	}
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CSIPProfileState::MigrationIsDisallowedL
       
   165 // By default, ignore the event.
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CSIPProfileState::MigrationIsDisallowedL(CSIPProfileCacheItem& /*aItem*/,
       
   169 										      TUint32 /*aIapId*/)
       
   170 	{
       
   171 	}
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CSIPProfileState::DoCommonErrorOccurred
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CSIPProfileState::DoCommonErrorOccurred(CSIPProfileCacheItem& aItem) const
       
   178 	{
       
   179 	PROFILE_DEBUG4("ProfileState::DoCommonErrorOccurred state,id",
       
   180 				   Name(),
       
   181 				   aItem.ProfileId())
       
   182 
       
   183 	aItem.ClearOldProfile();
       
   184 	aItem.ClearMigrationProfiles();
       
   185 	}
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CSIPProfileState::DoCommonEnableL
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CSIPProfileState::DoCommonEnableL(CSIPProfileCacheItem& aItem,
       
   192 	const MSIPExtendedConcreteProfileObserver& aObserver) const
       
   193 	{
       
   194 	PROFILE_DEBUG4("ProfileState::DoCommonEnableL state,id",
       
   195 				   Name(),
       
   196 				   aItem.ProfileId())
       
   197 	__ASSERT_ALWAYS(!aItem.IsUser(aObserver), User::Leave(KErrAlreadyExists));
       
   198 	__ASSERT_ALWAYS(aItem.IsActiveState(), User::Leave(KErrNotFound));
       
   199 
       
   200 	aItem.MoveToUserL(aObserver);
       
   201 	}
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CSIPProfileState::DoCommonDisable
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 void CSIPProfileState::DoCommonDisable(
       
   208 	CSIPProfileCacheItem& aItem,
       
   209 	const MSIPExtendedConcreteProfileObserver& aObserver) const
       
   210 	{
       
   211 	PROFILE_DEBUG4("ProfileState::DoCommonDisable state,id",
       
   212 				   Name(),
       
   213 				   aItem.ProfileId())
       
   214 
       
   215 	aItem.RemoveUser(aObserver);
       
   216 	}
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CSIPProfileState::ShouldRefreshIAPs
       
   220 // Not all states handle "IAP available" event, so by default don't refresh IAPs
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 TBool CSIPProfileState::ShouldRefreshIAPs(CSIPProfileCacheItem& /*aItem*/) const
       
   224 	{
       
   225 	return EFalse;
       
   226 	}
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CSIPProfileState::IsAlrState
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 TBool CSIPProfileState::IsAlrState() const
       
   233 	{
       
   234 	return EFalse;
       
   235 	}
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CSIPProfileState::ShutdownInitiated
       
   239 // No action.
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 void CSIPProfileState::ShutdownInitiated(CSIPProfileCacheItem& /*aItem*/)
       
   243 	{
       
   244 	}
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CSIPProfileState::CanProfileBeUpdated
       
   248 // PluginDirector may have a pending register in (un)registered progress state,
       
   249 // but not in (un)register state.
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 TBool CSIPProfileState::CanProfileBeUpdated(CSIPProfileCacheItem& aItem) const
       
   253 	{
       
   254 	return !IsAlrState() &&
       
   255 		   !iPluginDirector.IsRegisterPending(aItem.UsedProfile());
       
   256 	}
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CSIPProfileState::IsInitialRegisterDone
       
   260 // Used in "wait for IAP", "wait for permission" and "migrating" states, so use
       
   261 // current profile (aItem.Profile()), not profile of new IAP
       
   262 // (aItem.UsedProfile()).
       
   263 //
       
   264 // NOTE: if IsInitialRegisterDone is used also from non-ALR states, use code:
       
   265 //		const CSIPConcreteProfile* profile = &aItem.Profile();
       
   266 //		if (!IsAlrState())
       
   267 //			{
       
   268 //			profile = &aItem.UsedProfile();
       
   269 //			}
       
   270 //		TBool done = (iPluginDirector.State(status, *profile) == KErrNone...
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 TBool CSIPProfileState::IsInitialRegisterDone(CSIPProfileCacheItem& aItem) const
       
   274 	{
       
   275 	// Check that in ALR-related state
       
   276 	__ASSERT_ALWAYS(IsAlrState(),
       
   277 		User::Panic(_L("ProfileState::IsInitRegDone"), KErrNotReady));
       
   278 	
       
   279 	CSIPConcreteProfile::TStatus status(CSIPConcreteProfile::EUnregistered);
       
   280 	TBool done = (iPluginDirector.State(status, aItem.Profile()) == KErrNone &&
       
   281 		   		  (status == CSIPConcreteProfile::ERegistered ||
       
   282 		   		   status == CSIPConcreteProfile::ERegistrationInProgress));
       
   283 	PROFILE_DEBUG4("ProfileState::IsInitRegDone id,done",
       
   284 				   aItem.ProfileId(),
       
   285 				   done)
       
   286 	return done;
       
   287 	}
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CSIPProfileState::RegisterWithIapL
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CSIPProfileState::RegisterWithIapL(CSIPProfileCacheItem& aItem,
       
   294 							  			TUint32 aIapId,
       
   295 							  			CSIPProfileState& aRegInProg) const
       
   296 	{
       
   297 	CSIPConcreteProfile& profile = aItem.Profile();
       
   298 	profile.SetIapId(aIapId);
       
   299 	iPluginDirector.RegisterL(profile);
       
   300 	aItem.ChangeStateL(&aRegInProg);
       
   301 	}
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CSIPProfileState::StartDeregisterL
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CSIPProfileState::StartDeregisterL(CSIPProfileCacheItem& aItem,
       
   308 										CSIPProfileState& aUnregInProg) const
       
   309 	{
       
   310 	PROFILE_DEBUG4("ProfileState::StartDeregisterL state,id",
       
   311 				   Name(),
       
   312 				   aItem.ProfileId())
       
   313 
       
   314 	iPluginDirector.DeregisterL(aItem.UsedProfile());
       
   315 	aItem.ChangeStateL(&aUnregInProg);
       
   316 	}
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // CSIPProfileState::DoUpdateL
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 TBool CSIPProfileState::DoUpdateL(CSIPConcreteProfile& aProfile,
       
   323 								  CSIPConcreteProfile& aOldProfile) const
       
   324 	{
       
   325 	iPluginDirector.UpdateRegistrationL(aProfile, aOldProfile);
       
   326 	// Get old profile's state
       
   327 	CSIPConcreteProfile::TStatus state;
       
   328 	iPluginDirector.State(state, aOldProfile);
       
   329 	return state == CSIPConcreteProfile::EUnregistrationInProgress;
       
   330 	}
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CSIPProfileState::RefreshIAPsFailed
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 void CSIPProfileState::RefreshIAPsFailed(CSIPProfileCacheItem& aItem) const
       
   337 	{
       
   338 	PROFILE_DEBUG4("ProfileState::RefreshIAPsFailed state,id",
       
   339 				   Name(),
       
   340 				   aItem.ProfileId())
       
   341 
       
   342 	iPluginDirector.TerminateHandling(aItem.UsedProfile());
       
   343 	DoCommonErrorOccurred(aItem);
       
   344 	}
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // CSIPProfileState::DisableWhileWaitingIAPL
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 void CSIPProfileState::DisableWhileWaitingIAPL(CSIPProfileCacheItem& aItem,
       
   351 	const MSIPExtendedConcreteProfileObserver& aObserver,
       
   352 	CSIPProfileState& aUnregInProg,
       
   353 	CSIPProfileState& aUnregistered) const
       
   354 	{
       
   355 	PROFILE_DEBUG3("ProfileState::DisableWhileWaitingIAPL id",
       
   356 				   aItem.ProfileId())
       
   357 
       
   358 	DoCommonDisable(aItem, aObserver);
       
   359 
       
   360 	if (!aItem.IsReferred())
       
   361 		{
       
   362 		if (IsInitialRegisterDone(aItem))
       
   363 			{
       
   364 			// Work as in Registered-state
       
   365 			StartDeregisterL(aItem, aUnregInProg);
       
   366 			}
       
   367 		else
       
   368 			{
       
   369 			aItem.ChangeStateL(&aUnregistered);
       
   370 			}
       
   371 		}
       
   372 	}
       
   373 
       
   374 // -----------------------------------------------------------------------------
       
   375 // CSIPProfileState::DisableWhileInProgressL
       
   376 // -----------------------------------------------------------------------------
       
   377 //
       
   378 void CSIPProfileState::DisableWhileInProgressL(CSIPProfileCacheItem& aItem,
       
   379 	CSIPProfileState& aUnregInProg,
       
   380 	CSIPProfileState& aUnregistered) const
       
   381 	{
       
   382 	PROFILE_DEBUG3("ProfileState::DisableWhileInProgressL id",
       
   383 				   aItem.ProfileId())
       
   384 
       
   385 	if (!aItem.IsReferred() &&
       
   386 		!iPluginDirector.IsRegisterPending(aItem.UsedProfile()))
       
   387 		{
       
   388 		CSIPConcreteProfile::TStatus status;
       
   389 		iPluginDirector.State(status, aItem.UsedProfile());
       
   390 		iPluginDirector.DeregisterL(aItem.UsedProfile());
       
   391 		if (status == CSIPConcreteProfile::ERegistrationInProgress)
       
   392 			{
       
   393 			aItem.ChangeStateL(&aUnregistered);
       
   394 			}
       
   395 		else
       
   396 			{
       
   397 			aItem.ChangeStateL(&aUnregInProg);
       
   398 			}
       
   399 		}
       
   400 	}
       
   401 
       
   402 // -----------------------------------------------------------------------------
       
   403 // CSIPProfileState::NoNewIapAvailable()
       
   404 // -----------------------------------------------------------------------------
       
   405 //
       
   406 void CSIPProfileState::NoNewIapAvailable(CSIPProfileCacheItem& /*aItem*/) 
       
   407 	{
       
   408 	PROFILE_DEBUG1("CSIPProfileState::NoNewIapAvailable")
       
   409 	}