Changeset View
Changeset View
Standalone View
Standalone View
src/backends/julia/juliasession.h
Show All 25 Lines | |||||
26 | class JuliaExpression; | 26 | class JuliaExpression; | ||
27 | class JuliaCompletionObject; | 27 | class JuliaCompletionObject; | ||
28 | class KProcess; | 28 | class KProcess; | ||
29 | class QDBusInterface; | 29 | class QDBusInterface; | ||
30 | namespace Cantor { | 30 | namespace Cantor { | ||
31 | class DefaultVariableModel; | 31 | class DefaultVariableModel; | ||
32 | } | 32 | } | ||
33 | 33 | | |||
34 | /** | ||||
35 | * Implements a Cantor session for the Julia backend | ||||
36 | * | ||||
37 | * It communicates through DBus interface with JuliaServer | ||||
38 | */ | ||||
34 | class JuliaSession: public Cantor::Session | 39 | class JuliaSession: public Cantor::Session | ||
35 | { | 40 | { | ||
36 | Q_OBJECT | 41 | Q_OBJECT | ||
37 | public: | 42 | public: | ||
43 | /** | ||||
44 | * Constructs session | ||||
45 | * | ||||
46 | * @param backend owning backend | ||||
47 | */ | ||||
38 | JuliaSession(Cantor::Backend *backend); | 48 | JuliaSession(Cantor::Backend *backend); | ||
39 | virtual ~JuliaSession() {} | 49 | virtual ~JuliaSession() {} | ||
40 | 50 | | |||
51 | /** | ||||
52 | * @see Cantor::Session::login | ||||
53 | */ | ||||
41 | virtual void login() override; | 54 | virtual void login() override; | ||
55 | | ||||
56 | /** | ||||
57 | * @see Cantor::Session::logout | ||||
58 | */ | ||||
42 | virtual void logout() override; | 59 | virtual void logout() override; | ||
43 | 60 | | |||
61 | /** | ||||
62 | * @see Cantor::Session::interrupt | ||||
63 | */ | ||||
44 | virtual void interrupt() override; | 64 | virtual void interrupt() override; | ||
45 | 65 | | |||
66 | /** | ||||
67 | * @see Cantor::Session::evaluateExpression | ||||
68 | */ | ||||
46 | virtual Cantor::Expression *evaluateExpression( | 69 | virtual Cantor::Expression *evaluateExpression( | ||
47 | const QString &command, | 70 | const QString &command, | ||
48 | Cantor::Expression::FinishingBehavior behave) override; | 71 | Cantor::Expression::FinishingBehavior behave) override; | ||
49 | 72 | | |||
73 | /** | ||||
74 | * @see Cantor::Session::completionFor | ||||
75 | */ | ||||
50 | virtual Cantor::CompletionObject *completionFor( | 76 | virtual Cantor::CompletionObject *completionFor( | ||
51 | const QString &cmd, | 77 | const QString &cmd, | ||
52 | int index = -1) override; | 78 | int index = -1) override; | ||
53 | 79 | | |||
80 | /** | ||||
81 | * @see Cantor::Session::syntaxHighlighter | ||||
82 | */ | ||||
54 | virtual QSyntaxHighlighter *syntaxHighlighter(QObject *parent); | 83 | virtual QSyntaxHighlighter *syntaxHighlighter(QObject *parent); | ||
84 | | ||||
85 | /** | ||||
86 | * @see Cantor::Session::variableModel | ||||
87 | */ | ||||
55 | virtual QAbstractItemModel *variableModel() override; | 88 | virtual QAbstractItemModel *variableModel() override; | ||
56 | 89 | | |||
90 | /** | ||||
91 | * @return indicator if config says to integrate plots into worksheet | ||||
92 | */ | ||||
57 | bool integratePlots(); | 93 | bool integratePlots(); | ||
58 | 94 | | |||
59 | Q_SIGNALS: | 95 | Q_SIGNALS: | ||
96 | /** | ||||
97 | * Emit this to update syntax highlighter | ||||
98 | */ | ||||
60 | void updateHighlighter(); | 99 | void updateHighlighter(); | ||
61 | 100 | | |||
62 | private Q_SLOTS: | 101 | private Q_SLOTS: | ||
102 | /** | ||||
103 | * Called when async call to JuliaServer is finished | ||||
104 | */ | ||||
63 | void onResultReady(); | 105 | void onResultReady(); | ||
64 | 106 | | |||
65 | private: | 107 | private: | ||
66 | KProcess *m_process; | 108 | KProcess *m_process; //< process to run JuliaServer inside | ||
67 | QDBusInterface *m_interface; | 109 | QDBusInterface *m_interface; //< interface to JuliaServer | ||
68 | 110 | | |||
111 | /// Expressions running at the moment | ||||
69 | QList<JuliaExpression *> m_runningExpressions; | 112 | QList<JuliaExpression *> m_runningExpressions; | ||
70 | JuliaExpression *m_currentExpression; | 113 | JuliaExpression *m_currentExpression; //< current expression | ||
71 | 114 | | |||
115 | /// Variable management model | ||||
72 | Cantor::DefaultVariableModel *m_variableModel; | 116 | Cantor::DefaultVariableModel *m_variableModel; | ||
73 | 117 | | |||
118 | /// Cache to speedup modules whos calls | ||||
74 | QMap<QString, QString> m_whos_cache; | 119 | QMap<QString, QString> m_whos_cache; | ||
75 | 120 | | |||
76 | friend JuliaExpression; | 121 | friend JuliaExpression; | ||
77 | friend JuliaCompletionObject; | 122 | friend JuliaCompletionObject; | ||
78 | 123 | | |||
124 | /** | ||||
125 | * Runs Julia expression | ||||
126 | * | ||||
127 | * @param expression expression to run | ||||
128 | */ | ||||
79 | void runExpression(JuliaExpression *expression); | 129 | void runExpression(JuliaExpression *expression); | ||
80 | 130 | | |||
131 | /** | ||||
132 | * Runs Julia piece of code in synchronous mode | ||||
133 | * | ||||
134 | * @param command command to execute | ||||
135 | */ | ||||
81 | void runJuliaCommand(const QString &command) const; | 136 | void runJuliaCommand(const QString &command) const; | ||
137 | | ||||
138 | /** | ||||
139 | * Runs Julia piece of code in asynchronous mode. When finished | ||||
140 | * onResultReady is called | ||||
141 | * | ||||
142 | * @param command command to execute | ||||
143 | */ | ||||
82 | void runJuliaCommandAsync(const QString &command); | 144 | void runJuliaCommandAsync(const QString &command); | ||
83 | 145 | | |||
146 | /** | ||||
147 | * Helper method to get QString returning function result | ||||
148 | * | ||||
149 | * @param method DBus method to call | ||||
150 | * @return result of the method | ||||
151 | */ | ||||
84 | QString getStringFromServer(const QString &method); | 152 | QString getStringFromServer(const QString &method); | ||
153 | | ||||
154 | /** | ||||
155 | * @return stdout of the last executed command | ||||
156 | */ | ||||
85 | QString getOutput(); | 157 | QString getOutput(); | ||
158 | | ||||
159 | /** | ||||
160 | * @return stderr of the last executed command | ||||
161 | */ | ||||
86 | QString getError(); | 162 | QString getError(); | ||
163 | | ||||
164 | /** | ||||
165 | * @return indicator of exception occured during the last command execution | ||||
166 | */ | ||||
87 | bool getWasException(); | 167 | bool getWasException(); | ||
88 | 168 | | |||
169 | /** | ||||
170 | * Updates variable model by querying all modules in scope with whos command | ||||
171 | */ | ||||
89 | void listVariables(); | 172 | void listVariables(); | ||
90 | }; | 173 | }; |