The "Background" task in the palm OS

I am trying to create an application for Palm OS to check the website every X minutes or hours and provide a notification when some of the data is available. I know that this kind of thing can be done on the new Palm - for example, my Centro can download emails or websites when the application is not at the top, but I don’t know how to do it. Can someone point me in the right direction?

+4
source share
1 answer

This can be done, but very difficult. You need to take a few steps.

Firstly, it only works on Palm OS 5 and is sketchy on some early Palm OS 5 devices. The latest devices are better, but not perfect.

Then you need to create an alarm for your application using AlmSetAlarm. Here's how you do it "every X minutes or hours."

When the alarm goes off, your application will receive the sysAppLaunchCmdAlarmTriggered startup code, even if it is not already running. If you want to do something simple and quick, you can do it in response to the startup code, and you're done.

After you make your material in the alarm start code, be sure to set up the next alarm so that you continue to be called.

Important notes: you cannot access global variables when responding to this startup code! Depending on the setting in your compiler, you probably also will not be able to access some C ++ functions, such as virtual functions (which use global variables). In Codewarrior, you can set a setting that will help with this, but I'm not too familiar with it. You must archive your code so that it does not need a global value; for example, you can use FtrSet and FtrGet to store bits of global data that you may need. Finally, you can only access one 64-bit code segment of 68000 machine code. Intersegment jumps do not work properly without creating global bindings.

You can get around many of these limitations by moving most of your code to PNOlet, but this is a completely different and more complex topic.

If you want to do something more complex that may take some time (for example, loading a web page or downloading email), it is highly recommended not to do this during the alarm trigger code. You can do something in the sysAppLaunchCmdDisplayAlarm startup code and display the form to the user, allowing them to cancel. But this should quickly be annoying.

It’s better for the user (but much more difficult) to become a background application. This is a bit of black magic and is not really well supported, but it is possible. There are three main ways to make a background application:

  • Protect your application database with DmDatabaseProtect. This ensures that your application is locked, so it cannot be deleted.

  • Lock the code segment using MemHandleLock and MemHandleSetOwner (set the owner to 0). This ensures that your code is loaded into memory and not moved.

  • Register for some notifications. For example, sysNotifyIdleTimeEvent is a great notification for periodic background processing.

After you set this, you can exit the alarm start code, and then wait for your notifications to be triggered. Then you will do all the background processing when notification handlers are called.

Also, make sure that if you allocate any system objects (memory, descriptors, file descriptors, etc.), you set their owner to 0 (system) if you expect them to persist after you return from notification handler. Otherwise, the system will clear them. If you do, be extremely careful to avoid memory and resource leaks! They will never be cleared if the owner is set to 0!

To leave the background mode, just do the opposite: unregister, open your code segment and remove protection from the application database.

If you perform any network operations in the background, make sure that you set the sockets to non-blocking mode and deal with it correctly! Otherwise, you will block the foreground application and cause problems.

+7
source

Source: https://habr.com/ru/post/1276636/


All Articles