Subscribing and Responding to Time Zone Data Changes

Context

The Time Zone Services collection provides several Publish and Subscribe (P & S) properties. Clients can subscribe to these properties to allow them to be notified of TZ data changes. Clients are then able to respond to any changes.

The Calendar callback API MCalChangeCallBack2 is used for asynchronous change notification. The API allows Calendar clients who own cached Calendar entry instance data to be notified of changes in TZ rules. The Calendar client should refresh the instance data they own when called back.

For further details on Publish and Subscribe, and the active objects framework, see the Publish and Subscribe guide.

Steps

  1. To obtain notification of a change in TZ data using P&S, a client uses an active object. The active object's RunL() function is called when the value of the property changes.

    The code example below shows how an active object is implemented to subscribe and respond to a change in the NTzUpdate::ETzRulesChange() property.

    Example:

    #include <tzupdate.h>
    #include <…>
    
    class CMyTzRulesChangeObserver : public CActive
        {
    public:
        static CMyTzRulesChangeObserver* NewL();
        ~CMyTzRulesChangeObserver();
    	
    private:
        // From CActive.
        void RunL();
        void DoCancel();
    	
        CMyTzRulesChangeObserver();
        void ConstructL();
        void RespondToChanges();
    	
    private:
        RProperty iChangeProperty;
        };
    
    CMyTzRulesChangeObserver* CMyTzRulesChangeObserver::NewL()
        {
        CMyTzRulesChangeObserver* self = new( ELeave ) CMyTzRulesChangeObserver();
        CleanupStack::PushL( self );
        self->ConstructL();
        CleanupStack::Pop( self );
        return self;
        }
    
    CMyTzRulesChangeObserver::CMyTzRulesChangeObserver()
        : CActive( CActive::EPriorityStandard )
        {
        CActiveScheduler::Add( this );
        }
    
    void CMyTzRulesChangeObserver::ConstructL()
        {
        User::LeaveIfError( iChangeProperty.Attach( NTzUpdate::-KPropertyCategory, 
                                                    NTzUpdate::ETzRulesChange ) );
        iChangeProperty.Subscribe( iStatus );
        SetActive();
        // Make sure we start with the last published property values.
        RespondToChanges();
        }
    
    CMyTzRulesChangeObserver::~CMyTzRulesChangeObserver()
        {
        Cancel();    
        iChangeProperty.Close();
        }
    
    void CMyTzRulesChangeObserver::RespondToChanges()
        {
        TPckgBuf<TTime> changeBuf;
        TInt err = iChangeProperty.Get( changeBuf );
        if( err == KErrNone )
            {
            TTime changeTime = changeBuf();
            }
        }
    
    void CMyTzRulesChangeObserver::RunL()
        {	
        if( iStatus.Int() == KErrNone )
            {
            // Subscribe again before handling the change.
            iChangeProperty.Subscribe( iStatus );
            SetActive();
            RespondToChanges();
            }
        }
    
    void CMyTzRulesChangeObserver::DoCancel()
        {
        iChangeProperty.Cancel();
        }

See Also