Jazz 1.25.+
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
jazz_main::HttpServer Class Reference

HttpServer: The http server is also a Service. More...

#include <server.h>

Inheritance diagram for jazz_main::HttpServer:
jazz_elements::Service

Public Member Functions

 HttpServer (pLogger a_logger, pConfigFile a_config)
 
virtual pChar const id ()
 
StatusCode start (pSignalHandler p_sig_handler, pMHD_Daemon &p_daemon, MHD_AccessHandlerCallback dh, Channels &channels)
 
StatusCode shut_down ()
 
- Public Member Functions inherited from jazz_elements::Service
 Service (pLogger a_logger, pConfigFile a_config)
 
virtual StatusCode start ()
 A simple start()/shut_down() interface (Restart is: shut_down(TRUE):start())
 
void log (int loglevel, const char *message)
 
void log_printf (int loglevel, const char *fmt,...)
 
bool get_conf_key (const char *key, int &value)
 
bool get_conf_key (const char *key, double &value)
 
bool get_conf_key (const char *key, std::string &value)
 

Private Attributes

int http_port = 0
 The port the server is listening to.
 
MHD_OptionItem server_options [9]
 Variadic parameter MHD_OPTION_ARRAY, server_options, MHD_OPTION_END in MHD_start_daemon()
 

Additional Inherited Members

- Data Fields inherited from jazz_elements::Service
pLogger p_log
 The logger.
 
pConfigFile p_conf
 The configuration file.
 

Detailed Description

HttpServer: The http server is also a Service.

Constructor & Destructor Documentation

◆ HttpServer()

jazz_main::HttpServer::HttpServer ( pLogger  a_logger,
pConfigFile  a_config 
)

Constructor for the HttpServer service.

Parameters
a_loggerA pointer to the Logger object.
a_configA pointer to the ConfigFile object.

Member Function Documentation

◆ id()

pChar const jazz_main::HttpServer::id ( )
virtual

Return object ID.

Returns
A string identifying the object that is especially useful to track uplifts and versions.

Reimplemented from jazz_elements::Service.

◆ start()

StatusCode jazz_main::HttpServer::start ( pSignalHandler  p_sig_handler,
pMHD_Daemon p_daemon,
MHD_AccessHandlerCallback  dh,
Channels channels 
)

Start the Jazz server.

Parameters
p_sig_handlerA function (of type pSignalHandler) that will be called when the process receives a SIGTERM signal.
p_daemonReturns by reference the pointer that will be used to control the MHD_Daemon.
dhThe address of the MHD_AccessHandlerCallback (server callback).
channelsThe instance of Channel to find out the configuration port.
Returns
On failure, EXIT_FAILURE. On success, the thread forks and only the parent process returns EXIT_SUCCESS, the child does not return. The application is stopped when callback signalHandler_SIGTERM exits with EXIT_SUCCESS if shutting all services was successful or with EXIT_FAILURE if not. On failure, the caller is responsible of stopping all started services (see jazz_main.cpp).

Starting logic:

  1. Get all the MHD server config settings via get_conf_key()

    The default config file is JAZZ_DEFAULT_CONFIG_PATH but that can be changed via command line argument (see jazz_main.cpp).

  2. Registers the signal handlers for SIGTERM. (See argument p_sig_handler)
  3. Forks (== The parent exits with EXIT_SUCCESS, the child continues to call MHD_start_daemon().)
  4. Calls MHD_start_daemon()

    Then calls setsid() This creates a new session if the calling process is not a process group leader. The calling process is the leader of the new session, the process group leader of the new process group, and has no controlling terminal.

    And sleeps forever! (Remember, it is the child of the original caller who exited with EXIT_SUCCESS.)

◆ shut_down()

StatusCode jazz_main::HttpServer::shut_down ( )
virtual

Server closing method.

Returns
SERVICE_NO_ERROR if successful, an error code otherwise.

This overrides the Service shut_down() just to set the return to SERVICE_NO_ERROR.

The true closing mechanism is a: MHD_stop_daemon (Jazz_MHD_Daemon); done by the signalHandler_SIGTERM() callback that captures SIGTERM.

Reimplemented from jazz_elements::Service.


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