[1] | 1 | // Copyright (c) 2013 by István Váradi
|
---|
| 2 |
|
---|
| 3 | // This file is part of XPLRA, a remote-access plugin for X-Plane
|
---|
| 4 |
|
---|
| 5 | // Redistribution and use in source and binary forms, with or without
|
---|
| 6 | // modification, are permitted provided that the following conditions are met:
|
---|
| 7 |
|
---|
| 8 | // 1. Redistributions of source code must retain the above copyright notice, this
|
---|
| 9 | // list of conditions and the following disclaimer.
|
---|
| 10 | // 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
| 11 | // this list of conditions and the following disclaimer in the documentation
|
---|
| 12 | // and/or other materials provided with the distribution.
|
---|
| 13 |
|
---|
| 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
---|
| 15 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
| 16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
---|
| 18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
| 19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
| 20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
| 21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
| 23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 24 |
|
---|
| 25 | // The views and conclusions contained in the software and documentation are those
|
---|
| 26 | // of the authors and should not be interpreted as representing official policies,
|
---|
| 27 | // either expressed or implied, of the FreeBSD Project.
|
---|
| 28 |
|
---|
| 29 | //------------------------------------------------------------------------------
|
---|
| 30 |
|
---|
[0] | 31 | #include "ListenThread.h"
|
---|
| 32 |
|
---|
[38] | 33 | #include "MessageWindow.h"
|
---|
[43] | 34 | #include "Menu.h"
|
---|
[38] | 35 |
|
---|
[11] | 36 | #include <hu/varadiistvan/xplcommon/Util.h>
|
---|
| 37 | #include <hu/varadiistvan/scpl/config.h>
|
---|
[1] | 38 |
|
---|
[0] | 39 | #include <XPLMDefs.h>
|
---|
| 40 | #include <XPLMUtilities.h>
|
---|
| 41 | #include <XPLMProcessing.h>
|
---|
[42] | 42 | #include <XPLMMenus.h>
|
---|
[0] | 43 |
|
---|
| 44 | #include <cstdio>
|
---|
| 45 | #include <cstring>
|
---|
| 46 | #include <cstdarg>
|
---|
| 47 |
|
---|
[9] | 48 | #if TARGET_API_POSIX
|
---|
| 49 | #include <signal.h>
|
---|
| 50 | #endif
|
---|
| 51 |
|
---|
[0] | 52 | //------------------------------------------------------------------------------
|
---|
| 53 |
|
---|
| 54 | using xplra::ListenThread;
|
---|
[38] | 55 | using xplra::MessageWindow;
|
---|
[43] | 56 | using xplra::Menu;
|
---|
[0] | 57 |
|
---|
[11] | 58 | using hu::varadiistvan::xplcommon::Util;
|
---|
[1] | 59 |
|
---|
[0] | 60 | //------------------------------------------------------------------------------
|
---|
| 61 |
|
---|
[1] | 62 | /**
|
---|
[38] | 63 | * The window to display messages from the clients.
|
---|
| 64 | */
|
---|
| 65 | static MessageWindow* messageWindow = 0;
|
---|
| 66 |
|
---|
| 67 | /**
|
---|
[43] | 68 | * The menu.
|
---|
| 69 | */
|
---|
| 70 | static Menu* menu = 0;
|
---|
| 71 |
|
---|
| 72 | /**
|
---|
[1] | 73 | * The thread to use to listen for incoming connections.
|
---|
| 74 | */
|
---|
[0] | 75 | static ListenThread* listenThread = 0;
|
---|
| 76 |
|
---|
| 77 | //------------------------------------------------------------------------------
|
---|
| 78 |
|
---|
| 79 | PLUGIN_API int XPluginStart(char* outName, char* outSignature,
|
---|
| 80 | char* outDescription)
|
---|
| 81 | {
|
---|
[1] | 82 | Util::debug("hu.varadiistvan.xplra called\n");
|
---|
[0] | 83 |
|
---|
| 84 | strcpy(outName, "X-Plane Remote Access");
|
---|
| 85 | strcpy(outSignature, "hu.varadiistvan.xplra");
|
---|
| 86 | strcpy(outDescription, "Provides remote access to datarefs");
|
---|
| 87 |
|
---|
[9] | 88 | #if TARGET_API_POSIX
|
---|
| 89 | signal(SIGPIPE, SIG_IGN);
|
---|
| 90 | #endif
|
---|
| 91 |
|
---|
[0] | 92 | return 1;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[1] | 95 | //------------------------------------------------------------------------------
|
---|
[0] | 96 |
|
---|
| 97 | PLUGIN_API void XPluginEnable(void)
|
---|
| 98 | {
|
---|
[1] | 99 | Util::debug("hu.varadiistvan.xplra.XPluginEnable called\n");
|
---|
[0] | 100 | // XPLMRegisterFlightLoopCallback(&callback, 5.0, 0);
|
---|
[36] | 101 |
|
---|
| 102 | int xplaneVersion = 0;
|
---|
| 103 | int xplmVersion = 0;
|
---|
| 104 | XPLMHostApplicationID hostID = 0;
|
---|
| 105 | XPLMGetVersions(&xplaneVersion, &xplmVersion, &hostID);
|
---|
| 106 |
|
---|
[38] | 107 | messageWindow = new MessageWindow();
|
---|
[43] | 108 | menu = new Menu(*messageWindow);
|
---|
[38] | 109 |
|
---|
| 110 | listenThread = new ListenThread(xplaneVersion, xplmVersion,
|
---|
| 111 | *messageWindow);
|
---|
[0] | 112 | listenThread->start();
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[1] | 115 | //------------------------------------------------------------------------------
|
---|
| 116 |
|
---|
[0] | 117 | PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFrom, long inMessage,
|
---|
| 118 | void* inParam)
|
---|
| 119 | {
|
---|
[1] | 120 | Util::debug("hu.varadiistvan.xplra.XPluginReceiveMessage called, inFrom=%d, inMessage=%ld, inParam=%p\n",
|
---|
[0] | 121 | inFrom, inMessage, inParam);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[1] | 124 | //------------------------------------------------------------------------------
|
---|
| 125 |
|
---|
[0] | 126 | PLUGIN_API void XPluginDisable(void)
|
---|
| 127 | {
|
---|
[1] | 128 | Util::debug("hu.varadiistvan.xplra.XPluginDisable called\n");
|
---|
[0] | 129 | // XPLMUnregisterFlightLoopCallback(&callback, 0);
|
---|
[38] | 130 |
|
---|
[0] | 131 | if (listenThread!=0) {
|
---|
| 132 | listenThread->quit();
|
---|
| 133 | listenThread = 0;
|
---|
| 134 | }
|
---|
[38] | 135 |
|
---|
[43] | 136 | delete menu; menu = 0;
|
---|
[38] | 137 | delete messageWindow; messageWindow = 0;
|
---|
[0] | 138 | }
|
---|
| 139 |
|
---|
[1] | 140 | //------------------------------------------------------------------------------
|
---|
| 141 |
|
---|
[0] | 142 | PLUGIN_API void XPluginStop(void)
|
---|
| 143 | {
|
---|
[1] | 144 | Util::debug("hu.varadiistvan.xplra.XPluginStop called\n");
|
---|
[0] | 145 | }
|
---|
[1] | 146 |
|
---|
| 147 | //------------------------------------------------------------------------------
|
---|
| 148 |
|
---|
| 149 | // Local Variables:
|
---|
| 150 | // mode: C++
|
---|
| 151 | // c-basic-offset: 4
|
---|
| 152 | // indent-tabs-mode: nil
|
---|
| 153 | // End:
|
---|