The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
mhaserver_t Class Reference

MHA Framework listening on TCP port for commands. More...

Inheritance diagram for mhaserver_t:
Inheritance graph

Classes

class  tcp_server_t
 

Public Member Functions

 mhaserver_t (const std::string &ao, const std::string &af, const std::string &lf, bool b_interactive_)
 
 ~mhaserver_t ()
 
virtual std::string on_received_line (const std::string &line)
 A line of text was received from network client. More...
 
virtual void acceptor_started ()
 Notification: "TCP port is open". More...
 
virtual void send_port_announcement ()
 sends an announcement which port this MHA is listening on to the creator of the process. More...
 
virtual void start_stdin_thread ()
 Starts a separate thread that reads lines from stdin and forwards these lines over TCP to the MHA configuration thread which multiplexes multiple TCP connections. More...
 
virtual void set_announce_port (unsigned short announce_port)
 If set to nonzero, the spawning process has asked to be notified of the TCP port used by this process. More...
 
void logstring (const std::string &)
 Log a message to log file. More...
 
int run (unsigned short port, const std::string &_interface)
 Accept network connections and act on commands. More...
 
- Public Member Functions inherited from fw_t
 fw_t ()
 
 ~fw_t ()
 
bool exit_request () const
 
- Public Member Functions inherited from MHAParser::parser_t
 parser_t (const std::string &help_text="")
 Construct detached node to be used in the configuration tree. More...
 
 ~parser_t ()
 
void insert_item (const std::string &, base_t *)
 Register a parser item into this sub-parser. More...
 
void remove_item (const std::string &)
 Remove an item by name. More...
 
void force_remove_item (const std::string &)
 Remove an item by name. More...
 
void remove_item (const base_t *)
 Remove an item by address. More...
 
- Public Member Functions inherited from MHAParser::base_t
 base_t (const std::string &)
 Constructor for base class of all parser nodes. More...
 
 base_t (const base_t &)
 Copy constructor for base_t. More...
 
base_toperator= (const base_t &)=default
 
 base_t (base_t &&)=delete
 
base_toperator= (base_t &&)=delete
 
virtual ~base_t ()
 
virtual std::string parse (const std::string &)
 Causes this node to process a command in the openMHA configuration language. More...
 
virtual void parse (const char *, char *, unsigned int)
 This function parses a command and writes the parsing result into a C character array. More...
 
virtual void parse (const std::vector< std::string > &, std::vector< std::string > &)
 
virtual std::string query_perm (const std::string &)
 
virtual std::string query_range (const std::string &)
 
std::string query_version (const std::string &)
 
std::string query_id (const std::string &)
 
std::string query_subst (const std::string &)
 
std::string query_addsubst (const std::string &)
 
std::string query_help (const std::string &)
 
std::string query_cmds (const std::string &)
 
void set_node_id (const std::string &)
 Set the identification string of this parser node. More...
 
void set_help (const std::string &)
 Set the help comment of a variable or parser. More...
 
void add_parent_on_insert (parser_t *, std::string)
 
void rm_parent_on_remove (parser_t *)
 
const std::string & fullname () const
 Return the full dot-separated path name of this parser node in the openMHA configuration tree. More...
 

Public Attributes

MHAParser::int_t port
 
- Public Attributes inherited from MHAParser::base_t
MHAEvents::emitter_t writeaccess
 Event emitted on write access. More...
 
MHAEvents::emitter_t valuechanged
 Event emitted if the value has changed. More...
 
MHAEvents::emitter_t readaccess
 Event emitted on read access. More...
 
MHAEvents::emitter_t prereadaccess
 Event emitted on read access, before the data field is accessed. More...
 

Private Attributes

std::shared_ptr< tcp_server_ttcpserver
 
std::string ack_ok
 
std::string ack_fail
 
std::string logfile
 
unsigned short announce_port
 
bool b_interactive
 
MHAParser::int_mon_t pid_mon
 

Additional Inherited Members

- Protected Member Functions inherited from MHAParser::parser_t
std::string op_subparse (expression_t &)
 
std::string op_setval (expression_t &)
 
std::string op_query (expression_t &)
 
std::string query_type (const std::string &)
 
std::string query_dump (const std::string &)
 
std::string query_entries (const std::string &)
 
std::string query_readfile (const std::string &)
 
std::string query_savefile (const std::string &)
 
std::string query_savefile_compact (const std::string &)
 
std::string query_savemons (const std::string &)
 
std::string query_val (const std::string &)
 
std::string query_listids (const std::string &)
 
void set_id_string (const std::string &)
 
bool has_entry (const std::string &)
 
- Protected Member Functions inherited from MHAParser::base_t
void activate_query (const std::string &, query_t)
 
void notify ()
 
- Protected Attributes inherited from fw_t
io_lib_tio_lib
 
int proc_error
 
int io_error
 
- Protected Attributes inherited from MHAParser::base_t
query_map_t queries
 
bool data_is_initialized
 

Detailed Description

MHA Framework listening on TCP port for commands.

Constructor & Destructor Documentation

◆ mhaserver_t()

mhaserver_t::mhaserver_t ( const std::string &  ao,
const std::string &  af,
const std::string &  lf,
bool  b_interactive_ 
)
Parameters
aoAcknowledgement string at end of successful command responses
afAcknowledgement string at end of failed command responses
lfFile system path of file to use as log file. MHA appends.

◆ ~mhaserver_t()

mhaserver_t::~mhaserver_t ( )

Member Function Documentation

◆ on_received_line()

std::string mhaserver_t::on_received_line ( const std::string &  line)
virtual

A line of text was received from network client.

◆ acceptor_started()

void mhaserver_t::acceptor_started ( )
virtual

Notification: "TCP port is open".

◆ send_port_announcement()

void mhaserver_t::send_port_announcement ( )
virtual

sends an announcement which port this MHA is listening on to the creator of the process.

See command line option –announce

◆ start_stdin_thread()

void mhaserver_t::start_stdin_thread ( )
virtual

Starts a separate thread that reads lines from stdin and forwards these lines over TCP to the MHA configuration thread which multiplexes multiple TCP connections.

Enables users to type mha configuration language commands directly into the terminal where MHA was started, without the need to use third-party tools like nc or putty.

◆ set_announce_port()

void mhaserver_t::set_announce_port ( unsigned short  announce_port)
virtual

If set to nonzero, the spawning process has asked to be notified of the TCP port used by this process.

◆ logstring()

void mhaserver_t::logstring ( const std::string &  s)
inline

Log a message to log file.

◆ run()

int mhaserver_t::run ( unsigned short  port,
const std::string &  _interface 
)

Accept network connections and act on commands.

Calls acceptor_started() when the TCP port is opened. Calls on_received_line for every line received.

Returns
exit code that can be used as process exit code

Member Data Documentation

◆ tcpserver

std::shared_ptr<tcp_server_t> mhaserver_t::tcpserver
private

◆ ack_ok

std::string mhaserver_t::ack_ok
private

◆ ack_fail

std::string mhaserver_t::ack_fail
private

◆ logfile

std::string mhaserver_t::logfile
private

◆ announce_port

unsigned short mhaserver_t::announce_port
private

◆ b_interactive

bool mhaserver_t::b_interactive
private

◆ pid_mon

MHAParser::int_mon_t mhaserver_t::pid_mon
private

◆ port

MHAParser::int_t mhaserver_t::port

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