Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Bluedevil
Commits
8d771c35
Commit
8d771c35
authored
Mar 15, 2013
by
Ilya Basin
Committed by
Àlex Fiestas
Mar 17, 2013
Browse files
BlueDevilDaemon/monolithic fix race condition, use QDBusServiceWatcher
BUG: 314356
parent
ba6fb964
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/daemon/kded/BlueDevilDaemon.cpp
View file @
8d771c35
...
...
@@ -24,6 +24,8 @@
#include
"filereceiversettings.h"
#include
"version.h"
#include
<QtCore/QProcess>
#include
<QDBusServiceWatcher>
#include
<QDBusMetaType>
#include
<kdemacros.h>
...
...
@@ -31,7 +33,6 @@
#include
<KAboutData>
#include
<KPluginFactory>
#include
<kfileplacesmodel.h>
#include
<kprocess.h>
#include
<kdirnotify.h>
#include
<bluedevil/bluedevilmanager.h>
...
...
@@ -58,6 +59,7 @@ struct BlueDevilDaemon::Private
KFilePlacesModel
*
m_placesModel
;
Adapter
*
m_adapter
;
org
::
kde
::
BlueDevil
::
Service
*
m_service
;
QDBusServiceWatcher
*
m_monolithicWatcher
;
QList
<
DeviceInfo
>
m_discovered
;
QTimer
m_timer
;
};
...
...
@@ -73,6 +75,8 @@ BlueDevilDaemon::BlueDevilDaemon(QObject *parent, const QList<QVariant>&)
d
->
m_adapter
=
0
;
d
->
m_service
=
0
;
d
->
m_placesModel
=
0
;
d
->
m_monolithicWatcher
=
new
QDBusServiceWatcher
(
"org.kde.bluedevilmonolithic"
,
QDBusConnection
::
sessionBus
(),
QDBusServiceWatcher
::
WatchForUnregistration
,
this
);
d
->
m_timer
.
setInterval
(
20000
);
d
->
m_timer
.
setSingleShot
(
true
);
...
...
@@ -92,6 +96,8 @@ BlueDevilDaemon::BlueDevilDaemon(QObject *parent, const QList<QVariant>&)
aboutData
.
addAuthor
(
ki18n
(
"Eduardo Robles Elvira"
),
ki18n
(
"Maintainer"
),
"edulix@gmail.com"
,
"http://blog.edulix.es"
);
connect
(
d
->
m_monolithicWatcher
,
SIGNAL
(
serviceUnregistered
(
const
QString
&
)),
SLOT
(
monolithicFinished
(
const
QString
&
)));
connect
(
Manager
::
self
(),
SIGNAL
(
usableAdapterChanged
(
Adapter
*
)),
this
,
SLOT
(
usableAdapterChanged
(
Adapter
*
)));
...
...
@@ -171,6 +177,30 @@ bool BlueDevilDaemon::isServiceStarted()
return
r
.
value
();
}
void
BlueDevilDaemon
::
executeMonolithic
()
{
kDebug
();
QProcess
process
;
if
(
!
process
.
startDetached
(
"bluedevil-monolithic"
))
{
kError
()
<<
"Could not start bluedevil-monolithic"
;
}
}
void
BlueDevilDaemon
::
killMonolithic
()
{
kDebug
();
QDBusMessage
msg
=
QDBusMessage
::
createMethodCall
(
"org.kde.bluedevilmonolithic"
,
"/MainApplication"
,
"org.kde.KApplication"
,
"quit"
);
QDBusPendingCall
pending
=
QDBusConnection
::
sessionBus
().
asyncCall
(
msg
);
QDBusPendingCallWatcher
*
watcher
=
new
QDBusPendingCallWatcher
(
pending
);
connect
(
watcher
,
SIGNAL
(
finished
(
QDBusPendingCallWatcher
*
)),
SLOT
(
monolithicQuit
(
QDBusPendingCallWatcher
*
)));
}
void
BlueDevilDaemon
::
onlineMode
()
{
kDebug
();
...
...
@@ -207,12 +237,20 @@ void BlueDevilDaemon::onlineMode()
d
->
m_placesModel
->
addPlace
(
"Bluetooth"
,
KUrl
(
"bluetooth:/"
),
"preferences-system-bluetooth"
);
KProcess
process
;
process
.
startDetached
(
"bluedevil-monolithic"
);
executeMonolithic
();
d
->
m_status
=
Private
::
Online
;
}
void
BlueDevilDaemon
::
monolithicFinished
(
const
QString
&
)
{
kDebug
();
if
(
d
->
m_status
==
Private
::
Online
)
{
executeMonolithic
();
}
}
void
BlueDevilDaemon
::
offlineMode
()
{
kDebug
()
<<
"Offline mode"
;
...
...
@@ -239,13 +277,7 @@ void BlueDevilDaemon::offlineMode()
d
->
m_placesModel
->
removePlace
(
index
);
}
QDBusMessage
msg
=
QDBusMessage
::
createMethodCall
(
"org.kde.bluedevilmonolithic"
,
"/MainApplication"
,
"org.kde.KApplication"
,
"quit"
);
QDBusConnection
::
sessionBus
().
asyncCall
(
msg
);
killMonolithic
();
d
->
m_status
=
Private
::
Offline
;
}
...
...
@@ -280,6 +312,16 @@ void BlueDevilDaemon::deviceFound(Device *device)
org
::
kde
::
KDirNotify
::
emitFilesAdded
(
"bluetooth:/"
);
}
void
BlueDevilDaemon
::
monolithicQuit
(
QDBusPendingCallWatcher
*
watcher
)
{
kDebug
();
QDBusPendingReply
<
void
>
reply
=
*
watcher
;
if
(
reply
.
isError
())
{
qDebug
()
<<
"Error response: "
<<
reply
.
error
().
message
();
killMonolithic
();
}
}
DeviceInfo
BlueDevilDaemon
::
deviceToInfo
(
const
Device
*
device
)
const
{
DeviceInfo
info
;
...
...
@@ -289,4 +331,4 @@ DeviceInfo BlueDevilDaemon::deviceToInfo(const Device* device) const
info
[
"discovered"
]
=
"true"
;
return
info
;
}
\ No newline at end of file
}
src/daemon/kded/BlueDevilDaemon.h
View file @
8d771c35
...
...
@@ -29,6 +29,7 @@
typedef
QMap
<
QString
,
QString
>
DeviceInfo
;
typedef
QMap
<
QString
,
DeviceInfo
>
QMapDeviceInfo
;
class
QDBusPendingCallWatcher
;
namespace
BlueDevil
{
class
Adapter
;
class
Device
;
...
...
@@ -87,12 +88,16 @@ private Q_SLOTS:
void
agentReleased
();
void
deviceFound
(
Device
*
);
void
monolithicQuit
(
QDBusPendingCallWatcher
*
watcher
);
void
monolithicFinished
(
const
QString
&
);
private:
/**
* Tries to start the helper process via dbus and returns true if successful
*/
bool
isServiceStarted
();
void
executeMonolithic
();
void
killMonolithic
();
DeviceInfo
deviceToInfo
(
const
Device
*
device
)
const
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment