Skip to content

Commit

Permalink
[voicecall] Don't use sync DBus calls
Browse files Browse the repository at this point in the history
  • Loading branch information
giucam committed Sep 17, 2015
1 parent c526e41 commit 1cfacfb
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 29 deletions.
74 changes: 49 additions & 25 deletions plugins/declarative/src/voicecallhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class VoiceCallHandlerPrivate
VoiceCallHandlerPrivate(VoiceCallHandler *q, const QString &pHandlerId)
: q_ptr(q), handlerId(pHandlerId), interface(NULL), connected(false)
, duration(0), status(0), emergency(false), multiparty(false)
, forwarded(false), remoteHeld(false)
, forwarded(false), remoteHeld(false), initializing(false), notifyInitializeError(false)
{ /* ... */ }

VoiceCallHandler *q_ptr;
Expand All @@ -41,6 +41,8 @@ class VoiceCallHandlerPrivate
bool multiparty;
bool forwarded;
bool remoteHeld;
bool initializing;
bool notifyInitializeError;
};

/*!
Expand Down Expand Up @@ -73,6 +75,9 @@ void VoiceCallHandler::initialize(bool notifyError)
Q_D(VoiceCallHandler);
bool success = false;

if (d->initializing)
return;

if(d->interface->isValid())
{
success = true;
Expand All @@ -92,31 +97,50 @@ void VoiceCallHandler::initialize(bool notifyError)
QTimer::singleShot(2000, this, SLOT(initialize()));
if(notifyError) emit this->error("Failed to connect to VCM D-Bus service.");
} else {
QDBusReply<QVariantMap> reply = d->interface->call("getProperties");
if (reply.isValid()) {
QVariantMap props = reply.value();
d->providerId = props["providerId"].toString();
d->duration = props["duration"].toInt();
d->status = props["status"].toInt();
d->statusText = props["statusText"].toString();
d->lineId = props["lineId"].toString();
d->startedAt = QDateTime::fromMSecsSinceEpoch(props["startedAt"].toULongLong());
d->multiparty = props["isMultiparty"].toBool();
d->emergency = props["isEmergency"].toBool();
d->forwarded = props["isForwarded"].toBool();
d->remoteHeld = props["isRemoteHeld"].toBool();
emit durationChanged();
emit statusChanged();
emit lineIdChanged();
emit startedAtChanged();
emit multipartyChanged();
emit emergencyChanged();
emit forwardedChanged();
emit isReadyChanged();
emit isRemoteHeld();
} else if (notifyError) {
QDBusPendingCall call = d->interface->asyncCall("getProperties");
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);

connect(watcher, &QDBusPendingCallWatcher::finished, this, &VoiceCallHandler::initializeReply);
d->initializing = true;
d->notifyInitializeError = notifyError;
}
}

void VoiceCallHandler::initializeReply(QDBusPendingCallWatcher *watcher)
{
TRACE
QDBusPendingReply<QVariantMap> reply = *watcher;
watcher->deleteLater();

Q_D(VoiceCallHandler);
d->initializing = false;
if (reply.isError()) {
WARNING_T(QString::fromLatin1("Received error reply for member: %1 (%2)").arg(reply.reply().member()).arg(reply.error().message()));
if (d->notifyInitializeError)
emit this->error("Failed to getProperties() from VCM D-Bus service.");
}
} else {
DEBUG_T(QString::fromLatin1("Received successful reply for member: %1").arg(reply.reply().member()));

QVariantMap props = reply.value();
d->providerId = props["providerId"].toString();
d->duration = props["duration"].toInt();
d->status = props["status"].toInt();
d->statusText = props["statusText"].toString();
d->lineId = props["lineId"].toString();
d->startedAt = QDateTime::fromMSecsSinceEpoch(props["startedAt"].toULongLong());
d->multiparty = props["isMultiparty"].toBool();
d->emergency = props["isEmergency"].toBool();
d->forwarded = props["isForwarded"].toBool();
d->remoteHeld = props["isRemoteHeld"].toBool();
emit durationChanged();
emit statusChanged();
emit lineIdChanged();
emit startedAtChanged();
emit multipartyChanged();
emit emergencyChanged();
emit forwardedChanged();
emit isReadyChanged();
emit isRemoteHeld();
}
}

Expand Down
1 change: 1 addition & 0 deletions plugins/declarative/src/voicecallhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected Q_SLOTS:
void onRemoteHeldChanged(bool remoteHeld);

private:
void initializeReply(QDBusPendingCallWatcher *watcher);
class VoiceCallHandlerPrivate *d_ptr;

Q_DISABLE_COPY(VoiceCallHandler)
Expand Down
28 changes: 28 additions & 0 deletions plugins/declarative/src/voicecallmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,34 @@ bool VoiceCallManager::setMuteSpeaker(bool on)
return reply.isError() ? false : reply.value();
}

void VoiceCallManager::setAudioModeAsync(const QString &mode)
{
TRACE
Q_D(const VoiceCallManager);
d->interface->asyncCall("setAudioMode", mode);
}

void VoiceCallManager::setAudioRoutedAsync(bool on)
{
TRACE
Q_D(const VoiceCallManager);
d->interface->asyncCall("setAudioRouted", on);
}

void VoiceCallManager::setMuteMicrophoneAsync(bool on)
{
TRACE
Q_D(VoiceCallManager);
d->interface->asyncCall("setMuteMicrophone", on);
}

void VoiceCallManager::setMuteSpeakerAsync(bool on)
{
TRACE
Q_D(VoiceCallManager);
d->interface->asyncCall("setMuteSpeaker", on);
}

bool VoiceCallManager::startDtmfTone(const QString &tone)
{
TRACE
Expand Down
14 changes: 10 additions & 4 deletions plugins/declarative/src/voicecallmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class VoiceCallManager : public QObject

Q_PROPERTY(VoiceCallHandler* activeVoiceCall READ activeVoiceCall NOTIFY activeVoiceCallChanged)

Q_PROPERTY(QString audioMode READ audioMode WRITE setAudioMode NOTIFY audioModeChanged)
Q_PROPERTY(bool isAudioRouted READ isAudioRouted WRITE setAudioRouted NOTIFY audioRoutedChanged)
Q_PROPERTY(bool isMicrophoneMuted READ isMicrophoneMuted WRITE setMuteMicrophone NOTIFY microphoneMutedChanged)
Q_PROPERTY(bool isSpeakerMuted READ isSpeakerMuted WRITE setMuteSpeaker NOTIFY speakerMutedChanged)
Q_PROPERTY(QString audioMode READ audioMode WRITE setAudioModeAsync NOTIFY audioModeChanged)
Q_PROPERTY(bool isAudioRouted READ isAudioRouted WRITE setAudioRoutedAsync NOTIFY audioRoutedChanged)
Q_PROPERTY(bool isMicrophoneMuted READ isMicrophoneMuted WRITE setMuteMicrophoneAsync NOTIFY microphoneMutedChanged)
Q_PROPERTY(bool isSpeakerMuted READ isSpeakerMuted WRITE setMuteSpeakerAsync NOTIFY speakerMutedChanged)

public:
explicit VoiceCallManager(QObject *parent = 0);
Expand All @@ -42,6 +42,12 @@ class VoiceCallManager : public QObject

VoiceCallHandler* activeVoiceCall() const;

void setAudioModeAsync(const QString &mode);
void setAudioRoutedAsync(bool on);
void setMuteMicrophoneAsync(bool on);
void setMuteSpeakerAsync(bool on);


QString audioMode() const;
bool isAudioRouted() const;

Expand Down

0 comments on commit 1cfacfb

Please sign in to comment.