LTAPI
API to access LiveTraffic's aircraft information
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
LTAPIConnect Class Reference

Connects to LiveTraffic's dataRefs and returns aircraft information. More...

#include <LTAPI.h>

Public Types

typedef LTAPIAircraftfCreateAcObject()
 Callback function type passed in to LTAPIConnect() More...
 

Public Member Functions

 LTAPIConnect (fCreateAcObject *_pfCreateAcObject=LTAPIAircraft::CreateNewObject, int numBulkAc=50)
 Constructor. More...
 
virtual ~LTAPIConnect ()
 
const MapLTAPIAircraftUpdateAcList (ListLTAPIAircraft *plistRemovedAc=nullptr)
 Main function: updates map of aircrafts and returns reference to it. More...
 
const MapLTAPIAircraftgetAcMap () const
 Returns the map of aircraft as it currently stands. More...
 
SPtrLTAPIAircraft getAcByMultIdx (int multiIdx) const
 Finds an aircraft for a given multiplayer slot. More...
 
SPtrLTAPIAircraft getAcInCameraView () const
 Returns the aircraft being viewed in LiveTraffic's camera view, if any. More...
 

Static Public Member Functions

static bool isLTAvail ()
 Is LiveTraffic available? (checks via XPLMFindPluginBySignature) More...
 
static int getLTVerNr ()
 LiveTraffic's version number. More...
 
static int getLTVerDate ()
 LiveTraffic's version date. More...
 
static bool doesLTDisplayAc ()
 Does LiveTraffic display aircrafts? (Is it activated?) More...
 
static int getLTNumAc ()
 How many aircraft does LiveTraffic display right now? More...
 
static bool doesLTControlAI ()
 Does LiveTaffic control AI planes? More...
 
static time_t getLTSimTime ()
 What is current simulated time in LiveTraffic (usually 'now' minus buffering period)? More...
 
static std::chrono::system_clock::time_point getLTSimTimePoint ()
 What is current simulated time in LiveTraffic (usually 'now' minus buffering period)? More...
 

Public Attributes

std::chrono::seconds sPeriodExpsv = std::chrono::seconds(3)
 

Protected Member Functions

template<class T >
bool DoBulkFetch (int numAc, LTDataRef &DR, int &outSizeLT, std::unique_ptr< T[]> &vBulk)
 fetch bulk data and create/update aircraft objects More...
 

Protected Attributes

const int iBulkAc = 50
 Number of aircraft to fetch in one bulk operation. More...
 
std::unique_ptr< LTAPIAircraft::LTAPIBulkData[]> vBulkNum
 bulk data array for communication with LT More...
 
std::unique_ptr< LTAPIAircraft::LTAPIBulkInfoTexts[]> vInfoTexts
 bulk info text array for communication with LT More...
 
fCreateAcObjectpfCreateAcObject = nullptr
 Pointer to callback function returning new aircraft objects. More...
 
MapLTAPIAircraft mapAc
 THE map of aircrafts. More...
 
std::chrono::time_point< std::chrono::steady_clock > lastExpsvFetch
 Last fetching of expensive data. More...
 

Detailed Description

Connects to LiveTraffic's dataRefs and returns aircraft information.

Typically, exactly one instance of this class is used.

Member Typedef Documentation

◆ fCreateAcObject

typedef LTAPIAircraft* LTAPIConnect::fCreateAcObject()

Callback function type passed in to LTAPIConnect()

Returns
New LTAPIAircraft object or derived class' object

The callback is actually called by UpdateAcList().

If you use a class derived from LTAPIAircraft, then you pass in a pointer to a callback function, which returns new empty objects of your derived class whenever UpdateAcList() needs to create a new aircraft object.

Constructor & Destructor Documentation

◆ LTAPIConnect()

LTAPIConnect::LTAPIConnect ( fCreateAcObject _pfCreateAcObject = LTAPIAircraft::CreateNewObject,
int  numBulkAc = 50 
)

Constructor.

Parameters
_pfCreateAcObject(Optional) Poitner to callback function, which returns new aircraft objects, see typedef fCreateAcObject()
numBulkAcNumber of aircraft to fetch in one bulk operation

◆ ~LTAPIConnect()

LTAPIConnect::~LTAPIConnect ( )
virtual

Member Function Documentation

◆ DoBulkFetch()

template<class T >
bool LTAPIConnect::DoBulkFetch ( int  numAc,
LTDataRef DR,
int &  outSizeLT,
std::unique_ptr< T[]> &  vBulk 
)
protected

fetch bulk data and create/update aircraft objects

Parameters
numAcTotal number of aircraft to fetch
DRThe dataRef to use for fetching the actual data from LT
[out]outSizeLTReturns LT's structure size
vBulkReference to allocated memory for data transfer
Template Parameters
Tis the structure to fill, either LTAPIAircraft::LTAPIBulkData or LTAPIAircraft::LTAPIBulkInfoTexts
Returns
Have aircraft objects been created?

◆ doesLTControlAI()

bool LTAPIConnect::doesLTControlAI ( )
static

Does LiveTaffic control AI planes?

Note
If your plugin usually deals with AI/multiplayer planes, then you don't need to check for AI/multiplayer planes if doesLTControlAI() returns true: In this case the planes returned in the AI/multiplayer dataRefs are just a subset selected by LiveTraffic of what you get via UpdateAcList() anyway. Avoid duplicates, just use LTAPI if doesLTControlAI() is true.

◆ doesLTDisplayAc()

bool LTAPIConnect::doesLTDisplayAc ( )
static

Does LiveTraffic display aircrafts? (Is it activated?)

This is the only function which checks again and again if LiveTraffic's dataRefs are available. Use this to verify if LiveTraffic is (now) available before calling any other function on LiveTraffic's dataRefs.

◆ getAcByMultIdx()

SPtrLTAPIAircraft LTAPIConnect::getAcByMultIdx ( int  multiIdx) const

Finds an aircraft for a given multiplayer slot.

Parameters
multiIdxThe multiplayer index to look for
Returns
Pointer to aircraft in slot multiIdx, is empty if not found

◆ getAcInCameraView()

SPtrLTAPIAircraft LTAPIConnect::getAcInCameraView ( ) const

Returns the aircraft being viewed in LiveTraffic's camera view, if any.

Returns
Pointer to aircraft in camera view, is empty if none is being viewed

◆ getAcMap()

const MapLTAPIAircraft& LTAPIConnect::getAcMap ( ) const
inline

Returns the map of aircraft as it currently stands.

◆ getLTNumAc()

int LTAPIConnect::getLTNumAc ( )
static

How many aircraft does LiveTraffic display right now?

◆ getLTSimTime()

time_t LTAPIConnect::getLTSimTime ( )
static

What is current simulated time in LiveTraffic (usually 'now' minus buffering period)?

◆ getLTSimTimePoint()

std::chrono::system_clock::time_point LTAPIConnect::getLTSimTimePoint ( )
static

What is current simulated time in LiveTraffic (usually 'now' minus buffering period)?

◆ getLTVerDate()

int LTAPIConnect::getLTVerDate ( )
static

LiveTraffic's version date.

Version date became available with v2.01 only. This is why 20191231 is returned in case LiveTraffic is available, but not the dataRef to fetch the date from.

Returns
Version date (like 20200430 for 30-APR-2020), or constant 20191231 if unknown, or 0 if LiveTraffic is unavailable

◆ getLTVerNr()

int LTAPIConnect::getLTVerNr ( )
static

LiveTraffic's version number.

Version number became available with v2.01 only. This is why 150 is returned in case LiveTraffic is available, but not the dataRef to fetch the number from.

Note
Calling this function from your XPluginStart or XPluginEnable is not guaranteed to return proper results. Call from a flight loop callback, e.g. create a one-time late-init flight loop callback function for this purpose. LTAPIExample.cpp demonstrates this.
Depending on startup order, LiveTraffic might or might not have been started yet. This note is basically true for all requests accessing LiveTraffic data. It is noted here only because it is tempting to fetch the version number once only during startup.
Returns
Version (like 201 for v2.01), or constant 150 if unknown, or 0 if LiveTraffic is unavailable

◆ isLTAvail()

bool LTAPIConnect::isLTAvail ( )
static

Is LiveTraffic available? (checks via XPLMFindPluginBySignature)

◆ UpdateAcList()

const MapLTAPIAircraft & LTAPIConnect::UpdateAcList ( ListLTAPIAircraft plistRemovedAc = nullptr)

Main function: updates map of aircrafts and returns reference to it.

Parameters
plistRemovedAc(Optional) If you want to know which a/c are removed during this call (because the disappeared from LiveTraffic) then pass a ListLTAPIAircraft object: LTAPI will transfer otherwise removed objects there and management of them is then up to you. LTAPI will only emplace_back to the list, never remove anything.

Member Data Documentation

◆ iBulkAc

const int LTAPIConnect::iBulkAc = 50
protected

Number of aircraft to fetch in one bulk operation.

◆ lastExpsvFetch

std::chrono::time_point<std::chrono::steady_clock> LTAPIConnect::lastExpsvFetch
protected

Last fetching of expensive data.

◆ mapAc

MapLTAPIAircraft LTAPIConnect::mapAc
protected

THE map of aircrafts.

◆ pfCreateAcObject

fCreateAcObject* LTAPIConnect::pfCreateAcObject = nullptr
protected

Pointer to callback function returning new aircraft objects.

◆ sPeriodExpsv

std::chrono::seconds LTAPIConnect::sPeriodExpsv = std::chrono::seconds(3)

Number of seconds between two calls of the expensive type, which fetches all texts from LiveTraffic, which in fact don't change that often anyway

◆ vBulkNum

std::unique_ptr<LTAPIAircraft::LTAPIBulkData[]> LTAPIConnect::vBulkNum
protected

bulk data array for communication with LT

◆ vInfoTexts

std::unique_ptr<LTAPIAircraft::LTAPIBulkInfoTexts[]> LTAPIConnect::vInfoTexts
protected

bulk info text array for communication with LT


The documentation for this class was generated from the following files: