diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dc566efb..430d272fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ Note: The wizard will configure an APIv2 capable bridge always with Entertainmen - Changed default build from Stretch to Buster - Support Qt 6.7, Update to Protobuf 25.1, Update mbedTLS to v3.4.0, Update flatbuffers to v23.5.26 - Use C++17 standard as default +- Started using SmartPointers (#981) - Added Pull Request (PR) installation script, allowing users to test development builds savely on Linux - Fixed missing include limits in QJsonSchemaChecker - Thanks @Portisch - Fixed dependencies for deb packages in Debian Bookworm (#1579) - Thanks @hg42, @Psirus diff --git a/include/events/EventHandler.h b/include/events/EventHandler.h index 49b8c8aba..4eaf8e964 100644 --- a/include/events/EventHandler.h +++ b/include/events/EventHandler.h @@ -13,10 +13,9 @@ class EventHandler : public QObject Q_OBJECT public: - EventHandler(); ~EventHandler() override; - static EventHandler* getInstance(); + static QScopedPointer& getInstance(); public slots: @@ -40,6 +39,12 @@ public slots: Logger * _log {}; private: + EventHandler(); + EventHandler(const EventHandler&) = delete; + EventHandler& operator=(const EventHandler&) = delete; + + static QScopedPointer instance; + bool _isSuspended; bool _isIdle; }; diff --git a/include/grabber/amlogic/AmlogicWrapper.h b/include/grabber/amlogic/AmlogicWrapper.h index d97c45c10..3f763f5c1 100644 --- a/include/grabber/amlogic/AmlogicWrapper.h +++ b/include/grabber/amlogic/AmlogicWrapper.h @@ -12,6 +12,9 @@ class AmlogicWrapper : public GrabberWrapper { Q_OBJECT public: + + static constexpr const char* GRABBERTYPE = "Amlogic"; + /// /// Constructs the Amlogic frame grabber /// @@ -22,6 +25,12 @@ class AmlogicWrapper : public GrabberWrapper AmlogicWrapper(int pixelDecimation=GrabberWrapper::DEFAULT_PIXELDECIMATION, int updateRate_Hz=GrabberWrapper::DEFAULT_RATE_HZ); + /// + /// Constructs the Amlogic frame grabber from configuration settings + /// + AmlogicWrapper(const QJsonDocument& grabberConfig = QJsonDocument()); + + public slots: /// /// Performs a single frame grab and computes the led-colors diff --git a/include/grabber/directx/DirectXWrapper.h b/include/grabber/directx/DirectXWrapper.h index 56ec68798..c9e483230 100644 --- a/include/grabber/directx/DirectXWrapper.h +++ b/include/grabber/directx/DirectXWrapper.h @@ -6,6 +6,8 @@ class DirectXWrapper: public GrabberWrapper { public: + static constexpr const char* GRABBERTYPE = "DirectX"; + /// /// Constructs the DirectX grabber with a specified grab size and update rate. /// @@ -25,6 +27,11 @@ class DirectXWrapper: public GrabberWrapper int cropTop=0, int cropBottom=0 ); + /// + /// Constructs the QT frame grabber from configuration settings + /// + DirectXWrapper(const QJsonDocument& grabberConfig = QJsonDocument()); + /// /// Destructor of this DirectX grabber. Releases any claimed resources. /// diff --git a/include/grabber/dispmanx/DispmanxFrameGrabber.h b/include/grabber/dispmanx/DispmanxFrameGrabber.h index 9d617ba93..b61607bc8 100644 --- a/include/grabber/dispmanx/DispmanxFrameGrabber.h +++ b/include/grabber/dispmanx/DispmanxFrameGrabber.h @@ -36,9 +36,9 @@ class DispmanxFrameGrabber : public Grabber /// /// @brief Determine if the bcm library is available. /// - /// @return Zero, on success (i.e. library is present), else negative + /// @return true, on success (i.e. library is present), else false /// - bool isAvailable(); + bool isAvailable() override; /// /// @brief Opens the input device. diff --git a/include/grabber/dispmanx/DispmanxWrapper.h b/include/grabber/dispmanx/DispmanxWrapper.h index 499316fc4..ec41c9da9 100644 --- a/include/grabber/dispmanx/DispmanxWrapper.h +++ b/include/grabber/dispmanx/DispmanxWrapper.h @@ -13,6 +13,9 @@ class DispmanxWrapper: public GrabberWrapper { Q_OBJECT public: + + static constexpr const char* GRABBERTYPE = "DispmanX"; + /// /// Constructs the dispmanx frame grabber with a specified grab size and update rate. /// @@ -23,9 +26,12 @@ class DispmanxWrapper: public GrabberWrapper int pixelDecimation=GrabberWrapper::DEFAULT_PIXELDECIMATION ); - bool screenInit(); + /// + /// Constructs the QT frame grabber from configuration settings + /// + DispmanxWrapper(const QJsonDocument& grabberConfig = QJsonDocument()); - bool available = false; + bool screenInit(); /// /// Starts the grabber which produces led values with the specified update rate diff --git a/include/grabber/framebuffer/FramebufferFrameGrabber.h b/include/grabber/framebuffer/FramebufferFrameGrabber.h index 947ef0eab..e622f0b91 100644 --- a/include/grabber/framebuffer/FramebufferFrameGrabber.h +++ b/include/grabber/framebuffer/FramebufferFrameGrabber.h @@ -17,7 +17,7 @@ class FramebufferFrameGrabber : public Grabber /// /// @param[in] device The framebuffer device name/path /// - FramebufferFrameGrabber(const QString & device="/dev/fb0"); + FramebufferFrameGrabber(int deviceIdx = 0); ~FramebufferFrameGrabber() override; @@ -45,7 +45,7 @@ class FramebufferFrameGrabber : public Grabber ///@brief Set new width and height for framegrabber, overwrite Grabber.h implementation bool setWidthHeight(int width, int height) override; - QString getPath() const {return _fbDevice;} + QString getPath() const {return QString("/dev/fb%1").arg(_input);} /// /// @brief Discover Framebuffer screens available (for configuration). @@ -62,7 +62,7 @@ class FramebufferFrameGrabber : public Grabber bool closeDevice(); bool getScreenInfo(); - /// Framebuffer device e.g. /dev/fb0 + // /// Framebuffer device e.g. /dev/fb0 QString _fbDevice; int _fbfd; diff --git a/include/grabber/framebuffer/FramebufferWrapper.h b/include/grabber/framebuffer/FramebufferWrapper.h index 084eb96cb..942e4f5f9 100644 --- a/include/grabber/framebuffer/FramebufferWrapper.h +++ b/include/grabber/framebuffer/FramebufferWrapper.h @@ -12,18 +12,26 @@ class FramebufferWrapper: public GrabberWrapper { Q_OBJECT public: + + static constexpr const char* GRABBERTYPE = "FB"; + /// /// Constructs the framebuffer frame grabber with a specified grab size and update rate. /// /// @param[in] updateRate_Hz The image grab rate [Hz] - /// @param[in] device Framebuffer device name/path + /// @param[in] deviceIdx Framebuffer device index /// @param[in] pixelDecimation Decimation factor for image [pixels] /// FramebufferWrapper( int updateRate_Hz=GrabberWrapper::DEFAULT_RATE_HZ, - const QString & device = "/dev/fb0", + int deviceIdx = 0, int pixelDecimation=GrabberWrapper::DEFAULT_PIXELDECIMATION ); + /// + /// Constructs the QT frame grabber from configuration settings + /// + FramebufferWrapper(const QJsonDocument& grabberConfig = QJsonDocument()); + public slots: /// /// Performs a single frame grab and computes the led-colors diff --git a/include/grabber/osx/OsxWrapper.h b/include/grabber/osx/OsxWrapper.h index fd367184b..c119e811e 100644 --- a/include/grabber/osx/OsxWrapper.h +++ b/include/grabber/osx/OsxWrapper.h @@ -11,6 +11,8 @@ class OsxWrapper: public GrabberWrapper { Q_OBJECT public: + + static constexpr const char* GRABBERTYPE = "OSX"; /// /// Constructs the osx frame grabber with a specified grab size and update rate. /// @@ -23,6 +25,12 @@ class OsxWrapper: public GrabberWrapper int pixelDecimation=GrabberWrapper::DEFAULT_PIXELDECIMATION ); + /// + /// Constructs the QT frame grabber from configuration settings + /// + OsxWrapper(const QJsonDocument& grabberConfig = QJsonDocument()); + + public slots: /// /// Performs a single frame grab and computes the led-colors diff --git a/include/grabber/qt/QtWrapper.h b/include/grabber/qt/QtWrapper.h index 3df2a64e6..e830e1874 100644 --- a/include/grabber/qt/QtWrapper.h +++ b/include/grabber/qt/QtWrapper.h @@ -1,5 +1,8 @@ #pragma once +#include +#include + #include #include @@ -8,7 +11,10 @@ /// class QtWrapper: public GrabberWrapper { + public: + static constexpr const char* GRABBERTYPE = "Qt"; + /// /// Constructs the QT frame grabber with a specified grab size and update rate. /// @@ -19,7 +25,6 @@ class QtWrapper: public GrabberWrapper /// @param[in] cropRight Remove from right [pixels] /// @param[in] cropTop Remove from top [pixels] /// @param[in] cropBottom Remove from bottom [pixels] - /// QtWrapper( int updateRate_Hz=GrabberWrapper::DEFAULT_RATE_HZ, int display=0, @@ -28,6 +33,11 @@ class QtWrapper: public GrabberWrapper int cropTop=0, int cropBottom=0 ); + /// + /// Constructs the QT frame grabber from configuration settings + /// + QtWrapper(const QJsonDocument& grabberConfig = QJsonDocument()); + /// /// Starts the grabber which produces led values with the specified update rate /// diff --git a/include/grabber/x11/X11Wrapper.h b/include/grabber/x11/X11Wrapper.h index dae62ad70..ea1020cf3 100644 --- a/include/grabber/x11/X11Wrapper.h +++ b/include/grabber/x11/X11Wrapper.h @@ -7,7 +7,6 @@ #undef None #endif - /// /// The X11Wrapper uses an instance of the X11Grabber to obtain ImageRgb's from the displayed content. /// This ImageRgb is processed to a ColorRgb for each led and committed to the attached Hyperion. @@ -15,6 +14,8 @@ class X11Wrapper: public GrabberWrapper { public: + static constexpr const char* GRABBERTYPE = "X11"; + /// /// Constructs the X11 frame grabber with a specified grab size and update rate. /// @@ -27,6 +28,11 @@ class X11Wrapper: public GrabberWrapper int cropTop=0, int cropBottom=0 ); + /// + /// Constructs the X11 frame grabber from configuration settings + /// + X11Wrapper(const QJsonDocument& grabberConfig = QJsonDocument()); + /// /// Destructor of this frame grabber. Releases any claimed resources. /// diff --git a/include/grabber/xcb/XcbWrapper.h b/include/grabber/xcb/XcbWrapper.h index 0292937c1..f77e2a3de 100644 --- a/include/grabber/xcb/XcbWrapper.h +++ b/include/grabber/xcb/XcbWrapper.h @@ -11,12 +11,30 @@ class XcbWrapper: public GrabberWrapper { public: + + static constexpr const char* GRABBERTYPE = "XCB"; + + /// + /// Constructs the XCB frame grabber with a specified grab size and update rate. + /// + /// @param[in] updateRate_Hz The image grab rate [Hz] + /// @param[in] pixelDecimation Decimation factor for image [pixels] + /// @param[in] cropLeft Remove from left [pixels] + /// @param[in] cropRight Remove from right [pixels] + /// @param[in] cropTop Remove from top [pixels] + /// @param[in] cropBottom Remove from bottom [pixels] + /// XcbWrapper( int updateRate_Hz=GrabberWrapper::DEFAULT_RATE_HZ, int pixelDecimation=GrabberWrapper::DEFAULT_PIXELDECIMATION, int cropLeft=0, int cropRight=0, int cropTop=0, int cropBottom=0 ); + /// + /// Constructs the XCB frame grabber from configuration settings + /// + XcbWrapper(const QJsonDocument& grabberConfig = QJsonDocument()); + ~XcbWrapper() override; public slots: diff --git a/include/hyperion/Grabber.h b/include/hyperion/Grabber.h index 3408e3b8b..e73c4387e 100644 --- a/include/hyperion/Grabber.h +++ b/include/hyperion/Grabber.h @@ -113,6 +113,13 @@ class Grabber : public QObject QString getGrabberName() const { return _grabberName; } + /// + /// @brief Determine if the grabber is available. + /// + /// @return true, on success (i.e. library is present), else false + /// + virtual bool isAvailable() { return _isAvailable; } + public slots: virtual void handleEvent(Event event) {} @@ -168,10 +175,15 @@ protected slots: // Device states + /// Is the device available? + bool _isAvailable; + /// Is the device enabled? bool _isEnabled; /// Is the device in error state and stopped? bool _isDeviceInError; + + }; diff --git a/include/hyperion/GrabberWrapper.h b/include/hyperion/GrabberWrapper.h index e517b0131..51e7f792d 100644 --- a/include/hyperion/GrabberWrapper.h +++ b/include/hyperion/GrabberWrapper.h @@ -32,6 +32,14 @@ class GrabberWrapper : public QObject { Q_OBJECT public: + + static constexpr const char* GRABBERTYPE = "Base"; + + template + static QSharedPointer create(const QJsonDocument& config) { + return QSharedPointer::create(config); + } + GrabberWrapper(const QString& grabberName, Grabber * ggrabber,int updateRate_Hz = DEFAULT_RATE_HZ); ~GrabberWrapper() override; @@ -71,6 +79,11 @@ class GrabberWrapper : public QObject /// virtual bool isActive() const; + virtual bool isAvailable() { return _isAvailable; } + + + QString getName() { return _grabberName; } + /// /// @brief Get active grabber name /// @param hyperionInd The instance index @@ -195,4 +208,6 @@ private slots: /// The image used for grabbing frames Image _image; + + bool _isAvailable; }; diff --git a/include/mdns/MdnsBrowser.h b/include/mdns/MdnsBrowser.h index a5071b13a..46a0b9c3f 100644 --- a/include/mdns/MdnsBrowser.h +++ b/include/mdns/MdnsBrowser.h @@ -17,6 +17,7 @@ #include #include #include +#include #include // Utility includes @@ -39,21 +40,17 @@ class MdnsBrowser : public QObject /// // Run MdnsBrowser as singleton MdnsBrowser(QObject* parent = nullptr); - ~MdnsBrowser() override; - -public: - - static MdnsBrowser& getInstance() - { - static MdnsBrowser* instance = new MdnsBrowser(); - return *instance; - } - MdnsBrowser(const MdnsBrowser&) = delete; MdnsBrowser(MdnsBrowser&&) = delete; MdnsBrowser& operator=(const MdnsBrowser&) = delete; MdnsBrowser& operator=(MdnsBrowser&&) = delete; + static QScopedPointer instance; + +public: + ~MdnsBrowser() override; + static QScopedPointer& getInstance(); + QMdnsEngine::Service getFirstService(const QByteArray& serviceType, const QString& filter = ".*", const std::chrono::milliseconds waitTime = DEFAULT_DISCOVER_TIMEOUT) const; QJsonArray getServicesDiscoveredJson(const QByteArray& serviceType, const QString& filter = ".*", const std::chrono::milliseconds waitTime = std::chrono::milliseconds{ 0 }) const; diff --git a/include/utils/Logger.h b/include/utils/Logger.h index 0f71700ea..016b63525 100644 --- a/include/utils/Logger.h +++ b/include/utils/Logger.h @@ -7,6 +7,7 @@ #include #include #include +#include #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) #include @@ -106,8 +107,19 @@ class LoggerManager : public QObject { Q_OBJECT +private: + // Run LoggerManager as singleton + LoggerManager(); + LoggerManager(const LoggerManager&) = delete; + LoggerManager(LoggerManager&&) = delete; + LoggerManager& operator=(const LoggerManager&) = delete; + LoggerManager& operator=(LoggerManager&&) = delete; + + static QScopedPointer instance; + public: - static LoggerManager* getInstance(); + ~LoggerManager() override; + static QScopedPointer& getInstance(); public slots: void handleNewLogMessage(const Logger::T_LOG_MESSAGE&); @@ -117,7 +129,6 @@ public slots: void newLogMessage(const Logger::T_LOG_MESSAGE&); private: - LoggerManager(); QList _logMessageBuffer; const int _loggerMaxMsgBufferSize; diff --git a/include/utils/NetUtils.h b/include/utils/NetUtils.h index 9020539b9..a0f085bdd 100644 --- a/include/utils/NetUtils.h +++ b/include/utils/NetUtils.h @@ -111,7 +111,7 @@ namespace NetUtils { if (hostname.endsWith(".local") || hostname.endsWith(".local.")) { QHostAddress resolvedAddress; - QMetaObject::invokeMethod(&MdnsBrowser::getInstance(), "resolveAddress", + QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "resolveAddress", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, isHostAddressOK), Q_ARG(Logger*, log), Q_ARG(QString, hostname), Q_ARG(QHostAddress&, resolvedAddress)); @@ -163,7 +163,7 @@ namespace NetUtils { if (hostname.endsWith("._tcp.local")) { //Treat hostname as service instance name that requires to be resolved into an mDNS-Hostname first - QMdnsEngine::Record service = MdnsBrowser::getInstance().getServiceInstanceRecord(hostname.toUtf8()); + QMdnsEngine::Record service = MdnsBrowser::getInstance().data()->getServiceInstanceRecord(hostname.toUtf8()); if (!service.target().isEmpty()) { Info(log, "Resolved service [%s] to mDNS hostname [%s], service port [%d]", QSTRING_CSTR(hostname), service.target().constData(), service.port()); diff --git a/include/webserver/WebServer.h b/include/webserver/WebServer.h index 088b79b3d..e2cfef491 100644 --- a/include/webserver/WebServer.h +++ b/include/webserver/WebServer.h @@ -4,6 +4,7 @@ #include #include #include +#include // hyperion / utils #include @@ -64,7 +65,7 @@ public slots: void onServerStopped (); void onServerStarted (quint16 port); - void onServerError (QString msg); + void onServerError (const QString& msg); /// /// @brief Handle settings update from Hyperion Settingsmanager emit or this constructor @@ -90,7 +91,7 @@ public slots: QString _baseUrl; quint16 _port; StaticFileServing* _staticFileServing; - QtHttpServer* _server; + QScopedPointer _server; bool _inited = false; }; diff --git a/libsrc/api/JsonAPI.cpp b/libsrc/api/JsonAPI.cpp index e7ba96a6c..6becc6f76 100644 --- a/libsrc/api/JsonAPI.cpp +++ b/libsrc/api/JsonAPI.cpp @@ -142,7 +142,7 @@ void JsonAPI::initialize() } //notify eventhadler on suspend/resume/idle requests - connect(this, &JsonAPI::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent); + connect(this, &JsonAPI::signalEvent, EventHandler::getInstance().data(), &EventHandler::handleEvent); connect(_ledStreamTimer, &QTimer::timeout, this, &JsonAPI::streamLedColorsUpdate, Qt::UniqueConnection); } @@ -1077,7 +1077,7 @@ void JsonAPI::handleConfigRestoreCommand(const QJsonObject &message, const QStri } } -void JsonAPI::handleSchemaGetCommand(const QJsonObject &message, const QString &command, int tan) +void JsonAPI::handleSchemaGetCommand(const QJsonObject& /*message*/, const QString &command, int tan) { // create result QJsonObject schemaJson, alldevices, properties; @@ -1226,7 +1226,7 @@ void JsonAPI::handleLoggingCommand(const QJsonObject &message, const QString &co if (!_streaming_logging_activated) { _streaming_logging_reply["command"] = command + "-update"; - connect(LoggerManager::getInstance(), &LoggerManager::newLogMessage, this, &JsonAPI::incommingLogMessage); + connect(LoggerManager::getInstance().data(), &LoggerManager::newLogMessage, this, &JsonAPI::incommingLogMessage); emit incommingLogMessage (Logger::T_LOG_MESSAGE{}); // needed to trigger log sending Debug(_log, "log streaming activated for client %s", _peerAddress.toStdString().c_str()); @@ -1236,7 +1236,7 @@ void JsonAPI::handleLoggingCommand(const QJsonObject &message, const QString &co { if (_streaming_logging_activated) { - disconnect(LoggerManager::getInstance(), &LoggerManager::newLogMessage, this, &JsonAPI::incommingLogMessage); + disconnect(LoggerManager::getInstance().data(), &LoggerManager::newLogMessage, this, &JsonAPI::incommingLogMessage); _streaming_logging_activated = false; Debug(_log, "log streaming deactivated for client %s", _peerAddress.toStdString().c_str()); } @@ -1700,59 +1700,54 @@ void JsonAPI::handleInputSourceCommand(const QJsonObject& message, const QString QJsonObject device; #ifdef ENABLE_QT - QtGrabber* qtgrabber = new QtGrabber(); + QScopedPointer qtgrabber(new QtGrabber()); device = qtgrabber->discover(params); if (!device.isEmpty() ) { videoInputs.append(device); } - delete qtgrabber; #endif #ifdef ENABLE_DX - DirectXGrabber* dxgrabber = new DirectXGrabber(); + QScopedPointer dxgrabber (new DirectXGrabber()); device = dxgrabber->discover(params); if (!device.isEmpty() ) { videoInputs.append(device); } - delete dxgrabber; #endif #ifdef ENABLE_X11 - X11Grabber* x11Grabber = new X11Grabber(); + QScopedPointer x11Grabber(new X11Grabber()); device = x11Grabber->discover(params); if (!device.isEmpty() ) { videoInputs.append(device); } - delete x11Grabber; #endif #ifdef ENABLE_XCB - XcbGrabber* xcbGrabber = new XcbGrabber(); + QScopedPointer xcbGrabber (new XcbGrabber()); device = xcbGrabber->discover(params); if (!device.isEmpty() ) { videoInputs.append(device); } - delete xcbGrabber; #endif //Ignore FB for Amlogic, as it is embedded in the Amlogic grabber itself #if defined(ENABLE_FB) && !defined(ENABLE_AMLOGIC) - FramebufferFrameGrabber* fbGrabber = new FramebufferFrameGrabber(); + QScopedPointer fbGrabber(new FramebufferFrameGrabber()); device = fbGrabber->discover(params); if (!device.isEmpty() ) { videoInputs.append(device); } - delete fbGrabber; #endif #if defined(ENABLE_DISPMANX) - DispmanxFrameGrabber* dispmanx = new DispmanxFrameGrabber(); + QScopedPointer dispmanx(new DispmanxFrameGrabber()); if (dispmanx->isAvailable()) { device = dispmanx->discover(params); @@ -1761,27 +1756,24 @@ void JsonAPI::handleInputSourceCommand(const QJsonObject& message, const QString videoInputs.append(device); } } - delete dispmanx; #endif #if defined(ENABLE_AMLOGIC) - AmlogicGrabber* amlGrabber = new AmlogicGrabber(); + QScopedPointer amlGrabber(new AmlogicGrabber()); device = amlGrabber->discover(params); if (!device.isEmpty() ) { videoInputs.append(device); } - delete amlGrabber; #endif #if defined(ENABLE_OSX) - OsxFrameGrabber* osxGrabber = new OsxFrameGrabber(); + QScopedPointer osxGrabber(new OsxFrameGrabber()); device = osxGrabber->discover(params); if (!device.isEmpty() ) { videoInputs.append(device); } - delete osxGrabber; #endif } @@ -1826,10 +1818,10 @@ void JsonAPI::handleServiceCommand(const QJsonObject &message, const QString &co if (!serviceType.isEmpty()) { #ifdef ENABLE_MDNS - QMetaObject::invokeMethod(&MdnsBrowser::getInstance(), "browseForServiceType", + QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "browseForServiceType", Qt::QueuedConnection, Q_ARG(QByteArray, serviceType)); - serviceList = MdnsBrowser::getInstance().getServicesDiscoveredJson(serviceType, MdnsServiceRegister::getServiceNameFilter(type), DEFAULT_DISCOVER_TIMEOUT); + serviceList = MdnsBrowser::getInstance().data()->getServicesDiscoveredJson(serviceType, MdnsServiceRegister::getServiceNameFilter(type), DEFAULT_DISCOVER_TIMEOUT); #endif servicesOfType.insert(type, serviceList); @@ -1983,7 +1975,7 @@ void JsonAPI::incommingLogMessage(const Logger::T_LOG_MESSAGE &msg) if (!_streaming_logging_activated) { _streaming_logging_activated = true; - QMetaObject::invokeMethod(LoggerManager::getInstance(), "getLogMessageBuffer", + QMetaObject::invokeMethod(LoggerManager::getInstance().data(), "getLogMessageBuffer", Qt::DirectConnection, Q_RETURN_ARG(QJsonArray, messageArray), Q_ARG(Logger::LogLevel, _log->getLogLevel())); @@ -2033,7 +2025,7 @@ void JsonAPI::handleTokenResponse(bool success, const QString &token, const QStr sendErrorReply("Token request timeout or denied", cmd, tan); } -void JsonAPI::handleInstanceStateChange(InstanceState state, quint8 instance, const QString &name) +void JsonAPI::handleInstanceStateChange(InstanceState state, quint8 instance, const QString& /*name */) { switch (state) { diff --git a/libsrc/cec/CECHandler.cpp b/libsrc/cec/CECHandler.cpp index 438dd087d..cfbcc3959 100644 --- a/libsrc/cec/CECHandler.cpp +++ b/libsrc/cec/CECHandler.cpp @@ -38,6 +38,7 @@ CECHandler::CECHandler(const QJsonDocument& config, QObject * parent) CECHandler::~CECHandler() { + Info(_logger, "CEC handler stopped"); } void CECHandler::handleSettingsUpdate(settings::type type, const QJsonDocument& config) @@ -165,7 +166,7 @@ bool CECHandler::enable() else { _isOpen=true; - QObject::connect(this, &CECHandler::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent); + QObject::connect(this, &CECHandler::signalEvent, EventHandler::getInstance().data(), &EventHandler::handleEvent); #ifdef VERBOSE_CEC std::cout << "Found Devices: " << scan().toStdString() << std::endl; #endif @@ -188,7 +189,7 @@ void CECHandler::disable() { if (_isInitialised) { - QObject::disconnect(this, &CECHandler::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent); + QObject::disconnect(this, &CECHandler::signalEvent, EventHandler::getInstance().data(), &EventHandler::handleEvent); _cecAdapter->Close(); _isOpen=false; Info(_logger, "CEC handler disabled"); diff --git a/libsrc/events/EventHandler.cpp b/libsrc/events/EventHandler.cpp index 266ec26b8..a76ed462f 100644 --- a/libsrc/events/EventHandler.cpp +++ b/libsrc/events/EventHandler.cpp @@ -7,6 +7,8 @@ #include #include +QScopedPointer EventHandler::instance; + EventHandler::EventHandler() : _isSuspended(false) , _isIdle(false) @@ -15,6 +17,7 @@ EventHandler::EventHandler() _log = Logger::getInstance("EVENTS"); QObject::connect(this, &EventHandler::signalEvent, HyperionIManager::getInstance(), &HyperionIManager::handleEvent); + Debug(_log, "Hyperion event handler created"); } EventHandler::~EventHandler() @@ -22,10 +25,14 @@ EventHandler::~EventHandler() QObject::disconnect(this, &EventHandler::signalEvent, HyperionIManager::getInstance(), &HyperionIManager::handleEvent); } -EventHandler* EventHandler::getInstance() +QScopedPointer& EventHandler::getInstance() { - static EventHandler instance; - return &instance; + if (!instance) + { + instance.reset(new EventHandler()); + } + + return instance; } void EventHandler::suspend() diff --git a/libsrc/events/EventScheduler.cpp b/libsrc/events/EventScheduler.cpp index 9177151af..2a748f684 100644 --- a/libsrc/events/EventScheduler.cpp +++ b/libsrc/events/EventScheduler.cpp @@ -15,14 +15,16 @@ EventScheduler::EventScheduler() qRegisterMetaType("Event"); _log = Logger::getInstance("EVENTS-SCHED"); - QObject::connect(this, &EventScheduler::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent); + QObject::connect(this, &EventScheduler::signalEvent, EventHandler::getInstance().data(), &EventHandler::handleEvent); + + Debug(_log, "Hyperion event scheduler created"); } EventScheduler::~EventScheduler() { - QObject::disconnect(this, &EventScheduler::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent); + QObject::disconnect(this, &EventScheduler::signalEvent, EventHandler::getInstance().data(), &EventHandler::handleEvent); clearTimers(); - Info(_log, "Event scheduler stopped"); + Info(_log, "Hyperion event scheduler stopped"); } void EventScheduler::handleSettingsUpdate(settings::type type, const QJsonDocument& config) diff --git a/libsrc/events/OsEventHandler.cpp b/libsrc/events/OsEventHandler.cpp index 501e213dc..24026532b 100644 --- a/libsrc/events/OsEventHandler.cpp +++ b/libsrc/events/OsEventHandler.cpp @@ -39,12 +39,14 @@ OsEventHandlerBase::OsEventHandlerBase() { _isService = true; } - QObject::connect(this, &OsEventHandlerBase::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent); + QObject::connect(this, &OsEventHandlerBase::signalEvent, EventHandler::getInstance().data(), &EventHandler::handleEvent); + + Debug(_log, "Operating System event handler created"); } OsEventHandlerBase::~OsEventHandlerBase() { - QObject::disconnect(this, &OsEventHandlerBase::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent); + QObject::disconnect(this, &OsEventHandlerBase::signalEvent, EventHandler::getInstance().data(), &EventHandler::handleEvent); OsEventHandlerBase::unregisterLockHandler(); OsEventHandlerBase::unregisterOsEventHandler(); diff --git a/libsrc/flatbufserver/FlatBufferServer.cpp b/libsrc/flatbufserver/FlatBufferServer.cpp index 8c48a58b2..33e015a6e 100644 --- a/libsrc/flatbufserver/FlatBufferServer.cpp +++ b/libsrc/flatbufserver/FlatBufferServer.cpp @@ -125,6 +125,6 @@ void FlatBufferServer::stopServer() client->forceClose(); } _server->close(); - Info(_log, "Stopped"); + Info(_log, "FlatBuffer-Server stopped"); } } diff --git a/libsrc/forwarder/MessageForwarder.cpp b/libsrc/forwarder/MessageForwarder.cpp index 3720ad544..88322b294 100644 --- a/libsrc/forwarder/MessageForwarder.cpp +++ b/libsrc/forwarder/MessageForwarder.cpp @@ -48,7 +48,7 @@ MessageForwarder::MessageForwarder(Hyperion* hyperion) qRegisterMetaType("TargetHost"); #ifdef ENABLE_MDNS - QMetaObject::invokeMethod(&MdnsBrowser::getInstance(), "browseForServiceType", + QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "browseForServiceType", Qt::QueuedConnection, Q_ARG(QByteArray, MdnsServiceRegister::getServiceType("jsonapi"))); #endif @@ -257,7 +257,7 @@ int MessageForwarder::startJsonTargets(const QJsonObject& config) #ifdef ENABLE_MDNS if (!addr.isEmpty()) { - QMetaObject::invokeMethod(&MdnsBrowser::getInstance(), "browseForServiceType", + QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "browseForServiceType", Qt::QueuedConnection, Q_ARG(QByteArray, MdnsServiceRegister::getServiceType("jsonapi"))); } #endif @@ -362,7 +362,7 @@ int MessageForwarder::startFlatbufferTargets(const QJsonObject& config) #ifdef ENABLE_MDNS if (!addr.isEmpty()) { - QMetaObject::invokeMethod(&MdnsBrowser::getInstance(), "browseForServiceType", + QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "browseForServiceType", Qt::QueuedConnection, Q_ARG(QByteArray, MdnsServiceRegister::getServiceType("flatbuffer"))); } #endif diff --git a/libsrc/grabber/amlogic/AmlogicGrabber.cpp b/libsrc/grabber/amlogic/AmlogicGrabber.cpp index 0f6b05875..299cafd0a 100644 --- a/libsrc/grabber/amlogic/AmlogicGrabber.cpp +++ b/libsrc/grabber/amlogic/AmlogicGrabber.cpp @@ -27,7 +27,7 @@ namespace { const bool verbose = false; -const char DEFAULT_FB_DEVICE[] = "/dev/fb0"; +const int DEFAULT_FB_DEVICE_IDX = 0; const char DEFAULT_VIDEO_DEVICE[] = "/dev/amvideo"; const char DEFAULT_CAPTURE_DEVICE[] = "/dev/amvideocap0"; const int AMVIDEOCAP_WAIT_MAX_MS = 40; @@ -36,11 +36,11 @@ const int AMVIDEOCAP_DEFAULT_RATE_HZ = 25; } //End of constants AmlogicGrabber::AmlogicGrabber() - : Grabber("AMLOGICGRABBER") // Minimum required width or height is 160 + : Grabber("GRABBER-AMLOGIC") // Minimum required width or height is 160 , _captureDev(-1) , _videoDev(-1) , _lastError(0) - , _fbGrabber(DEFAULT_FB_DEVICE) + , _fbGrabber(DEFAULT_FB_DEVICE_IDX) , _grabbingModeNotification(0) { _image_ptr = _image_bgr.memptr(); @@ -57,7 +57,7 @@ bool AmlogicGrabber::setupScreen() { bool rc (false); - QSize screenSize = _fbGrabber.getScreenSize(DEFAULT_FB_DEVICE); + QSize screenSize = _fbGrabber.getScreenSize(); if ( !screenSize.isEmpty() ) { if (setWidthHeight(screenSize.width(), screenSize.height())) diff --git a/libsrc/grabber/amlogic/AmlogicWrapper.cpp b/libsrc/grabber/amlogic/AmlogicWrapper.cpp index ac371ba04..d568e999e 100644 --- a/libsrc/grabber/amlogic/AmlogicWrapper.cpp +++ b/libsrc/grabber/amlogic/AmlogicWrapper.cpp @@ -1,12 +1,18 @@ #include AmlogicWrapper::AmlogicWrapper(int pixelDecimation, int updateRate_Hz) - : GrabberWrapper("Amlogic", &_grabber, updateRate_Hz) + : GrabberWrapper(GRABBERTYPE, &_grabber, updateRate_Hz) , _grabber() { _grabber.setPixelDecimation(pixelDecimation); } +AmlogicWrapper::AmlogicWrapper(const QJsonDocument& grabberConfig) + : GrabberWrapper(GRABBERTYPE, &_grabber) +{ + this->handleSettingsUpdate(settings::SYSTEMCAPTURE, grabberConfig); +} + void AmlogicWrapper::action() { transferFrame(_grabber); diff --git a/libsrc/grabber/directx/DirectXGrabber.cpp b/libsrc/grabber/directx/DirectXGrabber.cpp index 24db4b4fc..a70acdb6a 100644 --- a/libsrc/grabber/directx/DirectXGrabber.cpp +++ b/libsrc/grabber/directx/DirectXGrabber.cpp @@ -10,7 +10,7 @@ namespace { } //End of constants DirectXGrabber::DirectXGrabber(int display, int cropLeft, int cropRight, int cropTop, int cropBottom) - : Grabber("DXGRABBER", cropLeft, cropRight, cropTop, cropBottom) + : Grabber("GRABBER-DIRECTX", cropLeft, cropRight, cropTop, cropBottom) , _display(unsigned(display)) , _displayWidth(0) , _displayHeight(0) diff --git a/libsrc/grabber/directx/DirectXWrapper.cpp b/libsrc/grabber/directx/DirectXWrapper.cpp index cddf19cef..c0ba4eccd 100644 --- a/libsrc/grabber/directx/DirectXWrapper.cpp +++ b/libsrc/grabber/directx/DirectXWrapper.cpp @@ -5,13 +5,19 @@ DirectXWrapper::DirectXWrapper( int updateRate_Hz, int pixelDecimation, int cropLeft, int cropRight, int cropTop, int cropBottom ) - : GrabberWrapper("DirectX", &_grabber, updateRate_Hz) + : GrabberWrapper(GRABBERTYPE, &_grabber, updateRate_Hz) , _grabber(display, cropLeft, cropRight, cropTop, cropBottom) { _grabber.setPixelDecimation(pixelDecimation); } +DirectXWrapper::DirectXWrapper(const QJsonDocument& grabberConfig) + : GrabberWrapper(GRABBERTYPE, &_grabber) +{ + this->handleSettingsUpdate(settings::SYSTEMCAPTURE, grabberConfig); +} + void DirectXWrapper::action() { transferFrame(_grabber); diff --git a/libsrc/grabber/dispmanx/DispmanxFrameGrabber.cpp b/libsrc/grabber/dispmanx/DispmanxFrameGrabber.cpp index d0486cdfa..34e0dcac3 100644 --- a/libsrc/grabber/dispmanx/DispmanxFrameGrabber.cpp +++ b/libsrc/grabber/dispmanx/DispmanxFrameGrabber.cpp @@ -19,7 +19,7 @@ namespace { #include "grabber/dispmanx/DispmanxFrameGrabber.h" DispmanxFrameGrabber::DispmanxFrameGrabber() - : Grabber("DISPMANXGRABBER") + : Grabber("GRABBER-DISPMANX") , _lib(nullptr) , _vc_display(0) , _vc_resource(0) diff --git a/libsrc/grabber/dispmanx/DispmanxWrapper.cpp b/libsrc/grabber/dispmanx/DispmanxWrapper.cpp index 19fb1b028..328247621 100644 --- a/libsrc/grabber/dispmanx/DispmanxWrapper.cpp +++ b/libsrc/grabber/dispmanx/DispmanxWrapper.cpp @@ -3,15 +3,20 @@ DispmanxWrapper::DispmanxWrapper( int updateRate_Hz, int pixelDecimation ) - : GrabberWrapper("Dispmanx", &_grabber, updateRate_Hz) - , _grabber() + : GrabberWrapper(GRABBERTYPE, &_grabber, updateRate_Hz) { - if (available = _grabber.isAvailable()) + if (_isAvailable) { _grabber.setPixelDecimation(pixelDecimation); } } +DispmanxWrapper::DispmanxWrapper(const QJsonDocument& grabberConfig) + : GrabberWrapper(GRABBERTYPE, &_grabber) +{ + this->handleSettingsUpdate(settings::SYSTEMCAPTURE, grabberConfig); +} + bool DispmanxWrapper::open() { return _grabber.open(); diff --git a/libsrc/grabber/framebuffer/FramebufferFrameGrabber.cpp b/libsrc/grabber/framebuffer/FramebufferFrameGrabber.cpp index c4129341f..1d197226f 100644 --- a/libsrc/grabber/framebuffer/FramebufferFrameGrabber.cpp +++ b/libsrc/grabber/framebuffer/FramebufferFrameGrabber.cpp @@ -30,11 +30,11 @@ const char DISCOVERY_FILEPATTERN[] = "fb?"; // Local includes #include -FramebufferFrameGrabber::FramebufferFrameGrabber(const QString & device) - : Grabber("FRAMEBUFFERGRABBER") - , _fbDevice(device) - , _fbfd (-1) +FramebufferFrameGrabber::FramebufferFrameGrabber(int deviceIdx) + : Grabber("GRABBER-FB") + , _fbfd (-1) { + _input = deviceIdx; _useImageResampler = true; } @@ -105,6 +105,7 @@ bool FramebufferFrameGrabber::openDevice() { bool rc = true; + _fbDevice = getPath(); /* Open the framebuffer device */ _fbfd = ::open(QSTRING_CSTR(_fbDevice), O_RDONLY); if (_fbfd < 0) @@ -136,8 +137,7 @@ QSize FramebufferFrameGrabber::getScreenSize() const QSize FramebufferFrameGrabber::getScreenSize(const QString& device) const { - int width (0); - int height(0); + QSize size; int fbfd = ::open(QSTRING_CSTR(device), O_RDONLY); if (fbfd != -1) @@ -146,13 +146,13 @@ QSize FramebufferFrameGrabber::getScreenSize(const QString& device) const int result = ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo); if (result == 0) { - width = static_cast(vinfo.xres); - height = static_cast(vinfo.yres); - DebugIf(verbose, _log, "FB device [%s] found with resolution: %dx%d", QSTRING_CSTR(device), width, height); + size.setWidth(static_cast(vinfo.xres)); + size.setHeight(static_cast(vinfo.yres)); + DebugIf(verbose, _log, "FB device [%s] found with resolution: %dx%d", QSTRING_CSTR(device), size.width(), size.height()); } ::close(fbfd); } - return QSize(width, height); + return size; } bool FramebufferFrameGrabber::getScreenInfo() diff --git a/libsrc/grabber/framebuffer/FramebufferWrapper.cpp b/libsrc/grabber/framebuffer/FramebufferWrapper.cpp index 9cb400462..2588afede 100644 --- a/libsrc/grabber/framebuffer/FramebufferWrapper.cpp +++ b/libsrc/grabber/framebuffer/FramebufferWrapper.cpp @@ -1,14 +1,20 @@ #include FramebufferWrapper::FramebufferWrapper( int updateRate_Hz, - const QString & device, + int deviceIdx, int pixelDecimation) - : GrabberWrapper("FrameBuffer", &_grabber, updateRate_Hz) - , _grabber(device) + : GrabberWrapper(GRABBERTYPE, &_grabber, updateRate_Hz) + , _grabber(deviceIdx) { _grabber.setPixelDecimation(pixelDecimation); } +FramebufferWrapper::FramebufferWrapper(const QJsonDocument& grabberConfig) + : GrabberWrapper(GRABBERTYPE, &_grabber) +{ + this->handleSettingsUpdate(settings::SYSTEMCAPTURE, grabberConfig); +} + void FramebufferWrapper::action() { transferFrame(_grabber); diff --git a/libsrc/grabber/osx/OsxFrameGrabber.cpp b/libsrc/grabber/osx/OsxFrameGrabber.cpp index c31b76062..916402c29 100644 --- a/libsrc/grabber/osx/OsxFrameGrabber.cpp +++ b/libsrc/grabber/osx/OsxFrameGrabber.cpp @@ -16,7 +16,7 @@ const bool verbose = false; } //End of constants OsxFrameGrabber::OsxFrameGrabber(int display) - : Grabber("OSXGRABBER") + : Grabber("GRABBER-OSX") , _screenIndex(display) { _isEnabled = false; diff --git a/libsrc/grabber/osx/OsxWrapper.cpp b/libsrc/grabber/osx/OsxWrapper.cpp index 408f7a69c..86058d4f1 100644 --- a/libsrc/grabber/osx/OsxWrapper.cpp +++ b/libsrc/grabber/osx/OsxWrapper.cpp @@ -4,12 +4,18 @@ OsxWrapper::OsxWrapper( int updateRate_Hz, int display, int pixelDecimation ) - : GrabberWrapper("OSX", &_grabber, updateRate_Hz) + : GrabberWrapper(GRABBERTYPE, &_grabber, updateRate_Hz) , _grabber(display) { _grabber.setPixelDecimation(pixelDecimation); } +OsxWrapper::OsxWrapper(const QJsonDocument& grabberConfig) + : GrabberWrapper(GRABBERTYPE, &_grabber) +{ + this->handleSettingsUpdate(settings::SYSTEMCAPTURE, grabberConfig); +} + void OsxWrapper::action() { transferFrame(_grabber); diff --git a/libsrc/grabber/qt/QtGrabber.cpp b/libsrc/grabber/qt/QtGrabber.cpp index f826f506e..ce040a74e 100644 --- a/libsrc/grabber/qt/QtGrabber.cpp +++ b/libsrc/grabber/qt/QtGrabber.cpp @@ -20,8 +20,9 @@ const bool verbose = false; } //End of constants QtGrabber::QtGrabber(int display, int cropLeft, int cropRight, int cropTop, int cropBottom) - : Grabber("QTGRABBER", cropLeft, cropRight, cropTop, cropBottom) + : Grabber("GRABBER-QT", cropLeft, cropRight, cropTop, cropBottom) , _display(display) + , _numberOfSDisplays(0) , _screenWidth(0) , _screenHeight(0) , _src_x(0) @@ -32,7 +33,6 @@ QtGrabber::QtGrabber(int display, int cropLeft, int cropRight, int cropTop, int , _screen(nullptr) , _isVirtual(false) { - _logger = Logger::getInstance("Qt"); _useImageResampler = false; } diff --git a/libsrc/grabber/qt/QtWrapper.cpp b/libsrc/grabber/qt/QtWrapper.cpp index 689f25c55..d4560676b 100644 --- a/libsrc/grabber/qt/QtWrapper.cpp +++ b/libsrc/grabber/qt/QtWrapper.cpp @@ -5,12 +5,18 @@ QtWrapper::QtWrapper( int updateRate_Hz, int pixelDecimation, int cropLeft, int cropRight, int cropTop, int cropBottom ) - : GrabberWrapper("Qt", &_grabber, updateRate_Hz) + : GrabberWrapper(GRABBERTYPE, &_grabber, updateRate_Hz) , _grabber(display, cropLeft, cropRight, cropTop, cropBottom) { _grabber.setPixelDecimation(pixelDecimation); } +QtWrapper::QtWrapper(const QJsonDocument& grabberConfig) + : GrabberWrapper(GRABBERTYPE, &_grabber) +{ + this->handleSettingsUpdate(settings::SYSTEMCAPTURE, grabberConfig); +} + bool QtWrapper::open() { return _grabber.open(); diff --git a/libsrc/grabber/x11/X11Grabber.cpp b/libsrc/grabber/x11/X11Grabber.cpp index b9418b836..b40cc7c73 100644 --- a/libsrc/grabber/x11/X11Grabber.cpp +++ b/libsrc/grabber/x11/X11Grabber.cpp @@ -10,7 +10,7 @@ namespace { } //End of constants X11Grabber::X11Grabber(int cropLeft, int cropRight, int cropTop, int cropBottom) - : Grabber("X11GRABBER", cropLeft, cropRight, cropTop, cropBottom) + : Grabber("GRABBER-X11", cropLeft, cropRight, cropTop, cropBottom) , _x11Display(nullptr) , _xImage(nullptr) , _pixmap(None) @@ -28,8 +28,6 @@ X11Grabber::X11Grabber(int cropLeft, int cropRight, int cropTop, int cropBottom) , _isWayland (false) , _logger{} { - _logger = Logger::getInstance("X11"); - _useImageResampler = false; _imageResampler.setCropping(0, 0, 0, 0); // cropping is performed by XRender, XShmGetImage or XGetImage memset(&_pictAttr, 0, sizeof(_pictAttr)); diff --git a/libsrc/grabber/x11/X11Wrapper.cpp b/libsrc/grabber/x11/X11Wrapper.cpp index a7e36b714..d8df3ceea 100644 --- a/libsrc/grabber/x11/X11Wrapper.cpp +++ b/libsrc/grabber/x11/X11Wrapper.cpp @@ -3,13 +3,19 @@ X11Wrapper::X11Wrapper( int updateRate_Hz, int pixelDecimation, int cropLeft, int cropRight, int cropTop, int cropBottom) - : GrabberWrapper("X11", &_grabber, updateRate_Hz) + : GrabberWrapper(GRABBERTYPE, &_grabber, updateRate_Hz) , _grabber(cropLeft, cropRight, cropTop, cropBottom) , _init(false) { _grabber.setPixelDecimation(pixelDecimation); } +X11Wrapper::X11Wrapper(const QJsonDocument& grabberConfig) + : GrabberWrapper(GRABBERTYPE, &_grabber) +{ + this->handleSettingsUpdate(settings::SYSTEMCAPTURE, grabberConfig); +} + X11Wrapper::~X11Wrapper() { if ( _init ) diff --git a/libsrc/grabber/xcb/XcbGrabber.cpp b/libsrc/grabber/xcb/XcbGrabber.cpp index bf58770d9..57f88b12e 100644 --- a/libsrc/grabber/xcb/XcbGrabber.cpp +++ b/libsrc/grabber/xcb/XcbGrabber.cpp @@ -18,7 +18,7 @@ namespace { #define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536)) XcbGrabber::XcbGrabber(int cropLeft, int cropRight, int cropTop, int cropBottom) - : Grabber("XCBGRABBER", cropLeft, cropRight, cropTop, cropBottom) + : Grabber("GRABBER-XCB", cropLeft, cropRight, cropTop, cropBottom) , _connection{} , _screen{} , _pixmap{} @@ -41,8 +41,6 @@ XcbGrabber::XcbGrabber(int cropLeft, int cropRight, int cropTop, int cropBottom) , _shmData{} , _XcbRandREventBase{-1} { - _logger = Logger::getInstance("XCB"); - // cropping is performed by XcbRender, XcbShmGetImage or XcbGetImage _useImageResampler = false; _imageResampler.setCropping(0, 0, 0, 0); diff --git a/libsrc/grabber/xcb/XcbWrapper.cpp b/libsrc/grabber/xcb/XcbWrapper.cpp index 129217e16..aa3db0003 100644 --- a/libsrc/grabber/xcb/XcbWrapper.cpp +++ b/libsrc/grabber/xcb/XcbWrapper.cpp @@ -3,13 +3,19 @@ XcbWrapper::XcbWrapper( int updateRate_Hz, int pixelDecimation, int cropLeft, int cropRight, int cropTop, int cropBottom) - : GrabberWrapper("Xcb", &_grabber, updateRate_Hz) + : GrabberWrapper(GRABBERTYPE, &_grabber, updateRate_Hz) , _grabber(cropLeft, cropRight, cropTop, cropBottom) , _init(false) { _grabber.setPixelDecimation(pixelDecimation); } +XcbWrapper::XcbWrapper(const QJsonDocument& grabberConfig) + : GrabberWrapper(GRABBERTYPE, &_grabber) +{ + this->handleSettingsUpdate(settings::SYSTEMCAPTURE, grabberConfig); +} + XcbWrapper::~XcbWrapper() { if ( _init ) diff --git a/libsrc/hyperion/Grabber.cpp b/libsrc/hyperion/Grabber.cpp index aefdb1425..4637962eb 100644 --- a/libsrc/hyperion/Grabber.cpp +++ b/libsrc/hyperion/Grabber.cpp @@ -18,6 +18,7 @@ Grabber::Grabber(const QString& grabberName, int cropLeft, int cropRight, int cr , _cropRight(0) , _cropTop(0) , _cropBottom(0) + , _isAvailable(true) , _isEnabled(true) , _isDeviceInError(false) { diff --git a/libsrc/hyperion/GrabberWrapper.cpp b/libsrc/hyperion/GrabberWrapper.cpp index 42a3c69cc..d7cc4a8f1 100644 --- a/libsrc/hyperion/GrabberWrapper.cpp +++ b/libsrc/hyperion/GrabberWrapper.cpp @@ -26,10 +26,11 @@ bool GrabberWrapper::GLOBAL_GRABBER_AUDIO_ENABLE = false; GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber * ggrabber, int updateRate_Hz) : _grabberName(grabberName) - , _log(Logger::getInstance(grabberName.toUpper())) + , _log(Logger::getInstance(("Grabber-" + grabberName).toUpper())) , _timer(nullptr) , _updateInterval_ms(1000/updateRate_Hz) , _ggrabber(ggrabber) + , _isAvailable(true) { GrabberWrapper::instance = this; @@ -58,7 +59,7 @@ GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber * ggrabber, i // listen for source requests connect(GlobalSignals::getInstance(), &GlobalSignals::requestSource, this, &GrabberWrapper::handleSourceRequest); - QObject::connect(EventHandler::getInstance(), &EventHandler::signalEvent, this, &GrabberWrapper::handleEvent); + QObject::connect(EventHandler::getInstance().data(), &EventHandler::signalEvent, this, &GrabberWrapper::handleEvent); } GrabberWrapper::~GrabberWrapper() @@ -75,7 +76,7 @@ bool GrabberWrapper::start() if (!_timer->isActive()) { // Start the timer with the pre configured interval - Debug(_log,"Grabber start()"); + Info(_log,"%s grabber started", QSTRING_CSTR(getName())); _timer->start(); } @@ -89,7 +90,7 @@ void GrabberWrapper::stop() if (_timer->isActive()) { // Stop the timer, effectively stopping the process - Debug(_log,"Grabber stop()"); + Info(_log,"%s grabber stopped", QSTRING_CSTR(getName())); _timer->stop(); } } diff --git a/libsrc/hyperion/HyperionIManager.cpp b/libsrc/hyperion/HyperionIManager.cpp index c5a9d9e65..b49d3ddfb 100644 --- a/libsrc/hyperion/HyperionIManager.cpp +++ b/libsrc/hyperion/HyperionIManager.cpp @@ -247,7 +247,7 @@ void HyperionIManager::handleFinished() Hyperion* hyperion = qobject_cast(sender()); quint8 instance = hyperion->getInstanceIndex(); - Info(_log,"Hyperion instance '%s' has been stopped", QSTRING_CSTR(_instanceTable->getNamebyIndex(instance))); + Info(_log,"Hyperion instance '%s' stopped", QSTRING_CSTR(_instanceTable->getNamebyIndex(instance))); _runningInstances.remove(instance); hyperion->thread()->deleteLater(); diff --git a/libsrc/jsonserver/JsonServer.cpp b/libsrc/jsonserver/JsonServer.cpp index 229372086..64d08ff66 100644 --- a/libsrc/jsonserver/JsonServer.cpp +++ b/libsrc/jsonserver/JsonServer.cpp @@ -29,11 +29,12 @@ JsonServer::JsonServer(const QJsonDocument& config) , _netOrigin(NetOrigin::getInstance()) , _config(config) { - Debug(_log, "Created instance"); + Debug(_log, "JSON API server created"); } JsonServer::~JsonServer() { + stop(); qDeleteAll(_openConnections); _openConnections.clear(); } @@ -66,10 +67,12 @@ void JsonServer::start() void JsonServer::stop() { if(!_server->isListening()) + { return; + } _server->close(); - Info(_log, "Stopped"); + Info(_log, "JSON-Server stopped"); } void JsonServer::handleSettingsUpdate(settings::type type, const QJsonDocument& config) diff --git a/libsrc/leddevice/LedDevice.cpp b/libsrc/leddevice/LedDevice.cpp index 92ceb1e66..5772ce27f 100644 --- a/libsrc/leddevice/LedDevice.cpp +++ b/libsrc/leddevice/LedDevice.cpp @@ -100,7 +100,7 @@ void LedDevice::stop() this->stopEnableAttemptsTimer(); this->disable(); this->stopRefreshTimer(); - Info(_log, " Stopped LedDevice '%s'", QSTRING_CSTR(_activeDeviceType)); + Info(_log, "Stopped LedDevice '%s'", QSTRING_CSTR(_activeDeviceType)); } int LedDevice::open() diff --git a/libsrc/leddevice/dev_net/LedDeviceCololight.cpp b/libsrc/leddevice/dev_net/LedDeviceCololight.cpp index 8fa454817..1ac5cee6e 100644 --- a/libsrc/leddevice/dev_net/LedDeviceCololight.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceCololight.cpp @@ -53,7 +53,7 @@ LedDeviceCololight::LedDeviceCololight(const QJsonObject& deviceConfig) , _sequenceNumber(1) { #ifdef ENABLE_MDNS - QMetaObject::invokeMethod(&MdnsBrowser::getInstance(), "browseForServiceType", + QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "browseForServiceType", Qt::QueuedConnection, Q_ARG(QByteArray, MdnsServiceRegister::getServiceType(_activeDeviceType))); #endif @@ -679,7 +679,7 @@ QJsonObject LedDeviceCololight::discover(const QJsonObject& /*params*/) #ifdef ENABLE_MDNS QString discoveryMethod("mDNS"); - deviceList = MdnsBrowser::getInstance().getServicesDiscoveredJson( + deviceList = MdnsBrowser::getInstance().data()->getServicesDiscoveredJson( MdnsServiceRegister::getServiceType(_activeDeviceType), MdnsServiceRegister::getServiceNameFilter(_activeDeviceType), DEFAULT_DISCOVER_TIMEOUT diff --git a/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp b/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp index f32521764..e2b8b3fbc 100644 --- a/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp @@ -111,7 +111,7 @@ LedDeviceNanoleaf::LedDeviceNanoleaf(const QJsonObject& deviceConfig) , _panelLedCount(0) { #ifdef ENABLE_MDNS - QMetaObject::invokeMethod(&MdnsBrowser::getInstance(), "browseForServiceType", + QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "browseForServiceType", Qt::QueuedConnection, Q_ARG(QByteArray, MdnsServiceRegister::getServiceType(_activeDeviceType))); #endif } @@ -461,7 +461,7 @@ QJsonObject LedDeviceNanoleaf::discover(const QJsonObject& /*params*/) #ifdef ENABLE_MDNS QString discoveryMethod("mDNS"); - deviceList = MdnsBrowser::getInstance().getServicesDiscoveredJson( + deviceList = MdnsBrowser::getInstance().data()->getServicesDiscoveredJson( MdnsServiceRegister::getServiceType(_activeDeviceType), MdnsServiceRegister::getServiceNameFilter(_activeDeviceType), DEFAULT_DISCOVER_TIMEOUT diff --git a/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp b/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp index ab6d0a174..f5f8d24b9 100644 --- a/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp +++ b/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp @@ -349,7 +349,7 @@ LedDevicePhilipsHueBridge::LedDevicePhilipsHueBridge(const QJsonObject &deviceCo , _isHueEntertainmentReady(false) { #ifdef ENABLE_MDNS - QMetaObject::invokeMethod(&MdnsBrowser::getInstance(), "browseForServiceType", + QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "browseForServiceType", Qt::QueuedConnection, Q_ARG(QByteArray, MdnsServiceRegister::getServiceType(_activeDeviceType))); #endif } @@ -1294,7 +1294,7 @@ QJsonObject LedDevicePhilipsHueBridge::discover(const QJsonObject& /*params*/) #ifdef ENABLE_MDNS QString discoveryMethod("mDNS"); - deviceList = MdnsBrowser::getInstance().getServicesDiscoveredJson( + deviceList = MdnsBrowser::getInstance().data()->getServicesDiscoveredJson( MdnsServiceRegister::getServiceType(_activeDeviceType), MdnsServiceRegister::getServiceNameFilter(_activeDeviceType), DEFAULT_DISCOVER_TIMEOUT diff --git a/libsrc/leddevice/dev_net/LedDeviceWled.cpp b/libsrc/leddevice/dev_net/LedDeviceWled.cpp index e23a8c9bc..9de8a5fa2 100644 --- a/libsrc/leddevice/dev_net/LedDeviceWled.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceWled.cpp @@ -99,7 +99,7 @@ LedDeviceWled::LedDeviceWled(const QJsonObject &deviceConfig) ,_isStreamToSegment(false) { #ifdef ENABLE_MDNS - QMetaObject::invokeMethod(&MdnsBrowser::getInstance(), "browseForServiceType", + QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "browseForServiceType", Qt::QueuedConnection, Q_ARG(QByteArray, MdnsServiceRegister::getServiceType(_activeDeviceType))); #endif } @@ -547,7 +547,7 @@ QJsonObject LedDeviceWled::discover(const QJsonObject& /*params*/) #ifdef ENABLE_MDNS QString discoveryMethod("mDNS"); - deviceList = MdnsBrowser::getInstance().getServicesDiscoveredJson( + deviceList = MdnsBrowser::getInstance().data()->getServicesDiscoveredJson( MdnsServiceRegister::getServiceType(_activeDeviceType), MdnsServiceRegister::getServiceNameFilter(_activeDeviceType), DEFAULT_DISCOVER_TIMEOUT diff --git a/libsrc/leddevice/dev_net/LedDeviceYeelight.cpp b/libsrc/leddevice/dev_net/LedDeviceYeelight.cpp index 8c0490ce5..327a7182a 100644 --- a/libsrc/leddevice/dev_net/LedDeviceYeelight.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceYeelight.cpp @@ -1006,7 +1006,7 @@ LedDeviceYeelight::LedDeviceYeelight(const QJsonObject &deviceConfig) ,_musicModeServerPort(-1) { #ifdef ENABLE_MDNS - QMetaObject::invokeMethod(&MdnsBrowser::getInstance(), "browseForServiceType", + QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "browseForServiceType", Qt::QueuedConnection, Q_ARG(QByteArray, MdnsServiceRegister::getServiceType(_activeDeviceType))); #endif } @@ -1391,7 +1391,7 @@ QJsonObject LedDeviceYeelight::discover(const QJsonObject& /*params*/) #ifdef ENABLE_MDNS QString discoveryMethod("mDNS"); - deviceList = MdnsBrowser::getInstance().getServicesDiscoveredJson( + deviceList = MdnsBrowser::getInstance().data()->getServicesDiscoveredJson( MdnsServiceRegister::getServiceType(_activeDeviceType), MdnsServiceRegister::getServiceNameFilter(_activeDeviceType), DEFAULT_DISCOVER_TIMEOUT diff --git a/libsrc/mdns/MdnsBrowser.cpp b/libsrc/mdns/MdnsBrowser.cpp index dd45b226b..b0faa39e7 100644 --- a/libsrc/mdns/MdnsBrowser.cpp +++ b/libsrc/mdns/MdnsBrowser.cpp @@ -21,6 +21,8 @@ namespace { const int SERVICE_LOOKUP_RETRIES = 5; } // End of constants +QScopedPointer MdnsBrowser::instance; + MdnsBrowser::MdnsBrowser(QObject* parent) : QObject(parent) , _log(Logger::getInstance("MDNS")) @@ -33,6 +35,16 @@ MdnsBrowser::~MdnsBrowser() _browsedServiceTypes.clear(); } +QScopedPointer& MdnsBrowser::getInstance() +{ + if (!instance) + { + instance.reset(new MdnsBrowser()); + } + + return instance; +} + void MdnsBrowser::browseForServiceType(const QByteArray& serviceType) { if (!_browsedServiceTypes.contains(serviceType)) @@ -163,8 +175,8 @@ bool MdnsBrowser::resolveAddress(Logger* log, const QString& hostname, QHostAddr QEventLoop loop; QTimer timer; - QObject::connect(&MdnsBrowser::getInstance(), &MdnsBrowser::addressResolved, &loop, &QEventLoop::quit); - weakConnect(&MdnsBrowser::getInstance(), &MdnsBrowser::addressResolved, + QObject::connect(MdnsBrowser::getInstance().data(), &MdnsBrowser::addressResolved, &loop, &QEventLoop::quit); + weakConnect(MdnsBrowser::getInstance().data(), &MdnsBrowser::addressResolved, [&hostAddress, hostname, log](const QHostAddress& resolvedAddress) { DebugIf(verboseBrowser, log, "Resolver resolved hostname [%s] to address [%s], Thread: %s", QSTRING_CSTR(hostname), QSTRING_CSTR(resolvedAddress.toString()), QSTRING_CSTR(QThread::currentThread()->objectName())); hostAddress = resolvedAddress; @@ -182,7 +194,7 @@ bool MdnsBrowser::resolveAddress(Logger* log, const QString& hostname, QHostAddr } else { - QObject::disconnect(&MdnsBrowser::getInstance(), &MdnsBrowser::addressResolved, nullptr, nullptr); + QObject::disconnect(MdnsBrowser::getInstance().data(), &MdnsBrowser::addressResolved, nullptr, nullptr); Error(log, "Resolved mDNS hostname [%s] timed out", QSTRING_CSTR(hostname)); } } diff --git a/libsrc/mdns/MdnsProvider.cpp b/libsrc/mdns/MdnsProvider.cpp index b894cac8f..eaaffb7f9 100644 --- a/libsrc/mdns/MdnsProvider.cpp +++ b/libsrc/mdns/MdnsProvider.cpp @@ -34,6 +34,7 @@ void MdnsProvider::init() MdnsProvider::~MdnsProvider() { _providedServiceTypes.clear(); + Info(_log, "mDNS info service stopped"); } void MdnsProvider::publishService(const QString& serviceType, quint16 servicePort, const QByteArray& serviceName) diff --git a/libsrc/ssdp/SSDPHandler.cpp b/libsrc/ssdp/SSDPHandler.cpp index 0fc3d43ab..329996426 100644 --- a/libsrc/ssdp/SSDPHandler.cpp +++ b/libsrc/ssdp/SSDPHandler.cpp @@ -20,7 +20,6 @@ static const QString SSDP_IDENTIFIER("urn:hyperion-project.org:device:basic:1"); SSDPHandler::SSDPHandler(WebServer* webserver, quint16 flatBufPort, quint16 protoBufPort, quint16 jsonServerPort, quint16 sslPort, const QString& name, QObject* parent) : SSDPServer(parent) , _webserver(webserver) - , _localAddress() #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) , _NCA(nullptr) #endif @@ -30,6 +29,8 @@ SSDPHandler::SSDPHandler(WebServer* webserver, quint16 flatBufPort, quint16 prot setJsonServerPort(jsonServerPort); setSSLServerPort(sslPort); setHyperionName(name); + + Debug(_log, "SSDP info service created"); } SSDPHandler::~SSDPHandler() @@ -87,6 +88,7 @@ void SSDPHandler::stopServer() { sendAnnounceList(false); SSDPServer::stop(); + Info(_log, "SSDP info service stopped"); } void SSDPHandler::handleSettingsUpdate(settings::type type, const QJsonDocument& config) diff --git a/libsrc/utils/Logger.cpp b/libsrc/utils/Logger.cpp index 9822501fe..957659465 100644 --- a/libsrc/utils/Logger.cpp +++ b/libsrc/utils/Logger.cpp @@ -53,7 +53,7 @@ Logger* Logger::getInstance(const QString & name, const QString & subName, Logge { log = new Logger(name, subName, minLevel); LoggerMap.insert(name + subName, log); - connect(log, &Logger::newLogMessage, LoggerManager::getInstance(), &LoggerManager::handleNewLogMessage); + connect(log, &Logger::newLogMessage, LoggerManager::getInstance().data(), &LoggerManager::handleNewLogMessage); } return log; @@ -151,9 +151,8 @@ void Logger::write(const Logger::T_LOG_MESSAGE & message) name.resize(MAX_IDENTIFICATION_LENGTH, ' '); const QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(message.utime); - std::cout << QString("%1 %2 : <%3> %4%5") - .arg(timestamp.toString("yyyy-MM-ddThh:mm:ss.zzz")) + .arg(timestamp.toString(Qt::ISODateWithMs)) .arg(name) .arg(LogLevelStrings[message.level]) .arg(location) @@ -169,8 +168,10 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u Logger::LogLevel globalLevel = static_cast(int(GLOBAL_MIN_LOG_LEVEL)); if ( (globalLevel == Logger::UNSET && level < _minLevel) // no global level, use level from logger - || (globalLevel > Logger::UNSET && level < globalLevel) ) // global level set, use global level + || (globalLevel > Logger::UNSET && level < globalLevel) ) // global level set, use global level + { return; + } const size_t max_msg_length = 1024; char msg[max_msg_length]; @@ -188,7 +189,9 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u write(repMsg); #ifndef _WIN32 if ( _syslogEnabled && repMsg.level >= Logger::WARNING ) + { syslog (LogLevelSysLog[repMsg.level], "Previous line repeats %d times", RepeatCount.localData()); + } #endif RepeatCount.setLocalData(0); @@ -201,14 +204,20 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u RepeatMessage.localData().line == line) { if (RepeatCount.localData() >= MaxRepeatCountSize) + { repeatedSummary(); + } else + { RepeatCount.setLocalData(RepeatCount.localData() + 1); + } } else { if (RepeatCount.localData()) + { repeatedSummary(); + } Logger::T_LOG_MESSAGE logMsg; @@ -225,12 +234,16 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u write(logMsg); #ifndef _WIN32 if ( _syslogEnabled && level >= Logger::WARNING ) + { syslog (LogLevelSysLog[level], "%s", msg); + } #endif RepeatMessage.setLocalData(logMsg); } } +QScopedPointer LoggerManager::instance; + LoggerManager::LoggerManager() : QObject() , _loggerMaxMsgBufferSize(MAX_LOG_MSG_BUFFERED) @@ -238,6 +251,14 @@ LoggerManager::LoggerManager() _logMessageBuffer.reserve(_loggerMaxMsgBufferSize); } +LoggerManager::~LoggerManager() +{ + // delete components + Logger::deleteInstance(); + + _logMessageBuffer.clear(); +} + QJsonArray LoggerManager::getLogMessageBuffer(Logger::LogLevel filter) const { QJsonArray messageArray; @@ -274,8 +295,12 @@ void LoggerManager::handleNewLogMessage(const Logger::T_LOG_MESSAGE & msg) emit newLogMessage(msg); } -LoggerManager* LoggerManager::getInstance() +QScopedPointer& LoggerManager::getInstance() { - static LoggerManager instance; - return &instance; + if (!instance) + { + instance.reset(new LoggerManager()); + } + + return instance; } diff --git a/libsrc/webserver/WebServer.cpp b/libsrc/webserver/WebServer.cpp index b2da87042..c40aa6a0c 100644 --- a/libsrc/webserver/WebServer.cpp +++ b/libsrc/webserver/WebServer.cpp @@ -31,7 +31,6 @@ WebServer::WebServer(const QJsonDocument& config, bool useSsl, QObject* parent) , _useSsl(useSsl) , _log(Logger::getInstance("WEBSERVER")) , _port(WEBSERVER_DEFAULT_PORT) - , _server() { } @@ -43,7 +42,7 @@ WebServer::~WebServer() void WebServer::initServer() { Debug(_log, "Initialize %s-Webserver", _useSsl ? "https" : "http"); - _server = new QtHttpServer(this); + _server.reset(new QtHttpServer(this)); _server->setServerName(QStringLiteral("Hyperion %1-Webserver").arg(_useSsl ? "https" : "http")); if (_useSsl) @@ -51,13 +50,13 @@ void WebServer::initServer() _server->setUseSecure(); } - connect(_server, &QtHttpServer::started, this, &WebServer::onServerStarted); - connect(_server, &QtHttpServer::stopped, this, &WebServer::onServerStopped); - connect(_server, &QtHttpServer::error, this, &WebServer::onServerError); + connect(_server.get(), &QtHttpServer::started, this, &WebServer::onServerStarted); + connect(_server.get(), &QtHttpServer::stopped, this, &WebServer::onServerStopped); + connect(_server.get(), &QtHttpServer::error, this, &WebServer::onServerError); // create StaticFileServing _staticFileServing = new StaticFileServing(this); - connect(_server, &QtHttpServer::requestNeedsReply, _staticFileServing, &StaticFileServing::onRequestNeedsReply); + connect(_server.get(), &QtHttpServer::requestNeedsReply, _staticFileServing, &StaticFileServing::onRequestNeedsReply); // init handleSettingsUpdate(settings::WEBSERVER, _config); @@ -83,11 +82,11 @@ void WebServer::onServerStarted(quint16 port) void WebServer::onServerStopped() { - Info(_log, "Stopped %s", _server->getServerName().toStdString().c_str()); + Info(_log, "%s stopped", _server->getServerName().toStdString().c_str()); emit stateChange(false); } -void WebServer::onServerError(QString msg) +void WebServer::onServerError(const QString& msg) { Error(_log, "%s", msg.toStdString().c_str()); } @@ -112,7 +111,9 @@ void WebServer::handleSettingsUpdate(settings::type type, const QJsonDocument& c } } else + { _baseUrl = WEBSERVER_DEFAULT_PATH; + } Debug(_log, "Set document root to: %s", _baseUrl.toUtf8().constData()); _staticFileServing->setBaseUrl(_baseUrl); @@ -127,7 +128,9 @@ void WebServer::handleSettingsUpdate(settings::type type, const QJsonDocument& c // eval if the port is available, will be incremented if not if (!_server->isListening()) + { NetUtils::portAvailable(_port, _log); + } // on ssl we want .key .cert and probably key password if (_useSsl) @@ -149,7 +152,9 @@ void WebServer::handleSettingsUpdate(settings::type type, const QJsonDocument& c } } else + { keyPath = WEBSERVER_DEFAULT_KEY_PATH; + } // check crtPath if ((crtPath != WEBSERVER_DEFAULT_CRT_PATH) && !crtPath.trimmed().isEmpty()) @@ -162,7 +167,9 @@ void WebServer::handleSettingsUpdate(settings::type type, const QJsonDocument& c } } else + { crtPath = WEBSERVER_DEFAULT_CRT_PATH; + } // load and verify crt QFile cfile(crtPath); @@ -174,9 +181,13 @@ void WebServer::handleSettingsUpdate(settings::type type, const QJsonDocument& c // Filter for valid certs for (const auto& entry : cList) { if (!entry.isNull() && QDateTime::currentDateTime().daysTo(entry.expiryDate()) > 0) + { validList.append(entry); + } else + { Error(_log, "The provided SSL certificate is invalid/not supported/reached expiry date ('%s')", crtPath.toUtf8().constData()); + } } if (!validList.isEmpty()) { diff --git a/libsrc/webserver/WebSocketClient.cpp b/libsrc/webserver/WebSocketClient.cpp index 555fae521..3cf8adbcd 100644 --- a/libsrc/webserver/WebSocketClient.cpp +++ b/libsrc/webserver/WebSocketClient.cpp @@ -23,9 +23,11 @@ WebSocketClient::WebSocketClient(QtHttpRequest* request, QTcpSocket* sock, bool const QString client = request->getClientInfo().clientAddress.toString(); // Json processor - _jsonAPI = new JsonAPI(client, _log, localConnection, this); - connect(_jsonAPI, &JsonAPI::callbackMessage, this, &WebSocketClient::sendMessage); - connect(_jsonAPI, &JsonAPI::forceClose, this,[this]() { this->sendClose(CLOSECODE::NORMAL); }); + _jsonAPI.reset(new JsonAPI(client, _log, localConnection, this)); + connect(_jsonAPI.get(), &JsonAPI::callbackMessage, this, &WebSocketClient::sendMessage); + connect(_jsonAPI.get(), &JsonAPI::forceClose, this,[this]() { this->sendClose(CLOSECODE::NORMAL); }); + + connect(this, &WebSocketClient::handleMessage, _jsonAPI.get(), &JsonAPI::handleMessage); Debug(_log, "New connection from %s", QSTRING_CSTR(client)); @@ -129,7 +131,7 @@ void WebSocketClient::handleWebSocketFrame() if (_frameOpCode == OPCODE::TEXT) { - _jsonAPI->handleMessage(QString(_wsReceiveBuffer)); + emit handleMessage(QString(_wsReceiveBuffer),""); } else { diff --git a/libsrc/webserver/WebSocketClient.h b/libsrc/webserver/WebSocketClient.h index df5342bd9..520cefdb1 100644 --- a/libsrc/webserver/WebSocketClient.h +++ b/libsrc/webserver/WebSocketClient.h @@ -2,6 +2,9 @@ #include #include "WebSocketUtils.h" +#include + +#include class QTcpSocket; @@ -28,7 +31,7 @@ class WebSocketClient : public QObject QTcpSocket* _socket; Logger* _log; Hyperion* _hyperion; - JsonAPI* _jsonAPI; + QScopedPointer _jsonAPI; void getWsFrameHeader(WebSocketHeader* header); void sendClose(int status, const QString& reason = ""); @@ -73,4 +76,7 @@ class WebSocketClient : public QObject private slots: void handleWebSocketFrame(); qint64 sendMessage(QJsonObject obj); + +signals: + void handleMessage(const QString &message, const QString &httpAuthHeader); }; diff --git a/src/hyperion-framebuffer/FramebufferWrapper.cpp b/src/hyperion-framebuffer/FramebufferWrapper.cpp index 48968c51e..872fa1028 100644 --- a/src/hyperion-framebuffer/FramebufferWrapper.cpp +++ b/src/hyperion-framebuffer/FramebufferWrapper.cpp @@ -2,13 +2,13 @@ #include "FramebufferWrapper.h" FramebufferWrapper::FramebufferWrapper( int updateRate_Hz, - const QString & device, + int deviceIdx, int pixelDecimation, int cropLeft, int cropRight, int cropTop, int cropBottom ) : _timer(this), - _grabber(device) + _grabber(deviceIdx) { _grabber.setFramerate(updateRate_Hz); _grabber.setCropping(cropLeft, cropRight, cropTop, cropBottom); diff --git a/src/hyperion-framebuffer/FramebufferWrapper.h b/src/hyperion-framebuffer/FramebufferWrapper.h index 9f1b74f28..a5be6f90f 100644 --- a/src/hyperion-framebuffer/FramebufferWrapper.h +++ b/src/hyperion-framebuffer/FramebufferWrapper.h @@ -12,7 +12,7 @@ class FramebufferWrapper : public QObject public: FramebufferWrapper( int updateRate_Hz=GrabberWrapper::DEFAULT_RATE_HZ, - const QString & device = "/dev/fb0", + int deviceIdx = 0, int pixelDecimation=GrabberWrapper::DEFAULT_PIXELDECIMATION, int cropLeft=0, int cropRight=0, int cropTop=0, int cropBottom=0 diff --git a/src/hyperion-framebuffer/hyperion-framebuffer.cpp b/src/hyperion-framebuffer/hyperion-framebuffer.cpp index e4c4f4e67..aa4991306 100644 --- a/src/hyperion-framebuffer/hyperion-framebuffer.cpp +++ b/src/hyperion-framebuffer/hyperion-framebuffer.cpp @@ -50,7 +50,7 @@ int main(int argc, char ** argv) // create the option parser and initialize all parameters Parser parser("FrameBuffer capture application for Hyperion. Will automatically search a Hyperion server if -a option isn't used. Please note that if you have more than one server running it's more or less random which one will be used."); - Option & argDevice = parser.add