File indexing completed on 2024-05-26 11:22:03
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2016 Ivan Lakhtanov <ivan.lakhtanov@gmail.com 0004 SPDX-FileCopyrightText: 2023 Alexander Semke <alexander.semke@web.de> 0005 */ 0006 #pragma once 0007 0008 #include <QObject> 0009 #include <QString> 0010 #include <QStringList> 0011 0012 #include <julia.h> 0013 0014 /** 0015 * Implementation of command execution server with DBus interface for Julia 0016 * language. 0017 * 0018 * Uses Julia embedding 0019 * https://docs.julialang.org/en/v1/manual/embedding/ to get results. 0020 */ 0021 class JuliaServer: public QObject 0022 { 0023 Q_OBJECT 0024 public: 0025 explicit JuliaServer(QObject *parent = nullptr); 0026 ~JuliaServer() override; 0027 0028 public Q_SLOTS: 0029 /** 0030 * Initializer for JuliaServer. Call this first before using it 0031 * 0032 * @return 0 - if all OK, 1 - if sys.so file missing. For error 1 - the filename of the missing file can be requested via getError() 0033 */ 0034 Q_SCRIPTABLE int login(); 0035 0036 /** 0037 * Runs a piece of julia code. After this returns use getOutput, getError, 0038 * getWasException methods to retrieve execution result. 0039 * 0040 * @param command maybe multiline piece of julia code to run 0041 */ 0042 Q_SCRIPTABLE void runJuliaCommand(const QString&); 0043 0044 /** 0045 * @return stdout output of the last command execution 0046 */ 0047 Q_SCRIPTABLE QString getOutput() const; 0048 0049 /** 0050 * @return stderr output of the last command execution 0051 */ 0052 Q_SCRIPTABLE QString getError() const; 0053 0054 /** 0055 * @return indicator that exception was triggered during last command 0056 * execution 0057 */ 0058 Q_SCRIPTABLE bool getWasException() const; 0059 0060 /** 0061 * Reparse internal julia module and update list of variables and functions 0062 * 0063 * @param variableManagement true, if Variable Management enabled for this session 0064 */ 0065 Q_SCRIPTABLE void parseModules(bool variableManagement); 0066 0067 /** 0068 * @return list of variables in internal Julia's module 0069 */ 0070 Q_SCRIPTABLE QStringList variablesList(); 0071 0072 /** 0073 * @return corresponding list of values for variables from variablesList. 0074 */ 0075 Q_SCRIPTABLE QStringList variableValuesList(); 0076 0077 /** 0078 * @return corresponding list of sizes for variables from variablesList. 0079 */ 0080 Q_SCRIPTABLE QStringList variableSizesList(); 0081 0082 /** 0083 * @return corresponding list of types for variables from variablesList. 0084 */ 0085 Q_SCRIPTABLE QStringList variableTypesList(); 0086 0087 /** 0088 * @return list of function in internal Julia's module 0089 */ 0090 Q_SCRIPTABLE QStringList functionsList(); 0091 0092 private: 0093 void parseJlModule(jl_module_t* module, bool parseValue); 0094 QString fromJuliaString(const jl_value_t*); 0095 0096 QString m_error; //< Stores last stderr output 0097 QString m_output; //< Stores last stdout output 0098 bool m_was_exception; //< Stores indicator of exception 0099 QStringList parsedModules; 0100 QStringList m_variables; 0101 QStringList m_variableValues; 0102 QStringList m_variableSizes; 0103 QStringList m_variableTypes; 0104 QStringList m_functions; 0105 static QStringList INTERNAL_VARIABLES; 0106 };