ADTF  3.18.2
interface_clients.h
Go to the documentation of this file.
1 
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"
15 
16 #include <adtfui/qt_shared_intf.h>
17 #include <plugins/recorder_intf.h>
18 #include <plugins/player_intf.h>
19 
20 #include <QObject>
21 #include <QJSEngine>
22 
23 namespace adtf
24 {
25 
26 namespace javascript
27 {
28 
29 namespace scripting
30 {
31 
38 class cScriptRecorderClient: public QObject
39 {
40  Q_OBJECT
41  Q_PROPERTY(bool connected READ isConnected)
42 
43  public:
46  m_oClient(oClient),
47  m_oEngine(oEngine)
48  {
49  }
51 
55  Q_INVOKABLE void start(const QString& strFileName = "")
56  {
57  SCRIPT_ERROR_IF_FAILED(m_oClient->Start(strFileName.toLocal8Bit().data()));
58  }
59 
63  Q_INVOKABLE void split(const QString& strFileName = "")
64  {
65  SCRIPT_ERROR_IF_FAILED(m_oClient->Split(strFileName.toLocal8Bit().data()));
66  }
67 
71  Q_INVOKABLE void stop(const QString& strFileName = "")
72  {
73  SCRIPT_ERROR_IF_FAILED(m_oClient->Stop(strFileName.toLocal8Bit().data()));
74  }
75 
79  Q_INVOKABLE void addMarker(double fTimeStamp, const QString& strName = "", const QString& strAdditional = "")
80  {
81  SCRIPT_ERROR_IF_FAILED(ucom::ucom_cast<services::IRecorder*>(&m_oClient.Get())->AddMarker(static_cast<tTimeStamp>(fTimeStamp),
82  strName.toStdString().c_str(),
83  strAdditional.toStdString().c_str()));
84  }
85 
89  Q_INVOKABLE void dropHistory()
90  {
91  SCRIPT_ERROR_IF_FAILED(ucom::ucom_cast<services::IRecorder*>(&m_oClient.Get())->DropHistory());
92  }
93 
95  private:
96  bool isConnected()
97  {
98  return m_oClient.IsValid();
99  }
100 
102  QJSEngine& m_oEngine;
104 
105 };
106 
113 class cScriptPlayerClient: public QObject
114 {
115  Q_OBJECT
116 
117  public:
119  cScriptPlayerClient(QJSEngine& oEngine):
120  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  }
180  EXCEPTION_TO_SCRIPT_ERROR({})
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 
198  private:
201  QJSEngine& m_oEngine;
203 };
204 
215 class cScriptQtSharedClient: public QObject
216 {
217  Q_OBJECT
218  Q_PROPERTY(bool connected READ isConnected)
219 
220  public:
223  m_oClient(oClient),
224  m_oEngine(oEngine)
225  {
226  }
228 
232  Q_INVOKABLE QObject* getObject(const QString& strName = "")
233  try
234  {
235  QObject* pObject;
236  THROW_IF_FAILED(m_oClient->GetObject(strName.toLocal8Bit().data(), pObject));
237  return pObject;
238  }
239  EXCEPTION_TO_SCRIPT_ERROR(nullptr)
240 
241  private:
243  bool isConnected()
244  {
245  return m_oClient.IsValid();
246  }
247 
249  QJSEngine& m_oEngine;
251 };
252 
253 }
254 }
255 }
Helper class that wraps a streaming::ant::IBindingClient.
Definition: graph_object.h:67
Interface client for adtf::services::ant::IPlayer.
Q_INVOKABLE qint64 getCurrentTime()
Information interface to get the current time position of the current opened files.
Q_INVOKABLE void open(const QString &strFileNames, bool bLoadReferencedFiles)
Opens one or more adtfdat files.
Q_INVOKABLE void pause()
Control interface to pause streaming.
Q_INVOKABLE void seekToTime(qint64 tmTime)
Control interface to seek to the given (Chunk) Time.
Q_INVOKABLE void play()
Control interface to start streaming.
Q_INVOKABLE void reset()
Control interface to Reset the streaming.
Q_INVOKABLE void close()
Closes the current loaded files.
Interface client for adtf::ui::giant::IQtShared.
Q_INVOKABLE QObject * getObject(const QString &strName="")
Get a handle to an existing or new Qt object (i.e.
Interface client for adtf::streaming::ant::IRecorder.
Q_INVOKABLE void start(const QString &strFileName="")
Starts a new recording.
Q_INVOKABLE void addMarker(double fTimeStamp, const QString &strName="", const QString &strAdditional="")
Adds a marker to the corrently ongoing recording.
Q_INVOKABLE void dropHistory()
Drops all data currently kept in the history buffer.
Q_INVOKABLE void split(const QString &strFileName="")
Stops an ongoing recording and starts a new one.
Q_INVOKABLE void stop(const QString &strFileName="")
Stops an ongoing recording.
virtual tResult GetObject(iobject_ptr< IObject > &pObject, const char *strNameOID) const =0
Get registered object from object registry.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
adtf::ucom::IRuntime * _runtime
Global Runtime Pointer to reference to the current runtime.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
#define THROW_IF_FAILED_DESC(s,...)
throws if the expression returns a failed tResult and ammends the error message.
#define THROW_IF_FAILED(s)
throws if the expression returns a failed tResult