forked from bramp/libcec-daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibcec.h
86 lines (66 loc) · 2.75 KB
/
libcec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <cstddef>
#include <libcec/cec.h>
#include <memory>
#include <map>
#include <string>
namespace HDMI {
class physical_address;
class address;
}
class CecCallback {
public:
virtual ~CecCallback() {}
// Virtual methods to handle callbacks
virtual int onCecLogMessage(const CEC::cec_log_message & message) = 0;
virtual int onCecKeyPress (const CEC::cec_keypress & key) = 0;
virtual int onCecCommand (const CEC::cec_command & command) = 0;
virtual int onCecConfigurationChanged(const CEC::libcec_configuration & configuration) = 0;
virtual int onCecAlert(const CEC::libcec_alert alert, const CEC::libcec_parameter & param) = 0;
virtual int onCecMenuStateChanged(const CEC::cec_menu_state & menu_state) = 0;
virtual void onCecSourceActivated(const CEC::cec_logical_address & address, bool bActivated) = 0;
};
/**
* Simple wrapper class around libcec
*/
class Cec {
private:
static std::map<CEC::cec_user_control_code, const char *> & setupUserControlCodeName();
// Members for the libcec interface
CEC::ICECCallbacks callbacks;
CEC::libcec_configuration config;
std::unique_ptr<CEC::ICECAdapter> cec;
// Inits the CECAdapter
void init();
public:
const static std::map<CEC::cec_user_control_code, const char *> cecUserControlCodeName;
Cec(const char *name, CecCallback *callback);
virtual ~Cec();
/**
* List all found adapters and prints them out
*/
std::ostream & listDevices(std::ostream & out);
/**
* Opens the first adapter it finds
*/
void open(const std::string &adapter = "");
/**
* Closes the open adapter
*/
void close(bool makeInactive = true);
void makeActive();
void setTargetAddress(const HDMI::address & address);
bool ping();
// These are just wrapper functions, to map C callbacks to C++
friend int cecLogMessage (void *cbParam, const CEC::cec_log_message &message);
friend int cecKeyPress (void *cbParam, const CEC::cec_keypress &key);
friend int cecCommand (void *cbParam, const CEC::cec_command &command);
friend int cecConfigurationChanged (void *cbParam, const CEC::libcec_configuration & configuration);
friend int cecAlert(void *cbParam, const CEC::libcec_alert alert, const CEC::libcec_parameter & param);
friend int cecMenuStateChanged(void *cbParam, const CEC::cec_menu_state & menu_state);
friend void cecSourceActivated(void *cbParam, const CEC::cec_logical_address & address, const uint8_t bActivated);
};
// Some helper << methods
std::ostream& operator<<(std::ostream &out, const CEC::cec_log_message & message);
std::ostream& operator<<(std::ostream &out, const CEC::cec_keypress & key);
std::ostream& operator<<(std::ostream &out, const CEC::cec_command & command);
std::ostream& operator<<(std::ostream &out, const CEC::libcec_configuration & configuration);