Skip to content

Commit

Permalink
cmake: use shared library internally
Browse files Browse the repository at this point in the history
  • Loading branch information
marenz2569 committed Jan 5, 2025
1 parent 3a8ac3d commit 5ed028c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 17)

option(NIX_BUILD "Is CMake called by a nix build?" OFF)

add_library(tetra-decoder-library
add_library(tetra-decoder-library SHARED
src/decoder.cpp
src/bit_stream_decoder.cpp
src/iq_stream_decoder.cpp
Expand Down Expand Up @@ -74,6 +74,7 @@ target_link_libraries(tetra-decoder-library ZLIB::ZLIB fmt::fmt nlohmann_json::n
target_link_libraries(tetra-decoder tetra-decoder-library)
target_link_libraries(tetra-viterbi viterbi)

install(TARGETS tetra-decoder-library DESTINATION lib)
install(TARGETS tetra-decoder DESTINATION bin)
install(TARGETS tetra-puncturing DESTINATION bin)
install(TARGETS tetra-viterbi DESTINATION bin)
Expand Down
3 changes: 2 additions & 1 deletion include/decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class Decoder {
const std::shared_ptr<PrometheusExporter>& prometheus_exporter);
~Decoder();

void main_loop();
/// \returns true if we should abort
[[nodiscard]] auto main_loop() -> bool;

private:
/// This flag is set when the program should termiate. It is pass down to the next stage in the chain when
Expand Down
3 changes: 0 additions & 3 deletions include/signal_handler.hpp

This file was deleted.

14 changes: 6 additions & 8 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

#include "decoder.hpp"
#include "signal_handler.hpp"
#include <arpa/inet.h>
#include <cassert>
#include <complex>
Expand Down Expand Up @@ -85,28 +84,25 @@ Decoder::~Decoder() {
termination_flag_ = true;
}

void Decoder::main_loop() {
auto Decoder::main_loop() -> bool {
std::array<uint8_t, kRX_BUFFER_SIZE> rx_buffer{};

auto bytes_read = read(input_fd_, rx_buffer.data(), sizeof(rx_buffer));

if (errno == EINTR) {
stop = true;
return;
return true;
}
if (bytes_read < 0) {
throw std::runtime_error("Read error.");
}
if (bytes_read == 0) {
stop = true;
return;
return true;
}

if (output_file_fd_.has_value()) {
if (write(*output_file_fd_, rx_buffer.data(), bytes_read) != bytes_read) {
throw std::runtime_error("Could not write to output file.");
stop = true;
return;
return true;
}
}

Expand All @@ -131,4 +127,6 @@ void Decoder::main_loop() {
}
}
}

return false;
}
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "decoder.hpp"
#include "signal_handler.hpp"
#include <csignal>
#include <cstdlib>
#include <cxxopts.hpp>
Expand Down Expand Up @@ -86,7 +85,7 @@ auto main(int argc, char** argv) -> int {
}

while (!stop) { // NOLINT handled by signal action
decoder->main_loop();
stop |= decoder->main_loop();
}

return EXIT_SUCCESS;
Expand Down

0 comments on commit 5ed028c

Please sign in to comment.