Skip to content

Commit

Permalink
As it was, the FunctionFusion was actually converting everything into…
Browse files Browse the repository at this point in the history
… an lvalue right before the call. The static cast here will fix the types so rvalues become rvalues again. Also remove the exception that watchdog servicer was using and make everything use unique pointers until there is something better
  • Loading branch information
TrentHouliston committed Dec 28, 2024
1 parent bf8ac58 commit cfdca5c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
11 changes: 4 additions & 7 deletions src/Reactor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ namespace dsl {
template <typename WatchdogGroup, typename RuntimeType>
struct WatchdogServicer;
template <typename WatchdogGroup, typename RuntimeType>
WatchdogServicer<WatchdogGroup, RuntimeType> ServiceWatchdog(RuntimeType&& data);
std::unique_ptr<WatchdogServicer<WatchdogGroup, RuntimeType>> ServiceWatchdog(RuntimeType&& data);
template <typename WatchdogGroup>
WatchdogServicer<WatchdogGroup, void> ServiceWatchdog();
std::unique_ptr<WatchdogServicer<WatchdogGroup, void>> ServiceWatchdog();
} // namespace emit
} // namespace word
} // namespace dsl
Expand Down Expand Up @@ -272,10 +272,7 @@ class Reactor {

/// @copydoc dsl::word::emit::ServiceWatchdog
template <typename WatchdogGroup, typename... Arguments>
auto ServiceWatchdog(Arguments&&... args)
// THIS IS VERY IMPORTANT, the return type must be dependent on the function call
// otherwise it won't check it's valid in SFINAE
-> decltype(dsl::word::emit::ServiceWatchdog<WatchdogGroup>(std::forward<Arguments>(args)...)) {
auto ServiceWatchdog(Arguments&&... args) {
return dsl::word::emit::ServiceWatchdog<WatchdogGroup>(std::forward<Arguments>(args)...);
}

Expand Down Expand Up @@ -368,7 +365,7 @@ class Reactor {
util::CallbackGenerator<DSL, Function>(std::forward<Function>(callback)));

// Get our tuple from binding our reaction
auto tuple = DSL::bind(reaction, std::get<Index>(args)...);
auto tuple = DSL::bind(reaction, std::move(std::get<Index>(args))...);

auto handle = threading::ReactionHandle(reaction);
reactor.reaction_handles.push_back(handle);
Expand Down
12 changes: 6 additions & 6 deletions src/dsl/word/emit/Watchdog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ namespace dsl {
* @return A WatchdogServicer object which will update the service time of the specified watchdog
*/
template <typename WatchdogGroup, typename RuntimeType>
WatchdogServicer<WatchdogGroup, RuntimeType> ServiceWatchdog(RuntimeType&& data) {
return WatchdogServicer<WatchdogGroup, RuntimeType>(std::forward<RuntimeType>(data));
std::unique_ptr<WatchdogServicer<WatchdogGroup, RuntimeType>> ServiceWatchdog(RuntimeType&& data) {
return std::make_unique<WatchdogServicer<WatchdogGroup, RuntimeType>>(std::forward<RuntimeType>(data));
}

/**
Expand All @@ -137,8 +137,8 @@ namespace dsl {
* @return WatchdogServicer<WatchdogGroup, void>
*/
template <typename WatchdogGroup>
WatchdogServicer<WatchdogGroup, void> ServiceWatchdog() {
return WatchdogServicer<WatchdogGroup, void>();
std::unique_ptr<WatchdogServicer<WatchdogGroup, void>> ServiceWatchdog() {
return std::make_unique<WatchdogServicer<WatchdogGroup, void>>();
}

/**
Expand All @@ -158,9 +158,9 @@ namespace dsl {

template <typename WatchdogGroup, typename RuntimeType>
static void emit(const PowerPlant& /*powerplant*/,
WatchdogServicer<WatchdogGroup, RuntimeType>& servicer) {
const std::shared_ptr<WatchdogServicer<WatchdogGroup, RuntimeType>>& servicer) {
// Update our service time
servicer.service();
servicer->service();
}
};

Expand Down
6 changes: 4 additions & 2 deletions src/util/FunctionFusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ namespace util {
* @return The object returned by the called subfunction
*/
template <typename Function, int... Shared, int... Selected, typename... Arguments>
auto apply_function_fusion_call(const std::tuple<Arguments...>& args,
auto apply_function_fusion_call(std::tuple<Arguments...>&& args,
const Sequence<Shared...>& /*shared*/,
const Sequence<Selected...>& /*selected*/)
-> decltype(Function::call(std::get<Shared>(args)..., std::get<Selected>(args)...)) {
return Function::call(std::get<Shared>(args)..., std::get<Selected>(args)...);
return Function::call(
static_cast<std::tuple_element_t<Shared, std::tuple<Arguments...>>>(std::get<Shared>(args))...,
static_cast<std::tuple_element_t<Selected, std::tuple<Arguments...>>>(std::get<Selected>(args))...);
}

/**
Expand Down

0 comments on commit cfdca5c

Please sign in to comment.