Central Repository Data Access Tutorial
This tutorial describes how to access and modify the data in Central Repository at run time on the Symbian platform.
Before you start, you must:
Repositories cannot be created at runtime. Applications must register with Central Repository using the initialisation file. The Central Repository API is provided by the CRepository class. Applications access the repository with the UID of the repository. Applications must have appropriate access to the repositories.
- Open a repository
The repositories are identified by a UID. To access the data in the Central Repository create a new CRepository object with the UID of the repository.
CRepository* repository = CRepository::NewL(KMyRepositoryUid);
One CRepository object must be created for each repository.
- Retrieve data from the repository
The data can be retrieved by using Get() or Find() functions of the CRepository class.
Use Get() to retrieve an individual value TInt Get(TUint32 aKey, TInt& aVal);
Use Find() function to retrieve the values by passing a range of keys The input parameters are a partial key and a key mask and the function returns all the settings that match the input range. TInt FindL(TUint32 aPartialKey, TUint32 aKeyMask, RArray<TUint32>& aFoundKeys);
aKey parameter represents a setting in a 32 bit unsigned integer and aVal represents the corresponding value of the setting.
- Modify the data of the repository
opened
The Set() functions of the CRepository class allows the applications to modify the data in the Central Repository.
Set new values using Set()
TInt Set(TUint32 aKey, TInt aVal);
Read the metadata of the repository
Use GetMeta() to get the metadata of the repository. The eight most significant bits are reserved for internal purpose and clients must not use these values. The value of the reserved bits may change for each GetMeta() call.
Applications must use logical AND function with the retun value of GetMeta() and the constant KMetaUnreserved to retrieve the user bits of the metadata. The constant KMetaUnreserved is defined in centralrepository.h.
TInt GetMeta(TUint32 aKey, TUint32& aMeta);
- Add a new setting
To add a new setting in the repository use Create().
TInt Create(TUint32 aKey, TInt aVal);
To delete an existing setting use Delete() TInt Delete(TUint32 aKey);
- Move settings
To move one or more settings from one key to another key use Move()
TInt Move (TUint32 aSourcePartialKey, TUint32 aTargetPartialKey, TUint32 aMask, TUint32 &aErrorKey) ;
The source key, target key and the partial mask must be provided by the clients.
Reset the settings
To reset the settings of a repository to the default values use Reset() TInt Reset();
To reset a particular setting, pass the key of the setting as a parameter to the Reset() function. TInt Reset(TUint32 aKey);
Go back to step 2 if you want to modify the settings after a reset or continue to step 8
- Close the repository
To close repository, use delete.
delete repository;
Each instance of the CRepository object must be deleted to clean up the resources.
The data in a repository will be modified with the new values by the application.
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.