34#include <NDEVR/Model.h>
35#include <NDEVR/DesignObjectUpdateTarget.h>
36#include <NDEVR/TimeSpan.h>
37#include <NDEVR/String.h>
39#if NDEVR_SUPPORTS_THREADING
134#if NDEVR_SUPPORTS_THREADING
138#if NDEVR_SUPPORTS_THREADING
161 virtual void run()
override;
A core class where all Design Objects including models, materials, and geometries are stored.
An object that will be called to update each time the lookup is updated.
A class that updates a device by repeatedly calling update() until stop() is called.
DeviceUpdateThread(DesignObjectLookup *lookup, Device *sensor)
Constructs an update thread for the given device.
Device * m_sensor
The device being updated by this thread.
void stop()
Signals the update loop to stop and waits for the thread to finish.
DesignObjectLookup * m_lookup
Design object lookup for update context.
volatile bool m_is_running
Flag controlling the update loop execution.
virtual void run() override
The main thread loop that repeatedly calls the device's update method.
A root class which describes some physical object, such as a Motor, Sensor, or Connection.
virtual TimeSpan updateInterval() const
Returns the time interval between automatic updates.
void startAutoUpdate(DesignObjectLookup *lookup=nullptr)
Starts automatic periodic updating of this device on a background thread.
void setWarningCallback(const std::function< void(const Exception &warning, LogPtr log)> &warning_callback)
Sets a callback to be invoked when a warning is generated by this device.
virtual void endUpdates()
Called when the auto-update loop ends, allowing cleanup.
virtual void update(Time)
Called to update the device with only the current time.
LogPtr deviceLog() const
Returns the log associated with this device.
void stopAutoUpdate(DesignObjectLookup *lookup=nullptr)
Stops automatic periodic updating of this device.
virtual void showWarning(const TranslatedString &warning) const
Displays a warning message through the warning callback or log.
static DesignObjectLookup * s_default_lookup
Default design object lookup shared by all devices.
virtual void update(DesignObjectLookup *lookup, Time time) override
Called by the update system to update this device with design context.
std::function< void(const Exception &warning, LogPtr log)> m_warning_callback
Callback invoked when warnings are generated.
virtual void setLog(LogPtr log)
Sets the log used for device diagnostics.
LogPtr m_log
Log for device diagnostic messages.
static void SetDefaultDeviceLookup(DesignObjectLookup *lookup)
Sets the default DesignObjectLookup used by all devices when none is specified.
Device(const Model &model, LogPtr log, QObject *parent=nullptr)
Constructs a Device from a Model with the given log and optional Qt parent.
virtual void showWarning(const Exception &warning) const
Displays a warning exception through the warning callback or log.
DeviceUpdateThread * m_update_thread
Background thread for auto-updating this device.
void onUpdated()
Emitted after the device has been updated.
Provides consistent interface to handle errors through the throw expression.
A light-weight base class for Log that allows processes to update, without the need for additional in...
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
Model()
Default constructor. Creates an uninitialized Model.
Stores a time span, or difference between two times, with an optional start time.
Represents a timestamp with utilities for manipulation and conversion.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
The primary namespace for the NDEVR SDK.