AsyncFw 1.2
Async Framework is c++ runtime with timers, poll notifiers, sockets, coroutines, etc.
 
Loading...
Searching...
No Matches
SystemProcess.h
1/*
2Copyright (c) 2026 Alexandr Kuzmuk
3
4This file is part of the AsyncFw project. Licensed under the MIT License.
5See {Link: LICENSE file https://mit-license.org} in the project root for full license information.
6*/
7
8#pragma once
9
10#include <string>
11#include "../core/FunctionConnector.h"
12
13namespace AsyncFw {
16class SystemProcess {
17public:
18 enum State : uint8_t { None, Running, Finished, Crashed, Error };
19 SystemProcess(bool = false);
20 ~SystemProcess();
21 bool start(const std::string &, const std::vector<std::string> & = {});
22 bool start();
23 State state();
24 pid_t pid();
25 void wait();
26 int exitCode();
27 bool input(const std::string &) const;
28
30 FunctionConnectorProtected<SystemProcess>::Connector<State> stateChanged {AbstractFunctionConnector::Queued};
32 FunctionConnectorProtected<SystemProcess>::Connector<const std::string &, bool /*stdout: 0, stderr: 1*/> output {AbstractFunctionConnector::Queued};
33
34 template <typename T>
35 static bool exec(const std::string &cmd, const std::vector<std::string> &args, T f) {
36 return exec_(cmd, args, new FunctionArgs<int, State, const std::string &, const std::string &>::Function<T>(f));
37 }
38 template <typename T>
39 static bool exec(const std::string &cmd, T f) {
40 return exec_(cmd, {}, new FunctionArgs<int, State, const std::string &, const std::string &>::Function<T>(f));
41 }
42 static bool exec(const std::string &cmd, const std::vector<std::string> &args = {}) { return exec_(cmd, args, nullptr); }
43
44private:
45 static bool exec_(const std::string &, const std::vector<std::string> &, AbstractFunction<int, State, const std::string &, const std::string &> *);
46
47 void finality();
48 struct Private;
49 Private *private_;
50};
51
52} // namespace AsyncFw
FunctionConnectorProtected< SystemProcess >::Connector< State > stateChanged
The FunctionConnector for SystemProcess stateChanged.
Definition SystemProcess.h:30
FunctionConnectorProtected< SystemProcess >::Connector< const std::string &, bool > output
The FunctionConnector for SystemProcess output.
Definition SystemProcess.h:32