Commit 9d1f3a05 authored by spiiroin's avatar spiiroin

[usb-moded-qt5] Expose target state as property. JB#44479

Usb-moded now provides information about target state of ongoing mode
transitions. Expose it as Qt / QML property.

Also utilize separate state change and event D-Bus signals provided by
usb-moded to avoid need of heuristics for telling apart mode names from
event names.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent ab68b301
/*
* Copyright (C) 2015 Jolla Ltd.
* Copyright (C) 2015-2019 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
......@@ -42,6 +42,7 @@
#define USB_MODED_CALL_MODE_REQUEST (0x04)
#define USB_MODED_CALL_GET_HIDDEN (0x08)
#define USB_MODED_CALL_GET_AVAILABLE_MODES (0x10)
#define USB_MODED_CALL_GET_TARGET_MODE (0x20)
class QUsbModed::Private
{
......@@ -54,6 +55,7 @@ public:
QStringList iHiddenModes;
QString iConfigMode;
QString iCurrentMode;
QString iTargetMode;
QDBusConnection iBus;
QUsbModedInterface* iInterface;
int iPendingCalls;
......@@ -121,6 +123,11 @@ QString QUsbModed::currentMode() const
return iPrivate->iCurrentMode;
}
QString QUsbModed::targetMode() const
{
return iPrivate->iTargetMode;
}
QString QUsbModed::configMode() const
{
return iPrivate->iConfigMode;
......@@ -200,8 +207,14 @@ void QUsbModed::setup()
iPrivate->iInterface = new QUsbModedInterface(USB_MODE_SERVICE,
USB_MODE_OBJECT, iPrivate->iBus, this);
connect(iPrivate->iInterface,
SIGNAL(sig_usb_state_ind(QString)),
SIGNAL(sig_usb_target_state_ind(QString)),
SLOT(onUsbTargetStateChanged(QString)));
connect(iPrivate->iInterface,
SIGNAL(sig_usb_current_state_ind(QString)),
SLOT(onUsbStateChanged(QString)));
connect(iPrivate->iInterface,
SIGNAL(sig_usb_event_ind(QString)),
SLOT(onUsbEventReceived(QString)));
connect(iPrivate->iInterface,
SIGNAL(sig_usb_config_ind(QString,QString,QString)),
SLOT(onUsbConfigChanged(QString,QString,QString)));
......@@ -239,6 +252,12 @@ void QUsbModed::setup()
SIGNAL(finished(QDBusPendingCallWatcher*)),
SLOT(onGetConfigFinished(QDBusPendingCallWatcher*)));
iPrivate->iPendingCalls |= USB_MODED_CALL_GET_TARGET_MODE;
connect(new QDBusPendingCallWatcher(
iPrivate->iInterface->get_target_state(), iPrivate->iInterface),
SIGNAL(finished(QDBusPendingCallWatcher*)),
SLOT(onGetTargetModeFinished(QDBusPendingCallWatcher*)));
iPrivate->iPendingCalls |= USB_MODED_CALL_MODE_REQUEST;
connect(new QDBusPendingCallWatcher(
iPrivate->iInterface->mode_request(), iPrivate->iInterface),
......@@ -309,10 +328,6 @@ void QUsbModed::onGetModeRequestFinished(QDBusPendingCallWatcher* aCall)
iPrivate->iCurrentMode = mode;
Q_EMIT currentModeChanged();
}
if (iPrivate->iCurrentMode != mode) {
iPrivate->iCurrentMode = mode;
Q_EMIT currentModeChanged();
}
} else {
DEBUG_(reply.error());
}
......@@ -320,6 +335,23 @@ void QUsbModed::onGetModeRequestFinished(QDBusPendingCallWatcher* aCall)
setupCallFinished(USB_MODED_CALL_MODE_REQUEST);
}
void QUsbModed::onGetTargetModeFinished(QDBusPendingCallWatcher* aCall)
{
QDBusPendingReply<QString> reply(*aCall);
if (!reply.isError()) {
QString mode = reply.value();
DEBUG_(mode);
if (iPrivate->iTargetMode != mode) {
iPrivate->iTargetMode = mode;
Q_EMIT targetModeChanged();
}
} else {
DEBUG_(reply.error());
}
aCall->deleteLater();
setupCallFinished(USB_MODED_CALL_GET_TARGET_MODE);
}
void QUsbModed::onGetHiddenFinished(QDBusPendingCallWatcher* aCall)
{
QDBusPendingReply<QString> reply(*aCall);
......@@ -447,13 +479,24 @@ void QUsbModed::onUnhideModeFinished(QDBusPendingCallWatcher* aCall)
void QUsbModed::onUsbStateChanged(QString aMode)
{
DEBUG_(aMode);
if (isEvent(aMode)) {
Q_EMIT eventReceived(aMode);
} else {
if (iPrivate->iCurrentMode != aMode) {
iPrivate->iCurrentMode = aMode;
Q_EMIT currentModeChanged();
}
if (iPrivate->iCurrentMode != aMode) {
iPrivate->iCurrentMode = aMode;
Q_EMIT currentModeChanged();
}
}
void QUsbModed::onUsbEventReceived(QString aEvent)
{
DEBUG_(aEvent);
Q_EMIT eventReceived(aEvent);
}
void QUsbModed::onUsbTargetStateChanged(QString aMode)
{
DEBUG_(aMode);
if (iPrivate->iTargetMode != aMode) {
iPrivate->iTargetMode = aMode;
Q_EMIT targetModeChanged();
}
}
......
/*
* Copyright (C) 2015 Jolla Ltd.
* Copyright (C) 2015-2019 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
......@@ -48,6 +48,7 @@ class QUSBMODED_EXPORT QUsbModed : public QUsbMode
Q_PROPERTY(QStringList availableModes READ availableModes NOTIFY availableModesChanged)
Q_PROPERTY(QStringList hiddenModes READ hiddenModes NOTIFY hiddenModesChanged)
Q_PROPERTY(QString currentMode READ currentMode WRITE setCurrentMode NOTIFY currentModeChanged)
Q_PROPERTY(QString targetMode READ targetMode NOTIFY targetModeChanged)
Q_PROPERTY(QString configMode READ configMode WRITE setConfigMode NOTIFY configModeChanged)
public:
......@@ -58,6 +59,7 @@ public:
QStringList supportedModes() const;
QStringList availableModes() const;
QString currentMode() const;
QString targetMode() const;
QString configMode() const;
bool setCurrentMode(QString mode);
......@@ -74,6 +76,7 @@ Q_SIGNALS:
void supportedModesChanged();
void availableModesChanged();
void currentModeChanged();
void targetModeChanged();
void eventReceived(QString event);
void configModeChanged();
void usbStateError(QString error);
......@@ -88,6 +91,7 @@ private Q_SLOTS:
void onGetAvailableModesFinished(QDBusPendingCallWatcher *call);
void onGetConfigFinished(QDBusPendingCallWatcher* call);
void onGetModeRequestFinished(QDBusPendingCallWatcher* call);
void onGetTargetModeFinished(QDBusPendingCallWatcher* aCall);
void onSetModeFinished(QDBusPendingCallWatcher* call);
void onSetConfigFinished(QDBusPendingCallWatcher* call);
void onHideModeFinished(QDBusPendingCallWatcher* call);
......@@ -95,6 +99,8 @@ private Q_SLOTS:
void onGetHiddenFinished(QDBusPendingCallWatcher* call);
void onUsbConfigChanged(QString section, QString key, QString value);
void onUsbStateChanged(QString mode);
void onUsbEventReceived(QString event);
void onUsbTargetStateChanged(QString mode);
void onUsbSupportedModesChanged(QString modes);
void onUsbHiddenModesChanged(QString modes);
......
Markdown is supported
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