Motion Master 6.0.0-alpha.86
Next-generation motion control software
Loading...
Searching...
No Matches
mm::auto_tuning::Process Class Reference

Starts the auto-tuning executable and keeps it running for the process lifetime. More...

#include <process.h>

Public Types

enum class  StopOutcome { NotRunning , Requested , Signalled , Killed }
 How a stop ended, so that the caller can log it. More...
 

Public Member Functions

 Process (ProcessOptions options)
 
 ~Process ()
 Stops the child. A Motion Master that exits leaves nothing running behind it.
 
 Process (const Process &)=delete
 
Processoperator= (const Process &)=delete
 
 Process (Process &&)=delete
 
Processoperator= (Process &&)=delete
 
std::expected< void, std::string > start ()
 Spawns the child and waits for it to serve.
 
StopOutcome stop ()
 Asks the child to exit, then kills it if it does not.
 
const std::string & version () const
 The version the child reported at startup, or empty when it never started.
 
std::string baseUrl () const
 The root URL of the child's API, for a client to build request URLs from.
 
const ProcessOptionsoptions () const
 The options this instance was constructed with.
 
std::int64_t pid () const
 The child's process id, or 0 when nothing is running. For the startup log line.
 

Detailed Description

Starts the auto-tuning executable and keeps it running for the process lifetime.

start and stop belong to the composition root and run on one thread. They are the only members that touch the child. Everything else is read-only after a successful start, and safe to read from any thread, which is what the HTTP routes do.

There is deliberately no "is it running" query. Answering it means reaping the child, and a reaped process id can be reissued to something else — so a query that reaped would let a later stop signal an unrelated process. The child's health is discovered by calling it: a request to a dead child fails, and that is the honest answer rather than a flag that was true a moment ago.

Member Enumeration Documentation

◆ StopOutcome

How a stop ended, so that the caller can log it.

On Windows only NotRunning, Requested and Killed occur: there is no signal that program handles there, so the middle step does not exist.

Enumerator
NotRunning 

Nothing was running.

Requested 

It exited on the exit request, which is the ordinary case.

Signalled 

It ignored the request and exited on the termination signal.

Killed 

It ignored both and was killed.

Constructor & Destructor Documentation

◆ Process() [1/3]

mm::auto_tuning::Process::Process ( ProcessOptions  options)
explicit

◆ ~Process()

mm::auto_tuning::Process::~Process ( )

Stops the child. A Motion Master that exits leaves nothing running behind it.

◆ Process() [2/3]

mm::auto_tuning::Process::Process ( const Process )
delete

◆ Process() [3/3]

mm::auto_tuning::Process::Process ( Process &&  )
delete

Member Function Documentation

◆ baseUrl()

std::string mm::auto_tuning::Process::baseUrl ( ) const

The root URL of the child's API, for a client to build request URLs from.

◆ operator=() [1/2]

Process & mm::auto_tuning::Process::operator= ( const Process )
delete

◆ operator=() [2/2]

Process & mm::auto_tuning::Process::operator= ( Process &&  )
delete

◆ options()

const ProcessOptions & mm::auto_tuning::Process::options ( ) const
inline

The options this instance was constructed with.

◆ pid()

std::int64_t mm::auto_tuning::Process::pid ( ) const
inline

The child's process id, or 0 when nothing is running. For the startup log line.

◆ start()

std::expected< void, std::string > mm::auto_tuning::Process::start ( )

Spawns the child and waits for it to serve.

Runs the executable as <binary> --http --host 127.0.0.1 --port <port>, then polls GET /api/health until it answers or startTimeout expires. The reply carries the program's version, which version then reports.

Call this before the calling thread becomes real-time. A child inherits the scheduling policy of the thread that spawned it, and this child spreads its work over one numerical worker thread per core, which synchronise by spin-waiting. At real-time priority each of those burns a whole timeslice waiting for the others: measured on the previous integration, a seven-second identification took minutes and starved the 1 ms cycle while it ran.

Returns
Nothing on success, or an error naming what failed: a missing executable, a spawn failure, a child that exited during the wait, or a timeout.

◆ stop()

Process::StopOutcome mm::auto_tuning::Process::stop ( )

Asks the child to exit, then kills it if it does not.

Three steps, politest first: a {"run":"exit"} request, which the auto-tuning program answers by shutting its server down; then a termination signal; then a kill of the whole process group. The request matters most on Windows, which has no signal the program handles, and where its own output is block-buffered — so a hard kill there would lose the tail of its log.

Safe to call when nothing was started, and safe to call twice.

Returns
Which step ended it. Killed is the one worth a warning: a child wedged inside a numerical routine had to be taken down, and that is the case where something could be left holding the port.

◆ version()

const std::string & mm::auto_tuning::Process::version ( ) const
inline

The version the child reported at startup, or empty when it never started.


The documentation for this class was generated from the following files: