Skip to content

Commit e2dae5b

Browse files
Split the files that can into hpp and cpp files (#117)
Originally these were put into header only to support having the nuclear base clock change. Now with the time travel features this is not needed and is detrimental to the ability to build the code
1 parent 55f8c2d commit e2dae5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1164
-1075
lines changed

docs/extension.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Bind
4343

4444
.. codeblock:: c++
4545
template <typename DSL>
46-
static inline void bind(const std::shared_ptr<threading::Reaction>& reaction, /*More arguments can be declared*/)
46+
static void bind(const std::shared_ptr<threading::Reaction>& reaction, /*More arguments can be declared*/)
4747

4848
This function is called when the reaction is bound, it should be thought of as the constructor. It is used to setup
4949
anything that is required by the DSL word.
@@ -68,7 +68,7 @@ Get
6868

6969
.. codeblock:: c++
7070
template <typename DSL>
71-
static inline T get(threading::Reaction&)
71+
static T get(threading::Reaction& reaction)
7272

7373
This is used to get the data for the callback. The returned value is passed to the callback.
7474

@@ -84,7 +84,7 @@ Precondition
8484

8585
.. codeblock:: c++
8686
template <typename DSL>
87-
static inline bool precondition(threading::Reaction& reaction)
87+
static bool precondition(threading::Reaction& reaction)
8888

8989
A precondition is used to test if the reaction should run. On a true return the reaction will run as normal. On a false
9090
return the reaction will be dropped.
@@ -103,7 +103,7 @@ Reschedule
103103

104104
.. codeblock:: c++
105105
template <typename DSL>
106-
static inline std::unique_ptr<threading::ReactionTask> reschedule(std::unique_ptr<threading::ReactionTask>&& task)
106+
static std::unique_ptr<threading::Reaction> reschedule(std::unique_ptr<threading::Reaction>&& task)
107107

108108
The ownership of the reaction task is passed to the DSL word. The task returned will be run instead of the passed in
109109
reaction task. If the returned task is the one passed in the task will be run normally.
@@ -167,7 +167,7 @@ Now we define the `reschedule` to interrupt any new tasks if we are currently ru
167167
multithreaded so a mutex is needed when accessing the static members.
168168
.. codeblock:: c++
169169
template <typename DSL>
170-
static inline std::unique_ptr<threading::ReactionTask> reschedule(
170+
static std::unique_ptr<threading::ReactionTask> reschedule(
171171
std::unique_ptr<threading::ReactionTask>&& task) {
172172

173173
// Lock our mutex

docs/networking.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ checks explicitly for an explicit type. Be careful about multiple declarations.
4343
For this partial specialisation three static methods need to be defined.
4444

4545
.. codeblock:: c++
46-
static inline std::vector<uint8_t> serialise(const T& in)
46+
static std::vector<uint8_t> serialise(const T& in)
4747

48-
static inline T deserialise(const std::vector<uint8_t>& in)
48+
static T deserialise(const std::vector<uint8_t>& in)
4949

50-
static inline uint64_t hash()
50+
static uint64_t hash()

src/PowerPlant.cpp

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,49 @@
2222

2323
#include "PowerPlant.hpp"
2424

25+
#include <exception>
26+
#include <tuple>
27+
28+
#include "Reactor.hpp"
29+
#include "dsl/store/DataStore.hpp"
30+
#include "dsl/word/Shutdown.hpp"
31+
#include "dsl/word/Startup.hpp"
32+
#include "dsl/word/emit/Direct.hpp"
33+
#include "message/CommandLineArguments.hpp"
34+
#include "message/LogMessage.hpp"
35+
#include "threading/ReactionTask.hpp"
36+
2537
namespace NUClear {
38+
namespace util {
39+
struct GroupDescriptor;
40+
struct ThreadPoolDescriptor;
41+
} // namespace util
2642

2743
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
2844
PowerPlant* PowerPlant::powerplant = nullptr;
2945

46+
// This is taking argc and argv as given by main so this should not take an array
47+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
48+
PowerPlant::PowerPlant(Configuration config, int argc, const char* argv[]) : scheduler(config.thread_count) {
49+
50+
// Stop people from making more then one powerplant
51+
if (powerplant != nullptr) {
52+
throw std::runtime_error("There is already a powerplant in existence (There should be a single PowerPlant)");
53+
}
54+
55+
// Store our static variable
56+
powerplant = this;
57+
58+
// Emit our arguments if any.
59+
message::CommandLineArguments args;
60+
for (int i = 0; i < argc; ++i) {
61+
args.emplace_back(argv[i]);
62+
}
63+
64+
// Emit our command line arguments
65+
emit(std::make_unique<message::CommandLineArguments>(args));
66+
}
67+
3068
PowerPlant::~PowerPlant() {
3169
// Make sure reactors are destroyed before anything else
3270
while (!reactors.empty()) {
@@ -50,6 +88,16 @@ void PowerPlant::start() {
5088
scheduler.start();
5189
}
5290

91+
void PowerPlant::add_idle_task(const NUClear::id_t& id,
92+
const util::ThreadPoolDescriptor& pool_descriptor,
93+
std::function<void()>&& task) {
94+
scheduler.add_idle_task(id, pool_descriptor, std::move(task));
95+
}
96+
97+
void PowerPlant::remove_idle_task(const NUClear::id_t& id, const util::ThreadPoolDescriptor& pool_descriptor) {
98+
scheduler.remove_idle_task(id, pool_descriptor);
99+
}
100+
53101
void PowerPlant::submit(const NUClear::id_t& id,
54102
const int& priority,
55103
const util::GroupDescriptor& group,
@@ -75,14 +123,19 @@ void PowerPlant::submit(std::unique_ptr<threading::ReactionTask>&& task, const b
75123
}
76124
}
77125

78-
void PowerPlant::add_idle_task(const NUClear::id_t& id,
79-
const util::ThreadPoolDescriptor& pool_descriptor,
80-
std::function<void()>&& task) {
81-
scheduler.add_idle_task(id, pool_descriptor, std::move(task));
82-
}
126+
void PowerPlant::log(const LogLevel& level, std::string message) {
127+
// Get the current task
128+
const auto* current_task = threading::ReactionTask::get_current_task();
83129

84-
void PowerPlant::remove_idle_task(const NUClear::id_t& id, const util::ThreadPoolDescriptor& pool_descriptor) {
85-
scheduler.remove_idle_task(id, pool_descriptor);
130+
// Direct emit the log message so that any direct loggers can use it
131+
emit<dsl::word::emit::Direct>(std::make_unique<message::LogMessage>(
132+
level,
133+
current_task != nullptr ? current_task->parent.reactor.log_level : LogLevel::UNKNOWN,
134+
std::move(message),
135+
current_task != nullptr ? current_task->stats : nullptr));
136+
}
137+
void PowerPlant::log(const LogLevel& level, std::stringstream& message) {
138+
log(level, message.str());
86139
}
87140

88141
void PowerPlant::shutdown() {
@@ -101,4 +154,5 @@ void PowerPlant::shutdown() {
101154
bool PowerPlant::running() const {
102155
return is_running.load();
103156
}
157+
104158
} // namespace NUClear

0 commit comments

Comments
 (0)