Skip to content

Commit

Permalink
Merge branch 'main' into houliston/fix-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentHouliston authored Oct 26, 2024
2 parents d84c30b + 3350a93 commit 9c7ca70
Show file tree
Hide file tree
Showing 30 changed files with 586 additions and 514 deletions.
8 changes: 8 additions & 0 deletions src/Reactor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ namespace dsl {

struct MainThread;

template <typename T>
struct TaskScope;

template <typename>
struct Network;

Expand Down Expand Up @@ -225,6 +228,10 @@ class Reactor {
/// @copydoc dsl::word::MainThread
using MainThread = dsl::word::MainThread;

/// @copydoc dsl::word::TaskScope
template <typename T>
using TaskScope = dsl::word::TaskScope<T>;

/// @copydoc dsl::word::Startup
using Startup = dsl::word::Startup;

Expand Down Expand Up @@ -474,6 +481,7 @@ class Reactor {
#include "dsl/word/Startup.hpp"
#include "dsl/word/Sync.hpp"
#include "dsl/word/TCP.hpp"
#include "dsl/word/TaskScope.hpp"
#include "dsl/word/Trigger.hpp"
#include "dsl/word/UDP.hpp"
#include "dsl/word/Watchdog.hpp"
Expand Down
10 changes: 7 additions & 3 deletions src/dsl/Fusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
#include "fusion/GroupFusion.hpp"
#include "fusion/InlineFusion.hpp"
#include "fusion/PoolFusion.hpp"
#include "fusion/PostconditionFusion.hpp"
#include "fusion/PostRunFusion.hpp"
#include "fusion/PreRunFusion.hpp"
#include "fusion/PreconditionFusion.hpp"
#include "fusion/PriorityFusion.hpp"
#include "fusion/ScopeFusion.hpp"

namespace NUClear {
namespace dsl {
Expand All @@ -43,10 +45,12 @@ namespace dsl {
, fusion::GetFusion<Words...>
, fusion::GroupFusion<Words...>
, fusion::InlineFusion<Words...>
, fusion::PoolFusion<Words...>
, fusion::PostRunFusion<Words...>
, fusion::PreRunFusion<Words...>
, fusion::PreconditionFusion<Words...>
, fusion::PriorityFusion<Words...>
, fusion::PoolFusion<Words...>
, fusion::PostconditionFusion<Words...> {};
, fusion::ScopeFusion<Words...> {};

} // namespace dsl
} // namespace NUClear
Expand Down
27 changes: 19 additions & 8 deletions src/dsl/Parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,36 @@ namespace dsl {
Parse<Sentence...>>(task);
}

static bool precondition(threading::ReactionTask& task) {
return std::conditional_t<fusion::has_precondition<DSL>::value, DSL, fusion::NoOp>::template precondition<
static std::shared_ptr<const util::ThreadPoolDescriptor> pool(threading::ReactionTask& task) {
return std::conditional_t<fusion::has_pool<DSL>::value, DSL, fusion::NoOp>::template pool<
Parse<Sentence...>>(task);
}

static int priority(threading::ReactionTask& task) {
return std::conditional_t<fusion::has_priority<DSL>::value, DSL, fusion::NoOp>::template priority<
static void post_run(threading::ReactionTask& task) {
std::conditional_t<fusion::has_post_run<DSL>::value, DSL, fusion::NoOp>::template post_run<
Parse<Sentence...>>(task);
}
static void pre_run(threading::ReactionTask& task) {
std::conditional_t<fusion::has_pre_run<DSL>::value, DSL, fusion::NoOp>::template pre_run<
Parse<Sentence...>>(task);
}

static std::shared_ptr<const util::ThreadPoolDescriptor> pool(threading::ReactionTask& task) {
return std::conditional_t<fusion::has_pool<DSL>::value, DSL, fusion::NoOp>::template pool<
static bool precondition(threading::ReactionTask& task) {
return std::conditional_t<fusion::has_precondition<DSL>::value, DSL, fusion::NoOp>::template precondition<
Parse<Sentence...>>(task);
}

static void postcondition(threading::ReactionTask& task) {
std::conditional_t<fusion::has_postcondition<DSL>::value, DSL, fusion::NoOp>::template postcondition<
static int priority(threading::ReactionTask& task) {
return std::conditional_t<fusion::has_priority<DSL>::value, DSL, fusion::NoOp>::template priority<
Parse<Sentence...>>(task);
}

static auto scope(threading::ReactionTask& task)
-> decltype(std::conditional_t<fusion::has_scope<DSL>::value, DSL, fusion::NoOp>::template scope<
Parse<Sentence...>>(task)) {
return std::conditional_t<fusion::has_scope<DSL>::value, DSL, fusion::NoOp>::template scope<Parse<Sentence...>>(
task);
}
};

} // namespace dsl
Expand Down
5 changes: 4 additions & 1 deletion src/dsl/fusion/BindFusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
#include "../../util/FunctionFusion.hpp"
#include "../operation/DSLProxy.hpp"
#include "FindWords.hpp"
#include "has_bind.hpp"
#include "has_nuclear_dsl_method.hpp"

namespace NUClear {
namespace dsl {
namespace fusion {

/// Make a SFINAE type to check if a word has a run_inline method
HAS_NUCLEAR_DSL_METHOD(bind);

/**
* This is our Function Fusion wrapper class that allows it to call bind functions.
*
Expand Down
5 changes: 4 additions & 1 deletion src/dsl/fusion/GetFusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
#include "../../util/tuplify.hpp"
#include "../operation/DSLProxy.hpp"
#include "FindWords.hpp"
#include "has_get.hpp"
#include "has_nuclear_dsl_method.hpp"

namespace NUClear {
namespace dsl {
namespace fusion {

/// Make a SFINAE type to check if a word has a get method
HAS_NUCLEAR_DSL_METHOD(get);

/**
* This is our Function Fusion wrapper class that allows it to call get functions.
*
Expand Down
5 changes: 4 additions & 1 deletion src/dsl/fusion/GroupFusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
#include "../../threading/Reaction.hpp"
#include "../operation/DSLProxy.hpp"
#include "FindWords.hpp"
#include "has_group.hpp"
#include "has_nuclear_dsl_method.hpp"

namespace NUClear {
namespace dsl {
namespace fusion {

/// Make a SFINAE type to check if a word has a group method
HAS_NUCLEAR_DSL_METHOD(group);

// Default case where there are no group words
template <typename Words>
struct GroupFuser {};
Expand Down
5 changes: 4 additions & 1 deletion src/dsl/fusion/InlineFusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
#include "../../util/Inline.hpp"
#include "../operation/DSLProxy.hpp"
#include "FindWords.hpp"
#include "has_run_inline.hpp"
#include "has_nuclear_dsl_method.hpp"

namespace NUClear {
namespace dsl {
namespace fusion {

/// Make a SFINAE type to check if a word has a run_inline method
HAS_NUCLEAR_DSL_METHOD(run_inline);

// Default case where there are no Inline words
template <typename Words>
struct InlineFuser {};
Expand Down
20 changes: 17 additions & 3 deletions src/dsl/fusion/NoOp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ namespace dsl {
return true;
}

template <typename DSL>
static void post_run(const threading::ReactionTask& /*task*/) {
// Empty as this is a no-op placeholder
}

template <typename DSL>
static void pre_run(const threading::ReactionTask& /*task*/) {
// Empty as this is a no-op placeholder
}

template <typename DSL>
static int priority(const threading::ReactionTask& /*task*/) {
return word::Priority::NORMAL::value;
Expand All @@ -80,8 +90,8 @@ namespace dsl {
}

template <typename DSL>
static void postcondition(const threading::ReactionTask& /*task*/) {
// Empty as this is a no-op placeholder
static std::tuple<> scope(const threading::ReactionTask& /*task*/) {
return {};
}
};

Expand All @@ -102,11 +112,15 @@ namespace dsl {

static bool precondition(threading::ReactionTask&);

static void post_run(threading::ReactionTask&);

static void pre_run(threading::ReactionTask&);

static int priority(threading::ReactionTask&);

static std::shared_ptr<const util::ThreadPoolDescriptor> pool(threading::ReactionTask&);

static void postcondition(threading::ReactionTask&);
static std::tuple<> scope(threading::ReactionTask&);
};

} // namespace fusion
Expand Down
5 changes: 4 additions & 1 deletion src/dsl/fusion/PoolFusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
#include "../../threading/ReactionTask.hpp"
#include "../operation/DSLProxy.hpp"
#include "FindWords.hpp"
#include "has_pool.hpp"
#include "has_nuclear_dsl_method.hpp"

namespace NUClear {
namespace dsl {
namespace fusion {

/// Make a SFINAE type to check if a word has a pool method
HAS_NUCLEAR_DSL_METHOD(pool);

// Default case where there are no pool words
template <typename Words>
struct PoolFuser {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,57 @@
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef NUCLEAR_DSL_FUSION_POSTCONDITION_FUSION_HPP
#define NUCLEAR_DSL_FUSION_POSTCONDITION_FUSION_HPP
#ifndef NUCLEAR_DSL_FUSION_POST_RUN_FUSION_HPP
#define NUCLEAR_DSL_FUSION_POST_RUN_FUSION_HPP

#include "../../threading/ReactionTask.hpp"
#include "../operation/DSLProxy.hpp"
#include "FindWords.hpp"
#include "has_postcondition.hpp"
#include "has_nuclear_dsl_method.hpp"

namespace NUClear {
namespace dsl {
namespace fusion {

// Default case where there are no postcondition words
/// Make a SFINAE type to check if a word has a post_run method
HAS_NUCLEAR_DSL_METHOD(post_run);

// Default case where there are no post_run words
template <typename Words>
struct PostconditionFuser {};
struct PostRunFuser {};

// Case where there is only a single word remaining
template <typename Word>
struct PostconditionFuser<std::tuple<Word>> {
struct PostRunFuser<std::tuple<Word>> {

template <typename DSL>
static void postcondition(threading::ReactionTask& task) {
static void post_run(threading::ReactionTask& task) {

// Run our remaining postcondition
Word::template postcondition<DSL>(task);
// Run our remaining post_run
Word::template post_run<DSL>(task);
}
};

// Case where there is more 2 more more words remaining
template <typename Word1, typename Word2, typename... WordN>
struct PostconditionFuser<std::tuple<Word1, Word2, WordN...>> {
struct PostRunFuser<std::tuple<Word1, Word2, WordN...>> {

template <typename DSL>
static void postcondition(threading::ReactionTask& task) {
static void post_run(threading::ReactionTask& task) {

// Run our postcondition
Word1::template postcondition<DSL>(task);
// Run our post_run
Word1::template post_run<DSL>(task);

// Run the rest of our postconditions
PostconditionFuser<std::tuple<Word2, WordN...>>::template postcondition<DSL>(task);
// Run the rest of our post_runs
PostRunFuser<std::tuple<Word2, WordN...>>::template post_run<DSL>(task);
}
};

template <typename Word1, typename... WordN>
struct PostconditionFusion : PostconditionFuser<FindWords<has_postcondition, Word1, WordN...>> {};
struct PostRunFusion : PostRunFuser<FindWords<has_post_run, Word1, WordN...>> {};

} // namespace fusion
} // namespace dsl
} // namespace NUClear

#endif // NUCLEAR_DSL_FUSION_POSTCONDITION_FUSION_HPP
#endif // NUCLEAR_DSL_FUSION_POST_RUN_FUSION_HPP
76 changes: 76 additions & 0 deletions src/dsl/fusion/PreRunFusion.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* MIT License
*
* Copyright (c) 2024 NUClear Contributors
*
* This file is part of the NUClear codebase.
* See https://github.com/Fastcode/NUClear for further info.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef NUCLEAR_DSL_FUSION_PRE_RUN_FUSION_HPP
#define NUCLEAR_DSL_FUSION_PRE_RUN_FUSION_HPP

#include "../../threading/ReactionTask.hpp"
#include "../operation/DSLProxy.hpp"
#include "FindWords.hpp"
#include "has_nuclear_dsl_method.hpp"

namespace NUClear {
namespace dsl {
namespace fusion {

/// Make a SFINAE type to check if a word has a pre_run method
HAS_NUCLEAR_DSL_METHOD(pre_run);

// Default case where there are no pre_run words
template <typename Words>
struct PreRunFuser {};

// Case where there is only a single word remaining
template <typename Word>
struct PreRunFuser<std::tuple<Word>> {

template <typename DSL>
static void pre_run(threading::ReactionTask& task) {

// Run our remaining pre_run
Word::template pre_run<DSL>(task);
}
};

// Case where there is more 2 more more words remaining
template <typename Word1, typename Word2, typename... WordN>
struct PreRunFuser<std::tuple<Word1, Word2, WordN...>> {

template <typename DSL>
static void pre_run(threading::ReactionTask& task) {

// Run our pre_run
Word1::template pre_run<DSL>(task);

// Run the rest of our pre_runs
PreRunFuser<std::tuple<Word2, WordN...>>::template pre_run<DSL>(task);
}
};

template <typename Word1, typename... WordN>
struct PreRunFusion : PreRunFuser<FindWords<has_pre_run, Word1, WordN...>> {};

} // namespace fusion
} // namespace dsl
} // namespace NUClear

#endif // NUCLEAR_DSL_FUSION_PRE_RUN_FUSION_HPP
Loading

0 comments on commit 9c7ca70

Please sign in to comment.