-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (BehaviorKit): Add structure to play behaviors
interface::Behavior and interface::BehaviorKit BehaviorID Register behaviors Use eventloop to start and stop behavior Unit tests + mock
- Loading branch information
1 parent
b5ef089
commit 698d6d8
Showing
9 changed files
with
266 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Leka - LekaOS | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <span> | ||
|
||
#include "interface/Behavior.h" | ||
#include "internal/BehaviorID.h" | ||
|
||
namespace leka::interface { | ||
|
||
class BehaviorKit | ||
{ | ||
public: | ||
virtual ~BehaviorKit() = default; | ||
|
||
virtual void registerBehaviors(std::span<interface::Behavior *> behaviors) = 0; | ||
virtual void start(interface::Behavior *behavior) = 0; | ||
virtual void start(BehaviorID id) = 0; | ||
virtual void stop() = 0; | ||
}; | ||
|
||
} // namespace leka::interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Leka - LekaOS | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
#include "../internal/BehaviorID.h" | ||
|
||
namespace leka::interface { | ||
|
||
struct Behavior { | ||
virtual ~Behavior() = default; | ||
|
||
virtual auto id() -> BehaviorID = 0; | ||
|
||
virtual void run() = 0; | ||
virtual void stop() = 0; | ||
}; | ||
|
||
} // namespace leka::interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Leka - LekaOS | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
using BehaviorID = uint16_t; | ||
|
||
namespace leka::behavior_id { | ||
|
||
inline constexpr BehaviorID none = 0x0000; | ||
|
||
} // namespace leka::behavior_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Leka - LekaOS | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <array> | ||
|
||
#include "gtest/gtest.h" | ||
#include "interface/Behavior.h" | ||
|
||
using namespace leka; | ||
|
||
TEST(BehaviorIDTest, behaviorsHaveUniqueID) | ||
{ | ||
// auto all_behaviors = std::to_array<interface::Behavior *>({}); | ||
std::array<interface::Behavior *, 0> all_behaviors = | ||
{}; // TODO: to remove, only for empty list, use above instead | ||
|
||
auto comparator = [](interface::Behavior *a, interface::Behavior *b) { return a->id() < b->id(); }; | ||
std::sort(all_behaviors.begin(), all_behaviors.end(), comparator); | ||
|
||
auto array_size = std::size(all_behaviors); | ||
if (array_size <= 1) { | ||
return; | ||
} | ||
|
||
for (auto i = 1; i < array_size; i++) { | ||
ASSERT_NE(all_behaviors.at(i - 1)->id(), all_behaviors.at(i)->id()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Leka - LekaOS | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "gmock/gmock.h" | ||
#include "interface/Behavior.h" | ||
|
||
namespace leka::mock { | ||
|
||
class Behavior : public interface::Behavior | ||
{ | ||
public: | ||
MOCK_METHOD(BehaviorID, id, (), (override)); | ||
|
||
MOCK_METHOD(void, run, (), (override)); | ||
MOCK_METHOD(void, stop, (), (override)); | ||
}; | ||
|
||
} // namespace leka::mock |