Skip to content

Commit f56d4eb

Browse files
Change how extensions and task generation works to always be a task (#118)
Changes how extensions work so they always run on a task object rather than on different types. By changing the order of construction, all of the reactions can be given full context.
1 parent e2dae5b commit f56d4eb

37 files changed

+319
-301
lines changed

src/PowerPlant.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#include "dsl/word/Shutdown.hpp"
3131
#include "dsl/word/Startup.hpp"
3232
#include "dsl/word/emit/Direct.hpp"
33+
#include "extension/ChronoController.hpp"
34+
#include "extension/IOController.hpp"
35+
#include "extension/NetworkController.hpp"
3336
#include "message/CommandLineArguments.hpp"
3437
#include "message/LogMessage.hpp"
3538
#include "threading/ReactionTask.hpp"
@@ -55,6 +58,11 @@ PowerPlant::PowerPlant(Configuration config, int argc, const char* argv[]) : sch
5558
// Store our static variable
5659
powerplant = this;
5760

61+
// Install the extension controllers
62+
install<extension::ChronoController>();
63+
install<extension::IOController>();
64+
install<extension::NetworkController>();
65+
5866
// Emit our arguments if any.
5967
message::CommandLineArguments args;
6068
for (int i = 0; i < argc; ++i) {
@@ -112,13 +120,13 @@ void PowerPlant::submit(std::unique_ptr<threading::ReactionTask>&& task, const b
112120
if (task) {
113121
try {
114122
const std::shared_ptr<threading::ReactionTask> t(std::move(task));
115-
submit(t->id, t->priority, t->group_descriptor, t->thread_pool_descriptor, immediate, [t]() { t->run(); });
123+
submit(t->id, t->priority, t->group_descriptor, t->pool_descriptor, immediate, [t]() { t->run(); });
116124
}
117125
catch (const std::exception& ex) {
118-
task->parent.reactor.log<NUClear::ERROR>("There was an exception while submitting a reaction", ex.what());
126+
task->parent->reactor.log<NUClear::ERROR>("There was an exception while submitting a reaction", ex.what());
119127
}
120128
catch (...) {
121-
task->parent.reactor.log<NUClear::ERROR>("There was an unknown exception while submitting a reaction");
129+
task->parent->reactor.log<NUClear::ERROR>("There was an unknown exception while submitting a reaction");
122130
}
123131
}
124132
}
@@ -130,7 +138,7 @@ void PowerPlant::log(const LogLevel& level, std::string message) {
130138
// Direct emit the log message so that any direct loggers can use it
131139
emit<dsl::word::emit::Direct>(std::make_unique<message::LogMessage>(
132140
level,
133-
current_task != nullptr ? current_task->parent.reactor.log_level : LogLevel::UNKNOWN,
141+
current_task != nullptr ? current_task->parent->reactor.log_level : LogLevel::UNKNOWN,
134142
std::move(message),
135143
current_task != nullptr ? current_task->stats : nullptr));
136144
}

src/dsl/Parse.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,36 @@ namespace dsl {
4040
return DSL::template bind<Parse<Sentence...>>(r, std::forward<Arguments>(args)...);
4141
}
4242

43-
static auto get(threading::Reaction& r)
43+
static auto get(threading::ReactionTask& task)
4444
-> decltype(std::conditional_t<fusion::has_get<DSL>::value, DSL, fusion::NoOp>::template get<
45-
Parse<Sentence...>>(r)) {
45+
Parse<Sentence...>>(task)) {
4646
return std::conditional_t<fusion::has_get<DSL>::value, DSL, fusion::NoOp>::template get<Parse<Sentence...>>(
47-
r);
47+
task);
4848
}
4949

50-
static bool precondition(threading::Reaction& r) {
50+
static bool precondition(threading::ReactionTask& task) {
5151
return std::conditional_t<fusion::has_precondition<DSL>::value, DSL, fusion::NoOp>::template precondition<
52-
Parse<Sentence...>>(r);
52+
Parse<Sentence...>>(task);
5353
}
5454

55-
static int priority(threading::Reaction& r) {
55+
static int priority(threading::ReactionTask& task) {
5656
return std::conditional_t<fusion::has_priority<DSL>::value, DSL, fusion::NoOp>::template priority<
57-
Parse<Sentence...>>(r);
57+
Parse<Sentence...>>(task);
5858
}
5959

60-
static util::GroupDescriptor group(threading::Reaction& r) {
60+
static util::GroupDescriptor group(threading::ReactionTask& task) {
6161
return std::conditional_t<fusion::has_group<DSL>::value, DSL, fusion::NoOp>::template group<
62-
Parse<Sentence...>>(r);
62+
Parse<Sentence...>>(task);
6363
}
6464

65-
static util::ThreadPoolDescriptor pool(threading::Reaction& r) {
65+
static util::ThreadPoolDescriptor pool(threading::ReactionTask& task) {
6666
return std::conditional_t<fusion::has_pool<DSL>::value, DSL, fusion::NoOp>::template pool<
67-
Parse<Sentence...>>(r);
67+
Parse<Sentence...>>(task);
6868
}
6969

70-
static void postcondition(threading::ReactionTask& r) {
70+
static void postcondition(threading::ReactionTask& task) {
7171
std::conditional_t<fusion::has_postcondition<DSL>::value, DSL, fusion::NoOp>::template postcondition<
72-
Parse<Sentence...>>(r);
72+
Parse<Sentence...>>(task);
7373
}
7474
};
7575

src/dsl/fusion/GetFusion.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ namespace dsl {
4040
*/
4141
template <typename Function, typename DSL>
4242
struct GetCaller {
43-
static auto call(threading::Reaction& reaction) -> decltype(Function::template get<DSL>(reaction)) {
44-
return Function::template get<DSL>(reaction);
43+
static auto call(threading::ReactionTask& task) -> decltype(Function::template get<DSL>(task)) {
44+
return Function::template get<DSL>(task);
4545
}
4646
};
4747

@@ -86,19 +86,19 @@ namespace dsl {
8686
struct GetFuser<std::tuple<Word1, WordN...>> {
8787

8888
template <typename DSL, typename U = Word1>
89-
static auto get(threading::Reaction& reaction)
89+
static auto get(threading::ReactionTask& task)
9090
-> decltype(util::FunctionFusion<std::tuple<Word1, WordN...>,
91-
decltype(std::forward_as_tuple(reaction)),
91+
decltype(std::forward_as_tuple(task)),
9292
GetCaller,
9393
std::tuple<DSL>,
94-
1>::call(reaction)) {
94+
1>::call(task)) {
9595

9696
// Perform our function fusion
9797
return util::FunctionFusion<std::tuple<Word1, WordN...>,
98-
decltype(std::forward_as_tuple(reaction)),
98+
decltype(std::forward_as_tuple(task)),
9999
GetCaller,
100100
std::tuple<DSL>,
101-
1>::call(reaction);
101+
1>::call(task);
102102
}
103103
};
104104

src/dsl/fusion/GroupFusion.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ namespace dsl {
7777
struct GroupFuser<std::tuple<Word>> {
7878

7979
template <typename DSL>
80-
static util::GroupDescriptor group(threading::Reaction& reaction) {
80+
static util::GroupDescriptor group(threading::ReactionTask& task) {
8181

8282
// Return our group
83-
return Word::template group<DSL>(reaction);
83+
return Word::template group<DSL>(task);
8484
}
8585
};
8686

@@ -89,7 +89,7 @@ namespace dsl {
8989
struct GroupFuser<std::tuple<Word1, Word2, WordN...>> {
9090

9191
template <typename DSL>
92-
static void group(const threading::Reaction& /*reaction*/) {
92+
static void group(const threading::ReactionTask& /*task*/) {
9393
throw std::invalid_argument("Can not be a member of more than one group");
9494
}
9595
};

src/dsl/fusion/NoOp.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,27 @@ namespace dsl {
4747
}
4848

4949
template <typename DSL>
50-
static std::tuple<> get(const threading::Reaction& /*reaction*/) {
50+
static std::tuple<> get(const threading::ReactionTask& /*task*/) {
5151
return {};
5252
}
5353

5454
template <typename DSL>
55-
static bool precondition(const threading::Reaction& /*reaction*/) {
55+
static bool precondition(const threading::ReactionTask& /*task*/) {
5656
return true;
5757
}
5858

5959
template <typename DSL>
60-
static int priority(const threading::Reaction& /*reaction*/) {
60+
static int priority(const threading::ReactionTask& /*task*/) {
6161
return word::Priority::NORMAL::value;
6262
}
6363

6464
template <typename DSL>
65-
static util::GroupDescriptor group(const threading::Reaction& /*reaction*/) {
66-
return util::GroupDescriptor{};
65+
static util::GroupDescriptor group(const threading::ReactionTask& /*task*/) {
66+
return {};
6767
}
6868

6969
template <typename DSL>
70-
static util::ThreadPoolDescriptor pool(const threading::Reaction& /*reaction*/) {
70+
static util::ThreadPoolDescriptor pool(const threading::ReactionTask& /*task*/) {
7171
return util::ThreadPoolDescriptor{};
7272
}
7373

@@ -86,15 +86,15 @@ namespace dsl {
8686

8787
static std::tuple<> bind(const std::shared_ptr<threading::Reaction>&);
8888

89-
static std::tuple<> get(threading::Reaction&);
89+
static std::tuple<> get(threading::ReactionTask&);
9090

91-
static bool precondition(threading::Reaction&);
91+
static bool precondition(threading::ReactionTask&);
9292

93-
static int priority(threading::Reaction&);
93+
static int priority(threading::ReactionTask&);
9494

95-
static util::GroupDescriptor group(threading::Reaction&);
95+
static util::GroupDescriptor group(threading::ReactionTask&);
9696

97-
static util::ThreadPoolDescriptor pool(threading::Reaction&);
97+
static util::ThreadPoolDescriptor pool(threading::ReactionTask&);
9898

9999
static void postcondition(threading::ReactionTask&);
100100
};

src/dsl/fusion/PoolFusion.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <algorithm>
2727
#include <stdexcept>
2828

29-
#include "../../threading/Reaction.hpp"
29+
#include "../../threading/ReactionTask.hpp"
3030
#include "../operation/DSLProxy.hpp"
3131
#include "has_pool.hpp"
3232

@@ -77,10 +77,10 @@ namespace dsl {
7777
struct PoolFuser<std::tuple<Word>> {
7878

7979
template <typename DSL>
80-
static util::ThreadPoolDescriptor pool(threading::Reaction& reaction) {
80+
static util::ThreadPoolDescriptor pool(threading::ReactionTask& task) {
8181

8282
// Return our pool
83-
return Word::template pool<DSL>(reaction);
83+
return Word::template pool<DSL>(task);
8484
}
8585
};
8686

@@ -89,7 +89,7 @@ namespace dsl {
8989
struct PoolFuser<std::tuple<Word1, Word2, WordN...>> {
9090

9191
template <typename DSL>
92-
static util::ThreadPoolDescriptor pool(const threading::Reaction& /*reaction*/) {
92+
static util::ThreadPoolDescriptor pool(const threading::ReactionTask& /*task*/) {
9393
throw std::invalid_argument("Can not be a member of more than one pool");
9494
}
9595
};

src/dsl/fusion/PreconditionFusion.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifndef NUCLEAR_DSL_FUSION_PRECONDITION_FUSION_HPP
2424
#define NUCLEAR_DSL_FUSION_PRECONDITION_FUSION_HPP
2525

26-
#include "../../threading/Reaction.hpp"
26+
#include "../../threading/ReactionTask.hpp"
2727
#include "../operation/DSLProxy.hpp"
2828
#include "has_precondition.hpp"
2929

@@ -75,10 +75,10 @@ namespace dsl {
7575
struct PreconditionFuser<std::tuple<Word>> {
7676

7777
template <typename DSL>
78-
static bool precondition(threading::Reaction& reaction) {
78+
static bool precondition(threading::ReactionTask& task) {
7979

8080
// Run our remaining precondition
81-
return Word::template precondition<DSL>(reaction);
81+
return Word::template precondition<DSL>(task);
8282
}
8383
};
8484

@@ -87,11 +87,11 @@ namespace dsl {
8787
struct PreconditionFuser<std::tuple<Word1, Word2, WordN...>> {
8888

8989
template <typename DSL>
90-
static bool precondition(threading::Reaction& reaction) {
90+
static bool precondition(threading::ReactionTask& task) {
9191

9292
// Perform a recursive and operation ending with the first false
93-
return Word1::template precondition<DSL>(reaction)
94-
&& PreconditionFuser<std::tuple<Word2, WordN...>>::template precondition<DSL>(reaction);
93+
return Word1::template precondition<DSL>(task)
94+
&& PreconditionFuser<std::tuple<Word2, WordN...>>::template precondition<DSL>(task);
9595
}
9696
};
9797

src/dsl/fusion/PriorityFusion.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifndef NUCLEAR_DSL_FUSION_PRIORITY_FUSION_HPP
2424
#define NUCLEAR_DSL_FUSION_PRIORITY_FUSION_HPP
2525

26-
#include "../../threading/Reaction.hpp"
26+
#include "../../threading/ReactionTask.hpp"
2727
#include "../operation/DSLProxy.hpp"
2828
#include "has_priority.hpp"
2929

@@ -74,10 +74,10 @@ namespace dsl {
7474
struct PriorityFuser<std::tuple<Word>> {
7575

7676
template <typename DSL>
77-
static int priority(threading::Reaction& reaction) {
77+
static int priority(threading::ReactionTask& task) {
7878

7979
// Return our priority
80-
return Word::template priority<DSL>(reaction);
80+
return Word::template priority<DSL>(task);
8181
}
8282
};
8383

@@ -86,11 +86,11 @@ namespace dsl {
8686
struct PriorityFuser<std::tuple<Word1, Word2, WordN...>> {
8787

8888
template <typename DSL>
89-
static int priority(threading::Reaction& reaction) {
89+
static int priority(threading::ReactionTask& task) {
9090

9191
// Choose our maximum priority
92-
return std::max(Word1::template priority<DSL>(reaction),
93-
PriorityFuser<std::tuple<Word2, WordN...>>::template priority<DSL>(reaction));
92+
return std::max(Word1::template priority<DSL>(task),
93+
PriorityFuser<std::tuple<Word2, WordN...>>::template priority<DSL>(task));
9494
}
9595
};
9696

src/dsl/fusion/has_get.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifndef NUCLEAR_DSL_FUSION_HAS_GET_HPP
2424
#define NUCLEAR_DSL_FUSION_HAS_GET_HPP
2525

26-
#include "../../threading/Reaction.hpp"
26+
#include "../../threading/ReactionTask.hpp"
2727
#include "NoOp.hpp"
2828

2929
namespace NUClear {
@@ -42,7 +42,8 @@ namespace dsl {
4242
using no = std::false_type;
4343

4444
template <typename U>
45-
static auto test(int) -> decltype(U::template get<ParsedNoOp>(std::declval<threading::Reaction&>()), yes());
45+
static auto test(int) -> decltype(U::template get<ParsedNoOp>(std::declval<threading::ReactionTask&>()),
46+
yes());
4647
template <typename>
4748
static no test(...);
4849

src/dsl/fusion/has_group.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifndef NUCLEAR_DSL_FUSION_HAS_GROUP_HPP
2424
#define NUCLEAR_DSL_FUSION_HAS_GROUP_HPP
2525

26-
#include "../../threading/Reaction.hpp"
26+
#include "../../threading/ReactionTask.hpp"
2727
#include "NoOp.hpp"
2828

2929
namespace NUClear {
@@ -42,7 +42,7 @@ namespace dsl {
4242
using no = std::false_type;
4343

4444
template <typename U>
45-
static auto test(int) -> decltype(U::template group<ParsedNoOp>(std::declval<threading::Reaction&>()),
45+
static auto test(int) -> decltype(U::template group<ParsedNoOp>(std::declval<threading::ReactionTask&>()),
4646
yes());
4747
template <typename>
4848
static no test(...);

src/dsl/fusion/has_pool.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifndef NUCLEAR_DSL_FUSION_HAS_POOL_HPP
2424
#define NUCLEAR_DSL_FUSION_HAS_POOL_HPP
2525

26-
#include "../../threading/Reaction.hpp"
26+
#include "../../threading/ReactionTask.hpp"
2727
#include "NoOp.hpp"
2828

2929
namespace NUClear {
@@ -42,7 +42,7 @@ namespace dsl {
4242
using no = std::false_type;
4343

4444
template <typename U>
45-
static auto test(int) -> decltype(U::template pool<ParsedNoOp>(std::declval<threading::Reaction&>()),
45+
static auto test(int) -> decltype(U::template pool<ParsedNoOp>(std::declval<threading::ReactionTask&>()),
4646
yes());
4747
template <typename>
4848
static no test(...);

src/dsl/fusion/has_precondition.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifndef NUCLEAR_DSL_FUSION_HAS_PRECONDITION_HPP
2424
#define NUCLEAR_DSL_FUSION_HAS_PRECONDITION_HPP
2525

26-
#include "../../threading/Reaction.hpp"
26+
#include "../../threading/ReactionTask.hpp"
2727
#include "NoOp.hpp"
2828

2929
namespace NUClear {
@@ -43,7 +43,7 @@ namespace dsl {
4343

4444
template <typename U>
4545
static auto test(int)
46-
-> decltype(U::template precondition<ParsedNoOp>(std::declval<threading::Reaction&>()), yes());
46+
-> decltype(U::template precondition<ParsedNoOp>(std::declval<threading::ReactionTask&>()), yes());
4747
template <typename>
4848
static no test(...);
4949

0 commit comments

Comments
 (0)