Line data Source code
1 : // Author(s): Thomas Neele 2 : // Copyright: see the accompanying file COPYING or copy at 3 : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING 4 : // 5 : // Distributed under the Boost Software License, Version 1.0. 6 : // (See accompanying file LICENSE_1_0.txt or copy at 7 : // http://www.boost.org/LICENSE_1_0.txt) 8 : // 9 : /// \file child_process.h 10 : 11 : #ifndef MCRL2_SMT_CHILD_PROCESS_H 12 : #define MCRL2_SMT_CHILD_PROCESS_H 13 : 14 : #include <chrono> 15 : #include <string> 16 : #include <memory> 17 : 18 : namespace mcrl2 19 : { 20 : namespace smt 21 : { 22 : 23 : class child_process 24 : { 25 : protected: 26 : struct platform_impl; 27 : 28 : std::string m_name; 29 : // The declaration of the pipes requires expensive headers on Windows, so 30 : // we use the pimpl idiom to hide platform dependent implementation details. 31 : std::shared_ptr<platform_impl> m_pimpl; 32 : 33 : void initialize(); 34 : 35 : /** 36 : * \brief Send the SIGINT signal to the child 37 : */ 38 : void send_sigint() const; 39 : 40 : public: 41 0 : child_process(const std::string& name) 42 0 : : m_name(name) 43 : { 44 0 : initialize(); 45 0 : } 46 : 47 : ~child_process(); 48 : 49 : void write(const std::string& s) const; 50 : 51 : /** 52 : * \brief Read output from the child process. This is a blocking call. 53 : */ 54 : std::string read() const; 55 : 56 : /** 57 : * \brief Read output from the child process. If no output is available before 58 : * the timeout happens, a SIGINT signal is sent to the child process and the 59 : * resulting output is read and returned. NOTE: this function is not 60 : * on Windows, and behaves like read() 61 : */ 62 : std::string read(const std::chrono::microseconds& timeout) const; 63 : }; 64 : 65 : } // namespace smt 66 : } // namespace mcrl2 67 : 68 : #endif // MCRL2_SMT_CHILD_PROCESS_H