Package COM.INFORMATIMAGO.COMMON-LISP.CESARUM.ACTIVITY

This package implements a kind of co-routine monitor.

An activity is a closure that is called at specified times (T+k*P).
It should return before processing can go on.  This package is
implemented in pure Common Lisp and allows to schedule independent
"tasks" portably, as long as you can split each task in small
chunks, timewise.


License:

    AGPL3

    Copyright Pascal J. Bourguignon 2003 - 2012

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.
    If not, see <http://www.gnu.org/licenses/>
(activity-closure activity)
generic-function
RETURN: the closure executed each time the activity is scheduled.
(activity-dropable-p activity)
generic-function
RETURN: Whether the activity should be skipped instead of scheduled too late.
(activity-exact-p activity)
generic-function
RETURN: Whether the activity should be run only on exact time.
(activity-name activity)
generic-function
RETURN: A label for the activity.
(activity-period activity)
generic-function
RETURN: The period of this activity, expressed in seconds.  If zero,
        then the activity is run as often as possible.
(activity-run &key one-step until)
function
DO:         Runs the scheduler.
ONE-STEP:   If true, runs only one activity (or don't sleep).
UNTIL:      Time (in universal-time seconds) until which activities
            must be run.
(activity-scheduled-time activity)
generic-function
RETURN: The scheduled time this activity should run.
(activity-yield)
function
DO:         Returns control to the scheduler.
NOTE:       This may be called from an activity closure to return
            early to the scheduler.
(activityp object)
function
RETURN: Whether the OBJECT is an instance of the ACTIVITY class (or
        one of its subclasses).
(all-activities)
function
RETURN:  A new list of all the activities.
(current-activity)
function
RETURN: The current activity.
(destroy-activity activity)
function
DO: Remove the activity from the scheduling queue.
(get-time timebase)
generic-function
RETURN:     Current number of seconds since epoch.
TIMEBASE:   :universal-time to get the time from (get-univeral-time),
            :real-time      to get the time from (get-internal-real-time),
            :run-time       to get the time from (get-internal-run-time).
            (in all cases, the time is in number of seconds since the epoch).
(make-activity function &key name start-at start-in period dropable exact idle scheduler)
function
FUNCTION:   A closure, that will be repeatitively called at specified times.
NAME:       A string, naming the activity.
PERIOD:     A real indicating the period of the activity.
            If 0 then run it when idle.
START-AT:   (mutually exclusive with START-IN)
            The first universal-time at which the activity should run.
START-IN:   (mutually exclusive with START-AT)
            The number of seconds from now when the activity should be
            run first.
            If none of START-AT or START-IN is specified, the start
            time is now.
*SCHEDULER* The scheduler used to run this activity.
(print-activities &optional stream)
function
DO:         Prints on the STREAM a formated list of activities.
STREAM:     An output stream to which the list of activities is
            printed.  Defaults to *STANDARD-OUTPUT*.