Agenda Observers-again
Login to reply to this topic.
Wed, 2005-04-06 09:13
Joined: 2005-03-03
Forum posts: 52
Hi all,
I had posted another query in this mailing list, but couldn't get any reply.
I had implemented an agenda observer and used it the following way.
iModel->SetMode(CAgnEntryModel::EClient);
TRAPD(error1,iModel->OpenL(_L("c:\\Documents\\AGENDA\\AGENDA")))
if(error1 != KErrNone)
   {
   delete iModel;
   iServer->CloseAgenda();
   User::Leave(error);

   }
iMyServer->WaitUntilLoaded();

Agenda = CAgnTestObserver::NewL();
CleanupStack::PushL(Agenda);
          // iModel->RegisterObserverL(_L("OBSERVERDLL"), Agenda);
TRAPD(err,iModel->RegisterObserverL(_L("OBSERVERDLL"), Agenda));
if(err == KErrNone)
{
   iEikonEnv->InfoMsg(_L("Observer no error."));
}
else
{
   iEikonEnv->InfoMsg(_L("Observer error."));
}
CleanupStack::Pop(5); // observer

and in the destructor i am deregistering it too.

My Observer class implementation is like this.
EXPORT_C CAgnTestObserver*CAgnTestObserver::NewL()
{
   CAgnTestObserver* self = new(ELeave) CAgnTestObserver();
   CleanupStack::PushL(self);
   self->ConstructL();
   CleanupStack::Pop();
   return (self);

}
CAgnTestObserver::CAgnTestObserver():iLogName(KNullLogFile)
{

}
CAgnTestObserver::~CAgnTestObserver()
{
   delete iMessageToInfoPrint;
   iFsSession.Close();
   iNotifier.Close();
   delete iCharConv;

}

CAgnObserver* CAgnTestObserver::CloneL()
{
   CAgnTestObserver* observer = CAgnTestObserver::NewL();
   observer->SetLogName(iLogName);
   return observer;

}

void CAgnTestObserver::StartObserving()
{
   _LIT(KStartedObserving, "Starting observing agenda file...");
   AppendToLogFileWithNewLineL(KStartedObserving);

}
void CAgnTestObserver::StopObserving()
{
   _LIT(KEndedObserving, "Finished observing agenda file...");
   AppendToLogFileWithNewLineL(KEndedObserving);

}   

void CAgnTestObserver::ConstructL()
   {
   User::LeaveIfError(iFsSession.Connect());
   User::LeaveIfError(iNotifier.Connect());

   iCharConv = CCnvCharacterSetConverter::NewL();
   CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable = iCharConv->CreateArrayOfCharacterSetsAvailableL(iFsSession);
   CleanupStack::PushL(arrayOfCharacterSetsAvailable);
   iCharConv->PrepareToConvertToOrFromL(0x100012b6, *arrayOfCharacterSetsAvailable, iFsSession); // 0x100012b6 is KCharacterSetIdentifierCodePage1252
   iCharConv->SetReplacementForUnconvertibleUnicodeCharactersL(_L8("?"));
   CleanupStack::PopAndDestroy(); // arrayOfCharacterSetsAvailable
   }


void CAgnTestObserver::ExternalizeL(RWriteStream& aStream) const
   {
   aStream << iLogName;
   
   WriteEndMarkerL(aStream);
   }

void CAgnTestObserver::InternalizeL(RReadStream& aStream)
   {
   aStream >> iLogName;
   ReadEndMarkerL(aStream);

   iFsSession.Delete(iLogName);
   }

void CAgnTestObserver::Send(TInt aFunction, CAgnEntry* aEntry)
   {
//   __ASSERT_ALWAYS(aEntry, Panic(EAgnObsPanicNoAgendaEntry));

   switch (aFunction)
      {
      case ENotifyAddEntry:
         WriteEntryActionL(KEntryAdded, *aEntry);
         break;
      case ENotifyDeleteEntry:
         WriteEntryActionL(KEntryDeleted, *aEntry);
         break;
      case ENotifyUpdateEntry:
         WriteEntryActionL(KEntryUpdated, *aEntry);
         break;
      /*case ENotifyFetchEntry:
         WriteEntryAction(_L("Entry fetched: "),aEntry);
         break*/;
      default:
         {
         TBuf<200> buf;
         buf.Format(KUnhandledEntryFunc, aFunction);
         WriteEntryActionL(buf, *aEntry);
         break;
         }
      }
   }

void CAgnTestObserver::Send(TInt aFunction, CAgnTodoList* aTodoList)
   {
//   __ASSERT_ALWAYS(aTodoList, Panic(EAgnObsPanicNoAgendaToDo));

   switch (aFunction)
      {
      case ENotifyAddTodoList:
         WriteTodoListActionL(KToDoAdded, *aTodoList);
         break;
      case ENotifyDeleteTodoList:
         WriteTodoListActionL(KToDoDeleted, *aTodoList);
         break;
      case ENotifyUpdateTodoList:
         WriteTodoListActionL(KToDoUpdated, *aTodoList);
         break;
      /*case ENotifyFetchTodoList:
         WriteTodoListActionL(_L("TodoList fetched: "),aTodoList);
         break; */
      default:
         {
         TBuf<200> buf;
         buf.Format(KUnhandledToDoFunc, aFunction);
         WriteTodoListActionL(buf, *aTodoList);
         break;
         }
      }
   }



///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

EXPORT_C void CAgnTestObserver::SetLogName(const TDesC& aLogName)
   {
   iLogName = aLogName;
   }

The start observing stop observing functions are getting called.
The agenda application also is working fine.
But i am not getting any events for agenda modifications/delete and additon through the send function of my observer.
what could be the reason.

A sppedy reply is hightly appreciated.
thanks for the time
arun

Mon, 2005-04-25 03:54
Joined: 2005-03-03
Forum posts: 52
Hi all,
Please help me in this. I am yet to get a solutions.

thanks
arun
Fri, 2005-11-18 09:40
Joined: 2005-02-17
Forum posts: 26
Did you evern find a solution to this problem? Could you post and explain what the problem was?

Thanks

Niimidan

Fri, 2005-11-18 11:30
Joined: 2005-03-14
Forum posts: 59
Fri, 2005-12-02 09:17
Joined: 2005-03-03
Forum posts: 52
The observer can be used to get events about changes made by the owner application of the observer (application which installed the observer). This observer cannot be used to get changes made by the default application.

At least this is the answer we got from symbian.
Tue, 2006-03-28 13:10
Joined: 2003-05-15
Forum posts: 53
If you want to get notified of events in the agenda database maybe you should try an agenda notifier.

I use like this:
<...snip...>
TCallBack serverNotifier(CheckNotifier,this);
iAgnServ->StartNotifierL(serverNotifier);
//RAgendaServ* iAgnServ
<...snip...>

the callback function:
TInt CXXX::CheckNotifier(TAny* aPtr)
   {
         // Refresh model.
        Model()->AgnModel()->CheckNotifier();
   //do something
   return EFalse;
        //works fine with EFalse, but it should be ETrue
   }

you check notifier will be called anytime there is a change in the agenda model ... unfortunately it doesn't tell you what type of change.
But that's better than nothing

copyright 2003-2009 NewLC SARL