The R Project SVN R

Rev

Rev 59039 | Rev 70260 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/base/man/taskCallbackManager.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 1995-2011 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
17067 duncan 6
\name{taskCallbackManager}
56186 murdoch 7
\alias{taskCallbackManager}
50821 ripley 8
\title{Create an R-level Task Callback Manager}
20029 duncan 9
\description{
10
  This provides an entirely S-language mechanism
11
  for managing callbacks or actions  that are invoked at
12
  the conclusion of each top-level task.  Essentially,
13
  we register a single R function from this manager
14
  with the underlying, native
15
  task-callback mechanism and this function handles invoking the other
16
  R callbacks under the control of the manager.
17
  The manager consists of a collection of functions that access shared
18
  variables to manage the list of user-level callbacks.
19
}
17067 duncan 20
\usage{
30912 ripley 21
taskCallbackManager(handlers = list(), registered = FALSE,
22
                    verbose = FALSE)
17067 duncan 23
}
24
\arguments{
25
  \item{handlers}{this can be a list of callbacks in which each element
26
    is a list with  an element  named \code{"f"}
27
    which is a callback function, and an optional
28
    element named \code{"data"} which is the 5-th argument to be
29
    supplied  to the callback when it is invoked.
30
    Typically this argument is not specified, and one uses \code{add} to
31
    register callbacks after the manager is created.}
32
  \item{registered}{a logical value indicating whether
33
    the \code{evaluate} function has already been registered
34
    with the internal task callback mechanism.
61433 ripley 35
    This is usually \code{FALSE} and
17067 duncan 36
    the first time a callback is added
37
    via the \code{add} function, the
38
    \code{evaluate} function is automatically registered.
39
    One can control when the function is registered
40
    by specifying \code{TRUE} for this argument
41
    and calling \code{\link{addTaskCallback}} manually.
42
  }
43
  \item{verbose}{a logical value, which if \code{TRUE},
44
    causes information to be printed to the console
45
    about certain activities this dispatch manager performs.
46
    This is useful for debugging callbacks and the handler
47
    itself.
48
  }
49
}
50
\value{
51
  A list containing 6 functions:
52
  \item{add}{register a callback with this manager, giving the
53
    function, an optional 5-th argument, an optional name
27625 ripley 54
    by which the callback is stored in the list,
17067 duncan 55
    and a \code{register} argument which controls whether
56
    the \code{evaluate} function is registered with the internal
57
    C-level dispatch mechanism if necessary.}
58
  \item{remove}{remove an element from the manager's collection
59
    of callbacks, either by name or position/index.}
25118 hornik 60
  \item{evaluate}{the \sQuote{real} callback function that is registered
17067 duncan 61
    with the C-level dispatch mechanism and which invokes each of the
27625 ripley 62
    R-level callbacks within this manager's control.}
17067 duncan 63
  \item{suspend}{a function to set the suspend state
55555 ripley 64
    of the manager.  If it is suspended, none of the callbacks will be
65
    invoked when a task is completed.  One sets the state by specifying
17067 duncan 66
    a logical value for the \code{status} argument.
67
  }
68
  \item{register}{a function to register the \code{evaluate}
55555 ripley 69
    function with the internal C-level dispatch mechanism.  This is
17067 duncan 70
    done automatically by the \code{add} function, but can be called
71
    manually.}
72
  \item{callbacks}{returns the list of callbacks being maintained by this
73
   manager.}
74
}
75
\seealso{
30912 ripley 76
  \code{\link{addTaskCallback}},
77
  \code{\link{removeTaskCallback}},
78
  \code{\link{getTaskCallbackNames}}\\
61433 ripley 79
  \url{http://developer.r-project.org/TaskHandlers.pdf}
17067 duncan 80
}
81
\examples{
30915 ripley 82
# create the manager
83
h <- taskCallbackManager()
17067 duncan 84
 
30915 ripley 85
# add a callback
86
h$add(function(expr, value, ok, visible) {
47616 ripley 87
                       cat("In handler\n")
88
                       return(TRUE)
89
                     }, name = "simpleHandler")
17067 duncan 90
 
30915 ripley 91
# look at the internal callbacks.
92
getTaskCallbackNames()
17067 duncan 93
 
30915 ripley 94
# look at the R-level callbacks
41607 ripley 95
names(h$callbacks())
30915 ripley 96
 
97
getTaskCallbackNames()
98
removeTaskCallback("R-taskCallbackManager")
17067 duncan 99
}
100
\keyword{environment}