MythTV  master
mythcecadapter.h
Go to the documentation of this file.
1 #ifndef CECADAPTER_H_
2 #define CECADAPTER_H_
3 
4 // Qt
5 #include <QObject>
6 
7 #define LIBCEC_ENABLED QString("libCECEnabled")
8 #define LIBCEC_DEVICE QString("libCECDevice")
9 #define LIBCEC_BASE QString("libCECBase")
10 #define LIBCEC_PORT QString("libCECPort")
11 #define POWEROFFTV_ALLOWED QString("PowerOffTVAllowed")
12 #define POWEROFFTV_ONEXIT QString("PowerOffTVOnExit")
13 #define POWERONTV_ALLOWED QString("PowerOnTVAllowed")
14 #define POWERONTV_ONSTART QString("PowerOnTVOnStart")
15 
16 // libcec
17 #include <libcec/cec.h>
18 #include <iostream>
19 using namespace CEC;
20 
21 class MythMainWindow;
22 
24 {
25  public:
26  enum MythCECAction : std::uint8_t
27  {
28  None = 0x00,
29  PowerOffTV = 0x01,
30  PowerOnTV = 0x02,
31  SwitchInput = 0x04
32  };
33 
34  Q_DECLARE_FLAGS(MythCECActions, MythCECAction)
35 
36 #if CEC_LIB_VERSION_MAJOR <= 3
37  static int LogMessageCallback(void* /*unused*/, const cec_log_message Message);
38  static int KeyPressCallback (void* Adapter, const cec_keypress Keypress);
39  static int CommandCallback (void* Adapter, const cec_command Command);
40  static int AlertCallback (void* /*unused*/, const libcec_alert Alert, const libcec_parameter Data);
41 #else
42  static void LogMessageCallback(void* /*unused*/, const cec_log_message* Message);
43  static void KeyPressCallback (void* Adapter, const cec_keypress* Keypress);
44  static void CommandCallback (void* Adapter, const cec_command* Command);
45  static void AlertCallback (void* /*unused*/, libcec_alert Alert, libcec_parameter Data);
46 #endif
47  static void SourceCallback (void* /*unused*/, cec_logical_address Address, uint8_t Activated);
48  static QString AddressToString(int Address);
49 
50  MythCECAdapter() = default;
51  ~MythCECAdapter();
52  void Open (MythMainWindow* Window);
53  void Close (void);
54  void Action (const QString &Action);
55  void IgnoreKeys (bool Ignore);
56 
57  protected:
58  void HandleActions (MythCECActions Actions);
59  int HandleCommand (const cec_command &Command);
60  int HandleKeyPress(cec_keypress Key) const;
61  static void HandleSource (cec_logical_address Address, uint8_t Activated);
62  static int LogMessage (const cec_log_message &Message);
63  static int HandleAlert (libcec_alert Alert, libcec_parameter Data);
64 
65  protected:
66  ICECAdapter *m_adapter { nullptr };
67  ICECCallbacks m_callbacks;
68  bool m_valid { false };
69  bool m_ignoreKeys { false };
70  bool m_powerOffTVAllowed { false };
71  bool m_powerOffTVOnExit { false };
72  bool m_powerOnTVAllowed { false };
73  bool m_powerOnTVOnStart { false };
74  bool m_switchInputAllowed { true };
75 };
76 #endif
77 
MythCECAdapter::m_callbacks
ICECCallbacks m_callbacks
Definition: mythcecadapter.h:67
AutoExtendType::None
@ None
Action
An action (for this plugin) consists of a description, and a set of key sequences.
Definition: action.h:40
Command
Definition: gamesettings.cpp:233
MythCECAdapter::MythCECAction
MythCECAction
Definition: mythcecadapter.h:26
MythCECAdapter
Definition: mythcecadapter.h:23
MythMainWindow
Definition: mythmainwindow.h:28