Skip to content

Commit

Permalink
[usb-moded-qt5] Expose target state as property. JB#44479
Browse files Browse the repository at this point in the history
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: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Feb 7, 2019
1 parent ab68b30 commit 9d1f3a0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 14 deletions.
69 changes: 56 additions & 13 deletions src/qusbmoded.cpp
@@ -1,5 +1,5 @@
/*
* 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:
Expand Down Expand Up @@ -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
{
Expand All @@ -54,6 +55,7 @@ class QUsbModed::Private
QStringList iHiddenModes;
QString iConfigMode;
QString iCurrentMode;
QString iTargetMode;
QDBusConnection iBus;
QUsbModedInterface* iInterface;
int iPendingCalls;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -309,17 +328,30 @@ 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());
}
aCall->deleteLater();
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);
Expand Down Expand Up @@ -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();
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/qusbmoded.h
@@ -1,5 +1,5 @@
/*
* 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:
Expand Down Expand Up @@ -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:
Expand All @@ -58,6 +59,7 @@ class QUSBMODED_EXPORT QUsbModed : public QUsbMode
QStringList supportedModes() const;
QStringList availableModes() const;
QString currentMode() const;
QString targetMode() const;
QString configMode() const;

bool setCurrentMode(QString mode);
Expand All @@ -74,6 +76,7 @@ public Q_SLOTS:
void supportedModesChanged();
void availableModesChanged();
void currentModeChanged();
void targetModeChanged();
void eventReceived(QString event);
void configModeChanged();
void usbStateError(QString error);
Expand All @@ -88,13 +91,16 @@ 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);
void onUnhideModeFinished(QDBusPendingCallWatcher* call);
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);

Expand Down

0 comments on commit 9d1f3a0

Please sign in to comment.