// Copyright (c) 2013 by István Váradi // This file is part of XPLRA, a remote-access plugin for X-Plane // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // The views and conclusions contained in the software and documentation are those // of the authors and should not be interpreted as representing official policies, // either expressed or implied, of the FreeBSD Project. //------------------------------------------------------------------------------ #include "ListenThread.h" #include "Globals.h" #include #include #include #include #include #include #include #include #if TARGET_API_POSIX #include #endif //------------------------------------------------------------------------------ using xplra::ListenThread; using xplra::Globals; using hu::varadiistvan::xplcommon::Util; //------------------------------------------------------------------------------ /** * The global objects. */ static Globals* globals = 0; /** * The thread to use to listen for incoming connections. */ static ListenThread* listenThread = 0; //------------------------------------------------------------------------------ PLUGIN_API int XPluginStart(char* outName, char* outSignature, char* outDescription) { Util::debug("hu.varadiistvan.xplra called\n"); strcpy(outName, "X-Plane Remote Access"); strcpy(outSignature, "hu.varadiistvan.xplra"); strcpy(outDescription, "Provides remote access to datarefs"); #if TARGET_API_POSIX signal(SIGPIPE, SIG_IGN); #endif return 1; } //------------------------------------------------------------------------------ PLUGIN_API void XPluginEnable(void) { Util::debug("hu.varadiistvan.xplra.XPluginEnable called\n"); // XPLMRegisterFlightLoopCallback(&callback, 5.0, 0); globals = new Globals(); listenThread = new ListenThread(*globals); listenThread->start(); } //------------------------------------------------------------------------------ PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFrom, long inMessage, void* inParam) { Util::debug("hu.varadiistvan.xplra.XPluginReceiveMessage called, inFrom=%d, inMessage=%ld, inParam=%p\n", inFrom, inMessage, inParam); } //------------------------------------------------------------------------------ PLUGIN_API void XPluginDisable(void) { Util::debug("hu.varadiistvan.xplra.XPluginDisable called\n"); // XPLMUnregisterFlightLoopCallback(&callback, 0); if (listenThread!=0) { listenThread->quit(); listenThread->join(); delete listenThread; listenThread = 0; } delete globals; globals = 0; } //------------------------------------------------------------------------------ PLUGIN_API void XPluginStop(void) { Util::debug("hu.varadiistvan.xplra.XPluginStop called\n"); } //------------------------------------------------------------------------------ // Local Variables: // mode: C++ // c-basic-offset: 4 // indent-tabs-mode: nil // End: