WSF
WsfScriptObserver Class Reference

#include <WsfScriptObserver.hpp>

Inheritance diagram for WsfScriptObserver:
Collaboration diagram for WsfScriptObserver:

Classes

struct  EventData
class  EventGuard

Public Types

using ScriptList = std::vector<UtScript*>
using EventList = std::vector<EventData>
using EventToIndexMap = std::map<std::string, int>
template<typename... Args>
using Observer = UtCallbackListN<void(double, Args...)>

Public Member Functions

 WsfScriptObserver (WsfSimulation &aSimulation, const WsfScriptObserverExtension &aScenario)
 ~WsfScriptObserver () override=default
void AddedToSimulation () override
bool Initialize () override
void Start () override
WSF_DEPRECATED int AddEvent (const std::string &aEventName, std::unique_ptr< UtCallback > aCallbackPtr, const std::string &aDefaultScriptName, const std::string &aExpectedArgumentTypes)
template<bool EnableGuard = false, typename... Args, typename ArgPacker>
void AddEvent (const std::string &aEventName, Observer< Args... > &aObserver, const std::string &aDefaultScriptName, const std::string &aExpectedArgumentTypes, const ArgPacker &aArgPacker)
template<bool EnableGuard = false, typename... Args>
void AddEvent (const std::string &aEventName, Observer< Args... > &aObserver, const std::string &aDefaultScriptName, const std::string &aExpectedArgumentTypes)
int GetEventIndex (const std::string &aEventName) const
ScriptListGetScriptList (int aIndex)
const EventListGetEvents () const
const EventToIndexMapGetEventIndexes () const
void EventEntry ()
void EventExit ()
bool EnableOrDisable (bool aEnable, const std::string &aCallbackName, const std::string &aScriptName)
bool EnableOrDisable (bool aEnable, const std::string &aEventName, const std::string &aScriptName, EventData &aEventData)
const EventToIndexMap GetEventMap () const
void ExecuteScriptList (double aSimTime, const std::vector< UtScript * > &aScriptList)
void ExecuteScriptList (double aSimTime, const std::vector< UtScript * > &aScriptList, UtScriptData &aScriptRetVal, UtScriptDataList &aScriptArgs)
Public Member Functions inherited from WsfSimulationExtension
 WsfSimulationExtension ()
 ~WsfSimulationExtension () override=default
WsfSimulationGetSimulation () const
const WsfScenarioGetScenario () const
virtual bool PrepareExtension ()
virtual bool PlatformsInitialized ()
virtual void PendingStart ()
virtual void Complete (double aSimTime)
Public Member Functions inherited from WsfExtension
virtual ~WsfExtension ()=default
const std::string & GetExtensionName () const

Static Public Member Functions

static WsfScriptObserverFind (const WsfSimulation &aSimulation)
static void __private_SetSim (WsfSimulationExtension &aExtension, WsfSimulation *aSimPtr)

Protected Member Functions

 WsfScriptObserver (const WsfScriptObserver &aSrc)=delete
 Copy constructor is declared but not defined to prevent use.
Protected Member Functions inherited from WsfExtension
void InitializeExtensionName (const std::string &aName)

Protected Attributes

UtCallbackHolder mCallbacks
 Container to hold registered callbacks.

Detailed Description

WsfScriptObserver allows script methods to be registered with observer callbacks

Member Typedef Documentation

◆ EventList

◆ EventToIndexMap

using WsfScriptObserver::EventToIndexMap = std::map<std::string, int>

◆ Observer

template<typename... Args>
using WsfScriptObserver::Observer = UtCallbackListN<void(double, Args...)>

◆ ScriptList

using WsfScriptObserver::ScriptList = std::vector<UtScript*>

Constructor & Destructor Documentation

◆ WsfScriptObserver() [1/2]

◆ ~WsfScriptObserver()

WsfScriptObserver::~WsfScriptObserver ( )
overridedefault

◆ WsfScriptObserver() [2/2]

WsfScriptObserver::WsfScriptObserver ( const WsfScriptObserver & aSrc)
protecteddelete

Copy constructor is declared but not defined to prevent use.

References WsfScriptObserver().

Member Function Documentation

◆ AddedToSimulation()

void WsfScriptObserver::AddedToSimulation ( )
overridevirtual

Called in response to WsfSimulation::RegisterExtension. The extension has now been registered in the simulation.

Reimplemented from WsfSimulationExtension.

References AddEvent(), WsfObserver::CommAddedToLocal(), WsfObserver::CommAddedToManager(), WsfObserver::Comment(), WsfObserver::CommFrequencyChanged(), WsfObserver::CommRemovedFromLocal(), WsfObserver::CommRemovedFromManager(), WsfObserver::CommTurnedOff(), WsfObserver::CommTurnedOn(), WsfObserver::CrashedIntoGround(), WsfObserver::ExecuteCallback(), WsfObserver::FuelEvent(), WsfSimulationExtension::GetSimulation(), WsfObserver::ImageCreated(), WsfObserver::LinkAddedToLocal(), WsfObserver::LinkAddedToManager(), WsfObserver::LinkDisabledOnLocal(), WsfObserver::LinkDisabledOnManager(), WsfObserver::LinkEnabledOnLocal(), WsfObserver::LinkEnabledOnManager(), WsfObserver::LinkRemovedFromLocal(), WsfObserver::LinkRemovedFromManager(), WsfObserver::LocalTrackCorrelation(), WsfObserver::LocalTrackDecorrelation(), WsfObserver::LocalTrackDropped(), WsfObserver::LocalTrackInitiated(), WsfObserver::LocalTrackUpdated(), WsfObserver::MessageDeliveryAttempt(), WsfObserver::MessageDiscarded(), WsfObserver::MessageFailedRouting(), WsfObserver::MessageHop(), WsfObserver::MessageQueued(), WsfObserver::MessageReceived(), WsfObserver::MessageTransmitEnded(), WsfObserver::MessageTransmitted(), WsfObserver::MessageTransmittedHeartbeat(), WsfObserver::MessageUpdated(), WsfObserver::MoverBroken(), WsfObserver::MoverBurnedOut(), WsfObserver::MoverStaged(), WsfObserver::MoverUpdated(), WsfObserver::NetworkAdded(), WsfObserver::NetworkRemoved(), WsfObserver::OperatingLevelChanged(), WsfObserver::PlatformAdded(), WsfObserver::PlatformAppearanceChanged(), WsfObserver::PlatformBroken(), WsfObserver::PlatformCapabilityChanged(), WsfObserver::PlatformDeleted(), WsfObserver::PlatformInitialized(), WsfObserver::PlatformOmitted(), WsfObserver::ProcessorTurnedOff(), WsfObserver::ProcessorTurnedOn(), WsfObserver::RouterTurnedOff(), WsfObserver::RouterTurnedOn(), WsfObserver::SensorDetectionAttempt(), WsfObserver::SensorDetectionChanged(), WsfObserver::SensorFrequencyChanged(), WsfObserver::SensorModeActivated(), WsfObserver::SensorModeDeactivated(), WsfObserver::SensorRequestCanceled(), WsfObserver::SensorRequestInitiated(), WsfObserver::SensorRequestUpdated(), WsfObserver::SensorTrackCoasted(), WsfObserver::SensorTrackDropped(), WsfObserver::SensorTrackInitiated(), WsfObserver::SensorTrackUpdated(), WsfObserver::SensorTurnedOff(), WsfObserver::SensorTurnedOn(), WsfObserver::SimulationComplete(), WsfObserver::StateEntry(), WsfObserver::StateExit(), WsfObserver::TankingEvent(), WsfObserver::TaskAssigned(), WsfObserver::TaskCanceled(), and WsfObserver::TaskCompleted().

Referenced by ~WsfScriptObserver().

◆ AddEvent() [1/3]

template<bool EnableGuard = false, typename... Args>
void WsfScriptObserver::AddEvent ( const std::string & aEventName,
Observer< Args... > & aObserver,
const std::string & aDefaultScriptName,
const std::string & aExpectedArgumentTypes )
inline

Register an event using the default argument packer, which will pack script arguments directly from the Observer in order (see UtScriptDataPack). Rather than a separate overload, this argument packer could have been provided as the default value for the ArgPacker in the 5-argument version above. However, a bug (#53837) in gcc versions < 4.9 gives a parse error when expanding a parameter pack in a function argument default value.

References AddEvent().

◆ AddEvent() [2/3]

template<bool EnableGuard, typename... Args, typename ArgPacker>
void WsfScriptObserver::AddEvent ( const std::string & aEventName,
Observer< Args... > & aObserver,
const std::string & aDefaultScriptName,
const std::string & aExpectedArgumentTypes,
const ArgPacker & aArgPacker )

Register an event, providing a function that will pack the arguments for the script.

Template Parameters
EnableGuardEnables the event guard for multi-threading safety (default false)
Parameters
aEventNameThe name of the event
aObserverThe observer which will trigger the script
aDefaultScriptNameThe name of the user script to execute, if none is specified
aExpectedArgumentTypesThe signature of the script
aArgPackerCallable object to pack the arguments for the script. Should have signature: void fun(UtScriptDataPacker&, Args...)

References ExecuteScriptList(), WsfSimulation::GetApplication(), GetEventIndex(), GetScriptList(), WsfApplication::GetScriptTypes(), WsfSimulationExtension::GetSimulation(), and detail::make_event_guard().

◆ AddEvent() [3/3]

WSF_DEPRECATED int WsfScriptObserver::AddEvent ( const std::string & aEventName,
std::unique_ptr< UtCallback > aCallbackPtr,
const std::string & aDefaultScriptName,
const std::string & aExpectedArgumentTypes )
inline

◆ EnableOrDisable() [1/2]

bool WsfScriptObserver::EnableOrDisable ( bool aEnable,
const std::string & aEventName,
const std::string & aScriptName )

Enable or disable the callback, specified by event name, with the Observer.

Parameters
aEnable'true' indicates the callback should be enabled.
aEventNameThe name of the callback to register.
aScriptNameThe name of the script to be associated with the callback.

References EnableOrDisable(), GetEventIndex(), and ok.

Referenced by EnableOrDisable(), and Initialize().

◆ EnableOrDisable() [2/2]

◆ EventEntry()

void WsfScriptObserver::EventEntry ( )

Perform initial processing upon entry into processing an event. All registered callback observers that issue output to the event stream should call this method prior to issuing any output for the event.

References WsfSimulationExtension::GetSimulation().

◆ EventExit()

void WsfScriptObserver::EventExit ( )

Perform final processing upon exit from processing an event. Registered callback observers that call EventEntry should call this method just prior to leaving the method.

References WsfSimulationExtension::GetSimulation().

◆ ExecuteScriptList() [1/2]

void WsfScriptObserver::ExecuteScriptList ( double aSimTime,
const std::vector< UtScript * > & aScriptList )

◆ ExecuteScriptList() [2/2]

void WsfScriptObserver::ExecuteScriptList ( double aSimTime,
const std::vector< UtScript * > & aScriptList,
UtScriptData & aScriptRetVal,
UtScriptDataList & aScriptArgs )

◆ Find()

◆ GetEventIndex()

int WsfScriptObserver::GetEventIndex ( const std::string & aEventName) const

◆ GetEventIndexes()

const EventToIndexMap & WsfScriptObserver::GetEventIndexes ( ) const
inline

◆ GetEventMap()

const EventToIndexMap WsfScriptObserver::GetEventMap ( ) const
inline

◆ GetEvents()

const EventList & WsfScriptObserver::GetEvents ( ) const
inline

◆ GetScriptList()

ScriptList & WsfScriptObserver::GetScriptList ( int aIndex)
inline

Referenced by AddEvent(), Initialize(), and Start().

◆ Initialize()

bool WsfScriptObserver::Initialize ( )
overridevirtual

Called in response to WsfSimulation::Initialize. This is called to allow the extension to perform any initialization that is required.

Note
The extension should not assume that another extension has been initialized unless it this extension has been registered as a dependency of the other extension.

Reimplemented from WsfSimulationExtension.

References EnableOrDisable(), ExecuteScriptList(), GetEventIndex(), and GetScriptList().

Referenced by ~WsfScriptObserver().

◆ Start()

void WsfScriptObserver::Start ( )
overridevirtual

Called in response to a call to WsfSimulation::Start. WsfSimulation::Start is typically called immediately before entry in the main event loop. The simulation is in its initial state, although the extension may also add additional platforms. using WsfSimulation::AddPlatform.

Reimplemented from WsfSimulationExtension.

References ExecuteScriptList(), GetEventIndex(), and GetScriptList().

Referenced by ~WsfScriptObserver().

Member Data Documentation

◆ mCallbacks

UtCallbackHolder WsfScriptObserver::mCallbacks
protected

Container to hold registered callbacks.


The documentation for this class was generated from the following files:
Copyrights Multiple, All Rights Reserved