swift
fsuipc.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_SIMPLUGIN_FSUIPC_H
7 #define SWIFT_SIMPLUGIN_FSUIPC_H
8 
9 #include <QStringList>
10 
13 
14 namespace swift::simplugin::fscommon
15 {
17  class FSCOMMON_EXPORT CFsuipc : public QObject
18  {
19  Q_OBJECT
20 
21  public:
23  CFsuipc(QObject *parent = nullptr);
24 
26  virtual ~CFsuipc() override;
27 
29  bool open(bool force = false);
30 
32  void close();
33 
35  bool isOpened() const;
36 
38  bool isOpen() const;
39 
41  bool write(const swift::misc::aviation::CTransponder &xpdr);
42 
44  bool setSimulatorTime(int hour, int minute);
45 
47  QString getVersion() const;
48 
55  bool read(swift::misc::simulation::CSimulatedAircraft &aircraft, bool cockpit, bool situation,
56  bool aircraftParts);
57 
59  static const QStringList &errorMessages()
60  {
61  static const QStringList errors({
62  "Okay",
63  "Attempt to Open when already Open",
64  "Cannot link to FSUIPC or WideClient",
65  "Failed to Register common message with Windows",
66  "Failed to create Atom for mapping filename",
67  "Failed to create a file mapping object",
68  "Failed to open a view to the file map",
69  "Incorrect version of FSUIPC, or not FSUIPC",
70  "Sim is not version requested",
71  "Call cannot execute, link not Open",
72  "Call cannot execute: no requests accumulated",
73  "IPC timed out all retries",
74  "IPC sendmessage failed all retries",
75  "IPC request contains bad data",
76  "Maybe running on WideClient, but FS not running on Server, or wrong FSUIPC",
77  "Read or Write request cannot be added, memory for Process is full",
78  });
79  return errors;
80  }
81 
83  static const QString &errorMessage(int index)
84  {
85  if (index >= 0 && index < errorMessages().size()) { return errorMessages().at(index); }
86  static const QString unknown("Unknown error message index");
87  return unknown;
88  }
89 
91  static const QStringList &simulators()
92  {
93  static const QStringList sims(
94  { "any", "FS98", "FS2000", "CFS2", "CFS1", "Fly!", "FS2002", "FS2004", "FSX", "ESP", "P3D" });
95  return sims;
96  }
97 
99  static const QString &simulator(int index)
100  {
101  if (index >= 0 && index < simulators().size()) { return simulators().at(index); }
102  static const QString unknown("Unknown simulator index");
103  return unknown;
104  }
105 
106  private:
107  bool m_opened = false;
108  int m_openCount = 0;
109  int m_closeCount = 0;
110  int m_lastErrorIndex = 0;
111  QString m_lastErrorMessage;
112  QString m_fsuipcVersion;
113 
114  unsigned int m_lastTimestamp = 0;
115 
117  static double intToFractional(double fractional);
118  };
119 } // namespace swift::simplugin::fscommon
120 
121 #endif // SWIFT_SIMPLUGIN_FSUIPC_H
Comprehensive information of an aircraft.
Class representing a FSUIPC "interface".
Definition: fsuipc.h:18
static const QString & simulator(int index)
Simulator for index.
Definition: fsuipc.h:99
static const QStringList & errorMessages()
Error messages.
Definition: fsuipc.h:59
static const QString & errorMessage(int index)
Message for index.
Definition: fsuipc.h:83
static const QStringList & simulators()
Simulators.
Definition: fsuipc.h:91
#define FSCOMMON_EXPORT
FSCommon Export Macro.