os/persistentdata/persistentstorage/centralrepository/cenrepnotifierhandler/inc/cenrepnotifyhandler.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
#ifndef CENREPNOTIFYHANDLER_H
sl@0
    21
#define CENREPNOTIFYHANDLER_H
sl@0
    22
sl@0
    23
// INCLUDES
sl@0
    24
#include <e32std.h>
sl@0
    25
#include <e32base.h>
sl@0
    26
sl@0
    27
// FORWARD DECLARATIONS
sl@0
    28
class MCenRepNotifyHandlerCallback;
sl@0
    29
class CRepository;
sl@0
    30
sl@0
    31
/**
sl@0
    32
* Active object wrapper for Central Repository one-shot notification handling.
sl@0
    33
* Central Repository Notification Handler API provides an easy-to-use 
sl@0
    34
* implementation of a CActive-based wrapper for Central Repository single-shot
sl@0
    35
* notifications. In most cases Central Repository Notification Handler can 
sl@0
    36
* automatically resubscribe to notifications and fetch the modified value from
sl@0
    37
* Central Repository. 
sl@0
    38
* The API consists of the classes CCenRepNotifyHandler and 
sl@0
    39
* MCenRepNotifyHandlerCallback. The user of this class needs to implement relevant
sl@0
    40
* MCenRepNotifyHandlerCallback interface methods to receive notifications. 
sl@0
    41
* The user of Central Repository Notification Handler API needs access to 
sl@0
    42
* Central Repository (centralrepository.h).
sl@0
    43
*
sl@0
    44
* Usage:
sl@0
    45
*  
sl@0
    46
* Initialization example (from a class that implements MCenRepNotifyHandlerCallback interface):
sl@0
    47
* @code
sl@0
    48
* iSession = CRepository::NewL(KTestUid);
sl@0
    49
* iNotifyHandler = CCenRepNotifyHandler::NewL(*this, *iSession, CCenRepNotifyHandler::EStringKey, KKey1);
sl@0
    50
* iNotifyHandler->StartListeningL();
sl@0
    51
* @endcode
sl@0
    52
*
sl@0
    53
* Uninitialization example:
sl@0
    54
* @code
sl@0
    55
* iNotifyHandler->StopListening(); 
sl@0
    56
* delete iNotifyHandler;
sl@0
    57
* @endcode
sl@0
    58
*
sl@0
    59
* Handler method implementation example:
sl@0
    60
* @code
sl@0
    61
* void CMyCenRepNotifyTest::HandleNotifyString(TUint32 aId, const TDesC16&  aNewValue)
sl@0
    62
*    {
sl@0
    63
*    // Print out the notified value
sl@0
    64
*    RDebug::Print(_L("Key %d changed, new value: %S"), aId, &aNewValue);
sl@0
    65
*    }
sl@0
    66
* @endcode
sl@0
    67
*
sl@0
    68
* @publishedAll
sl@0
    69
* @released
sl@0
    70
*/
sl@0
    71
class CCenRepNotifyHandler : public CActive
sl@0
    72
    {
sl@0
    73
    public:
sl@0
    74
        /**
sl@0
    75
        * Defines different key types. Enumeration is used to indicate the 
sl@0
    76
        * key type that is listened to. 
sl@0
    77
        */
sl@0
    78
        enum TCenRepKeyType
sl@0
    79
        {
sl@0
    80
            EIntKey,    ///< Key holds a TInt value.
sl@0
    81
            ERealKey,   ///< Key holds a TReal value.
sl@0
    82
            EStringKey, ///< Key holds a TDesC16 value.
sl@0
    83
            EBinaryKey  ///< Key holds a TDesC8 value.
sl@0
    84
        };
sl@0
    85
sl@0
    86
        IMPORT_C static CCenRepNotifyHandler* NewL( MCenRepNotifyHandlerCallback& aCallback, 
sl@0
    87
                                                    CRepository& aSession, 
sl@0
    88
                                                    TCenRepKeyType aKeyType, 
sl@0
    89
                                                    TUint32 aId );
sl@0
    90
sl@0
    91
        IMPORT_C static CCenRepNotifyHandler* NewL( MCenRepNotifyHandlerCallback& aCallback, 
sl@0
    92
                                                    CRepository& aSession );
sl@0
    93
sl@0
    94
        IMPORT_C static CCenRepNotifyHandler* NewLC( MCenRepNotifyHandlerCallback& aCallback, 
sl@0
    95
                                                     CRepository& aSession, 
sl@0
    96
                                                     TCenRepKeyType aKeyType, 
sl@0
    97
                                                     TUint32 aId );
sl@0
    98
sl@0
    99
        IMPORT_C static CCenRepNotifyHandler* NewLC( MCenRepNotifyHandlerCallback& aCallback, 
sl@0
   100
                                                     CRepository& aSession );
sl@0
   101
        IMPORT_C void StartListeningL();
sl@0
   102
sl@0
   103
        IMPORT_C void StopListening();
sl@0
   104
sl@0
   105
sl@0
   106
        /**
sl@0
   107
        * Destructor.
sl@0
   108
        */
sl@0
   109
        IMPORT_C virtual ~CCenRepNotifyHandler();
sl@0
   110
sl@0
   111
    protected:
sl@0
   112
sl@0
   113
        void RunL();
sl@0
   114
    
sl@0
   115
        TInt RunError( TInt aError );
sl@0
   116
sl@0
   117
        void DoCancel();
sl@0
   118
sl@0
   119
    private:
sl@0
   120
sl@0
   121
        CCenRepNotifyHandler( MCenRepNotifyHandlerCallback& aCallback, 
sl@0
   122
                              CRepository& aSession, 
sl@0
   123
                              TCenRepKeyType aKeyType, 
sl@0
   124
                              TUint32 aId );
sl@0
   125
                                                   
sl@0
   126
        CCenRepNotifyHandler( MCenRepNotifyHandlerCallback& aCallback, 
sl@0
   127
                              CRepository& aSession );
sl@0
   128
        TInt OrderNotification();
sl@0
   129
       
sl@0
   130
    private:
sl@0
   131
        
sl@0
   132
        CRepository& iSession;  // not owned by this class
sl@0
   133
        MCenRepNotifyHandlerCallback& iCallback; // not owned by this class
sl@0
   134
        TCenRepKeyType iKeyType;
sl@0
   135
        TUint32 iId;        
sl@0
   136
        TBool iWholeRepository;  // The flag to indicate if listening is for whole repository
sl@0
   137
    };
sl@0
   138
sl@0
   139
sl@0
   140
/**
sl@0
   141
* Class provides a callback interface for handling the notifification
sl@0
   142
* events from the Central Repository. The Client derives a class 
sl@0
   143
* from this interface and implements the HandleNotify-methods that 
sl@0
   144
* interest it.
sl@0
   145
* An empty default implementation is provided for all of the methods.
sl@0
   146
* In debug build the default implementations print out a debug trace.
sl@0
   147
*
sl@0
   148
* @publishedAll
sl@0
   149
* @released
sl@0
   150
*/
sl@0
   151
class MCenRepNotifyHandlerCallback
sl@0
   152
    {
sl@0
   153
sl@0
   154
    public:
sl@0
   155
sl@0
   156
    /** 
sl@0
   157
    * This callback method is used to notify the client about
sl@0
   158
    * changes for integer value keys, i.e. key type is EIntKey.
sl@0
   159
    *
sl@0
   160
    * @param aId Id of the key that has changed.
sl@0
   161
    * @param aNewValue The new value of the key.
sl@0
   162
    * @capability Dependent Capability required depends on implementation of override.
sl@0
   163
    */
sl@0
   164
    IMPORT_C virtual void HandleNotifyInt( TUint32 aId, TInt aNewValue );
sl@0
   165
sl@0
   166
    /** 
sl@0
   167
    * This callback method is used to notify the client about
sl@0
   168
    * changes for real value keys, i.e. key type is ERealKey.
sl@0
   169
    *
sl@0
   170
    * @param aId Id of the key that has changed.
sl@0
   171
    * @param aNewValue The new value of the key.
sl@0
   172
     * @capability Dependent Capability required depends on implementation of override.
sl@0
   173
   */
sl@0
   174
    IMPORT_C virtual void HandleNotifyReal( TUint32 aId, TReal aNewValue );
sl@0
   175
sl@0
   176
    /** 
sl@0
   177
    * This callback method is used to notify the client about
sl@0
   178
    * changes for string value keys, i.e. key type is EStringKey.
sl@0
   179
    *
sl@0
   180
    * @param aId Id of the key that has changed.
sl@0
   181
    * @param aNewValue The new value of the key.
sl@0
   182
    * @capability Dependent Capability required depends on implementation of override.
sl@0
   183
    */
sl@0
   184
    IMPORT_C virtual void HandleNotifyString( TUint32 aId, const TDesC16& aNewValue );
sl@0
   185
sl@0
   186
    /** 
sl@0
   187
    * This callback method is used to notify the client about
sl@0
   188
    * changes for binary value keys, i.e. key type is EBinaryKey.
sl@0
   189
    *
sl@0
   190
    * @param aId Id of the key that has changed.
sl@0
   191
    * @param aNewValue The new value of the key.
sl@0
   192
    * @capability Dependent Capability required depends on implementation of override.
sl@0
   193
    */
sl@0
   194
    IMPORT_C virtual void HandleNotifyBinary( TUint32 aId, const TDesC8& aNewValue );
sl@0
   195
sl@0
   196
    /** 
sl@0
   197
    * This callback method is used to notify the client about
sl@0
   198
    * changes in keys when the whole repository is listened for.
sl@0
   199
    *
sl@0
   200
    * Note: It is not guaranteed that a notification will be received
sl@0
   201
    *       for all keys, if multiple keys are changed in rapid succession
sl@0
   202
    *       by multiple threads or when the whole repository is reset,
sl@0
   203
    *       therefore only listen for whole repository if this is not an issue.
sl@0
   204
    *
sl@0
   205
    * @param aId Id of the key that has changed. If multiple keys were changed by
sl@0
   206
    *            whole repository reset, value will be KInvalidNotificationId.
sl@0
   207
    * @capability Dependent Capability required depends on implementation of override.
sl@0
   208
    */
sl@0
   209
    IMPORT_C virtual void HandleNotifyGeneric( TUint32 aId );
sl@0
   210
sl@0
   211
    /** 
sl@0
   212
    * This callback method is used to notify the client about errors
sl@0
   213
    * in the handler. Any error in handling causes the handler to stop
sl@0
   214
    * handling any more notifications. Handling can be restarted with
sl@0
   215
    * a call to aHandler->StartListeningL(), if the error is non-fatal.
sl@0
   216
    * However, be careful to trap any errors from this call if this is done.
sl@0
   217
    *
sl@0
   218
    * @param aId Id of the key this instance listens to or if notifications for
sl@0
   219
    *            whole repository are listened, could also be KInvalidNotificationId.
sl@0
   220
    * @param aError Error code.
sl@0
   221
    * @param aHandler Pointer to the handler instance. 
sl@0
   222
    *                 This pointer can be used to identify the handler or restart the listening.
sl@0
   223
    * @capability Dependent Capability required depends on implementation of override.
sl@0
   224
    */
sl@0
   225
    IMPORT_C virtual void HandleNotifyError( TUint32 aId, TInt aError, 
sl@0
   226
                                            CCenRepNotifyHandler* aHandler );
sl@0
   227
    };
sl@0
   228
sl@0
   229
#endif      // CENREPNOTIFYHANDLER_H
sl@0
   230
sl@0
   231
// End of File