wxMaxima
Loading...
Searching...
No Matches
TroubleshootingRunner.h
Go to the documentation of this file.
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2026 Gunter Königsmann <wxMaxima@physikbuch.de>
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//
20// SPDX-License-Identifier: GPL-2.0+
21
26#ifndef TROUBLESHOOTINGRUNNER_H
27#define TROUBLESHOOTINGRUNNER_H
28
30#include <wx/event.h>
31#include <wx/process.h>
32#include <wx/socket.h>
33#include <wx/timer.h>
34#include <wx/utils.h>
35#include <functional>
36#include <memory>
37#include <set>
38#include <string>
39
68class TroubleshootingRunner : public wxEvtHandler
69{
70public:
72 struct Settings {
78 wxString maximaCommand;
80 wxEnvVariableHashMap environment;
82 wxString setupCommand;
89 wxString setupCheckFunction = wxS("wx-define-unicode-aliases");
97 long connectTimeoutMs = 30000;
99 long promptTimeoutMs = 60000;
101 long setupTimeoutMs = 60000;
103 long queryTimeoutMs = 90000;
105 long stopTimeoutMs = 10000;
107 long gnuplotTimeoutMs = 30000;
108 };
109
110 using ResultCallback = std::function<void (const wxm::TroubleshootingResult &)>;
111
112 TroubleshootingRunner(const Settings &settings, ResultCallback onResult,
113 std::function<void ()> onFinished = {});
115 ~TroubleshootingRunner() override;
116
118 void Start();
125 void Poll();
127 bool IsFinished() const { return m_stage == Stage::finished; }
128
130 static const std::set<wxm::TroubleshootingCheck> &Checks();
131
132private:
134 class Process;
135 friend class Process;
136
138 enum class Stage {
139 notStarted,
140 waitConnect,
141 waitPrompt,
142 waitSetup,
143 waitAnswers,
144 waitStop,
145 gnuplotPng,
146 gnuplotPngCairo,
147 finished
148 };
149
152 const wxString &details, const wxString &hint = wxEmptyString);
154 void SkipRemainingMaximaChecks(const wxString &reason);
156 void StartMaxima();
158 void PumpIO();
160 void ProcessEnded(Process *process, int status);
162 void PollConnect();
164 void PollPrompt();
166 void PollSetup();
168 void PollAnswers();
170 void SendQuestions();
172 void EvaluateAnswers(bool timedOut);
174 void StopMaxima();
176 void PollStop();
178 void StartGnuplot(const wxString &terminal);
180 void PollGnuplot();
182 wxString FindGnuplot();
184 void EnterStage(Stage stage);
186 long StageAge() const;
188 wxString MaximaOutputTail() const;
190 void SendToMaxima(const wxString &text);
191
192 Settings m_settings;
193 ResultCallback m_onResult;
194 std::function<void ()> m_onFinished;
196 std::set<wxm::TroubleshootingCheck> m_reported;
197 Stage m_stage = Stage::notStarted;
199 wxLongLong m_stageStart;
200 wxTimer m_timer;
201
203 std::unique_ptr<wxSocketServer> m_server;
205 int m_port = 0;
207 std::unique_ptr<wxSocketBase> m_socket;
209 wxString m_secret;
211 wxString m_fromMaxima;
213 std::string m_undecoded;
215 std::string m_toMaxima;
217 bool m_gotPrompt = false;
219 bool m_authenticated = false;
220
222 Process *m_maxima = nullptr;
223 long m_maximaPid = 0;
224 bool m_maximaEnded = false;
225 int m_maximaExitCode = 0;
227 bool m_killedMaxima = false;
229 wxString m_maximaConsole;
230
232 Process *m_gnuplot = nullptr;
233 bool m_gnuplotEnded = false;
234 int m_gnuplotExitCode = 0;
235 wxString m_gnuplotErrors;
236 wxString m_gnuplotTerminal;
237 wxString m_gnuplotScript;
238 wxString m_gnuplotOutput;
240 wxString m_gnuplotBinary;
241
243 wxString m_tempDir;
244 wxString m_gnuplotFromMaxima;
245};
246
247#endif // TROUBLESHOOTINGRUNNER_H
The checks the troubleshooting dialog runs (GH #2559), their results, and the pure helpers that inter...
TroubleshootingCheck
One thing the troubleshooting dialog checks. The order is the display order.
Definition: TroubleshootingChecks.h:42
TroubleshootingStatus
What a check found.
Definition: TroubleshootingChecks.h:71
Runs the troubleshooting checks that need a Maxima or a gnuplot process.
Definition: TroubleshootingRunner.h:69
~TroubleshootingRunner() override
Stops Maxima and gnuplot if they still run.
Definition: TroubleshootingRunner.cpp:184
static const std::set< wxm::TroubleshootingCheck > & Checks()
The checks this runner runs, and only these.
Definition: TroubleshootingRunner.cpp:163
void Start()
Starts the checks; from now on a timer calls Poll()
Definition: TroubleshootingRunner.cpp:210
void Poll()
Does whatever can be done now, without waiting.
Definition: TroubleshootingRunner.cpp:394
bool IsFinished() const
True once every check this runner runs has been reported.
Definition: TroubleshootingRunner.h:127
What the runner needs to know to start Maxima and gnuplot.
Definition: TroubleshootingRunner.h:72
wxString setupCheckFunction
A Lisp function wxMathML.lisp defines near its end.
Definition: TroubleshootingRunner.h:89
long stopTimeoutMs
How long a killed Maxima may take to end.
Definition: TroubleshootingRunner.h:105
long connectTimeoutMs
How long Maxima may take to connect to us.
Definition: TroubleshootingRunner.h:97
wxEnvVariableHashMap environment
The environment Maxima is started with, minus MAXIMA_AUTH_CODE.
Definition: TroubleshootingRunner.h:80
wxString setupCommand
What wxMaxima sends Maxima once it is connected: wxMathML.lisp.
Definition: TroubleshootingRunner.h:82
wxString maximaConfigured
The Maxima program as configured, before it was looked for.
Definition: TroubleshootingRunner.h:76
wxString maximaExecutable
The Maxima program, resolved to a path, as MaximaProcessManager would run it.
Definition: TroubleshootingRunner.h:74
wxString maximaCommand
The whole command line Maxima is started with, minus the "-s <port>".
Definition: TroubleshootingRunner.h:78
long queryTimeoutMs
How long Maxima may take to answer all questions, loading draw included.
Definition: TroubleshootingRunner.h:103
wxString gnuplotCommand
The gnuplot the worksheet's Maxima session found.
Definition: TroubleshootingRunner.h:95
long setupTimeoutMs
How long Maxima may take to load wxMathML.lisp and authenticate.
Definition: TroubleshootingRunner.h:101
long promptTimeoutMs
How long Maxima may take from connecting to its first prompt.
Definition: TroubleshootingRunner.h:99
long gnuplotTimeoutMs
How long gnuplot may take to draw one plot.
Definition: TroubleshootingRunner.h:107
The result of one check.
Definition: TroubleshootingChecks.h:95