I was wondering whether there are any restrictions on the use of Objects passed between processes via ApplicationManager.postGlobalEvent or the RuntimeStore.
On the device I have a GUI application that interacts with the user and a daemon application that the GUI application calls to perform tasks. I would like to be able to pass a callback interface from the daemon application to the GUI application. So in a shared library I might have a DaemonServices callback interface:
Code:
public interface DaemonServices {
public long executeTask1();
public long executeTask2();
public int getStatus(long taskID);
...
}
The daemon would pass an instance of this interface to the GUI application:
Code:
DaemonServices daemonCallback = new DaemonServicesImpl();
appMgr.postGlobalEvent(guiPid, EnumEvents.REGISTER_CALLBACK_EVENT, 0, 0, daemonCallback, null);
The GUI application would receive the callback interface, and could then use it to execute tasks in the daemon:
Code:
private DaemonServices _daemonCallback;
private class GUIGlobalEventListener implements GlobalEventListener {
public void eventOccurred(long guid, int data0, int data1, Object object0, Object object1) {
if (guid == EnumEvents.REGISTER_CALLBACK_EVENT) {
_daemonCallback = object0;
}
}
}
....
private void someInternalMethod() {
long taskID = _daemonCallback.executeTask1();
...
}
The methods on DaemonServices would be non-blocking. For example, executeTask1() would simply cause a task to be queued for a daemon thread to execute later. Also, the daemon application would be a system application that is started when the device starts up, so it would always be alive when the GUI tries to communicate with it.
This model (having a thread in one application perform operations in another application) seems to violate process isolation somewhat, but the RIM API clearly supports it. Am I safe in using this model as long as I'm careful about how I implement the DaemonServices operations? Are there any other problems I could run into--for example, if the device was shutting down and the daemon application terminated before the GUI application?
Thanks...