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#include "MaximaItemQueue.h"
47
65class Maxima : public wxEvtHandler
66{
67public:
70 explicit Maxima(wxSocketBase *socket, Configuration *config);
71 ~Maxima() override;
72
78 static wxString EscapeVarnameForMaxima(wxString var);
80 static wxString InvertCase(const wxString &var);
82 static wxString MaximaVarnameToLisp(const wxString& var);
83
84 wxSocketBase *Socket() const { return m_socket.get(); }
85
87 bool IsConnected() const { return m_socket->IsConnected(); }
88
90 static void SetPipeToStdErr(bool pipe) { m_pipeToStderr = pipe; }
92 static void GetPipeToStdErr(bool pipe) { m_pipeToStderr = pipe; }
93 static bool GetPipeToStdErr() { return m_pipeToStderr; }
94
103 bool Write(const void *buffer, std::size_t length);
104
112 bool TakeItem(MaximaItemQueue::Item &item) { return m_items.Take(item); }
113
116 void ClearFirstPrompt() { m_firstPrompt = false; }
117
123 XML_PROMPT,
124 XML_SUPPRESSOUTPUT,
125 XML_WXXMLSYMBOLS,
126 XML_VARIABLES,
127 XML_WATCH_VARIABLES_ADD,
128 XML_STATUSBAR,
129 XML_WORKSHEET_EXPORT,
130 XML_HTML_MANUAL_KEYWORDS,
131 XML_MATHS,
132 XML_TOOLONGMATHS,
133 XML_WXXML_KEY,
150 STRING_FOR_XMLINSPECTOR,
156 };
157 void XmlInspectorActive(bool active){m_xmlInspector = active;}
158private:
160 std::atomic_bool m_xmlInspector{false};
161
163 Configuration *m_configuration;
164
166 jthread m_workerThread;
167
169 void SocketEvent(wxSocketEvent &event);
171 void TimerEvent(wxTimerEvent &event);
173 void OnIdle(wxIdleEvent &event);
174
175 std::unique_ptr<wxSocketBase> m_socket;
177 std::mutex m_socketMutex;
179 wxSocketInputStream m_socketInput;
188 wxTextInputStream m_textInput;
189
194 wxString m_socketInputData;
195
199 wxString m_processingBuffer;
200
204 std::vector<std::vector<char>> m_outputQueue;
205 std::mutex m_outputQueueMutex;
206
210 void PushItems(std::vector<MaximaItemQueue::Item> &&items);
211
217 wxMemoryBuffer m_socketOutputData;
218
220 bool m_firstPrompt = true;
222 static bool m_pipeToStderr;
223
231 void WorkerThread(const stop_token& stopToken);
232
243 void ProcessData(const stop_token& stopToken);
252 wxTimer m_readIdleTimer{this};
254 static const std::unordered_map<wxString, EventCause, wxStringHash> &KnownTags();
255};
256
257wxDECLARE_EVENT(EVT_MAXIMA, wxThreadEvent);
258#endif
Small compatibility shims for older toolchains and older wxWidgets.
The hand-over of Maxima's output from the socket thread to the GUI (GH #2594).
The configuration storage for the current worksheet.
Definition: Configuration.h:102
Items Maxima sent, on their way from the socket thread to the GUI thread.
Definition: MaximaItemQueue.h:63
bool Take(Item &item)
Takes the oldest item, merged with the mergeable items that follow it.
Definition: MaximaItemQueue.cpp:42
Interface to the Maxima process.
Definition: Maxima.h:66
EventCause
Definition: Maxima.h:118
@ WRITE_PENDING
A write to Maxima is still ongoing. We use this event to keep the traffic indicator alive.
Definition: Maxima.h:147
@ DATA_AVAILABLE
There are items to take with TakeItem().
Definition: Maxima.h:155
@ READ_PENDING
There's still pending data coming from Maxima. The Data member is empty at the moment.
Definition: Maxima.h:120
@ XML_ASYNC_OUTPUT
Output from a background job, naming the cell it belongs to.
Definition: Maxima.h:143
@ WRITE_ERROR
The transmission has failed - this is an unrecoverable error, most likely.
Definition: Maxima.h:149
@ DISCONNECTED
Maxima has disconnected (possibly because the process had died).
Definition: Maxima.h:145
@ READ_MISC_TEXT
Maxima has sent non-XML text.
Definition: Maxima.h:122
@ XML_ASCIIMATH
Maxima has sent one complete block of ASCII-art 2D display output.
Definition: Maxima.h:135
static void GetPipeToStdErr(bool pipe)
Tells if the user wants all data to maxima to be copied to StdErr.
Definition: Maxima.h:92
static wxString MaximaVarnameToLisp(const wxString &var)
Convert a human-readable maxima variable name to one lisp understands.
Definition: Maxima.cpp:313
static wxString InvertCase(const wxString &var)
Invert case of chars that have inverted case in lisp.
Definition: Maxima.cpp:236
static void SetPipeToStdErr(bool pipe)
Tells us if the user wants all data to maxima to be copied to StdErr.
Definition: Maxima.h:90
bool TakeItem(MaximaItemQueue::Item &item)
Takes the next item Maxima sent.
Definition: Maxima.h:112
bool IsConnected() const
Are we connected to Maxima?
Definition: Maxima.h:87
static wxString EscapeVarnameForMaxima(wxString var)
Convert a human-readable maxima variable name to one maxima understands.
Definition: Maxima.cpp:251
bool Write(const void *buffer, std::size_t length)
Write more data to be sent to maxima.
Definition: Maxima.cpp:122
void ClearFirstPrompt()
Clear the first prompt state, based on what was read from maxima. This is called from prompt recogniz...
Definition: Maxima.h:116
Definition: Compat.h:58
One piece of Maxima's output: what it is, and its text.
Definition: MaximaItemQueue.h:66
Definition: Compat.h:47