-
Notifications
You must be signed in to change notification settings - Fork 277
XPCPlugin
The XPCPlugin module contains the core functions that the X-Plane plugin manager uses to interact with the plugin. These functions handle startup, shutdown, and the the core operation of the plugin.
###Basic Flow
When X-Plane is launched, it looks for plugins and runs their XPluginStart
function. The plugin manager expects us to copy some basic information into the
provided char*
parameters. X-Plane Connect also uses the XPluginStart
function to perform some basic startup tasks like initializing its log file and
setting up the DataManager
component.
As X-Plane is running, the plugin can be enabled and disabled by several
mechanisms, including directly by the user and by other plugins. Each time the
plugin is enabled, the XPluginEnable
function is called, and each time the
plugin is disabled, the XPluginDisable
function is called. X-Plane Connect uses
these functions to manage resources that are only needed while the plugin is
running. Each time XPluginEnable
is called, X-Plane Connect creates a new UDP
socket to listen for commands and registers a callback on the flight loop. Each
time XPluginDisable
is called, the flight loop callback is unregistered and
the socket released.
Finally, when X-Plane is shut down normally the XPluginStop
function is called.
Because XPluginDisable
is always called before XPluginStop
, there is little
for X-Plane Connect to do on shutdown. Currently and event is logged and the
log file is closed on shutdown.
###Functions
The following functions are declared and implemented in XPCPlugin.cpp
.
####XPluginStart
Signature: PLUGIN_API int XPluginStart(char* outName, char* outSig, char* outDesc);
XPluginStart performs the following operations:
- Writes the name, signature, and description for the plugin.
- Initializes the log file
- Initializes the
DataManager
component
####XPluginStop
Signature: PLUGIN_API void XPluginStop(void);
XPluginStop performs the following operations:
- Closes the log file
####XPluginEnable
Signature: PLUGIN_API int XPluginEnable(void);
XPluginEnable performs the following operations:
- Open a UDP socket
- Register the flight loop callback
####XPluginDisable
Signature: PLUGIN_API void XPluginDisable(void);
XPluginDisable performs the following operations:
- Close the UDP socket
- Unregister the flight loop callback
####XPluginReceiveMessage Signature:
PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFromWho,
int inMessage,
void* inParam);
XPluginReceiveMessage does not currently perform any operations. It is defined only because the X-Plane Plugin manager requires that all plugins implement this function.
####XPCFlightLoopCallback Signature:
static float XPCFlightLoopCallback(float inElapsedSinceLastCall,
float inElapsedTimeSinceLastFlightLoop,
int inCounter,
void* inRefcon);
XPCFlightLoopCallback performs the following operations:
- Try to read a message from the UDP socket.
- If a message is received, pass it to
MessageHandlers
to be processed. - Repeat the above two steps up to
OPS_PER_CYCLE
times