wxMaxima
Loading...
Searching...
No Matches
MaximaProcessManager.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
38#ifndef MAXIMAPROCESSMANAGER_H
39#define MAXIMAPROCESSMANAGER_H
40
41#include <wx/string.h>
42#include <wx/timer.h>
43
44class wxMaxima;
45class wxSocketEvent;
46class wxProcessEvent;
47class wxThreadEvent;
48class wxCommandEvent;
49
56{
57public:
58 explicit MaximaProcessManager(wxMaxima &wxm) : m_wxMaxima(wxm) {
59 m_itemTimer.Bind(wxEVT_TIMER, &MaximaProcessManager::OnItemTimer, this);
60 }
61
64 static void RegisterChildMaxima(long pid);
65
68 static void UnregisterChildMaxima(long pid);
69
77 static void KillAllChildMaximas();
78
83 static void SetupTerminationHandlers();
84
87 bool StartServer();
88
90 void ServerEvent(wxSocketEvent &event);
91
94 void OnMaximaConnect();
95
100 bool StartMaxima(bool force = false);
101
103 void KillMaxima(bool logMessage = true);
104
107 void OnMaximaClose();
110 void OnMaximaClose(wxProcessEvent &event);
111
114 void MaximaEvent(wxThreadEvent &event);
115
124 bool WriteToMaximaStdin(const wxString &line);
125
127 void Interrupt(wxCommandEvent &event);
128
131 void GnuplotCommandName(const wxString &gnuplot);
132
135 void OnGnuplotQueryTerminals(wxProcessEvent &event);
136
138 void OnGnuplotClose(wxProcessEvent &event);
139
148 void OnGnuplotPopoutCheckClose(wxProcessEvent &event);
149
150private:
153 wxMaxima &m_wxMaxima;
163 bool m_inMaximaEvent = false;
164
174 void ProcessItems();
176 void OnItemTimer(wxTimerEvent &event);
178 wxTimer m_itemTimer;
184 static constexpr int ItemBudgetMs = 50;
185
191 bool m_skipOutputUntilPrompt = false;
193 long m_skippedOutputItems = 0;
195 void ReportSkippedOutput();
196};
197
198#endif // MAXIMAPROCESSMANAGER_H
The Maxima process/socket lifecycle extracted from the wxMaxima god class.
Definition: MaximaProcessManager.h:56
void ServerEvent(wxSocketEvent &event)
Handles a socket event on the server: on a connection, accepts it.
Definition: MaximaProcessManager.cpp:143
bool StartServer()
Opens the local socket server Maxima connects back to. Returns false if no server could be created.
Definition: MaximaProcessManager.cpp:203
void OnMaximaConnect()
Accepts Maxima's connection to our server socket, wires up the data stream and kicks off the initial ...
Definition: MaximaProcessManager.cpp:155
void OnGnuplotClose(wxProcessEvent &event)
wxEVT_END_PROCESS handler for the gnuplot subprocess: notes it has closed.
Definition: MaximaProcessManager.cpp:1200
static void RegisterChildMaxima(long pid)
Remember a running child Maxima's (group-leader) PID so a signal/crash handler can kill it....
Definition: MaximaProcessManager.cpp:83
void OnGnuplotPopoutCheckClose(wxProcessEvent &event)
wxEVT_END_PROCESS handler for the hidden, headless gnuplot check that runs alongside "Pop out interac...
Definition: MaximaProcessManager.cpp:1206
static void UnregisterChildMaxima(long pid)
Forget a child Maxima's PID once we have taken it down ourselves. Async-signal-safe; no-op on Windows...
Definition: MaximaProcessManager.cpp:98
static void KillAllChildMaximas()
SIGKILL every child Maxima we still have registered.
Definition: MaximaProcessManager.cpp:113
void KillMaxima(bool logMessage=true)
Kills the Maxima process (and cleans up its temp files / registered PID).
Definition: MaximaProcessManager.cpp:441
void Interrupt(wxCommandEvent &event)
Sends the running Maxima an interrupt (Ctrl+G / the interrupt button).
Definition: MaximaProcessManager.cpp:1052
bool StartMaxima(bool force=false)
(Re)starts the Maxima process (and its server socket) if needed.
Definition: MaximaProcessManager.cpp:260
static void SetupTerminationHandlers()
Install the SIGTERM/SIGINT/SIGHUP handlers that run KillAllChildMaximas() so a child Maxima is not or...
Definition: MaximaProcessManager.cpp:128
void OnMaximaClose()
Reacts to the Maxima process having exited (reports it and, unless we closed it on purpose,...
Definition: MaximaProcessManager.cpp:590
void MaximaEvent(wxThreadEvent &event)
The EVT_MAXIMA handler: classifies each chunk Maxima sent over the socket and hands it to the matchin...
Definition: MaximaProcessManager.cpp:776
void OnGnuplotQueryTerminals(wxProcessEvent &event)
wxEVT_END_PROCESS handler for the gnuplot terminal-query subprocess: reads which terminals gnuplot su...
Definition: MaximaProcessManager.cpp:1138
bool WriteToMaximaStdin(const wxString &line)
Writes one line of input to the Maxima process's stdin.
Definition: MaximaProcessManager.cpp:674
void GnuplotCommandName(const wxString &gnuplot)
Resolves the gnuplot executable path and (re)starts a background query of the graphics terminals it s...
Definition: MaximaProcessManager.cpp:1315
Definition: wxMaxima.h:76