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
dr_cmd_reg.h
Go to the documentation of this file.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license in the file COPYING
10 * or http://www.opensource.org/licenses/CDDL-1.0.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file COPYING.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2025 Saso Kiselkov. All rights reserved.
24 */
49#ifndef _ACF_UTILS_DR_CMD_REG_H_
50#define _ACF_UTILS_DR_CMD_REG_H_
51
52#include <stdarg.h>
53#include <stdbool.h>
54
55#include "cmd.h"
56#include "dr.h"
57
58#ifdef __cplusplus
59extern "C" {
60#endif
61
62API_EXPORT void dcr_init(void);
63API_EXPORT void dcr_fini(void);
64
65API_EXPORT XPLMCommandRef dcr_find_cmd(PRINTF_FORMAT(const char *fmt),
66 XPLMCommandCallback_f cb, bool before, void *refcon, ...)
67 PRINTF_ATTR2(1, 5);
68API_EXPORT XPLMCommandRef dcr_find_cmd_v(const char *fmt,
69 XPLMCommandCallback_f cb, bool before, void *refcon, va_list ap);
70API_EXPORT XPLMCommandRef f_dcr_find_cmd(PRINTF_FORMAT(const char *fmt),
71 XPLMCommandCallback_f cb, bool before, void *refcon, ...)
72 PRINTF_ATTR2(1, 5);
73API_EXPORT XPLMCommandRef f_dcr_find_cmd_v(const char *fmt,
74 XPLMCommandCallback_f cb, bool before, void *refcon, va_list ap);
75API_EXPORT XPLMCommandRef dcr_create_cmd(const char *cmdname,
76 const char *cmddesc, XPLMCommandCallback_f cb, bool before, void *refcon);
77
78API_EXPORT void *dcr_alloc_rdr(void);
79API_EXPORT dr_t *dcr_get_dr(void *token);
80API_EXPORT void dcr_insert_rdr(void *token);
81#ifdef __clang
82#pragma GCC diagnostic push
83#pragma GCC diagnostic ignored "-Wnull-dereference"
84#endif
85
90#define DCR_CREATE_COMMON(type, dr_ptr, ...) \
91 do { \
92 void *__rdr = dcr_alloc_rdr(); \
93 dr_t *__dr = dcr_get_dr(__rdr); \
94 dr_create_ ## type ## _cfg(__dr, __VA_ARGS__); \
95 dcr_insert_rdr(__rdr); \
96 if ((dr_ptr) != NULL) \
97 *(dr_t **)(dr_ptr) = __dr; \
98 } while (0)
115#define DCR_CREATE_I(dr_p, __value, __writable, ...) \
116 DCR_CREATE_COMMON(i, dr_p, __value, \
117 (dr_cfg_t){ .writable = (__writable) }, __VA_ARGS__)
118#define DCR_CREATE_I_CFG(dr_p, __value, __cfg, ...) \
119 DCR_CREATE_COMMON(i, dr_p, __value, __cfg, __VA_ARGS__)
123#define DCR_CREATE_F(dr_p, __value, __writable, ...) \
124 DCR_CREATE_COMMON(f, dr_p, __value, \
125 (dr_cfg_t){ .writable = (__writable) }, __VA_ARGS__)
126#define DCR_CREATE_F_CFG(dr_p, __value, __cfg, ...) \
127 DCR_CREATE_COMMON(f, dr_p, __value, __cfg, __VA_ARGS__)
131#define DCR_CREATE_F64(dr_p, __value, __writable, ...) \
132 DCR_CREATE_COMMON(f64, dr_p, __value, \
133 (dr_cfg_t){ .writable = (__writable) }, __VA_ARGS__)
134#define DCR_CREATE_F64_CFG(dr_p, __value, __cfg, ...) \
135 DCR_CREATE_COMMON(f64, dr_p, __value, __cfg, __VA_ARGS__)
140#define DCR_CREATE_VI(dr_p, __value, __n, __writable, ...) \
141 DCR_CREATE_COMMON(vi, dr_p, __value, \
142 (dr_cfg_t){ .writable = (__writable), .count = (__n) }, __VA_ARGS__)
143#define DCR_CREATE_VI_CFG(dr_p, __value, __cfg, ...) \
144 DCR_CREATE_COMMON(vi, dr_p, __value, __cfg, __VA_ARGS__)
149#define DCR_CREATE_VF(dr_p, __value, __n, __writable, ...) \
150 DCR_CREATE_COMMON(vf, dr_p, __value, \
151 (dr_cfg_t){ .writable = (__writable), .count = (__n)}, __VA_ARGS__)
152#define DCR_CREATE_VF_CFG(dr_p, __value, __cfg, ...) \
153 DCR_CREATE_COMMON(vf, dr_p, __value, __cfg, __VA_ARGS__)
158#define DCR_CREATE_VF64(dr_p, __value, __n, __writable, ...) \
159 DCR_CREATE_COMMON(vf64, dr_p, __value, \
160 (dr_cfg_t){ .writable = (__writable), .count = (__n) }, __VA_ARGS__)
161#define DCR_CREATE_VF64_CFG(dr_p, __value, __cfg, ...) \
162 DCR_CREATE_COMMON(vf64, dr_p, __value, __cfg, __VA_ARGS__)
167#define DCR_CREATE_VI_AUTOSCALAR(dr_p, __value, __n, __writable, ...) \
168 DCR_CREATE_COMMON(vi_autoscalar, dr_p, __value, \
169 (dr_cfg_t){ .writable = (__writable), .count = (__n) }, __VA_ARGS__)
170#define DCR_CREATE_VI_AUTOSCALAR_CFG(dr_p, __value, __cfg, ...) \
171 DCR_CREATE_COMMON(vi_autoscalar, dr_p, __value, __cfg, __VA_ARGS__)
176#define DCR_CREATE_VF_AUTOSCALAR(dr_p, __value, __n, __writable, ...) \
177 DCR_CREATE_COMMON(vf_autoscalar, dr_p, __value, \
178 (dr_cfg_t){ .writable = (__writable), .count = (__n) }, __VA_ARGS__)
179#define DCR_CREATE_VF_AUTOSCALAR_CFG(dr_p, __value, __cfg, ...) \
180 DCR_CREATE_COMMON(vf_autoscalar, dr_p, __value, __cfg, __VA_ARGS__)
185#define DCR_CREATE_VF64_AUTOSCALAR(dr_p, __value, __n, __writable, ...) \
186 DCR_CREATE_COMMON(vf64_autoscalar, dr_p, __value, \
187 (dr_cfg_t){ .writable = (__writable), .count = (__n) }, __VA_ARGS__)
188#define DCR_CREATE_VF64_AUTOSCALAR_CFG(dr_p, __value, __cfg, ...) \
189 DCR_CREATE_COMMON(vf64_autoscalar, dr_p, __value, __cfg, __VA_ARGS__)
194#define DCR_CREATE_B(dr_p, __value, __n, __writable, ...) \
195 DCR_CREATE_COMMON(b, dr_p, __value, \
196 (dr_cfg_t){ .writable = (__writable), .count = (__n) }, __VA_ARGS__)
197#define DCR_CREATE_B_CFG(dr_p, __value, __cfg, ...) \
198 DCR_CREATE_COMMON(b, dr_p, __value, __cfg, __VA_ARGS__)
199
200#ifdef __clang
201#pragma GCC diagnostic pop
202#endif
203
204#ifdef __cplusplus
205}
206#endif
207
208#endif /* _ACF_UTILS_DR_CMD_REG_H_ */
XPLMCommandRef dcr_find_cmd(const char *fmt, XPLMCommandCallback_f cb, bool before, void *refcon,...)
Definition dr_cmd_reg.c:173
void dcr_fini(void)
Definition dr_cmd_reg.c:96
XPLMCommandRef f_dcr_find_cmd_v(const char *fmt, XPLMCommandCallback_f cb, bool before, void *refcon, va_list ap)
Definition dr_cmd_reg.c:254
dr_t * dcr_get_dr(void *token)
Definition dr_cmd_reg.c:132
void dcr_init(void)
Definition dr_cmd_reg.c:75
void dcr_insert_rdr(void *token)
Definition dr_cmd_reg.c:141
XPLMCommandRef f_dcr_find_cmd(const char *fmt, XPLMCommandCallback_f cb, bool before, void *refcon,...)
Definition dr_cmd_reg.c:234
void * dcr_alloc_rdr(void)
Definition dr_cmd_reg.c:124
XPLMCommandRef dcr_create_cmd(const char *cmdname, const char *cmddesc, XPLMCommandCallback_f cb, bool before, void *refcon)
Definition dr_cmd_reg.c:289
XPLMCommandRef dcr_find_cmd_v(const char *fmt, XPLMCommandCallback_f cb, bool before, void *refcon, va_list ap)
Definition dr_cmd_reg.c:192