mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-08 03:35:35 +08:00
54 lines
1.5 KiB
C++
54 lines
1.5 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_XBUS_COMMAND_H
|
|
#define BLACKSIM_XBUS_COMMAND_H
|
|
|
|
//! \file
|
|
|
|
#include <XPLMUtilities.h>
|
|
#include <functional>
|
|
|
|
namespace XBus
|
|
{
|
|
|
|
/*!
|
|
* 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));
|
|
}
|
|
|
|
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
|