mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Hyperion X11 KodiCheck (#685)
* Update X11Grabber.h * Update ProtoConnection.h * Update ProtoConnectionWrapper.h * Update ProtoServer.h * Update X11Grabber.cpp * Update message.proto * Update ProtoClientConnection.cpp * Update ProtoClientConnection.h * Update ProtoConnection.cpp * Update ProtoConnectionWrapper.cpp * Update ProtoServer.cpp * Update hyperion-x11.cpp * Update X11Wrapper.cpp * Update X11Wrapper.h * Update hyperiond.cpp * Update ProtoClientConnection.cpp * Update X11Wrapper.cpp * Update hyperiond.cpp Former-commit-id: a572f275b270217cd8ce8cdd91b3eca3037d6472
This commit is contained in:
committed by
brindosch
parent
614131ebe6
commit
f0dec4cf73
@@ -79,6 +79,32 @@ void ProtoClientConnection::socketClosed()
|
||||
emit connectionClosed(this);
|
||||
}
|
||||
|
||||
void ProtoClientConnection::setGrabbingMode(const GrabbingMode mode)
|
||||
{
|
||||
int grabbing_mode = (int)mode;
|
||||
proto::HyperionReply gMode;
|
||||
|
||||
// create proto message
|
||||
gMode.set_type(proto::HyperionReply::GRABBING);
|
||||
gMode.set_grabbing(grabbing_mode);
|
||||
|
||||
// send message
|
||||
sendMessage(gMode);
|
||||
}
|
||||
|
||||
void ProtoClientConnection::setVideoMode(const VideoMode videoMode)
|
||||
{
|
||||
int video_Mode = (int)videoMode;
|
||||
proto::HyperionReply vMode;
|
||||
|
||||
// create proto message
|
||||
vMode.set_type(proto::HyperionReply::VIDEO);
|
||||
vMode.set_grabbing(video_Mode);
|
||||
|
||||
// send message
|
||||
sendMessage(vMode);
|
||||
}
|
||||
|
||||
void ProtoClientConnection::handleMessage(const proto::HyperionRequest & message)
|
||||
{
|
||||
// forward messages
|
||||
@@ -208,6 +234,7 @@ void ProtoClientConnection::sendSuccessReply()
|
||||
{
|
||||
// create reply
|
||||
proto::HyperionReply reply;
|
||||
reply.set_type(proto::HyperionReply::REPLY);
|
||||
reply.set_success(true);
|
||||
|
||||
// send reply
|
||||
@@ -218,6 +245,7 @@ void ProtoClientConnection::sendErrorReply(const std::string &error)
|
||||
{
|
||||
// create reply
|
||||
proto::HyperionReply reply;
|
||||
reply.set_type(proto::HyperionReply::REPLY);
|
||||
reply.set_success(false);
|
||||
reply.set_error(error);
|
||||
|
||||
|
@@ -11,6 +11,10 @@
|
||||
// Hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
//Utils includes
|
||||
#include <utils/GrabbingMode.h>
|
||||
#include <utils/VideoMode.h>
|
||||
|
||||
// proto includes
|
||||
#include "message.pb.h"
|
||||
#include "protoserver/ProtoConnection.h"
|
||||
@@ -18,7 +22,7 @@
|
||||
class ImageProcessor;
|
||||
|
||||
///
|
||||
/// The Connection object created by \a ProtoServer when a new connection is establshed
|
||||
/// The Connection object created by a ProtoServer when a new connection is establshed
|
||||
///
|
||||
class ProtoClientConnection : public QObject
|
||||
{
|
||||
@@ -36,6 +40,13 @@ public:
|
||||
/// Destructor
|
||||
///
|
||||
~ProtoClientConnection();
|
||||
|
||||
public slots:
|
||||
///
|
||||
/// Send XBMC Video Checker message to connected client
|
||||
///
|
||||
void setGrabbingMode(const GrabbingMode mode);
|
||||
void setVideoMode(const VideoMode videoMode);
|
||||
|
||||
signals:
|
||||
///
|
||||
|
@@ -35,7 +35,8 @@ ProtoConnection::ProtoConnection(const std::string & a) :
|
||||
_timer.setInterval(5000);
|
||||
_timer.setSingleShot(false);
|
||||
|
||||
connect(&_timer,SIGNAL(timeout()), this, SLOT(connectToHost()) );
|
||||
connect(&_timer,SIGNAL(timeout()), this, SLOT(connectToHost()));
|
||||
connect(&_socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
_timer.start();
|
||||
}
|
||||
|
||||
@@ -45,6 +46,44 @@ ProtoConnection::~ProtoConnection()
|
||||
_socket.close();
|
||||
}
|
||||
|
||||
void ProtoConnection::readData()
|
||||
{
|
||||
_receiveBuffer += _socket.readAll();
|
||||
|
||||
// check if we can read a message size
|
||||
if (_receiveBuffer.size() <= 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// read the message size
|
||||
uint32_t messageSize =
|
||||
((_receiveBuffer[0]<<24) & 0xFF000000) |
|
||||
((_receiveBuffer[1]<<16) & 0x00FF0000) |
|
||||
((_receiveBuffer[2]<< 8) & 0x0000FF00) |
|
||||
((_receiveBuffer[3] ) & 0x000000FF);
|
||||
|
||||
// check if we can read a complete message
|
||||
if ((uint32_t) _receiveBuffer.size() < messageSize + 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// read a message
|
||||
proto::HyperionReply reply;
|
||||
|
||||
if (!reply.ParseFromArray(_receiveBuffer.data() + 4, messageSize))
|
||||
{
|
||||
std::cerr << "PROTOCONNECTION ERROR: Unable to parse message" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
parseReply(reply);
|
||||
|
||||
// remove message data from buffer
|
||||
_receiveBuffer = _receiveBuffer.mid(messageSize + 4);
|
||||
}
|
||||
|
||||
void ProtoConnection::setSkipReply(bool skip)
|
||||
{
|
||||
_skipReply = skip;
|
||||
@@ -157,58 +196,51 @@ void ProtoConnection::sendMessage(const proto::HyperionRequest &message)
|
||||
std::cerr << "PROTOCONNECTION ERROR: Error while writing data to host" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_skipReply)
|
||||
{
|
||||
// read reply data
|
||||
QByteArray serializedReply;
|
||||
length = -1;
|
||||
while (length < 0 && serializedReply.size() < length+4)
|
||||
{
|
||||
// receive reply
|
||||
if (!_socket.waitForReadyRead())
|
||||
{
|
||||
std::cerr << "PROTOCONNECTION ERROR: Error while reading data from host" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
serializedReply += _socket.readAll();
|
||||
|
||||
if (length < 0 && serializedReply.size() >= 4)
|
||||
{
|
||||
// read the message size
|
||||
length =
|
||||
((serializedReply[0]<<24) & 0xFF000000) |
|
||||
((serializedReply[1]<<16) & 0x00FF0000) |
|
||||
((serializedReply[2]<< 8) & 0x0000FF00) |
|
||||
((serializedReply[3] ) & 0x000000FF);
|
||||
}
|
||||
}
|
||||
|
||||
// parse reply data
|
||||
proto::HyperionReply reply;
|
||||
reply.ParseFromArray(serializedReply.constData()+4, length);
|
||||
|
||||
// parse reply message
|
||||
parseReply(reply);
|
||||
}
|
||||
}
|
||||
|
||||
bool ProtoConnection::parseReply(const proto::HyperionReply &reply)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
if (!reply.success())
|
||||
|
||||
switch (reply.type())
|
||||
{
|
||||
if (reply.has_error())
|
||||
case proto::HyperionReply::REPLY:
|
||||
{
|
||||
throw std::runtime_error("PROTOCONNECTION ERROR: " + reply.error());
|
||||
if (!_skipReply)
|
||||
{
|
||||
if (!reply.success())
|
||||
{
|
||||
if (reply.has_error())
|
||||
{
|
||||
throw std::runtime_error("PROTOCONNECTION ERROR: " + reply.error());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("PROTOCONNECTION ERROR: No error info");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
case proto::HyperionReply::GRABBING:
|
||||
{
|
||||
throw std::runtime_error("PROTOCONNECTION ERROR: No error info");
|
||||
int grabbing = reply.has_grabbing() ? reply.grabbing() : 6;
|
||||
GrabbingMode gMode = (GrabbingMode)grabbing;
|
||||
emit setGrabbingMode(gMode);
|
||||
break;
|
||||
}
|
||||
case proto::HyperionReply::VIDEO:
|
||||
{
|
||||
int video = reply.has_video() ? reply.video() : 0;
|
||||
VideoMode vMode = (VideoMode)video;
|
||||
emit setVideoMode(vMode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@ ProtoConnectionWrapper::ProtoConnectionWrapper(const std::string & address, int
|
||||
_connection(address)
|
||||
{
|
||||
_connection.setSkipReply(skipProtoReply);
|
||||
connect(&_connection, SIGNAL(setGrabbingMode(GrabbingMode)), this, SIGNAL(setGrabbingMode(GrabbingMode)));
|
||||
connect(&_connection, SIGNAL(setVideoMode(VideoMode)), this, SIGNAL(setVideoMode(VideoMode)));
|
||||
}
|
||||
|
||||
ProtoConnectionWrapper::~ProtoConnectionWrapper()
|
||||
|
@@ -64,6 +64,10 @@ void ProtoServer::newConnection()
|
||||
// register slot for cleaning up after the connection closed
|
||||
connect(connection, SIGNAL(connectionClosed(ProtoClientConnection*)), this, SLOT(closedConnection(ProtoClientConnection*)));
|
||||
connect(connection, SIGNAL(newMessage(const proto::HyperionRequest*)), this, SLOT(newMessage(const proto::HyperionRequest*)));
|
||||
|
||||
// register forward signal for xbmc checker
|
||||
connect(this, SIGNAL(grabbingMode(GrabbingMode)), connection, SLOT(setGrabbingMode(GrabbingMode)));
|
||||
connect(this, SIGNAL(videoMode(VideoMode)), connection, SLOT(setVideoMode(VideoMode)));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -61,9 +61,24 @@ message ClearRequest {
|
||||
}
|
||||
|
||||
message HyperionReply {
|
||||
enum Type {
|
||||
REPLY = 1;
|
||||
GRABBING = 2;
|
||||
VIDEO = 3;
|
||||
}
|
||||
|
||||
// Identifies which field is filled in.
|
||||
required Type type = 1;
|
||||
|
||||
// flag indication success or failure
|
||||
required bool success = 1;
|
||||
optional bool success = 2;
|
||||
|
||||
// string indicating the reason for failure (if applicable)
|
||||
optional string error = 2;
|
||||
optional string error = 3;
|
||||
|
||||
// XBMC Video Checker Proto Messages for Grabbing mode
|
||||
optional int32 grabbing = 4;
|
||||
|
||||
// XBMC Video Checker Proto Messages for Video mode
|
||||
optional int32 video = 5;
|
||||
}
|
||||
|
Reference in New Issue
Block a user