You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.6 KiB
69 lines
1.6 KiB
#include <QCoreApplication>
|
|
|
|
#include "controller.h"
|
|
#include "videosocket.h"
|
|
#include "controlevent.h"
|
|
#include "receiver.h"
|
|
|
|
Controller::Controller(QObject* parent) : QObject(parent)
|
|
{
|
|
m_receiver = new Receiver(this);
|
|
}
|
|
|
|
Controller::~Controller()
|
|
{
|
|
|
|
}
|
|
|
|
void Controller::setControlSocket(QTcpSocket* controlSocket)
|
|
{
|
|
if (m_controlSocket || !controlSocket) {
|
|
return;
|
|
}
|
|
m_controlSocket = controlSocket;
|
|
connect(controlSocket, &QTcpSocket::readyRead, m_receiver, &Receiver::onReadyRead);
|
|
}
|
|
|
|
QTcpSocket *Controller::getControlSocket()
|
|
{
|
|
return m_controlSocket;
|
|
}
|
|
|
|
void Controller::postControlEvent(ControlEvent *controlEvent)
|
|
{
|
|
if (controlEvent) {
|
|
QCoreApplication::postEvent(this, controlEvent);
|
|
}
|
|
}
|
|
|
|
void Controller::test(QRect rc)
|
|
{
|
|
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_MOUSE);
|
|
controlEvent->setMouseEventData(AMOTION_EVENT_ACTION_DOWN, AMOTION_EVENT_BUTTON_PRIMARY, rc);
|
|
postControlEvent(controlEvent);
|
|
}
|
|
|
|
bool Controller::event(QEvent *event)
|
|
{
|
|
if (event && event->type() == ControlEvent::Control) {
|
|
ControlEvent* controlEvent = dynamic_cast<ControlEvent*>(event);
|
|
if (controlEvent) {
|
|
sendControl(controlEvent->serializeData());
|
|
}
|
|
return true;
|
|
}
|
|
return QObject::event(event);
|
|
}
|
|
|
|
bool Controller::sendControl(const QByteArray &buffer)
|
|
{
|
|
if (buffer.isEmpty()) {
|
|
return false;
|
|
}
|
|
qint32 len = 0;
|
|
if (m_controlSocket) {
|
|
len = m_controlSocket->write(buffer.data(), buffer.length());
|
|
}
|
|
return len == buffer.length() ? true : false;
|
|
}
|