Skip to content

Commit ef64176

Browse files
authored
Merge pull request #277 from TwinFan/Next
v4.1.1 but still includes crash-testing code
2 parents 284beb7 + e161777 commit ef64176

File tree

26 files changed

+2765
-2007
lines changed

26 files changed

+2765
-2007
lines changed

.github/actions/build-lin/action.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,23 @@ runs:
4949
echo Expected target build not found: "$TARGET_XPL"
5050
exit 1
5151
fi
52+
- name: Extract symbol info
53+
shell: bash
54+
env:
55+
TARGET_XPL: build-lin/${{ inputs.archFolder }}/${{ inputs.pluginName }}.xpl
56+
TARGET_DBG: build-lin/${{ inputs.archFolder }}/${{ inputs.pluginName }}.xpl.debug
57+
TARGET_PDB: build-lin/${{ inputs.archFolder }}/${{ inputs.pluginName }}.xpl.debug.zip
58+
run: |
59+
objcopy --only-keep-debug "$TARGET_XPL" "$TARGET_DBG"
60+
strip --strip-debug --strip-unneeded "$TARGET_XPL"
61+
objcopy --add-gnu-debuglink="$TARGET_DBG" "$TARGET_XPL"
62+
zip -9 "$TARGET_PDB" "$TARGET_DBG"
5263
- name: Return Value
5364
id: return
5465
shell: bash
5566
env:
5667
TARGET_XPL: build-lin/${{ inputs.archFolder }}/${{ inputs.pluginName }}.xpl
57-
run: echo "xpl-file-name=$(echo $TARGET_XPL)" >> $GITHUB_OUTPUT
68+
TARGET_PDB: build-lin/${{ inputs.archFolder }}/${{ inputs.pluginName }}.xpl.debug.zip
69+
run: |
70+
echo "xpl-file-name=$(echo $TARGET_XPL)" >> $GITHUB_OUTPUT
71+
echo "pdb-file-name=$(echo $TARGET_PDB)" >> $GITHUB_OUTPUT

.github/actions/build-mac/action.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,23 @@ runs:
4848
echo Expected target build not found: "$TARGET_XPL"
4949
exit 1
5050
fi
51+
- name: Extract symbol info
52+
shell: bash
53+
env:
54+
TARGET_XPL: build-mac/${{ inputs.archFolder }}/${{ inputs.pluginName }}.xpl
55+
TARGET_DSYM: build-mac/${{ inputs.archFolder }}/${{ inputs.pluginName }}.xpl.dSYM
56+
TARGET_PDB: build-mac/${{ inputs.archFolder }}/${{ inputs.pluginName }}.xpl.dSYM.zip
57+
run: |
58+
dsymutil "$TARGET_XPL"
59+
zip -9r "$TARGET_PDB" "$TARGET_DSYM"
60+
rm -rf "$TARGET_DSYM"
61+
strip -S "$TARGET_XPL"
5162
- name: Return Value
5263
id: return
5364
shell: bash
5465
env:
5566
TARGET_XPL: build-mac/${{ inputs.archFolder }}/${{ inputs.pluginName }}.xpl
56-
run: echo "xpl-file-name=$(echo $TARGET_XPL)" >> $GITHUB_OUTPUT
67+
TARGET_PDB: build-mac/${{ inputs.archFolder }}/${{ inputs.pluginName }}.xpl.dSYM.zip
68+
run: |
69+
echo "xpl-file-name=$(echo $TARGET_XPL)" >> $GITHUB_OUTPUT
70+
echo "pdb-file-name=$(echo $TARGET_PDB)" >> $GITHUB_OUTPUT

.github/workflows/build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ jobs:
3535
pluginName: ${{ env.PRJ_NAME }}
3636
archFolder: lin_x64
3737
xplFileName: "${{ steps.build.outputs.xpl-file-name }}"
38+
pdbFileName: "${{ steps.build.outputs.pdb-file-name }}"
3839

3940
#####################################
4041
# MacOS with CMake/clang and sign/notarize in self-written script
4142
build-mac:
42-
runs-on: macos-12
43+
runs-on: macos-14
4344
env:
4445
platform: mac
4546
steps:
@@ -78,7 +79,8 @@ jobs:
7879
with:
7980
pluginName: ${{ env.PRJ_NAME }}
8081
archFolder: mac_x64
81-
xplFileName: ${{ steps.build.outputs.xpl-file-name }}
82+
xplFileName: "${{ steps.build.outputs.xpl-file-name }}"
83+
pdbFileName: "${{ steps.build.outputs.pdb-file-name }}"
8284

8385
#####################################
8486
# Windows with MS Visual Studio

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ else()
2020
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Archs to build")
2121
endif()
2222

23+
set(CMAKE_BUILD_TYPE RelWithDebInfo)
24+
2325
project(LiveTraffic
24-
VERSION 4.1.0
26+
VERSION 4.1.1
2527
DESCRIPTION "LiveTraffic X-Plane plugin")
2628
set(VERSION_BETA 0)
2729

@@ -45,6 +47,12 @@ if (VERSION_BETA)
4547
message(" BETA Version")
4648
endif()
4749

50+
# By default we build Release with Debug Info (and strip the debug info in post-processing)
51+
if ((NOT DEFINED CMAKE_BUILD_TYPE) OR (CMAKE_BUILD_TYPE STREQUAL ""))
52+
set(CMAKE_BUILD_TYPE RelWithDebInfo)
53+
endif()
54+
message ("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
55+
4856
################################################################################
4957
# Target Systems
5058
################################################################################
@@ -171,6 +179,7 @@ set(Header_Files
171179
Include/LTWeather.h
172180
Include/SettingsUI.h
173181
Include/TextIO.h
182+
Include/ThreadCrashHdl.h
174183
Lib/base64/base64.h
175184
Lib/parson/parson.h
176185
Lib/LTAPI/LTAPI.h
@@ -219,6 +228,7 @@ set(Source_Files
219228
Src/LTWeather.cpp
220229
Src/SettingsUI.cpp
221230
Src/TextIO.cpp
231+
Src/ThreadCrashHdl.cpp
222232
Lib/base64/base64.c
223233
Lib/parson/parson.c
224234
Lib/ImGui/imgui_draw.cpp

Include/DataRefs.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ enum dataRefsLT {
370370
DR_CFG_LABEL_SHOWN,
371371
DR_CFG_LABEL_MAX_DIST,
372372
DR_CFG_LABEL_VISIBILITY_CUT_OFF,
373+
DR_CFG_LABEL_FOR_PARKED,
373374
DR_CFG_LABEL_COL_DYN,
374375
DR_CFG_LABEL_COLOR,
375376
DR_CFG_LOG_LEVEL,
@@ -593,7 +594,8 @@ class DataRefs
593594
bAlt : 1, // default
594595
bHeightAGL : 1,
595596
bSpeed : 1, // default
596-
bVSI : 1;
597+
bVSI : 1,
598+
bChannel : 1;
597599

598600
// this is a bit ugly but avoids a wrapper union with an int
599601
inline unsigned GetUInt() const { return *reinterpret_cast<const unsigned*>(this); }
@@ -697,11 +699,12 @@ class DataRefs
697699
bool bAwaitingAIControl = false; ///< have in vain tried acquiring AI control and are waiting for callback now?
698700
int bAINotOnGnd = false; ///< shall a/c on the ground be hidden from TCAS/AI?
699701
// which elements make up an a/c label?
700-
LabelCfgTy labelCfg = { 0,1,0,0,0,0,0,0, 0,0,0,0,0,0 };
702+
LabelCfgTy labelCfg = { 0,1,0,0,0,0,0,0, 0,0,0,0,0,0,0 };
701703
LabelShowCfgTy labelShown = { 1, 1, 1, 1 }; ///< when to show? (default: always)
702704
int labelMaxDist = 3; ///< [nm] max label distance
703-
bool bLabelVisibilityCUtOff = true; ///< cut off labels at reported visibility?
704-
bool bLabelColDynamic = false; // dynamic label color?
705+
int bLabelVisibilityCUtOff = true; ///< cut off labels at reported visibility?
706+
int bLabelForParked = true; ///< show labels for parked aircraft?
707+
int bLabelColDynamic = false; ///< dynamic label color?
705708
int labelColor = COLOR_YELLOW; ///< label color, by default yellow
706709
int maxNumAc = DEF_MAX_NUM_AC; ///< how many aircraft to create at most?
707710
int fdStdDistance = DEF_FD_STD_DISTANCE; ///< nm: miles to look for a/c around myself
@@ -724,7 +727,7 @@ class DataRefs
724727
int contrailAltMin_ft = DEF_CONTR_ALT_MIN; ///< [ft] Auto Contrails: Minimum altitude
725728
int contrailAltMax_ft = DEF_CONTR_ALT_MAX; ///< [ft] Auto Contrails: Maximum altitude
726729
int contrailLifeTime = DEF_CONTR_LIFETIME; ///< [s] Contrail default time to live
727-
bool contrailMulti = DEF_CONTR_MULTI; ///< Auto-create multiple or just a single contrail?
730+
int contrailMulti = DEF_CONTR_MULTI; ///< Auto-create multiple or just a single contrail?
728731
int remoteSupport = 0; ///< support XPMP2 Remote Client? (3-way: -1 off, 0 auto, 1 on)
729732
int bUseExternalCamera = false; ///< Do not activate LiveTraffic's camera view when hitting the camera button (intended for a 3rd party camera plugin to activate instead based on reading livetraffic/camera/... dataRefs or using LTAPI)
730733

@@ -947,6 +950,7 @@ class DataRefs
947950
inline LabelCfgTy GetLabelCfg() const { return labelCfg; }
948951
inline LabelShowCfgTy GetLabelShowCfg() const { return labelShown; }
949952
inline bool IsLabelColorDynamic() const { return bLabelColDynamic; }
953+
bool LabelShowForParked() const { return bLabelForParked; }
950954
inline int GetLabelColor() const { return labelColor; }
951955
void GetLabelColor (float outColor[4]) const;
952956
inline int GetMaxNumAc() const { return maxNumAc; }

Include/LTChannel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class LTACMasterdataChannel : public LTOnlineChannel
315315
protected:
316316
/// @brief Register a master data channel, that will be called to process requests
317317
/// @note The order, in which registration happens, serves as a priority
318-
static void RegisterMasterDataChn (LTACMasterdataChannel* pChn);
318+
static void RegisterMasterDataChn (LTACMasterdataChannel* pChn, bool bToFrontOfQueue);
319319
/// Unregister a mster data channel
320320
static void UnregisterMasterDataChn (LTACMasterdataChannel* pChn);
321321
/// Generically, uniquely add request to fetch data (returns `true` if added, `false` if duplicate)

Include/LTFlightData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class LTFlightData
211211
int sig; // signal level
212212

213213
std::string labelStat; // static part of the a/c label
214-
DataRefs::LabelCfgTy labelCfg = { 0,0,0,0,0,0,0,0, 0,0,0,0,0,0 }; // the configuration the label was saved for
214+
DataRefs::LabelCfgTy labelCfg = { 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0 }; // the configuration the label was saved for
215215

216216
protected:
217217
// DYNAMIC DATA (protected, access will be mutex-controlled for thread-safety)

Include/LTOpenSky.h

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ constexpr std::chrono::duration OPSKY_WAIT_NOQUEUE = std::chrono::milliseconds(3
101101
constexpr size_t OPSKY_MD_TEXT_VEHICLE_LEN = 20; ///< length after which category description might contain useful text in case of a Surface Vehicle
102102
#define OPSKY_MD_TEXT_NO_CAT "No ADS-B Emitter Category Information"
103103

104-
#define OPSKY_MD_DB_NAME "OpenSky Masterdata File"
105-
#define OPSKY_MD_DB_URL "https://opensky-network.org/datasets/metadata/"
106-
#define OPSKY_MD_DB_FILE_BEGIN "aircraft-database-complete-"
107-
#define OPSKY_MD_DB_FILE "aircraft-database-complete-%04d-%02d.csv"
108-
109104
#define OPSKY_ROUTE_URL "https://opensky-network.org/api/routes?callsign="
110105
#define OPSKY_ROUTE_CALLSIGN "callsign"
111106
#define OPSKY_ROUTE_ROUTE "route"
@@ -135,37 +130,38 @@ class OpenSkyAcMasterdata : public LTACMasterdataChannel
135130
//MARK: OpenSkyAcMasterFile
136131
//
137132

138-
// Every how many lines to we save file position information?
133+
#define OPSKY_MDF_NAME "OpenSky Masterdata File"
134+
#define OPSKY_MDF_URL "https://s3.opensky-network.org/data-samples/metadata/"
135+
#define OPSKY_MDF_FILE_BEGIN "aircraft-database-complete-"
136+
#define OPSKY_MDF_FILE "aircraft-database-complete-%04d-%02d.csv"
137+
138+
// Field names of interest within the database file
139+
#define OPSKY_MDF_HEXID "icao24"
140+
#define OPSKY_MDF_CATDESCR "categoryDescription"
141+
#define OPSKY_MDF_COUNTRY "country"
142+
#define OPSKY_MDF_MAN "manufacturerName"
143+
#define OPSKY_MDF_MANICAO "manufacturerIcao"
144+
#define OPSKY_MDF_MDL "model"
145+
#define OPSKY_MDF_OP "operatorCallsign"
146+
#define OPSKY_MDF_OWNER "owner"
147+
#define OPSKY_MDF_OPICAO "operatorIcao"
148+
#define OPSKY_MDF_REG "registration"
149+
#define OPSKY_MDF_ACTYPE "typecode"
150+
151+
/// Every how many lines to we save file position information?
139152
constexpr unsigned long OPSKY_NUM_LN_PER_POS = 250;
140153

141-
// Index into the fields of each line of the database file
142-
enum AcMasterFileFieldsTy : size_t {
143-
ACMFF_hexId = 0,
144-
ACMFF_reg,
145-
ACMFF_manIcao,
146-
ACMFF_man,
147-
ACMFF_mdl,
148-
ACMFF_designator,
149-
ACMFF_serialNum,
150-
ACMFF_lineNum,
151-
ACMFF_icaoAircraftClass,
152-
ACMFF_operator,
153-
ACMFF_operatorCallsign,
154-
ACMFF_opIcao,
155-
ACMFF_opIata,
156-
ACMFF_owner,
157-
ACMFF_catDescr,
158-
ACMFF_NUM_FIELDS
159-
};
160-
161154
/// Represents downloading and reading from the OpenSky Master data file `aircraft-database-complete-YYYY-MM.csv`
162155
class OpenSkyAcMasterFile : public LTACMasterdataChannel
163156
{
164157
protected:
165158
std::ifstream fAcDb; ///< Aircraft Database file
159+
std::string ln; ///< a line in the database file
160+
161+
std::map<std::string, std::size_t> mapFieldPos; ///< map of field names to field indexes
166162
typedef std::map<unsigned long,std::ifstream::pos_type> mapPosTy;///< map of a/c ids to file positions
163+
std::size_t numFields = 0; ///< number of fields expected in each row
167164
mapPosTy mapPos; ///< map of a/c ids to file positions
168-
std::string ln; ///< a line in the database file
169165
public:
170166
OpenSkyAcMasterFile (); ///< Constructor sets channel, name, and URLs
171167
public:

Include/LiveTraffic.h

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
#include "XPMPMultiplayer.h"
109109
#include "XPMPAircraft.h"
110110

111+
// Thread Settings, Crash Reporter
112+
#include "ThreadCrashHdl.h"
113+
111114
// FMOD Logo
112115
#include "FMOD_Logo.h"
113116

@@ -466,31 +469,4 @@ inline int strerror_s( char *buf, size_t bufsz, int errnum )
466469
{ strerror_r(errnum, buf, bufsz); return 0; }
467470
#endif
468471

469-
// MARK: Thread and Locale
470-
471-
/// Begin a thread and set a thread-local locale
472-
/// @details In the communication with servers we must use internal standards,
473-
/// ie. C locale, so that for example the decimal point is `.`
474-
/// Hence we set a thread-local locale in all threads as they deal with communication.
475-
/// See https://stackoverflow.com/a/17173977
476-
class ThreadSettings {
477-
protected:
478-
#if IBM
479-
#define LC_ALL_MASK LC_ALL
480-
#else
481-
locale_t threadLocale = locale_t(0);
482-
locale_t prevLocale = locale_t(0);
483-
#endif
484-
public:
485-
/// @brief Defines thread's name and sets the thread's locale
486-
/// @param sThreadName Thread's name, max 16 chars
487-
/// @param localeMask One of the LC_*_MASK constants. If `0` then locale is not changed.
488-
/// @param sLocaleName New locale to set
489-
ThreadSettings (const char* sThreadName,
490-
int localeMask = 0,
491-
const char* sLocaleName = "C");
492-
/// Restores and cleans up locale
493-
~ThreadSettings();
494-
};
495-
496472
#endif /* LiveTraffic_h */

Include/ThreadCrashHdl.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/// @file ThreadCrashHdl.h
2+
/// @brief Thead handling and Crash Report
3+
/// @see For thread-local locales see
4+
/// https://stackoverflow.com/a/17173977
5+
/// @see For Crash Reporter see
6+
/// https://developer.x-plane.com/code-sample/crash-handling/
7+
/// @details Sets standard settings for worker threads like locale and
8+
/// crashh reporting.
9+
/// Installs our own crash reporter (since X-Plane seems to filter
10+
/// out crashes in plugins and doesn't write a dump any longer
11+
/// in such cases).
12+
/// @author Birger Hoppe
13+
/// @copyright (c) 2024 Birger Hoppe
14+
/// @copyright Permission is hereby granted, free of charge, to any person obtaining a
15+
/// copy of this software and associated documentation files (the "Software"),
16+
/// to deal in the Software without restriction, including without limitation
17+
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
18+
/// and/or sell copies of the Software, and to permit persons to whom the
19+
/// Software is furnished to do so, subject to the following conditions:\n
20+
/// The above copyright notice and this permission notice shall be included in
21+
/// all copies or substantial portions of the Software.\n
22+
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28+
/// THE SOFTWARE.
29+
30+
#ifndef ThreadCrashHdl_h
31+
#define ThreadCrashHdl_h
32+
33+
//
34+
// MARK: Crash Handler
35+
//
36+
37+
/// @brief Registers the global crash handler
38+
/// @details Should be called from XPluginStart()
39+
void CrashHandlerRegister();
40+
/// @brief Unregisters the global crash handler
41+
/// @details You need to call this in XPluginStop() so we can clean up after ourselves
42+
void CrashHandlerUnregister();
43+
44+
/// @brief Registers the calling thread with the crash handler
45+
/// @details We use this to figure out if a crashed thread belongs to us
46+
/// when we later try to figure out if we caused a crash
47+
void CrashHandlerRegisterThread (const char* sThrName);
48+
/// @brief Unregisters the calling thread from the crash handler
49+
/// @details MUST be called at the end of thread that was registered
50+
/// via CrashHandlerRegister()
51+
void CrashHandlerUnregisterThread();
52+
53+
54+
55+
//
56+
// MARK: Thread Settings
57+
//
58+
59+
/// Begin a thread and set a thread-local locale
60+
/// @details In the communication with servers we must use internal standards,
61+
/// ie. C locale, so that for example the decimal point is `.`
62+
/// Hence we set a thread-local locale in all threads as they deal with communication.
63+
/// See https://stackoverflow.com/a/17173977
64+
class ThreadSettings {
65+
protected:
66+
#if IBM
67+
#define LC_ALL_MASK LC_ALL
68+
#else
69+
locale_t threadLocale = locale_t(0);
70+
locale_t prevLocale = locale_t(0);
71+
#endif
72+
public:
73+
/// @brief Defines thread's name and sets the thread's locale
74+
/// @param sThreadName Thread's name, max 16 chars
75+
/// @param localeMask One of the LC_*_MASK constants. If `0` then locale is not changed.
76+
/// @param sLocaleName New locale to set
77+
ThreadSettings (const char* sThreadName,
78+
int localeMask = 0,
79+
const char* sLocaleName = "C");
80+
/// Restores and cleans up locale
81+
~ThreadSettings();
82+
};
83+
84+
#endif /* ThreadCrashHdl_h */

0 commit comments

Comments
 (0)