module: Implement action router (#2336)
* module: Implement proof of concept action router Action implementation inside module becomes much cleaner because each module just registers action names together with a callback (pointer to member function) and the action router does the rest. * Make input function final This forces all modules to use the action router * modules: Catch exceptions in action handlers * Use action router for all modules * Use action_ prefix for function names The mpd module's 'stop' action overwrote the base module's stop function which caused difficult to debug behavior. To prevent this in the future we now prefix each function that is responsible for an action with 'action_' * Cleanup * actions: Throw exception when re-registering action Action names are unique inside modules. Unfortunately there is no way to ensure this statically, the next best thing is to crash the module and let the user know that this is a bug. * Formatting * actions: Ignore data for actions without data This is the same behavior as before. * action_router: Write tests
This commit is contained in:
parent
7521da900f
commit
26be83f893
30 changed files with 585 additions and 356 deletions
src/components
|
@ -472,8 +472,6 @@ bool controller::try_forward_legacy_action(const string& cmd) {
|
|||
for (auto&& module : m_modules) {
|
||||
if (module->type() == type) {
|
||||
auto module_name = module->name_raw();
|
||||
// TODO make this message more descriptive and maybe link to some documentation
|
||||
// TODO use route to string methods to print action name that should be used.
|
||||
if (data.empty()) {
|
||||
m_log.warn("The action '%s' is deprecated, use '#%s.%s' instead!", cmd, module_name, action);
|
||||
} else {
|
||||
|
@ -546,7 +544,8 @@ void controller::switch_module_visibility(string module_name_raw, int visible) {
|
|||
return;
|
||||
}
|
||||
|
||||
m_log.err("controller: Module '%s' not found for visibility change (state=%s)", module_name_raw, visible ? "shown" : "hidden");
|
||||
m_log.err("controller: Module '%s' not found for visibility change (state=%s)", module_name_raw,
|
||||
visible ? "shown" : "hidden");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -694,8 +693,6 @@ bool controller::process_update(bool force) {
|
|||
* Creates module instances for all the modules in the given alignment block
|
||||
*/
|
||||
size_t controller::setup_modules(alignment align) {
|
||||
size_t count{0};
|
||||
|
||||
string key;
|
||||
|
||||
switch (align) {
|
||||
|
@ -739,13 +736,12 @@ size_t controller::setup_modules(alignment align) {
|
|||
|
||||
m_modules.push_back(module);
|
||||
m_blocks[align].push_back(module);
|
||||
count++;
|
||||
} catch (const runtime_error& err) {
|
||||
} catch (const std::exception& err) {
|
||||
m_log.err("Disabling module \"%s\" (reason: %s)", module_name, err.what());
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
return m_modules.size();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue