Skip to content

Commit

Permalink
changed naming of Settings, Transactions, Tag
Browse files Browse the repository at this point in the history
+ fixed CMakeLists.txt case-sensitivity bug
  • Loading branch information
RalphSteinhagen authored and wirew0rm committed Oct 11, 2023
1 parent 391b262 commit 6303c46
Show file tree
Hide file tree
Showing 30 changed files with 396 additions and 396 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ if (ENABLE_TESTING AND UNIX AND NOT APPLE)
setup_target_for_coverage_gcovr_xml(
NAME coverage
EXECUTABLE ctest
DEPENDENCIES qa_buffer qa_data_sink qa_DynamicPort qa_DynamicBlock qa_HierBlock qa_filter qa_settings qa_tags qa_Scheduler qa_thread_pool qa_thread_affinity
DEPENDENCIES qa_buffer qa_data_sink qa_DynamicPort qa_DynamicBlock qa_HierBlock qa_filter qa_Settings qa_Tags qa_Scheduler qa_thread_pool qa_thread_affinity
EXCLUDE "$CMAKE_BUILD_DIR/*" "concepts/.*" ".*/test/.*")
setup_target_for_coverage_gcovr_html(
NAME coverage_html
EXECUTABLE ctest
DEPENDENCIES qa_buffer qa_data_sink qa_DynamicPort qa_DynamicBlock qa_HierBlock qa_filter qa_settings qa_tags qa_Scheduler qa_thread_pool qa_thread_affinity
DEPENDENCIES qa_buffer qa_data_sink qa_DynamicPort qa_DynamicBlock qa_HierBlock qa_filter qa_Settings qa_Tags qa_Scheduler qa_thread_pool qa_thread_affinity
EXCLUDE "$CMAKE_BUILD_DIR/*" "concepts/.*" ".*/test/.*")
endif ()
message("Building Tests and benchmarks.")
Expand Down
12 changes: 6 additions & 6 deletions blocks/basic/include/gnuradio-4.0/basic/clock_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <gnuradio-4.0/Block.hpp>
#include <gnuradio-4.0/reflection.hpp>
#include <gnuradio-4.0/tag.hpp>
#include <gnuradio-4.0/Tag.hpp>

#include <gnuradio-4.0/testing/tag_monitors.hpp>

Expand All @@ -32,9 +32,9 @@ ClockSource Documentation -- add here
)"">> {
std::chrono::time_point<ClockSourceType> nextTimePoint = ClockSourceType::now();
//
PortOut<T> out;
std::vector<tag_t> tags{};
std::size_t next_tag{ 0 };
PortOut<T> out;
std::vector<Tag> tags{};
std::size_t next_tag{ 0 };
//
A<std::uint32_t, "n_samples_max", Visible, Doc<"0: unlimited">> n_samples_max = 1024;
std::uint32_t n_samples_produced{ 0 };
Expand Down Expand Up @@ -85,7 +85,7 @@ ClockSource Documentation -- add here
}

void
settings_changed(const property_map & /*old_settings*/, const property_map & /*new_settings*/) {
settingsChanged(const property_map & /*old_settings*/, const property_map & /*new_settings*/) {
nextTimePoint = ClockSourceType::now();
}

Expand Down Expand Up @@ -113,7 +113,7 @@ ClockSource Documentation -- add here
std::uint32_t samples_to_produce = n_available;
while (next_tag < tags.size() && tags[next_tag].index <= static_cast<std::make_signed_t<std::size_t>>(n_samples_produced + n_available)) {
gr::testing::print_tag(tags[next_tag], fmt::format("{}::processBulk(...)\t publish tag at {:6}", this->name, n_samples_produced));
tag_t &out_tag = this->output_tags()[0];
Tag &out_tag = this->output_tags()[0];
out_tag = tags[next_tag];
out_tag.index = tags[next_tag].index - static_cast<std::make_signed_t<std::size_t>>(n_samples_produced);
samples_to_produce = static_cast<std::uint32_t>(tags[next_tag].index) - n_samples_produced;
Expand Down
22 changes: 11 additions & 11 deletions blocks/basic/include/gnuradio-4.0/basic/common_blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ class multi_adder : public gr::BlockModel {
gr::PortOut<T> _output_port;

protected:
using setting_map = std::map<std::string, int, std::less<>>;
std::string _name = "multi_adder";
std::string _type_name = "multi_adder";
gr::property_map _meta_information; /// used to store non-graph-processing information like UI block position etc.
bool _input_tags_present = false;
bool _output_tags_changed = false;
std::vector<gr::property_map> _tags_at_input;
std::vector<gr::property_map> _tags_at_output;
std::unique_ptr<gr::settings_base> _settings = std::make_unique<gr::basic_settings<multi_adder<T>>>(*this);
using setting_map = std::map<std::string, int, std::less<>>;
std::string _name = "multi_adder";
std::string _type_name = "multi_adder";
gr::property_map _meta_information; /// used to store non-graph-processing information like UI block position etc.
bool _input_tags_present = false;
bool _output_tags_changed = false;
std::vector<gr::property_map> _tags_at_input;
std::vector<gr::property_map> _tags_at_output;
std::unique_ptr<gr::SettingsBase> _settings = std::make_unique<gr::BasicSettings<multi_adder<T>>>(*this);

void
apply_input_count() {
Expand All @@ -108,7 +108,7 @@ class multi_adder : public gr::BlockModel {
~multi_adder() override = default;

void
settings_changed(const gr::property_map & /*old_setting*/, const gr::property_map & /*new_setting*/) noexcept {
settingsChanged(const gr::property_map & /*old_setting*/, const gr::property_map & /*new_setting*/) noexcept {
apply_input_count();
}

Expand Down Expand Up @@ -195,7 +195,7 @@ class multi_adder : public gr::BlockModel {
return _meta_information;
}

[[nodiscard]] gr::settings_base &
[[nodiscard]] gr::SettingsBase &
settings() const override {
return *_settings;
}
Expand Down
50 changes: 25 additions & 25 deletions blocks/basic/include/gnuradio-4.0/basic/data_sink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <gnuradio-4.0/CircularBuffer.hpp>
#include <gnuradio-4.0/DataSet.hpp>
#include <gnuradio-4.0/HistoryBuffer.hpp>
#include <gnuradio-4.0/tag.hpp>
#include <gnuradio-4.0/Tag.hpp>

#include <any>
#include <chrono>
Expand Down Expand Up @@ -35,7 +35,7 @@ concept DataSetCallback = std::invocable<T, DataSet<V>>;
* Stream callback functions receive the span of data, with optional tags and reference to the sink.
*/
template<typename T, typename V>
concept StreamCallback = std::invocable<T, std::span<const V>> || std::invocable<T, std::span<const V>, std::span<const tag_t>> || std::invocable<T, std::span<const V>, std::span<const tag_t>, const data_sink<V>&>;
concept StreamCallback = std::invocable<T, std::span<const V>> || std::invocable<T, std::span<const V>, std::span<const Tag>> || std::invocable<T, std::span<const V>, std::span<const Tag>, const data_sink<V>&>;

/**
* Used for testing whether a tag should trigger data acquisition.
Expand Down Expand Up @@ -64,7 +64,7 @@ concept StreamCallback = std::invocable<T, std::span<const V>> || std::invocable
* // matcher observing three possible tag values, "green", "yellow", "red".
* // starting a dataset when seeing "green", stopping on "red", starting a new dataset on "yellow"
* struct color_matcher {
* matcher_result operator()(const tag_t &tag) {
* matcher_result operator()(const Tag &tag) {
* if (tag == green || tag == yellow) {
* return trigger_match_result::Matching;
* }
Expand All @@ -80,7 +80,7 @@ concept StreamCallback = std::invocable<T, std::span<const V>> || std::invocable
* @see trigger_match_result
*/
template<typename T>
concept TriggerMatcher = requires(T matcher, tag_t tag) {
concept TriggerMatcher = requires(T matcher, Tag tag) {
{ matcher(tag) } -> std::convertible_to<trigger_match_result>;
};

Expand Down Expand Up @@ -326,7 +326,7 @@ class data_sink : public Block<data_sink<T>> {
gr::CircularBuffer<T> buffer = gr::CircularBuffer<T>(_listener_buffer_size);
decltype(buffer.new_reader()) reader = buffer.new_reader();
decltype(buffer.new_writer()) writer = buffer.new_writer();
gr::CircularBuffer<tag_t> tag_buffer = gr::CircularBuffer<tag_t>(1024);
gr::CircularBuffer<Tag> tag_buffer = gr::CircularBuffer<Tag>(1024);
decltype(tag_buffer.new_reader()) tag_reader = tag_buffer.new_reader();
decltype(tag_buffer.new_writer()) tag_writer = tag_buffer.new_writer();
std::size_t samples_read = 0; // reader thread
Expand All @@ -342,14 +342,14 @@ class data_sink : public Block<data_sink<T>> {
}

const auto read_data = reader.get(available);
if constexpr (requires { fnc(std::span<const T>(), std::span<const tag_t>()); }) {
if constexpr (requires { fnc(std::span<const T>(), std::span<const Tag>()); }) {
const auto tags = tag_reader.get();
const auto it = std::find_if_not(tags.begin(), tags.end(), [until = static_cast<int64_t>(samples_read + available)](const auto &tag) { return tag.index < until; });
auto relevant_tags = std::vector<tag_t>(tags.begin(), it);
auto relevant_tags = std::vector<Tag>(tags.begin(), it);
for (auto &t : relevant_tags) {
t.index -= static_cast<int64_t>(samples_read);
}
fnc(read_data, std::span<const tag_t>(relevant_tags));
fnc(read_data, std::span<const Tag>(relevant_tags));
std::ignore = tag_reader.consume(relevant_tags.size());
} else {
std::ignore = tag_reader.consume(tag_reader.available());
Expand Down Expand Up @@ -392,7 +392,7 @@ class data_sink : public Block<data_sink<T>> {
}

void
settings_changed(const property_map & /*old_settings*/, const property_map &new_settings) {
settingsChanged(const property_map & /*old_settings*/, const property_map &new_settings) {
if (apply_signal_info(new_settings)) {
_has_signal_info_from_settings = true;
}
Expand Down Expand Up @@ -616,17 +616,17 @@ class data_sink : public Block<data_sink<T>> {
template<typename Callback>
struct continuous_listener : public abstract_listener {
static constexpr auto has_callback = !std::is_same_v<Callback, gr::meta::null_type>;
static constexpr auto callback_takes_tags = std::is_invocable_v<Callback, std::span<const T>, std::span<const tag_t>>
|| std::is_invocable_v<Callback, std::span<const T>, std::span<const tag_t>, const data_sink<T> &>;
static constexpr auto callback_takes_tags = std::is_invocable_v<Callback, std::span<const T>, std::span<const Tag>>
|| std::is_invocable_v<Callback, std::span<const T>, std::span<const Tag>, const data_sink<T> &>;

const data_sink<T> &parent_sink;
bool block = false;
std::size_t samples_written = 0;

// callback-only
std::size_t buffer_fill = 0;
std::vector<T> buffer;
std::vector<tag_t> tag_buffer;
std::size_t buffer_fill = 0;
std::vector<T> buffer;
std::vector<Tag> tag_buffer;

// polling-only
std::weak_ptr<poller> polling_handler = {};
Expand All @@ -639,10 +639,10 @@ class data_sink : public Block<data_sink<T>> {
explicit continuous_listener(std::shared_ptr<poller> poller, bool do_block, const data_sink<T> &parent) : parent_sink(parent), block(do_block), polling_handler{ std::move(poller) } {}

inline void
call_callback(std::span<const T> data, std::span<const tag_t> tags) {
if constexpr (std::is_invocable_v<Callback, std::span<const T>, std::span<const tag_t>, const data_sink<T> &>) {
call_callback(std::span<const T> data, std::span<const Tag> tags) {
if constexpr (std::is_invocable_v<Callback, std::span<const T>, std::span<const Tag>, const data_sink<T> &>) {
callback(std::move(data), std::move(tags), parent_sink);
} else if constexpr (std::is_invocable_v<Callback, std::span<const T>, std::span<const tag_t>>) {
} else if constexpr (std::is_invocable_v<Callback, std::span<const T>, std::span<const Tag>>) {
callback(std::move(data), std::move(tags));
} else {
callback(std::move(data));
Expand All @@ -660,7 +660,7 @@ class data_sink : public Block<data_sink<T>> {
detail::copy_span(data.first(n), std::span(buffer).subspan(buffer_fill, n));
if constexpr (callback_takes_tags) {
if (tag_data0) {
tag_buffer.push_back({ static_cast<tag_t::signed_index_type>(buffer_fill), *tag_data0 });
tag_buffer.push_back({ static_cast<Tag::signed_index_type>(buffer_fill), *tag_data0 });
tag_data0.reset();
}
}
Expand All @@ -678,7 +678,7 @@ class data_sink : public Block<data_sink<T>> {
// send out complete chunks directly
while (data.size() >= buffer.size()) {
if constexpr (callback_takes_tags) {
std::vector<tag_t> tags;
std::vector<Tag> tags;
if (tag_data0) {
tags.push_back({ 0, std::move(*tag_data0) });
tag_data0.reset();
Expand Down Expand Up @@ -713,7 +713,7 @@ class data_sink : public Block<data_sink<T>> {
if (to_write > 0) {
if (tag_data0) {
auto tw = poller->tag_writer.reserve_output_range(1);
tw[0] = { static_cast<tag_t::signed_index_type>(samples_written), std::move(*tag_data0) };
tw[0] = { static_cast<Tag::signed_index_type>(samples_written), std::move(*tag_data0) };
tw.publish(1);
}
auto write_data = poller->writer.reserve_output_range(to_write);
Expand Down Expand Up @@ -800,14 +800,14 @@ class data_sink : public Block<data_sink<T>> {

void
process(std::span<const T> history, std::span<const T> in_data, std::optional<property_map> tag_data0) override {
if (tag_data0 && trigger_matcher(tag_t{ 0, *tag_data0 }) == trigger_match_result::Matching) {
if (tag_data0 && trigger_matcher(Tag{ 0, *tag_data0 }) == trigger_match_result::Matching) {
DataSet<T> dataset = dataset_template;
dataset.signal_values.reserve(pre_samples + post_samples); // TODO maybe make the circ. buffer smaller but preallocate these

const auto pre_sample_view = history.last(std::min(pre_samples, history.size()));
dataset.signal_values.insert(dataset.signal_values.end(), pre_sample_view.begin(), pre_sample_view.end());

dataset.timing_events = { { { static_cast<tag_t::signed_index_type>(pre_sample_view.size()), *tag_data0 } } };
dataset.timing_events = { { { static_cast<Tag::signed_index_type>(pre_sample_view.size()), *tag_data0 } } };
pending_trigger_windows.push_back({ .dataset = std::move(dataset), .pending_post_samples = post_samples });
}

Expand Down Expand Up @@ -892,11 +892,11 @@ class data_sink : public Block<data_sink<T>> {
void
process(std::span<const T>, std::span<const T> in_data, std::optional<property_map> tag_data0) override {
if (tag_data0) {
const auto obsr = matcher(tag_t{ 0, *tag_data0 });
const auto obsr = matcher(Tag{ 0, *tag_data0 });
if (obsr == trigger_match_result::NotMatching || obsr == trigger_match_result::Matching) {
if (pending_dataset) {
if (obsr == trigger_match_result::NotMatching) {
pending_dataset->timing_events[0].push_back({ static_cast<tag_t::signed_index_type>(pending_dataset->signal_values.size()), *tag_data0 });
pending_dataset->timing_events[0].push_back({ static_cast<Tag::signed_index_type>(pending_dataset->signal_values.size()), *tag_data0 });
}
this->publish_dataset(std::move(*pending_dataset));
pending_dataset.reset();
Expand Down Expand Up @@ -1011,7 +1011,7 @@ class data_sink : public Block<data_sink<T>> {
}

DataSet<T> dataset = dataset_template;
dataset.timing_events = { { { -static_cast<tag_t::signed_index_type>(it->delay), std::move(it->tag_data) } } };
dataset.timing_events = { { { -static_cast<Tag::signed_index_type>(it->delay), std::move(it->tag_data) } } };
dataset.signal_values = { in_data[it->pending_samples] };
this->publish_dataset(std::move(dataset));

Expand Down
2 changes: 1 addition & 1 deletion blocks/basic/include/gnuradio-4.0/basic/selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct Selector : Block<Selector<T>, SelectorDoc> {
std::uint32_t _selectedSrc = -1U;

void
settings_changed(const gr::property_map &old_settings, const gr::property_map &new_settings) {
settingsChanged(const gr::property_map &old_settings, const gr::property_map &new_settings) {
if (new_settings.contains("nInputs") || new_settings.contains("nOutputs")) {
fmt::print("{}: configuration changed: nInputs {} -> {}, nOutputs {} -> {}\n", static_cast<void *>(this), old_settings.at("nInputs"),
new_settings.contains("nInputs") ? new_settings.at("nInputs") : "same", old_settings.at("nOutputs"), new_settings.contains("nOutputs") ? new_settings.at("nOutputs") : "same");
Expand Down
Loading

0 comments on commit 6303c46

Please sign in to comment.