Motion Master 6.0.0-alpha.86
Next-generation motion control software
Loading...
Searching...
No Matches
process.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5#include <expected>
6#include <filesystem>
7#include <string>
8
26
27namespace mm::auto_tuning {
28
33constexpr std::uint16_t kDefaultPort = 63528;
34
39std::filesystem::path defaultBinaryName();
40
45 std::filesystem::path binary;
46 std::uint16_t port = kDefaultPort;
51 std::filesystem::path logFile;
59 std::chrono::milliseconds startTimeout{30000};
60};
61
73class Process {
74 public:
76
78 ~Process();
79
80 Process(const Process&) = delete;
81 Process& operator=(const Process&) = delete;
82 Process(Process&&) = delete;
84
99 std::expected<void, std::string> start();
100
105 enum class StopOutcome {
106 NotRunning,
107 Requested,
108 Signalled,
109 Killed,
110 };
111
126
128 const std::string& version() const { return version_; }
129
131 std::string baseUrl() const;
132
134 const ProcessOptions& options() const { return options_; }
135
137 std::int64_t pid() const { return pid_; }
138
139 private:
142 void forget();
143
144 ProcessOptions options_;
146 std::int64_t pid_ = 0;
148 std::intptr_t handle_ = 0;
151 std::intptr_t group_ = 0;
152 std::string version_;
153};
154
155} // namespace mm::auto_tuning
Starts the auto-tuning executable and keeps it running for the process lifetime.
Definition process.h:73
StopOutcome stop()
Asks the child to exit, then kills it if it does not.
Definition process.cc:113
const std::string & version() const
The version the child reported at startup, or empty when it never started.
Definition process.h:128
Process & operator=(Process &&)=delete
const ProcessOptions & options() const
The options this instance was constructed with.
Definition process.h:134
std::expected< void, std::string > start()
Spawns the child and waits for it to serve.
Definition process.cc:64
Process & operator=(const Process &)=delete
StopOutcome
How a stop ended, so that the caller can log it.
Definition process.h:105
@ Signalled
It ignored the request and exited on the termination signal.
@ Killed
It ignored both and was killed.
@ Requested
It exited on the exit request, which is the ordinary case.
std::int64_t pid() const
The child's process id, or 0 when nothing is running. For the startup log line.
Definition process.h:137
~Process()
Stops the child. A Motion Master that exits leaves nothing running behind it.
Definition process.cc:60
Process(const Process &)=delete
std::string baseUrl() const
The root URL of the child's API, for a client to build request URLs from.
Definition process.cc:62
Process(Process &&)=delete
Definition client.cc:5
std::filesystem::path defaultBinaryName()
Name of the executable Motion Master installs beside itself.
Definition process.cc:50
constexpr std::uint16_t kDefaultPort
Port the child serves on when the configuration names none.
Definition process.h:33
What to start, and where.
Definition process.h:42
std::uint16_t port
Definition process.h:46
std::chrono::milliseconds startTimeout
Definition process.h:59
std::filesystem::path logFile
Definition process.h:51
std::filesystem::path binary
Definition process.h:45