Low-level Activity API: Difference between revisions

From OLPC
Jump to navigation Jump to search
m (→‎Overview: wording)
Line 8: Line 8:
The [[#Activity Factory|factory service]] provides a <tt>org.laptop.ActivityFactory.create()</tt> method which spawns an activity instance. Each activity instance has a unique <tt>activity_id</tt> which is passed as one of the parameters to the <tt>create()</tt> method.
The [[#Activity Factory|factory service]] provides a <tt>org.laptop.ActivityFactory.create()</tt> method which spawns an activity instance. Each activity instance has a unique <tt>activity_id</tt> which is passed as one of the parameters to the <tt>create()</tt> method.


Each [[#Activity Instance|activity instance]] opens an X window. This window must have two utf8 string properties, <code>_SUGAR_BUNDLE_ID</code> specifying the service name and <code>_SUGAR_ACTIVITY_ID</code> which is the id that was passed to <code>create()</code>. The instance registers a DBus object at <tt>/org/laptop/Activity/''id''</tt> where ''id'' is the decimal XID of the window. This object must implement the <tt>org.laptop.Activity</tt> interface.
Each [[#Activity Instance|activity instance]] opens an X window. This window must have two string properties, <code>_SUGAR_BUNDLE_ID</code> specifying the service name and <code>_SUGAR_ACTIVITY_ID</code> which is the id that was passed to <code>create()</code>. The instance registers a DBus object at <tt>/org/laptop/Activity/''id''</tt> where ''id'' is the decimal XID of the window. This object must implement the <tt>org.laptop.Activity</tt> interface.


When the last activity instance exits, the factory service should quit.
When the last activity instance exits, the factory service should quit.

Revision as of 22:15, 19 June 2007

Most activities will use the Python API to implement activities. This page will document the underlying mechanism that non-Python activities need to conform to.

This documentation effort was started by Bert while implementing the Squeak-based Etoys activity. Please fill in missing pieces and correct mistakes!

Overview

An Activity Bundle can specify an executable in the activity.info's exec field. When installing the bundle, the path of this executable will be expanded and added to the list of DBus services in $HOME/.local/share/dbus-1/services/ using the DBus service name as specified in the service_name field. When launching an activity from Sugar shell, a request to that DBus service is made, which makes DBus run the previously specified executable. The executable must create a "factory service" on the DBus using the specified service name.

The factory service provides a org.laptop.ActivityFactory.create() method which spawns an activity instance. Each activity instance has a unique activity_id which is passed as one of the parameters to the create() method.

Each activity instance opens an X window. This window must have two string properties, _SUGAR_BUNDLE_ID specifying the service name and _SUGAR_ACTIVITY_ID which is the id that was passed to create(). The instance registers a DBus object at /org/laptop/Activity/id where id is the decimal XID of the window. This object must implement the org.laptop.Activity interface.

When the last activity instance exits, the factory service should quit.

Activity Factory

Service name: my.organization.MyActivity (from activity bundle info file)

Object path: /my/organization/MyActivity (derived from service name)

Interface: org.laptop.ActivityFactory

org.laptop.ActivityFactory.create(params)

The create() method creates a new Activity instance. That instance is exposed on the DBus as /org/laptop/Activity/123456 where the number 123456 is the instance's top-level window XID.

The params dictionary can have the following entries:

activity_id
unique id for the activity to be created
pservice_id
identity of the sharing service for this activity in the PresenceService
object_id
identity of the journal object associated with the activity. When you resume an activity from the journal the object_id will be passed in.
uri
URI associated with the activity. Used when opening an external file or resource in the activity, rather than a journal object (downloads stored on the file system for example or web pages)

Activity Instance

Service name: org.laptop.Activity123456 (where 123456 is the window's XID)

Object path: /org/laptop/Activity/123456 (where 123456 is the window's XID)

Interface: org.laptop.Activity

An activity instance needs to support the following methods:

org.laptop.Activity.get_id()

Get the activity identifier as passed into create() (e.g., 6f7f3acacca87886332f50bdd522d805f0abbf1f).

org.laptop.Activity.get_service_name()

Get the activity factory service name (e.g., my.organization.MyActivity).

org.laptop.Activity.share()

Called by the shell to request the activity to share itself on the network.

org.laptop.Activity.get_shared()

Returns True if the activity is shared on the mesh.

org.laptop.Activity.set_active(active)

Activate or passivate an activity. Passive activities must release resources like sound, camera etc.

org.laptop.Activity.execute(cmd, args[])

Optional - execute a command defined in the activity, answer True on success. might be deprecated soon

Example

[Activity]
name = My Activity
activity_version = 1
host_version = 1
service_name = my.organization.MyActivity
icon = activity-my
exec = myactivityfactory
show_launcher = yes

Signal /org/freedesktop/DBus org.freedesktop.DBus.NameAcquired(':1.23')

Signal /org/freedesktop/DBus org.freedesktop.DBus.NameAcquired('my.organization.MyActivity')

MethodCall /my/organization/MyActivity org.freedesktop.DBus.Introspectable.Introspect()

MethodCall /my/organization/MyActivity org.laptop.ActivityFactory.create(activity_id='6f7f3acacca87886332f50bdd522d805f0abbf1f')

(create X window with ID 0xA00002 = 10485762)

Signal /org/freedesktop/DBus org.freedesktop.DBus.NameAcquired('org.laptop.Activity10485762')

MethodCall /org/laptop/Activity/10485762 org.freedesktop.DBus.Introspectable.Introspect()

MethodCall /org/laptop/Activity/10485762 org.laptop.Activity.get_id()

MethodCall /org/laptop/Activity/10485762 org.laptop.Activity.get_service_name()