v1.3.0.0
enums_impl.h
1/*
2This file is part of the WASimCommander project.
3https://github.com/mpaperno/WASimCommander
4
5COPYRIGHT: (c) Maxim Paperno; All Rights Reserved.
6
7This file may be used under the terms of either the GNU General Public License (GPL)
8or the GNU Lesser General Public License (LGPL), as published by the Free Software
9Foundation, either version 3 of the Licenses, or (at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16Copies of the GNU GPL and LGPL are included with this project
17and are available at <http://www.gnu.org/licenses/>.
18*/
19
20// DO NOT USE THIS FILE DIRECTLY -- NO INCLUDE GUARD
21// Use enums.h
22
23#include <cstdint>
24#include <vector>
25
26#ifndef WSMCMND_ENUM_EXPORT
27 #define WSMCMND_ENUM_EXPORT
28 #define WSMCMND_ENUM_NAMESPACE WASimCommander::Enums
29#endif
30
31/// WASimCommander::Enums namespace. Contains all enum definitions for the base API.
32namespace WSMCMND_ENUM_NAMESPACE
33{
34
35 /// Commands for client-server interaction. Both sides can send commands via dedicated channels by writing a \refwc{Command} data structure.
36 /// The fields `uData`, `sData` and `fData` referenced below refer to \refwc{Command::uData}, \refwc{Command::sData} and \refwc{Command::fData} respectively.
37 /// \sa Command struct.
38 WSMCMND_ENUM_EXPORT enum class CommandId : uint8_t
39 {
40 None = 0, ///< An invalid command.
41 Ack, ///< Last command acknowledge. `CommandId` of the original command (which succeeded) is sent in `uData`. The `token` value from the original command is also sent back in the `token` member.
42 Nak, ///< Last command failure. `CommandId` of the original command (which failed) is sent in `uData`. `sData` _may_ contain a reason for failure. The `token` value from the original command is also sent back in the `token` member.
43 Ping, ///< Query for a response from remote server/client. The remote should respond with an `Ack` command.
44 Connect, ///< Reconnect a previously-established client (same as "WASimCommander.Connect" custom event). This CommandId is also sent back in an Ack/Nak response after a client connects (or tries to). In this case the `token` of the Ack/Nak is the client ID.
45 Disconnect, ///< Stop data updates for this client. Use the `Connect` command to resume updates. The server may also spontaneously send a Disconnect command in case it is shutting down or otherwise terminating connections.
46 List, ///< Request a listing of items like local variables. `uData` should be one of `WASimCommander::LookupItemType` enum values (Sim and Token vars currently cannot be listed).
47 /// List is returned as a series of `List` type response commands with `sData` as var name and `uData` is var ID, followed by an `Ack` at the end. A `Nak` response is returned if the item type cannot be listed for any reason.
48 Lookup, ///< Get information about an item, such as the ID of a variable or unit name. `uData` should be one of `WASimCommander::LookupItemType` enum values and `sData` is the name of the thing to look up.
49 /// `Ack` is returned on success with the ID of the variable/unit in the `fData` member (as an `INT32`) and the original requested string name echoed back in `sData`. In case of lookup failure, a `Nak` response is returned with possible reason in `sData`.
50 Get, ///< Get a named variable value with optional unit type. `uData` is a char of the variable type, eg. 'L' for local, 'A' for SimVar, or 'T' for Token. Only 'L', 'A' and 'E' types support unit specifiers.\n
51 /// `sData` is the variable name or numeric ID, optionally followed by comma (`,`) and unit name or numeric ID (**no spaces**). For indexed SimVars, include the index after the variable name, separated by a colon (`:`).\n
52 /// For example, a SimVar: ```uData = 'A'; sData = "PROP BETA:2,degrees";``` \n
53 /// Other variables types can also be requested ('B', 'E', 'M', etc) but such requests are simply converted to a calculator string and processed as an `Exec` type command (using an `Exec` command directly may be more efficient).\n
54 /// Result is returned with the `Ack` response in `fData` as a double-precision value. In case of failure a `Nak` is returned with possible error message in `sData`.
55 GetCreate, ///< Same as `Get` but creates a local 'L' variable if it doesn't already exist (with `register_named_variable()` _Gauge API_). Use `Lookup` command to check if a variable exists.
56 /// \n **Since v1.2:** If a variable is created, the value provided in `fData` will be used as the initial value of the variable, and will be returned as the result
57 /// (essentially providing a default value in this case). Previous versions would _not_ set a value (or unit type) on the variable after creating it and would return the default of `0.0`. \n
58 /// **Creating variables only works with `L` (local) types.** Since v1.2, for all other types this command will be handled the same as `Get`. Previous versions would return a `Nak`.
59 Set, ///< Set a named local variable with optional unit type. `uData` is a char of the variable type, with default of 'L' for local vars.
60 /// `sData` is the variable name or numeric ID (for local vars only), optionally followed by comma (`,`) and unit name (or numeric unit ID for local vars) (**no spaces**). The value to set is passed in `fData` member.\n
61 /// For example, a SimVar: ```uData = 'A'; sData = "PROP RPM:2,rpm"; fData = 2200;```\n
62 /// Other variables types can also be set this way ('A', 'H", 'K', etc) but such requests are simply converted to a calculator string and processed as an `Exec` type command (using an `Exec` command directly may be slightly more efficient).
63 SetCreate, ///< Same as `Set` but creates a local 'L' variable if it doesn't already exist (with `register_named_variable()` _Gauge API_). Use the `Lookup` command to check if a variable exists. \n
64 /// **Creating variables only works with `L` (local) types.** Since v1.2, for all other types this command will be handled the same as `Get`. Previous versions would return a `Nak`.
65 Exec, ///< Run calculator code contained in `sData` with `WASimCommander::CalcResultType` in `uData`. Result, if any, is returned with the `Ack` response, numeric types in `fData` and strings in `sData`.
66 /// (Due to the way the _Gauge API_ calculator function works, a string result is typically also returned even when only a numeric result is requested.)\n\n
67 /// In case of failure a `Nak` is returned with possible error message in `sData`. Note however that the _Gauge API_ functions often happily return a "success" status even when the actual thing you're trying to do fails. The only feedback
68 /// in this case appears to be the MSFS Console window available from "Dev Tools," which will (usually) log any actual errors.
69 Register, ///< Register a named Exec-type event. `uData` is a unique event ID, and `sData` a calculator code string. Optional event name in `sData` before a `$` separator (maximum length of \refwc{STRSZ_ENAME}). Default is to use event ID as string.\n
70 /// If the custom event name contains a period (`.`) then it is used as-is. Otherwise "WASimCommander.[client_name]." will be prepended to the given name.\n
71 /// Use with `SimConnect_MapClientEventToSimEvent(id, "event_name")` and `SimConnect_TransmitClientEvent()`, or the `Transmit` command (below).\n
72 /// To change the calculator string used for an event, re-send this command with the same event ID and a new string to use. The event name cannot be modified after creation.\n
73 /// To remove a registered event, send this command with the event ID to delete and a blank `sData`.
74 Transmit, ///< Trigger an event previously registered with the `Register` command. `uData` should be the event ID from the original registration. This is a (faster) alternative to triggering events via SimConnect mappings.
75 Subscribe, ///< Sending this command to the server with a `uData` value of `0` (zero) will suspend (pause) any and all data subscription request value updates. Updates can be resumed again by sending any non-zero value in `uData`.\n
76 /// This command ID is also used as an `Ack/Nak` response to new Data Request records being processed. The client must write a `DataRequest` struct to the shared data area and the server should respond with this command to indicate success/failure.
77 Update, ///< Trigger data update of a previously-added Data Request, with the request ID in `uData`. This is used primarily to request updates for subscription types where the `UpdatePeriod` is `Never` or `Once`. The data is sent in the usual
78 /// manner for subscriptions, by writing the new value to the related client data area. Note also that this command will force an update of the data, without comparing the result to any (potentially) cached value from previous lookup.
79 SendKey, ///< `send_key_event(event_id, value)` with `event_id` in `uData` and an optional `UINT32` type `value` in `fData` (default is `0`).\n\n
80 /// "The send_key_event function transmits a WM_COMMAND application event. This function transmits a message with the following syntax: `PostMessage(hwndMain, WM_COMMAND, event_id, (LPARAM) value);`"\n\n
81 /// In practice this means you can send a KEY Event ID directly to the simulator, bypassing SimConnect event name mappings or calculator code evaluation. The event IDs can be found in the MSFS SDK's `MSFS/Legacy/gauges.h` header file as `KEY_*` macros,
82 /// and are also available via the `Lookup` command. If this command is sent with `uData` == 0 and `sData` contains a string, a `LookupItemType::KeyEventId` lookup will be performed on the Key Event name first and the resulting ID (if any) used.\n\n
83 /// Custom event IDs (registered by gauges or other modules) can also be triggered this way. There may be other uses for this command... TBD.
84 Log, ///< Set severity level for logging to the Client's `LogRecord` data area. `uData` should be one of the `WASimCommander::LogLevel` enum values. `LogLevel::None` disables logging, which is also the initial default for a newly connected Client.
85 /// Additionally, the server-wide log levels can be set for the file and console loggers independently. To specify these levels, set `fData` to one of the `WASimCommander::LogFacility` enum values. The default of `0` assumes `LogFacility::Remote`.
86 };
87 /// \name Enumeration name strings
88 /// \{
89 static const std::vector<const char *> CommandIdNames = {
90 "None", "Ack", "Nak", "Ping", "Connect", "Disconnect", "List", "Lookup",
91 "Get", "GetCreate", "Set", "SetCreate", "Exec", "Register", "Transmit",
92 "Subscribe", "Update", "SendKey", "Log" }; ///< \refwc{Enums::CommandId} enum names.
93 /// \}
94
95 /// Types of things to request or set. \sa DataRequest struct.
96 WSMCMND_ENUM_EXPORT enum class RequestType : uint8_t
97 {
98 None = 0, ///< Use to remove a previously-added request.
99 Named, ///< A named variable.
100 Calculated ///< Calculator code.
101 };
102 /// \name Enumeration name strings
103 /// \{
104 static const std::vector<const char *> RequestTypeNames = { "None", "Named", "Calculated" }; ///< \refwc{Enums::RequestType} enum names.
105 /// \}
106
107 /// The type of result that calculator code is expected to produce. \sa DataRequest struct, Enums::CommandId::Exec command.
108 WSMCMND_ENUM_EXPORT enum class CalcResultType : uint8_t
109 {
110 None = 0, ///< No result is expected (eg. triggering an event).
111 Double, ///< Expect a double ("FLOAT64") type result.
112 Integer, ///< Expect an 32bit signed integer result.
113 String, ///< Expect a string type result from `execute_calculator_code()`.
114 Formatted, ///< Execute code using `format_calculator_string()` function and expect a string result type.
115 };
116 /// \name Enumeration name strings
117 /// \{
118 static const std::vector<const char *> CalcResultTypeNames = { "None", "Double", "Integer", "String", "Formatted" }; ///< \refwc{Enums::CalcResultType} enum names.
119 /// \}
120
121 /// How often to check for updated request values. \sa DataRequest struct.
122 WSMCMND_ENUM_EXPORT enum class UpdatePeriod : uint8_t
123 {
124 Never = 0, ///< Suspend all automatic updates, only check value on `Enums::CommandId::Update` command.
125 Once, ///< Update once when DataRequest is added/updated, and then only on `Update` command.
126 Tick, ///< Update as often as possible (see \refwc{TICK_PERIOD_MS}).
127 Millisecond, ///< Update every `interval` milliseconds (interval value must be greater than 0 with effective minimum being the "Tick" period (\refwc{TICK_PERIOD_MS})).
128 };
129 /// \name Enumeration name strings
130 /// \{
131 static const std::vector<const char *> UpdatePeriodNames = { "Never", "Once", "Tick", "Millisecond" }; ///< \refwc{Enums::UpdatePeriod} enum names.
132 /// \}
133
134 /// Types of things to look up or list. \sa Enums::CommandId::List, Enums::CommandId::Lookup commands
135 WSMCMND_ENUM_EXPORT enum class LookupItemType : uint8_t
136 {
137 None, ///< Null type, possible internal use, ignored by server.
138 LocalVariable, ///< LVar ('L') names and IDs. Available for `List` and `Lookup` commands.
139 SimulatorVariable, ///< SimVar ('A') names and IDs. Available for `Lookup` command only.
140 TokenVariable, ///< Token Variable ('T'). Available for `Lookup` command only.
141 UnitType, ///< Measurement Unit. Available for `Lookup` command only.
142 KeyEventId, ///< Key Event ID, value of `KEY_*` macros from "guauges.h" header. Available for `Lookup` command only (use event name w/out the "KEY_" prefix).
143 DataRequest, ///< Saved value subscription for current Client, indexed by `requestId` and `nameOrCode` values. Available for `List` and `Lookup` commands.
144 RegisteredEvent, ///< Saved calculator event for current Client, indexed by `eventId` and `code` values. Available for `List` and `Lookup` commands.
145 };
146 /// \name Enumeration name strings
147 /// \{
148 static const std::vector<const char *> LookupItemTypeNames = {
149 "None", "LocalVariable", "SimulatorVariable", "TokenVariable", "UnitType", "KeyEventId", "DataRequest", "RegisteredEvent"
150 }; ///< \refwc{Enums::LookupItemType} enum names.
151 /// \}
152
153 /// Logging levels. \sa LogRecord struct, CommandId::Log command.
154 WSMCMND_ENUM_EXPORT enum class LogLevel : uint8_t
155 {
156 None = 0, ///< Disables logging
157 Critical, ///< Events which cause termination.
158 Error, ///< Hard errors preventing function execution.
159 Warning, ///< Possible anomalies which do not necessarily prevent execution.
160 Info, ///< Informational messages about key processes like startup and shutdown.
161 Debug, ///< Verbose debugging information.
162 Trace ///< Very verbose and frequent debugging data, do not use with "slow" logger outputs.
163 };
164 /// \name Enumeration name strings
165 /// \{
166 static const std::vector<const char *> LogLevelNames = { "None", "Critical", "Error", "Warning", "Info", "Debug", "Trace" }; ///< \refwc{Enums::LogLevel} enum names.
167 /// \}
168
169 /// Logging destination type. \sa CommandId::Log command.
170 WSMCMND_ENUM_EXPORT enum class LogFacility : uint8_t
171 {
172 None = 0x00, ///< Invalid or default logging facility. For the `Enums::CommandId::Log` command this is same as `Remote`.
173 Console = 0x01, ///< Console logging, eg. stderr/stdout.
174 File = 0x02, ///< Log file destination.
175 Remote = 0x04, ///< Remote destination, eg. network transmission or a callback event.
176 All = Console | File | Remote
177 };
178#if defined(DEFINE_ENUM_FLAG_OPERATORS) && !defined(_MANAGED)
179 DEFINE_ENUM_FLAG_OPERATORS(WSMCMND_ENUM_NAMESPACE::LogFacility)
180#endif
181 /// \name Enumeration name strings
182 /// \{
183 static const std::vector<const char *> LogFacilityNames = {
184 "None", "Console", "File", "Console | File", "Remote", "Console | Remote", "File | Remote", "All"
185 }; ///< \refwc{Enums::LogFacility} enum names.
186 /// \}
187
188};
UpdatePeriod
How often to check for updated request values.
Definition: enums_impl.h:123
@ Tick
Update as often as possible (see TICK_PERIOD_MS).
@ Never
Suspend all automatic updates, only check value on Enums::CommandId::Update command.
@ Millisecond
Update every interval milliseconds (interval value must be greater than 0 with effective minimum bein...
@ Once
Update once when DataRequest is added/updated, and then only on Update command.
static const std::vector< const char * > LogLevelNames
Enums::LogLevel enum names.
Definition: enums_impl.h:166
static const std::vector< const char * > CalcResultTypeNames
Enums::CalcResultType enum names.
Definition: enums_impl.h:118
LogLevel
Logging levels.
Definition: enums_impl.h:155
@ Warning
Possible anomalies which do not necessarily prevent execution.
@ Critical
Events which cause termination.
@ Info
Informational messages about key processes like startup and shutdown.
@ Error
Hard errors preventing function execution.
@ Debug
Verbose debugging information.
@ Trace
Very verbose and frequent debugging data, do not use with "slow" logger outputs.
static const std::vector< const char * > CommandIdNames
Enums::CommandId enum names.
Definition: enums_impl.h:89
static const std::vector< const char * > UpdatePeriodNames
Enums::UpdatePeriod enum names.
Definition: enums_impl.h:131
LookupItemType
Types of things to look up or list.
Definition: enums_impl.h:136
@ TokenVariable
Token Variable ('T'). Available for Lookup command only.
@ SimulatorVariable
SimVar ('A') names and IDs. Available for Lookup command only.
@ LocalVariable
LVar ('L') names and IDs. Available for List and Lookup commands.
@ RegisteredEvent
Saved calculator event for current Client, indexed by eventId and code values. Available for List and...
@ KeyEventId
Key Event ID, value of KEY_* macros from "guauges.h" header. Available for Lookup command only (use e...
@ UnitType
Measurement Unit. Available for Lookup command only.
static const std::vector< const char * > LookupItemTypeNames
Enums::LookupItemType enum names.
Definition: enums_impl.h:148
CalcResultType
The type of result that calculator code is expected to produce.
Definition: enums_impl.h:109
@ String
Expect a string type result from execute_calculator_code().
@ Formatted
Execute code using format_calculator_string() function and expect a string result type.
@ Integer
Expect an 32bit signed integer result.
@ Double
Expect a double ("FLOAT64") type result.
static const std::vector< const char * > RequestTypeNames
Enums::RequestType enum names.
Definition: enums_impl.h:104
CommandId
Commands for client-server interaction. Both sides can send commands via dedicated channels by writin...
Definition: enums_impl.h:39
@ Update
Trigger data update of a previously-added Data Request, with the request ID in uData....
@ Register
Register a named Exec-type event. uData is a unique event ID, and sData a calculator code string....
@ GetCreate
Same as Get but creates a local 'L' variable if it doesn't already exist (with register_named_variabl...
@ Nak
Last command failure. CommandId of the original command (which failed) is sent in uData....
@ SetCreate
Same as Set but creates a local 'L' variable if it doesn't already exist (with register_named_variabl...
@ Disconnect
Stop data updates for this client. Use the Connect command to resume updates. The server may also spo...
@ Connect
Reconnect a previously-established client (same as "WASimCommander.Connect" custom event)....
@ List
Request a listing of items like local variables. uData should be one of WASimCommander::LookupItemTyp...
@ Set
Set a named local variable with optional unit type. uData is a char of the variable type,...
@ Transmit
Trigger an event previously registered with the Register command. uData should be the event ID from t...
@ Exec
Run calculator code contained in sData with WASimCommander::CalcResultType in uData....
@ Ack
Last command acknowledge. CommandId of the original command (which succeeded) is sent in uData....
@ Subscribe
Sending this command to the server with a uData value of 0 (zero) will suspend (pause) any and all da...
@ SendKey
send_key_event(event_id, value) with event_id in uData and an optional UINT32 type value in fData (de...
@ Ping
Query for a response from remote server/client. The remote should respond with an Ack command.
@ Get
Get a named variable value with optional unit type. uData is a char of the variable type,...
@ Log
Set severity level for logging to the Client's LogRecord data area. uData should be one of the WASimC...
@ Lookup
Get information about an item, such as the ID of a variable or unit name. uData should be one of WASi...
RequestType
Types of things to request or set.
Definition: enums_impl.h:97
LogFacility
Logging destination type.
Definition: enums_impl.h:171
@ File
Log file destination.
@ Console
Console logging, eg. stderr/stdout.
@ Remote
Remote destination, eg. network transmission or a callback event.
static const std::vector< const char * > LogFacilityNames
Enums::LogFacility enum names.
Definition: enums_impl.h:183
Structure for variable value subscription requests.