xtd 0.2.0
process.h
Go to the documentation of this file.
1 #pragma once
5 #include "../core_export.h"
6 #include "../date_time.h"
7 #include "../event.h"
8 #include "../event_handler.h"
9 #include "../object.h"
10 #include "../ustring.h"
11 #include "../optional.h"
13 #include "process_priority_class.h"
14 #include "process_start_info.h"
15 #include <functional>
16 #include <memory>
17 
19 struct __init_process_message_box_message__;
21 
23 namespace xtd {
25  namespace diagnostics {
47  class core_export_ process final : public xtd::object {
48  struct data;
49 
50  public:
57  friend process;
58  void set_data(process::data* data) {data_ = data;}
59  public:
61 
65  bool is_empty() const noexcept;
67 
69 
75 
79  xtd::diagnostics::data_received_event_handler& operator +=(const typename xtd::diagnostics::data_received_event_handler::function_t& function) noexcept;
80 
84  template<typename fn_t>
85  xtd::diagnostics::data_received_event_handler& operator +=(fn_t function) noexcept {
86  error_data_received_callback() += (function);
87  return xtd::diagnostics::data_received_event_handler::operator +=(function);
88  }
89 
94 
98  xtd::diagnostics::data_received_event_handler& operator -=(const typename xtd::diagnostics::data_received_event_handler::function_t& function) noexcept;
99 
103  template<typename fn_t>
104  xtd::diagnostics::data_received_event_handler& operator -=(fn_t function) noexcept {
105  error_data_received_callback() -= (function);
106  return data_received_event_handler::operator -=(function);
107  }
109 
110  private:
111  data_received_event_handler& error_data_received_callback() noexcept;
112  process::data* data_ = nullptr;
113  };
114 
120  class exit_event : protected xtd::event_handler {
121  friend process;
122  void set_data(process::data* data) {data_ = data;}
123  public:
125 
129  bool is_empty() const noexcept;
131 
133 
138  xtd::event_handler& operator +=(const xtd::event_handler& handler) noexcept;
139 
143  xtd::event_handler& operator +=(const typename xtd::event_handler::function_t& function) noexcept;
144 
148  template<typename fn_t>
149  xtd::event_handler& operator +=(fn_t function) noexcept {
150  exit_callback() += (function);
151  return xtd::event_handler::operator +=(function);
152  }
153 
157  xtd::event_handler& operator -=(const xtd::event_handler& handler) noexcept;
158 
162  xtd::event_handler& operator -=(const typename xtd::event_handler::function_t& function) noexcept;
163 
167  template<typename fn_t>
168  xtd::event_handler& operator -=(fn_t function) noexcept {
169  exit_callback() -= (function);
170  return xtd::event_handler::operator -=(function);
171  }
173 
174  private:
175  event_handler& exit_callback() noexcept;
176  process::data* data_ = nullptr;
177  };
178 
185  friend process;
186  void set_data(process::data* data) {data_ = data;}
187  public:
189 
193  bool is_empty() const noexcept;
195 
197 
203 
207  xtd::diagnostics::data_received_event_handler& operator +=(const typename xtd::diagnostics::data_received_event_handler::function_t& function) noexcept;
208 
212  template<typename fn_t>
213  xtd::diagnostics::data_received_event_handler& operator +=(fn_t function) noexcept {
214  output_data_received_callback() += (function);
215  return xtd::diagnostics::data_received_event_handler::operator +=(function);
216  }
217 
222 
226  xtd::diagnostics::data_received_event_handler& operator -=(const typename xtd::diagnostics::data_received_event_handler::function_t& function) noexcept;
227 
231  template<typename fn_t>
232  xtd::diagnostics::data_received_event_handler& operator -=(fn_t function) noexcept {
233  output_data_received_callback() -= (function);
234  return xtd::diagnostics::data_received_event_handler::operator -=(function);
235  }
237 
238  private:
239  data_received_event_handler& output_data_received_callback() noexcept;
240  process::data* data_ = nullptr;
241  };
242 
244 
253  process();
255 
257  process(const process&) = default;
258  process& operator =(const process& value);
259  ~process();
261 
263 
280  int32 base_priority() const;
281 
289  bool enable_raising_events() const;
297  process& enable_raising_events(bool value);
298 
310  int32 exit_code() const;
311 
316  xtd::date_time exit_time() const;
317 
325  intptr handle() const;
326 
334  bool has_exited() const;
335 
343  int32 id() const;
344 
350  ustring machine_name() const;
351 
367  xtd::diagnostics::process_priority_class priority_class() const;
383  process& priority_class(xtd::diagnostics::process_priority_class value);
384 
390  ustring process_name() const;
391 
500  std::istream& standard_error();
501 
565  std::ostream& standard_input();
566 
690  std::istream& standard_output();
691 
701  const xtd::diagnostics::process_start_info& start_info() const;
721  process& start_info(const xtd::diagnostics::process_start_info& value);
722 
726  xtd::date_time start_time() const;
728 
730 
735  void close();
736 
745  void kill();
746 
753  bool start();
767  static process start(const xtd::diagnostics::process_start_info& start_info);
779  static process start(const ustring& file_name);
791  static process start(const ustring& file_name, const ustring& arguments);
792 
800  process& wait_for_exit();
801 
810  process& wait_for_exit(int32 milliseconds);
812 
814 
821 
828 
835 
836  protected:
838 
843  virtual void on_exited();
845 
846  private:
847  std::shared_ptr<data> data_;
848  friend __init_process_message_box_message__;
849  inline static xtd::delegate<void(const ustring&)> message_box_message_;
850  };
851  }
852 }
Represents a process output data received event.
Definition: process.h:184
intmax_t intptr
Represent a pointer or a handle.
Definition: types.h:151
process_priority_class
Indicates the priority that the system associates with a process. This value, together with the prior...
Definition: process_priority_class.h:24
generic_event_handler<> event_handler
Represents the method that will handle an event that has no event data.
Definition: event_handler.h:32
Represents a process error data received event.
Definition: process.h:56
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
output_data_received_event output_data_received
Occurs each time an application writes a line to its redirected xtd::diagnostics::process::standard_o...
Definition: process.h:833
error_data_received_event error_data_received
Occurs when an application writes to its redirected xtd::diagnostics::process::standard_error stream...
Definition: process.h:820
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
Contains xtd::diagnostics::process_start_info class.
Starting of a logical operation.
Provides access to local and remote processes and enables you to start and stop local system processe...
Definition: process.h:47
Represents an instant in time, typically expressed as a date and time of day.
Definition: date_time.h:78
xtd::delegate< void(xtd::object &sender, const xtd::diagnostics::data_received_event_args &e)> data_received_event_handler
Represents the method that will handle the xtd::diagnostics::process::output_data_received and xtd::d...
Definition: data_received_event_handler.h:25
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains xtd::diagnostics::process_priority_class enum class.
Represents a process exit event.
Definition: process.h:120
Contains xtd::diagnostics::data_received_event_handler event handler.
exit_event exited
Occurs when a process exits.
Definition: process.h:827
Specifies a set of values that are used when you start a process.
Definition: process_start_info.h:37