mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-06 23:31:19 +00:00
* Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes. clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer. * Remove Unused Project Includes From Files With Platform-Specific Code A Linux include-what-you-use run cannot see the code inside _WIN32, __APPLE__ or __linux__ blocks, so its verdict is only taken where nothing the removed header declares, directly or through what it includes, is named inside those blocks. Removals also have to hold in both the Release and Debug configuration and never touch a line inside a conditional block. * Restore the libslic3r Precompiled Header and Direct Includes Lost in the Platform Pass The platform-file pass treated pchheader.hpp as an ordinary header and emptied it, and left GUI_Preview.hpp and 14 other files relying on headers they no longer reached directly. * Restore MainFrame.hpp in ParamsDialog.cpp for the Windows-Only Reparent Call * Include Headers That Files Reached Through Ones the Cleanup Removed * Drop Includes Duplicated by the Cleanup or by Main's Own Additions * Leave PreciseSeam.cpp as Main Has It After the Precise Seam Rework
97 lines
3.0 KiB
C++
97 lines
3.0 KiB
C++
#ifndef slic3r_GUI_ProcessRunner_hpp_
|
|
#define slic3r_GUI_ProcessRunner_hpp_
|
|
|
|
#include <boost/process/pipe.hpp>
|
|
#include <wx/event.h>
|
|
#include <wx/timer.h>
|
|
|
|
#include <atomic>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <vector>
|
|
#include <functional>
|
|
|
|
#include <boost/process.hpp>
|
|
|
|
namespace boost::process { class child; }
|
|
|
|
namespace Slic3r { namespace GUI {
|
|
|
|
class ProcessRunner : public wxEvtHandler
|
|
{
|
|
public:
|
|
ProcessRunner();
|
|
~ProcessRunner() override;
|
|
|
|
struct OutputLine {
|
|
std::string text;
|
|
bool is_stderr;
|
|
};
|
|
using OutputCallback = std::function<void(const std::vector<OutputLine>& lines)>;
|
|
using DoneCallback = std::function<void(int exit_code)>;
|
|
|
|
// Non-blocking command-line style launch. Boost parses command_line into
|
|
// executable + arguments.
|
|
// Output is batched per timer tick (50ms) and delivered via on_output on the GUI thread.
|
|
// on_done fires on the GUI thread with the exit code.
|
|
// Returns false if a process is already running.
|
|
bool run_command_line_async(const std::string& command_line,
|
|
OutputCallback on_output,
|
|
DoneCallback on_done);
|
|
|
|
struct SyncResult {
|
|
int exit_code = -1;
|
|
std::string stdout_output;
|
|
std::string stderr_output;
|
|
};
|
|
|
|
// Blocking: runs the process and waits for it to finish.
|
|
// Safe to call from any thread (no wx dependency).
|
|
static SyncResult run_sync(const std::string& executable,
|
|
const std::vector<std::string>& args);
|
|
|
|
// Write data to the running process's stdin (async mode only).
|
|
void write_stdin(const std::string& data);
|
|
|
|
// True while an async process is launching or running.
|
|
bool is_running() const;
|
|
|
|
// Terminate the running process (async mode only).
|
|
void terminate();
|
|
|
|
private:
|
|
void on_timer(wxTimerEvent& event);
|
|
void finish_process(int exit_code);
|
|
void start_reader_threads();
|
|
void join_reader_threads();
|
|
void enqueue_output(std::string line, bool is_stderr);
|
|
std::vector<OutputLine> drain_output_queue();
|
|
// Join any completed background launcher thread before reusing or destroying it.
|
|
void join_launch_thread();
|
|
|
|
wxTimer m_poll_timer;
|
|
|
|
// True while the launcher thread is still creating the child process; join only after this becomes false.
|
|
std::atomic_bool m_launching{false};
|
|
std::atomic_bool m_launch_failed{false};
|
|
std::thread m_launch_thread;
|
|
std::thread m_stdout_thread;
|
|
std::thread m_stderr_thread;
|
|
std::mutex m_output_mutex;
|
|
std::vector<OutputLine> m_output_queue;
|
|
|
|
std::unique_ptr<boost::process::child> m_process;
|
|
std::unique_ptr<boost::process::ipstream> m_stdout_pipe;
|
|
std::unique_ptr<boost::process::ipstream> m_stderr_pipe;
|
|
std::unique_ptr<boost::process::opstream> m_stdin_pipe;
|
|
|
|
OutputCallback m_on_output;
|
|
DoneCallback m_on_done;
|
|
};
|
|
|
|
}} // namespace Slic3r::GUI
|
|
|
|
#endif
|