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
6c81fa1e
Commit
6c81fa1e
authored
Jun 03, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
neighbor/udisks: move code to ForEachInterface()
parent
24874b82
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
18 deletions
+43
-18
ObjectManager.hxx
src/lib/dbus/ObjectManager.hxx
+30
-0
UdisksNeighborPlugin.cxx
src/neighbor/plugins/UdisksNeighborPlugin.cxx
+13
-18
No files found.
src/lib/dbus/ObjectManager.hxx
View file @
6c81fa1e
...
...
@@ -20,6 +20,8 @@
#ifndef ODBUS_OBJECT_MANAGER_HXX
#define ODBUS_OBJECT_MANAGER_HXX
#include "ReadIter.hxx"
#include <dbus/dbus.h>
#define DBUS_OM_INTERFACE "org.freedesktop.DBus.ObjectManager"
...
...
@@ -47,4 +49,32 @@
DBUS_TYPE_ARRAY_AS_STRING \
DBUS_TYPE_STRING_AS_STRING
namespace
ODBus
{
template
<
typename
F
>
inline
void
RecurseInterfaceDictEntry
(
ReadMessageIter
&&
i
,
F
&&
f
)
{
if
(
i
.
GetArgType
()
!=
DBUS_TYPE_OBJECT_PATH
)
return
;
const
char
*
path
=
i
.
GetString
();
i
.
Next
();
if
(
i
.
GetArgType
()
!=
DBUS_TYPE_ARRAY
)
return
;
f
(
path
,
i
.
Recurse
());
}
template
<
typename
F
>
inline
void
ForEachInterface
(
ReadMessageIter
&&
i
,
F
&&
f
)
{
i
.
ForEach
(
DBUS_TYPE_DICT_ENTRY
,
[
&
f
](
auto
&&
j
){
RecurseInterfaceDictEntry
(
j
.
Recurse
(),
f
);
});
}
}
#endif
src/neighbor/plugins/UdisksNeighborPlugin.cxx
View file @
6c81fa1e
...
...
@@ -47,12 +47,15 @@
static
constexpr
Domain
udisks_domain
(
"udisks"
);
struct
UdisksObject
{
std
::
string
path
;
const
std
::
string
path
;
std
::
string
drive_id
,
block_id
;
bool
is_filesystem
=
false
;
explicit
UdisksObject
(
const
char
*
_path
)
noexcept
:
path
(
_path
)
{}
bool
IsValid
()
const
noexcept
{
return
!
drive_id
.
empty
()
||
!
block_id
.
empty
();
}
...
...
@@ -275,17 +278,7 @@ ParseInterfaceDictEntry(UdisksObject &o, ODBus::ReadMessageIter &&i) noexcept
static
bool
ParseObject
(
UdisksObject
&
o
,
ODBus
::
ReadMessageIter
&&
i
)
noexcept
{
if
(
i
.
GetArgType
()
!=
DBUS_TYPE_OBJECT_PATH
)
return
false
;
o
.
path
=
i
.
GetString
();
i
.
Next
();
if
(
i
.
GetArgType
()
!=
DBUS_TYPE_ARRAY
)
return
false
;
i
.
Recurse
().
ForEach
(
DBUS_TYPE_DICT_ENTRY
,
[
&
o
](
auto
&&
j
){
i
.
ForEach
(
DBUS_TYPE_DICT_ENTRY
,
[
&
o
](
auto
&&
j
){
ParseInterfaceDictEntry
(
o
,
j
.
Recurse
());
});
...
...
@@ -365,9 +358,9 @@ UdisksNeighborExplorer::OnListNotify(DBusPendingCall *pending) noexcept
return
;
}
i
.
Recurse
().
ForEach
(
DBUS_TYPE_DICT_ENTRY
,
[
this
](
auto
&&
j
){
UdisksObject
o
;
if
(
ParseObject
(
o
,
j
.
Recurse
(
))
&&
o
.
IsValid
())
ForEachInterface
(
i
.
Recurse
(),
[
this
](
const
char
*
path
,
auto
&&
j
){
UdisksObject
o
(
path
)
;
if
(
ParseObject
(
o
,
std
::
move
(
j
))
&&
o
.
IsValid
())
Insert
(
std
::
move
(
o
));
});
}
...
...
@@ -380,9 +373,11 @@ UdisksNeighborExplorer::HandleMessage(DBusConnection *, DBusMessage *message) no
if
(
dbus_message_is_signal
(
message
,
DBUS_OM_INTERFACE
,
"InterfacesAdded"
)
&&
dbus_message_has_signature
(
message
,
DBUS_OM_INTERFACES_ADDED_SIGNATURE
))
{
UdisksObject
o
;
if
(
ParseObject
(
o
,
ReadMessageIter
(
*
message
))
&&
o
.
IsValid
())
Insert
(
std
::
move
(
o
));
RecurseInterfaceDictEntry
(
ReadMessageIter
(
*
message
),
[
this
](
const
char
*
path
,
auto
&&
i
){
UdisksObject
o
(
path
);
if
(
ParseObject
(
o
,
std
::
move
(
i
))
&&
o
.
IsValid
())
Insert
(
std
::
move
(
o
));
});
return
DBUS_HANDLER_RESULT_HANDLED
;
}
else
if
(
dbus_message_is_signal
(
message
,
DBUS_OM_INTERFACE
,
...
...
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