source: xplra/src/plugin/src/xplra/plugin.cc@ 38:128b9ced9779

Last change on this file since 38:128b9ced9779 was 38:128b9ced9779, checked in by István Váradi <ivaradi@…>, 11 years ago

Added basic support for showing a message

File size: 4.6 KB
RevLine 
[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"
34
[11]35#include <hu/varadiistvan/xplcommon/Util.h>
36#include <hu/varadiistvan/scpl/config.h>
[1]37
[0]38#include <XPLMDefs.h>
39#include <XPLMUtilities.h>
40#include <XPLMProcessing.h>
41
42#include <cstdio>
43#include <cstring>
44#include <cstdarg>
45
[9]46#if TARGET_API_POSIX
47#include <signal.h>
48#endif
49
[0]50//------------------------------------------------------------------------------
51
52using xplra::ListenThread;
[38]53using xplra::MessageWindow;
[0]54
[11]55using hu::varadiistvan::xplcommon::Util;
[1]56
[0]57//------------------------------------------------------------------------------
58
[1]59/**
[38]60 * The window to display messages from the clients.
61 */
62static MessageWindow* messageWindow = 0;
63
64/**
[1]65 * The thread to use to listen for incoming connections.
66 */
[0]67static ListenThread* listenThread = 0;
68
69//------------------------------------------------------------------------------
70
71PLUGIN_API int XPluginStart(char* outName, char* outSignature,
72 char* outDescription)
73{
[1]74 Util::debug("hu.varadiistvan.xplra called\n");
[0]75
76 strcpy(outName, "X-Plane Remote Access");
77 strcpy(outSignature, "hu.varadiistvan.xplra");
78 strcpy(outDescription, "Provides remote access to datarefs");
79
[9]80#if TARGET_API_POSIX
81 signal(SIGPIPE, SIG_IGN);
82#endif
83
[0]84 return 1;
85}
86
[1]87//------------------------------------------------------------------------------
[0]88
89PLUGIN_API void XPluginEnable(void)
90{
[1]91 Util::debug("hu.varadiistvan.xplra.XPluginEnable called\n");
[0]92 // XPLMRegisterFlightLoopCallback(&callback, 5.0, 0);
[36]93
94 int xplaneVersion = 0;
95 int xplmVersion = 0;
96 XPLMHostApplicationID hostID = 0;
97 XPLMGetVersions(&xplaneVersion, &xplmVersion, &hostID);
98
[38]99 messageWindow = new MessageWindow();
100
101 listenThread = new ListenThread(xplaneVersion, xplmVersion,
102 *messageWindow);
[0]103 listenThread->start();
104}
105
[1]106//------------------------------------------------------------------------------
107
[0]108PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFrom, long inMessage,
109 void* inParam)
110{
[1]111 Util::debug("hu.varadiistvan.xplra.XPluginReceiveMessage called, inFrom=%d, inMessage=%ld, inParam=%p\n",
[0]112 inFrom, inMessage, inParam);
113}
114
[1]115//------------------------------------------------------------------------------
116
[0]117PLUGIN_API void XPluginDisable(void)
118{
[1]119 Util::debug("hu.varadiistvan.xplra.XPluginDisable called\n");
[0]120 // XPLMUnregisterFlightLoopCallback(&callback, 0);
[38]121
[0]122 if (listenThread!=0) {
123 listenThread->quit();
124 listenThread = 0;
125 }
[38]126
127 delete messageWindow; messageWindow = 0;
[0]128}
129
[1]130//------------------------------------------------------------------------------
131
[0]132PLUGIN_API void XPluginStop(void)
133{
[1]134 Util::debug("hu.varadiistvan.xplra.XPluginStop called\n");
[0]135}
[1]136
137//------------------------------------------------------------------------------
138
139// Local Variables:
140// mode: C++
141// c-basic-offset: 4
142// indent-tabs-mode: nil
143// End:
Note: See TracBrowser for help on using the repository browser.