...
This commit is contained in:
parent
2b353ab839
commit
1806ffda99
@ -8,30 +8,51 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
|
||||||
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
find_package(spdlog REQUIRED)
|
# find_package(spdlog REQUIRED)
|
||||||
|
find_package(spdlog CONFIG)
|
||||||
|
|
||||||
find_package(CFITSIO REQUIRED)
|
find_package(CFITSIO REQUIRED)
|
||||||
find_package(XCLIB REQUIRED)
|
find_package(XCLIB REQUIRED)
|
||||||
|
find_package(cxxopts CONFIG)
|
||||||
|
|
||||||
|
|
||||||
set(RAPTOR_EAGLEV_LIB raptor_eaglev)
|
set(RAPTOR_EAGLEV_LIB raptor_eaglev)
|
||||||
add_library(${RAPTOR_EAGLEV_LIB} SHARED
|
|
||||||
|
option(STATIC_LIB "Create static '${RAPTOR_EAGLEV_LIB}' library" OFF)
|
||||||
|
|
||||||
|
set(RAPTOR_EAGLEV_LIB_SRC
|
||||||
raptor_eagle_ccd.h raptor_eagle_ccd.cpp
|
raptor_eagle_ccd.h raptor_eagle_ccd.cpp
|
||||||
raptor_eagle_cameralink.h
|
raptor_eagle_cameralink.h
|
||||||
raptor_eagle_exception.h
|
raptor_eagle_exception.h
|
||||||
raptor_eagle_acqproc.cpp)
|
raptor_eagle_acqproc.cpp)
|
||||||
|
|
||||||
# to activate spdlog-library support in ADC-library
|
if (STATIC_LIB)
|
||||||
target_compile_definitions(${RAPTOR_EAGLEV_LIB} PRIVATE USE_SPDLOG_LIBRARY)
|
add_library(${RAPTOR_EAGLEV_LIB} STATIC ${RAPTOR_EAGLEV_LIB_SRC})
|
||||||
# !!!!! TEMPORARY !!!!!
|
else()
|
||||||
target_include_directories(${RAPTOR_EAGLEV_LIB} PRIVATE "../ADC/")
|
add_library(${RAPTOR_EAGLEV_LIB} SHARED ${RAPTOR_EAGLEV_LIB_SRC})
|
||||||
target_include_directories(${RAPTOR_EAGLEV_LIB} PRIVATE ${XCLIB_INCLUDE_DIR})
|
# add_library(${RAPTOR_EAGLEV_LIB} SHARED
|
||||||
target_link_libraries(${RAPTOR_EAGLEV_LIB} PUBLIC Threads::Threads spdlog::spdlog_header_only ${XCLIB_LIBRARIES})
|
# raptor_eagle_ccd.h raptor_eagle_ccd.cpp
|
||||||
|
# raptor_eagle_cameralink.h
|
||||||
|
# raptor_eagle_exception.h
|
||||||
|
# raptor_eagle_acqproc.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(RaptorEagleV main.cpp)
|
# to activate spdlog-library support in ADC-library
|
||||||
|
# target_compile_definitions(${RAPTOR_EAGLEV_LIB} PRIVATE USE_ASIO_LIBRARY USE_SPDLOG_LIBRARY USE_OPENSSL_WITH_ASIO)
|
||||||
|
target_compile_definitions(${RAPTOR_EAGLEV_LIB} PUBLIC USE_ASIO_LIBRARY USE_SPDLOG_LIBRARY)
|
||||||
|
|
||||||
|
# !!!!! TEMPORARY !!!!!
|
||||||
|
target_include_directories(${RAPTOR_EAGLEV_LIB} PUBLIC "../ADC/")
|
||||||
|
target_include_directories(${RAPTOR_EAGLEV_LIB} PUBLIC ${XCLIB_INCLUDE_DIR} ${CFITSIO_INCLUDE_DIR})
|
||||||
|
target_link_libraries(${RAPTOR_EAGLEV_LIB} PUBLIC Threads::Threads spdlog::spdlog_header_only ${XCLIB_LIBRARIES} ${CFITSIO_LIBRARY})
|
||||||
|
|
||||||
|
|
||||||
|
set(RAPTOR_EAGLEV_SERVER raptor_eaglev_server)
|
||||||
|
add_executable(${RAPTOR_EAGLEV_SERVER} raptor_eaglev_server.cpp)
|
||||||
|
target_link_libraries(${RAPTOR_EAGLEV_SERVER} PUBLIC ${RAPTOR_EAGLEV_LIB} cxxopts::cxxopts)
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
install(TARGETS RaptorEagleV
|
install(TARGETS ${RAPTOR_EAGLEV_LIB}
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
)
|
)
|
||||||
|
|||||||
157
raptor_eaglev_server.cpp
Normal file
157
raptor_eaglev_server.cpp
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
#include <common/adc_spdlog.h>
|
||||||
|
#include <net/adc_netproto.h>
|
||||||
|
#include <net/asio/adc_device_netserver_asio.h>
|
||||||
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
|
#include <spdlog/sinks/null_sink.h>
|
||||||
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
|
#include <cxxopts.hpp>
|
||||||
|
|
||||||
|
#include "raptor_eagle_ccd.h"
|
||||||
|
|
||||||
|
typedef adc::impl::AdcDeviceNetServerASIO<std::string_view, adc::AdcSpdlogLogger> server_t;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int exit_code = 0;
|
||||||
|
asio::io_context ctx;
|
||||||
|
std::vector<std::thread> threads;
|
||||||
|
std::size_t Nthreads = 2;
|
||||||
|
|
||||||
|
/* COMMANDLINE OPTS */
|
||||||
|
cxxopts::Options options(argv[0], "ADC-library test device network server (ASIO implementation)\n");
|
||||||
|
|
||||||
|
options.allow_unrecognised_options();
|
||||||
|
|
||||||
|
options.add_options()("h,help", "Print usage");
|
||||||
|
options.add_options()("D", "Daemonize server", cxxopts::value<bool>()->default_value("false"));
|
||||||
|
|
||||||
|
options.add_options()("l,log", "Log filename (use stdout and stderr for standard output and error stream)",
|
||||||
|
cxxopts::value<std::string>()->default_value(""));
|
||||||
|
|
||||||
|
options.add_options()("level", "Log level (see SPDLOG package description for valid values)",
|
||||||
|
cxxopts::value<std::string>()->default_value("info"));
|
||||||
|
|
||||||
|
options.add_options()("t,threads", "Number of threads used by the server",
|
||||||
|
cxxopts::value<uint>()->default_value(std::to_string(Nthreads)));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
options.add_options()(
|
||||||
|
"endpoints",
|
||||||
|
"endpoints server will be listening for. For 'local' endpoint the '@' symbol at the beginning of the path "
|
||||||
|
"means "
|
||||||
|
"abstract namespace socket.",
|
||||||
|
cxxopts::value<std::vector<std::string>>()->default_value("local://stream/@RAPTOR_EAGLEV_SERVER"));
|
||||||
|
|
||||||
|
|
||||||
|
options.positional_help("[endpoint0] [enpoint1] ... [endpointN]");
|
||||||
|
options.parse_positional({"endpoints"});
|
||||||
|
|
||||||
|
try {
|
||||||
|
auto opt_result = options.parse(argc, argv);
|
||||||
|
|
||||||
|
if (opt_result["help"].count()) {
|
||||||
|
std::cout << options.help();
|
||||||
|
std::cout << "\n";
|
||||||
|
std::cout << "[endpoint0] [enpoint1] ... [endpointN] - endpoints server will be listening for. For 'local' "
|
||||||
|
"endpoint the '@' symbol at the beginning of the path "
|
||||||
|
"means abstract namespace socket."
|
||||||
|
<< "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
auto logname = opt_result["log"].as<std::string>();
|
||||||
|
|
||||||
|
auto logger = [&logname]() {
|
||||||
|
if (logname == "stdout") {
|
||||||
|
return spdlog::stdout_color_mt("console");
|
||||||
|
} else if (logname == "stderr") {
|
||||||
|
return spdlog::stderr_color_mt("stderr");
|
||||||
|
} else if (logname == "") {
|
||||||
|
return spdlog::null_logger_mt("RAPTOR_EAGLEV_SERVER_NULL_LOGGER");
|
||||||
|
} else {
|
||||||
|
return spdlog::basic_logger_mt(logname, logname);
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
std::string level_str = opt_result["level"].as<std::string>();
|
||||||
|
|
||||||
|
auto log_level = [&level_str]() {
|
||||||
|
if (level_str == "TRACE") {
|
||||||
|
return spdlog::level::trace;
|
||||||
|
} else if (level_str == "DEBUG") {
|
||||||
|
return spdlog::level::debug;
|
||||||
|
} else if (level_str == "INFO") {
|
||||||
|
return spdlog::level::info;
|
||||||
|
} else if (level_str == "WARN") {
|
||||||
|
return spdlog::level::warn;
|
||||||
|
} else if (level_str == "ERROR") {
|
||||||
|
return spdlog::level::err;
|
||||||
|
} else if (level_str == "CRITICAL") {
|
||||||
|
return spdlog::level::critical;
|
||||||
|
} else if (level_str == "OFF") {
|
||||||
|
return spdlog::level::off;
|
||||||
|
}
|
||||||
|
|
||||||
|
return spdlog::level::info;
|
||||||
|
}();
|
||||||
|
|
||||||
|
logger->set_level(log_level);
|
||||||
|
|
||||||
|
logger->flush_on(spdlog::level::trace);
|
||||||
|
|
||||||
|
|
||||||
|
asio::io_context io_ctx;
|
||||||
|
|
||||||
|
asio::signal_set signals(io_ctx, SIGINT, SIGTERM);
|
||||||
|
signals.async_wait([&](std::error_code, int) { io_ctx.stop(); });
|
||||||
|
|
||||||
|
|
||||||
|
RaptorEagleCCD ccd_device(logger);
|
||||||
|
|
||||||
|
server_t server("RAPTOR EAGLE V CCD SERVER", io_ctx, logger);
|
||||||
|
server.setupSignals();
|
||||||
|
|
||||||
|
server.addDevice(&ccd_device);
|
||||||
|
|
||||||
|
auto epnt = opt_result["endpoints"].as<std::vector<std::string>>();
|
||||||
|
|
||||||
|
for (auto& ep : epnt) {
|
||||||
|
adc::AdcEndpoint epn(ep);
|
||||||
|
if (epn.isValid()) {
|
||||||
|
if (epn.isLocalSeqpacket() || epn.isLocalStream()) {
|
||||||
|
if (epn.path()[0] == '@') { // replace '@' to '\0' (use of UNIX abstract namespace)
|
||||||
|
auto it = std::ranges::find(ep, '@');
|
||||||
|
*it = '\0';
|
||||||
|
epn = adc::AdcEndpoint(ep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server.start<adc::AdcStopSeqSessionProto<>>(epn);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
std::cerr << "Unrecognized endpoint: '" << ep << "'! Ignore!\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt_result["D"].as<bool>()) {
|
||||||
|
// server.daemonize();
|
||||||
|
}
|
||||||
|
|
||||||
|
io_ctx.run();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (const cxxopts::exceptions::exception& ex) {
|
||||||
|
std::cerr << "\nAn error occured while parsing input options: " << ex.what() << "\n";
|
||||||
|
return 127;
|
||||||
|
} catch (const std::system_error& ex) {
|
||||||
|
std::cerr << "\nAn error ocured: " << ex.what() << "\n";
|
||||||
|
std::cerr << "Category: " << ex.code().category().name() << "; message: " << ex.code().message() << "\n";
|
||||||
|
return 128;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user