Deprecated: Function set_magic_quotes_runtime() is deprecated in /home2/creabros/public_html/ on line 14
CreaBros Oy: StoreL & RestoreL in Symbian UIKON

StoreL & RestoreL in Symbian UIKON

Apr 28, 05:35 PM

One interesting thing about Symbian is the application framework UIKON, which is recommended or pretty much pushed on the developers. I won’t go into detail what are the components of UIKON, search UIKON core overview or reference for more info, but I will write about a funny problem that I ran into. Last weekend when I was timing the kids games with my nifty Stopwatch application I clicked exit by accident.
On any other application that would be fine, but since it was something as important as how many seconds more/less has coaches daughter has played compared to others, it wasn’t a joking matter. So I decided that the stopwatch needs to save state.

That brings us back to UIKON where every application creates a document instance, which can be persisted. This means that when application starts it calls documents overridden function CEikDocument::RestoreL, which should read the contents of the saved file and restore state. When application exits it should save it’s state using documents override of CEikDocument::StoreL function. Writing these functions was easy enough, bit of streaming of integers and other data, but when I started my application it nothing happened. What now? My framework of the application was generated using Carbide and uidesigner, so I hadn’t really looked at the resource files except to add my icon file to the application definition.

I started by looking at the examples, what is the difference between working and non-working code. It turned out to be very simple, but took me half an hour to find. Text r_default_document_name wasn’t in the generated textfile and the framework didn’t trigger the restore function. (But I was wrong, this wasn’t the cause)

RESOURCE TBUF r_default_document_name
	buf = "LBCD";

Actually things were worse. I first added the whole block behind the empty RESOURCE TBUF declaration and the whole application crashed at startup and all I can see in the debugger is assembly gibberish, nothing that I would really want to start looking through. Another thirty minutes of life wasted.

After this moment of genius, the application started, but I ran into second problem. Instead of calling RestoreL the application crashed with EIKON 44, which means EEikPanicProcessNoStore, defined in eikpanic.h. So for some reason my application isn’t creating a store? Or is there something else going on. Debugging problems like this is like a really boring part of a really boring detective story. The moment in the movie when it’s time to go to the fridge. (This is how far I got when I started to write this blog entry).

It turns out that if the file doesn’t exist then the framework will first call the StoreL function.

After all the problems I did find the error, first I thought had to override the OpenFileL method and all would be well. The CAknDocument overrides the function so that it doesn’t open a file since most people don’t use the persistence. Would be nice, if this was mentioned in the CAknDocument reference.

Here is the fix:

CFileStore* CLBChronometerDocument::OpenFileL(TBool aDoOpen,
                               const TDesC& aFilename,
                               RFs& aFs)
// skip CAknDocument call it's base class function
	return CEikDocument::OpenFileL(aDoOpen,aFilename,aFs);

But no, it still didn’t work. Finally it turned out I had looked wrong at the StoreL function declaration. Function is const and I had left the const declaration from the end and that is why the framework never called my store function. I guess if there was a compiler warning I would have noticed, but not this time.

Lesson, never underestimate the time that a project will take, because it takes a long time to find a needle in the haystack.

Well now I can “run” my timer even if the phone is off. I’ll add another feature, which is storing the results into separate file and perhaps a possibility of adding notes to times.

Kalle Kuismanen

Mobile, Current Projects


Commenting is closed for this article.