wxMaxima
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 <wx/hashmap.h>
26 #include <wx/string.h>
27 #include <memory>
28 #include <unordered_map>
29 #include <vector>
30 
31 class wxMaxima;
32 class wxEvent;
33 class wxEvtHandler;
34 
39 class MaximaIPC
40 {
41 public:
42  explicit MaximaIPC(wxMaxima *wxm);
43 
49  void ReadInputData(wxString &data);
50  static void EnableIPC() { m_enabled = true; }
51 
63  bool DrainQueue();
64 
65 private:
66  wxMaxima *m_wxMaxima = nullptr;
67  std::unordered_map<wxString, wxEvtHandler*, wxStringHash> m_eventTargets;
68 
69  struct QueuedEvent {
70  wxEvtHandler *target;
71  std::unique_ptr<wxEvent> event;
72  QueuedEvent(wxEvtHandler *target, std::unique_ptr<wxEvent> &&event)
73  : target(target), event(std::move(event)) {}
74  };
75  size_t m_queueTail = 0;
76  std::vector<QueuedEvent> m_queue;
77 
78  static bool m_enabled;
79 };
80 
81 #endif
MaximaIPC::DrainQueue
bool DrainQueue()
Definition: MaximaIPC.cpp:166
MaximaIPC
Definition: MaximaIPC.h:39
MaximaIPC::ReadInputData
void ReadInputData(wxString &data)
Definition: MaximaIPC.cpp:86
wxMaxima
Definition: wxMaxima.h:80