libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
Typedefs | Functions
cmd.h File Reference
#include <stdarg.h>
#include <XPLMUtilities.h>
#include "sysmacros.h"
Include dependency graph for cmd.h:

Go to the source code of this file.

Typedefs

typedef int(* cmd_cb_t) (XPLMCommandRef ref, XPLMCommandPhase phase, void *refcon)
 

Functions

XPLMCommandRef cmd_find (const char *fmt,...)
 
XPLMCommandRef fcmd_find (const char *fmt,...)
 
XPLMCommandRef cmd_find_v (const char *fmt, va_list ap)
 
XPLMCommandRef fcmd_find_v (const char *fmt, va_list ap)
 
XPLMCommandRef cmd_bind (const char *fmt, cmd_cb_t cb, bool_t before, void *refcon,...)
 
XPLMCommandRef cmd_bind_v (const char *fmt, cmd_cb_t cb, bool_t before, void *refcon, va_list ap)
 
XPLMCommandRef fcmd_bind (const char *fmt, cmd_cb_t cb, bool_t before, void *refcon,...)
 
bool_t cmd_unbind (const char *fmt, cmd_cb_t cb, bool_t before, void *refcon,...)
 
bool_t cmd_unbind_v (const char *fmt, cmd_cb_t cb, bool_t before, void *refcon, va_list ap)
 
void fcmd_unbind (const char *fmt, cmd_cb_t cb, bool_t before, void *refcon,...)
 

Detailed Description

This file contains convenience functions to interact with X-Plane's command handling machinery.

Definition in file cmd.h.

Typedef Documentation

◆ cmd_cb_t

typedef int(* cmd_cb_t) (XPLMCommandRef ref, XPLMCommandPhase phase, void *refcon)

Definition at line 37 of file cmd.h.

Function Documentation

◆ cmd_bind()

XPLMCommandRef cmd_bind ( const char *  fmt,
cmd_cb_t  cb,
bool_t  before,
void *  refcon,
  ... 
)

Performs a combination of an XPLMFindCommand followed by an XPLMRegisterCommandHandler, with support for printf-style command name construction.

Parameters
fmtA printf-style format string that specifies the command name to search for. The variadic arguments must comply with the format string's format specifiers.
cbThe callback to register for the command handler.
beforeSpecifies whether the callback should be invoked before X-Plane handles the command, or after.
refconReference constant that will be passed by X-Plane to the command handler every time cb is called.
Returns
The XPLMCommandRef for the command, if it was found, otherwise NULL. If the command doesn't exist, no callback registration takes place.
See also
https://www.man7.org/linux/man-pages/man3/printf.3.html

Definition at line 110 of file cmd.c.

◆ cmd_bind_v()

XPLMCommandRef cmd_bind_v ( const char *  fmt,
cmd_cb_t  cb,
bool_t  before,
void *  refcon,
va_list  ap 
)

Same as cmd_bind(), but takes a va_list for the format arguments, instead of being variadic.

Definition at line 86 of file cmd.c.

◆ cmd_find()

XPLMCommandRef cmd_find ( const char *  fmt,
  ... 
)

Performs the equivalent of XPLMFindCommand(), but with printf-style auto-formatting support for the command name.

Parameters
fmtA printf-style format string that specifies the command name to search for. The remaining arguments must comply with the format string's format specifiers.
Returns
The XPLMCommandRef for the command, if it was found, otherwise NULL.
See also
https://www.man7.org/linux/man-pages/man3/printf.3.html

Definition at line 48 of file cmd.c.

◆ cmd_find_v()

XPLMCommandRef cmd_find_v ( const char *  fmt,
va_list  ap 
)

Same as cmd_find(), but takes a va_list for the format arguments, instead of being variadic.

Definition at line 74 of file cmd.c.

◆ cmd_unbind()

bool_t cmd_unbind ( const char *  fmt,
cmd_cb_t  cb,
bool_t  before,
void *  refcon,
  ... 
)

Same as cmd_bind(), but instead of registering the callback, unregisters it.

Definition at line 171 of file cmd.c.

◆ cmd_unbind_v()

bool_t cmd_unbind_v ( const char *  fmt,
cmd_cb_t  cb,
bool_t  before,
void *  refcon,
va_list  ap 
)

Same as cmd_bind_v(), but instead of registering the callback, unregisters it.

Definition at line 144 of file cmd.c.

◆ fcmd_bind()

XPLMCommandRef fcmd_bind ( const char *  fmt,
cmd_cb_t  cb,
bool_t  before,
void *  refcon,
  ... 
)

Same as cmd_bind(), but if the command doesn't exist, causes an assertion failure ("f" prefix meaning "force").

Definition at line 123 of file cmd.c.

◆ fcmd_find()

XPLMCommandRef fcmd_find ( const char *  fmt,
  ... 
)

Same as cmd_find(), but if the command doesn't exist, causes an assertion failure ("f" prefix meaning "force").

Definition at line 61 of file cmd.c.

◆ fcmd_find_v()

XPLMCommandRef fcmd_find_v ( const char *  fmt,
va_list  ap 
)

Same as fcmd_find(), but takes a va_list for the format arguments, instead of being variadic.

Definition at line 80 of file cmd.c.

◆ fcmd_unbind()

void fcmd_unbind ( const char *  fmt,
cmd_cb_t  cb,
bool_t  before,
void *  refcon,
  ... 
)

Same as fcmd_bind(), but instead of registering the callback, unregisters it.

Definition at line 184 of file cmd.c.