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
640de551
Commit
640de551
authored
Jun 04, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
neighbor/udisks: move struct UdisksObject to UDisks2.hxx
parent
a92c694f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
38 deletions
+46
-38
UDisks2.hxx
src/lib/dbus/UDisks2.hxx
+31
-0
UdisksNeighborPlugin.cxx
src/neighbor/plugins/UdisksNeighborPlugin.cxx
+15
-38
No files found.
src/lib/dbus/UDisks2.hxx
View file @
640de551
...
...
@@ -20,7 +20,38 @@
#ifndef UDISKS2_HXX
#define UDISKS2_HXX
#include <string>
#define UDISKS2_PATH "/org/freedesktop/UDisks2"
#define UDISKS2_INTERFACE "org.freedesktop.UDisks2"
namespace
UDisks2
{
struct
Object
{
const
std
::
string
path
;
std
::
string
drive_id
,
block_id
;
bool
is_filesystem
=
false
;
explicit
Object
(
const
char
*
_path
)
noexcept
:
path
(
_path
)
{}
bool
IsValid
()
const
noexcept
{
return
is_filesystem
&&
(
!
drive_id
.
empty
()
||
!
block_id
.
empty
());
}
std
::
string
GetUri
()
const
noexcept
{
if
(
!
drive_id
.
empty
())
return
"udisks://"
+
drive_id
;
else
if
(
!
block_id
.
empty
())
return
"udisks://"
+
block_id
;
else
return
{};
}
};
}
// namespace UDisks2
#endif
src/neighbor/plugins/UdisksNeighborPlugin.cxx
View file @
640de551
...
...
@@ -46,34 +46,11 @@
static
constexpr
Domain
udisks_domain
(
"udisks"
);
struct
UdisksObject
{
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
is_filesystem
&&
(
!
drive_id
.
empty
()
||
!
block_id
.
empty
());
}
std
::
string
GetUri
()
const
noexcept
{
if
(
!
drive_id
.
empty
())
return
"udisks://"
+
drive_id
;
else
if
(
!
block_id
.
empty
())
return
"udisks://"
+
block_id
;
else
return
{};
}
NeighborInfo
ToNeighborInfo
()
const
noexcept
{
return
{
GetUri
(),
path
};
}
};
static
NeighborInfo
ToNeighborInfo
(
const
UDisks2
::
Object
&
o
)
noexcept
{
return
{
o
.
GetUri
(),
o
.
path
};
}
class
UdisksNeighborExplorer
final
:
public
NeighborExplorer
{
...
...
@@ -115,7 +92,7 @@ private:
void
DoOpen
();
void
DoClose
()
noexcept
;
void
Insert
(
U
disks
Object
&&
o
)
noexcept
;
void
Insert
(
U
Disks2
::
Object
&&
o
)
noexcept
;
void
Remove
(
const
std
::
string
&
path
)
noexcept
;
void
OnListNotify
(
ODBus
::
Message
reply
)
noexcept
;
...
...
@@ -199,7 +176,7 @@ CheckString(I &&i) noexcept
}
static
void
ParseDriveDictEntry
(
U
disks
Object
&
o
,
const
char
*
name
,
ParseDriveDictEntry
(
U
Disks2
::
Object
&
o
,
const
char
*
name
,
ODBus
::
ReadMessageIter
&&
value_i
)
noexcept
{
if
(
StringIsEqual
(
name
,
"Id"
))
{
...
...
@@ -210,7 +187,7 @@ ParseDriveDictEntry(UdisksObject &o, const char *name,
}
static
void
ParseBlockDictEntry
(
U
disks
Object
&
o
,
const
char
*
name
,
ParseBlockDictEntry
(
U
Disks2
::
Object
&
o
,
const
char
*
name
,
ODBus
::
ReadMessageIter
&&
value_i
)
noexcept
{
if
(
StringIsEqual
(
name
,
"Id"
))
{
...
...
@@ -221,7 +198,7 @@ ParseBlockDictEntry(UdisksObject &o, const char *name,
}
static
void
ParseInterface
(
U
disks
Object
&
o
,
const
char
*
interface
,
ParseInterface
(
U
Disks2
::
Object
&
o
,
const
char
*
interface
,
ODBus
::
ReadMessageIter
&&
i
)
noexcept
{
using
namespace
std
::
placeholders
;
...
...
@@ -237,7 +214,7 @@ ParseInterface(UdisksObject &o, const char *interface,
}
static
void
ParseInterfaceDictEntry
(
U
disks
Object
&
o
,
ODBus
::
ReadMessageIter
&&
i
)
noexcept
ParseInterfaceDictEntry
(
U
Disks2
::
Object
&
o
,
ODBus
::
ReadMessageIter
&&
i
)
noexcept
{
if
(
i
.
GetArgType
()
!=
DBUS_TYPE_STRING
)
return
;
...
...
@@ -252,7 +229,7 @@ ParseInterfaceDictEntry(UdisksObject &o, ODBus::ReadMessageIter &&i) noexcept
}
static
bool
ParseObject
(
U
disks
Object
&
o
,
ODBus
::
ReadMessageIter
&&
i
)
noexcept
ParseObject
(
U
Disks2
::
Object
&
o
,
ODBus
::
ReadMessageIter
&&
i
)
noexcept
{
i
.
ForEach
(
DBUS_TYPE_DICT_ENTRY
,
[
&
o
](
auto
&&
j
){
ParseInterfaceDictEntry
(
o
,
j
.
Recurse
());
...
...
@@ -274,11 +251,11 @@ UdisksNeighborExplorer::GetList() const noexcept
}
void
UdisksNeighborExplorer
::
Insert
(
U
disks
Object
&&
o
)
noexcept
UdisksNeighborExplorer
::
Insert
(
U
Disks2
::
Object
&&
o
)
noexcept
{
assert
(
o
.
IsValid
());
const
NeighborInfo
info
=
o
.
ToNeighborInfo
(
);
const
NeighborInfo
info
=
ToNeighborInfo
(
o
);
{
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
...
...
@@ -330,7 +307,7 @@ UdisksNeighborExplorer::OnListNotify(ODBus::Message reply) noexcept
}
ForEachInterface
(
i
.
Recurse
(),
[
this
](
const
char
*
path
,
auto
&&
j
){
U
disks
Object
o
(
path
);
U
Disks2
::
Object
o
(
path
);
if
(
ParseObject
(
o
,
std
::
move
(
j
))
&&
o
.
IsValid
())
Insert
(
std
::
move
(
o
));
});
...
...
@@ -345,7 +322,7 @@ UdisksNeighborExplorer::HandleMessage(DBusConnection *, DBusMessage *message) no
"InterfacesAdded"
)
&&
dbus_message_has_signature
(
message
,
InterfacesAddedType
::
value
))
{
RecurseInterfaceDictEntry
(
ReadMessageIter
(
*
message
),
[
this
](
const
char
*
path
,
auto
&&
i
){
U
disks
Object
o
(
path
);
U
Disks2
::
Object
o
(
path
);
if
(
ParseObject
(
o
,
std
::
move
(
i
))
&&
o
.
IsValid
())
Insert
(
std
::
move
(
o
));
});
...
...
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