Tuesday, March 4, 2008

Implementing Active backup

Yeah.. Its would be really good if you understood the idea / concept behind the backup & Restore.

If not please refer to my previous post on "Backup & Restore"

Now its time to code your application / process to interact with Symbian Backup Engine (SBE). That is implementing active backup for your application.

Before that let me explain few more things.

Backup Listener:
You must have a listener class which listens to the events from SBE. It should be an Active Obeject and it should implement MActiveBackupDataClient
class CMyBackupListener : public CActive, public conn::MActiveBackupDataClient

Signaling from SBE to Listener:
The signalling method provided to inform processes that a backup or restore is taking place is via the publish-and-subscribe API. The publish-and-subscribe server maintains a list of subscribers expressing an interest in the backup and restore flag. Any published changes to this flag by the backup and restore engine results in all subscribers being notified. The flag provides information on whether a backup or restore operation is in progress, whether a backup is base or incremental and whether the operation is full or partial. Subscribing to the flag is done via RProperty, which must be used in conjunction with an active object to be notified when the value changes.
The following key and category values should be used (these are defined in epoc32\include\connect\sbdefs.h):

Category : KUidSystemCategoryValue

Key : KUidBackupRestoreKey

The following code fragment demonstrates this:

#include RProperty iProperty;
iProperty.Attach(KUidSystemCategory, KUidBackupRestoreKey);
CActiveScheduler::Add(this);
iStatus = KRequestPending;
iProperty.Subscribe(iStatus);
SetActive(); // In CMyBackupListener::RunL, you will get the notification

Yep. You got a notification from SBE that its going to backup the data. How to make connection with SBE then?

Connecting to SBE:
Once you got the notification from SBE, then make a connection as follows

iConn = conn::CActiveBackupClient::NewL(this); // Listener is again the observer for this
iConn ->ConfirmReadyForBURL(KErrNone);

yes.. we initimated SBE that we are ready for backup.


Hereafter you will start getting events from SBE to backup and restore. Its up to the application writer, what data to be backed up and what not to be. Because its active backup method 

If its passive, it would have been already mentioned in the backup registration file and the fact is that the data owning process need not to be run at that time.

As you know the active backup expects the data owning processes need to be run. So, a question should flash in your mind here.

“Where did we mention which process to be expected to run?”

Yeah.. Here is the answer

It should be mentioned in the backup registration file. The following is the syntax of that.

xml version="1.0" standalone="yes"?
backup_registration
active_backup process_name = "Myprocess" requires_delay_to_prepare_data = "yes"
backup_registration

Conclusion:

When your phone is connected to PC, the SBE from backup software signals all the processes that are registered for the backup process. (obviously by referring the backup registration files )

On receiving those events, the process creates a connection (CActiveBackupClient)

Then Processes receive events from SBE and they backups the data they wish. The same way as restore.

2 comments:

Senthil said...

Suuuuper kalakalaana article...
eppadida kalakuraa..
Fine..romba nenaichikaathaa..

written something just
to test if the comments are
working in ur blog..:-)

Me said...

It works man:) LOL

 
Template design by Amanda @ Blogger Buster