swift
Loading...
Searching...
No Matches
command.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4#ifndef SWIFT_SIM_XSWIFTBUS_COMMAND_H
5#define SWIFT_SIM_XSWIFTBUS_COMMAND_H
6
8
9#include <XPLMUtilities.h>
10
11#include <functional>
12
13namespace XSwiftBus
14{
15
20 {
21 public:
23 CCommand(const char *name, const char *description, std::function<void()> handler)
24 : m_handler(handler), m_command(XPLMCreateCommand(name, description))
25 {
26 XPLMRegisterCommandHandler(m_command, callback, false, static_cast<void *>(this));
27 }
28
30 ~CCommand() { XPLMUnregisterCommandHandler(m_command, callback, false, static_cast<void *>(this)); }
31
34 CCommand(const CCommand &) = delete;
35 CCommand &operator=(const CCommand &) = delete;
37
38 private:
39 static int callback(XPLMCommandRef, XPLMCommandPhase phase, void *refcon)
40 {
41 if (phase == xplm_CommandBegin)
42 {
43 (static_cast<CCommand *>(refcon)->m_handler)();
44 }
45 return 1;
46 }
47
48 std::function<void()> m_handler;
49 XPLMCommandRef m_command;
50 };
51
52} // namespace XSwiftBus
53
54#endif // SWIFT_SIM_XSWIFTBUS_COMMAND_H
CCommand(const CCommand &)=delete
Not copyable.
CCommand & operator=(const CCommand &)=delete
Not copyable.
~CCommand()
Destructor.
Definition command.h:30
CCommand(const char *name, const char *description, std::function< void()> handler)
Constructor.
Definition command.h:23
Plugin loaded by X-Plane which publishes a DBus service.
Definition command.h:14