commonappservices/alarmserver/Server/Source/ASSrvEnvironmentChangeManager.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1999-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 //
       
    15 
       
    16 #include "ASSrvEnvironmentChangeManager.h"
       
    17 
       
    18 // System includes
       
    19 
       
    20 // User includes
       
    21 #include "ASSrvStaticUtils.h"
       
    22 #include "ASSrvServerWideData.h"
       
    23 #include "ASSrvSessionCollection.h"
       
    24 #include "ASSrvEnvironmentChangeObserver.h"
       
    25 
       
    26 // Type definitions
       
    27 
       
    28 // Constants
       
    29 
       
    30 // Enumerations
       
    31 
       
    32 // Classes referenced
       
    33 
       
    34 
       
    35 //
       
    36 // ----> CASSrvEnvironmentChangeManager (source)
       
    37 //
       
    38 
       
    39 //*************************************************************************************
       
    40 CASSrvEnvironmentChangeManager::CASSrvEnvironmentChangeManager(CASSrvServerWideData& aServerWideData)
       
    41 :	iServerWideData(aServerWideData)
       
    42 	{
       
    43 	}
       
    44 
       
    45 
       
    46 //*************************************************************************************
       
    47 CASSrvEnvironmentChangeManager::~CASSrvEnvironmentChangeManager()
       
    48 	{
       
    49 	iObservers.Close();
       
    50 	delete iChangeNotifier;
       
    51 	}
       
    52 
       
    53 
       
    54 //*************************************************************************************
       
    55 void CASSrvEnvironmentChangeManager::ConstructL()
       
    56 	{
       
    57 	CachedWorkDays() = TLocale().WorkDays();
       
    58 
       
    59 #ifdef _DEBUG
       
    60 	iEnvChgHandling = ETrue;
       
    61 #endif	
       
    62 	
       
    63 	
       
    64 	// The priority of the change notifier should also be above that of the CASSrvAlarmTimer
       
    65 	// When the system time is moved forward, if the UI broadcasts multiple events, like locale change
       
    66 	// then at the end of handling of the first locale event, the alarm's due time is calculated as the old time
       
    67 	// and the timer is called with it. In the meantime if the system time is also changed then the timer
       
    68 	// expires with KErrUnderflow which causes the old alarm to go off.
       
    69 	iChangeNotifier = CEnvironmentChangeNotifier::NewL(CActive::EPriorityHigh+1, TCallBack(EnvironmentChangeCallBack, this));
       
    70 	iChangeNotifier->Start();
       
    71 	}
       
    72 
       
    73 
       
    74 //*************************************************************************************
       
    75 CASSrvEnvironmentChangeManager* CASSrvEnvironmentChangeManager::NewL(CASSrvServerWideData& aServerWideData)
       
    76 	{
       
    77 	CASSrvEnvironmentChangeManager* self = new(ELeave) CASSrvEnvironmentChangeManager(aServerWideData);
       
    78 	CleanupStack::PushL(self);
       
    79 	self->ConstructL();
       
    80 	CleanupStack::Pop(self);
       
    81 	return self;
       
    82 	}
       
    83 
       
    84 
       
    85 //
       
    86 //
       
    87 //
       
    88 
       
    89 
       
    90 //*************************************************************************************
       
    91 /**
       
    92  * Request environment change notifications
       
    93  */
       
    94 void CASSrvEnvironmentChangeManager::RequestEnvironmentChangesL(MASSrvEnvironmentChangeObserver& aObserver)
       
    95 	{
       
    96 	User::LeaveIfError(iObservers.InsertInAddressOrder(&aObserver));
       
    97 	}
       
    98 
       
    99 
       
   100 //*************************************************************************************
       
   101 /**
       
   102  * Cancel a previous change notification request
       
   103  */
       
   104 void CASSrvEnvironmentChangeManager::RequestEnvironmentChangesCancel(MASSrvEnvironmentChangeObserver& aObserver)
       
   105 	{
       
   106 	TInt index = KErrNotFound;
       
   107 	const TInt error = iObservers.FindInAddressOrder(&aObserver, index);
       
   108 	if	(error != KErrNotFound)
       
   109 		iObservers.Remove(index);
       
   110 	}
       
   111 
       
   112 
       
   113 //
       
   114 //
       
   115 //
       
   116 
       
   117 
       
   118 //*************************************************************************************
       
   119 /**
       
   120  * @internalComponent
       
   121  */
       
   122 TBool CASSrvEnvironmentChangeManager::EnvironmentChangeCallBack(TAny* aSelf)
       
   123 	{
       
   124 	CASSrvEnvironmentChangeManager& self = *reinterpret_cast<CASSrvEnvironmentChangeManager*>(aSelf);
       
   125 #ifdef _DEBUG	
       
   126 	if(!self.iEnvChgHandling)
       
   127 		{
       
   128 		 return ETrue;
       
   129 		}
       
   130 #endif	
       
   131 	self.HandleEnvironmentChange();
       
   132 	return ETrue;
       
   133 	}
       
   134 
       
   135 
       
   136 //
       
   137 //
       
   138 //
       
   139 
       
   140 
       
   141 //*************************************************************************************
       
   142 /**
       
   143  * Handle an environment change event
       
   144  */
       
   145 void CASSrvEnvironmentChangeManager::HandleEnvironmentChange()
       
   146 	{
       
   147 	 if	(!iHaveAbsorbedFirstChange)
       
   148 		{
       
   149 		iHaveAbsorbedFirstChange = ETrue;
       
   150 		return;
       
   151 		}
       
   152 
       
   153 	const TInt changes = iChangeNotifier->Change();
       
   154 	//
       
   155 	TBool workDaysChanged = EFalse;
       
   156 	if	(changes & EChangesLocale)
       
   157 		{
       
   158 		const TUint workdays = TLocale().WorkDays();
       
   159 		if	(workdays != CachedWorkDays())
       
   160 			{
       
   161 			CachedWorkDays() = workdays;
       
   162 			workDaysChanged = ETrue;
       
   163 			}
       
   164 		}
       
   165 
       
   166 	// Cascade changes to observers
       
   167 	const TInt count = iObservers.Count();
       
   168 	for(TInt i=0; i<count; i++)
       
   169 		{
       
   170 		iObservers[i]->MEnvChangeHandleEvent(changes, CachedWorkDays(), workDaysChanged);
       
   171 		}
       
   172 			
       
   173 	}
       
   174 
       
   175 
       
   176 
       
   177 
       
   178 
       
   179 
       
   180 
       
   181 
       
   182 
       
   183