source: xplra/src/plugin/src/xplra/plugin.cc@ 36:29e3b676c0c2

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

Added a new command to query the versions

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