Skip to content

Commit

Permalink
update(core/mod): added a macro to perform bound modules checking.
Browse files Browse the repository at this point in the history
Moreover, fixed build.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
  • Loading branch information
FedeDP committed May 1, 2022
1 parent 1b32343 commit 4e996ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
36 changes: 12 additions & 24 deletions Lib/core/mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,55 +612,43 @@ _public_ m_ctx_t *m_mod_ctx(const m_mod_t *mod) {

/** Module state setters **/

#define M_MOD_BOUND(fn) \
if (ret == 0) { \
m_itr_foreach(mod->bound_mods, { \
m_mod_t *bmod = m_itr_get(m_itr); \
fn(bmod); \
}); \
}

_public_ int m_mod_start(m_mod_t *mod) {
M_MOD_ASSERT_STATE(mod, M_MOD_IDLE | M_MOD_STOPPED);

int ret = start(mod, true);
if (ret == 0) {
m_itr_foreach(mod->bound_mods, {
m_mod_t *bmod = m_itr_get(m_itr);
m_mod_start(bmod);
});
}
M_MOD_BOUND(m_mod_start);
return ret;
}

_public_ int m_mod_pause(m_mod_t *mod) {
M_MOD_ASSERT_STATE(mod, M_MOD_RUNNING);

int ret = stop(mod, false);
if (ret == 0) {
m_itr_foreach(mod->bound_mods, {
m_mod_t *bmod = m_itr_get(m_itr);
m_mod_pause(bmod);
});
}
M_MOD_BOUND(m_mod_pause);
return ret;
}

_public_ int m_mod_resume(m_mod_t *mod) {
M_MOD_ASSERT_STATE(mod, M_MOD_PAUSED);

int ret = start(mod, false);
if (ret == 0) {
m_itr_foreach(mod->bound_mods, {
m_mod_t *bmod = m_itr_get(m_itr);
m_mod_resume(bmod);
});
}
M_MOD_BOUND(m_mod_resume);
return ret;
}

_public_ int m_mod_stop(m_mod_t *mod) {
M_MOD_ASSERT_STATE(mod, M_MOD_RUNNING | M_MOD_PAUSED);

int ret = stop(mod, true);
if (ret == 0) {
m_itr_foreach(mod->bound_mods, {
m_mod_t *bmod = m_itr_get(m_itr);
m_mod_stop(bmod);
});
}
M_MOD_BOUND(m_mod_stop);
return ret;
}

Expand Down
1 change: 0 additions & 1 deletion Samples/Easy/doggo.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <module/mod_easy.h>
#include <module/plugin.h>
#include <module/ctx.h>
#include <string.h>
#include <stdlib.h>
Expand Down

0 comments on commit 4e996ce

Please sign in to comment.