- added command line option -v to daemon to return current version

- set current daemon version to bondagit-1.0
- added HTTP API to return current daemon version and updated documentation
- added diplay of current daemon version in WebUI Config page
This commit is contained in:
Andrea Bondavalli 2021-02-25 18:00:01 +01:00
parent 0cda7c7ad3
commit 399e22216a
6 changed files with 72 additions and 10 deletions

View File

@ -30,6 +30,13 @@ All operations returns HTTP *200* status code in case of success and HTTP *4xx*
In case of failure the server returns a **text/plain** content type with the category and a description of the error occurred. In case of failure the server returns a **text/plain** content type with the category and a description of the error occurred.
**_NOTE:_** At present the embedded HTTP server doesn't implement neither HTTPS nor user authentication. **_NOTE:_** At present the embedded HTTP server doesn't implement neither HTTPS nor user authentication.
### Get Daemon Version ###
* **URL** /api/version
* **Method** GET
* **URL Params** none
* **Body Type** application/json
* **Body** [Version params](#version)
### Get Daemon Configuration ### ### Get Daemon Configuration ###
* **URL** /api/config * **URL** /api/config
* **Method** GET * **Method** GET
@ -142,6 +149,18 @@ In case of failure the server returns a **text/plain** content type with the cat
## HTTP REST API structures ## ## HTTP REST API structures ##
### JSON Version<a name="version"></a> ###
Example
{
"version:" "bondagit-1.0"
}
where:
> **version**
> JSON string specifying the daemon version.
### JSON Config<a name="config"></a> ### ### JSON Config<a name="config"></a> ###
Example Example

View File

@ -23,6 +23,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "main.hpp"
#include "json.hpp" #include "json.hpp"
#include "log.hpp" #include "log.hpp"
#include "http_server.hpp" #include "http_server.hpp"
@ -98,6 +99,12 @@ bool HttpServer::init() {
set_headers(res); set_headers(res);
}); });
/* get version */
svr_.Get("/api/version", [&](const Request& req, Response& res) {
set_headers(res, "application/json");
res.body = "{ \"version\": \"" + get_version() + "\" }";
});
/* get config */ /* get config */
svr_.Get("/api/config", [&](const Request& req, Response& res) { svr_.Get("/api/config", [&](const Request& req, Response& res) {
set_headers(res, "application/json"); set_headers(res, "application/json");

View File

@ -35,6 +35,7 @@ namespace po = boost::program_options;
namespace postyle = boost::program_options::command_line_style; namespace postyle = boost::program_options::command_line_style;
namespace logging = boost::log; namespace logging = boost::log;
static std::string version("bondagit-1.0");
static std::atomic<bool> terminate = false; static std::atomic<bool> terminate = false;
void termination_handler(int signum) { void termination_handler(int signum) {
@ -47,14 +48,19 @@ bool is_terminated() {
return terminate.load(); return terminate.load();
} }
const std::string& get_version() {
return version;
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
int rc = EXIT_SUCCESS; int rc = EXIT_SUCCESS;
po::options_description desc("Options"); po::options_description desc("Options");
desc.add_options()( desc.add_options()
"config,c", po::value<std::string>()->default_value("/etc/daemon.conf"), ("version,v", "Print daemon version and exit")
"daemon configuration file")("http_port,p", po::value<int>(), ("config,c", po::value<std::string>()->default_value("/etc/daemon.conf"),
"HTTP server port")( "daemon configuration file")
"help,h", "Print this help message"); ("http_port,p", po::value<int>(), "HTTP server port")
("help,h", "Print this help message");
int unix_style = postyle::unix_style | postyle::short_allow_next; int unix_style = postyle::unix_style | postyle::short_allow_next;
po::variables_map vm; po::variables_map vm;
@ -67,6 +73,10 @@ int main(int argc, char* argv[]) {
po::notify(vm); po::notify(vm);
if (vm.count("version")) {
std::cout << version << '\n';
return EXIT_SUCCESS;
}
if (vm.count("help")) { if (vm.count("help")) {
std::cout << "USAGE: " << argv[0] << '\n' << desc << '\n'; std::cout << "USAGE: " << argv[0] << '\n' << desc << '\n';
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -21,5 +21,6 @@
#define _MAIN_HPP_ #define _MAIN_HPP_
bool is_terminated(); bool is_terminated();
const std::string& get_version();
#endif #endif

View File

@ -30,6 +30,7 @@ class Config extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
version: '',
httpPort: '', httpPort: '',
rtspPort: '', rtspPort: '',
rtspPortErr: false, rtspPortErr: false,
@ -57,7 +58,8 @@ class Config extends Component {
macAddr: '', macAddr: '',
ipAddr: '', ipAddr: '',
errors: 0, errors: 0,
isConfigLoading: false isConfigLoading: false,
isVersionLoading: false
}; };
this.onSubmit = this.onSubmit.bind(this); this.onSubmit = this.onSubmit.bind(this);
this.inputIsValid = this.inputIsValid.bind(this); this.inputIsValid = this.inputIsValid.bind(this);
@ -65,6 +67,16 @@ class Config extends Component {
componentDidMount() { componentDidMount() {
this.setState({isConfigLoading: true}); this.setState({isConfigLoading: true});
this.setState({isVersionLoading: true});
RestAPI.getVersion()
.then(response => response.json())
.then(
data => this.setState(
{
version: data.version,
isVersionLoading: false
}))
.catch(err => this.setState({isVersionLoading: false}));
RestAPI.getConfig() RestAPI.getConfig()
.then(response => response.json()) .then(response => response.json())
.then( .then(
@ -105,6 +117,7 @@ class Config extends Component {
!this.state.rtspPortErr && !this.state.rtspPortErr &&
!this.state.sapIntervalErr && !this.state.sapIntervalErr &&
!this.state.syslogServerErr && !this.state.syslogServerErr &&
!this.state.isVersionLoading &&
!this.state.isConfigLoading; !this.state.isConfigLoading;
} }
@ -130,6 +143,14 @@ class Config extends Component {
render() { render() {
return ( return (
<div className='config'> <div className='config'>
{this.state.isVersionLoading ? <Loader/> : <h3>Version</h3>}
<table><tbody>
<tr>
<th align="left"> <label>Daemon</label> </th>
<th align="left"> <input value={this.state.version} disabled/> </th>
</tr>
</tbody></table>
<br/>
{this.state.isConfigLoading ? <Loader/> : <h3>Audio Config</h3>} {this.state.isConfigLoading ? <Loader/> : <h3>Audio Config</h3>}
<table><tbody> <table><tbody>
<tr> <tr>
@ -140,10 +161,6 @@ class Config extends Component {
<th align="left"> <label>TIC frame size @1FS (samples) </label> </th> <th align="left"> <label>TIC frame size @1FS (samples) </label> </th>
<th align="left"> <th align="left">
<select value={this.state.ticFrameSizeAt1fs} onChange={e => this.setState({ticFrameSizeAt1fs: e.target.value})}> <select value={this.state.ticFrameSizeAt1fs} onChange={e => this.setState({ticFrameSizeAt1fs: e.target.value})}>
<option value="6">6 - 125&mu;s</option>
<option value="12">12 - 250&mu;s</option>
<option value="16">16 - 333&mu;s</option>
<option value="24">24 - 500&mu;s</option>
<option value="48">48 - 1ms</option> <option value="48">48 - 1ms</option>
<option value="96">96 - 2ms</option> <option value="96">96 - 2ms</option>
<option value="192">192 - 4ms</option> <option value="192">192 - 4ms</option>

View File

@ -21,6 +21,7 @@
import { toast } from 'react-toastify'; import { toast } from 'react-toastify';
const API = '/api'; const API = '/api';
const version = '/version';
const config = '/config'; const config = '/config';
const streams = '/streams'; const streams = '/streams';
const sources = '/sources'; const sources = '/sources';
@ -69,6 +70,13 @@ export default class RestAPI {
); );
} }
static getVersion() {
return this.doFetch(version).catch(err => {
toast.error('Config get failed: ' + err.message);
return Promise.reject(Error(err.message));
});
}
static getConfig() { static getConfig() {
return this.doFetch(config).catch(err => { return this.doFetch(config).catch(err => {
toast.error('Config get failed: ' + err.message); toast.error('Config get failed: ' + err.message);