wxMaxima
Loading...
Searching...
No Matches
Maxima.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) 2004-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4// (C) 2014-2018 Gunter Königsmann <wxMaxima@physikbuch.de>
5// (C) 2020 Kuba Ober <kuba@bertec.com>
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21//
22// SPDX-License-Identifier: GPL-2.0+
23
24#ifndef WXMAXIMA_MAXIMA_H
25#define WXMAXIMA_MAXIMA_H
26
32#include <wx/defs.h>
33#include <wx/buffer.h>
34#include <wx/event.h>
35#include <wx/sckstrm.h>
36#include <wx/txtstrm.h>
37#include <wx/socket.h>
38#include <wx/string.h>
39#include <wx/timer.h>
40#include <memory>
41#include <thread>
42#include <atomic>
43#include <mutex>
44#include "Configuration.h"
45#include "Compat.h"
46
62class Maxima : public wxEvtHandler
63{
64public:
67 explicit Maxima(wxSocketBase *socket, Configuration *config);
68 virtual ~Maxima() override;
69
75 static wxString EscapeVarnameForMaxima(wxString var);
77 static wxString InvertCase(const wxString &var);
79 static wxString MaximaVarnameToLisp(wxString var);
80
81 wxSocketBase *Socket() const { return m_socket.get(); }
82
84 bool IsConnected() const { return m_socket->IsConnected(); }
85
87 static void SetPipeToStdErr(bool pipe) { m_pipeToStderr = pipe; }
89 static void GetPipeToStdErr(bool pipe) { m_pipeToStderr = pipe; }
90 static bool GetPipeToStdErr() { return m_pipeToStderr; }
91
100 bool Write(const void *buffer, std::size_t length);
101
104 void ReadSocket();
105
108 void ClearFirstPrompt() { m_firstPrompt = false; }
109
115 XML_PROMPT,
116 XML_SUPPRESSOUTPUT,
117 XML_WXXMLSYMBOLS,
118 XML_VARIABLES,
119 XML_WATCH_VARIABLES_ADD,
120 XML_STATUSBAR,
121 XML_WORKSHEET_EXPORT,
122 XML_HTML_MANUAL_KEYWORDS,
123 XML_MATHS,
124 XML_TOOLONGMATHS,
125 XML_WXXML_KEY,
134 STRING_FOR_XMLINSPECTOR,
135 };
136 void XmlInspectorActive(bool active){m_xmlInspector = active;}
137private:
139 std::atomic_bool m_xmlInspector{false};
140
142 Configuration *m_configuration;
143
145 jthread m_workerThread;
147 std::atomic_bool m_readPendingQueued;
148
150 void SocketEvent(wxSocketEvent &event);
152 void TimerEvent(wxTimerEvent &event);
154 void OnIdle(wxIdleEvent &event);
155
156 std::unique_ptr<wxSocketBase> m_socket;
158 std::mutex m_socketMutex;
160 wxSocketInputStream m_socketInput;
169 wxTextInputStream m_textInput;
170
175 wxString m_socketInputData;
176
180 wxString m_processingBuffer;
181
185 std::vector<std::vector<char>> m_outputQueue;
186 std::mutex m_outputQueueMutex;
187
190 struct InterpretedItem {
191 EventCause cause;
192 wxString data;
193 };
194 std::vector<InterpretedItem> m_interpretedQueue;
195 std::mutex m_interpretedQueueMutex;
196
202 wxMemoryBuffer m_socketOutputData;
203
205 bool m_firstPrompt = true;
207 static bool m_pipeToStderr;
208
214 void WorkerThread(stop_token stopToken);
215
226 void ProcessData(stop_token stopToken);
235 wxTimer m_readIdleTimer{this};
237 static std::unordered_map<wxString, EventCause, wxStringHash> m_knownTags;
238 static std::mutex m_knownTagsMutex;
239};
240
241wxDECLARE_EVENT(EVT_MAXIMA, wxThreadEvent);
242#endif
Small compatibility shims for older toolchains and older wxWidgets.
The configuration storage for the current worksheet.
Definition: Configuration.h:98
Interface to the Maxima process.
Definition: Maxima.h:63
EventCause
Definition: Maxima.h:110
@ WRITE_PENDING
A write to Maxima is still ongoing. We use this event to keep the traffic indicator alive.
Definition: Maxima.h:131
@ READ_PENDING
There's still pending data coming from Maxima. The Data member is empty at the moment.
Definition: Maxima.h:112
@ WRITE_ERROR
The transmission has failed - this is an unrecoverable error, most likely.
Definition: Maxima.h:133
@ DISCONNECTED
Maxima has disconnected (possibly because the process had died).
Definition: Maxima.h:129
@ READ_MISC_TEXT
Maxima has sent non-XML text.
Definition: Maxima.h:114
@ XML_ASCIIMATH
Maxima has sent one complete block of ASCII-art 2D display output.
Definition: Maxima.h:127
void ReadSocket()
Read whatever data is in the socket. This is normally handled by the event handler,...
Definition: Maxima.cpp:126
static void GetPipeToStdErr(bool pipe)
Tells if the user wants all data to maxima to be copied to StdErr.
Definition: Maxima.h:89
static wxString MaximaVarnameToLisp(wxString var)
Convert a human-readable maxima variable name to one lisp understands.
Definition: Maxima.cpp:388
static wxString InvertCase(const wxString &var)
Invert case of chars that have inverted case in lisp.
Definition: Maxima.cpp:311
static void SetPipeToStdErr(bool pipe)
Tells us if the user wants all data to maxima to be copied to StdErr.
Definition: Maxima.h:87
bool IsConnected() const
Are we connected to Maxima?
Definition: Maxima.h:84
static wxString EscapeVarnameForMaxima(wxString var)
Convert a human-readable maxima variable name to one maxima understands.
Definition: Maxima.cpp:326
bool Write(const void *buffer, std::size_t length)
Write more data to be sent to maxima.
Definition: Maxima.cpp:109
void ClearFirstPrompt()
Clear the first prompt state, based on what was read from maxima. This is called from prompt recogniz...
Definition: Maxima.h:108
Definition: Compat.h:58
Definition: Compat.h:47