Update udpcommander plugin
This commit is contained in:
parent
3dcc5a038d
commit
ddedc1ebc2
@ -30,8 +30,10 @@ DevicePluginUdpCommander::DevicePluginUdpCommander()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::DeviceSetupStatus DevicePluginUdpCommander::setupDevice(Device *device)
|
void DevicePluginUdpCommander::setupDevice(DeviceSetupInfo *info)
|
||||||
{
|
{
|
||||||
|
Device *device = info->device();
|
||||||
|
|
||||||
qCDebug(dcUdpCommander()) << "Setup device" << device->name() << device->params();
|
qCDebug(dcUdpCommander()) << "Setup device" << device->name() << device->params();
|
||||||
|
|
||||||
if (device->deviceClassId() == udpReceiverDeviceClassId) {
|
if (device->deviceClassId() == udpReceiverDeviceClassId) {
|
||||||
@ -40,28 +42,29 @@ Device::DeviceSetupStatus DevicePluginUdpCommander::setupDevice(Device *device)
|
|||||||
if (!udpSocket->bind(QHostAddress::Any, port, QUdpSocket::ShareAddress)) {
|
if (!udpSocket->bind(QHostAddress::Any, port, QUdpSocket::ShareAddress)) {
|
||||||
qCWarning(dcUdpCommander()) << device->name() << "cannot bind to port" << port;
|
qCWarning(dcUdpCommander()) << device->name() << "cannot bind to port" << port;
|
||||||
delete udpSocket;
|
delete udpSocket;
|
||||||
return Device::DeviceSetupStatusFailure;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable, QT_TR_NOOP("Error opening UDP port."));
|
||||||
}
|
}
|
||||||
qCDebug(dcUdpCommander()) << "Listening on port" << port;
|
qCDebug(dcUdpCommander()) << "Listening on port" << port;
|
||||||
|
|
||||||
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
|
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
|
||||||
m_receiverList.insert(udpSocket, device);
|
m_receiverList.insert(udpSocket, device);
|
||||||
|
|
||||||
return Device::DeviceSetupStatusSuccess;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
} else if (device->deviceClassId() == udpCommanderDeviceClassId) {
|
} else if (device->deviceClassId() == udpCommanderDeviceClassId) {
|
||||||
QUdpSocket *udpSocket = new QUdpSocket(this);
|
QUdpSocket *udpSocket = new QUdpSocket(this);
|
||||||
m_commanderList.insert(udpSocket, device);
|
m_commanderList.insert(udpSocket, device);
|
||||||
return Device::DeviceSetupStatusSuccess;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Device::DeviceSetupStatusFailure;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Device::DeviceError DevicePluginUdpCommander::executeAction(Device *device, const Action &action) {
|
void DevicePluginUdpCommander::executeAction(DeviceActionInfo *info)
|
||||||
|
{
|
||||||
|
Device *device = info->device();
|
||||||
|
Action action = info->action();
|
||||||
|
|
||||||
|
Q_ASSERT_X(action.actionTypeId() == udpCommanderTriggerActionTypeId, "UdpCommander", "Unhandled action type in UDP commander.");
|
||||||
|
|
||||||
if (device->deviceClassId() == udpCommanderDeviceClassId) {
|
|
||||||
if (action.actionTypeId() == udpCommanderTriggerActionTypeId) {
|
|
||||||
QUdpSocket *udpSocket = m_commanderList.key(device);
|
QUdpSocket *udpSocket = m_commanderList.key(device);
|
||||||
int port = device->paramValue(udpCommanderDevicePortParamTypeId).toInt();
|
int port = device->paramValue(udpCommanderDevicePortParamTypeId).toInt();
|
||||||
QHostAddress address = QHostAddress(device->paramValue(udpCommanderDeviceAddressParamTypeId).toString());
|
QHostAddress address = QHostAddress(device->paramValue(udpCommanderDeviceAddressParamTypeId).toString());
|
||||||
@ -69,11 +72,7 @@ Device::DeviceError DevicePluginUdpCommander::executeAction(Device *device, cons
|
|||||||
qDebug(dcUdpCommander()) << "Send UDP datagram:" << data << "address:" << address.toIPv4Address() << "port:" << port;
|
qDebug(dcUdpCommander()) << "Send UDP datagram:" << data << "address:" << address.toIPv4Address() << "port:" << port;
|
||||||
udpSocket->writeDatagram(data, address, port);
|
udpSocket->writeDatagram(data, address, port);
|
||||||
|
|
||||||
return Device::DeviceErrorNoError;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
}
|
|
||||||
return Device::DeviceErrorActionTypeNotFound;
|
|
||||||
}
|
|
||||||
return Device::DeviceErrorDeviceClassNotFound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginUdpCommander::deviceRemoved(Device *device)
|
void DevicePluginUdpCommander::deviceRemoved(Device *device)
|
||||||
|
|||||||
@ -39,10 +39,10 @@ class DevicePluginUdpCommander : public DevicePlugin
|
|||||||
public:
|
public:
|
||||||
explicit DevicePluginUdpCommander();
|
explicit DevicePluginUdpCommander();
|
||||||
|
|
||||||
Device::DeviceSetupStatus setupDevice(Device *device) override;
|
void setupDevice(DeviceSetupInfo *info) override;
|
||||||
void deviceRemoved(Device *device) override;
|
void deviceRemoved(Device *device) override;
|
||||||
|
|
||||||
Device::DeviceError executeAction(Device *device, const Action &action) override;
|
void executeAction(DeviceActionInfo *info) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<QUdpSocket *, Device *> m_receiverList;
|
QHash<QUdpSocket *, Device *> m_receiverList;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user