Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
f3ffdaf2
Commit
f3ffdaf2
authored
Jun 03, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/dbus/Glue: singleton for global initialization
parent
3aade670
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
126 additions
and
22 deletions
+126
-22
Makefile.am
Makefile.am
+1
-0
Glue.cxx
src/lib/dbus/Glue.cxx
+45
-0
Glue.hxx
src/lib/dbus/Glue.hxx
+63
-0
UdisksNeighborPlugin.cxx
src/neighbor/plugins/UdisksNeighborPlugin.cxx
+17
-22
No files found.
Makefile.am
View file @
f3ffdaf2
...
...
@@ -293,6 +293,7 @@ libodbus_a_SOURCES = \
src/lib/dbus/ScopeMatch.cxx src/lib/dbus/ScopeMatch.hxx
\
src/lib/dbus/Types.hxx
\
src/lib/dbus/Values.hxx
\
src/lib/dbus/Glue.cxx src/lib/dbus/Glue.hxx
\
src/lib/dbus/Watch.cxx src/lib/dbus/Watch.hxx
libodbus_a_CPPFLAGS
=
$(AM_CPPFLAGS)
$(DBUS_CFLAGS)
endif
...
...
src/lib/dbus/Glue.cxx
0 → 100644
View file @
f3ffdaf2
/*
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "Glue.hxx"
namespace
ODBus
{
void
Glue
::
Connect
()
{
watch
.
SetConnection
(
Connection
::
GetSystem
());
dbus_connection_set_exit_on_disconnect
(
GetConnection
(),
false
);
}
void
Glue
::
Disconnect
()
{
watch
.
SetConnection
(
Connection
());
}
void
Glue
::
OnDBusClosed
()
noexcept
{
// TODO: reconnect
}
}
src/lib/dbus/Glue.hxx
0 → 100644
View file @
f3ffdaf2
/*
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_DBUS_GLUE_HXX
#define MPD_DBUS_GLUE_HXX
#include "Watch.hxx"
class
EventLoop
;
namespace
ODBus
{
/**
* A class which manages the D-Bus client connection.
*/
class
Glue
final
:
ODBus
::
WatchManagerObserver
{
WatchManager
watch
;
public
:
explicit
Glue
(
EventLoop
&
event_loop
)
:
watch
(
event_loop
,
*
this
)
{
Connect
();
}
~
Glue
()
noexcept
{
Disconnect
();
}
EventLoop
&
GetEventLoop
()
noexcept
{
return
watch
.
GetEventLoop
();
}
Connection
&
GetConnection
()
noexcept
{
return
watch
.
GetConnection
();
}
private
:
void
Connect
();
void
Disconnect
();
/* virtual methods from class ODBus::WatchManagerObserver */
void
OnDBusClosed
()
noexcept
override
;
};
}
#endif
src/neighbor/plugins/UdisksNeighborPlugin.cxx
View file @
f3ffdaf2
...
...
@@ -21,7 +21,7 @@
#include "UdisksNeighborPlugin.hxx"
#include "lib/dbus/Connection.hxx"
#include "lib/dbus/Error.hxx"
#include "lib/dbus/
Watch
.hxx"
#include "lib/dbus/
Glue
.hxx"
#include "lib/dbus/Message.hxx"
#include "lib/dbus/PendingCall.hxx"
#include "lib/dbus/ReadIter.hxx"
...
...
@@ -34,6 +34,7 @@
#include "thread/Mutex.hxx"
#include "util/Domain.hxx"
#include "util/StringAPI.hxx"
#include "util/Manual.hxx"
#include "Log.hxx"
#include <stdexcept>
...
...
@@ -69,9 +70,11 @@ struct UdisksObject {
};
class
UdisksNeighborExplorer
final
:
public
NeighborExplorer
,
ODBus
::
WatchManagerObserver
{
:
public
NeighborExplorer
{
ODBus
::
WatchManager
dbus_watch
;
EventLoop
&
event_loop
;
Manual
<
ODBus
::
Glue
>
dbus_glue
;
ODBus
::
PendingCall
pending_list_call
;
...
...
@@ -85,13 +88,16 @@ class UdisksNeighborExplorer final
std
::
map
<
std
::
string
,
ByUri
::
iterator
>
by_path
;
public
:
UdisksNeighborExplorer
(
EventLoop
&
event_loop
,
UdisksNeighborExplorer
(
EventLoop
&
_
event_loop
,
NeighborListener
&
_listener
)
noexcept
:
NeighborExplorer
(
_listener
),
dbus_watch
(
event_loop
,
*
this
)
{}
:
NeighborExplorer
(
_listener
),
event_loop
(
_event_loop
)
{}
auto
&
GetEventLoop
()
noexcept
{
return
dbus_watch
.
GetEventLoop
();
return
event_loop
;
}
auto
&&
GetConnection
()
noexcept
{
return
dbus_glue
->
GetConnection
();
}
/* virtual methods from class NeighborExplorer */
...
...
@@ -100,10 +106,6 @@ public:
List
GetList
()
const
noexcept
override
;
private
:
/* virtual methods from class ODBus::WatchManagerObserver */
void
OnDBusClosed
()
noexcept
override
;
private
:
void
Insert
(
UdisksObject
&&
o
)
noexcept
;
void
Remove
(
const
std
::
string
&
path
)
noexcept
;
...
...
@@ -127,10 +129,9 @@ UdisksNeighborExplorer::Open()
{
using
namespace
ODBus
;
dbus_
watch
.
SetConnection
(
Connection
::
GetSystem
()
);
dbus_
glue
.
Construct
(
event_loop
);
auto
&
connection
=
dbus_watch
.
GetConnection
();
dbus_connection_set_exit_on_disconnect
(
connection
,
false
);
auto
&
connection
=
GetConnection
();
try
{
Error
error
;
...
...
@@ -152,7 +153,7 @@ UdisksNeighborExplorer::Open()
pending_list_call
=
PendingCall
::
SendWithReply
(
connection
,
msg
.
Get
());
pending_list_call
.
SetNotify
(
OnListNotify
,
this
);
}
catch
(...)
{
dbus_
watch
.
SetConnection
(
Connection
()
);
dbus_
glue
.
Destruct
(
);
throw
;
}
}
...
...
@@ -169,7 +170,7 @@ UdisksNeighborExplorer::Close() noexcept
// TODO: remove_match
// TODO: remove_filter
dbus_
watch
.
SetConnection
(
Connection
()
);
dbus_
glue
.
Destruct
(
);
}
template
<
typename
I
>
...
...
@@ -289,12 +290,6 @@ UdisksNeighborExplorer::GetList() const noexcept
}
void
UdisksNeighborExplorer
::
OnDBusClosed
()
noexcept
{
// TODO: reconnect
}
void
UdisksNeighborExplorer
::
Insert
(
UdisksObject
&&
o
)
noexcept
{
assert
(
o
.
IsValid
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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