|
21 | 21 |
|
22 | 22 | #pragma once
|
23 | 23 |
|
24 |
| -#include <memory> // for unique_ptr<>, shared_ptr<> |
25 |
| -#include <string> // for string |
| 24 | +#include <memory> // for unique_ptr<>, shared_ptr<> |
| 25 | +#include <string> // for string |
| 26 | +#include <string_view> // for string_view |
26 | 27 |
|
27 |
| -#include <cloe/registrar.hpp> // for cloe::Registrar |
| 28 | +#include <cloe/core/logger.hpp> // for logger::get |
| 29 | +#include <cloe/registrar.hpp> // for cloe::Registrar |
28 | 30 |
|
| 31 | +#include "config.hpp" // for CLOE_TRIGGER_PATH_DELIMITER, ... |
29 | 32 | #include "coordinator.hpp" // for Coordinator
|
30 | 33 | #include "server.hpp" // for Server, ServerRegistrar
|
31 | 34 |
|
@@ -59,55 +62,69 @@ class Registrar : public cloe::Registrar {
|
59 | 62 | server_registrar_->register_api_handler(endpoint, t, h);
|
60 | 63 | }
|
61 | 64 |
|
62 |
| - std::unique_ptr<cloe::Registrar> clone() const { |
| 65 | + [[nodiscard]] std::unique_ptr<cloe::Registrar> clone() const { |
63 | 66 | return std::make_unique<Registrar>(*this, "", "", "");
|
64 | 67 | }
|
65 | 68 |
|
66 | 69 | std::unique_ptr<cloe::Registrar> with_static_prefix(const std::string& prefix) const override {
|
67 |
| - assert(prefix.size() > 0); |
| 70 | + assert(!prefix.empty()); |
68 | 71 | return std::make_unique<Registrar>(*this, "", prefix, "");
|
69 | 72 | }
|
70 | 73 |
|
71 | 74 | std::unique_ptr<cloe::Registrar> with_api_prefix(const std::string& prefix) const override {
|
72 |
| - assert(prefix.size() > 0); |
| 75 | + assert(!prefix.empty()); |
73 | 76 | return std::make_unique<Registrar>(*this, "", "", prefix);
|
74 | 77 | }
|
75 | 78 |
|
76 | 79 | std::unique_ptr<cloe::Registrar> with_trigger_prefix(const std::string& prefix) const override {
|
77 |
| - assert(prefix.size() > 0 && prefix[0] != '_'); |
| 80 | + assert(!prefix.empty() && prefix[0] != '_'); |
78 | 81 | return std::make_unique<Registrar>(*this, prefix, "", "");
|
79 | 82 | }
|
80 | 83 |
|
81 |
| - std::string trigger_key(const std::string& name) { |
82 |
| - assert(name.size() != 0); |
| 84 | + [[nodiscard]] std::string make_prefix(std::string_view name, std::string_view delim) const { |
| 85 | + assert(!name.empty()); |
83 | 86 |
|
84 |
| - if (trigger_prefix_.size() == 0) { |
| 87 | + if (trigger_prefix_.empty()) { |
85 | 88 | // This only works for Cloe internal triggers.
|
86 |
| - return name; |
| 89 | + return std::string(name); |
87 | 90 | }
|
| 91 | + |
| 92 | + std::string prefix = trigger_prefix_; |
88 | 93 | if (name == "_") {
|
89 | 94 | // Special case: "_" means we can actually use just trigger_prefix_.
|
90 | 95 | // This might cause a problem if we name a plugin the same as one
|
91 | 96 | // of the internal Cloe triggers...
|
92 |
| - return trigger_prefix_; |
| 97 | + return prefix; |
93 | 98 | }
|
94 |
| - return trigger_prefix_ + "/" + name; |
| 99 | + prefix += delim; |
| 100 | + prefix += name; |
| 101 | + return prefix; |
| 102 | + } |
| 103 | + |
| 104 | + [[nodiscard]] std::string make_trigger_name(std::string_view name) const { |
| 105 | + return make_prefix(name, CLOE_TRIGGER_PATH_DELIMITER); |
| 106 | + } |
| 107 | + |
| 108 | + [[nodiscard]] std::string make_signal_name(std::string_view name) const override { |
| 109 | + auto sname = make_prefix(name, CLOE_SIGNAL_PATH_DELIMITER); |
| 110 | + coordinator_->logger()->debug("Register signal: {}", sname); |
| 111 | + return sname; |
95 | 112 | }
|
96 | 113 |
|
97 | 114 | void register_action(cloe::ActionFactoryPtr&& af) override {
|
98 |
| - coordinator_->register_action(trigger_key(af->name()), std::move(af)); |
| 115 | + coordinator_->register_action(make_trigger_name(af->name()), std::move(af)); |
99 | 116 | }
|
100 | 117 |
|
101 | 118 | void register_event(
|
102 | 119 | cloe::EventFactoryPtr&& ef, std::shared_ptr<cloe::Callback> storage) override {
|
103 |
| - coordinator_->register_event(trigger_key(ef->name()), std::move(ef), storage); |
| 120 | + coordinator_->register_event(make_trigger_name(ef->name()), std::move(ef), storage); |
104 | 121 | }
|
105 | 122 |
|
106 | 123 | sol::table register_lua_table() override {
|
107 | 124 | return coordinator_->register_lua_table(trigger_prefix_);
|
108 | 125 | }
|
109 | 126 |
|
110 |
| - cloe::DataBroker& data_broker() const override { |
| 127 | + [[nodiscard]] cloe::DataBroker& data_broker() const override { |
111 | 128 | assert(data_broker_ != nullptr);
|
112 | 129 | return *data_broker_;
|
113 | 130 | }
|
|
0 commit comments