FlightGear next
swift_connection.cxx
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: (C) 2019-2022 swift Project Community / Contributors (https://swift-project.org/)
3 * SPDX-FileCopyrightText: (C) 2019-2022 Lars Toenning <dev@ltoenning.de>
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifdef HAVE_CONFIG_H
8#include <config.h>
9#endif
10
11#include "plugin.h"
12#include "swift_connection.hxx"
13#include <Main/fg_props.hxx>
14#include <simgear/props/props.hxx>
15#include <simgear/structure/commands.hxx>
16#include <simgear/structure/event_mgr.hxx>
17#include <simgear/structure/subsystem_mgr.hxx>
18
19namespace flightgear::swift {
20
21bool SwiftConnection::startServer([[maybe_unused]] const SGPropertyNode*, [[maybe_unused]] SGPropertyNode* root)
22{
23 m_plugin = std::make_unique<CPlugin>();
24 return true;
25}
26
27bool SwiftConnection::stopServer([[maybe_unused]] const SGPropertyNode* arg, [[maybe_unused]] SGPropertyNode* root)
28{
29 m_plugin.reset();
30 return true;
31}
32
34{
35 shutdownSwift();
36}
37
39{
40 if (!m_initialized) {
41 globals->get_commands()->addCommand("swiftStart", this, &SwiftConnection::startServer);
42 globals->get_commands()->addCommand("swiftStop", this, &SwiftConnection::stopServer);
43
44 fgSetBool("/sim/swift/available", true);
45 m_initialized = true;
46 }
47}
48
49void SwiftConnection::update(double delta_time_sec)
50{
51 if (m_plugin) {
52 m_plugin->fastLoop();
53 }
54}
55
57{
58 shutdownSwift();
59}
60
61void SwiftConnection::shutdownSwift()
62{
63 if (m_initialized) {
64 fgSetBool("/sim/swift/available", false);
65 m_initialized = false;
66
67 globals->get_commands()->removeCommand("swiftStart");
68 globals->get_commands()->removeCommand("swiftStop");
69 }
70}
71
73{
74 shutdown();
75 init();
76}
77
78} // namespace flightgear::swift
79
80// Register the subsystem.
81SGSubsystemMgr::Registrant<flightgear::swift::SwiftConnection> registrantSwiftConnection(
82 SGSubsystemMgr::POST_FDM);
void update(double delta_time_sec) override
FGGlobals * globals
Definition globals.cxx:142
bool fgSetBool(char const *name, bool val)
Set a bool value for a property.
Definition proptest.cpp:24
SGSubsystemMgr::Registrant< flightgear::swift::SwiftConnection > registrantSwiftConnection(SGSubsystemMgr::POST_FDM)