26static bool inited =
false;
28static avl_tree_t cmds;
32 XPLMCommandCallback_f cb;
44reg_dr_compar(
const void *a,
const void *b)
47 int res = strcmp(ra->dr.name, rb->dr.name);
57reg_cmd_compar(
const void *a,
const void *b)
59 int res = memcmp(a, b, offsetof(
reg_cmd_t, node));
115 XPLMUnregisterCommandHandler(cmd->cmd, cmd->cb, cmd->before,
149 ASSERT(rdr->dr.dr != NULL);
152 "Duplicate dataref registration for dr %s\n", rdr->dr.name);
179 va_start(ap, refcon);
193 void *refcon, va_list ap)
205 cmd->cmd = XPLMFindCommand(cmdname);
206 if (cmd->cmd == NULL) {
212 cmd->before = before;
213 cmd->refcon = refcon;
215 XPLMRegisterCommandHandler(cmd->cmd, cb, before, refcon);
218 "Found duplicate registration of command %s with cb: %p "
219 "before: %d, refcon: %p", cmdname, cb, before, refcon);
240 va_start(ap, refcon);
255 void *refcon, va_list ap)
264 VERIFY_MSG(ref != NULL,
"Command %s not found",
290 XPLMCommandCallback_f cb,
bool before,
void *refcon)
296 ref = XPLMCreateCommand(cmdname, cmddesc);
298 "Cannot create command %s: XPLMCreateCommand failed", cmdname);
#define VERIFY_MSG(x, fmt,...)
void * avl_destroy_nodes(avl_tree_t *tree, void **cookie)
void avl_insert(avl_tree_t *tree, void *node, avl_index_t where)
void avl_create(avl_tree_t *tree, int(*compar)(const void *, const void *), size_t size, size_t offset)
void avl_destroy(avl_tree_t *tree)
void * avl_find(const avl_tree_t *tree, const void *node, avl_index_t *where)
XPLMCommandRef dcr_find_cmd(const char *fmt, XPLMCommandCallback_f cb, bool before, void *refcon,...)
XPLMCommandRef f_dcr_find_cmd_v(const char *fmt, XPLMCommandCallback_f cb, bool before, void *refcon, va_list ap)
dr_t * dcr_get_dr(void *token)
void dcr_insert_rdr(void *token)
XPLMCommandRef f_dcr_find_cmd(const char *fmt, XPLMCommandCallback_f cb, bool before, void *refcon,...)
void * dcr_alloc_rdr(void)
XPLMCommandRef dcr_create_cmd(const char *cmdname, const char *cmddesc, XPLMCommandCallback_f cb, bool before, void *refcon)
XPLMCommandRef dcr_find_cmd_v(const char *fmt, XPLMCommandCallback_f cb, bool before, void *refcon, va_list ap)
static char * vsprintf_alloc(const char *fmt, va_list ap)
static void * safe_calloc(size_t nmemb, size_t size)