Archived:Implementing agenda observers using Symbian C++
Article Metadata
Compatibility
Article
Overview
Implementing agenda observers
Description
3rd-party applications may want to be notified whenever agenda entries are added, deleted, or modified by other applications. They may also want to know which event has occurred for which entry.
The solution below describes how to write an agenda observer DLL in S60 2nd Edition. For S60 3rd Edition, see the documentation on the Calendar Interim API.
Solution
1) Create a separate DLL for an Agenda observer. For example a CAgendaObs class derived from CAgnObserver with CAgendaObs::NewL() function exported as the first ordinal.
Below are minimal example implementations for virtual methods from CAgnObserver:
CAgnObserver* CAgendaObs::CloneL()
{
if(!iClone) // initial value (TBool) EFalse
{
// Log: Creating clone
CAgendaObs* result = NewL();
result->iClone = ETrue;
return result;
}
}
void CAgendaObs::StartObserving()
{
if(iClone)
{
//Log: Start observing
}
}
void CAgendaObs::StopObserving()
{
if(iClone)
{
// Log: Stop observing
}
}
void CAgendaObs::Send(TInt aFunction, CAgnEntry *aEntry)
{
if(iClone)
{
switch(aFunction)
{
case ENotifyAddEntry:
// Entry added
break;
case ENotifyDeleteEntry:
// Entry deleted
break;
case ENotifyUpdateEntry:
// Entry updated
break;
case ENotifyAddTodoList:
// ToDo entry added
break;
case ENotifyDeleteTodoList:
// ToDo entry deleted
break;
case ENotifyUpdateTodoList:
// ToDo entry updated
break;
default:
// Unexpected command
break;
}
}
}
void CAgendaObs::Send(TInt aFunction, CAgnTodoList *aTodoList)
{
if(iClone)
{
switch(aFunction)
{
case ENotifyAddEntry:
// Entry added
break;
case ENotifyDeleteEntry:
// Entry deleted
break;
case ENotifyUpdateEntry:
// Entry updated
break;
case ENotifyAddTodoList:
// ToDo entry added
break;
case ENotifyDeleteTodoList:
// ToDo entry deleted
break;
case ENotifyUpdateTodoList:
// ToDo entry updated
break;
default:
// Unexpected command
break;
}
}
}
void CAgendaObs::ExternalizeL(RWriteStream &aStream) const
{
//write your code here
if(iClone)
{
// Log: ExternalizeL called
}
//closing
CAgnObserver::WriteEndMarkerL(aStream);
}
void CAgendaObs::InternalizeL(RReadStream &aStream)
{
//write your code here
if(iClone)
{
// Log: InternalizeL called
}
//closing
CAgnObserver::ReadEndMarkerL(aStream);
}
// The NewL of the DLL, to be exported
EXPORT_C CAgendaObs* CAgendaObs::NewL()
{
CAgendaObs* self = new (ELeave) CAgendaObs();
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
2) In another application register the observer using the following code:
#ifdef __WINS__
_LIT(KObserverFile,"agendaobs.dll");
#else
_LIT(KObserverFile,"c:\\system\\libs\\agendaobs.dll");
#endif
_LIT(KAgendaFile,"c:\\system\\data\\calendar");
// In ConstructL:
RAgendaServ *iServer = RAgendaServ::NewL();
iServer->Connect();
CAgendaObs* iObserver = CAgendaObs::NewL();
CAgnEntryModel *iModel = CAgnEntryModel::NewL(this);
iModel->SetServer(iServer);
iModel->OpenL(KAgendaFile);
// Call this method to register the observer DLL
void CSomeAppUi::Register()
{
if(iModel)
{
iModel->RegisterObserverL(TFileName(KObserverFile), iObserver);
}
}
// Before exiting, unregister the DLL
void CAgendaAppAppUi::Unregister()
{
if(iModel)
{
iModel->UnregisterObserverL(TFileName(KObserverFile));
}
}
Note: The observer DLL should use 0x10000135 as UID2 in MMP file.


(no comments yet)