diff -r 73a1feb507fb -r bc78a40cd63c mmshplugins/mmshsettingsuiplugin/src/mussipprofilemodel.cpp --- a/mmshplugins/mmshsettingsuiplugin/src/mussipprofilemodel.cpp Tue Aug 31 15:12:07 2010 +0300 +++ b/mmshplugins/mmshsettingsuiplugin/src/mussipprofilemodel.cpp Wed Sep 01 12:31:01 2010 +0100 @@ -12,40 +12,56 @@ * Contributors: * * Description: Model for managing SIP profiles. +* Version : %version: 19 % << Don't touch! Updated by Synergy at check-out. * */ +#include +#include #include "mussipprofilemodel.h" #include "muslogger.h" -#include -#include -#include -#include +#include "mussettings.inl" +#include "mussettingsmodel.h" -const TInt KSIPGranularity = 5; const TInt KUnknownProfileId = 0; // ======== MEMBER FUNCTIONS ======== +// ---------------------------------------------------------------------------- +// +// ---------------------------------------------------------------------------- +// CMusSIPProfileModel::CMusSIPProfileModel() { - MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::CMusSIPProfileModel()" ) } - +// ---------------------------------------------------------------------------- +// +// ---------------------------------------------------------------------------- +// void CMusSIPProfileModel::ConstructL() { MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ConstructL()" ) + + MUS_LOG( "[MUSSET] Creating CSIPManagedProfileRegistry " ) iEngine = CSIPManagedProfileRegistry::NewL( *this ); - ReadArrayFromEngineL(); + MUS_LOG( "[MUSSET] Done " ) + MUS_LOG( "[MUSSET] Getting profiles " ) + iEngine->ProfilesL( iProfiles ); + MUS_LOG( "[MUSSET] Done " ) + SortProfilesL(); + MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ConstructL()" ) } - +// ---------------------------------------------------------------------------- +// +// ---------------------------------------------------------------------------- +// CMusSIPProfileModel* CMusSIPProfileModel::NewL() { MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::NewL()" ) @@ -59,30 +75,28 @@ return self; } - +// ---------------------------------------------------------------------------- +// +// ---------------------------------------------------------------------------- +// CMusSIPProfileModel::~CMusSIPProfileModel() { MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::~CMusSIPProfileModel()" ) - DeleteProfiles(); + iProfiles.ResetAndDestroy(); delete iEngine; - iEngine = NULL; MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::~CMusSIPProfileModel()" ) } - // ---------------------------------------------------------------------------- -// Returns pointer to the locally cached SIP profile array. +// Returns reference to the locally cached SIP profile array. // ---------------------------------------------------------------------------- // -CArrayPtr* CMusSIPProfileModel::ProfileArrayL() +RPointerArray& CMusSIPProfileModel::ProfileArrayL() { - MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ProfileArrayL()" ) - ReadProfileListFromEngineSafeL(); - MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileArrayL()" ) + MUS_LOG( "[MUSSET] <-> CMusSIPProfileModel::ProfileArrayL()" ) return iProfiles; } - // ---------------------------------------------------------------------------- // Returns index to the default SIP profile in locally cached array. // ---------------------------------------------------------------------------- @@ -92,12 +106,12 @@ MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DefaultProfileIndex()" ) TInt index( KErrNotFound ); - for ( TInt i = 0; i < iProfiles->Count(); i++ ) + for ( TInt i = 0; i < iProfiles.Count(); i++ ) { TBool defProfile( EFalse ); if ( KErrNone == - iProfiles->At( i )->GetParameter( KSIPDefaultProfile, defProfile ) + iProfiles[i]->GetParameter( KSIPDefaultProfile, defProfile ) && defProfile ) { index = i; @@ -110,7 +124,6 @@ return index; } - // ---------------------------------------------------------------------------- // Returns id of the default SIP profile. If default SIP profile is not found // KUnknownProfileId is returned. @@ -121,16 +134,14 @@ MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DefaultProfileId()" ) TUint32 id( KUnknownProfileId ); - for ( TInt i = 0; i < iProfiles->Count(); i++ ) + for ( TInt i = 0; i < iProfiles.Count(); i++ ) { TBool defProfile( EFalse ); - if ( - KErrNone == - iProfiles->At( i )->GetParameter( KSIPDefaultProfile, defProfile ) - && defProfile ) + TInt error = iProfiles[i]->GetParameter( KSIPDefaultProfile, defProfile ); + if ( error == KErrNone && defProfile ) { - iProfiles->At( i )->GetParameter( KSIPProfileId, id ); - break; + iProfiles[i]->GetParameter( KSIPProfileId, id ); + break; } } @@ -139,6 +150,66 @@ return id; } +// ----------------------------------------------------------------------------- +// Disable SIP Registration. +// ----------------------------------------------------------------------------- +// +void CMusSIPProfileModel::DisableProfileL() + { + MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DisableProfileL " ) + CSIPManagedProfile* managedProfile = static_cast( + iEngine->ProfileL( DefaultProfileId()) ); + CleanupStack::PushL( managedProfile ); + MUS_LOG( "[MUSSET] Add registration parameter to profile.dat file " ) + //set autoregistration off (i.e. when needed) => disable profile + User::LeaveIfError( managedProfile->SetParameter( KSIPAutoRegistration, EFalse ) ); + MUS_LOG( "[MUSSET] Saving profile " ) + iEngine->SaveL( *managedProfile ); + MUS_LOG( "[MUSSET] Saved" ) + CleanupStack::PopAndDestroy( managedProfile ); + MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::DisableProfileL " ) + } + +// ----------------------------------------------------------------------------- +// Enable SIP Registration. +// ----------------------------------------------------------------------------- +// +void CMusSIPProfileModel::EnableProfileL() + { + MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::EnableProfileL " ) + CSIPManagedProfile* managedProfile = static_cast( + iEngine->ProfileL( DefaultProfileId() ) ); + CleanupStack::PushL( managedProfile ); + MUS_LOG( "[MUSSET] Add registration parameters to profile.dat file " ) + //set autoregistration on (i.e. always on) => enable profile + User::LeaveIfError( managedProfile->SetParameter( KSIPAutoRegistration, ETrue ) ); + MUS_LOG( "[MUSSET] Saving profile " ) + iEngine->SaveL( *managedProfile ); + MUS_LOG( "[MUSSET] Saved" ) + CleanupStack::PopAndDestroy( managedProfile ); + MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::EnableRegisterL " ) + } + +// ----------------------------------------------------------------------------- +// if SIP Registration enabled. +// ----------------------------------------------------------------------------- +// +TBool CMusSIPProfileModel::ProfileEnabledL() + { + MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ProfileEnabledL " ) + CSIPManagedProfile* managedProfile = static_cast( + iEngine->ProfileL( DefaultProfileId() ) ); + CleanupStack::PushL( managedProfile ); + TBool enabled; + MUS_LOG( "[MUSSET] Getting KSIPAutoRegistration" ) + User::LeaveIfError( + managedProfile->GetParameter( KSIPAutoRegistration, enabled ) ); + MUS_LOG( "[MUSSET] Done" ) + MUS_LOG1( "[MUSSET] KSIPAutoRegistration=%d", enabled ) + CleanupStack::PopAndDestroy( managedProfile ); + MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileEnabledL " ) + return enabled; + } // ---------------------------------------------------------------------------- // Returns index of the default SIP profile on locally cached array. If default @@ -149,14 +220,12 @@ { MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ProfileIndexByIdL()" ) TInt index( KErrNotFound ); - - ReadProfileListFromEngineSafeL(); - for ( TInt i = 0; i < iProfiles->Count(); i++ ) + + for ( TInt i = 0; i < iProfiles.Count(); i++ ) { TUint32 id( KUnknownProfileId ); - - if ( KErrNone == iProfiles->At( i )->GetParameter( KSIPProfileId, id ) - && id == aId ) + TInt error = iProfiles[i]->GetParameter( KSIPProfileId, id ); + if ( error == KErrNone && id == aId ) { index = i; break; @@ -178,10 +247,9 @@ MUS_LOG1( "[MUSSET] -> CMusSIPProfileModel::ProfileIdByIndex()( %d )", aIndex ) TUint32 profileId( KUnknownProfileId ); - if ( iProfiles->Count() > aIndex ) + if ( aIndex < iProfiles.Count() ) { - if ( iProfiles->At( aIndex )->GetParameter( - KSIPProfileId, profileId ) ) + if ( iProfiles[aIndex]->GetParameter( KSIPProfileId, profileId ) ) { profileId = KUnknownProfileId; } @@ -191,41 +259,6 @@ return profileId; } - -// ---------------------------------------------------------------------------- -// Reads SIP profiles from SIP Profile Client array to locally cached array. -// ---------------------------------------------------------------------------- -// -void CMusSIPProfileModel::ReadArrayFromEngineL() - { - MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ReadArrayFromEngineL()" ) - - DeleteProfiles(); - - // Create the profile pointer array - iProfiles = - new ( ELeave ) CArrayPtrFlat( KSIPGranularity ); - - RPointerArray profilePointerArray; - TCleanupItem clItem( ResetAndDestroy, &profilePointerArray ); - CleanupStack::PushL( clItem ); - - iEngine->ProfilesL( profilePointerArray ); - for ( TInt i = 0; i < profilePointerArray.Count(); i++ ) - { - iProfiles->AppendL( - static_cast( profilePointerArray[i] ) ); - } - - profilePointerArray.Reset(); - CleanupStack::PopAndDestroy(); // clItem (profilePointerArray) - - SortProfilesL(); - - MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ReadArrayFromEngineL()" ) - } - - // ---------------------------------------------------------------------------- // Sorts internal array of SIP profiles by id. Used algorithm is generally // slower than quicksort and selectionsort but very feasible for expected @@ -236,52 +269,69 @@ { TUint32 profileIdFirst( 0 ); TUint32 profileIdSecond( 0 ); - for ( TInt a = 0; a < iProfiles->Count() - 1; a++ ) + for ( TInt a = 0; a < iProfiles.Count() - 1; a++ ) { - for ( TInt b = a + 1; b < iProfiles->Count(); b++ ) + for ( TInt b = a + 1; b < iProfiles.Count(); b++ ) { - User::LeaveIfError( iProfiles->At( a )->GetParameter( + User::LeaveIfError( iProfiles[a]->GetParameter( KSIPProfileId, profileIdFirst ) ); - User::LeaveIfError( iProfiles->At( b )->GetParameter( + User::LeaveIfError( iProfiles[b]->GetParameter( KSIPProfileId, profileIdSecond ) ); if ( profileIdFirst > profileIdSecond ) { - CSIPManagedProfile* tmp = iProfiles->At( b ); - iProfiles->At( b ) = iProfiles->At( a ); - iProfiles->At( a ) = tmp; + CSIPProfile* tmp = iProfiles[b]; + iProfiles[b] = iProfiles[a]; + iProfiles[a] = tmp; } } } } - -// ---------------------------------------------------------------------------- -// Deletes internally cached SIP profiles. -// ---------------------------------------------------------------------------- -// -void CMusSIPProfileModel::DeleteProfiles() - { - if ( iProfiles ) - { - iProfiles->ResetAndDestroy(); - delete iProfiles; - iProfiles = NULL; - } - } - - // ---------------------------------------------------------------------------- // From class MSIPProfileRegistryObserver. // Notifies of an event in SIP profile registry. // ---------------------------------------------------------------------------- // void CMusSIPProfileModel::ProfileRegistryEventOccurred( - TUint32 /*aSIPProfileId*/, TEvent /*aEvent*/ ) - { + TUint32 aSIPProfileId, TEvent aEvent ) + { + MUS_LOG("[MUSSET] -> CMusSIPProfileModel::ProfileRegistryEventOccurred()" ) + MUS_LOG2(" SIPProfileId is %d,Event is %d",aSIPProfileId,aEvent) + + // We revert back to default settings if the profile used by MuS is deleted + if ( aEvent == EProfileDestroyed ) + { + TRAP_IGNORE( + //if the profile is the profile used by mush + if ( MultimediaSharingSettings::SipProfileSettingL() == + aSIPProfileId ) + { + //set the profile to default + MultimediaSharingSettings::SetSipProfileSettingL( + CMusSettingsModel::KVsSipProfileDefault ); + //set mush off + MultimediaSharingSettings::SetActivationSettingL( + MusSettingsKeys::EActiveInHomeNetworks ); + } + ); + } + + if ( aEvent == EProfileCreated || + aEvent == EProfileUpdated || + aEvent == EProfileDestroyed ) + { + // Profiles have been manipulated in SIP side, we must delete client + // side profile objects and retrieve them again. If fetching fails, + // we have empty array which is better than showing wrong values to + // user. + iProfiles.ResetAndDestroy(); + TRAP_IGNORE( iEngine->ProfilesL( iProfiles ) ); + TRAP_IGNORE( SortProfilesL() ); + } + MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileRegistryEventOccurred()" ) } - // ---------------------------------------------------------------------------- // From class MSIPProfileRegistryObserver. // An asynchronous error has occurred related to SIP profile @@ -294,50 +344,11 @@ MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileRegistryErrorOccurred()" ) } - // ---------------------------------------------------------------------------- -// Reads SIP profile list from engine; if reading fails, old cached list is -// kept and returned. +//Set CMusSettingsModel to handle ProfileRegistry Event. // ---------------------------------------------------------------------------- // -void CMusSIPProfileModel::ReadProfileListFromEngineSafeL() - { - MUS_LOG( - "[MUSSET] -> CMusSIPProfileModel::ReadProfileListFromEngineSafeL()" ) - // To prevent complete disaster it we'll save the pointer of the old array - CArrayPtrFlat* profiles = iProfiles; - iProfiles = 0; - TRAPD( error, ReadArrayFromEngineL() ); - - if ( error ) - { - // Problems with re-reading profiles; use existing array - DeleteProfiles(); - iProfiles = profiles; - User::Leave( error ); - } - else - { - // No problems; delete backup array - profiles->ResetAndDestroy(); - delete profiles; - } - MUS_LOG( - "[MUSSET] <- CMusSIPProfileModel::ReadProfileListFromEngineSafeL()" ) - } - - -// ---------------------------------------------------------------------------- -// For deleting RPointerArray in case of leave (used in association with -// TCleanupItem). -// ---------------------------------------------------------------------------- -// -void CMusSIPProfileModel::ResetAndDestroy( TAny* aPointerArray ) - { - MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ResetAndDestroy()" ) - RPointerArray* array = - static_cast*>( aPointerArray ); - array->ResetAndDestroy(); - array->Close(); - MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ResetAndDestroy()" ) - } +void CMusSIPProfileModel::SetCMusSettingsModel(CMusSettingsModel* aCMusSettingsModel) + { + iCMusSettingsModel = aCMusSettingsModel; + }