ADTF Qt5
Loading...
Searching...
No Matches
interface_clients.h
Go to the documentation of this file.
1
7
8/*
9 * This file depends on Qt which is licensed under LGPLv3.
10 * See ADTF_DIR/3rdparty/qt5 and doc/license for detailed information.
11 */
12#pragma once
13#include "error_handling.h"
14#include <adtffiltersdk/graph_object.h>
15
17#include <plugins/recorder_intf.h>
18#include <plugins/player_intf.h>
20
21#include <QObject>
22#include <QJSEngine>
23#include <QJSValue>
24#include <QMetaEnum>
25
26namespace adtf
27{
28
29namespace javascript
30{
31
32namespace scripting
33{
34
41class cScriptRecorderClient : public QObject
42{
43 Q_OBJECT
45 Q_PROPERTY(bool connected READ isConnected)
46
47public:
48 cScriptRecorderClient(filter::interface_client<services::ant::IRecorder> oClient, QJSEngine& oEngine):
49 m_oClient(oClient), m_oEngine(oEngine)
50 {
51 }
53
57 Q_INVOKABLE void start(const QString& strFileName = "")
58 {
59 SCRIPT_ERROR_IF_FAILED(m_oClient->Start(strFileName.toLocal8Bit().data()));
60 }
61
65 Q_INVOKABLE void split(const QString& strFileName = "")
66 {
67 SCRIPT_ERROR_IF_FAILED(m_oClient->Split(strFileName.toLocal8Bit().data()));
68 }
69
73 Q_INVOKABLE void stop(const QString& strFileName = "")
74 {
75 SCRIPT_ERROR_IF_FAILED(m_oClient->Stop(strFileName.toLocal8Bit().data()));
76 }
77
81 Q_INVOKABLE void addMarker(double fTimeStamp, const QString& strName = "", const QString& strAdditional = "")
82 {
83 SCRIPT_ERROR_IF_FAILED(ucom::ucom_cast<services::IRecorder*>(&m_oClient.Get())
84 ->AddMarker(static_cast<tTimeStamp>(fTimeStamp), strName.toStdString().c_str(),
85 strAdditional.toStdString().c_str()));
86 }
87
91 Q_INVOKABLE void dropHistory()
92 {
93 SCRIPT_ERROR_IF_FAILED(ucom::ucom_cast<services::IRecorder*>(&m_oClient.Get())->DropHistory());
94 }
95
97private:
98 bool isConnected()
99 {
100 return m_oClient.IsValid();
101 }
102
103 filter::interface_client<services::ant::IRecorder> m_oClient;
104 QJSEngine& m_oEngine;
106};
107
114class cScriptPlayerClient : public QObject
115{
116 Q_OBJECT
117
118public:
120 cScriptPlayerClient(QJSEngine& oEngine): m_oEngine(oEngine)
121 {
122 THROW_IF_FAILED_DESC(_runtime->GetObject(m_pClient), "Unable to aquire player interface");
123 }
125
129 Q_INVOKABLE void open(const QString& strFileNames, bool bLoadReferencedFiles)
130 {
131 SCRIPT_ERROR_IF_FAILED(m_pClient->Open(strFileNames.toLocal8Bit().data(), bLoadReferencedFiles));
132 }
133
137 Q_INVOKABLE void close()
138 {
139 SCRIPT_ERROR_IF_FAILED(m_pClient->Close());
140 }
141
145 Q_INVOKABLE void play()
146 {
147 SCRIPT_ERROR_IF_FAILED(m_pClient->Play());
148 }
149
153 Q_INVOKABLE void pause()
154 {
155 SCRIPT_ERROR_IF_FAILED(m_pClient->Pause());
156 }
157
161 Q_INVOKABLE void reset()
162 {
163 SCRIPT_ERROR_IF_FAILED(m_pClient->Reset());
164 }
165
169 Q_INVOKABLE QVariantList getTimeRange()
170 try
171 {
172 tTimeStamp tmStart;
173 tTimeStamp tmEnd;
174 THROW_IF_FAILED(m_pClient->GetTimeRange(tmStart, tmEnd));
175 QVariantList oReturnValue;
176 oReturnValue.push_back(static_cast<qint64>(base::duration_cast<base::tNanoSeconds>(tmStart).nCount));
177 oReturnValue.push_back(static_cast<qint64>(base::duration_cast<base::tNanoSeconds>(tmEnd).nCount));
178 return oReturnValue;
179 }
181
185 Q_INVOKABLE qint64 getCurrentTime()
186 {
187 return base::duration_cast<base::tNanoSeconds>(m_pClient->GetCurrentTime()).nCount;
188 }
189
193 Q_INVOKABLE void seekToTime(qint64 tmTime)
194 {
195 SCRIPT_ERROR_IF_FAILED(m_pClient->SeekToTime(base::duration_cast<tTimeStamp>(base::tNanoSeconds{tmTime})));
196 }
197
198private:
200 ucom::object_ptr<services::ant::IPlayer> m_pClient;
201 QJSEngine& m_oEngine;
203};
204
211class cScriptXSystemClient : public QObject
212{
213 Q_OBJECT
215 Q_PROPERTY(QJSValue Theme READ themeEnum CONSTANT)
216
217public:
218 cScriptXSystemClient(QJSEngine& oEngine): m_oEngine(oEngine)
219 {
220 THROW_IF_FAILED_DESC(_runtime->GetObject(m_pClient), "Unable to aquire xsystem interface");
221 }
222
223 QJSValue themeEnum() const noexcept
224 {
225 return m_oEngine.newQMetaObject(&staticMetaObject);
226 }
228
232 enum Theme
233 {
237 };
238 Q_ENUM(Theme)
239
240
244 Q_INVOKABLE void setTheme(const QJSValue& oTheme)
245 {
246 SCRIPT_ERROR_IF_FAILED(m_pClient->SetTheme(toThemeMode(oTheme)));
247 }
248
252 Q_INVOKABLE void setScaling(double fFactor)
253 {
254 SCRIPT_ERROR_IF_FAILED(m_pClient->SetScaling(fFactor));
255 }
256
257private:
259 static ui::v2::IQtXSystem::eThemeMode toThemeMode(const QJSValue& oTheme)
260 {
261 const auto nTheme = oTheme.toInt();
262 if (!oTheme.isNumber() || oTheme.toNumber() != nTheme || !QMetaEnum::fromType<Theme>().valueToKey(nTheme))
263 {
264 THROW_ERROR_DESC(ERR_INVALID_ARG, "Invalid theme: %s", oTheme.toString().toLocal8Bit().data());
265 }
266
267 return static_cast<ui::v2::IQtXSystem::eThemeMode>(nTheme);
268 }
269
270 ucom::object_ptr<ui::v2::IQtXSystem> m_pClient;
271 QJSEngine& m_oEngine;
273};
274
285class cScriptQtSharedClient : public QObject
286{
287 Q_OBJECT
289 Q_PROPERTY(bool connected READ isConnected)
290
291public:
292 cScriptQtSharedClient(filter::interface_client<ui::giant::IQtShared> oClient, QJSEngine& oEngine):
293 m_oClient(oClient), m_oEngine(oEngine)
294 {
295 }
297
303 Q_INVOKABLE QObject* getObject(const QString& strName = "")
304 try
305 {
306 QObject* pObject;
307 THROW_IF_FAILED(m_oClient->GetObject(strName.toLocal8Bit().data(), pObject));
308 return pObject;
309 }
311
312private:
314 bool isConnected()
315 {
316 return m_oClient.IsValid();
317 }
318
319 filter::interface_client<ui::giant::IQtShared> m_oClient;
320 QJSEngine& m_oEngine;
322};
323
324} // namespace scripting
325} // namespace javascript
326} // namespace adtf
Definition interface_clients.h:115
Q_INVOKABLE qint64 getCurrentTime()
Definition interface_clients.h:185
Q_INVOKABLE void open(const QString &strFileNames, bool bLoadReferencedFiles)
Definition interface_clients.h:129
Q_INVOKABLE void reset()
Definition interface_clients.h:161
Q_INVOKABLE void pause()
Definition interface_clients.h:153
Q_INVOKABLE void seekToTime(qint64 tmTime)
Definition interface_clients.h:193
Q_INVOKABLE void close()
Definition interface_clients.h:137
Q_INVOKABLE QVariantList getTimeRange()
Definition interface_clients.h:169
Q_INVOKABLE void play()
Definition interface_clients.h:145
Definition interface_clients.h:286
Definition interface_clients.h:212
eThemeMode
Theme mode.
Definition qtxsystem_intf.h:549
@ System
System theme mode.
Definition qtxsystem_intf.h:553
@ Light
Light theme mode.
Definition qtxsystem_intf.h:557
@ Dark
Dark theme mode.
Definition qtxsystem_intf.h:561
#define EXCEPTION_TO_SCRIPT_ERROR(__return_value)
Converts an exception to an error code.
Definition error_handling.h:24
#define SCRIPT_ERROR_IF_FAILED(__exp)
Throws an error/exception in case of error in script.
Definition error_handling.h:32
Definition clock.h:25
Namespace for the ADTF JavaScript Filter SDK.
Definition clock.h:22
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtfui_pkg.h:13