Vuo  1.2.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
VuoRunner Class Reference

Description

This class runs and controls a composition that has been compiled and linked by VuoCompiler.

The composition can run in the same process as the VuoRunner or in a separate process, depending on how the VuoRunner is constructed.

To construct a VuoRunner, use one of the factory methods:

To start a composition running, call start() or startPaused(). To stop the composition, call stop(). The composition must be stopped by the time VuoRunner's destructor is called. If the composition process ends on its own, the VuoRunner detects this and stops itself.

While the composition is running, the VuoRunner can control it by sending control request messages to it. The VuoRunner functions that send control request messages must only be called while the composition is running. They are mutually thread-safe, so they may be called concurrently with each other. These functions include:

While the composition is running, the VuoRunner receives telemetry messages from it. To receive notifications of these messages, create a class that inherits from VuoRunnerDelegate, and call VuoRunner::setDelegate().

See Also
Developing Applications that Use Vuo
VuoRunnerCocoa (a similar API, in Objective-C)

Classes

class  Port
 This class represents a published port in a composition. More...
 

Public Member Functions

 ~VuoRunner (void)
 Destructor.
 
void start (void)
 Starts the composition running.
 
void startPaused (void)
 Starts the composition running, but in a paused state.
 
void runOnMainThread (void)
 For a composition in the current process, runs the composition on the main thread until it stops (either on its own or from a call to stop() on another thread).
 
void drainMainDispatchQueue (void)
 For a composition in the current process, briefly performs work that requires the main thread (such as Cocoa event handling).
 
void pause (void)
 Sends a control request to the composition telling it to cease firing events.
 
void unpause (void)
 Sends a control request to the composition telling it to resume firing events.
 
void replaceComposition (string compositionDylibPath, string resourceDylibPath, string compositionDiff)
 Sends a control request to the composition loader telling it to load an updated version of the running composition.
 
void stop (void)
 Sends a control request to the composition telling it to stop.
 
void waitUntilStopped (void)
 Waits until the composition is stopped.
 
void setPublishedInputPortValue (Port *port, json_object *value)
 Sends a control request to the composition telling it to modify a published input port's value.
 
void firePublishedInputPortEvent (Port *port)
 Sends a control request to the composition telling it to fire an event into a published input port.
 
void firePublishedInputPortEvent (void)
 Sends a control request to the composition telling it to fire an event into all published input ports.
 
void waitForAnyPublishedOutputPortEvent (void)
 Waits until the first event following a call to firePublishedInputPortEvent() comes out of any published output port.
 
json_objectgetPublishedInputPortValue (Port *port)
 Sends a control request to the composition telling it to retrieve a published input port's value.
 
json_objectgetPublishedOutputPortValue (Port *port)
 Sends a control request to the composition telling it to retrieve a published output port's value.
 
vector< Port * > getPublishedInputPorts (void)
 Returns the list of published input ports in the composition.
 
vector< Port * > getPublishedOutputPorts (void)
 Returns the list of published output ports in the composition.
 
PortgetPublishedInputPortWithName (string name)
 Returns the published input port with the given name, or NULL if no such port exists.
 
PortgetPublishedOutputPortWithName (string name)
 Returns the published output port with the given name, or NULL if no such port exists.
 
void setInputPortValue (string portIdentifier, json_object *value)
 Sends a control request to the composition telling it to modify an input port's value.
 
void fireTriggerPortEvent (string portIdentifier)
 Sends a control request to the composition telling it to fire an event from the trigger port.
 
json_objectgetInputPortValue (string portIdentifier)
 Sends a control request to the composition telling it to retrieve an input port's value.
 
json_objectgetOutputPortValue (string portIdentifier)
 Sends a control request to the composition telling it to retrieve an output port's value.
 
string getInputPortSummary (string portIdentifier)
 Sends a control request to the composition telling it to retrieve an input port's summary.
 
string getOutputPortSummary (string portIdentifier)
 Sends a control request to the composition telling it to retrieve an output port's summary.
 
string subscribeToInputPortTelemetry (string portIdentifier)
 Sends a control request to the composition telling it to start sending telemetry for each event through an input port.
 
string subscribeToOutputPortTelemetry (string portIdentifier)
 Sends a control request to the composition telling it to start sending telemetry for each event through an output port.
 
void unsubscribeFromInputPortTelemetry (string portIdentifier)
 Sends a control request to the composition telling it to stop sending telemetry for each event through an input port.
 
void unsubscribeFromOutputPortTelemetry (string portIdentifier)
 Sends a control request to the composition telling it to stop sending telemetry for each event through an output port.
 
void subscribeToEventTelemetry (void)
 Sends a control request to the composition telling it to start sending telemetry for all events.
 
void unsubscribeFromEventTelemetry (void)
 Sends a control request to the composition telling it to stop sending telemetry for all events.
 
void subscribeToAllTelemetry (void)
 Sends a control request to the composition telling it to start sending all telemetry.
 
void unsubscribeFromAllTelemetry (void)
 Sends a control request to the composition telling it to stop sending all telemetry The composition will continue sending any telemetry subscribed by subscribeToInputPortTelemetry(), subscribeToOutputPortTelemetry(), or subscribeToEventTelemetry().
 
bool isStopped (void)
 Returns true if the composition either has not been started or has been started and stopped.
 
void setDelegate (VuoRunnerDelegate *delegate)
 Sets the delegate that receives telemetry messages from the running composition.
 
void setTrialRestrictions (bool isTrial)
 If true, some nodes may restrict how they can be used.
 

Static Public Member Functions

static VuoRunnernewSeparateProcessRunnerFromCompositionFile (string compositionPath, bool continueIfRunnerDies=false, bool useExistingCache=false)
 Creates a runner object that can run the composition in file compositionPath in a new process.
 
static VuoRunnernewSeparateProcessRunnerFromCompositionString (string compositionString, string name, string sourceDir, bool continueIfRunnerDies=false, bool useExistingCache=false)
 Creates a runner object that can run a composition in a new process.
 
static VuoRunnernewSeparateProcessRunnerFromExecutable (string executablePath, string sourceDir, bool continueIfRunnerDies, bool deleteExecutableWhenFinished)
 Creates a runner that can run a composition in a new process.
 
static VuoRunnernewSeparateProcessRunnerFromExecutable (string executablePath, string sourceDir, bool deleteExecutableWhenFinished=false)
 
static VuoRunnernewSeparateProcessRunnerFromDynamicLibrary (string compositionLoaderPath, string compositionDylibPath, string resourceDylibPath, string sourceDir, bool continueIfRunnerDies=false, bool deleteDylibsWhenFinished=false)
 Creates a runner object that can run a composition in a new process and replace the composition with a new version while it's running.
 
static VuoRunnernewCurrentProcessRunnerFromDynamicLibrary (string dylibPath, string sourceDir, bool deleteDylibWhenFinished=false)
 Creates a runner object that can run a composition in the current process.
 
static void initializeCompilerCache ()
 Initializes the compiler's cache in a separate process.
 

Friends

class TestVuoRunner
 

Constructor & Destructor Documentation

VuoRunner::~VuoRunner ( void  )

Destructor.

Assumes the composition either has not been started or has been started and stopped.

Member Function Documentation

void VuoRunner::drainMainDispatchQueue ( void  )

For a composition in the current process, briefly performs work that requires the main thread (such as Cocoa event handling).

Repeated calls to this function allow the composition to run without taking over the main thread like runOnMainThread() does.

Start calling this function after start() or startPaused().

There's no need to call this function if your application calls dispatch_main(), NSApplicationMain(), or UIApplicationMain(), or if it invokes a CFRunLoop on the main thread.

Throws a std::logic_error if this runner was not constructed to run the composition in the current process or if this function was not called on the main thread.

Example:
runner->start();
while (! runner->isStopped())
{
// do other work on the main thread
}

This can be used only in 64-bit applications, not 32-bit applications.

See Also
runOnMainThread(), an alternative to this function.
void VuoRunner::firePublishedInputPortEvent ( VuoRunner::Port port)

Sends a control request to the composition telling it to fire an event into a published input port.

Upon return, the event will have been fired.

Assumes the composition has been started, is not paused, and has not been stopped.

void VuoRunner::firePublishedInputPortEvent ( void  )

Sends a control request to the composition telling it to fire an event into all published input ports.

This is a single event that goes to all published input ports simultaneously.

Upon return, the event will have been fired.

Assumes the composition has been started, is not paused, and has not been stopped.

void VuoRunner::fireTriggerPortEvent ( string  portIdentifier)

Sends a control request to the composition telling it to fire an event from the trigger port.

If the trigger port carries data, its most recent data is fired along with the event.

Upon return, the event will have been fired.

Assumes the composition has been started and has not been stopped.

Parameters
portIdentifierThe compile-time identifier for the port (see VuoCompilerEventPort::getIdentifier()).
string VuoRunner::getInputPortSummary ( string  portIdentifier)

Sends a control request to the composition telling it to retrieve an input port's summary.

Assumes the composition has been started and has not been stopped.

Parameters
portIdentifierThe compile-time identifier for the port (see VuoCompilerEventPort::getIdentifier()).
Returns
A brief description of the port's value.
See Also
Built-in Types for information about types and their summaries.
json_object * VuoRunner::getInputPortValue ( string  portIdentifier)

Sends a control request to the composition telling it to retrieve an input port's value.

Assumes the composition has been started and has not been stopped.

Parameters
portIdentifierThe compile-time identifier for the port (see VuoCompilerEventPort::getIdentifier()).
Returns
JSON representation of the port's value.
See Also
Built-in Types for information about types and their JSON representations.
string VuoRunner::getOutputPortSummary ( string  portIdentifier)

Sends a control request to the composition telling it to retrieve an output port's summary.

Assumes the composition has been started and has not been stopped.

Parameters
portIdentifierThe compile-time identifier for the port (see VuoCompilerEventPort::getIdentifier()).
Returns
A brief description of the port's value.
See Also
Built-in Types for information about types and their summaries.
json_object * VuoRunner::getOutputPortValue ( string  portIdentifier)

Sends a control request to the composition telling it to retrieve an output port's value.

Assumes the composition has been started and has not been stopped.

Parameters
portIdentifierThe compile-time identifier for the port (see VuoCompilerEventPort::getIdentifier()).
Returns
JSON representation of the port's value.
See Also
Built-in Types for information about types and their JSON representations.
vector< VuoRunner::Port * > VuoRunner::getPublishedInputPorts ( void  )

Returns the list of published input ports in the composition.

This function may either send a control request to the composition or use cached values.

Assumes the composition has been started and has not been stopped.

json_object * VuoRunner::getPublishedInputPortValue ( VuoRunner::Port port)

Sends a control request to the composition telling it to retrieve a published input port's value.

Assumes the composition has been started and has not been stopped.

Parameters
portThe published input port.
Returns
JSON representation of the port's value.
See Also
Built-in Types for information about types and their JSON representations.
VuoRunner::Port * VuoRunner::getPublishedInputPortWithName ( string  name)

Returns the published input port with the given name, or NULL if no such port exists.

This function may either send a control request to the composition or use cached values.

Assumes the composition has been started and has not been stopped.

vector< VuoRunner::Port * > VuoRunner::getPublishedOutputPorts ( void  )

Returns the list of published output ports in the composition.

This function may either send a control request to the composition or use cached values.

Assumes the composition has been started and has not been stopped.

json_object * VuoRunner::getPublishedOutputPortValue ( VuoRunner::Port port)

Sends a control request to the composition telling it to retrieve a published output port's value.

Assumes the composition has been started and has not been stopped.

Parameters
portThe published output port.
Returns
JSON representation of the port's value.
See Also
Built-in Types for information about types and their JSON representations.
VuoRunner::Port * VuoRunner::getPublishedOutputPortWithName ( string  name)

Returns the published output port with the given name, or NULL if no such port exists.

This function may either send a control request to the composition or use cached values.

Assumes the composition has been started and has not been stopped.

void VuoRunner::initializeCompilerCache ( )
static

Initializes the compiler's cache in a separate process.

This function is useful in conjunction with newSeparateProcessRunnerFromCompositionFile() or newSeparateProcessRunnerFromCompositionString() , when using the useExistingCache for those functions.

This function is less efficient than VuoCompiler::prepareForFastBuild(), so you should call that function instead unless you're running compositions from a 32-bit process and thus can't use VuoCompiler.

bool VuoRunner::isStopped ( void  )

Returns true if the composition either has not been started or has been started and stopped.

VuoRunner * VuoRunner::newCurrentProcessRunnerFromDynamicLibrary ( string  dylibPath,
string  sourceDir,
bool  deleteDylibWhenFinished = false 
)
static

Creates a runner object that can run a composition in the current process.

Parameters
dylibPathA linked composition dynamic library, produced by VuoCompiler::linkCompositionToCreateDynamicLibrary().
sourceDirThe directory containing the composition (.vuo) source file, used by nodes in the composition to resolve relative paths.
deleteDylibWhenFinishedTrue if the runner should delete dylibPath when it's finished using the file.

This can be used only in 64-bit applications, not 32-bit applications.

See Also
CompileAndRunInCurrentProcess.cc
VuoRunner * VuoRunner::newSeparateProcessRunnerFromCompositionFile ( string  compositionPath,
bool  continueIfRunnerDies = false,
bool  useExistingCache = false 
)
static

Creates a runner object that can run the composition in file compositionPath in a new process.

Parameters
compositionPathA composition (.vuo) file.
continueIfRunnerDiesIf true, the composition keeps running if the runner process exits without stopping the composition.
useExistingCacheIf true, the build is sped up by skipping the step of ensuring that the compiler's cache exists.
VuoRunner * VuoRunner::newSeparateProcessRunnerFromCompositionString ( string  compositionString,
string  name,
string  sourceDir,
bool  continueIfRunnerDies = false,
bool  useExistingCache = false 
)
static

Creates a runner object that can run a composition in a new process.

Parameters
compositionStringA string containing the composition source code.
nameThe executable filename that the running composition should use.
sourceDirThe directory nodes should use to resolve relative paths in the composition.
continueIfRunnerDiesIf true, the composition keeps running if the runner process exits without stopping the composition.
useExistingCacheIf true, the build is sped up by skipping the step of ensuring that the compiler's cache exists.
VuoRunner * VuoRunner::newSeparateProcessRunnerFromDynamicLibrary ( string  compositionLoaderPath,
string  compositionDylibPath,
string  resourceDylibPath,
string  sourceDir,
bool  continueIfRunnerDies = false,
bool  deleteDylibsWhenFinished = false 
)
static

Creates a runner object that can run a composition in a new process and replace the composition with a new version while it's running.

Parameters
compositionLoaderPathThe VuoCompositionLoader executable.
compositionDylibPathA linked composition dynamic library, produced by VuoCompiler::linkCompositionToCreateDynamicLibraries().
resourceDylibPathA linked resource dynamic library, produced by the first call to VuoCompiler::linkCompositionToCreateDynamicLibraries() for this runner.
sourceDirThe directory containing the composition (.vuo) source file, used by nodes in the composition to resolve relative paths.
continueIfRunnerDiesIf true, the composition keeps running if the runner process exits without stopping the composition.
deleteDylibsWhenFinishedTrue if the runner should delete compositionDylibPath and resourceDylibPath when it's finished using the files.
VuoRunner * VuoRunner::newSeparateProcessRunnerFromExecutable ( string  executablePath,
string  sourceDir,
bool  continueIfRunnerDies,
bool  deleteExecutableWhenFinished 
)
static

Creates a runner that can run a composition in a new process.

Parameters
executablePathA linked composition executable, produced by VuoCompiler::linkCompositionToCreateExecutable().
sourceDirThe directory containing the composition (.vuo) source file, used by nodes in the composition to resolve relative paths.
continueIfRunnerDiesIf true, the composition keeps running if the runner process exits without stopping the composition.
deleteExecutableWhenFinishedTrue if the runner should delete executablePath when it's finished using the file.
See Also
CompileAndRunInNewProcess.cc
VuoRunner * VuoRunner::newSeparateProcessRunnerFromExecutable ( string  executablePath,
string  sourceDir,
bool  deleteExecutableWhenFinished = false 
)
static
void VuoRunner::pause ( void  )

Sends a control request to the composition telling it to cease firing events.

Upon return, no more events will be fired and all events will have finished propagating through the composition.

Assumes the composition has been started, is not paused, and has not been stopped.

void VuoRunner::replaceComposition ( string  compositionDylibPath,
string  resourceDylibPath,
string  compositionDiff 
)

Sends a control request to the composition loader telling it to load an updated version of the running composition.

Upon return, the old version of the composition will have stopped and the updated version will have started.

Assumes the composition loader has been started and has not been stopped.

Parameters
compositionDylibPathA linked composition dynamic library, produced by VuoCompiler::linkCompositionToCreateDynamicLibrary().
resourceDylibPathA linked resource dynamic library, produced by a call to VuoCompiler::linkCompositionToCreateDynamicLibraries() for this runner. Pass an empty string if no linked resource dynamic library was created.
compositionDiffA comparison of the old and new compositions, produced by VuoCompilerComposition::diffAgainstOlderComposition().
void VuoRunner::runOnMainThread ( void  )

For a composition in the current process, runs the composition on the main thread until it stops (either on its own or from a call to stop() on another thread).

Call this function after start() or startPaused().

There's no need to call this function if your application calls dispatch_main(), NSApplicationMain(), or UIApplicationMain(), or if it invokes a CFRunLoop on the main thread.

Throws a std::logic_error if this runner was not constructed to run the composition in the current process or if this function was not called on the main thread.

This can be used only in 64-bit applications, not 32-bit applications.

See Also
drainMainDispatchQueue(), an alternative to this function.
void VuoRunner::setDelegate ( VuoRunnerDelegate delegate)

Sets the delegate that receives telemetry messages from the running composition.

May be null.

void VuoRunner::setInputPortValue ( string  portIdentifier,
json_object value 
)

Sends a control request to the composition telling it to modify an input port's value.

Upon return, the input port value will have been modified.

Assumes the composition has been started and has not been stopped.

Parameters
portIdentifierThe compile-time identifier for the port (see VuoCompilerEventPort::getIdentifier()).
valueJSON representation of the port's new value.
See Also
Built-in Types for information about types and their JSON representations.
void VuoRunner::setPublishedInputPortValue ( VuoRunner::Port port,
json_object value 
)

Sends a control request to the composition telling it to modify a published input port's value.

Upon return, the published input port value will have been modified.

Assumes the composition has been started and has not been stopped.

Parameters
portThe published input port.
valueJSON representation of the port's new value.
See Also
Built-in Types for information about types and their JSON representations.
void VuoRunner::setTrialRestrictions ( bool  isTrial)

If true, some nodes may restrict how they can be used.

Call this before start.

void VuoRunner::start ( void  )

Starts the composition running.

If running the composition in the current process, a call to this method must be followed by either a call to runOnMainThread() or repeated calls to drainMainDispatchQueue() in order to run the composition.

If running the composition in a separate process, no further calls are needed to run the composition.

If running the composition in the current process, the current working directory is changed to the composition source directory that was passed to newCurrentProcessRunnerFromDynamicLibrary() until the composition is stopped.

Assumes the composition is not already running.

void VuoRunner::startPaused ( void  )

Starts the composition running, but in a paused state.

This is useful if you want to call setPublishedInputPortValue() before the composition begins firing events. To unpause the composition, call unpause().

If running the composition in the current process, a call to this method must be followed by either a call to runOnMainThread() or repeated calls to drainMainDispatchQueue() in order to run the composition.

If running the composition in a separate process, no further calls are needed.

If running the composition in the current process, the current working directory is changed to the composition source directory that was passed to newCurrentProcessRunnerFromDynamicLibrary() until the composition is stopped.

Assumes the composition is not already running.

void VuoRunner::stop ( void  )

Sends a control request to the composition telling it to stop.

Upon return, the composition will have stopped. If the composition was running in a separate process, that process will have ended.

If the composition has already stopped on its own, this function skips sending the control request. It just performs some cleanup.

This function waits for any pending VuoRunnerDelegate function calls to return.

Assumes the composition has been started and has not been stopped.

void VuoRunner::subscribeToAllTelemetry ( void  )

Sends a control request to the composition telling it to start sending all telemetry.

Assumes the composition has been started and has not been stopped.

void VuoRunner::subscribeToEventTelemetry ( void  )

Sends a control request to the composition telling it to start sending telemetry for all events.

Assumes the composition has been started and has not been stopped.

string VuoRunner::subscribeToInputPortTelemetry ( string  portIdentifier)

Sends a control request to the composition telling it to start sending telemetry for each event through an input port.

Assumes the composition has been started and has not been stopped.

Parameters
portIdentifierThe compile-time identifier for the port (see VuoCompilerEventPort::getIdentifier()).
Returns
A brief description of the port's value.
See Also
Built-in Types for information about types and their summaries.
string VuoRunner::subscribeToOutputPortTelemetry ( string  portIdentifier)

Sends a control request to the composition telling it to start sending telemetry for each event through an output port.

Assumes the composition has been started and has not been stopped.

Parameters
portIdentifierThe compile-time identifier for the port (see VuoCompilerEventPort::getIdentifier()).
Returns
A brief description of the port's value.
See Also
Built-in Types for information about types and their summaries.
void VuoRunner::unpause ( void  )

Sends a control request to the composition telling it to resume firing events.

Assumes the composition is paused.

void VuoRunner::unsubscribeFromAllTelemetry ( void  )

Sends a control request to the composition telling it to stop sending all telemetry The composition will continue sending any telemetry subscribed by subscribeToInputPortTelemetry(), subscribeToOutputPortTelemetry(), or subscribeToEventTelemetry().

Assumes the composition has been started and has not been stopped.

void VuoRunner::unsubscribeFromEventTelemetry ( void  )

Sends a control request to the composition telling it to stop sending telemetry for all events.

The composition will continue sending any telemetry subscribed by subscribeToInputPortTelemetry(), subscribeToOutputPortTelemetry() or subscribeToAllTelemetry().

Assumes the composition has been started and has not been stopped.

void VuoRunner::unsubscribeFromInputPortTelemetry ( string  portIdentifier)

Sends a control request to the composition telling it to stop sending telemetry for each event through an input port.

Assumes the composition has been started and has not been stopped.

Parameters
portIdentifierThe compile-time identifier for the port (see VuoCompilerEventPort::getIdentifier()).
void VuoRunner::unsubscribeFromOutputPortTelemetry ( string  portIdentifier)

Sends a control request to the composition telling it to stop sending telemetry for each event through an output port.

Assumes the composition has been started and has not been stopped.

Parameters
portIdentifierThe compile-time identifier for the port (see VuoCompilerEventPort::getIdentifier()).
void VuoRunner::waitForAnyPublishedOutputPortEvent ( void  )

Waits until the first event following a call to firePublishedInputPortEvent() comes out of any published output port.

The event that comes out may not be the same as the one fired by firePublishedInputPortEvent() if the composition contains trigger ports. The event also may not be finished traveling through the composition if the composition contains a branch where the event travels through multiple parts of the composition concurrently.

Assumes the composition has been started and has not been stopped.

Example:
runner.setPublishedInputPortValue(inputPort, inputValue);
runner.setPublishedInputPortValue(anotherInputPort, anotherInputValue);
runner.firePublishedInputPortEvent(inputPort);
result = runner.getPublishedOutputPortValue(outputPort);
void VuoRunner::waitUntilStopped ( void  )

Waits until the composition is stopped.

If the composition is already stopped, this function returns immediately.


The documentation for this class was generated from the following files: