Maemo initialization
All maemo applications need to be initialized correctly, or they will not work as expected.
Initializing application is performed with osso_initialize() function.
- Connects to D-Bus session bus and system bus.
- Should only be called once in the application.
- The structure of type osso_context_t type that is returned should be stored for later use.
osso_context_t* /* shoud be stored for later use */
osso_initialize(const gchar *application,/* D-BUS name */
const gchar* version, /* application version */
gboolean activation, /* TURE: application binary has been launched by the D-Bus
GMainContext *context /* GLib main-loop context to connect to */
)
osso_deinitialize() should be called to close the message bus connection and free all the memory allocated by the library.
void osso_deinitialize(osso_context_t* osso);
Remote Process Messages
System wide messages in maemo platform are handled with D-BUS system messaging, which is a Remote Process Communication (RPC) method.
osso_rpc_set_cb_f(...);
gint dbus_message_handler(const gchar* interface,
const gchar* method,
GArray* arguments,
gpointer data,
sso_rpc_t* retval);
osso_rpc_run(osso_context,
const gchar* service,
const gchar* object,
const gchar* interface,
const gchar* message,
...);
The receiving application does not even need to be started: D-BUS can automatically start the application based on its service file, and then pass the message to it!.
Hardware State Messages
Maemo applications can connect to listen the system D-BUS messages, like "battery low" and "shutdown".When these messages are received, the application may want to ask the user to save files that are open, or react however wanted.
void hw_event_handler(osso_hw_state_t* state, gpointer data);
state->memory_low_ind
state->system_inactivity_ind
osso_hw_set_event_cb( appdata->osso_context, NULL, hw_event_handler, (gpointer)appdata );
These hardware events are not sent to the SDK, testing them is only possible in maemo device.
System Exit Message
void exit_event_handler(gboolean die_now, goiinter data);
osso_application_set_exit_cb(appdata->osso_context,
exit_event_handler,
(gpointer)appdata);
whenever the system needs to close an application for any reason, exit_event_handler will be performed gracefully.
Information on how to implement state saving can be found in LibOSSO API document.
沒有留言:
張貼留言