Commit f9faaa79 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Emit propertiesChanged signal and add fake port test

parent 297d1efa
......@@ -5,6 +5,10 @@
Controller::Controller(QObject *parent) : QObject(parent), connection(QDBusConnection::sessionBus())
{
Autodetect();
Port *port = new Port("test0",1);
new PortAdaptor(port);
port->dbusPath.setPath("/fake/test0");
connection.registerObject(port->dbusPath.path(), port);
}
QStringList Controller::PortList() const
......
......@@ -4,8 +4,12 @@
#include <QMetaEnum>
#include <QSerialPortInfo>
Port::Port(QString name, QObject *parent) : QObject(parent), closeTimer(), autoCloseTimer(), readTimer(), serialPort(name)
#include <QDBusMessage>
#include <QDBusConnection>
Port::Port(QString name, quint8 type, QObject *parent) : QObject(parent), closeTimer(), autoCloseTimer(), readTimer(), serialPort(name)
{
this->type = type;
closeTimer.setInterval(5000);
closeTimer.setSingleShot(true);
connect(&closeTimer,&QTimer::timeout,
......@@ -132,6 +136,7 @@ void Port::Close()
bool Port::Exists() const
{
if(type == 1) return true;
for(QSerialPortInfo info: QSerialPortInfo::availablePorts()) {
if(info.portName() == serialPort.portName()) return true;
}
......@@ -153,6 +158,7 @@ void Port::setFlowControl(quint8 flow_control)
if(serialPort.setFlowControl(QSerialPort::FlowControl(flow_control-1))) {
qDebug() << "Setting flow control to" << flow_control << "succeeded";
emit flowControlChanged(flow_control);
notifyPropertyChanged("FlowControl");
} else {
qDebug() << "Setting flow control to" << flow_control << "failed - error" << errorString();
}
......@@ -169,6 +175,7 @@ void Port::setBaudrate(qint32 baudrate)
if(serialPort.setBaudRate(baudrate)) {
qDebug() << "Setting baudrate to" << baudrate << "succeeded";
emit baudrateChanged(baudrate);
notifyPropertyChanged("Baudrate");
} else {
qDebug() << "Setting baudrate to" << baudrate << "failed - error" << errorString();
}
......@@ -185,6 +192,7 @@ void Port::setDataBits(quint8 dataBits)
if(serialPort.setDataBits(QSerialPort::DataBits(dataBits))) {
qDebug() << "Setting data bits to" << dataBits << "succeeded";
emit dataBitsChanged(dataBits);
notifyPropertyChanged("DataBits");
} else {
qDebug() << "Setting data bits to" << dataBits << "failed - error" << errorString();
}
......@@ -201,6 +209,7 @@ void Port::setStopBits(quint8 stopBits)
if(serialPort.setStopBits(QSerialPort::StopBits(stopBits))) {
qDebug() << "Setting stop bits to" << stopBits << "succeeded";
emit stopBitsChanged(stopBits);
notifyPropertyChanged("StopBits");
} else {
qDebug() << "Setting stop bits to" << stopBits << "failed - error" << errorString();
}
......@@ -218,6 +227,7 @@ void Port::setParity(quint8 parity)
if(serialPort.setParity(QSerialPort::Parity(parity))) {
qDebug() << "Setting parity to" << parity << "succeeded";
emit parityChanged(parity);
notifyPropertyChanged("Parity");
} else {
qDebug() << "Setting parity to" << parity << "failed - error" << errorString();
}
......@@ -259,3 +269,19 @@ void Port::read()
}
}
/*****
* HELPERS
*****/
void Port::notifyPropertyChanged( const char *propertyName )
{
QDBusMessage signal = QDBusMessage::createSignal(
dbusPath.path(),
"org.freedesktop.DBus.Properties",
"PropertiesChanged");
signal << QString("info.skorepa.DSerial.port1");
QVariantMap changedProps;
changedProps.insert(propertyName, property(propertyName));
signal << changedProps;
signal << QStringList();
QDBusConnection::sessionBus().send(signal);
}
......@@ -11,7 +11,7 @@ class Port : public QObject
{
Q_OBJECT
public: // Interface from rest of program
explicit Port(QString name ,QObject *parent = 0);
explicit Port(QString name, quint8 type = 0, QObject *parent = 0);
QDBusObjectPath dbusPath;
signals:
void removeMe(QDBusObjectPath) const;
......@@ -67,6 +67,9 @@ class Port : public QObject
void read();
private:
quint8 type;
void notifyPropertyChanged( const char *propertyName );
QTimer closeTimer;
QTimer autoCloseTimer;
QTimer readTimer;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment