Maintenance: swift_connection
Fix memory leaks. Fix mixed use of tab/spaces for indentation.
This commit is contained in:
parent
0ee3fd4ab6
commit
82c34590f6
2 changed files with 36 additions and 29 deletions
|
@ -1,5 +1,5 @@
|
|||
// swift_connection.cxx
|
||||
//
|
||||
// swift_connection.cxx
|
||||
//
|
||||
// Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/)
|
||||
// Adapted to Flightgear by Lars Toenning <dev@ltoenning.de>
|
||||
//
|
||||
|
@ -43,18 +43,21 @@ inline std::string fgswiftbusServiceName()
|
|||
|
||||
bool SwiftConnection::startServer(const SGPropertyNode* arg, SGPropertyNode* root)
|
||||
{
|
||||
SwiftConnection::plug = new FGSwiftBus::CPlugin();
|
||||
serverRunning = true;
|
||||
SwiftConnection::plug = std::make_unique<FGSwiftBus::CPlugin>();
|
||||
|
||||
serverRunning = true;
|
||||
fgSetBool("/sim/swift/serverRunning", true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SwiftConnection::stopServer(const SGPropertyNode* arg, SGPropertyNode* root)
|
||||
{
|
||||
delete SwiftConnection::plug;
|
||||
SwiftConnection::plug = nullptr;
|
||||
fgSetBool("/sim/swift/serverRunning", false);
|
||||
serverRunning = false;
|
||||
serverRunning = false;
|
||||
|
||||
SwiftConnection::plug.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -63,39 +66,42 @@ SwiftConnection::SwiftConnection()
|
|||
init();
|
||||
}
|
||||
|
||||
|
||||
SwiftConnection::~SwiftConnection()
|
||||
{
|
||||
shutdown();
|
||||
|
||||
if (serverRunning) {
|
||||
SwiftConnection::plug.release();
|
||||
}
|
||||
}
|
||||
|
||||
void SwiftConnection::init()
|
||||
{
|
||||
if (!initialized) {
|
||||
if (!initialized) {
|
||||
globals->get_commands()->addCommand("swiftStart", this, &SwiftConnection::startServer);
|
||||
globals->get_commands()->addCommand("swiftStop", this, &SwiftConnection::stopServer);
|
||||
|
||||
fgSetBool("/sim/swift/available", true);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void SwiftConnection::update(double delta_time_sec)
|
||||
{
|
||||
if (serverRunning) {
|
||||
if (serverRunning) {
|
||||
SwiftConnection::plug->fastLoop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SwiftConnection::shutdown()
|
||||
{
|
||||
if (initialized) {
|
||||
globals->get_commands()->removeCommand("swiftStart");
|
||||
globals->get_commands()->removeCommand("swiftStop");
|
||||
if (initialized) {
|
||||
fgSetBool("/sim/swift/available", false);
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
globals->get_commands()->removeCommand("swiftStart");
|
||||
globals->get_commands()->removeCommand("swiftStop");
|
||||
}
|
||||
}
|
||||
|
||||
void SwiftConnection::reinit()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// swift_connection.hxx
|
||||
//
|
||||
//
|
||||
// Copyright (C) 2019 - swift Project Community / Contributors (http://swift-project.org/)
|
||||
// Adapted to Flightgear by Lars Toenning <dev@ltoenning.de>
|
||||
//
|
||||
|
@ -17,19 +17,21 @@
|
|||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#ifndef SWIFT_CONNECTION_H
|
||||
#define SWIFT_CONNECTION_H
|
||||
#include "dbusconnection.h"
|
||||
#include "dbusdispatcher.h"
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/io/raw_socket.hxx>
|
||||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include "plugin.h"
|
||||
|
||||
#include "dbusconnection.h"
|
||||
#include "dbusdispatcher.h"
|
||||
#include "dbusserver.h"
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include "plugin.h"
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
|
@ -52,11 +54,10 @@ public:
|
|||
|
||||
bool startServer(const SGPropertyNode* arg, SGPropertyNode* root);
|
||||
bool stopServer(const SGPropertyNode* arg, SGPropertyNode* root);
|
||||
FGSwiftBus::CPlugin* plug{};
|
||||
|
||||
std::unique_ptr<FGSwiftBus::CPlugin> plug{};
|
||||
|
||||
private:
|
||||
bool serverRunning = false;
|
||||
bool initialized = false;
|
||||
bool initialized = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue