Rumba C++ SDK
RedirectStd.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2024
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 #pragma once
16 
17 #include "Maquina/Export.h"
18 
19 MAQUINA_IGNORE_WARNINGS_BEGIN
20 #include <thread>
21 MAQUINA_IGNORE_WARNINGS_END
22 
23 namespace pybind11
24 {
25 class object;
26 }
27 
28 namespace maquina
29 {
30 
34 {
35 public:
36  enum class FileDescriptor
37  {
38  out,
39  err
40  };
41 
44  FileDescriptor fd
45  );
46  virtual ~RedirectStd() {}
47 
49  {
50  return _fd;
51  }
52 
54  void restore();
55 
57 
58  virtual void on_data(const gsl::span<char>& buffer) = 0;
59 
60 private:
61 
62  int _pipe_read = -1; // The READ pipe
63  FileDescriptor _fd = FileDescriptor::out; // The original file descriptor
64  int _original_fd = -1; // The original file descriptor
65  std::shared_ptr<pybind11::object> _python_stdxx = nullptr; // Original python sys.stdxxx
66  std::thread _thread; // The working thread dispatching the buffers
67  FILE* _freopen = nullptr;
68 };
69 
70 }
FileDescriptor
Definition: RedirectStd.h:36
Definition: RedirectStd.h:23
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
#define MAQUINA_EXPORT
Definition: Export.h:31
virtual ~RedirectStd()
Definition: RedirectStd.h:46
FileDescriptor file_descriptor() const
Definition: RedirectStd.h:48
Definition: RedirectStd.h:33