API Documentation
Loading...
Searching...
No Matches
Device.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Hardware
28File: Device
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/Model.h>
35#include <NDEVR/DesignObjectUpdateTarget.h>
36#include <NDEVR/TimeSpan.h>
37#include <NDEVR/String.h>
38#include <QObject>
39#if NDEVR_SUPPORTS_THREADING
40#include <QThread>
41#endif
42namespace NDEVR
43{
44 class DesignObjectLookup;
45 class ProgressInfo;
46 class DeviceUpdateThread;
47 /**--------------------------------------------------------------------------------------------------
48 \brief A root class which describes some physical object, such as a Motor, Sensor, or Connection.
49 Devices are updated automatically by calling startAutoUpdate and stopAutoUpdate.
50 **/
51 class HARDWARE_API Device : public QObject, public Model, public DesignObjectUpdateTarget
52 {
53 Q_OBJECT
54 public:
55 Device(const Model& model, ProgressInfo* log, QObject* parent = nullptr);
56 virtual void setLog(ProgressInfo* log) { m_log = log; };
57 virtual void update(DesignObjectLookup* lookup, Time time) override;
58 virtual void update() {};
59 [[nodiscard]] virtual TimeSpan updateInterval() const { return TimeSpan(1.0f); }
60 virtual void endUpdates() {}
61 [[nodiscard]] ProgressInfo* deviceLog() const { return m_log; }
62 void setWarningCallback(const std::function<void(const Exception& warning, ProgressInfo* log)>& warning_callback);
63 void startAutoUpdate(DesignObjectLookup* lookup = nullptr);
64 void stopAutoUpdate(DesignObjectLookup* lookup = nullptr);
66 signals:
67 void onUpdated();
68 protected:
69 virtual void showWarning(const TranslatedString& warning) const;
70 virtual void showWarning(const Exception& warning) const;
71 protected:
73 std::function<void(const Exception& warning, ProgressInfo* log)> m_warning_callback;
75#if NDEVR_SUPPORTS_THREADING
76 DeviceUpdateThread* m_update_thread = nullptr;
77#endif
78 };
79#if NDEVR_SUPPORTS_THREADING
80 /**--------------------------------------------------------------------------------------------------
81 \brief A class that updates a device by repeatedly calling update() until stop() is called.
82
83 \warning Should not be called or created directly and instead will be generated by calling Device().startAutoUpdate
84 and Device().stopAutoUpdate
85 **/
86 class HARDWARE_API DeviceUpdateThread : public QThread
87 {
88 public:
92 virtual ~DeviceUpdateThread() override;
93 virtual void run() override;
94 void stop();
95 protected:
96 //std::mutex m_critical_section;//critical section for this object only
97 DesignObjectLookup* m_lookup = nullptr;
99 volatile bool m_is_running;
100 };
101#endif
102}
#define HARDWARE_API
Definition DLLInfo.h:56
A core class where all Design Objects including models, materials, and geometries are stored....
Definition DesignObjectLookup.h:65
An object that will be call update, each time the lookup is updated.
Definition DesignObjectUpdateTarget.h:10
A root class which describes some physical object, such as a Motor, Sensor, or Connection....
Definition Device.h:52
void onUpdated()
void startAutoUpdate(DesignObjectLookup *lookup=nullptr)
static void SetDefaultDeviceLookup(DesignObjectLookup *lookup)
virtual void showWarning(const Exception &warning) const
std::function< void(const Exception &warning, ProgressInfo *log)> m_warning_callback
Definition Device.h:73
void stopAutoUpdate(DesignObjectLookup *lookup=nullptr)
virtual void setLog(ProgressInfo *log)
Definition Device.h:56
virtual void endUpdates()
Definition Device.h:60
ProgressInfo * m_log
Definition Device.h:72
virtual void showWarning(const TranslatedString &warning) const
virtual TimeSpan updateInterval() const
Definition Device.h:59
Device(const Model &model, ProgressInfo *log, QObject *parent=nullptr)
virtual void update()
Definition Device.h:58
ProgressInfo * deviceLog() const
Definition Device.h:61
static DesignObjectLookup * s_default_lookup
Definition Device.h:74
virtual void update(DesignObjectLookup *lookup, Time time) override
void setWarningCallback(const std::function< void(const Exception &warning, ProgressInfo *log)> &warning_callback)
A class that updates a device by repeatedly calling update() until stop() is called.
Definition Device.h:87
DeviceUpdateThread(const DeviceUpdateThread &)=delete
virtual void run() override
virtual ~DeviceUpdateThread() override
DeviceUpdateThread(DeviceUpdateThread &&)=delete
volatile bool m_is_running
Definition Device.h:99
DeviceUpdateThread(DesignObjectLookup *lookup, Device *sensor)
Device * m_sensor
Definition Device.h:98
Provides consistent interface to handle errors through the throw expression. All exceptions generated...
Definition Exception.hpp:47
A core class that represents a node on model heirarchy. This node may contain a Geometry or one or mo...
Definition Model.h:58
A light-weight base class for Log that allows processes to update, without the need for additional in...
Definition ProgressInfo.hpp:48
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
Definition ACIColor.h:37