wxMaxima
Loading...
Searching...
No Matches
MaximaIPC.h
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2020 Kuba Ober <kuba@bertec.com>
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
22#ifndef WXMAXIMA_MAXIMA_IPC_H
23#define WXMAXIMA_MAXIMA_IPC_H
24
25#include <memory>
26#include <unordered_map>
27#include <vector>
28#include <utility>
29#include <wx/hashmap.h>
30#include <wx/string.h>
31
32class wxMaxima;
33class wxEvent;
34class wxEvtHandler;
35
41{
42public:
43 explicit MaximaIPC(wxMaxima *wxm);
44
50 void ReadInputData(const wxString &data);
51 static void EnableIPC() { m_enabled = true; }
52 static bool GetEnableIPC() { return m_enabled; }
53
65 bool DrainQueue();
66
67private:
68 wxMaxima *m_wxMaxima = nullptr;
69 std::unordered_map<wxString, wxEvtHandler*, wxStringHash> m_eventTargets;
70
71 struct QueuedEvent {
72 wxEvtHandler *target;
73 std::unique_ptr<wxEvent> event;
74 QueuedEvent(wxEvtHandler *target, std::unique_ptr<wxEvent> &&event)
75 : target(target), event(std::move(event)) {}
76 };
77 std::size_t m_queueTail = 0;
78 std::vector<QueuedEvent> m_queue;
79
80 static bool m_enabled;
81};
82
83#endif
Handles the "<ipc>" tag from Maxima.
Definition: MaximaIPC.h:41
bool DrainQueue()
Drains the event queue and dispatches a queued IPC event to its target.
Definition: MaximaIPC.cpp:155
void ReadInputData(const wxString &data)
Reads the interprocess communications tag, used in test scripts, etc.
Definition: MaximaIPC.cpp:90
Definition: wxMaxima.h:65