Goby3 3.6.1
2026.09.15
Loading...
Searching...
No Matches
goby::middleware::python::ApplicationWrapper< App > Class Template Reference

The class exposed to Python; user application classes subclass this. More...

#include <goby/middleware/languages/python/application.h>

Inheritance diagram for goby::middleware::python::ApplicationWrapper< App >:
goby::middleware::python::ApplicationWrapperTrampoline< App >

Public Member Functions

 ApplicationWrapper (double loop_frequency_hertz=0)
 Constructs the underlying Goby application.
 
virtual ~ApplicationWrapper ()=default
 
 ApplicationWrapper (const ApplicationWrapper &)=delete
 
ApplicationWrapper & operator= (const ApplicationWrapper &)=delete
 
virtual void loop ()
 Override in Python to do work at loop_frequency Hz.
 
virtual void initialize ()
 Override in Python for work that can't be done in the constructor.
 
virtual void finalize ()
 Override in Python for cleanup just before the application exits.
 
virtual std::string health (py::bytes serialized)
 Override in Python to answer goby_coroner's health request.
 
int run ()
 Runs the Goby event loop until quit() is called or the application is terminated.
 
void quit (int return_value=0)
 Requests a clean exit.
 
std::string app_name ()
 The application name, as set by –app_name or derived from argv[0].
 
py::bytes cfg_serialized ()
 The configuration the application was started with, serialized as Protobuf.
 
void set_loop_frequency_hertz (double loop_frequency_hertz)
 
void publish (int layer, const std::string &type_name, int scheme, const std::string &group, const std::string &data)
 Publishes already-marshalled bytes; dispatched by the generated glue code.
 
void subscribe (int layer, const std::string &type_name, int scheme, const std::string &group, py::object callback)
 Subscribes a Python callable; dispatched by the generated glue code.
 

Static Public Member Functions

static py::bytes configure (const std::vector< std::string > &argv)
 Reads the command line into the application configuration.
 
static py::bytes configure_from_text (const std::string &config_text)
 Reads the application configuration from a Protobuf TextFormat string.
 
static py::bytes configure_from_serialized (const std::string &config_bytes)
 Reads the application configuration from a serialized Protobuf message.
 

Detailed Description

template<typename App>
class goby::middleware::python::ApplicationWrapper< App >

The class exposed to Python; user application classes subclass this.

Template Parameters
Appthe generated glue class, which derives from python::Application

Definition at line 246 of file application.h.

Constructor & Destructor Documentation

◆ ApplicationWrapper() [1/2]

template<typename App >
goby::middleware::python::ApplicationWrapper< App >::ApplicationWrapper ( double  loop_frequency_hertz = 0)
inline

Constructs the underlying Goby application.

configure() must have been called first (goby.run does this), as the Goby application reads its configuration during construction.

Parameters
loop_frequency_hertzfrequency at which to call loop(); zero means never

Definition at line 255 of file application.h.

◆ ~ApplicationWrapper()

template<typename App >
virtual goby::middleware::python::ApplicationWrapper< App >::~ApplicationWrapper ( )
virtualdefault

◆ ApplicationWrapper() [2/2]

template<typename App >
goby::middleware::python::ApplicationWrapper< App >::ApplicationWrapper ( const ApplicationWrapper< App > &  )
delete

Member Function Documentation

◆ app_name()

template<typename App >
std::string goby::middleware::python::ApplicationWrapper< App >::app_name ( )
inline

The application name, as set by –app_name or derived from argv[0].

Definition at line 398 of file application.h.

◆ cfg_serialized()

template<typename App >
py::bytes goby::middleware::python::ApplicationWrapper< App >::cfg_serialized ( )
inline

The configuration the application was started with, serialized as Protobuf.

Definition at line 401 of file application.h.

◆ configure()

template<typename App >
static py::bytes goby::middleware::python::ApplicationWrapper< App >::configure ( const std::vector< std::string > &  argv)
inlinestatic

Reads the command line into the application configuration.

Mirrors the configuration handling in goby::run, so Python applications accept the same command line as C++ applications (–help, –example_config, -v, per-field overrides, ...).

Parameters
argvthe full command line, including argv[0]
Returns
the parsed configuration, serialized as Protobuf
Exceptions
goby::middleware::ConfigExceptiontranslated to goby.ConfigError in Python

Definition at line 306 of file application.h.

◆ configure_from_serialized()

template<typename App >
static py::bytes goby::middleware::python::ApplicationWrapper< App >::configure_from_serialized ( const std::string &  config_bytes)
inlinestatic

Reads the application configuration from a serialized Protobuf message.

Exceptions
goby::middleware::ConfigExceptiontranslated to goby.ConfigError in Python

Definition at line 372 of file application.h.

◆ configure_from_text()

template<typename App >
static py::bytes goby::middleware::python::ApplicationWrapper< App >::configure_from_text ( const std::string &  config_text)
inlinestatic

Reads the application configuration from a Protobuf TextFormat string.

Intended for embedding a Goby application in a larger Python program, and for tests that shouldn't need a command line or a configuration file.

Exceptions
goby::middleware::ConfigExceptiontranslated to goby.ConfigError in Python

Definition at line 353 of file application.h.

◆ finalize()

template<typename App >
virtual void goby::middleware::python::ApplicationWrapper< App >::finalize ( )
inlinevirtual

Override in Python for cleanup just before the application exits.

Reimplemented in goby::middleware::python::ApplicationWrapperTrampoline< App >.

Definition at line 290 of file application.h.

◆ health()

template<typename App >
virtual std::string goby::middleware::python::ApplicationWrapper< App >::health ( py::bytes  serialized)
inlinevirtual

Override in Python to answer goby_coroner's health request.

Parameters
serializedthe ThreadHealth Goby filled in
Returns
the ThreadHealth to report, or an empty string to keep Goby's unchanged

Reimplemented in goby::middleware::python::ApplicationWrapperTrampoline< App >.

Definition at line 296 of file application.h.

◆ initialize()

template<typename App >
virtual void goby::middleware::python::ApplicationWrapper< App >::initialize ( )
inlinevirtual

Override in Python for work that can't be done in the constructor.

Reimplemented in goby::middleware::python::ApplicationWrapperTrampoline< App >.

Definition at line 287 of file application.h.

◆ loop()

template<typename App >
virtual void goby::middleware::python::ApplicationWrapper< App >::loop ( )
inlinevirtual

Override in Python to do work at loop_frequency Hz.

Reimplemented in goby::middleware::python::ApplicationWrapperTrampoline< App >.

Definition at line 280 of file application.h.

◆ operator=()

template<typename App >
ApplicationWrapper & goby::middleware::python::ApplicationWrapper< App >::operator= ( const ApplicationWrapper< App > &  )
delete

◆ publish()

template<typename App >
void goby::middleware::python::ApplicationWrapper< App >::publish ( int  layer,
const std::string &  type_name,
int  scheme,
const std::string &  group,
const std::string &  data 
)
inline

Publishes already-marshalled bytes; dispatched by the generated glue code.

Definition at line 414 of file application.h.

◆ quit()

template<typename App >
void goby::middleware::python::ApplicationWrapper< App >::quit ( int  return_value = 0)
inline

Requests a clean exit.

Definition at line 395 of file application.h.

◆ run()

template<typename App >
int goby::middleware::python::ApplicationWrapper< App >::run ( )
inline

Runs the Goby event loop until quit() is called or the application is terminated.

The GIL is released for the duration, and reacquired for each callback into Python.

Returns
the application return value

Definition at line 387 of file application.h.

◆ set_loop_frequency_hertz()

template<typename App >
void goby::middleware::python::ApplicationWrapper< App >::set_loop_frequency_hertz ( double  loop_frequency_hertz)
inline

Definition at line 408 of file application.h.

◆ subscribe()

template<typename App >
void goby::middleware::python::ApplicationWrapper< App >::subscribe ( int  layer,
const std::string &  type_name,
int  scheme,
const std::string &  group,
py::object  callback 
)
inline

Subscribes a Python callable; dispatched by the generated glue code.

Definition at line 422 of file application.h.


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