32 #include "ccec/LibCCEC.hpp"
33 #include "ccec/Assert.hpp"
34 #include "ccec/Messages.hpp"
35 #include "ccec/Connection.hpp"
36 #include "ccec/MessageEncoder.hpp"
37 #include "ccec/MessageDecoder.hpp"
38 #include "ccec/MessageProcessor.hpp"
39 #include "ccec/Util.hpp"
40 #include "ccec/Host.hpp"
42 static CECHost_Err_t CECHost_HDMI_HotplugCallback_(int32_t connect);
43 static CECHost_Err_t CECHost_PowerStateCallback_ (int32_t curState, int32_t newState);
44 static CECHost_Err_t CECHost_DevMgrStatusCallback_(
bool ipStatus,
bool* opStatus);
45 static CECHost_Err_t CECHost_OSDNameCallback_(uint8_t *name,
size_t len);
52 static int file_exists(
const char *filename)
55 memset(&st,0,
sizeof(st));
57 if (0 == stat(filename,&st))
59 if (S_ISREG(st.st_mode))
67 static bool devMgrStatus =
false;
68 static int32_t cecClntRefCounter = 0;
69 static pthread_mutex_t devMgrMutex = PTHREAD_MUTEX_INITIALIZER;
82 static int32_t isConnected = 0;
84 static int32_t powerState = CECHost_POWERSTATE_STANDBY;
86 #define MAX_LOGICAL_ADDRESS 14
87 #define MAX_LENGTH_OF_OSD_NAME 15
92 static std::string CECHost_GetOSDName_Simple(
void)
94 uint8_t name[OSDName::MAX_LEN + 1] = {0};
95 size_t len = OSDName::MAX_LEN;
106 static int32_t CECHost_IsActive_Simple(
void)
110 if ((err == CECHost_ERR_NONE) && active) {
118 static int32_t CECHost_HDMI_IsConnected_Simple(uint8_t *byte0 = 0, uint8_t *byte1 = 0, uint8_t *byte2 = 0, uint8_t *byte3 = 0)
120 int32_t connected = 0;
122 if ((err == CECHost_ERR_NONE) && connected) {
130 static int32_t CECHost_GetPowerState_Simple(
void)
134 if (ret == CECHost_ERR_NONE) {
135 state = ((state == CECHost_POWERSTATE_ON) ? PowerStatus::ON : PowerStatus::STANDBY);
138 state = PowerStatus::STANDBY;
150 if (!(header.from ==
LogicalAddress(LogicalAddress::BROADCAST))) {
152 if (CECHost_IsActive_Simple() && (CECHost_HDMI_CONNECTED == isConnected)) {
153 CCEC_LOG( LOG_DEBUG,
"DevMgrProcessor:: Reporting ActiveSource\r\n");
161 if (!(header.from ==
LogicalAddress(LogicalAddress::BROADCAST))) {
162 CCEC_LOG( LOG_DEBUG,
"DevMgrProcessor:: Reporting OSDName\r\n");
170 if (!(header.from ==
LogicalAddress(LogicalAddress::BROADCAST))) {
172 CCEC_LOG( LOG_DEBUG,
"DevMgrProcessor:: Reporting DeviceVendorID\r\n");
180 if (!(header.from ==
LogicalAddress(LogicalAddress::BROADCAST))) {
182 CCEC_LOG( LOG_DEBUG,
"DevMgrProcessor:: Reporting DevicePowerStatus\r\n");
189 if (!(header.from ==
LogicalAddress(LogicalAddress::BROADCAST))) {
190 CCEC_LOG( LOG_DEBUG,
"DevMgrProcessor:: Reporting CECVersion\r\n");
196 if (!(header.from ==
LogicalAddress(LogicalAddress::BROADCAST))) {
198 CCEC_LOG( LOG_DEBUG,
"DevMgrProcessor:: Reporting PhysicalAddress\r\n");
204 virtual void process (
const Standby &msg,
const Header &header) {
228 void notify(
const CECFrame &in)
const {
236 int main(
int argc,
char *argv[])
238 setvbuf(stdout, NULL, _IOLBF, 0);
240 CECHost_LoadPlugin();
245 CECHost_PowerStateCallback_,
255 CCEC_LOG( LOG_WARN,
"Calling CECHost_IsHdmiOutputConnected\r\n");
258 isConnected = CECHost_HDMI_CONNECTED;
260 isConnected = CECHost_HDMI_DISCONNECTED;
261 uint8_t byte0, byte1, byte2, byte3;
264 CCEC_LOG( LOG_WARN,
"PhysicalAddress : %s\n", phy.toString().c_str());
267 CCEC_LOG( LOG_WARN,
"PhysicalAddress cannot be obtained: \n");
272 CCEC_LOG( LOG_WARN,
"Calling CECHost_GetPowerState\r\n");
278 CCEC_LOG( LOG_WARN,
"PowerState cannot be obtained: \n");
284 Connection conn(LogicalAddress::TUNER_1,
false,
"CECDevMgr::Connection::");
290 conn.addFrameListener(&frameListener);
297 CCEC_LOG( LOG_WARN,
"DevMgr Heartbeating %d\r\n", j++);
307 CECHost_UnloadPlugin();
311 static CECHost_Err_t CECHost_HDMI_HotplugCallback_(int32_t connect)
313 CCEC_LOG( LOG_WARN,
"Dev Manager received Hot plug event \r\n");
315 if(CECHost_HDMI_CONNECTED == connect)
317 uint8_t byte0, byte1, byte2, byte3;
320 CCEC_LOG( LOG_WARN,
"PhysicalAddress : %s\n", phy.toString().c_str());
323 CCEC_LOG( LOG_WARN,
"PhysicalAddress cannot be obtained: \n");
330 return CECHost_ERR_NONE;
336 static CECHost_Err_t CECHost_PowerStateCallback_(int32_t curState, int32_t newState)
338 if (newState == CECHost_POWERSTATE_ON) {
339 CCEC_LOG( LOG_DEBUG,
"DevMgrProcessor:: Send ImageViewOn and ActiveSource\r\n");
344 CCEC_LOG( LOG_DEBUG,
"DevMgrProcessor:: Send InActiveSource\r\n");
348 powerState = newState;
349 return CECHost_ERR_NONE;