mmfenh/profilesettingsmonitor/src/ProfileSettingsMonitorServerImpl.cpp
changeset 0 71ca22bcf22a
child 19 095bea5f582e
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2 * Copyright (c) 2007 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:  This file contains implementation of 
       
    15                     ProfileSettingsMonitorServerImpl.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "ProfileSettingsMonitorServerImpl.h"
       
    21 #include <AudioClientsListPSKeys.h>
       
    22 #include <AudioClientsListPSData.h>
       
    23 #include <MediaStreamPropertiesPSKeys.h>
       
    24 
       
    25 #ifdef _DEBUG
       
    26 #define DEB_TRACE0(str)             RDebug::Print(str)
       
    27 #define DEB_TRACE1(str, val1)       RDebug::Print(str, val1)
       
    28 #else
       
    29 #define DEB_TRACE0(str)
       
    30 #define DEB_TRACE1(str, val1)
       
    31 #endif // _DEBUG
       
    32 
       
    33 
       
    34 static _LIT_SECURITY_POLICY_PASS(KClientStateReadPolicy);
       
    35 static _LIT_SECURITY_POLICY_S0(KMMFAudioServerSIDPolicy, KUidMmfAudioServerDllUnicodeDefine);
       
    36 
       
    37 
       
    38 CProfileSettingsMonitorServerImpl::CProfileSettingsMonitorServerImpl()
       
    39 	{
       
    40 	}
       
    41 
       
    42 CProfileSettingsMonitorServerImpl::~CProfileSettingsMonitorServerImpl()
       
    43 	{
       
    44 	iWarningTonesProperty.Close();
       
    45 	RProperty::Delete(KGASPSUidGlobalAudioSettings, KGASWarningTones);
       
    46 	
       
    47 	iMessagingTonesProperty.Close();
       
    48 	RProperty::Delete(KGASPSUidGlobalAudioSettings, KGASMessageTones);
       
    49 	
       
    50 	iSilentProfileProperty.Close();
       
    51 	RProperty::Delete(KGASPSUidGlobalAudioSettings, KGASSilentProfile);
       
    52 	
       
    53 	iVibraProperty.Close();
       
    54 	RProperty::Delete(KGASPSUidGlobalAudioSettings, KGASVibra);
       
    55 	
       
    56 	// Release profile engine resources
       
    57 	if ( iEngine )
       
    58 	    {
       
    59 	    iEngine->Release();
       
    60 	    }
       
    61 	delete iEngine;
       
    62 	delete iNotifyHandler;
       
    63 	}
       
    64 
       
    65 CProfileSettingsMonitorServerImpl* CProfileSettingsMonitorServerImpl::NewL()
       
    66 	{
       
    67 	CProfileSettingsMonitorServerImpl* s = new(ELeave) CProfileSettingsMonitorServerImpl();
       
    68 	CleanupStack::PushL(s);
       
    69 	s->ConstructL();
       
    70 	CleanupStack::Pop();
       
    71 	return s;
       
    72 	}
       
    73 
       
    74 void CProfileSettingsMonitorServerImpl::ConstructL()
       
    75 	{
       
    76     iEngine = ProEngFactory::NewEngineL();
       
    77     iNotifyHandler = ProEngFactory::NewNotifyHandlerL();    
       
    78     User::LeaveIfError( iNotifyHandler->RequestProfileActivationNotificationsL( *this ));    
       
    79     User::LeaveIfError( iNotifyHandler->RequestActiveProfileNotificationsL( *this ));
       
    80     
       
    81     // Initialize iSilentProfile
       
    82     iActiveProfileId = iEngine->ActiveProfileId();
       
    83     if(iActiveProfileId == 1) 
       
    84         iSilentProfile = ETrue;
       
    85     else
       
    86         iSilentProfile = EFalse;
       
    87     
       
    88     // Initialize iWarningTones, iMessagingTones and iVibra
       
    89     MProEngProfile* currentProfile = iEngine->ActiveProfileL();
       
    90     //CleanupStack::PushL(currentProfile);
       
    91     MProEngToneSettings& settings = currentProfile->ToneSettings();
       
    92     iWarningTones = settings.WarningAndGameTones();
       
    93     iMessagingTones = !( currentProfile->IsSilent() );
       
    94     iVibra = settings.VibratingAlert();
       
    95     //CleanupStack::PopAndDestroy(currentProfile);
       
    96     
       
    97     // Get PublicSilence from CenRep
       
    98     TInt featureBitmask( 0 );     
       
    99     CRepository* profileCenRep = CRepository::NewL( KCRUidProfilesLV );
       
   100     CleanupStack::PushL(profileCenRep);
       
   101     User::LeaveIfError( profileCenRep->Get( KProfilesLVFlags, featureBitmask ) );
       
   102     if  ( featureBitmask & KProEngFeatureIdForceSilentMode )
       
   103         iPublicSilence = ETrue;
       
   104     else
       
   105         iPublicSilence = EFalse;
       
   106     CleanupStack::PopAndDestroy(profileCenRep);
       
   107     
       
   108     TSecurityPolicy read = TSecurityPolicy(ECapabilityWriteDeviceData);
       
   109     TSecurityPolicy write = TSecurityPolicy(ECapabilityMultimediaDD);
       
   110 
       
   111     // Define and Initialize Warning Tones PnS key
       
   112     User::LeaveIfError(RProperty::Define(
       
   113                                     KGASPSUidGlobalAudioSettings,
       
   114                                     KGASWarningTones,
       
   115                                     RProperty::EInt,
       
   116                                     read,
       
   117                                     write));	    
       
   118     User::LeaveIfError(iWarningTonesProperty.Attach(
       
   119                                                 KGASPSUidGlobalAudioSettings,
       
   120                                                 KGASWarningTones));
       
   121     User::LeaveIfError(iWarningTonesProperty.Set(
       
   122                                                 KGASPSUidGlobalAudioSettings,
       
   123                                                 KGASWarningTones,
       
   124                                                 iWarningTones));
       
   125     
       
   126     // Define and Initialize Messaging Tones PnS key
       
   127     User::LeaveIfError(RProperty::Define(
       
   128                                     KGASPSUidGlobalAudioSettings,
       
   129                                     KGASMessageTones,
       
   130                                     RProperty::EInt,
       
   131                                     read,
       
   132                                     write));
       
   133     User::LeaveIfError(iMessagingTonesProperty.Attach(
       
   134                                                 KGASPSUidGlobalAudioSettings,
       
   135                                                 KGASMessageTones));
       
   136     User::LeaveIfError(iMessagingTonesProperty.Set(
       
   137                                                 KGASPSUidGlobalAudioSettings,
       
   138                                                 KGASMessageTones,
       
   139                                                 iMessagingTones));
       
   140     
       
   141     // Define and Initialize Silent Profile PnS key
       
   142      User::LeaveIfError(RProperty::Define(
       
   143                                     KGASPSUidGlobalAudioSettings,
       
   144                                     KGASSilentProfile,
       
   145                                     RProperty::EInt,
       
   146                                     read,
       
   147                                     write));
       
   148     User::LeaveIfError(iSilentProfileProperty.Attach(
       
   149                                                 KGASPSUidGlobalAudioSettings,
       
   150                                                 KGASSilentProfile));
       
   151     User::LeaveIfError(iSilentProfileProperty.Set(
       
   152                                                 KGASPSUidGlobalAudioSettings,
       
   153                                                 KGASSilentProfile,
       
   154                                                 iSilentProfile));
       
   155     
       
   156     // Define and Initialize Vibra PnS key
       
   157     User::LeaveIfError(RProperty::Define(
       
   158                                     KGASPSUidGlobalAudioSettings,
       
   159                                     KGASVibra,
       
   160                                     RProperty::EInt,
       
   161                                     read,
       
   162                                     write));
       
   163     User::LeaveIfError(iVibraProperty.Attach(
       
   164                                         KGASPSUidGlobalAudioSettings,
       
   165                                         KGASVibra));
       
   166     User::LeaveIfError(iVibraProperty.Set(
       
   167                                         KGASPSUidGlobalAudioSettings,
       
   168                                         KGASVibra,
       
   169                                         iVibra));
       
   170                         
       
   171     // Define and Initialize Public Silence PnS key
       
   172     User::LeaveIfError(RProperty::Define(
       
   173                                     KGASPSUidGlobalAudioSettings,
       
   174                                     KGASPublicSilence,
       
   175                                     RProperty::EInt,
       
   176                                     read,
       
   177                                     write));
       
   178     User::LeaveIfError(iPublicSilenceProperty.Attach(
       
   179                                                 KGASPSUidGlobalAudioSettings,
       
   180                                                 KGASPublicSilence));
       
   181     User::LeaveIfError(iPublicSilenceProperty.Set(
       
   182                                                 KGASPSUidGlobalAudioSettings,
       
   183                                                 KGASPublicSilence,
       
   184                                                 iPublicSilence));
       
   185 
       
   186     //Stream Gain Control
       
   187     TInt status = RProperty::Define(
       
   188                                 KPSUidMediaStreamProperties,
       
   189                                 KMediaStreamCurrentGain,
       
   190                                 RProperty::EInt,
       
   191                                 read,
       
   192                                 write);
       
   193     if ( status != KErrAlreadyExists )
       
   194 	    User::LeaveIfError(status);
       
   195 
       
   196     // Audio Clients List
       
   197     InitializeAudioClientsListPSKeysL();
       
   198     }
       
   199 
       
   200 void CProfileSettingsMonitorServerImpl::InitializeAudioClientsListPSKeysL()
       
   201     {
       
   202     DEB_TRACE0(_L("CProfileSettingsMonitorServerImpl::InitializeAudioClientsListPSKeysL:Enter"));
       
   203 	// define KAudioPolicyApplicationAudioStatePlaying property to be a byte array
       
   204 	TInt status = RProperty::Define(KPSUidMMFAudioServer,
       
   205 	                                KAudioPolicyApplicationAudioStatePlaying,
       
   206 	                                RProperty::EByteArray,
       
   207 		                            KClientStateReadPolicy,
       
   208 		                            KMMFAudioServerSIDPolicy,
       
   209 		                            sizeof(struct TAudioPolicyProcessIdListStruct));
       
   210 	DEB_TRACE1(_L("Define KAudioPolicyApplicationAudioStatePlaying returns %d"), status);
       
   211 	if (status != KErrAlreadyExists)
       
   212 	    {
       
   213 	    User::LeaveIfError(status);
       
   214 	    }
       
   215 
       
   216 	// define KAudioPolicyApplicationAudioStateRecording property to be a byte array
       
   217 	status = RProperty::Define(KPSUidMMFAudioServer,
       
   218 	                           KAudioPolicyApplicationAudioStateRecording,
       
   219 	                           RProperty::EByteArray,
       
   220 	                           KClientStateReadPolicy,
       
   221 	                           KMMFAudioServerSIDPolicy,
       
   222 	                           sizeof(struct TAudioPolicyProcessIdListStruct));
       
   223 	DEB_TRACE1(_L("Define KAudioPolicyApplicationAudioStateRecording returns %d"), status);
       
   224 	if (status != KErrAlreadyExists)
       
   225 	    {
       
   226 	    User::LeaveIfError(status);
       
   227 	    }
       
   228 
       
   229 	// define KAudioPolicyApplicationAudioStatePaused property to be a byte array
       
   230 	status = RProperty::Define(KPSUidMMFAudioServer,
       
   231 	                           KAudioPolicyApplicationAudioStatePaused,
       
   232 	                           RProperty::EByteArray,
       
   233 	                           KClientStateReadPolicy,
       
   234 	                           KMMFAudioServerSIDPolicy,
       
   235 	                           sizeof(struct TAudioPolicyProcessIdListStruct));
       
   236 	DEB_TRACE1(_L("Define KAudioPolicyApplicationAudioStatePaused returns %d"), status);
       
   237 	if (status != KErrAlreadyExists)
       
   238     	{
       
   239     	User::LeaveIfError(status);
       
   240     	}
       
   241 
       
   242 	// define KAudioPolicyForceMutedClients property to be a byte array
       
   243 	status = RProperty::Define(KPSUidMMFAudioServer,
       
   244 	                           KAudioPolicyForceMutedClients,
       
   245 	                           RProperty::EByteArray,
       
   246 	                           KClientStateReadPolicy,
       
   247 	                           KMMFAudioServerSIDPolicy,
       
   248 	                           sizeof(struct TAudioPolicyProcessIdListStruct));
       
   249 	DEB_TRACE1(_L("Define KAudioPolicyForceMutedClients returns %d"), status);
       
   250 	if (status != KErrAlreadyExists)
       
   251     	{
       
   252     	User::LeaveIfError(status);
       
   253     	}
       
   254 
       
   255 	// define KAudioPolicyAudioClients property to be a byte array
       
   256 	status = RProperty::Define(KPSUidMMFAudioServer,
       
   257 	                           KAudioPolicyAudioClients,
       
   258 	                           RProperty::EByteArray,
       
   259 	                           KClientStateReadPolicy,
       
   260 	                           KMMFAudioServerSIDPolicy,
       
   261 	                           sizeof(struct TAudioClientListStruct));
       
   262 	DEB_TRACE1(_L("Define KAudioPolicyAudioClients returns %d"), status);
       
   263 	if (status != KErrAlreadyExists)
       
   264     	{
       
   265     	User::LeaveIfError(status);
       
   266     	}
       
   267     DEB_TRACE0(_L("CProfileSettingsMonitorServerImpl::InitializeAudioClientsListPSKeysL:Exit"));
       
   268     }
       
   269 
       
   270 void CProfileSettingsMonitorServerImpl::HandleProfileActivatedL( TInt aProfileId )
       
   271     {
       
   272     DEB_TRACE1(_L("CProfileSettingsMonitorServerImpl::HandleProfileActivatedL[%d]"), aProfileId);
       
   273     
       
   274     if ( iActiveProfileId != aProfileId )
       
   275         {
       
   276         MProEngProfile* currentProfile = iEngine->ActiveProfileL();
       
   277         CleanupReleasePushL(*currentProfile);
       
   278         
       
   279         TBool silentProfile;
       
   280         iActiveProfileId = aProfileId;
       
   281         //iActiveProfileId = iEngine->ActiveProfileId();
       
   282         
       
   283         if(iActiveProfileId == 1) // Silent profile is always '1'
       
   284             silentProfile = ETrue;
       
   285         else
       
   286             silentProfile = EFalse;
       
   287         
       
   288         if(silentProfile != iSilentProfile)
       
   289             {
       
   290             iSilentProfile = silentProfile;
       
   291             User::LeaveIfError(iSilentProfileProperty.Set(
       
   292                                                         KGASPSUidGlobalAudioSettings,
       
   293                                                         KGASSilentProfile,
       
   294                                                         iSilentProfile));
       
   295             }
       
   296             
       
   297         MProEngToneSettings& settings = currentProfile->ToneSettings();
       
   298         
       
   299         if(iWarningTones != settings.WarningAndGameTones())
       
   300             {
       
   301             iWarningTones = settings.WarningAndGameTones();
       
   302             User::LeaveIfError(iWarningTonesProperty.Set(
       
   303                                                         KGASPSUidGlobalAudioSettings,
       
   304                                                         KGASWarningTones,
       
   305                                                         iWarningTones));
       
   306             }
       
   307         
       
   308         if(iMessagingTones != (!( currentProfile->IsSilent() )))
       
   309             {
       
   310             iMessagingTones = !( currentProfile->IsSilent() );
       
   311             User::LeaveIfError(iMessagingTonesProperty.Set(
       
   312                                                         KGASPSUidGlobalAudioSettings,
       
   313                                                         KGASMessageTones,
       
   314                                                         iMessagingTones));
       
   315             }
       
   316         if(iVibra != settings.VibratingAlert())
       
   317             {
       
   318             iVibra = settings.VibratingAlert();
       
   319             User::LeaveIfError(iVibraProperty.Set(
       
   320                                                 KGASPSUidGlobalAudioSettings,
       
   321                                                 KGASVibra,
       
   322                                                 iVibra));
       
   323             }
       
   324         CleanupStack::PopAndDestroy(currentProfile);
       
   325         }
       
   326 #ifdef _DEBUG
       
   327     else
       
   328         {
       
   329         RDebug::Print(_L("CProfileSettingsMonitorServerImpl::HandleProfileActivatedL[%d]- \
       
   330             Activated is same as current profile"), aProfileId);
       
   331         }
       
   332 #endif // _DEBUG    
       
   333     }
       
   334 
       
   335 void CProfileSettingsMonitorServerImpl::HandleProfileActivationNotificationError( TInt /*aError*/ )
       
   336     {
       
   337     DEB_TRACE0(_L("CMyProfileNameArrayObserver::HandleProfileActivationNotificationError"));
       
   338 	}
       
   339 
       
   340 void CProfileSettingsMonitorServerImpl::HandleActiveProfileModifiedL()
       
   341     {
       
   342     DEB_TRACE0(_L("CProfileSettingsMonitorServerImpl::HandleActiveProfileModifiedL"));
       
   343     
       
   344     iActiveProfileId = iEngine->ActiveProfileId();
       
   345     MProEngProfile* currentProfile = iEngine->ActiveProfileL();
       
   346     CleanupReleasePushL(*currentProfile);
       
   347     
       
   348     MProEngToneSettings& settings = currentProfile->ToneSettings();
       
   349     if(iWarningTones != settings.WarningAndGameTones())
       
   350         {
       
   351         iWarningTones = settings.WarningAndGameTones();
       
   352         User::LeaveIfError(iWarningTonesProperty.Set(
       
   353                                                     KGASPSUidGlobalAudioSettings,
       
   354                                                     KGASWarningTones,
       
   355                                                     iWarningTones));
       
   356         }
       
   357     if(iMessagingTones != (!( currentProfile->IsSilent() )))
       
   358         {
       
   359         iMessagingTones = !( currentProfile->IsSilent() );
       
   360         User::LeaveIfError(iMessagingTonesProperty.Set(
       
   361                                                     KGASPSUidGlobalAudioSettings,
       
   362                                                     KGASMessageTones,
       
   363                                                     iMessagingTones));
       
   364         }
       
   365 
       
   366     if(iVibra != settings.VibratingAlert())
       
   367         {
       
   368         iVibra = settings.VibratingAlert();
       
   369         User::LeaveIfError(iVibraProperty.Set(
       
   370                                             KGASPSUidGlobalAudioSettings,
       
   371                                             KGASVibra,
       
   372                                             iVibra));
       
   373         }
       
   374     CleanupStack::PopAndDestroy(currentProfile);
       
   375     }
       
   376 
       
   377 void CProfileSettingsMonitorServerImpl::HandleActiveProfileNotificationError( TInt /*aError*/ )
       
   378     {
       
   379     DEB_TRACE0(_L("CMyProfileNameArrayObserver::HandleProfileActivationNotificationError"));
       
   380 	}
       
   381 
       
   382 // End of file
       
   383