diff --git a/include/ged/defines.h b/include/ged/defines.h index ce43cdb790..c37aee13dc 100644 --- a/include/ged/defines.h +++ b/include/ged/defines.h @@ -405,9 +405,12 @@ GED_EXPORT extern void ged_init(struct ged *gedp); GED_EXPORT extern void ged_free(struct ged *gedp); -// Associate a callback function pointer for a command. If pre is non-zero, -// function will be registered to run BEFORE actual cmd logic is run, and if -// zero will be registered to run AFTER the cmd logic is run. +// Associate a callback function pointer for a command. If mode is less than zero, +// function will be registered to run BEFORE actual cmd logic is run, and if greater +// than zero will be registered to run AFTER the cmd logic is run. If mode is zero, +// then it is intended to be used *during* command execution and it will be up +// to the command's implementation to incorporate the callback into its +// execution logic. // // Only one function can be registered for each pre/post command slot - an // assignment to a command slot that already has an assigned function will @@ -425,10 +428,10 @@ GED_EXPORT extern void ged_free(struct ged *gedp); // // To clear all command callbacks, iterate over the ged_cmd_list results // and assign NULL f values. -GED_EXPORT extern int ged_clbk_set(struct ged *gedp, const char *cmd, int pre, bu_clbk_t f, void *d); +GED_EXPORT extern int ged_clbk_set(struct ged *gedp, const char *cmd, int mode, bu_clbk_t f, void *d); // Method calling code can use to get the current clbk info for a specific command. -GED_EXPORT extern int ged_clbk_get(bu_clbk_t *f, void **d, struct ged *gedp, const char *cmd, int pre); +GED_EXPORT extern int ged_clbk_get(bu_clbk_t *f, void **d, struct ged *gedp, const char *cmd, int mode); diff --git a/src/libged/exec.cpp b/src/libged/exec.cpp index 0dbf2648dd..8c4929e2a4 100644 --- a/src/libged/exec.cpp +++ b/src/libged/exec.cpp @@ -90,7 +90,7 @@ ged_exec(struct ged *gedp, int argc, const char *argv[]) // We have a command now - check for a pre-exec callback. bu_clbk_t f = NULL; void *d = NULL; - if ((ged_clbk_get(&f, &d, gedp, cmdname.c_str(), 1) == BRLCAD_OK) && f) { + if ((ged_clbk_get(&f, &d, gedp, cmdname.c_str(), -1) == BRLCAD_OK) && f) { cret = (*f)(argc, argv, gedp, d); if (cret != BRLCAD_OK) bu_log("error running %s pre-execution callback\n", cmdname.c_str()); @@ -111,7 +111,7 @@ ged_exec(struct ged *gedp, int argc, const char *argv[]) } // Command execution complete - check for a post command callback. - if ((ged_clbk_get(&f, &d, gedp, cmdname.c_str(), 0) == BRLCAD_OK) && f) { + if ((ged_clbk_get(&f, &d, gedp, cmdname.c_str(), -1) == BRLCAD_OK) && f) { cret = (*f)(argc, argv, gedp, d); if (cret != BRLCAD_OK) bu_log("error running %s post-execution callback\n", cmdname.c_str()); diff --git a/src/libged/ged.cpp b/src/libged/ged.cpp index fcaf0bfcb2..b05ac4ae5b 100644 --- a/src/libged/ged.cpp +++ b/src/libged/ged.cpp @@ -530,7 +530,8 @@ ged_clbk_set(struct ged *gedp, const char *cmd, int pre, bu_clbk_t f, void *d) std::string scmd = std::string(cmd); GED_CK_MAGIC(gedp); Ged_Internal *gedip = gedp->i->i; - std::map> *cm = (pre) ? &gedip->cmd_prerun_clbk : &gedip->cmd_postrun_clbk; + std::map> *cm = (pre < 0) ? &gedip->cmd_prerun_clbk : &gedip->cmd_postrun_clbk; + cm = (pre == 0) ? &gedip->cmd_during_clbk : cm; std::map>::iterator c_it = cm->find(scmd); if (c_it != cm->end()) ret |= GED_OVERRIDE; @@ -549,6 +550,7 @@ ged_clbk_get(bu_clbk_t *f, void **d, struct ged *gedp, const char *cmd, int pre) std::string scmd = std::string(cmd); Ged_Internal *gedip = gedp->i->i; std::map> *cm = (pre) ? &gedip->cmd_prerun_clbk : &gedip->cmd_postrun_clbk; + cm = (pre == 0) ? &gedip->cmd_during_clbk : cm; std::map>::iterator c_it = cm->find(scmd); c_it = cm->find(scmd); if (c_it == cm->end()) { diff --git a/src/libged/ged_private.h b/src/libged/ged_private.h index 9e7b9fe975..2acd0422f3 100644 --- a/src/libged/ged_private.h +++ b/src/libged/ged_private.h @@ -48,6 +48,7 @@ class Ged_Internal { public: struct ged *gedp; std::map> cmd_prerun_clbk; + std::map> cmd_during_clbk; std::map> cmd_postrun_clbk; };