12 class JupyROOTExecutorHandler {
14 bool fCapturing =
false;
15 std::string fStdoutpipe;
16 std::string fStderrpipe;
17 int fStdout_pipe[2] = {0,0};
18 int fStderr_pipe[2] = {0,0};
19 int fSaved_stderr = 0;
20 int fSaved_stdout = 0;
22 JupyROOTExecutorHandler();
27 std::string &GetStdout();
28 std::string &GetStderr();
32 #ifndef F_LINUX_SPECIFIC_BASE 33 #define F_LINUX_SPECIFIC_BASE 1024 36 #define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7) 41 JupyROOTExecutorHandler::JupyROOTExecutorHandler() {}
44 static void PollImpl(FILE *stdStream,
int *pipeHandle, std::string &pipeContent)
50 buf_read =
read(pipeHandle[0], &ch, 1);
57 void JupyROOTExecutorHandler::Poll()
59 PollImpl(stdout, fStdout_pipe, fStdoutpipe);
60 PollImpl(stderr, fStderr_pipe, fStderrpipe);
65 savedStdStream = dup(FILENO);
66 if (pipe(pipeHandle) != 0) {
69 long flags_stdout = fcntl(pipeHandle[0], F_GETFL);
70 if (flags_stdout == -1)
return;
71 flags_stdout |= O_NONBLOCK;
72 fcntl(pipeHandle[0], F_SETFL, flags_stdout);
74 dup2(pipeHandle[1], FILENO);
78 void JupyROOTExecutorHandler::InitCapture()
87 void JupyROOTExecutorHandler::EndCapture()
91 dup2(fSaved_stdout, STDOUT_FILENO);
92 dup2(fSaved_stderr, STDERR_FILENO);
97 void JupyROOTExecutorHandler::Clear()
103 std::string &JupyROOTExecutorHandler::GetStdout()
108 std::string &JupyROOTExecutorHandler::GetStderr()
127 gInterpreter->ProcessLine(
"cerr << \"Unbalanced braces. This cell was not processed.\" << endl;");
162 JupyROOTExecutorHandler_ptr->Clear();
167 if (!JupyROOTExecutorHandler_ptr) {
168 JupyROOTExecutorHandler_ptr =
new JupyROOTExecutorHandler();
170 gInterpreter->ProcessLine(
"SetErrorHandler((ErrorHandlerFunc_t)&DefaultErrorHandler);");
176 JupyROOTExecutorHandler_ptr->Poll();
181 JupyROOTExecutorHandler_ptr->EndCapture();
186 JupyROOTExecutorHandler_ptr->InitCapture();
191 return JupyROOTExecutorHandler_ptr->GetStdout().c_str();
196 return JupyROOTExecutorHandler_ptr->GetStderr().c_str();
201 if (!JupyROOTExecutorHandler_ptr)
return;
203 JupyROOTExecutorHandler_ptr =
nullptr;
bool JupyROOTExecutorImpl(const char *code)
double read(const std::string &file_name)
reading
void JupyROOTExecutorHandler_Clear()
static void InitCaptureImpl(int &savedStdStream, int *pipeHandle, int FILENO)
constexpr long MAX_PIPE_SIZE
const char * JupyROOTExecutorHandler_GetStdout()
void JupyROOTExecutorHandler_Ctor()
void JupyROOTExecutorHandler_EndCapture()
int JupyROOTExecutor(const char *code)
static void PollImpl(FILE *stdStream, int *pipeHandle, std::string &pipeContent)
JupyROOTExecutorHandler * JupyROOTExecutorHandler_ptr
int JupyROOTDeclarer(const char *code)
bool JupyROOTDeclarerImpl(const char *code)
void JupyROOTExecutorHandler_Poll()
void JupyROOTExecutorHandler_Dtor()
const char * JupyROOTExecutorHandler_GetStderr()
void JupyROOTExecutorHandler_InitCapture()