xentara-plugin v2.0.4
The Xentara Plugin Framework
Loading...
Searching...
No Matches
xentara::skill::Skill Class Referenceabstract

A Xentara skill. More...

#include <xentara/skill/Skill.hpp>

+ Inheritance diagram for xentara::skill::Skill:

Classes

class  Class
 Meta-Information about a skill class. More...
 
class  ConcreteClass
 Convenience subclass of Class that implements all callbacks. More...
 

Public Member Functions

virtual ~Skill ()=0
 Virtual destructor.
 
virtual auto loadConfig (utils::json::decoder::Object &jsonObject, config::Context &context) -> void
 Called by the framework to load the skill’s configuration from a JSON object.
 
virtual auto createElement (const Element::Class &elementClass, skill::ElementFactory &factory) -> std::shared_ptr< Element >=0
 Called by the framework to create a new top-level element.
 
- Public Member Functions inherited from xentara::utils::tools::DisableCopy
constexpr DisableCopy () noexcept=default
 
 DisableCopy (const DisableCopy &)=delete
 
DisableCopyoperator= (const DisableCopy &)=delete
 

Static Public Member Functions

static auto persistentDataPath (const std::filesystem::path &skillSubdirectory, const std::filesystem::path &subPath) -> std::filesystem::path
 Makes a path suitable for storing persistent data for a skill.
 

Detailed Description

A Xentara skill.

Constructor & Destructor Documentation

◆ ~Skill()

xentara::skill::Skill::~Skill ( )
pure virtualdefault

Virtual destructor.

Member Function Documentation

◆ createElement()

virtual auto xentara::skill::Skill::createElement ( const Element::Class elementClass,
skill::ElementFactory factory 
) -> std::shared_ptr< Element >
pure virtual

Called by the framework to create a new top-level element.

This function is called to create elements that are not children of any other elements belonging to the same skill. To create an element that is the child of another skill element, Element::createChildElement() is called instead.

The implementation for this method must use the given factory to create a new element of the given element class:

return factory.makeShared<MyElement>();

If your skill requires access to the element later, you must store a pointer or reference to it.

The framework will call load() on the newly created element.

Parameters
elementClassThe class for the new element
factoryThe factory that must be used to create the element
Returns
The newly created element, or nullptr if the skill does not support top-level elements of the given class.
Exceptions
std::runtime_errorThe function must throw this exception (or a suitable subclass) if an error occurs
See also
Creating Skill Element Objects

Implemented in xentara::io::Driver::Environment, and xentara::process::ServiceProvider::Environment.

◆ loadConfig()

virtual auto xentara::skill::Skill::loadConfig ( utils::json::decoder::Object jsonObject,
config::Context context 
) -> void
virtual

Called by the framework to load the skill’s configuration from a JSON object.

This callback is called if the Xentara configuration file contains a section for this skill.

If there is no section for this skill in the Xentara configuration file, this function is never called. The skill should generally provide default values for all configuration parameters, but if a default value is not possible, then the skill must handle that situation gracefully. This means that no exception must be thrown if no skill element belonging to this skill is created. Otherwise, the mere presence of the skill plugin on the system will force the user to configure the skill, even if it is not used. Generally, the first skill element that needs the configuration should throw an error if it is missing, not the skill itself.

Default Implementation
The default implementation throws an error denoting that the skill does not have any configurable parameters.
Parameters
jsonObjectThe JSON object
contextA context that can be used to find external configurations. The context cannot be used to resolve cross-references or create synthetic children, as that only makes sense when loading the Xentara model file.
Exceptions
std::runtime_errorThe function must throw this exception (or a suitable subclass) if an error occurs

◆ persistentDataPath()

static auto xentara::skill::Skill::persistentDataPath ( const std::filesystem::path skillSubdirectory,
const std::filesystem::path subPath 
) -> std::filesystem::path
static

Makes a path suitable for storing persistent data for a skill.

Parameters
skillSubdirectoryThe skill subdirectory. This should generally be the skill name without any “Xentara” prefix, in all lowercase, with dashes as word separator. The skill subdirectory for the Xentara EtherCAT Driver, for example, should be “xentara-ethercat-driver”.
subPathThe sub path beneath the skill subdirectory.
Returns
The absolute path to use to store the data.