mirror of
				https://github.com/hyperion-project/hyperion.ng.git
				synced 2025-03-01 10:33:28 +00:00 
			
		
		
		
	Merge pull request #120 from redPanther/grabber_rework
every input sources trackes now its priority and ID to hyperion core
This commit is contained in:
		| @@ -2,6 +2,7 @@ | |||||||
|  |  | ||||||
| // stl includes | // stl includes | ||||||
| #include <list> | #include <list> | ||||||
|  | #include <map> | ||||||
|  |  | ||||||
| // QT includes | // QT includes | ||||||
| #include <QObject> | #include <QObject> | ||||||
| @@ -46,6 +47,7 @@ class Hyperion : public QObject | |||||||
| public: | public: | ||||||
| 	///  Type definition of the info structure used by the priority muxer | 	///  Type definition of the info structure used by the priority muxer | ||||||
| 	typedef PriorityMuxer::InputInfo InputInfo; | 	typedef PriorityMuxer::InputInfo InputInfo; | ||||||
|  | 	typedef std::map<std::string,int> PriorityRegister; | ||||||
|  |  | ||||||
| 	/// | 	/// | ||||||
| 	/// RGB-Color channel enumeration | 	/// RGB-Color channel enumeration | ||||||
| @@ -109,11 +111,24 @@ public: | |||||||
| 	/// @return The list of active effects | 	/// @return The list of active effects | ||||||
| 	const std::list<ActiveEffectDefinition> &getActiveEffects(); | 	const std::list<ActiveEffectDefinition> &getActiveEffects(); | ||||||
| 	 | 	 | ||||||
| 	///  | 	/// gets the current json config object | ||||||
|  | 	/// @return json config | ||||||
| 	const Json::Value& getJsonConfig() { return _jsonConfig; }; | 	const Json::Value& getJsonConfig() { return _jsonConfig; }; | ||||||
| 	 |  | ||||||
|  | 	/// get filename of configfile | ||||||
|  | 	/// @return the current config filename | ||||||
| 	std::string getConfigFileName() { return _configFile; }; | 	std::string getConfigFileName() { return _configFile; }; | ||||||
|  |  | ||||||
|  | 	/// register a input source to a priority channel | ||||||
|  | 	/// @param name uniq name of input source | ||||||
|  | 	/// @param priority priority channel | ||||||
|  | 	void registerPriority(const std::string name, const int priority); | ||||||
|  | 	 | ||||||
|  | 	/// unregister a input source to a priority channel | ||||||
|  | 	/// @param name uniq name of input source | ||||||
|  | 	void unRegisterPriority(const std::string name); | ||||||
|  | 	 | ||||||
|  | 	const PriorityRegister& getPriorityRegister() { return _priorityRegister; } | ||||||
| public slots: | public slots: | ||||||
| 	/// | 	/// | ||||||
| 	/// Writes a single color to all the leds for the given time and priority | 	/// Writes a single color to all the leds for the given time and priority | ||||||
| @@ -307,4 +322,7 @@ private: | |||||||
| 	 | 	 | ||||||
| 	/// count of hardware leds | 	/// count of hardware leds | ||||||
| 	unsigned _hwLedCount; | 	unsigned _hwLedCount; | ||||||
|  | 	 | ||||||
|  | 	/// register of input sources and it's prio channel | ||||||
|  | 	PriorityRegister _priorityRegister; | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -22,15 +22,15 @@ | |||||||
| // project includes | // project includes | ||||||
| #include "BoblightClientConnection.h" | #include "BoblightClientConnection.h" | ||||||
|  |  | ||||||
| BoblightClientConnection::BoblightClientConnection(QTcpSocket *socket, const int priority, Hyperion * hyperion) | BoblightClientConnection::BoblightClientConnection(QTcpSocket *socket, const int priority) | ||||||
| 	: QObject() | 	: QObject() | ||||||
| 	, _locale(QLocale::C) | 	, _locale(QLocale::C) | ||||||
| 	, _socket(socket) | 	, _socket(socket) | ||||||
| 	, _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()) | 	, _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()) | ||||||
| 	, _hyperion(hyperion) | 	, _hyperion(Hyperion::getInstance()) | ||||||
| 	, _receiveBuffer() | 	, _receiveBuffer() | ||||||
| 	, _priority(priority) | 	, _priority(priority) | ||||||
| 	, _ledColors(hyperion->getLedCount(), ColorRgb::BLACK) | 	, _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb::BLACK) | ||||||
| 	, _log(Logger::getInstance("BOBLIGHT")) | 	, _log(Logger::getInstance("BOBLIGHT")) | ||||||
| { | { | ||||||
| 	// initalize the locale. Start with the default C-locale | 	// initalize the locale. Start with the default C-locale | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ public: | |||||||
| 	/// @param socket The Socket object for this connection | 	/// @param socket The Socket object for this connection | ||||||
| 	/// @param hyperion The Hyperion server | 	/// @param hyperion The Hyperion server | ||||||
| 	/// | 	/// | ||||||
| 	BoblightClientConnection(QTcpSocket * socket, const int priority, Hyperion * hyperion); | 	BoblightClientConnection(QTcpSocket * socket, const int priority); | ||||||
|  |  | ||||||
| 	/// | 	/// | ||||||
| 	/// Destructor | 	/// Destructor | ||||||
|   | |||||||
| @@ -37,6 +37,9 @@ void BoblightServer::start() | |||||||
|  |  | ||||||
| 	_isActive = true; | 	_isActive = true; | ||||||
| 	emit statusChanged(_isActive); | 	emit statusChanged(_isActive); | ||||||
|  |  | ||||||
|  | 	_hyperion->registerPriority("Boblight", _priority); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void BoblightServer::stop() | void BoblightServer::stop() | ||||||
| @@ -49,6 +52,9 @@ void BoblightServer::stop() | |||||||
| 	} | 	} | ||||||
| 	_isActive = false; | 	_isActive = false; | ||||||
| 	emit statusChanged(_isActive); | 	emit statusChanged(_isActive); | ||||||
|  |  | ||||||
|  | 	_hyperion->unRegisterPriority("Boblight"); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -64,7 +70,7 @@ void BoblightServer::newConnection() | |||||||
| 	if (socket != nullptr) | 	if (socket != nullptr) | ||||||
| 	{ | 	{ | ||||||
| 		Info(_log, "new connection"); | 		Info(_log, "new connection"); | ||||||
| 		BoblightClientConnection * connection = new BoblightClientConnection(socket, _priority, _hyperion); | 		BoblightClientConnection * connection = new BoblightClientConnection(socket, _priority); | ||||||
| 		_openConnections.insert(connection); | 		_openConnections.insert(connection); | ||||||
|  |  | ||||||
| 		// register slot for cleaning up after the connection closed | 		// register slot for cleaning up after the connection closed | ||||||
|   | |||||||
| @@ -181,6 +181,7 @@ int EffectEngine::runEffectScript(const std::string &script, const Json::Value & | |||||||
| 	_activeEffects.push_back(effect); | 	_activeEffects.push_back(effect); | ||||||
|  |  | ||||||
| 	// start the effect | 	// start the effect | ||||||
|  | 	_hyperion->registerPriority("EFFECT: "+script, priority); | ||||||
| 	effect->start(); | 	effect->start(); | ||||||
|  |  | ||||||
| 	return 0; | 	return 0; | ||||||
| @@ -225,4 +226,5 @@ void EffectEngine::effectFinished(Effect *effect) | |||||||
|  |  | ||||||
| 	// cleanup the effect | 	// cleanup the effect | ||||||
| 	effect->deleteLater(); | 	effect->deleteLater(); | ||||||
|  | 	_hyperion->unRegisterPriority("EFFECT: " + effect->getScript()); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -44,6 +44,7 @@ void AmlogicWrapper::start() | |||||||
| { | { | ||||||
| 	// Start the timer with the pre configured interval | 	// Start the timer with the pre configured interval | ||||||
| 	_timer.start(); | 	_timer.start(); | ||||||
|  | 	_hyperion->registerPriority("Amlogic Grabber",_priority); | ||||||
| } | } | ||||||
|  |  | ||||||
| void AmlogicWrapper::action() | void AmlogicWrapper::action() | ||||||
| @@ -70,6 +71,8 @@ void AmlogicWrapper::stop() | |||||||
| { | { | ||||||
| 	// Stop the timer, effectivly stopping the process | 	// Stop the timer, effectivly stopping the process | ||||||
| 	_timer.stop(); | 	_timer.stop(); | ||||||
|  | 	_hyperion->unRegisterPriority("Amlogic Grabber"); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void AmlogicWrapper::setGrabbingMode(const GrabbingMode mode) | void AmlogicWrapper::setGrabbingMode(const GrabbingMode mode) | ||||||
|   | |||||||
| @@ -44,6 +44,7 @@ void DispmanxWrapper::start() | |||||||
| { | { | ||||||
| 	// Start the timer with the pre configured interval | 	// Start the timer with the pre configured interval | ||||||
| 	_timer.start(); | 	_timer.start(); | ||||||
|  | 	_hyperion->registerPriority("Dispmanx Grabber", _priority); | ||||||
| } | } | ||||||
|  |  | ||||||
| void DispmanxWrapper::action() | void DispmanxWrapper::action() | ||||||
| @@ -66,6 +67,7 @@ void DispmanxWrapper::stop() | |||||||
| { | { | ||||||
| 	// Stop the timer, effectivly stopping the process | 	// Stop the timer, effectivly stopping the process | ||||||
| 	_timer.stop(); | 	_timer.stop(); | ||||||
|  | 	_hyperion->unRegisterPriority("Dispmanx Grabber"); | ||||||
| } | } | ||||||
|  |  | ||||||
| void DispmanxWrapper::setGrabbingMode(const GrabbingMode mode) | void DispmanxWrapper::setGrabbingMode(const GrabbingMode mode) | ||||||
|   | |||||||
| @@ -39,6 +39,7 @@ void FramebufferWrapper::start() | |||||||
| { | { | ||||||
| 	// Start the timer with the pre configured interval | 	// Start the timer with the pre configured interval | ||||||
| 	_timer.start(); | 	_timer.start(); | ||||||
|  | 	_hyperion->registerPriority("FrameBuffer Grabber", _priority); | ||||||
| } | } | ||||||
|  |  | ||||||
| void FramebufferWrapper::action() | void FramebufferWrapper::action() | ||||||
| @@ -55,6 +56,7 @@ void FramebufferWrapper::stop() | |||||||
| { | { | ||||||
| 	// Stop the timer, effectivly stopping the process | 	// Stop the timer, effectivly stopping the process | ||||||
| 	_timer.stop(); | 	_timer.stop(); | ||||||
|  | 	_hyperion->unRegisterPriority("FrameBuffer Grabber"); | ||||||
| } | } | ||||||
|  |  | ||||||
| void FramebufferWrapper::setGrabbingMode(const GrabbingMode mode) | void FramebufferWrapper::setGrabbingMode(const GrabbingMode mode) | ||||||
|   | |||||||
| @@ -39,6 +39,7 @@ void OsxWrapper::start() | |||||||
| { | { | ||||||
| 	// Start the timer with the pre configured interval | 	// Start the timer with the pre configured interval | ||||||
| 	_timer.start(); | 	_timer.start(); | ||||||
|  | 	_hyperion->registerPriority("OsxFrameGrabber", _priority); | ||||||
| } | } | ||||||
|  |  | ||||||
| void OsxWrapper::action() | void OsxWrapper::action() | ||||||
| @@ -55,6 +56,7 @@ void OsxWrapper::stop() | |||||||
| { | { | ||||||
| 	// Stop the timer, effectivly stopping the process | 	// Stop the timer, effectivly stopping the process | ||||||
| 	_timer.stop(); | 	_timer.stop(); | ||||||
|  | 	_hyperion->unRegisterPriority("OsxFrameGrabber"); | ||||||
| } | } | ||||||
|  |  | ||||||
| void OsxWrapper::setGrabbingMode(const GrabbingMode mode) | void OsxWrapper::setGrabbingMode(const GrabbingMode mode) | ||||||
|   | |||||||
| @@ -15,10 +15,10 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device, | |||||||
| 		double redSignalThreshold, | 		double redSignalThreshold, | ||||||
| 		double greenSignalThreshold, | 		double greenSignalThreshold, | ||||||
| 		double blueSignalThreshold, | 		double blueSignalThreshold, | ||||||
| 		int hyperionPriority) : | 		int hyperionPriority) | ||||||
| 	_timeout_ms(1000), | 	: _timeout_ms(1000) | ||||||
| 	_priority(hyperionPriority), | 	, _priority(hyperionPriority) | ||||||
| 	_grabber(device, | 	, _grabber(device, | ||||||
| 			input, | 			input, | ||||||
| 			videoStandard, | 			videoStandard, | ||||||
| 			pixelFormat, | 			pixelFormat, | ||||||
| @@ -26,18 +26,14 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device, | |||||||
| 			height, | 			height, | ||||||
| 			frameDecimation, | 			frameDecimation, | ||||||
| 			pixelDecimation, | 			pixelDecimation, | ||||||
| 			pixelDecimation), | 			pixelDecimation) | ||||||
| 	_processor(ImageProcessorFactory::getInstance().newImageProcessor()), | 	, _processor(ImageProcessorFactory::getInstance().newImageProcessor()) | ||||||
| 	_hyperion(Hyperion::getInstance()), | 	, _hyperion(Hyperion::getInstance()) | ||||||
| 	_ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0}), | 	, _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb{0,0,0}) | ||||||
| 	_timer() | 	, _timer() | ||||||
| { | { | ||||||
| 	// set the signal detection threshold of the grabber | 	// set the signal detection threshold of the grabber | ||||||
| 	_grabber.setSignalThreshold( | 	_grabber.setSignalThreshold( redSignalThreshold, greenSignalThreshold, blueSignalThreshold, 50); | ||||||
| 			redSignalThreshold, |  | ||||||
| 			greenSignalThreshold, |  | ||||||
| 			blueSignalThreshold, |  | ||||||
| 			50); |  | ||||||
|  |  | ||||||
| 	// register the image type | 	// register the image type | ||||||
| 	qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>"); | 	qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>"); | ||||||
| @@ -55,6 +51,7 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device, | |||||||
| 				_hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int)), | 				_hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int)), | ||||||
| 				Qt::QueuedConnection); | 				Qt::QueuedConnection); | ||||||
|  |  | ||||||
|  | 	 | ||||||
| 	// setup the higher prio source checker | 	// setup the higher prio source checker | ||||||
| 	// this will disable the v4l2 grabber when a source with hisher priority is active | 	// this will disable the v4l2 grabber when a source with hisher priority is active | ||||||
| 	_timer.setInterval(500); | 	_timer.setInterval(500); | ||||||
| @@ -72,14 +69,21 @@ bool V4L2Wrapper::start() | |||||||
| { | { | ||||||
| 	bool grabber_started = _grabber.start(); | 	bool grabber_started = _grabber.start(); | ||||||
| 	if ( ! grabber_started ) | 	if ( ! grabber_started ) | ||||||
|  | 	{ | ||||||
| 		_timer.stop(); | 		_timer.stop(); | ||||||
| 	 | 	} | ||||||
|  | 	else | ||||||
|  | 	{ | ||||||
|  | 		_hyperion->registerPriority("V4L2", _priority); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	return grabber_started; | 	return grabber_started; | ||||||
| } | } | ||||||
|  |  | ||||||
| void V4L2Wrapper::stop() | void V4L2Wrapper::stop() | ||||||
| { | { | ||||||
| 	_grabber.stop(); | 	_grabber.stop(); | ||||||
|  | 	_hyperion->unRegisterPriority("V4L2"); | ||||||
| } | } | ||||||
|  |  | ||||||
| void V4L2Wrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom) | void V4L2Wrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom) | ||||||
|   | |||||||
| @@ -541,32 +541,32 @@ MessageForwarder * Hyperion::getForwarder() | |||||||
| 	return _messageForwarder; | 	return _messageForwarder; | ||||||
| } | } | ||||||
|  |  | ||||||
| Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile) : | Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile) | ||||||
| 	_ledString(createLedString(jsonConfig["leds"], createColorOrder(jsonConfig["device"]))), | 	: _ledString(createLedString(jsonConfig["leds"], createColorOrder(jsonConfig["device"]))) | ||||||
| 	_muxer(_ledString.leds().size()), | 	, _muxer(_ledString.leds().size()) | ||||||
| 	_raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), jsonConfig["color"])), | 	, _raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), jsonConfig["color"])) | ||||||
| 	_raw2ledTemperature(createLedColorsTemperature(_ledString.leds().size(), jsonConfig["color"])), | 	, _raw2ledTemperature(createLedColorsTemperature(_ledString.leds().size(), jsonConfig["color"])) | ||||||
| 	_raw2ledAdjustment(createLedColorsAdjustment(_ledString.leds().size(), jsonConfig["color"])), | 	, _raw2ledAdjustment(createLedColorsAdjustment(_ledString.leds().size(), jsonConfig["color"])) | ||||||
| 	_device(LedDeviceFactory::construct(jsonConfig["device"])), | 	, _device(LedDeviceFactory::construct(jsonConfig["device"])) | ||||||
| 	_effectEngine(nullptr), | 	, _effectEngine(nullptr) | ||||||
| 	_messageForwarder(createMessageForwarder(jsonConfig["forwarder"])), | 	, _messageForwarder(createMessageForwarder(jsonConfig["forwarder"])) | ||||||
| 	_jsonConfig(jsonConfig), | 	, _jsonConfig(jsonConfig) | ||||||
| 	_configFile(configFile), | 	, _configFile(configFile) | ||||||
| 	_timer(), | 	, _timer() | ||||||
| 	_log(Logger::getInstance("Core")), | 	, _log(Logger::getInstance("Core")) | ||||||
| 	_hwLedCount(_ledString.leds().size()) | 	, _hwLedCount(_ledString.leds().size()) | ||||||
| { | { | ||||||
| 	if (!_raw2ledAdjustment->verifyAdjustments()) | 	if (!_raw2ledAdjustment->verifyAdjustments()) | ||||||
| 	{ | 	{ | ||||||
| 		throw std::runtime_error("HYPERION ERROR: Color adjustment incorrectly set"); | 		throw std::runtime_error("Color adjustment incorrectly set"); | ||||||
| 	} | 	} | ||||||
| 	if (!_raw2ledTemperature->verifyCorrections()) | 	if (!_raw2ledTemperature->verifyCorrections()) | ||||||
| 	{ | 	{ | ||||||
| 		throw std::runtime_error("HYPERION ERROR: Color temperature incorrectly set"); | 		throw std::runtime_error("Color temperature incorrectly set"); | ||||||
| 	} | 	} | ||||||
| 	if (!_raw2ledTransform->verifyTransforms()) | 	if (!_raw2ledTransform->verifyTransforms()) | ||||||
| 	{ | 	{ | ||||||
| 		throw std::runtime_error("HYPERION ERROR: Color transformation incorrectly set"); | 		throw std::runtime_error("Color transformation incorrectly set"); | ||||||
| 	} | 	} | ||||||
| 	// initialize the image processor factory | 	// initialize the image processor factory | ||||||
| 	ImageProcessorFactory::getInstance().init( | 	ImageProcessorFactory::getInstance().init( | ||||||
| @@ -614,6 +614,26 @@ unsigned Hyperion::getLedCount() const | |||||||
| 	return _ledString.leds().size(); | 	return _ledString.leds().size(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void Hyperion::registerPriority(const std::string name, const int priority) | ||||||
|  | { | ||||||
|  | 	Info(_log, "Register new input source named '%s' for priority channel '%d'", name.c_str(), priority ); | ||||||
|  | 	 | ||||||
|  | 	for(auto const &entry : _priorityRegister) | ||||||
|  | 	{ | ||||||
|  | 		WarningIf( ( entry.first != name && entry.second == priority), _log, | ||||||
|  | 		           "Input source '%s' uses same priority channel (%d) as '%s'.", name.c_str(), priority, entry.first.c_str()); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	_priorityRegister.emplace(name,priority); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Hyperion::unRegisterPriority(const std::string name) | ||||||
|  | { | ||||||
|  | 	Info(_log, "Unregister input source named '%s' from priority register", name.c_str()); | ||||||
|  | 	_priorityRegister.erase(name); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms, bool clearEffects) | void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms, bool clearEffects) | ||||||
| { | { | ||||||
| 	// create led output | 	// create led output | ||||||
|   | |||||||
| @@ -387,6 +387,7 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) | |||||||
| 	Json::Value & priorities = info["priorities"] = Json::Value(Json::arrayValue); | 	Json::Value & priorities = info["priorities"] = Json::Value(Json::arrayValue); | ||||||
| 	uint64_t now = QDateTime::currentMSecsSinceEpoch(); | 	uint64_t now = QDateTime::currentMSecsSinceEpoch(); | ||||||
| 	QList<int> activePriorities = _hyperion->getActivePriorities(); | 	QList<int> activePriorities = _hyperion->getActivePriorities(); | ||||||
|  | 	const Hyperion::PriorityRegister& priorityRegister = _hyperion->getPriorityRegister(); | ||||||
| 	foreach (int priority, activePriorities) { | 	foreach (int priority, activePriorities) { | ||||||
| 		const Hyperion::InputInfo & priorityInfo = _hyperion->getPriorityInfo(priority); | 		const Hyperion::InputInfo & priorityInfo = _hyperion->getPriorityInfo(priority); | ||||||
| 		Json::Value & item = priorities[priorities.size()]; | 		Json::Value & item = priorities[priorities.size()]; | ||||||
| @@ -395,6 +396,16 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) | |||||||
| 		{ | 		{ | ||||||
| 			item["duration_ms"] = Json::Value::UInt(priorityInfo.timeoutTime_ms - now); | 			item["duration_ms"] = Json::Value::UInt(priorityInfo.timeoutTime_ms - now); | ||||||
| 		} | 		} | ||||||
|  | 		 | ||||||
|  | 		item["owner"] = "unknown"; | ||||||
|  | 		for(auto const &entry : priorityRegister) | ||||||
|  | 		{ | ||||||
|  | 			if (entry.second == priority) | ||||||
|  | 			{ | ||||||
|  | 				item["owner"] = entry.first; | ||||||
|  | 				break; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	// collect temperature correction information | 	// collect temperature correction information | ||||||
|   | |||||||
| @@ -20,16 +20,19 @@ | |||||||
| // project includes | // project includes | ||||||
| #include "ProtoClientConnection.h" | #include "ProtoClientConnection.h" | ||||||
|  |  | ||||||
| ProtoClientConnection::ProtoClientConnection(QTcpSocket *socket, Hyperion * hyperion) : | ProtoClientConnection::ProtoClientConnection(QTcpSocket *socket) | ||||||
| 	QObject(), | 	: QObject() | ||||||
| 	_socket(socket), | 	, _socket(socket) | ||||||
| 	_imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()), | 	, _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()) | ||||||
| 	_hyperion(hyperion), | 	, _hyperion(Hyperion::getInstance()) | ||||||
| 	_receiveBuffer() | 	, _receiveBuffer() | ||||||
|  | 	, _priority(-1) | ||||||
| { | { | ||||||
| 	// connect internal signals and slots | 	// connect internal signals and slots | ||||||
| 	connect(_socket, SIGNAL(disconnected()), this, SLOT(socketClosed())); | 	connect(_socket, SIGNAL(disconnected()), this, SLOT(socketClosed())); | ||||||
| 	connect(_socket, SIGNAL(readyRead()), this, SLOT(readData())); | 	connect(_socket, SIGNAL(readyRead()), this, SLOT(readData())); | ||||||
|  | 	 | ||||||
|  | 	_priorityChannelName = "proto@"+ _socket->peerAddress().toString().toStdString(); | ||||||
| } | } | ||||||
|  |  | ||||||
| ProtoClientConnection::~ProtoClientConnection() | ProtoClientConnection::~ProtoClientConnection() | ||||||
| @@ -76,6 +79,7 @@ void ProtoClientConnection::readData() | |||||||
|  |  | ||||||
| void ProtoClientConnection::socketClosed() | void ProtoClientConnection::socketClosed() | ||||||
| { | { | ||||||
|  | 	_hyperion->unRegisterPriority(_priorityChannelName); | ||||||
| 	emit connectionClosed(this); | 	emit connectionClosed(this); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -110,6 +114,7 @@ void ProtoClientConnection::handleMessage(const proto::HyperionRequest & message | |||||||
| 	// forward messages | 	// forward messages | ||||||
| 	emit newMessage(&message); | 	emit newMessage(&message); | ||||||
|  |  | ||||||
|  | 	int prevPriority = _priority; | ||||||
| 	switch (message.command()) | 	switch (message.command()) | ||||||
| 	{ | 	{ | ||||||
| 	case proto::HyperionRequest::COLOR: | 	case proto::HyperionRequest::COLOR: | ||||||
| @@ -142,12 +147,18 @@ void ProtoClientConnection::handleMessage(const proto::HyperionRequest & message | |||||||
| 	default: | 	default: | ||||||
| 		handleNotImplemented(); | 		handleNotImplemented(); | ||||||
| 	} | 	} | ||||||
|  | 	 | ||||||
|  | 	if (prevPriority != _priority) | ||||||
|  | 	{ | ||||||
|  | 		_hyperion->registerPriority(_priorityChannelName, _priority); | ||||||
|  | 		prevPriority = _priority; | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &message) | void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &message) | ||||||
| { | { | ||||||
| 	// extract parameters | 	// extract parameters | ||||||
| 	int priority = message.priority(); | 	_priority = message.priority(); | ||||||
| 	int duration = message.has_duration() ? message.duration() : -1; | 	int duration = message.has_duration() ? message.duration() : -1; | ||||||
| 	ColorRgb color; | 	ColorRgb color; | ||||||
| 	color.red = qRed(message.rgbcolor()); | 	color.red = qRed(message.rgbcolor()); | ||||||
| @@ -155,7 +166,7 @@ void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &messag | |||||||
| 	color.blue = qBlue(message.rgbcolor()); | 	color.blue = qBlue(message.rgbcolor()); | ||||||
|  |  | ||||||
| 	// set output | 	// set output | ||||||
| 	_hyperion->setColor(priority, color, duration); | 	_hyperion->setColor(_priority, color, duration); | ||||||
|  |  | ||||||
| 	// send reply | 	// send reply | ||||||
| 	sendSuccessReply(); | 	sendSuccessReply(); | ||||||
| @@ -164,7 +175,7 @@ void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &messag | |||||||
| void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &message) | void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &message) | ||||||
| { | { | ||||||
| 	// extract parameters | 	// extract parameters | ||||||
| 	int priority = message.priority(); | 	_priority = message.priority(); | ||||||
| 	int duration = message.has_duration() ? message.duration() : -1; | 	int duration = message.has_duration() ? message.duration() : -1; | ||||||
| 	int width = message.imagewidth(); | 	int width = message.imagewidth(); | ||||||
| 	int height = message.imageheight(); | 	int height = message.imageheight(); | ||||||
| @@ -186,7 +197,7 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag | |||||||
|  |  | ||||||
| 	// process the image | 	// process the image | ||||||
| 	std::vector<ColorRgb> ledColors = _imageProcessor->process(image); | 	std::vector<ColorRgb> ledColors = _imageProcessor->process(image); | ||||||
| 	_hyperion->setColors(priority, ledColors, duration); | 	_hyperion->setColors(_priority, ledColors, duration); | ||||||
|  |  | ||||||
| 	// send reply | 	// send reply | ||||||
| 	sendSuccessReply(); | 	sendSuccessReply(); | ||||||
| @@ -196,11 +207,11 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag | |||||||
| void ProtoClientConnection::handleClearCommand(const proto::ClearRequest &message) | void ProtoClientConnection::handleClearCommand(const proto::ClearRequest &message) | ||||||
| { | { | ||||||
| 	// extract parameters | 	// extract parameters | ||||||
| 	int priority = message.priority(); | 	_priority = message.priority(); | ||||||
|  |  | ||||||
| 	// clear priority | 	// clear priority | ||||||
| 	_hyperion->clear(priority); | 	_hyperion->clear(_priority); | ||||||
|  | 	_hyperion->unRegisterPriority(_priorityChannelName); | ||||||
| 	// send reply | 	// send reply | ||||||
| 	sendSuccessReply(); | 	sendSuccessReply(); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -34,7 +34,7 @@ public: | |||||||
| 	/// @param socket The Socket object for this connection | 	/// @param socket The Socket object for this connection | ||||||
| 	/// @param hyperion The Hyperion server | 	/// @param hyperion The Hyperion server | ||||||
| 	/// | 	/// | ||||||
| 	ProtoClientConnection(QTcpSocket * socket, Hyperion * hyperion); | 	ProtoClientConnection(QTcpSocket * socket); | ||||||
|  |  | ||||||
| 	/// | 	/// | ||||||
| 	/// Destructor | 	/// Destructor | ||||||
| @@ -137,4 +137,8 @@ private: | |||||||
|  |  | ||||||
| 	/// The buffer used for reading data from the socket | 	/// The buffer used for reading data from the socket | ||||||
| 	QByteArray _receiveBuffer; | 	QByteArray _receiveBuffer; | ||||||
|  | 	 | ||||||
|  | 	int _priority; | ||||||
|  | 	 | ||||||
|  | 	std::string _priorityChannelName; | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -1,10 +1,10 @@ | |||||||
| // protoserver includes | // protoserver includes | ||||||
| #include "protoserver/ProtoConnectionWrapper.h" | #include "protoserver/ProtoConnectionWrapper.h" | ||||||
|  |  | ||||||
| ProtoConnectionWrapper::ProtoConnectionWrapper(const std::string & address, int priority, int duration_ms, bool skipProtoReply) : | ProtoConnectionWrapper::ProtoConnectionWrapper(const std::string & address, int priority, int duration_ms, bool skipProtoReply) | ||||||
| 	_priority(priority), | 	: _priority(priority) | ||||||
| 	_duration_ms(duration_ms), | 	, _duration_ms(duration_ms) | ||||||
| 	_connection(address) | 	, _connection(address) | ||||||
| { | { | ||||||
| 	_connection.setSkipReply(skipProtoReply); | 	_connection.setSkipReply(skipProtoReply); | ||||||
| 	connect(&_connection, SIGNAL(setGrabbingMode(GrabbingMode)), this, SIGNAL(setGrabbingMode(GrabbingMode))); | 	connect(&_connection, SIGNAL(setGrabbingMode(GrabbingMode)), this, SIGNAL(setGrabbingMode(GrabbingMode))); | ||||||
|   | |||||||
| @@ -7,12 +7,12 @@ | |||||||
| #include "protoserver/ProtoConnection.h" | #include "protoserver/ProtoConnection.h" | ||||||
| #include "ProtoClientConnection.h" | #include "ProtoClientConnection.h" | ||||||
|  |  | ||||||
| ProtoServer::ProtoServer(uint16_t port) : | ProtoServer::ProtoServer(uint16_t port) | ||||||
| 	QObject(), | 	: QObject() | ||||||
| 	_hyperion(Hyperion::getInstance()), | 	, _hyperion(Hyperion::getInstance()) | ||||||
| 	_server(), | 	, _server() | ||||||
| 	_openConnections(), | 	, _openConnections() | ||||||
| 	_log(Logger::getInstance("PROTOSERVER")) | 	, _log(Logger::getInstance("PROTOSERVER")) | ||||||
| { | { | ||||||
|  |  | ||||||
| 	MessageForwarder * forwarder = _hyperion->getForwarder(); | 	MessageForwarder * forwarder = _hyperion->getForwarder(); | ||||||
| @@ -59,7 +59,7 @@ void ProtoServer::newConnection() | |||||||
| 	if (socket != nullptr) | 	if (socket != nullptr) | ||||||
| 	{ | 	{ | ||||||
| 		Debug(_log, "New connection"); | 		Debug(_log, "New connection"); | ||||||
| 		ProtoClientConnection * connection = new ProtoClientConnection(socket, _hyperion); | 		ProtoClientConnection * connection = new ProtoClientConnection(socket); | ||||||
| 		_openConnections.insert(connection); | 		_openConnections.insert(connection); | ||||||
|  |  | ||||||
| 		// register slot for cleaning up after the connection closed | 		// register slot for cleaning up after the connection closed | ||||||
|   | |||||||
| @@ -29,6 +29,9 @@ UDPListener::UDPListener(const int priority, const int timeout, const std::strin | |||||||
|  |  | ||||||
| 	// Set trigger for incoming connections | 	// Set trigger for incoming connections | ||||||
| 	connect(_server, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); | 	connect(_server, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); | ||||||
|  | 	 | ||||||
|  | 	_hyperion->registerPriority("UDPLISTENER", _priority); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| UDPListener::~UDPListener() | UDPListener::~UDPListener() | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ StaticFileServing::StaticFileServing (Hyperion *hyperion, QString baseUrl, quint | |||||||
| 	_mimeDb = new QMimeDatabase; | 	_mimeDb = new QMimeDatabase; | ||||||
|  |  | ||||||
| 	_server = new QtHttpServer (this); | 	_server = new QtHttpServer (this); | ||||||
| 	_server->setServerName (QStringLiteral ("Qt Static HTTP File Server")); | 	_server->setServerName (QStringLiteral ("Hyperion WebConfig")); | ||||||
|  |  | ||||||
| 	connect (_server, &QtHttpServer::started,           this, &StaticFileServing::onServerStarted); | 	connect (_server, &QtHttpServer::started,           this, &StaticFileServing::onServerStarted); | ||||||
| 	connect (_server, &QtHttpServer::stopped,           this, &StaticFileServing::onServerStopped); | 	connect (_server, &QtHttpServer::stopped,           this, &StaticFileServing::onServerStopped); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user