networkprotocolmodules/suplprotocolmodule/HostSettingsApi/src/lbshostsettingsnotifier.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     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 // An Active Object that requests and handles change notification requests from the CenRep 
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalAll
       
    21  @deprecated 
       
    22 */
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <e32debug.h>
       
    26 #include "lbshostsettingsnotifier.h"
       
    27 #include <lbs/lbshostsettingsclasstypes.h>
       
    28 #include "lbshostsettingsconsts.h"
       
    29 
       
    30 const TUid KInvalidSettingsId = {-1};
       
    31 
       
    32 /**
       
    33 Create new instance of notifier
       
    34 
       
    35 @param aStoreId		Host settings store ID
       
    36 @param aRepository	Repository
       
    37 @param aObserver	Observer that is to receive notifications
       
    38 @return New notifier
       
    39 */
       
    40 CLbsHostSettingsNotifier* CLbsHostSettingsNotifier::NewL(TLbsHostStoreId aStoreId, CRepository& aRepository, MLbsHostSettingsStoreObserver* aObserver)
       
    41 	{
       
    42 	ASSERT(aObserver);
       
    43 	CLbsHostSettingsNotifier* self = new(ELeave) CLbsHostSettingsNotifier(aStoreId, aRepository, aObserver);
       
    44 	return self;
       
    45 	}
       
    46 
       
    47 /**
       
    48 Constructor. Add notifier to the current active scheduler.
       
    49 */
       
    50 CLbsHostSettingsNotifier::CLbsHostSettingsNotifier(TLbsHostStoreId aStoreId, CRepository& aRepository, MLbsHostSettingsStoreObserver* aObserver) : 
       
    51 	CActive(EPriorityStandard), iRepository(aRepository), iStoreId(aStoreId), iObserver(aObserver), iSuppressSettingsId(KInvalidSettingsId)
       
    52 	{
       
    53 	CActiveScheduler::Add(this);
       
    54 	}
       
    55 
       
    56 /**
       
    57 Destructor. Cancel notifications.
       
    58 */
       
    59 CLbsHostSettingsNotifier::~CLbsHostSettingsNotifier()
       
    60 	{
       
    61 	Cancel();
       
    62 	}
       
    63 
       
    64 /**
       
    65 Request notification about changes to LBS Host Settings from CenRep
       
    66 
       
    67 @leave Error code from CenRep
       
    68 */
       
    69 void CLbsHostSettingsNotifier::RequestNotificationL()
       
    70 	{
       
    71 	// Only one request for notification can be made at a time.
       
    72 	// Any other requests are ignored.
       
    73 	if (!IsActive())
       
    74 		{
       
    75 		// We only want one notificaton for each account that is modified,
       
    76 		// not one for every record (i.e. CenRep key). So request notifications
       
    77 		// for timestamp records only, since these are updated by every
       
    78 		// change made via the API. This also conveniently excludes changes
       
    79 		// to metadata.
       
    80 		User::LeaveIfError(iRepository.NotifyRequest(static_cast<TUint32>(ETimestamp) << KRecordTypeShift, KRecordTypeMask, iStatus));
       
    81 		SetActive();
       
    82 		}
       
    83 	}
       
    84 
       
    85 /**
       
    86 Suppress the next notification for the specified settings ID.
       
    87 This method is called when an account has been modified by the
       
    88 CLbsHostSettingsStore instance that created this notifier, in order
       
    89 to prevent the observer receiving notifications of its own changes.
       
    90 
       
    91 @param settingsId	Settings id to ignore
       
    92 */
       
    93 void CLbsHostSettingsNotifier::SuppressNotification(TUid aSettingsId)
       
    94 	{
       
    95 	iSuppressSettingsId = aSettingsId;
       
    96 	}
       
    97 	
       
    98 /**
       
    99 Implements CActive. Handle a notification from CenRep.
       
   100 */
       
   101 void CLbsHostSettingsNotifier::RunL()
       
   102 	{
       
   103 	// A notification has been recieved from the CenRep.
       
   104 	// The ID of the changed setting is in iStatus.
       
   105 	TInt status = iStatus.Int();
       
   106 	TUid updatedSettingsId = TUid::Uid(status & KSettingIdMask);
       
   107 	
       
   108 	// Renew request before invoking callback to avoid missing any changes
       
   109 	RequestNotificationL();
       
   110 	
       
   111 	// Notify the observer.
       
   112 	// Ignore repository wide resets (KInvalidNotificationId) and changes
       
   113 	// made by the same client session.
       
   114 	if (status != NCentralRepositoryConstants::KInvalidNotificationId)
       
   115 		{
       
   116 		ASSERT((status & KRecordTypeMask) == (static_cast<TUint32>(ETimestamp) << KRecordTypeShift));
       
   117 		if (updatedSettingsId == iSuppressSettingsId)
       
   118 			{
       
   119 			iSuppressSettingsId = KInvalidSettingsId;
       
   120 			}
       
   121 		else
       
   122 			{
       
   123 			iObserver->LbsHostSettingsUpdated(KErrNone, iStoreId, updatedSettingsId);
       
   124 			}
       
   125 		}
       
   126 	}
       
   127 
       
   128 /**
       
   129 Implements CActive. Cancel notifications from CenRep.
       
   130 */
       
   131 void CLbsHostSettingsNotifier::DoCancel()
       
   132 	{
       
   133 	iRepository.NotifyCancelAll();
       
   134 	}
       
   135 
       
   136 /**
       
   137 Implements CActive. Handles leave from RunL().
       
   138 */
       
   139 TInt CLbsHostSettingsNotifier::RunError(TInt aError)
       
   140 	{
       
   141 	iObserver->LbsHostSettingsUpdated(aError, iStoreId, KNullUid);
       
   142 	return KErrNone;
       
   143 	}