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 class HARDWARE_API Device : public QObject, public Model, public DesignObjectUpdateTarget
48 {
49 Q_OBJECT
50 public:
51 Device(const Model& model, ProgressInfo* log, QObject* parent = nullptr);
52 virtual void setLog(ProgressInfo* log) { m_log = log; };
53 virtual void update(DesignObjectLookup* lookup, Time time) override;
54 virtual void update() {};
55 [[nodiscard]] virtual TimeSpan updateInterval() const { return TimeSpan(1.0f); }
56 virtual void endUpdates() {}
57 [[nodiscard]] ProgressInfo* deviceLog() const { return m_log; }
58 void setWarningCallback(const std::function<void(const Exception& warning, ProgressInfo* log)>& warning_callback);
59 void startAutoUpdate(DesignObjectLookup* lookup = nullptr);
60 void stopAutoUpdate(DesignObjectLookup* lookup = nullptr);
61 static void SetDefaultDeviceLookup(DesignObjectLookup* lookup);
62 signals:
63 void onUpdated();
64 protected:
65 virtual void showWarning(const TranslatedString& warning) const;
66 virtual void showWarning(const Exception& warning) const;
67 protected:
69 std::function<void(const Exception& warning, ProgressInfo* log)> m_warning_callback;
71#if NDEVR_SUPPORTS_THREADING
72 DeviceUpdateThread* m_update_thread = nullptr;
73#endif
74 };
75#if NDEVR_SUPPORTS_THREADING
76 class HARDWARE_API DeviceUpdateThread : public QThread
77 {
78 public:
79 DeviceUpdateThread(DesignObjectLookup* lookup, Device* sensor);
80 DeviceUpdateThread(const DeviceUpdateThread&) = delete;
81 DeviceUpdateThread(DeviceUpdateThread&&) = delete;
82 virtual ~DeviceUpdateThread() override;
83 virtual void run() override;
84 void stop();
85 protected:
86 //std::mutex m_critical_section;//critical section for this object only
87 DesignObjectLookup* m_lookup = nullptr;
88 Device* m_sensor;
89 volatile bool m_is_running;
90 };
91#endif
92}
#define HARDWARE_API
Definition DLLInfo.h:74
Definition DesignObjectLookup.h:61
Definition DesignObjectUpdateTarget.h:8
Definition Device.h:48
void onUpdated()
std::function< void(const Exception &warning, ProgressInfo *log)> m_warning_callback
Definition Device.h:69
static DesignObjectLookup * s_default_lookup
Definition Device.h:70
virtual void setLog(ProgressInfo *log)
Definition Device.h:52
virtual void endUpdates()
Definition Device.h:56
ProgressInfo * m_log
Definition Device.h:68
virtual TimeSpan updateInterval() const
Definition Device.h:55
virtual void update()
Definition Device.h:54
ProgressInfo * deviceLog() const
Definition Device.h:57
Definition Exception.hpp:56
Definition Model.h:54
Definition ProgressInfo.hpp:43
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Definition TimeSpan.h:40
Definition TranslatedString.h:9
Definition ACIColor.h:37