Turi Create  4.0
process_wrapper.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef __TC_PROCESS_WRAPPER
7 #define __TC_PROCESS_WRAPPER
8 
9 #include "io_buffer.hpp"
10 
11 #include <cstdio>
12 #include <string>
13 #include <thread>
14 #include <core/parallel/pthread_tools.hpp>
15 
16 #include <process/process.hpp>
17 
18 
19 namespace turi {
20  namespace visualization {
21  class process_wrapper {
22  private:
23  volatile bool m_alive;
24  turi::mutex m_mutex;
25  turi::conditional m_cond;
26  ::turi::process m_client_process;
27  io_buffer m_inputBuffer;
28  std::thread m_inputThread;
29  io_buffer m_outputBuffer;
30  std::thread m_outputThread;
31 
32  public:
33  explicit process_wrapper(const std::string& path_to_client);
34  ~process_wrapper();
35  process_wrapper& operator<<(const std::string& to_client);
36  process_wrapper& operator>>(std::string& from_client);
37  bool good();
38  };
39 
40  }
41 }
42 
43 #endif // __TC_PROCESS_WRAPPER