Merge pull request #3119 from Carbenium/fmt
Add fmt library for type-safe string formatting
This commit is contained in:
commit
90d930c7c3
|
@ -6,7 +6,7 @@ task:
|
||||||
- image_family: freebsd-13-0
|
- image_family: freebsd-13-0
|
||||||
|
|
||||||
prepare_script:
|
prepare_script:
|
||||||
- pkg install -yq git cmake pkgconf jpeg-turbo mysql80-client ffmpeg libvncserver libjwt catch p5-DBI p5-DBD-mysql p5-Date-Manip p5-Test-LWP-UserAgent p5-Sys-Mmap v4l_compat
|
- pkg install -yq git cmake pkgconf jpeg-turbo mysql80-client ffmpeg libvncserver libjwt libfmt catch p5-DBI p5-DBD-mysql p5-Date-Manip p5-Test-LWP-UserAgent p5-Sys-Mmap v4l_compat
|
||||||
|
|
||||||
configure_script:
|
configure_script:
|
||||||
- git submodule update --init --recursive
|
- git submodule update --init --recursive
|
||||||
|
|
|
@ -52,9 +52,11 @@ jobs:
|
||||||
git submodule init
|
git submodule init
|
||||||
git submodule update --init --recursive
|
git submodule update --init --recursive
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
|
|
||||||
sudo apt-get install libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libjwt-gnutls-dev
|
sudo apt-get install libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libjwt-gnutls-dev
|
||||||
sudo apt-get install libbz2-dev libcurl4-gnutls-dev libjpeg-turbo8-dev libturbojpeg0-dev
|
sudo apt-get install libbz2-dev libcurl4-gnutls-dev libjpeg-turbo8-dev libturbojpeg0-dev
|
||||||
sudo apt-get install default-libmysqlclient-dev libpcre3-dev libpolkit-gobject-1-dev libv4l-dev libvlc-dev
|
sudo apt-get install default-libmysqlclient-dev libpcre3-dev libpolkit-gobject-1-dev libv4l-dev libvlc-dev libfmt-dev
|
||||||
|
|
||||||
sudo apt-get install libdate-manip-perl libdbd-mysql-perl libphp-serialization-perl libsys-mmap-perl
|
sudo apt-get install libdate-manip-perl libdbd-mysql-perl libphp-serialization-perl libsys-mmap-perl
|
||||||
sudo apt-get install libwww-perl libdata-uuid-perl libssl-dev libcrypt-eksblowfish-perl libdata-entropy-perl
|
sudo apt-get install libwww-perl libdata-uuid-perl libssl-dev libcrypt-eksblowfish-perl libdata-entropy-perl
|
||||||
|
|
||||||
|
|
|
@ -536,6 +536,8 @@ else()
|
||||||
set(HAVE_RTSP_SERVER 0)
|
set(HAVE_RTSP_SERVER 0)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
find_package(fmt REQUIRED)
|
||||||
|
|
||||||
#
|
#
|
||||||
# *** END OF LIBRARY CHECKS ***
|
# *** END OF LIBRARY CHECKS ***
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ BuildRequires: libv4l-devel
|
||||||
BuildRequires: desktop-file-utils
|
BuildRequires: desktop-file-utils
|
||||||
BuildRequires: gzip
|
BuildRequires: gzip
|
||||||
BuildRequires: zlib-devel
|
BuildRequires: zlib-devel
|
||||||
|
BuildRequires: fmt-devel
|
||||||
|
|
||||||
# ZoneMinder looks for and records the location of the ffmpeg binary during build
|
# ZoneMinder looks for and records the location of the ffmpeg binary during build
|
||||||
BuildRequires: ffmpeg
|
BuildRequires: ffmpeg
|
||||||
|
@ -141,6 +142,7 @@ Requires: perl(Net::FTP)
|
||||||
Requires: perl(LWP::Protocol::https)
|
Requires: perl(LWP::Protocol::https)
|
||||||
Requires: ca-certificates
|
Requires: ca-certificates
|
||||||
Requires: zip
|
Requires: zip
|
||||||
|
Requires: fmt
|
||||||
%{?systemd_requires}
|
%{?systemd_requires}
|
||||||
|
|
||||||
Requires(post): %{_bindir}/gpasswd
|
Requires(post): %{_bindir}/gpasswd
|
||||||
|
|
|
@ -29,8 +29,10 @@ Build-Depends: debhelper (>= 11), sphinx-doc, python3-sphinx, dh-linktree, dh-ap
|
||||||
,libcrypt-eksblowfish-perl
|
,libcrypt-eksblowfish-perl
|
||||||
,libdata-entropy-perl
|
,libdata-entropy-perl
|
||||||
,libvncserver-dev
|
,libvncserver-dev
|
||||||
|
,libfmt-dev
|
||||||
,libjwt-gnutls-dev|libjwt-dev
|
,libjwt-gnutls-dev|libjwt-dev
|
||||||
,libgsoap-dev
|
,libgsoap-dev
|
||||||
|
|
||||||
Standards-Version: 4.5.0
|
Standards-Version: 4.5.0
|
||||||
Homepage: https://www.zoneminder.com/
|
Homepage: https://www.zoneminder.com/
|
||||||
|
|
||||||
|
@ -74,8 +76,10 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}
|
||||||
,libcrypt-eksblowfish-perl
|
,libcrypt-eksblowfish-perl
|
||||||
,libdata-entropy-perl
|
,libdata-entropy-perl
|
||||||
,libvncclient1|libvncclient0
|
,libvncclient1|libvncclient0
|
||||||
|
,libfmt
|
||||||
,libjwt-gnutls0|libjwt0
|
,libjwt-gnutls0|libjwt0
|
||||||
,libgsoap-2.8.104|libgsoap-2.8.91|libgsoap-2.8.75|libgsoap-2.8.60|libgsoap10
|
,libgsoap-2.8.104|libgsoap-2.8.91|libgsoap-2.8.75|libgsoap-2.8.60|libgsoap10
|
||||||
|
|
||||||
Recommends: ${misc:Recommends}
|
Recommends: ${misc:Recommends}
|
||||||
,libapache2-mod-php | php-fpm
|
,libapache2-mod-php | php-fpm
|
||||||
,default-mysql-server | mariadb-server | virtual-mysql-server
|
,default-mysql-server | mariadb-server | virtual-mysql-server
|
||||||
|
|
|
@ -192,6 +192,7 @@ target_link_libraries(zmc
|
||||||
PRIVATE
|
PRIVATE
|
||||||
zm-core-interface
|
zm-core-interface
|
||||||
zm
|
zm
|
||||||
|
fmt::fmt
|
||||||
${ZM_EXTRA_LIBS}
|
${ZM_EXTRA_LIBS}
|
||||||
${CMAKE_DL_LIBS})
|
${CMAKE_DL_LIBS})
|
||||||
|
|
||||||
|
@ -213,6 +214,7 @@ target_link_libraries(zmbenchmark
|
||||||
PRIVATE
|
PRIVATE
|
||||||
zm-core-interface
|
zm-core-interface
|
||||||
zm
|
zm
|
||||||
|
fmt::fmt
|
||||||
${ZM_EXTRA_LIBS}
|
${ZM_EXTRA_LIBS}
|
||||||
${CMAKE_DL_LIBS})
|
${CMAKE_DL_LIBS})
|
||||||
|
|
||||||
|
|
|
@ -547,14 +547,14 @@ void Logger::logPrint(bool hex, const char *filepath, int line, int level, const
|
||||||
}
|
}
|
||||||
} // end logPrint
|
} // end logPrint
|
||||||
|
|
||||||
void logInit(const char *name, const Logger::Options &options) {
|
void logInit(const std::string &id, const Logger::Options &options) {
|
||||||
if (Logger::smInstance) {
|
if (Logger::smInstance) {
|
||||||
delete Logger::smInstance;
|
delete Logger::smInstance;
|
||||||
Logger::smInstance = nullptr;
|
Logger::smInstance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::smInstance = new Logger();
|
Logger::smInstance = new Logger();
|
||||||
Logger::smInstance->initialise(name, options);
|
Logger::smInstance->initialise(id, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logTerm() {
|
void logTerm() {
|
||||||
|
|
|
@ -137,7 +137,7 @@ private:
|
||||||
static void usrHandler(int sig);
|
static void usrHandler(int sig);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend void logInit(const char *name, const Options &options);
|
friend void logInit(const std::string &id, const Options &options);
|
||||||
friend void logTerm();
|
friend void logTerm();
|
||||||
|
|
||||||
static Logger *fetch() {
|
static Logger *fetch() {
|
||||||
|
@ -182,7 +182,7 @@ private:
|
||||||
...) __attribute__((format(printf, 6, 7)));
|
...) __attribute__((format(printf, 6, 7)));
|
||||||
};
|
};
|
||||||
|
|
||||||
void logInit(const char *name, const Logger::Options &options=Logger::Options());
|
void logInit(const std::string &id, const Logger::Options &options=Logger::Options());
|
||||||
void logTerm();
|
void logTerm();
|
||||||
inline const std::string &logId() {
|
inline const std::string &logId() {
|
||||||
return Logger::fetch()->id();
|
return Logger::fetch()->id();
|
||||||
|
|
18
src/zmc.cpp
18
src/zmc.cpp
|
@ -63,6 +63,7 @@ possible, this should run at more or less constant speed.
|
||||||
#include "zm_signal.h"
|
#include "zm_signal.h"
|
||||||
#include "zm_time.h"
|
#include "zm_time.h"
|
||||||
#include "zm_utils.h"
|
#include "zm_utils.h"
|
||||||
|
#include <fmt/format.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
void Usage() {
|
void Usage() {
|
||||||
|
@ -168,24 +169,24 @@ int main(int argc, char *argv[]) {
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char log_id_string[32] = "";
|
std::string logId;
|
||||||
if ( device[0] ) {
|
if ( device[0] ) {
|
||||||
const char *slash_ptr = strrchr(device, '/');
|
const char *slash_ptr = strrchr(device, '/');
|
||||||
snprintf(log_id_string, sizeof(log_id_string), "zmc_d%s", slash_ptr?slash_ptr+1:device);
|
logId = fmt::format("zmc_d{}", slash_ptr ? slash_ptr + 1 : device);
|
||||||
} else if ( host[0] ) {
|
} else if ( host[0] ) {
|
||||||
snprintf(log_id_string, sizeof(log_id_string), "zmc_h%s", host);
|
logId = fmt::format("zmc_h{}", host);
|
||||||
} else if ( file[0] ) {
|
} else if ( file[0] ) {
|
||||||
const char *slash_ptr = strrchr(file, '/');
|
const char *slash_ptr = strrchr(file, '/');
|
||||||
snprintf(log_id_string, sizeof(log_id_string), "zmc_f%s", slash_ptr?slash_ptr+1:file);
|
logId = fmt::format("zmc_f{}", slash_ptr ? slash_ptr + 1 : file);
|
||||||
} else {
|
} else {
|
||||||
snprintf(log_id_string, sizeof(log_id_string), "zmc_m%d", monitor_id);
|
logId = fmt::format("zmc_m{}", monitor_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
logInit(log_id_string);
|
logInit(logId);
|
||||||
zmLoadStaticConfig();
|
zmLoadStaticConfig();
|
||||||
zmDbConnect();
|
zmDbConnect();
|
||||||
zmLoadDBConfig();
|
zmLoadDBConfig();
|
||||||
logInit(log_id_string);
|
logInit(logId);
|
||||||
|
|
||||||
HwCapsDetect();
|
HwCapsDetect();
|
||||||
|
|
||||||
|
@ -353,8 +354,7 @@ int main(int argc, char *argv[]) {
|
||||||
monitor->Reload();
|
monitor->Reload();
|
||||||
}
|
}
|
||||||
logTerm();
|
logTerm();
|
||||||
logInit(log_id_string);
|
logInit(logId);
|
||||||
|
|
||||||
zm_reload = false;
|
zm_reload = false;
|
||||||
} // end if zm_reload
|
} // end if zm_reload
|
||||||
} // end while ! zm_terminate outer connection loop
|
} // end while ! zm_terminate outer connection loop
|
||||||
|
|
12
src/zms.cpp
12
src/zms.cpp
|
@ -24,6 +24,8 @@
|
||||||
#include "zm_monitorstream.h"
|
#include "zm_monitorstream.h"
|
||||||
#include "zm_eventstream.h"
|
#include "zm_eventstream.h"
|
||||||
#include "zm_fifo_stream.h"
|
#include "zm_fifo_stream.h"
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -83,8 +85,7 @@ int main(int argc, const char *argv[], char **envp) {
|
||||||
nph = true;
|
nph = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char log_id_string[32] = "zms";
|
logInit("zms");
|
||||||
logInit(log_id_string);
|
|
||||||
zmLoadStaticConfig();
|
zmLoadStaticConfig();
|
||||||
zmDbConnect();
|
zmDbConnect();
|
||||||
zmLoadDBConfig();
|
zmLoadDBConfig();
|
||||||
|
@ -191,12 +192,13 @@ int main(int argc, const char *argv[], char **envp) {
|
||||||
} // end if possible parameter names
|
} // end if possible parameter names
|
||||||
} // end foreach parm
|
} // end foreach parm
|
||||||
|
|
||||||
|
std::string logId;
|
||||||
if ( monitor_id ) {
|
if ( monitor_id ) {
|
||||||
snprintf(log_id_string, sizeof(log_id_string), "zms_m%d", monitor_id);
|
logId = fmt::format("zms_m{}", monitor_id);
|
||||||
} else {
|
} else {
|
||||||
snprintf(log_id_string, sizeof(log_id_string), "zms_e%" PRIu64, event_id);
|
logId = fmt::format("zms_e{}", event_id);
|
||||||
}
|
}
|
||||||
logInit(log_id_string);
|
logInit(logId);
|
||||||
|
|
||||||
if ( config.opt_use_auth ) {
|
if ( config.opt_use_auth ) {
|
||||||
User *user = nullptr;
|
User *user = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue