Skip to content

Commit

Permalink
Return a message when a Settings Context is removed
Browse files Browse the repository at this point in the history
Also always return current active context time when set/get

Signed-off-by: Daniel Nicoletti <[email protected]>
  • Loading branch information
dantti authored and RalphSteinhagen committed Dec 2, 2024
1 parent 155961f commit 2b37b65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
13 changes: 5 additions & 8 deletions core/include/gnuradio-4.0/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,12 +1043,6 @@ class Block : public lifecycle::StateMachine<Derived> {
using enum gr::message::Command;
assert(propertyName == block::property::kActiveContext);

if (message.cmd == Get) {
const auto& ctx = settings().activeContext();
message.data = {{"context", ctx.context}, {"time", ctx.time}};
return message;
}

if (message.cmd == Set) {
if (!message.data.has_value()) {
throw gr::exception(fmt::format("block {} (aka. {}) cannot set {} w/o data msg: {}", unique_name, name, propertyName, message));
Expand Down Expand Up @@ -1082,8 +1076,11 @@ class Block : public lifecycle::StateMachine<Derived> {
if (!ctx.has_value()) {
throw gr::exception(fmt::format("propertyCallbackActiveContext - failed to activate context {}, msg: {}", contextStr, message));
}
}

message.data = {{"context", ctx.value().context}};
if (message.cmd == Get || message.cmd == Set) {
const auto& ctx = settings().activeContext();
message.data = {{"context", ctx.context}, {"time", ctx.time}};
return message;
}

Expand Down Expand Up @@ -1162,7 +1159,7 @@ class Block : public lifecycle::StateMachine<Derived> {
if (!settings().removeContext(ctx)) {
throw gr::exception(fmt::format("propertyCallbackSettingsCtx - could not delete context {}, msg: {}", ctx.context, message));
}
return std::nullopt;
return message;
}

throw gr::exception(fmt::format("block {} property {} does not implement command {}, msg: {}", unique_name, propertyName, message.cmd, message));
Expand Down
7 changes: 5 additions & 2 deletions core/test/qa_Messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ const boost::ut::suite MessagesTests = [] {
expect(eq(reply.endpoint, std::string(block::property::kActiveContext)));
expect(reply.data.has_value());
expect(reply.data.value().contains("context"));
expect(reply.data.value().contains("time"));
expect(eq("new_context"s, std::get<std::string>(reply.data.value().at("context"))));
};

Expand All @@ -469,6 +470,7 @@ const boost::ut::suite MessagesTests = [] {
expect(eq(reply.endpoint, std::string(block::property::kActiveContext)));
expect(reply.data.has_value());
expect(reply.data.value().contains("context"));
expect(reply.data.value().contains("time"));
expect(eq("new_context"s, std::get<std::string>(reply.data.value().at("context"))));
};

Expand Down Expand Up @@ -510,8 +512,9 @@ const boost::ut::suite MessagesTests = [] {
sendMessage<Disconnect>(toBlock, "" /* serviceName */, block::property::kSettingsCtx /* endpoint */, {{"context", "new_context"}, {"time", internalTimeForWasm}} /* data */);
expect(nothrow([&] { unitTestBlock.processScheduledMessages(); })) << "manually execute processing of messages";

expect(eq(fromBlock.streamReader().available(), 0UZ)) << "should not receive a reply";
std::string activeContext = std::get<std::string>(unitTestBlock.settings().activeContext().context);
expect(eq(fromBlock.streamReader().available(), 1UZ)) << "didn't receive reply message";
const Message reply = returnReplyMsg(fromBlock);
std::string activeContext = std::get<std::string>(unitTestBlock.settings().activeContext().context);
expect(eq(""s, activeContext));
};

Expand Down

0 comments on commit 2b37b65

Please sign in to comment.