×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    9

    has anybody used CAgnObserver?

    I'm trying to get the last modified calendar entry and the best way seems to be by using CAgnObserver. However, the details of doing this are not very well documented. Is the only possible way of doing it by writing the modified entry to a file that my application then reads, or is there a way of getting notified directly?

    Thanks,

    alampi

  2. #2
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015
    CAgnObserver is for getting changes to the agenda *as they happen*. If this is what you need you will have to use CAgnObserver.

    If you use them you don't have to write anything to a file - the observers are a mechanism for the agenda sending to you information about changes as they happen in real time, you can do what you want with the information.
    Last edited by hotcheese; 2005-01-13 at 19:04.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    9
    Yeah, that's exactly what I'm trying to do. But my impression was that when I register my observer with CAgnModel, it calls the CloneL() method of the observer and installs that instance instead of the original instance, which wouldn't then get the notification. I was hoping I'm wrong and wanted to get advice on how this should be done.

    cheers,

    alampi

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015
    Ah I see what you're saying.
    The registration process is a one off event by the way - once you've registered your observer its 'attached' to the agenda i.e. if the agenda gets closed down, next time it opens it launches your observer and starts sending information to it.
    So ideally you want some mechanism of your observer being aware of your program and pushing data to it. Doesn't necessarily have to be a file of course though.

    My knowledge of observers is very very old but I can send you code for an observer if you like.

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    9
    I would really appreciate it if you could do that.

    Thanks in advance,


    alampi

  6. #6
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015
    whats your email?

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    9
    Please use my profile email, I check that regularly.

    Thanks again,

    alampi

  8. #8
    Registered User
    Join Date
    Oct 2004
    Posts
    47
    I would love to see some code for an observer as well. I assume that they have to be in their own dlls, since model->RegisterObserver seems to want a dll name.

    Anyway, my email is fbs88@comcast.net

    Thanks

  9. #9
    Registered User
    Join Date
    Oct 2004
    Posts
    47
    In your example (logob), there is nowhere where an observer is registered. I wrote some code to do that (following an example I found in a document on this site). I do an iModel->Open of the calendar file, followed by iModel->RegisterObserverL. However, when I run that code, RegisterObserverL crashes deep in Symbian code. From the stack trace and using dependency walker, dumpbin, etc., it looks like the crashes happens when CAgnEntryModel::SaveL calls TAgnEntryIter::NumEntriesForStream. I don't know why it is crashing.

    A couple of things:
    1) I have everything in one dll (call it foo.dll) -- both the agenda model and the agenda observer, so the RegisterObserverL call takes "foo" as a parameter. I assume this is ok, but am not sure.

    2) The SDK docs say that RegisterObserverL should be called before OpenL -- the code I found calls OpenL first. It still crashes both ways.

    I wonder if there is any code out there that has the model and the observer -- to see how you actually register the observer. Any info on that, or on the possible reasons for the crash would be appreciated.

    Thanks

  10. #10
    Registered User
    Join Date
    Oct 2004
    Posts
    47
    Got farther. Turns out my clone method wasn't doing anything. I can now get past the crash. I generally get a KErrEof on the calendar file (unless there is an event). That causes a crash between StartObserving and ExternalizeL, but maybe this is just my environment. Sure wish there were some docs on this stuff.

  11. #11
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015
    The example code was just of the observer plugin itself, there needs to be other code in another program to register it.

  12. #12
    Registered User
    Join Date
    Oct 2004
    Posts
    47
    Using the emulator, I can see my observer'sStartObservingL and ExternalizeL methods getting called when I register my observer, but then I go to the calendar app, and add a meeting. I don't see my Send method getting called.

    Also, I have to start the Calendar on the emulator first. If my observer is already up and observing, the Calendar won't start up -- from debug output, it looks like it's getting an "Access Denied" error (-21). When I shut my app down and I'm then able to start the calendar app, it resets the Calendar file back to empty, thus wiping out any appointments.

    What am I missing here?

    I'm just doing the standard stuff:

    iServer = RAgendaServ::NewL();
    TInt ret = iServer->Connect();
    User::LeaveIfError(ret);
    iModel = CAgnEntryModel::NewL();
    iModel->SetServer(iServer);
    iModel->OpenL(_L("C:\\system\\data\\Calendar"));
    iObserver = CTstAgnObserver::NewL();
    iModel->RegisterObserverL(_L("TstAgnObserver"), iObserver);

    In the observer itself, except for CloneL, I just have debug statements to see if the methods are getting called.

    There has to be some more info somewhere.

  13. #13
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015
    Hi

    Its been about 7 years since I knew about observers so I can't remember much and don't have time to look at it right now.
    However the fact that you can't lanuch the agenda definatly doesn't sound right - what do you mean when you say if your observer is already up and running and observing you can't start the agenda?
    An observer can't be observing unless the agenda is running in the first place.

    The sequence of steps is you need to have some code which creates an observer, you then register the observer with the agenda - note this is a one time operation!!, you just do it once and thats it. I don't mean register once every time your code runs I mean register once for all eternity. The agenda makes a copy of your observer and starts sending data to that copy not the the copy your created in your code. If the agenda closes down then next time it reopens it automatically creates an object of your observer and starts sending change information to it.

    Your code thats doing the registration isn't being repetedly run is it, or it or the observer has got hold of some shared resource thus causing a KErrAccessDenied?

    And what do you mean about the calendar file being reset to empty - the agenda is incapable of deleting entries unless specifically instructed to do so. If you are seeing entries deleted you have something serious going wrong.
    Last edited by hotcheese; 2005-01-28 at 22:00.

  14. #14
    Registered User
    Join Date
    Oct 2004
    Posts
    47
    If my observer is up and running, I can't start the emulator's calendar app (access denied). I noticed that this didn't happen if I used automatic variables instead of class members for model, server, observer. However that really didn't help with anything else, and then it makes it hard to unregister (if the model is gone, how do I get it back -- I can't open the calendar again -- it's already open). I have a driver program using the console test harness, and when it is done (you hit a key), then I want to unregister the observer. I assume you do that in a destructor (there is no example anywhere of unregistering.)

    The code that registers is only being executed once. I think the calendar being reset to empty has to do with corruption. I have a scenario: open emulator calendar app; run my driver app that registers, observes, etc.; add an entry to the emulator's calendar (my Send method does not execute); close my app, close the emulator's calendar, open the emulator's calendar. All the entries are gone, and I noticed a debug statement saying error -20 (corrupt).

    Maybe my problem with not getting notifications is because it's the copy that gets the changes, and I'm not doing anything about it. Right now, the only method I implement is CloneL. The rest just have a debug statement to show they have been called.


    Both the code that registers and the observer code are in the same dll. I don't know if this is a problem or not. I tried to keep them in 2 separate dlls, but when I load the polymorphic DLL (that does the registering), it wouldn't load (-1 error) if the NewL call to the observer was in there.

  15. #15
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015
    It all sounds like you've got something fundamentally wrong, its not possible to diagnose the problem from a verbal description.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •