This tutorial describes how to access and modify the data in Central Repository at run time on the Symbian platform.
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.
Before you start, you must:
understand the Central Repository
know how to register and use the repositories in the Central Repository
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.
Example:
CRepository* repository = CRepository::NewL(KMyRepositoryUid);
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.
Get()
to retrieve an individual value Example:
TInt Get(TUint32 aKey, TInt& aVal);
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. Example:
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()
Example:
TInt Set(TUint32 aKey, TInt aVal);
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. GetMeta()
and the constant KMetaUnreserved
to retrieve the user bits of the metadata. The constant KMetaUnreserved
is defined in centralrepository.h
. Example:
TInt GetMeta(TUint32 aKey, TUint32& aMeta);
Add a new setting
To add a new setting in the repository use Create()
.
Example:
TInt Create(TUint32 aKey, TInt aVal);
Delete()
Example:
TInt Delete(TUint32 aKey);
Move settings
To move one or more settings from one key to another key use Move()
Example:
TInt Move (TUint32 aSourcePartialKey, TUint32 aTargetPartialKey, TUint32 aMask, TUint32 &aErrorKey) ;
Reset()
Example:
TInt Reset();
Reset()
function. Example:
TInt Reset(TUint32 aKey);
Close the repository
To close repository, use delete.
Example:
delete repository;
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.