mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-08 03:35:35 +08:00
Summary: I wanted to rename xbus because its relation to //swift// is not immediately clear from the name. xswiftbus seems reasonable. Reviewers: #swift_pilot_client, kbasan Reviewed By: kbasan Subscribers: kbasan, jenkins Tags: #swift_pilot_client Differential Revision: https://dev.swift-project.org/D14
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
/* Copyright (C) 2015
|
|
* swift project Community / Contributors
|
|
*
|
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
|
* contained in the LICENSE file.
|
|
*/
|
|
|
|
#ifndef BLACKSIM_XSWIFTBUS_COMMAND_H
|
|
#define BLACKSIM_XSWIFTBUS_COMMAND_H
|
|
|
|
//! \file
|
|
|
|
#include <XPLMUtilities.h>
|
|
#include <functional>
|
|
|
|
namespace XSwiftBus
|
|
{
|
|
|
|
/*!
|
|
* Class-based interface to X-Plane's custom command API.
|
|
*/
|
|
class CCommand
|
|
{
|
|
public:
|
|
//! Constructor.
|
|
CCommand(const char *name, const char *description, std::function<void()> handler) : m_handler(handler)
|
|
{
|
|
m_command = XPLMCreateCommand(name, description);
|
|
XPLMRegisterCommandHandler(m_command, callback, false, static_cast<void*>(this));
|
|
}
|
|
|
|
//! Destructor.
|
|
~CCommand()
|
|
{
|
|
XPLMUnregisterCommandHandler(m_command, callback, false, static_cast<void*>(this));
|
|
}
|
|
|
|
//! Not copyable.
|
|
//! @{
|
|
CCommand(const CCommand &) = delete;
|
|
CCommand &operator =(const CCommand &) = delete;
|
|
//! @}
|
|
|
|
private:
|
|
static int callback(XPLMCommandRef, XPLMCommandPhase phase, void *refcon)
|
|
{
|
|
if (phase == xplm_CommandBegin) { (static_cast<CCommand*>(refcon)->m_handler)(); }
|
|
return 1;
|
|
}
|
|
|
|
std::function<void()> m_handler;
|
|
XPLMCommandRef m_command;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|