source: xplra/src/plugin/src/xplra/plugin.cc@ 43:d05df1944444

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

Moved the menu handling into its own class

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