mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Refactor event handling incl.CEC
This commit is contained in:
@@ -32,6 +32,12 @@ add_subdirectory(db)
|
||||
add_subdirectory(api)
|
||||
add_subdirectory(ssdp)
|
||||
|
||||
if(ENABLE_CEC)
|
||||
add_subdirectory(cec)
|
||||
endif()
|
||||
|
||||
add_subdirectory(events)
|
||||
|
||||
if(ENABLE_MDNS)
|
||||
add_subdirectory(mdns)
|
||||
endif()
|
||||
@@ -41,10 +47,6 @@ if(ENABLE_EFFECTENGINE)
|
||||
add_subdirectory(python)
|
||||
endif()
|
||||
|
||||
if(ENABLE_CEC)
|
||||
add_subdirectory(cec)
|
||||
endif()
|
||||
|
||||
if(ENABLE_EXPERIMENTAL)
|
||||
add_subdirectory(experimental)
|
||||
endif()
|
||||
|
@@ -22,6 +22,7 @@
|
||||
#include <grabber/QtGrabber.h>
|
||||
|
||||
#include <utils/WeakConnect.h>
|
||||
#include <events/Event.h>
|
||||
|
||||
#if defined(ENABLE_MF)
|
||||
#include <grabber/MFGrabber.h>
|
||||
@@ -82,6 +83,7 @@
|
||||
|
||||
// api includes
|
||||
#include <api/JsonCB.h>
|
||||
#include <events/EventHandler.h>
|
||||
|
||||
// auth manager
|
||||
#include <hyperion/AuthManager.h>
|
||||
@@ -110,6 +112,8 @@ JsonAPI::JsonAPI(QString peerAddress, Logger *log, bool localConnection, QObject
|
||||
_ledStreamTimer = new QTimer(this);
|
||||
|
||||
Q_INIT_RESOURCE(JSONRPC_schemas);
|
||||
|
||||
qRegisterMetaType<Event>("Event");
|
||||
}
|
||||
|
||||
void JsonAPI::initialize()
|
||||
@@ -135,16 +139,13 @@ void JsonAPI::initialize()
|
||||
connect(this, &JsonAPI::forwardJsonMessage, _hyperion, &Hyperion::forwardJsonMessage);
|
||||
}
|
||||
|
||||
//notify instance manager on suspend/resume/idle requests
|
||||
connect(this, &JsonAPI::suspendAll, _instanceManager, &HyperionIManager::triggerSuspend);
|
||||
connect(this, &JsonAPI::toggleSuspendAll, _instanceManager, &HyperionIManager::triggerToggleSuspend);
|
||||
connect(this, &JsonAPI::idleAll, _instanceManager, &HyperionIManager::triggerIdle);
|
||||
connect(this, &JsonAPI::toggleIdleAll, _instanceManager, &HyperionIManager::triggerToggleIdle);
|
||||
//notify eventhadler on suspend/resume/idle requests
|
||||
connect(this, &JsonAPI::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent);
|
||||
|
||||
connect(_ledStreamTimer, &QTimer::timeout, this, &JsonAPI::streamLedColorsUpdate, Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
bool JsonAPI::handleInstanceSwitch(quint8 inst, bool forced)
|
||||
bool JsonAPI::handleInstanceSwitch(quint8 inst, bool /*forced*/)
|
||||
{
|
||||
if (API::setHyperionInstance(inst))
|
||||
{
|
||||
@@ -1014,8 +1015,7 @@ void JsonAPI::handleConfigCommand(const QJsonObject &message, const QString &com
|
||||
if (_adminAuthorized)
|
||||
{
|
||||
Debug(_log, "Restarting due to RPC command");
|
||||
|
||||
Process::restartHyperion(10);
|
||||
emit signalEvent(Event::Reload);
|
||||
|
||||
sendSuccessReply(command + "-" + subcommand, tan);
|
||||
}
|
||||
@@ -1852,32 +1852,37 @@ void JsonAPI::handleSystemCommand(const QJsonObject &message, const QString &com
|
||||
|
||||
if (subc == "suspend")
|
||||
{
|
||||
emit suspendAll(true);
|
||||
emit signalEvent(Event::Suspend);
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else if (subc == "resume")
|
||||
{
|
||||
emit suspendAll(false);
|
||||
emit signalEvent(Event::Resume);
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else if (subc == "restart")
|
||||
{
|
||||
Process::restartHyperion(11);
|
||||
emit signalEvent(Event::Restart);
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else if (subc == "toggleSuspend")
|
||||
{
|
||||
emit toggleSuspendAll();
|
||||
emit signalEvent(Event::ToggleSuspend);
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else if (subc == "idle")
|
||||
{
|
||||
emit idleAll(true);
|
||||
emit signalEvent(Event::Idle);
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else if (subc == "resumeIdle")
|
||||
{
|
||||
emit signalEvent(Event::ResumeIdle);
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else if (subc == "toggleIdle")
|
||||
{
|
||||
emit toggleIdleAll();
|
||||
emit signalEvent(Event::ToggleIdle);
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <libcec/cecloader.h>
|
||||
#include <events/EventHandler.h>
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
@@ -12,13 +13,14 @@
|
||||
#include <QFile>
|
||||
|
||||
/* Enable to turn on detailed CEC logs */
|
||||
#define NO_VERBOSE_CEC
|
||||
#define VERBOSE_CEC
|
||||
|
||||
CECHandler::CECHandler()
|
||||
: _isEnabled(false)
|
||||
{
|
||||
qRegisterMetaType<CECEvent>("CECEvent");
|
||||
qRegisterMetaType<Event>("Event");
|
||||
|
||||
_logger = Logger::getInstance("CEC");
|
||||
_logger = Logger::getInstance("CEC");
|
||||
|
||||
_cecCallbacks = getCallbacks();
|
||||
_cecConfig = getConfig();
|
||||
@@ -31,25 +33,41 @@ CECHandler::~CECHandler()
|
||||
stop();
|
||||
}
|
||||
|
||||
void CECHandler::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
||||
{
|
||||
if(type == settings::CECEVENTS)
|
||||
{
|
||||
const QJsonObject& obj = config.object();
|
||||
|
||||
_isEnabled = obj["Enable"].toBool(false);
|
||||
|
||||
Debug(_logger, "_isEnabled: [%d]", _isEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
bool CECHandler::start()
|
||||
{
|
||||
if (_cecAdapter)
|
||||
return true;
|
||||
|
||||
std::string library = std::string("" CEC_LIBRARY);
|
||||
_cecAdapter = LibCecInitialise(&_cecConfig, QFile::exists(QString::fromStdString(library)) ? library.c_str() : nullptr);
|
||||
if(!_cecAdapter)
|
||||
{
|
||||
Error(_logger, "Failed to loading libcec.so");
|
||||
return true;
|
||||
}
|
||||
|
||||
// std::string library = std::string("" CEC_LIBRARY);
|
||||
// _cecAdapter = LibCecInitialise(&_cecConfig, QFile::exists(QString::fromStdString(library)) ? library.c_str() :CEC_DEVICE_TYPE_PLAYBACK_DEVICE nullptr);
|
||||
|
||||
_cecAdapter = LibCecInitialise(&_cecConfig);
|
||||
if(_cecAdapter == nullptr)
|
||||
{
|
||||
Error(_logger, "Failed loading libCEC library. CEC is not supported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Info(_logger, "CEC handler started");
|
||||
|
||||
auto adapters = getAdapters();
|
||||
const auto adapters = getAdapters();
|
||||
if (adapters.isEmpty())
|
||||
{
|
||||
Error(_logger, "Failed to find CEC adapter");
|
||||
Error(_logger, "Failed to find any CEC adapter.");
|
||||
UnloadLibCec(_cecAdapter);
|
||||
_cecAdapter = nullptr;
|
||||
|
||||
@@ -64,14 +82,19 @@ bool CECHandler::start()
|
||||
|
||||
if (!opened && openAdapter(adapter))
|
||||
{
|
||||
Info(_logger, "CEC Handler initialized with adapter : %s", adapter.strComName);
|
||||
QObject::connect(this, &CECHandler::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent);
|
||||
|
||||
Info(_logger, "CEC adapter '%s', type: %s initialized." , adapter.strComName, _cecAdapter->ToString(adapter.adapterType));
|
||||
opened = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
scan();
|
||||
|
||||
if (!opened)
|
||||
{
|
||||
Error(_logger, "Could not initialize any CEC adapter.");
|
||||
UnloadLibCec(_cecAdapter);
|
||||
_cecAdapter = nullptr;
|
||||
}
|
||||
@@ -81,10 +104,12 @@ bool CECHandler::start()
|
||||
|
||||
void CECHandler::stop()
|
||||
{
|
||||
if (_cecAdapter)
|
||||
if (_cecAdapter != nullptr)
|
||||
{
|
||||
Info(_logger, "Stopping CEC handler");
|
||||
|
||||
QObject::disconnect(this, &CECHandler::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent);
|
||||
|
||||
_cecAdapter->Close();
|
||||
UnloadLibCec(_cecAdapter);
|
||||
_cecAdapter = nullptr;
|
||||
@@ -97,9 +122,9 @@ CECConfig CECHandler::getConfig() const
|
||||
|
||||
const std::string name("HyperionCEC");
|
||||
name.copy(configuration.strDeviceName, std::min(name.size(), sizeof(configuration.strDeviceName)));
|
||||
|
||||
configuration.deviceTypes.Add(CEC::CEC_DEVICE_TYPE_RECORDING_DEVICE);
|
||||
configuration.clientVersion = CEC::LIBCEC_VERSION_CURRENT;
|
||||
configuration.bActivateSource = 0;
|
||||
|
||||
return configuration;
|
||||
}
|
||||
@@ -125,7 +150,8 @@ QVector<CECAdapterDescriptor> CECHandler::getAdapters() const
|
||||
return {};
|
||||
|
||||
QVector<CECAdapterDescriptor> descriptors(16);
|
||||
int8_t size = _cecAdapter->DetectAdapters(descriptors.data(), descriptors.size(), nullptr, true /*quickscan*/);
|
||||
//int8_t size = _cecAdapter->DetectAdapters(descriptors.data(), static_cast<uint8_t>(descriptors.size()), nullptr, true /*quickscan*/);
|
||||
int8_t size = _cecAdapter->DetectAdapters(descriptors.data(), static_cast<uint8_t>(descriptors.size()), nullptr, false /*NO quickscan*/);
|
||||
descriptors.resize(size);
|
||||
|
||||
return descriptors;
|
||||
@@ -138,10 +164,7 @@ bool CECHandler::openAdapter(const CECAdapterDescriptor & descriptor)
|
||||
|
||||
if(!_cecAdapter->Open(descriptor.strComName))
|
||||
{
|
||||
Error(_logger, "%s", QSTRING_CSTR(QString("Failed to open the CEC adaper on port %1")
|
||||
.arg(descriptor.strComName))
|
||||
);
|
||||
|
||||
Error(_logger, "CEC adapter '%s', type: %s failed to open.", descriptor.strComName, _cecAdapter->ToString(descriptor.adapterType));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -149,9 +172,16 @@ bool CECHandler::openAdapter(const CECAdapterDescriptor & descriptor)
|
||||
|
||||
void CECHandler::printAdapter(const CECAdapterDescriptor & descriptor) const
|
||||
{
|
||||
Info(_logger, "%s", QSTRING_CSTR(QString("CEC Adapter:")));
|
||||
Info(_logger, "%s", QSTRING_CSTR(QString("\tName : %1").arg(descriptor.strComName)));
|
||||
Info(_logger, "%s", QSTRING_CSTR(QString("\tPath : %1").arg(descriptor.strComPath)));
|
||||
Info(_logger, "CEC Adapter:");
|
||||
Info(_logger, "\tName : %s", descriptor.strComName);
|
||||
Info(_logger, "\tPath : %s", descriptor.strComPath);
|
||||
Info(_logger, "\tVendor id: %04x", descriptor.iVendorId);
|
||||
Info(_logger, "\tProduct id: %04x", descriptor.iProductId);
|
||||
Info(_logger, "\tFirmware id: %d", descriptor.iFirmwareVersion);
|
||||
if (descriptor.adapterType != CEC::ADAPTERTYPE_UNKNOWN)
|
||||
{
|
||||
Info(_logger, "\tType : %s", _cecAdapter->ToString(descriptor.adapterType));
|
||||
}
|
||||
}
|
||||
|
||||
QString CECHandler::scan() const
|
||||
@@ -163,14 +193,14 @@ QString CECHandler::scan() const
|
||||
|
||||
QJsonArray devices;
|
||||
CECLogicalAddresses addresses = _cecAdapter->GetActiveDevices();
|
||||
for (int address = CEC::CECDEVICE_TV; address <= CEC::CECDEVICE_BROADCAST; ++address)
|
||||
for (uint8_t address = CEC::CECDEVICE_TV; address <= CEC::CECDEVICE_BROADCAST; ++address)
|
||||
{
|
||||
if (addresses[address])
|
||||
if (addresses[address] != 0)
|
||||
{
|
||||
CECLogicalAddress logicalAddress = (CECLogicalAddress)address;
|
||||
CECLogicalAddress logicalAddress = static_cast<CECLogicalAddress>(address);
|
||||
|
||||
QJsonObject device;
|
||||
CECVendorId vendor = (CECVendorId)_cecAdapter->GetDeviceVendorId(logicalAddress);
|
||||
CECVendorId vendor = static_cast<CECVendorId>(_cecAdapter->GetDeviceVendorId(logicalAddress));
|
||||
CECPowerStatus power = _cecAdapter->GetDevicePowerStatus(logicalAddress);
|
||||
|
||||
device["name" ] = _cecAdapter->GetDeviceOSDName(logicalAddress).c_str();
|
||||
@@ -181,14 +211,17 @@ QString CECHandler::scan() const
|
||||
devices << device;
|
||||
|
||||
Info(_logger, "%s", QSTRING_CSTR(QString("\tCECDevice: %1 / %2 / %3 / %4")
|
||||
.arg(device["name"].toString(),
|
||||
device["vendor"].toString(),
|
||||
device["address"].toString(),
|
||||
device["power"].toString()))
|
||||
.arg(device["name"].toString(),
|
||||
device["vendor"].toString(),
|
||||
device["address"].toString(),
|
||||
device["power"].toString())
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Devices: " << QJsonDocument(devices).toJson().toStdString() << std::endl;
|
||||
|
||||
return QJsonDocument(devices).toJson(QJsonDocument::Compact);
|
||||
}
|
||||
|
||||
@@ -202,25 +235,17 @@ void CECHandler::onCecLogMessage(void * context, const CECLogMessage * message)
|
||||
switch (message->level)
|
||||
{
|
||||
case CEC::CEC_LOG_ERROR:
|
||||
Error(handler->_logger, QString("%1")
|
||||
.arg(message->message)
|
||||
.toLocal8Bit());
|
||||
Error(handler->_logger, "%s", message->message);
|
||||
break;
|
||||
case CEC::CEC_LOG_WARNING:
|
||||
Warning(handler->_logger, QString("%1")
|
||||
.arg(message->message)
|
||||
.toLocal8Bit());
|
||||
Warning(handler->_logger, "%s", message->message);
|
||||
break;
|
||||
case CEC::CEC_LOG_TRAFFIC:
|
||||
case CEC::CEC_LOG_NOTICE:
|
||||
Info(handler->_logger, QString("%1")
|
||||
.arg(message->message)
|
||||
.toLocal8Bit());
|
||||
Info(handler->_logger, "%s", message->message);
|
||||
break;
|
||||
case CEC::CEC_LOG_DEBUG:
|
||||
Debug(handler->_logger, QString("%1")
|
||||
.arg(message->message)
|
||||
.toLocal8Bit());
|
||||
Debug(handler->_logger, "%s", message->message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -230,29 +255,44 @@ void CECHandler::onCecLogMessage(void * context, const CECLogMessage * message)
|
||||
|
||||
void CECHandler::onCecKeyPress(void * context, const CECKeyPress * key)
|
||||
{
|
||||
#ifdef VERBOSE_CEC
|
||||
CECHandler * handler = qobject_cast<CECHandler*>(static_cast<QObject*>(context));
|
||||
if (!handler)
|
||||
return;
|
||||
|
||||
CECAdapter * adapter = handler->_cecAdapter;
|
||||
|
||||
Debug(handler->_logger, QString("CECHandler::onCecKeyPress: %1")
|
||||
.arg(adapter->ToString(key->keycode))
|
||||
.toLocal8Bit());
|
||||
#ifdef VERBOSE_CEC
|
||||
Debug(handler->_logger, "CECHandler::onCecKeyPress: %s", adapter->ToString(key->keycode));
|
||||
#endif
|
||||
|
||||
switch (key->keycode) {
|
||||
case CEC::CEC_USER_CONTROL_CODE_F1_BLUE:
|
||||
emit handler->signalEvent(Event::ToggleIdle);
|
||||
break;
|
||||
case CEC::CEC_USER_CONTROL_CODE_F2_RED:
|
||||
emit handler->signalEvent(Event::Suspend);
|
||||
break;
|
||||
case CEC::CEC_USER_CONTROL_CODE_F3_GREEN:
|
||||
emit handler->signalEvent(Event::Resume);
|
||||
break;
|
||||
|
||||
case CEC::CEC_USER_CONTROL_CODE_F4_YELLOW:
|
||||
emit handler->signalEvent(Event::ToggleSuspend);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CECHandler::onCecAlert(void * context, const CECAlert alert, const CECParameter data)
|
||||
void CECHandler::onCecAlert(void * context, const CECAlert alert, const CECParameter /* data */)
|
||||
{
|
||||
#ifdef VERBOSE_CEC
|
||||
CECHandler * handler = qobject_cast<CECHandler*>(static_cast<QObject*>(context));
|
||||
if (!handler)
|
||||
return;
|
||||
|
||||
Error(handler->_logger, QString("CECHandler::onCecAlert: %1")
|
||||
.arg(alert)
|
||||
.toLocal8Bit());
|
||||
Error(handler->_logger, QSTRING_CSTR(QString("CECHandler::onCecAlert: %1")
|
||||
.arg(alert)));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -263,9 +303,7 @@ void CECHandler::onCecConfigurationChanged(void * context, const CECConfig * con
|
||||
if (!handler)
|
||||
return;
|
||||
|
||||
Debug(handler->_logger, QString("CECHandler::onCecConfigurationChanged: %1")
|
||||
.arg(configuration->strDeviceName)
|
||||
.toLocal8Bit());
|
||||
Debug(handler->_logger, "CECHandler::onCecConfigurationChanged: %s", configuration->strDeviceName);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -278,9 +316,7 @@ int CECHandler::onCecMenuStateChanged(void * context, const CECMenuState state)
|
||||
|
||||
CECAdapter * adapter = handler->_cecAdapter;
|
||||
|
||||
Debug(handler->_logger, QString("CECHandler::onCecMenuStateChanged: %1")
|
||||
.arg(adapter->ToString(state))
|
||||
.toLocal8Bit());
|
||||
Debug(handler->_logger, "CECHandler::onCecMenuStateChanged: %s", adapter->ToString(state));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -294,28 +330,28 @@ void CECHandler::onCecCommandReceived(void * context, const CECCommand * command
|
||||
CECAdapter * adapter = handler->_cecAdapter;
|
||||
|
||||
#ifdef VERBOSE_CEC
|
||||
Debug(handler->_logger, QString("CECHandler::onCecCommandReceived: %1 (%2 > %3)")
|
||||
.arg(adapter->ToString(command->opcode))
|
||||
.arg(adapter->ToString(command->initiator))
|
||||
.arg(adapter->ToString(command->destination))
|
||||
.toLocal8Bit());
|
||||
Debug(handler->_logger, "CECHandler::onCecCommandReceived: %s %s > %s)",
|
||||
adapter->ToString(command->opcode),
|
||||
adapter->ToString(command->initiator),
|
||||
adapter->ToString(command->destination)
|
||||
);
|
||||
#endif
|
||||
/* We do NOT check sender */
|
||||
// if (address == CEC::CECDEVICE_TV)
|
||||
//if (address == CEC::CECDEVICE_TV)
|
||||
{
|
||||
if (command->opcode == CEC::CEC_OPCODE_SET_STREAM_PATH)
|
||||
{
|
||||
Info(handler->_logger, "%s", QSTRING_CSTR(QString("CEC source activated: %1")
|
||||
.arg(adapter->ToString(command->initiator)))
|
||||
);
|
||||
emit handler->cecEvent(CECEvent::On);
|
||||
}
|
||||
if (command->opcode == CEC::CEC_OPCODE_STANDBY)
|
||||
{
|
||||
Info(handler->_logger, "%s", QSTRING_CSTR(QString("CEC source deactivated: %1")
|
||||
.arg(adapter->ToString(command->initiator)))
|
||||
);
|
||||
emit handler->cecEvent(CECEvent::Off);
|
||||
switch (command->opcode) {
|
||||
case CEC::CEC_OPCODE_STANDBY:
|
||||
Info(handler->_logger, "CEC source deactivated: %s", adapter->ToString(command->initiator));
|
||||
emit handler->signalEvent(Event::Suspend);
|
||||
break;
|
||||
|
||||
case CEC::CEC_OPCODE_SET_STREAM_PATH:
|
||||
Info(handler->_logger, "'CEC source activated: %s", adapter->ToString(command->initiator));
|
||||
emit handler->signalEvent(Event::Resume);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,14 +364,15 @@ void CECHandler::onCecSourceActivated(void * context, const CECLogicalAddress ad
|
||||
#ifdef VERBOSE_CEC
|
||||
CECHandler * handler = qobject_cast<CECHandler*>(static_cast<QObject*>(context));
|
||||
if (!handler)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CECAdapter * adapter = handler->_cecAdapter;
|
||||
|
||||
Debug(handler->_logger, QString("CEC source %1 : %2")
|
||||
.arg(activated ? "activated" : "deactivated")
|
||||
.arg(adapter->ToString(address))
|
||||
.toLocal8Bit());
|
||||
Debug(handler->_logger, QSTRING_CSTR(QString("CEC source %1 : %2")
|
||||
.arg(activated ? "activated" : "deactivated",
|
||||
adapter->ToString(address))
|
||||
));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,9 @@ SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/cec)
|
||||
FILE (GLOB CEC_SOURCES "${CURRENT_HEADER_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(cechandler ${CEC_SOURCES})
|
||||
|
||||
message(STATUS "CEC_LIBRARIES = ${CEC_LIBRARIES}")
|
||||
|
||||
list(GET CEC_LIBRARIES 0 CEC_LIBRARIES)
|
||||
add_definitions(-DCEC_LIBRARY="${CEC_LIBRARIES}")
|
||||
|
||||
|
25
libsrc/events/CMakeLists.txt
Normal file
25
libsrc/events/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
# Define the current source/header locations
|
||||
SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/events)
|
||||
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/events)
|
||||
|
||||
add_library(events
|
||||
${CURRENT_HEADER_DIR}/Event.h
|
||||
${CURRENT_HEADER_DIR}/EventHandler.h
|
||||
${CURRENT_SOURCE_DIR}/EventHandler.cpp
|
||||
${CURRENT_HEADER_DIR}/OsEventHandler.h
|
||||
${CURRENT_SOURCE_DIR}/OsEventHandler.cpp
|
||||
)
|
||||
|
||||
if (UNIX)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS DBus QUIET )
|
||||
if (Qt${QT_VERSION_MAJOR}DBus_FOUND)
|
||||
target_link_libraries(events Qt${QT_VERSION_MAJOR}::DBus)
|
||||
if (NOT APPLE)
|
||||
target_compile_definitions(events PUBLIC HYPERION_HAS_DBUS)
|
||||
endif()
|
||||
endif()
|
||||
endif(UNIX)
|
||||
|
||||
target_include_directories(events PUBLIC
|
||||
${CURRENT_HEADER_DIR}
|
||||
)
|
186
libsrc/events/EventHandler.cpp
Normal file
186
libsrc/events/EventHandler.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
#include <events/EventHandler.h>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <events/Event.h>
|
||||
|
||||
#include <utils/Logger.h>
|
||||
#include <utils/Process.h>
|
||||
#include <hyperion/HyperionIManager.h>
|
||||
|
||||
EventHandler::EventHandler()
|
||||
: _isSuspended(false)
|
||||
, _isIdle(false)
|
||||
{
|
||||
qRegisterMetaType<Event>("Event");
|
||||
_log = Logger::getInstance("EVENTS");
|
||||
|
||||
QObject::connect(this, &EventHandler::signalEvent, HyperionIManager::getInstance(), &HyperionIManager::handleEvent);
|
||||
}
|
||||
|
||||
EventHandler::~EventHandler()
|
||||
{
|
||||
QObject::disconnect(this, &EventHandler::signalEvent, HyperionIManager::getInstance(), &HyperionIManager::handleEvent);
|
||||
}
|
||||
|
||||
EventHandler* EventHandler::getInstance()
|
||||
{
|
||||
static EventHandler instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
void EventHandler::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
||||
{
|
||||
if(type == settings::OSEVENTS)
|
||||
{
|
||||
const QJsonObject& obj = config.object();
|
||||
}
|
||||
}
|
||||
|
||||
void EventHandler::suspend()
|
||||
{
|
||||
suspend(true);
|
||||
}
|
||||
|
||||
void EventHandler::suspend(bool sleep)
|
||||
{
|
||||
if (sleep)
|
||||
{
|
||||
if (!_isSuspended)
|
||||
{
|
||||
_isSuspended = true;
|
||||
Info(_log, "Suspend event received - Hyperion is going to sleep");
|
||||
emit signalEvent(Event::Suspend);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_log, "Suspend event ignored - already suspended");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_isSuspended || _isIdle)
|
||||
{
|
||||
Info(_log, "Resume event received - Hyperion is going into working mode");
|
||||
emit signalEvent(Event::Resume);
|
||||
_isSuspended = false;
|
||||
_isIdle = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_log, "Resume event ignored - not in suspend nor idle mode");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EventHandler::resume()
|
||||
{
|
||||
suspend(false);
|
||||
}
|
||||
|
||||
void EventHandler::toggleSuspend()
|
||||
{
|
||||
Debug(_log, "Toggle suspend event received");
|
||||
if (!_isSuspended)
|
||||
{
|
||||
suspend(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
suspend(false);
|
||||
}
|
||||
}
|
||||
|
||||
void EventHandler::idle()
|
||||
{
|
||||
idle(true);
|
||||
}
|
||||
|
||||
void EventHandler::idle(bool isIdle)
|
||||
{
|
||||
if (!_isSuspended)
|
||||
{
|
||||
if (isIdle)
|
||||
{
|
||||
if (!_isIdle)
|
||||
{
|
||||
_isIdle = true;
|
||||
Info(_log, "Idle event received");
|
||||
emit signalEvent(Event::Idle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_isIdle)
|
||||
{
|
||||
Info(_log, "Resume from idle event recevied");
|
||||
emit signalEvent(Event::ResumeIdle);
|
||||
_isIdle = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_log, "Idle event ignored - Hyperion is suspended");
|
||||
}
|
||||
}
|
||||
void EventHandler::resumeIdle()
|
||||
{
|
||||
idle(false);
|
||||
}
|
||||
|
||||
void EventHandler::toggleIdle()
|
||||
{
|
||||
Debug(_log, "Toggle idle event received");
|
||||
if (!_isIdle)
|
||||
{
|
||||
idle(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
idle(false);
|
||||
}
|
||||
}
|
||||
|
||||
void EventHandler::handleEvent(Event event)
|
||||
{
|
||||
Debug(_log,"%s Event [%d] received", eventToString(event), event);
|
||||
switch (event) {
|
||||
case Event::Suspend:
|
||||
suspend();
|
||||
break;
|
||||
|
||||
case Event::Resume:
|
||||
resume();
|
||||
break;
|
||||
|
||||
case Event::ToggleSuspend:
|
||||
suspend();
|
||||
break;
|
||||
|
||||
case Event::Idle:
|
||||
idle(true);
|
||||
break;
|
||||
|
||||
case Event::ResumeIdle:
|
||||
idle(false);
|
||||
break;
|
||||
|
||||
case Event::ToggleIdle:
|
||||
toggleIdle();
|
||||
break;
|
||||
|
||||
case Event::Reload:
|
||||
Process::restartHyperion(10);
|
||||
break;
|
||||
|
||||
case Event::Restart:
|
||||
Process::restartHyperion(11);
|
||||
break;
|
||||
|
||||
default:
|
||||
Error(_log,"Unkonwn Event '%d' received", event);
|
||||
break;
|
||||
}
|
||||
}
|
448
libsrc/events/OsEventHandler.cpp
Normal file
448
libsrc/events/OsEventHandler.cpp
Normal file
@@ -0,0 +1,448 @@
|
||||
#include "OsEventHandler.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <events/EventHandler.h>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <QCoreApplication>
|
||||
#include <QWidget>
|
||||
#include <windows.h>
|
||||
#include <wtsapi32.h>
|
||||
|
||||
#pragma comment( lib, "wtsapi32.lib" )
|
||||
#endif
|
||||
|
||||
OsEventHandlerBase::OsEventHandlerBase()
|
||||
: _isSuspendEnabled(false)
|
||||
, _isLockEnabled(false)
|
||||
, _isSuspendOnLock(false)
|
||||
, _isSuspendRegistered(false)
|
||||
, _isLockRegistered(false)
|
||||
{
|
||||
qRegisterMetaType<Event>("Event");
|
||||
_log = Logger::getInstance("EVENTS");
|
||||
|
||||
QObject::connect(this, &OsEventHandlerBase::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent);
|
||||
}
|
||||
|
||||
OsEventHandlerBase::~OsEventHandlerBase()
|
||||
{
|
||||
QObject::disconnect(this, &OsEventHandlerBase::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent);
|
||||
|
||||
unregisterLockHandler();
|
||||
unregisterOsEventHandler();
|
||||
}
|
||||
|
||||
void OsEventHandlerBase::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
||||
{
|
||||
if(type == settings::OSEVENTS)
|
||||
{
|
||||
const QJsonObject& obj = config.object();
|
||||
|
||||
//Suspend on lock or go into idle mode
|
||||
bool prevIsSuspendOnLock = _isSuspendOnLock;
|
||||
_isSuspendOnLock = obj["suspendOnLockEnable"].toBool(false);
|
||||
|
||||
//Handle OS event related configurations
|
||||
_isSuspendEnabled = obj["suspendEnable"].toBool(true);
|
||||
if (_isSuspendEnabled)
|
||||
{
|
||||
// Listen to suspend/resume/idle events received by the OS
|
||||
registerOsEventHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
unregisterOsEventHandler();
|
||||
}
|
||||
|
||||
_isLockEnabled = obj["lockEnable"].toBool(true);
|
||||
if (_isLockEnabled || _isSuspendOnLock != prevIsSuspendOnLock)
|
||||
{
|
||||
// Listen to lock/screensaver events received by the OS
|
||||
registerLockHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
unregisterLockHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OsEventHandlerBase::suspend(bool sleep)
|
||||
{
|
||||
if (sleep)
|
||||
{
|
||||
emit signalEvent(Event::Suspend);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit signalEvent(Event::Resume);
|
||||
}
|
||||
}
|
||||
|
||||
void OsEventHandlerBase::lock(bool isLocked)
|
||||
{
|
||||
if (isLocked)
|
||||
{
|
||||
if (_isSuspendOnLock)
|
||||
{
|
||||
emit signalEvent(Event::Suspend);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit signalEvent(Event::Idle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_isSuspendOnLock)
|
||||
{
|
||||
emit signalEvent(Event::Resume);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit signalEvent(Event::ResumeIdle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
OsEventHandlerWindows::OsEventHandlerWindows()
|
||||
: _notifyHandle(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
OsEventHandlerWindows::~OsEventHandlerWindows()
|
||||
{
|
||||
unregisterLockHandler();
|
||||
unregisterOsEventHandler();
|
||||
}
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
bool OsEventHandlerWindows::nativeEventFilter(const QByteArray& eventType, void* message, qintptr* /*result*/)
|
||||
#else
|
||||
bool OsEventHandlerWindows::nativeEventFilter(const QByteArray& eventType, void* message, long int* /*result*/)
|
||||
#endif
|
||||
{
|
||||
MSG* msg = static_cast<MSG*>(message);
|
||||
|
||||
switch (msg->message)
|
||||
{
|
||||
case WM_WTSSESSION_CHANGE:
|
||||
switch (msg->wParam)
|
||||
{
|
||||
case WTS_SESSION_LOCK:
|
||||
emit lock(true);
|
||||
return true;
|
||||
break;
|
||||
case WTS_SESSION_UNLOCK:
|
||||
emit lock(false);
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_POWERBROADCAST:
|
||||
switch (msg->wParam)
|
||||
{
|
||||
case PBT_APMRESUMESUSPEND:
|
||||
emit suspend(false);
|
||||
return true;
|
||||
break;
|
||||
case PBT_APMSUSPEND:
|
||||
emit suspend(true);
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OsEventHandlerWindows::registerOsEventHandler()
|
||||
{
|
||||
bool isRegistered{ _isSuspendRegistered };
|
||||
if (!_isSuspendRegistered)
|
||||
{
|
||||
auto handle = reinterpret_cast<HWND> (_widget.winId());
|
||||
_notifyHandle = RegisterSuspendResumeNotification(handle, DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||
if (_notifyHandle != NULL)
|
||||
{
|
||||
QCoreApplication::instance()->installNativeEventFilter(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(_log, "Could not register for suspend/resume events!");
|
||||
}
|
||||
|
||||
if (isRegistered)
|
||||
{
|
||||
_isSuspendRegistered = true;
|
||||
}
|
||||
}
|
||||
return isRegistered;
|
||||
}
|
||||
|
||||
void OsEventHandlerWindows::unregisterOsEventHandler()
|
||||
{
|
||||
if (_isSuspendRegistered)
|
||||
{
|
||||
if (_notifyHandle != NULL)
|
||||
{
|
||||
QCoreApplication::instance()->removeNativeEventFilter(this);
|
||||
UnregisterSuspendResumeNotification(_notifyHandle);
|
||||
}
|
||||
_notifyHandle = NULL;
|
||||
_isSuspendRegistered = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool OsEventHandlerWindows::registerLockHandler()
|
||||
{
|
||||
bool isRegistered{ _isLockRegistered };
|
||||
if (!_isLockRegistered)
|
||||
{
|
||||
auto handle = reinterpret_cast<HWND> (_widget.winId());
|
||||
if (WTSRegisterSessionNotification(handle, NOTIFY_FOR_THIS_SESSION))
|
||||
{
|
||||
isRegistered = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(_log, "Could not register for lock/unlock events!");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (isRegistered)
|
||||
{
|
||||
_isLockRegistered = true;
|
||||
}
|
||||
return isRegistered;
|
||||
}
|
||||
|
||||
void OsEventHandlerWindows::unregisterLockHandler()
|
||||
{
|
||||
if (_isLockRegistered)
|
||||
{
|
||||
auto handle = reinterpret_cast<HWND> (_widget.winId());
|
||||
WTSUnRegisterSessionNotification(handle);
|
||||
_isLockRegistered = false;
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(__linux__)
|
||||
|
||||
#include <csignal>
|
||||
|
||||
OsEventHandlerLinux* OsEventHandlerLinux::getInstance()
|
||||
{
|
||||
static OsEventHandlerLinux instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
OsEventHandlerLinux::OsEventHandlerLinux()
|
||||
{
|
||||
signal(SIGUSR1, static_signaleHandler);
|
||||
signal(SIGUSR2, static_signaleHandler);
|
||||
}
|
||||
|
||||
void OsEventHandlerLinux::handleSignal (int signum)
|
||||
{
|
||||
if (signum == SIGUSR1)
|
||||
{
|
||||
suspend(true);
|
||||
}
|
||||
else if (signum == SIGUSR2)
|
||||
{
|
||||
suspend(false);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HYPERION_HAS_DBUS)
|
||||
#include <QDBusConnection>
|
||||
|
||||
struct dBusSignals
|
||||
{
|
||||
QString service;
|
||||
QString path;
|
||||
QString interface;
|
||||
QString name;
|
||||
};
|
||||
|
||||
typedef QMultiMap<QString, dBusSignals> DbusSignalsMap;
|
||||
|
||||
// Constants
|
||||
namespace {
|
||||
const DbusSignalsMap dbusSignals = {
|
||||
//system signals
|
||||
{"Suspend", {"org.freedesktop.login1","/org/freedesktop/login1","org.freedesktop.login1.Manager","PrepareForSleep"}},
|
||||
|
||||
//Session signals
|
||||
{"ScreenSaver", {"org.freedesktop.ScreenSaver","/org/freedesktop/ScreenSaver","org.freedesktop.ScreenSaver","ActiveChanged"}},
|
||||
{"ScreenSaver", {"org.gnome.ScreenSaver","/org/gnome/ScreenSaver","org.gnome.ScreenSaver","ActiveChanged"}},
|
||||
};
|
||||
} //End of constants
|
||||
|
||||
bool OsEventHandlerLinux::registerOsEventHandler()
|
||||
{
|
||||
|
||||
bool isRegistered {_isSuspendRegistered};
|
||||
if (!_isSuspendRegistered)
|
||||
{
|
||||
QDBusConnection systemBus = QDBusConnection::systemBus();
|
||||
if (!systemBus.isConnected())
|
||||
{
|
||||
Info(_log, "The suspend/resume feature is not supported by your system configuration");
|
||||
}
|
||||
else
|
||||
{
|
||||
QString service = dbusSignals.find("Suspend").value().service;
|
||||
if (systemBus.connect(service,
|
||||
dbusSignals.find("Suspend").value().path,
|
||||
dbusSignals.find("Suspend").value().interface,
|
||||
dbusSignals.find("Suspend").value().name,
|
||||
this, SLOT(suspend(bool))))
|
||||
{
|
||||
Debug(_log, "Registered for suspend/resume events via service: %s", QSTRING_CSTR(service));
|
||||
isRegistered = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(_log, "Could not register for suspend/resume events via service: %s", QSTRING_CSTR(service));
|
||||
}
|
||||
}
|
||||
|
||||
if (isRegistered)
|
||||
{
|
||||
_isSuspendRegistered = true;
|
||||
}
|
||||
|
||||
}
|
||||
return isRegistered;
|
||||
}
|
||||
|
||||
void OsEventHandlerLinux::unregisterOsEventHandler()
|
||||
{
|
||||
if (_isSuspendRegistered)
|
||||
{
|
||||
QDBusConnection systemBus = QDBusConnection::systemBus();
|
||||
if (!systemBus.isConnected())
|
||||
{
|
||||
Info(_log, "The suspend/resume feature is not supported by your system configuration");
|
||||
}
|
||||
else
|
||||
{
|
||||
QString service = dbusSignals.find("Suspend").value().service;
|
||||
if (systemBus.disconnect(service,
|
||||
dbusSignals.find("Suspend").value().path,
|
||||
dbusSignals.find("Suspend").value().interface,
|
||||
dbusSignals.find("Suspend").value().name,
|
||||
this, SLOT(suspend(bool))))
|
||||
{
|
||||
Debug(_log, "Unregistered for suspend/resume events via service: %s", QSTRING_CSTR(service));
|
||||
_isSuspendRegistered = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(_log, "Could not unregister for suspend/resume events via service: %s", QSTRING_CSTR(service));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool OsEventHandlerLinux::registerLockHandler()
|
||||
{
|
||||
bool isRegistered {_isLockRegistered};
|
||||
|
||||
if (!_isLockRegistered)
|
||||
{
|
||||
QDBusConnection sessionBus = QDBusConnection::sessionBus();
|
||||
if (!sessionBus.isConnected())
|
||||
{
|
||||
Info(_log, "The lock/unlock feature is not supported by your system configuration");
|
||||
}
|
||||
else
|
||||
{
|
||||
DbusSignalsMap::const_iterator iter = dbusSignals.find("ScreenSaver");
|
||||
while (iter != dbusSignals.end() && iter.key() == "ScreenSaver") {
|
||||
QString service = iter.value().service;
|
||||
if (sessionBus.connect(service,
|
||||
iter.value().path,
|
||||
iter.value().interface,
|
||||
iter.value().name,
|
||||
this, SLOT(lock(bool))))
|
||||
{
|
||||
Debug(_log, "Registered for lock/unlock events via service: %s", QSTRING_CSTR(service));
|
||||
isRegistered = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(_log, "Could not register for lock/unlock events via service: %s", QSTRING_CSTR(service));
|
||||
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (isRegistered)
|
||||
{
|
||||
_isLockRegistered = true;
|
||||
}
|
||||
|
||||
return isRegistered;
|
||||
}
|
||||
|
||||
void OsEventHandlerLinux::unregisterLockHandler()
|
||||
{
|
||||
bool isUnregistered {false};
|
||||
|
||||
if (_isLockRegistered)
|
||||
{
|
||||
QDBusConnection sessionBus = QDBusConnection::sessionBus();
|
||||
if (!sessionBus.isConnected())
|
||||
{
|
||||
Info(_log, "The lock/unlock feature is not supported by your system configuration");
|
||||
}
|
||||
else
|
||||
{
|
||||
DbusSignalsMap::const_iterator iter = dbusSignals.find("ScreenSaver");
|
||||
while (iter != dbusSignals.end() && iter.key() == "ScreenSaver") {
|
||||
QString service = iter.value().service;
|
||||
if (sessionBus.disconnect(service,
|
||||
iter.value().path,
|
||||
iter.value().interface,
|
||||
iter.value().name,
|
||||
this, SLOT(lock(bool))))
|
||||
{
|
||||
Debug(_log, "Unregistered for lock/unlock events via service: %s", QSTRING_CSTR(service));
|
||||
isUnregistered = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(_log, "Could not unregister for lock/unlock events via service: %s", QSTRING_CSTR(service));
|
||||
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
|
||||
if (isUnregistered)
|
||||
{
|
||||
_isLockRegistered = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // HYPERION_HAS_DBUS
|
||||
|
||||
#endif // __linux__
|
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <grabber/VideoWrapper.h>
|
||||
|
||||
#include <events/EventHandler.h>
|
||||
|
||||
// qt includes
|
||||
#include <QTimer>
|
||||
|
||||
@@ -15,10 +17,15 @@ VideoWrapper::VideoWrapper()
|
||||
{
|
||||
// register the image type
|
||||
qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>");
|
||||
qRegisterMetaType<Event>("Event");
|
||||
|
||||
// Handle the image in the captured thread (Media Foundation/V4L2) using a direct connection
|
||||
connect(&_grabber, SIGNAL(newFrame(const Image<ColorRgb>&)), this, SLOT(newFrame(const Image<ColorRgb>&)), Qt::DirectConnection);
|
||||
connect(&_grabber, SIGNAL(readError(const char*)), this, SLOT(readError(const char*)), Qt::DirectConnection);
|
||||
|
||||
connect(&_grabber, SIGNAL(readError(const char*)), this, SLOT(readError(const char*)), Qt::DirectConnection);
|
||||
|
||||
QObject::connect(EventHandler::getInstance(), &EventHandler::signalEvent, this, &VideoWrapper::handleEvent);
|
||||
}
|
||||
|
||||
VideoWrapper::~VideoWrapper()
|
||||
@@ -37,15 +44,11 @@ void VideoWrapper::stop()
|
||||
GrabberWrapper::stop();
|
||||
}
|
||||
|
||||
#if defined(ENABLE_CEC) && !defined(ENABLE_MF)
|
||||
|
||||
void VideoWrapper::handleCecEvent(CECEvent event)
|
||||
void VideoWrapper::handleEvent(Event event)
|
||||
{
|
||||
_grabber.handleCecEvent(event);
|
||||
_grabber.handleEvent(event);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void VideoWrapper::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
||||
{
|
||||
if(type == settings::V4L2 && _grabberName.startsWith("V4L2"))
|
||||
@@ -100,11 +103,6 @@ void VideoWrapper::handleSettingsUpdate(settings::type type, const QJsonDocument
|
||||
obj["hardware_saturation"].toInt(0),
|
||||
obj["hardware_hue"].toInt(0));
|
||||
|
||||
#if defined(ENABLE_CEC) && defined(ENABLE_V4L2)
|
||||
// CEC Standby
|
||||
_grabber.setCecDetectionEnable(obj["cecDetection"].toBool(true));
|
||||
#endif
|
||||
|
||||
// Software frame skipping
|
||||
_grabber.setFpsSoftwareDecimation(obj["fpsSoftwareDecimation"].toInt(1));
|
||||
|
||||
|
@@ -79,8 +79,7 @@ V4L2Grabber::V4L2Grabber()
|
||||
, _currentFrame(0)
|
||||
, _noSignalCounterThreshold(40)
|
||||
, _noSignalThresholdColor(ColorRgb{0,0,0})
|
||||
, _cecDetectionEnabled(true)
|
||||
, _cecStandbyActivated(false)
|
||||
, _standbyActivated(false)
|
||||
, _signalDetectionEnabled(true)
|
||||
, _noSignalDetected(false)
|
||||
, _noSignalCounter(0)
|
||||
@@ -1035,7 +1034,7 @@ bool V4L2Grabber::process_image(const void *p, int size)
|
||||
|
||||
void V4L2Grabber::newThreadFrame(Image<ColorRgb> image)
|
||||
{
|
||||
if (_cecDetectionEnabled && _cecStandbyActivated)
|
||||
if (_standbyActivated)
|
||||
return;
|
||||
|
||||
if (_signalDetectionEnabled)
|
||||
@@ -1203,16 +1202,6 @@ void V4L2Grabber::setSignalDetectionEnable(bool enable)
|
||||
}
|
||||
}
|
||||
|
||||
void V4L2Grabber::setCecDetectionEnable(bool enable)
|
||||
{
|
||||
if (_cecDetectionEnabled != enable)
|
||||
{
|
||||
_cecDetectionEnabled = enable;
|
||||
if(_initialized)
|
||||
Info(_log, "%s", QSTRING_CSTR(QString("CEC detection is now %1").arg(enable ? "enabled" : "disabled")));
|
||||
}
|
||||
}
|
||||
|
||||
bool V4L2Grabber::reload(bool force)
|
||||
{
|
||||
if (_reload || force)
|
||||
@@ -1231,26 +1220,24 @@ bool V4L2Grabber::reload(bool force)
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(ENABLE_CEC)
|
||||
|
||||
void V4L2Grabber::handleCecEvent(CECEvent event)
|
||||
void V4L2Grabber::handleEvent(Event event)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case CECEvent::On :
|
||||
Debug(_log,"CEC on event received");
|
||||
_cecStandbyActivated = false;
|
||||
return;
|
||||
case CECEvent::Off :
|
||||
Debug(_log,"CEC off event received");
|
||||
_cecStandbyActivated = true;
|
||||
return;
|
||||
default: break;
|
||||
case Event::Suspend:
|
||||
case Event::Idle:
|
||||
Debug(_log,"Suspend/Idle event received");
|
||||
_standbyActivated = true;
|
||||
return;
|
||||
case Event::Resume:
|
||||
case Event::ResumeIdle:
|
||||
Debug(_log,"Resume event received");
|
||||
_standbyActivated = false;
|
||||
return;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
QJsonArray V4L2Grabber::discover(const QJsonObject& params)
|
||||
{
|
||||
DebugIf(verbose, _log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||
|
@@ -63,23 +63,28 @@ void HyperionIManager::stopAll()
|
||||
}
|
||||
}
|
||||
|
||||
void HyperionIManager::suspend()
|
||||
void HyperionIManager::handleEvent(Event event)
|
||||
{
|
||||
Info(_log,"Suspend all instances and enabled components");
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
{
|
||||
emit instance->suspendRequest(true);
|
||||
}
|
||||
}
|
||||
Debug(_log,"%s Event [%d] received", eventToString(event), event);
|
||||
switch (event) {
|
||||
case Event::Suspend:
|
||||
toggleSuspend(true);
|
||||
break;
|
||||
|
||||
void HyperionIManager::resume()
|
||||
{
|
||||
Info(_log,"Resume all instances and enabled components");
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
{
|
||||
emit instance->suspendRequest(false);
|
||||
case Event::Resume:
|
||||
toggleSuspend(false);
|
||||
break;
|
||||
|
||||
case Event::Idle:
|
||||
toggleIdle(true);
|
||||
break;
|
||||
|
||||
case Event::ResumeIdle:
|
||||
toggleIdle(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -91,10 +91,14 @@
|
||||
{
|
||||
"$ref": "schema-leds.json"
|
||||
},
|
||||
"systemEvents":
|
||||
"osEvents":
|
||||
{
|
||||
"$ref": "schema-systemEvents.json"
|
||||
}
|
||||
"$ref": "schema-osEvents.json"
|
||||
},
|
||||
"cecEvents":
|
||||
{
|
||||
"$ref": "schema-cecEvents.json"
|
||||
}
|
||||
},
|
||||
"additionalProperties" : false
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@
|
||||
<file alias="schema-leds.json">schema/schema-leds.json</file>
|
||||
<file alias="schema-instCapture.json">schema/schema-instCapture.json</file>
|
||||
<file alias="schema-network.json">schema/schema-network.json</file>
|
||||
<file alias="schema-systemEvents.json">schema/schema-systemEvents.json</file>
|
||||
<file alias="schema-osEvents.json">schema/schema-osEvents.json</file>
|
||||
<file alias="schema-cecEvents.json">schema/schema-cecEvents.json</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
17
libsrc/hyperion/schema/schema-cecEvents.json
Normal file
17
libsrc/hyperion/schema/schema-cecEvents.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"required" : true,
|
||||
"title" : "edt_conf_cec_events_heading_title",
|
||||
"properties" :
|
||||
{
|
||||
"enable" :
|
||||
{
|
||||
"type" : "boolean",
|
||||
"required" : true,
|
||||
"title" : "edt_conf_general_enable_title",
|
||||
"default" : false,
|
||||
"propertyOrder" : 1
|
||||
}
|
||||
},
|
||||
"additionalProperties" : false
|
||||
}
|
@@ -1,26 +1,26 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"required" : true,
|
||||
"title" : "edt_conf_system_events_heading_title",
|
||||
"title" : "edt_conf_os_events_heading_title",
|
||||
"properties": {
|
||||
"suspendEnable": {
|
||||
"type": "boolean",
|
||||
"required": true,
|
||||
"title": "edt_conf_system_events_suspendEnable_title",
|
||||
"title": "edt_conf_os_events_suspendEnable_title",
|
||||
"default": true,
|
||||
"propertyOrder": 1
|
||||
},
|
||||
"lockEnable": {
|
||||
"type": "boolean",
|
||||
"required": true,
|
||||
"title": "edt_conf_system_events_lockEnable_title",
|
||||
"title": "edt_conf_os_events_lockEnable_title",
|
||||
"default": true,
|
||||
"propertyOrder": 2
|
||||
},
|
||||
"suspendOnLockEnable": {
|
||||
"type": "boolean",
|
||||
"required": false,
|
||||
"title": "edt_conf_system_events_suspendOnLockEnable_title",
|
||||
"title": "edt_conf_os_events_suspendOnLockEnable_title",
|
||||
"default": false,
|
||||
"options": {
|
||||
"dependencies": {
|
@@ -36,6 +36,8 @@ void JsonClientConnection::readRequest()
|
||||
// remove message data from buffer
|
||||
_receiveBuffer = _receiveBuffer.mid(bytes);
|
||||
|
||||
std::cout << "JsonClientConnection::readRequest | [" << _socket->peerAddress().toString().toStdString() << "] Received: [" << message.toStdString() << "]" << std::endl;
|
||||
|
||||
// handle message
|
||||
_jsonAPI->handleMessage(message);
|
||||
|
||||
@@ -49,6 +51,8 @@ qint64 JsonClientConnection::sendMessage(QJsonObject message)
|
||||
QJsonDocument writer(message);
|
||||
QByteArray data = writer.toJson(QJsonDocument::Compact) + "\n";
|
||||
|
||||
std::cout << "JsonClientConnection::sendMessage | [" << _socket->peerAddress().toString().toStdString() << "] Send: [" << data.constData() << "]" << std::endl;
|
||||
|
||||
if (!_socket || (_socket->state() != QAbstractSocket::ConnectedState)) return 0;
|
||||
return _socket->write(data.data(), data.size());
|
||||
}
|
||||
|
Reference in New Issue
Block a user