HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
python_thread.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 #include <QThread>
28 #include <QString>
29 #include <QMutex>
30 #include <QVariant>
31 #include <QElapsedTimer>
33 
34 namespace hal {
35  class Module;
36  class Gate;
37 
48  {
49  int mState;
50  public:
52  PythonMutex();
53 
55  ~PythonMutex();
56  };
57 
62  {
63  public:
65  private:
66  Q_OBJECT
67  QString mScript;
68  QString mErrorMessage;
69  QString mResult;
70  QString mStdoutBuffer;
71  unsigned long mPythonThreadID;
72  QVariant mInput;
73  QMutex mInputMutex;
74  QElapsedTimer mElapsedTimer;
75  bool mSingleStatement;
76  bool mAbortRequested;
77  int mSpamCount;
78  Q_SIGNALS:
79  void stdOutput(QString txt);
80  void stdError(QString txt);
81  void requireInput(int type, QString prompt, QVariant defaultValue);
82  public:
83  PythonThread(const QString& script, bool singleStatement, QObject* parent = nullptr);
84  ~PythonThread();
85  void run() override;
86  void interrupt();
87  QString errorMessage() const { return mErrorMessage; }
88  QString result() const { return mResult; }
89  void handleStdout(const QString& output) override;
90  void handleError(const QString& output) override;
91  std::string handleConsoleInput(const QString& prompt);
92  std::string handleStringInput(const QString& prompt, const QString& defval);
93  int handleNumberInput(const QString& prompt, int defval);
94  Module* handleModuleInput(const QString& prompt);
95  Gate* handleGateInput(const QString& prompt);
96  std::string handleFilenameInput(const QString& prompt, const QString& filetype);
97  void clear() override;
98  void setInput(const QVariant& inp);
99  bool getInput(InputType type, QString prompt, QVariant defaultValue);
100  void unlock();
101  const QString& stdoutBuffer() const { return mStdoutBuffer; }
103  };
104 }
Definition: gate.h:58
Interface for handling python outputs.
PythonMutex()
Aquire GIL.
~PythonMutex()
Release GIL.
void clear() override
void stdError(QString txt)
Gate * handleGateInput(const QString &prompt)
void handleStdout(const QString &output) override
QString errorMessage() const
Definition: python_thread.h:87
QString result() const
Definition: python_thread.h:88
void setInput(const QVariant &inp)
std::string handleStringInput(const QString &prompt, const QString &defval)
int handleNumberInput(const QString &prompt, int defval)
bool getInput(InputType type, QString prompt, QVariant defaultValue)
std::string handleConsoleInput(const QString &prompt)
Module * handleModuleInput(const QString &prompt)
void handleError(const QString &output) override
void stdOutput(QString txt)
void requireInput(int type, QString prompt, QVariant defaultValue)
const QString & stdoutBuffer() const
void run() override
PythonThread(const QString &script, bool singleStatement, QObject *parent=nullptr)
std::string handleFilenameInput(const QString &prompt, const QString &filetype)
Definition: defines.h:45
PinType type
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const