Bifrost SDK
Bifrost SDK documentation
BifrostGraph::Executor::Workspace Class Reference

The Workspace is the central element of the BifrostGraph Executor. More...

#include <Workspace.h>

Public Types

template<typename T >
using DeleterFunc = void(*)(T *p)
 The signature for the custom pointer deleter of a pointee p. More...
 

Public Member Functions

virtual ~Workspace () noexcept
 Destructor. More...
 
virtual bool isValid () const noexcept
 Check if this Workspace has been successfully initialized. More...
 
bool loadConfigFiles (const StringArray &configFiles, const StringArray &disabledPacks=StringArray()) noexcept
 Read the Bifrost configuration JSON files listed in configFiles, excluding from them the packs listed in disabledPacks, and then load all resources listed in these files. More...
 
bool registerTypeTranslationsPlugins (TypeTranslation::PluginHostData *hostData) const noexcept
 Let the TypeTranslations register any plugins or data types they need. More...
 
bool unregisterTypeTranslationsPlugins (TypeTranslation::PluginHostData *hostData) const noexcept
 Let the TypeTranslations unregister any previously registered plugins or data types. More...
 
template<typename Functor >
GraphContaineraddGraphContainerT (Functor &&func) noexcept
 Create a new GraphContainer and add it to this Workspace. This template method allows one to create and add an instance of their own subclass of the GraphContainer base class by passing a Functor func that creates such an instance of their subclass. More...
 
bool deleteGraphContainer (GraphContainer &graphContainer) noexcept
 Delete the GraphContainer referred by graphContainer and remove it from this Workspace. Once deleted, any attempt to access the methods of graphContainer will produce undefined behavior. More...
 
const WatchpointgetWatchpoint (const Amino::TypeId &typeId) const noexcept
 Get the Watchpoint registered for the Amino::TypeId typeId. More...
 
const LibrarygetLibrary () const noexcept
 Get the Library that is used by this Workspace. More...
 
LibrarygetLibrary () noexcept
 Get the Library that is used by this Workspace. More...
 
GraphContaineraddGraphContainer () noexcept
 Aliases for adding an instance of a GraphContainer base class, using an optional custom deleter function. These alias methods call the generic addGraphContainerT<> template method, passing a Functor that creates a new instance of a GraphContainer base class. More...
 
GraphContaineraddGraphContainer (DeleterFunc< GraphContainer > deleter) noexcept
 Aliases for adding an instance of a GraphContainer base class, using an optional custom deleter function. These alias methods call the generic addGraphContainerT<> template method, passing a Functor that creates a new instance of a GraphContainer base class. More...
 
WatchpointLayoutFactory const & getWatchpointLayoutFactory () const noexcept
 Get the watchpoint layout factory. More...
 
WatchpointLayoutFactorygetWatchpointLayoutFactory () noexcept
 Get the watchpoint layout factory. More...
 
const Private::IRestrictedWorkspaceServices & getRestrictedServices () const noexcept
 Obtain an interface giving access to private Workspace services. More...
 
Private::IRestrictedWorkspaceServices & getRestrictedServices () noexcept
 Obtain an interface giving access to private Workspace services. More...
 

Static Public Member Functions

static WorkspacegetInvalid () noexcept
 Get a statically allocated Workspace that is uninitialized, invalid and not linked to any Library, GraphContainer or Job. Any operation on this instance will always fail and Workspace::isValid will return false. More...
 

Protected Member Functions

 Workspace (const Amino::String &name) noexcept
 Construct a Workspace. The Workspace is initialized with a newly created BifrostGraph::Executor::Library with the given name. More...
 
 Workspace (Uninitialized uninitialized) noexcept
 Constructor that leaves the Workspace in an uninitialized state. More...
 
 EXECUTOR_DECLARE_MAKE_OWNER_FRIENDSHIP ()
 Allow the makeOwner<> factory functions to access the constructors of this class. More...
 
void reportMessage (MessageCategory category, const Amino::String &message) const noexcept
 Report a message from this Workspace and call the Workspace's onReportedMessage notification method. The source of the reported message will be set to MessageSource::kWorkspace. More...
 

Private Member Functions

virtual void onReportedMessage (MessageSource source, MessageCategory category, const Amino::String &message) const noexcept
 The method called by the Workspace to notify the deriving class that a message was reported by this Workspace, its BifrostGraph::Executor::Library, a BifrostGraph::Executor::GraphContainer or a Job. Bifrost can call this method asynchronously in some situations such as reporting information when loading configuration files, loading definition files, loading a compound, terminating a job etc. If overridden, the implementation of this method must be thread safe and must not throw any exception. More...
 

Friends

class Private::WorkspaceImpl
 

Detailed Description

The Workspace is the central element of the BifrostGraph Executor.

A Workspace object holds a Library that stores all Bifrost resources and GraphContainers that represent the graphs to be executed. For the time being, a Library should not be shared by multiple Workspaces, since the Library modifications are not yet thread safe. On the other hand, creating a Library, loading resources into it and then sharing it in read-only with another Workspace could be supported in the future, but there are no mechanism that enforces the read-only mode, so users would have to be careful here.

Definition at line 69 of file Workspace.h.

Member Typedef Documentation

◆ DeleterFunc

template<typename T >
using BifrostGraph::Executor::Workspace::DeleterFunc = void (*)(T* p)

The signature for the custom pointer deleter of a pointee p.

This is the custom deleter type used by the Workspace::addGraphContainer(DeleterFunc<GraphContainer>) alias method.

Template Parameters
Tthe storage type used for the owned GraphContainer object.
Parameters
[in]pa pointer to the owned object to destruct. Can be nullptr.

Definition at line 234 of file Workspace.h.

Constructor & Destructor Documentation

◆ Workspace() [1/2]

BifrostGraph::Executor::Workspace::Workspace ( const Amino::String name)
explicitprotectednoexcept

Construct a Workspace. The Workspace is initialized with a newly created BifrostGraph::Executor::Library with the given name.

If an error occurs during the construction of this Workspace, or its underlying BifrostGraph::Executor::Library, then BifrostGraph::Executor::Workspace::isValid will return false and all future operations on this Workspace will fail.

This constructor is protected to force the usage of factory functions BifrostGraph::Executor::makeOwner (see Factory.h) to create it. If a class is derived from Workspace, it is recommended to keep protected the constructors on the derived class, and still use the factory functions to create a derived class instance.

Parameters
[in]nameAn optional name for the BifrostGraph::Executor::Library.

◆ Workspace() [2/2]

BifrostGraph::Executor::Workspace::Workspace ( Uninitialized  uninitialized)
explicitprotectednoexcept

Constructor that leaves the Workspace in an uninitialized state.

After this constructor returns, the method BifrostGraph::Executor::Workspace::isValid will return false and all future operations on the Workspace will fail.

Parameters
[in]uninitializedan Uninitialized enum value.
Warning
This constructor is used internally by the Executor. Use with caution.

◆ ~Workspace()

virtual BifrostGraph::Executor::Workspace::~Workspace ( )
virtualnoexcept

Destructor.

Member Function Documentation

◆ addGraphContainer() [1/2]

GraphContainer & BifrostGraph::Executor::Workspace::addGraphContainer ( )
noexcept

Aliases for adding an instance of a GraphContainer base class, using an optional custom deleter function. These alias methods call the generic addGraphContainerT<> template method, passing a Functor that creates a new instance of a GraphContainer base class.

◆ addGraphContainer() [2/2]

GraphContainer & BifrostGraph::Executor::Workspace::addGraphContainer ( DeleterFunc< GraphContainer deleter)
noexcept

Aliases for adding an instance of a GraphContainer base class, using an optional custom deleter function. These alias methods call the generic addGraphContainerT<> template method, passing a Functor that creates a new instance of a GraphContainer base class.

◆ addGraphContainerT()

template<typename Functor >
GraphContainer & BifrostGraph::Executor::Workspace::addGraphContainerT ( Functor &&  func)
inlinenoexcept

Create a new GraphContainer and add it to this Workspace. This template method allows one to create and add an instance of their own subclass of the GraphContainer base class by passing a Functor func that creates such an instance of their subclass.

Template Parameters
Functorthe function used to create a new instance of a GraphContainer, wrapped in an Owner object. The signature of this function must be: Owner<GraphContainer> func(Private::IGraphContainerOwner& owner);
Parameters
functhe function called by this method to create a new GraphContainer.
Returns
If this Workspace is valid, and if func returned a non-empty Owner<> containing a valid GraphContainer, and if the Workspace has successfully added it, then a reference to the newly added GraphContainer is returned; otherwise, a reference to an invalid GraphContainer is returned.

Definition at line 207 of file Workspace.h.

References BifrostGraph::Executor::GraphContainer::getInvalid().

◆ deleteGraphContainer()

bool BifrostGraph::Executor::Workspace::deleteGraphContainer ( GraphContainer graphContainer)
noexcept

Delete the GraphContainer referred by graphContainer and remove it from this Workspace. Once deleted, any attempt to access the methods of graphContainer will produce undefined behavior.

Returns
true if graphContainer is owned by this Workspace and it has been successfully deleted and removed; false otherwise.

◆ EXECUTOR_DECLARE_MAKE_OWNER_FRIENDSHIP()

BifrostGraph::Executor::Workspace::EXECUTOR_DECLARE_MAKE_OWNER_FRIENDSHIP ( )
protected

Allow the makeOwner<> factory functions to access the constructors of this class.

◆ getInvalid()

static Workspace & BifrostGraph::Executor::Workspace::getInvalid ( )
staticnoexcept

Get a statically allocated Workspace that is uninitialized, invalid and not linked to any Library, GraphContainer or Job. Any operation on this instance will always fail and Workspace::isValid will return false.

◆ getLibrary() [1/2]

const Library & BifrostGraph::Executor::Workspace::getLibrary ( ) const
noexcept

Get the Library that is used by this Workspace.

If the Workspace is valid, then the returned Library will also be valid. Otherwise, the returned Library will be invalid (see BifrostGraph::Executor::Library::isValid).

Returns
A reference to the Library that is used by this Workspace.

◆ getLibrary() [2/2]

Library & BifrostGraph::Executor::Workspace::getLibrary ( )
noexcept

Get the Library that is used by this Workspace.

If the Workspace is valid, then the returned Library will also be valid. Otherwise, the returned Library will be invalid (see BifrostGraph::Executor::Library::isValid).

Returns
A reference to the Library that is used by this Workspace.

◆ getRestrictedServices() [1/2]

const Private::IRestrictedWorkspaceServices & BifrostGraph::Executor::Workspace::getRestrictedServices ( ) const
noexcept

Obtain an interface giving access to private Workspace services.

Precondition
This Workspace must be valid (BifrostGraph::Executor::Workspace::isValid). Calling this method on an invalid Workspace will produce undefined behavior.
Note
This is an internal method used by the Executor SDK.
Returns
A reference to the IRestrictedWorkspaceServices interface of this Workspace.

◆ getRestrictedServices() [2/2]

Private::IRestrictedWorkspaceServices & BifrostGraph::Executor::Workspace::getRestrictedServices ( )
noexcept

Obtain an interface giving access to private Workspace services.

Precondition
This Workspace must be valid (BifrostGraph::Executor::Workspace::isValid). Calling this method on an invalid Workspace will produce undefined behavior.
Note
This is an internal method used by the Executor SDK.
Returns
A reference to the IRestrictedWorkspaceServices interface of this Workspace.

◆ getWatchpoint()

const Watchpoint * BifrostGraph::Executor::Workspace::getWatchpoint ( const Amino::TypeId typeId) const
noexcept

Get the Watchpoint registered for the Amino::TypeId typeId.

Parameters
typeIdThe Amino::TypeId for which to get the Watchpoint.
Returns
The Watchpoint registered for typeId or nullptr if none is registered for it.

◆ getWatchpointLayoutFactory() [1/2]

WatchpointLayoutFactory const & BifrostGraph::Executor::Workspace::getWatchpointLayoutFactory ( ) const
noexcept

Get the watchpoint layout factory.

Returns
The watchpoint layout factory.

◆ getWatchpointLayoutFactory() [2/2]

WatchpointLayoutFactory & BifrostGraph::Executor::Workspace::getWatchpointLayoutFactory ( )
noexcept

Get the watchpoint layout factory.

Returns
The watchpoint layout factory.

◆ isValid()

virtual bool BifrostGraph::Executor::Workspace::isValid ( ) const
virtualnoexcept

Check if this Workspace has been successfully initialized.

If an error occurs during the construction of a Workspace, isValid() will return false and all future operations on the Workspace will fail. If this method is overridden, the deriving implementation should first call the base class implementation to check if this Workspace is valid, then do its own subclass validation.

Returns
true if this Workspace has been successfully initialized and is ready to be used; false otherwise.

◆ loadConfigFiles()

bool BifrostGraph::Executor::Workspace::loadConfigFiles ( const StringArray configFiles,
const StringArray disabledPacks = StringArray() 
)
noexcept

Read the Bifrost configuration JSON files listed in configFiles, excluding from them the packs listed in disabledPacks, and then load all resources listed in these files.

The details about the errors that may occur while reading the configuration data, or while loading the resources, are reported by calls to Workspace's onReportedMessage. All configuration files are read even if errors are detected while reading them. If any error is detected while reading the configuration files, none of the resources they list will be loaded and false will be returned.

Parameters
[in]configFilesA list of Bifrost configuration JSON files to read.
[in]disabledPacksThe list of packs to skip, designated by their library names in the Bifrost configuration JSON files.
Returns
true if all Bifrost configuration JSON files have been successfully read and all resources have been successfully loaded; false if an error occurred while reading the Bifrost configuration JSON files or while loading the resources they list.

◆ onReportedMessage()

virtual void BifrostGraph::Executor::Workspace::onReportedMessage ( MessageSource  source,
MessageCategory  category,
const Amino::String message 
) const
privatevirtualnoexcept

The method called by the Workspace to notify the deriving class that a message was reported by this Workspace, its BifrostGraph::Executor::Library, a BifrostGraph::Executor::GraphContainer or a Job. Bifrost can call this method asynchronously in some situations such as reporting information when loading configuration files, loading definition files, loading a compound, terminating a job etc. If overridden, the implementation of this method must be thread safe and must not throw any exception.

Parameters
sourceThe source of this message.
categoryThe message category.
messageThe message itself.
Note
The default implementation writes information (MessageCategory::kInfo) and warning (MessageCategory::kWarning) messages to the output stream object std::cout, and writes error (MessageCategory::kError) messages to the output stream object std::cerr.

◆ registerTypeTranslationsPlugins()

bool BifrostGraph::Executor::Workspace::registerTypeTranslationsPlugins ( TypeTranslation::PluginHostData hostData) const
noexcept

Let the TypeTranslations register any plugins or data types they need.

This method will call TypeTranslation::registerHostPlugins with the hostData argument on each registered TypeTranslation resource object.

Parameters
hostDataThe host data to pass to each registerHostPlugins function to call.
Returns
true if all registerHostPlugins called functions have returned true; false otherwise.

◆ reportMessage()

void BifrostGraph::Executor::Workspace::reportMessage ( MessageCategory  category,
const Amino::String message 
) const
protectednoexcept

Report a message from this Workspace and call the Workspace's onReportedMessage notification method. The source of the reported message will be set to MessageSource::kWorkspace.

Parameters
categoryThe message category.
messageThe message itself.

◆ unregisterTypeTranslationsPlugins()

bool BifrostGraph::Executor::Workspace::unregisterTypeTranslationsPlugins ( TypeTranslation::PluginHostData hostData) const
noexcept

Let the TypeTranslations unregister any previously registered plugins or data types.

This method will call TypeTranslation::unregisterHostPlugins with the hostData argument on each registered TypeTranslation resource object.

Parameters
hostDataThe host data to pass to each unregisterHostPlugins function to call.
Returns
true if all unregisterHostPlugins called functions have returned true; false otherwise.

Friends And Related Function Documentation

◆ Private::WorkspaceImpl

friend class Private::WorkspaceImpl
friend

Definition at line 355 of file Workspace.h.