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
e560f6bc
Commit
e560f6bc
authored
Jun 03, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/dbus/ReadIter: add ForEachProperty()
parent
fbfbc568
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
31 deletions
+33
-31
ReadIter.hxx
src/lib/dbus/ReadIter.hxx
+22
-0
UdisksNeighborPlugin.cxx
src/neighbor/plugins/UdisksNeighborPlugin.cxx
+11
-31
No files found.
src/lib/dbus/ReadIter.hxx
View file @
e560f6bc
...
...
@@ -102,6 +102,28 @@ public:
f
(
i
.
Recurse
());
});
}
/**
* Invoke a function for each name/value pair (string/variant)
* in a dictionary (array containing #DBUS_TYPE_DICT_ENTRY).
* The function gets two parameters: the property name (as C
* string) and the variant value (as #ReadMessageIter).
*/
template
<
typename
F
>
void
ForEachProperty
(
F
&&
f
)
{
ForEachRecurse
(
DBUS_TYPE_DICT_ENTRY
,
[
&
f
](
auto
&&
i
){
if
(
i
.
GetArgType
()
!=
DBUS_TYPE_STRING
)
return
;
const
char
*
name
=
i
.
GetString
();
i
.
Next
();
if
(
i
.
GetArgType
()
!=
DBUS_TYPE_VARIANT
)
return
;
f
(
name
,
i
.
Recurse
());
});
}
};
}
/* namespace ODBus */
...
...
src/neighbor/plugins/UdisksNeighborPlugin.cxx
View file @
e560f6bc
...
...
@@ -202,44 +202,23 @@ CheckString(I &&i) noexcept
return
i
.
GetString
();
}
template
<
typename
I
>
gcc_pure
static
const
char
*
CheckVariantString
(
I
&&
i
)
noexcept
{
if
(
i
.
GetArgType
()
!=
DBUS_TYPE_VARIANT
)
return
nullptr
;
return
CheckString
(
i
.
Recurse
());
}
static
void
ParseDriveDictEntry
(
UdisksObject
&
o
,
ODBus
::
ReadMessageIter
&&
i
)
noexcept
ParseDriveDictEntry
(
UdisksObject
&
o
,
const
char
*
name
,
ODBus
::
ReadMessageIter
&&
value_i
)
noexcept
{
if
(
i
.
GetArgType
()
!=
DBUS_TYPE_STRING
)
return
;
const
char
*
name
=
i
.
GetString
();
i
.
Next
();
if
(
StringIsEqual
(
name
,
"Id"
))
{
const
char
*
value
=
Check
VariantString
(
i
);
const
char
*
value
=
Check
String
(
value_
i
);
if
(
value
!=
nullptr
&&
o
.
drive_id
.
empty
())
o
.
drive_id
=
value
;
}
}
static
void
ParseBlockDictEntry
(
UdisksObject
&
o
,
ODBus
::
ReadMessageIter
&&
i
)
noexcept
ParseBlockDictEntry
(
UdisksObject
&
o
,
const
char
*
name
,
ODBus
::
ReadMessageIter
&&
value_i
)
noexcept
{
if
(
i
.
GetArgType
()
!=
DBUS_TYPE_STRING
)
return
;
const
char
*
name
=
i
.
GetString
();
i
.
Next
();
if
(
StringIsEqual
(
name
,
"Id"
))
{
const
char
*
value
=
Check
VariantString
(
i
);
const
char
*
value
=
Check
String
(
value_
i
);
if
(
value
!=
nullptr
&&
o
.
block_id
.
empty
())
o
.
block_id
=
value
;
}
...
...
@@ -249,12 +228,13 @@ static void
ParseInterface
(
UdisksObject
&
o
,
const
char
*
interface
,
ODBus
::
ReadMessageIter
&&
i
)
noexcept
{
using
namespace
std
::
placeholders
;
if
(
StringIsEqual
(
interface
,
"org.freedesktop.UDisks2.Drive"
))
{
for
(;
i
.
GetArgType
()
==
DBUS_TYPE_DICT_ENTRY
;
i
.
Next
())
ParseDriveDictEntry
(
o
,
i
.
Recurse
(
));
i
.
ForEachProperty
(
std
::
bind
(
ParseDriveDictEntry
,
std
::
ref
(
o
),
_1
,
_2
));
}
else
if
(
StringIsEqual
(
interface
,
"org.freedesktop.UDisks2.Block"
))
{
for
(;
i
.
GetArgType
()
==
DBUS_TYPE_DICT_ENTRY
;
i
.
Next
())
ParseBlockDictEntry
(
o
,
i
.
Recurse
(
));
i
.
ForEachProperty
(
std
::
bind
(
ParseBlockDictEntry
,
std
::
ref
(
o
),
_1
,
_2
));
}
else
if
(
StringIsEqual
(
interface
,
"org.freedesktop.UDisks2.Filesystem"
))
{
o
.
is_filesystem
=
true
;
}
...
...
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