Commit ab68b301 authored by spiiroin's avatar spiiroin

Merge branch 'jb42756_usb_mode_select' into 'master'

Handle usb mode changes separately from events

See merge request !4
parents 22a12aab 9282bb86
......@@ -41,6 +41,11 @@ const QString QUsbMode::Mode::Connected(USB_CONNECTED);
const QString QUsbMode::Mode::DataInUse(DATA_IN_USE);
const QString QUsbMode::Mode::Disconnected(USB_DISCONNECTED);
const QString QUsbMode::Mode::ModeRequest(USB_CONNECTED_DIALOG_SHOW);
const QString QUsbMode::Mode::PreUnmount(USB_PRE_UNMOUNT);
const QString QUsbMode::Mode::ReMountFailed(RE_MOUNT_FAILED);
const QString QUsbMode::Mode::ModeSettingFailed(MODE_SETTING_FAILED);
const QString QUsbMode::Mode::ChargerConnected(CHARGER_CONNECTED);
const QString QUsbMode::Mode::ChargerDisconnected(CHARGER_DISCONNECTED);
// Modes (from usb_moded-modes.h)
const QString QUsbMode::Mode::Undefined(MODE_UNDEFINED);
......@@ -55,8 +60,76 @@ const QString QUsbMode::Mode::Adb(MODE_ADB);
const QString QUsbMode::Mode::PCSuite(MODE_PC_SUITE);
const QString QUsbMode::Mode::Charging(MODE_CHARGING);
const QString QUsbMode::Mode::Charger(MODE_CHARGER);
const QString QUsbMode::Mode::ChargingFallback(MODE_CHARGING_FALLBACK);
const QString QUsbMode::Mode::Busy(MODE_BUSY);
QUsbMode::QUsbMode(QObject* aParent) :
QObject(aParent)
{
}
bool QUsbMode::isEvent(const QString &modeName)
{
// "Event" is something usb-moded can broadcast as
// com.meego.usb_moded.sig_usb_state_ind(modeName)
// but is never returned as result of mode query
// modeName = com.meego.usb_moded.mode_request()
// The set of possible "events" is hard-coded in usb-moded and
// can be assumed to be fairly stable
return (modeName == QUsbMode::Mode::Connected ||
modeName == QUsbMode::Mode::DataInUse ||
modeName == QUsbMode::Mode::Disconnected ||
modeName == QUsbMode::Mode::ModeRequest ||
modeName == QUsbMode::Mode::PreUnmount ||
modeName == QUsbMode::Mode::ReMountFailed ||
modeName == QUsbMode::Mode::ModeSettingFailed ||
modeName == QUsbMode::Mode::ChargerConnected ||
modeName == QUsbMode::Mode::ChargerDisconnected);
}
bool QUsbMode::isState(const QString &modeName)
{
// "State" is something usb-moded can broadcast as
// com.meego.usb_moded.sig_usb_state_ind(modeName)
// and can be returned as result of mode query
// modeName = com.meego.usb_moded.mode_request()
// The set of "states" depends on configuration files and
// thus the only assumption that can be made is: If it is
// not an "event", it is a "state".
return !isEvent(modeName);
}
bool QUsbMode::isWaitingState(const QString &modeName)
{
// Busy -> Waiting for usb reconfiguration etc tasks related
// to mode switch to finish.
// ChargingFallback -> Waiting for device state that allows
// mode selection e.g. device to get unlocked.
// Ask -> Waiting for user to select a mode.
return (modeName == QUsbMode::Mode::Busy ||
modeName == QUsbMode::Mode::ChargingFallback ||
modeName == QUsbMode::Mode::Ask);
}
bool QUsbMode::isFinalState(const QString &modeName)
{
return isState(modeName) && !isWaitingState(modeName);
}
bool QUsbMode::isDisconnected(const QString &modeName)
{
return (modeName == QUsbMode::Mode::Disconnected ||
modeName == QUsbMode::Mode::ChargerDisconnected ||
modeName == QUsbMode::Mode::Undefined);
}
bool QUsbMode::isConnected(const QString &modeName)
{
// Note that "busy" indicates neither connected nor disconnected.
return !isDisconnected(modeName) && modeName != QUsbMode::Mode::Busy;
}
......@@ -47,6 +47,11 @@ class QUSBMODED_EXPORT QUsbMode : public QObject
Q_PROPERTY(QString DATA_IN_USE READ DATA_IN_USE CONSTANT)
Q_PROPERTY(QString USB_DISCONNECTED READ USB_DISCONNECTED CONSTANT)
Q_PROPERTY(QString USB_CONNECTED_DIALOG_SHOW READ USB_CONNECTED_DIALOG_SHOW CONSTANT)
Q_PROPERTY(QString USB_PRE_UNMOUNT READ USB_PRE_UNMOUNT CONSTANT)
Q_PROPERTY(QString RE_MOUNT_FAILED READ RE_MOUNT_FAILED CONSTANT)
Q_PROPERTY(QString MODE_SETTING_FAILED READ MODE_SETTING_FAILED CONSTANT)
Q_PROPERTY(QString CHARGER_CONNECTED READ CHARGER_CONNECTED CONSTANT)
Q_PROPERTY(QString CHARGER_DISCONNECTED READ CHARGER_DISCONNECTED CONSTANT)
// Modes (from usb_moded-modes.h)
Q_PROPERTY(QString MODE_UNDEFINED READ MODE_UNDEFINED CONSTANT)
......@@ -61,6 +66,8 @@ class QUSBMODED_EXPORT QUsbMode : public QObject
Q_PROPERTY(QString MODE_PC_SUITE READ MODE_PC_SUITE CONSTANT)
Q_PROPERTY(QString MODE_CHARGING READ MODE_CHARGING CONSTANT)
Q_PROPERTY(QString MODE_CHARGER READ MODE_CHARGER CONSTANT)
Q_PROPERTY(QString MODE_CHARGING_FALLBACK READ MODE_CHARGING_FALLBACK CONSTANT)
Q_PROPERTY(QString MODE_BUSY READ MODE_BUSY CONSTANT)
public:
class Mode {
......@@ -70,6 +77,11 @@ public:
static const QString DataInUse;
static const QString Disconnected;
static const QString ModeRequest;
static const QString PreUnmount;
static const QString ReMountFailed;
static const QString ModeSettingFailed;
static const QString ChargerConnected;
static const QString ChargerDisconnected;
// Modes (from usb_moded-modes.h)
static const QString Undefined;
......@@ -84,6 +96,8 @@ public:
static const QString PCSuite;
static const QString Charging;
static const QString Charger;
static const QString ChargingFallback;
static const QString Busy;
private:
Mode(); // Disallow instantiation
......@@ -91,12 +105,25 @@ public:
QUsbMode(QObject* parent = NULL);
Q_INVOKABLE static bool isEvent(const QString &modeName);
Q_INVOKABLE static bool isState(const QString &modeName);
Q_INVOKABLE static bool isWaitingState(const QString &modeName);
Q_INVOKABLE static bool isFinalState(const QString &modeName);
Q_INVOKABLE static bool isConnected(const QString &modeName);
Q_INVOKABLE static bool isDisconnected(const QString &modeName);
private:
// Getters for QML constants
QString USB_CONNECTED() const { return Mode::Connected; }
QString DATA_IN_USE() const { return Mode::DataInUse; }
QString USB_DISCONNECTED() const { return Mode::Disconnected; }
QString USB_CONNECTED_DIALOG_SHOW() const { return Mode::ModeRequest; }
QString USB_PRE_UNMOUNT() const { return Mode::PreUnmount; }
QString RE_MOUNT_FAILED() const { return Mode::ReMountFailed; }
QString MODE_SETTING_FAILED() const { return Mode::ModeSettingFailed; }
QString CHARGER_CONNECTED() const { return Mode::ChargerConnected; }
QString CHARGER_DISCONNECTED() const { return Mode::ChargerDisconnected; }
QString MODE_UNDEFINED() const { return Mode::Undefined; }
QString MODE_ASK() const { return Mode::Ask; }
QString MODE_MASS_STORAGE() const { return Mode::MassStorage; }
......@@ -109,6 +136,8 @@ private:
QString MODE_PC_SUITE() const { return Mode::PCSuite; }
QString MODE_CHARGING() const { return Mode::Charging; }
QString MODE_CHARGER() const { return Mode::Charger; }
QString MODE_CHARGING_FALLBACK() const { return Mode::ChargingFallback; }
QString MODE_BUSY() const { return Mode::Busy; }
};
#endif // QUSBMODED_H
......@@ -398,10 +398,10 @@ void QUsbModed::onSetModeFinished(QDBusPendingCallWatcher* aCall)
if (!reply.isError()) {
QString mode = reply.value();
DEBUG_(mode);
if (iPrivate->iCurrentMode != mode) {
iPrivate->iCurrentMode = mode;
Q_EMIT currentModeChanged();
}
// Note: Getting a reply does not indicate mode change.
// Even accepted requests could get translated to
// something else (e.g. charging only) if there
// are problems during mode activation
} else {
DEBUG_(reply.error());
}
......@@ -447,9 +447,13 @@ void QUsbModed::onUnhideModeFinished(QDBusPendingCallWatcher* aCall)
void QUsbModed::onUsbStateChanged(QString aMode)
{
DEBUG_(aMode);
if (iPrivate->iCurrentMode != aMode) {
iPrivate->iCurrentMode = aMode;
Q_EMIT currentModeChanged();
if (isEvent(aMode)) {
Q_EMIT eventReceived(aMode);
} else {
if (iPrivate->iCurrentMode != aMode) {
iPrivate->iCurrentMode = aMode;
Q_EMIT currentModeChanged();
}
}
}
......
......@@ -74,6 +74,7 @@ Q_SIGNALS:
void supportedModesChanged();
void availableModesChanged();
void currentModeChanged();
void eventReceived(QString event);
void configModeChanged();
void usbStateError(QString error);
void hiddenModesChanged();
......
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