source: xplra/src/plugin/src/xplra/plugin.cc@ 105:43a4a27845da

Last change on this file since 105:43a4a27845da was 105:43a4a27845da, checked in by István Váradi <ivaradi@…>, 17 months ago

The VSCPL logger is given a function to log into X-Plane's log.

File size: 4.4 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
[44]33#include "Globals.h"
[38]34
[11]35#include <hu/varadiistvan/xplcommon/Util.h>
36#include <hu/varadiistvan/scpl/config.h>
[105]37#include <hu/varadiistvan/scpl/Log.h>
[1]38
[0]39#include <XPLMDefs.h>
40#include <XPLMProcessing.h>
[42]41#include <XPLMMenus.h>
[0]42
43#include <cstdio>
44#include <cstring>
45#include <cstdarg>
46
[9]47#if TARGET_API_POSIX
48#include <signal.h>
49#endif
50
[0]51//------------------------------------------------------------------------------
52
53using xplra::ListenThread;
[44]54using xplra::Globals;
[0]55
[11]56using hu::varadiistvan::xplcommon::Util;
[1]57
[105]58using hu::varadiistvan::scpl::Log;
59
[0]60//------------------------------------------------------------------------------
61
[1]62/**
[44]63 * The global objects.
[38]64 */
[44]65static Globals* globals = 0;
[43]66
67/**
[1]68 * The thread to use to listen for incoming connections.
69 */
[0]70static ListenThread* listenThread = 0;
71
72//------------------------------------------------------------------------------
73
74PLUGIN_API int XPluginStart(char* outName, char* outSignature,
75 char* outDescription)
76{
[105]77 Log::registerFunction(&Util::debug);
[1]78 Util::debug("hu.varadiistvan.xplra called\n");
[0]79
80 strcpy(outName, "X-Plane Remote Access");
81 strcpy(outSignature, "hu.varadiistvan.xplra");
82 strcpy(outDescription, "Provides remote access to datarefs");
83
[9]84#if TARGET_API_POSIX
85 signal(SIGPIPE, SIG_IGN);
86#endif
87
[0]88 return 1;
89}
90
[1]91//------------------------------------------------------------------------------
[0]92
93PLUGIN_API void XPluginEnable(void)
94{
[1]95 Util::debug("hu.varadiistvan.xplra.XPluginEnable called\n");
[0]96 // XPLMRegisterFlightLoopCallback(&callback, 5.0, 0);
[36]97
[44]98 globals = new Globals();
[36]99
[44]100 listenThread = new ListenThread(*globals);
[0]101 listenThread->start();
102}
103
[1]104//------------------------------------------------------------------------------
105
[0]106PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFrom, long inMessage,
107 void* inParam)
108{
[1]109 Util::debug("hu.varadiistvan.xplra.XPluginReceiveMessage called, inFrom=%d, inMessage=%ld, inParam=%p\n",
[0]110 inFrom, inMessage, inParam);
111}
112
[1]113//------------------------------------------------------------------------------
114
[0]115PLUGIN_API void XPluginDisable(void)
116{
[1]117 Util::debug("hu.varadiistvan.xplra.XPluginDisable called\n");
[0]118 // XPLMUnregisterFlightLoopCallback(&callback, 0);
[38]119
[0]120 if (listenThread!=0) {
121 listenThread->quit();
[46]122 listenThread->join();
123 delete listenThread;
[0]124 listenThread = 0;
125 }
[38]126
[44]127 delete globals; globals = 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.