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
09b00fa4
Commit
09b00fa4
authored
Jan 10, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp/Object: use strictly-typed enums
At the same time, rename the enum types and the class attributes, and add an "UNKNOWN" type/class. The latter avoids the "-1" hack.
parent
74842fd6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
44 deletions
+74
-44
UpnpDatabasePlugin.cxx
src/db/UpnpDatabasePlugin.cxx
+53
-32
Directory.cxx
src/db/upnp/Directory.cxx
+6
-6
Object.hxx
src/db/upnp/Object.hxx
+15
-6
No files found.
src/db/UpnpDatabasePlugin.cxx
View file @
09b00fa4
...
...
@@ -721,18 +721,27 @@ UpnpDatabase::VisitServer(ContentDirectoryService* server,
return
SearchSongs
(
server
,
objid
.
c_str
(),
selection
,
visit_song
,
error
);
if
(
tdirent
.
m_type
==
UPnPDirObject
::
item
)
{
if
(
tdirent
.
type
==
UPnPDirObject
::
Type
::
ITEM
)
{
// Target is a song. Not too sure we ever get there actually, maybe
// this is always catched by the special uri test above.
if
(
visit_song
&&
tdirent
.
m_iclass
==
UPnPDirObject
::
audioItem_musicTrack
)
{
return
visitSong
(
tdirent
,
""
,
selection
,
visit_song
,
error
);
}
else
if
(
visit_playlist
&&
tdirent
.
m_iclass
==
UPnPDirObject
::
audioItem_playlist
)
{
// Note: I've yet to see a playlist item (playlists
// seem to be usually handled as containers, so I'll
// decide what to do when I see one...
switch
(
tdirent
.
item_class
)
{
case
UPnPDirObject
:
:
ItemClass
::
MUSIC
:
if
(
visit_song
)
return
visitSong
(
tdirent
,
""
,
selection
,
visit_song
,
error
);
break
;
case
UPnPDirObject
:
:
ItemClass
::
PLAYLIST
:
if
(
visit_playlist
)
{
/* Note: I've yet to see a playlist
item (playlists seem to be usually
handled as containers, so I'll decide
what to do when I see one... */
}
break
;
case
UPnPDirObject
:
:
ItemClass
::
UNKNOWN
:
break
;
}
return
true
;
...
...
@@ -757,28 +766,40 @@ UpnpDatabase::VisitServer(ContentDirectoryService* server,
if
(
visit_song
||
visit_playlist
)
{
for
(
const
auto
&
dirent
:
dirbuf
.
m_items
)
{
if
(
visit_song
&&
dirent
.
m_iclass
==
UPnPDirObject
::
audioItem_musicTrack
)
{
/* We identify songs by giving them a
special path. The Id is enough to
fetch them from the server
anyway. */
std
::
string
p
;
if
(
!
selection
.
recursive
)
p
=
selection
.
uri
+
"/"
+
titleToPathElt
(
dirent
.
m_title
);
if
(
!
visitSong
(
dirent
,
p
.
c_str
(),
selection
,
visit_song
,
error
))
return
false
;
}
else
if
(
visit_playlist
&&
dirent
.
m_iclass
==
UPnPDirObject
::
audioItem_playlist
)
{
/* Note: I've yet to see a playlist
item (playlists seem to be usually
handled as containers, so I'll
decide what to do when I see
one... */
switch
(
dirent
.
item_class
)
{
case
UPnPDirObject
:
:
ItemClass
::
MUSIC
:
if
(
visit_song
)
{
/* We identify songs by giving
them a special path. The Id
is enough to fetch them
from the server anyway. */
std
::
string
p
;
if
(
!
selection
.
recursive
)
p
=
selection
.
uri
+
"/"
+
titleToPathElt
(
dirent
.
m_title
);
if
(
!
visitSong
(
dirent
,
p
.
c_str
(),
selection
,
visit_song
,
error
))
return
false
;
}
break
;
case
UPnPDirObject
:
:
ItemClass
::
PLAYLIST
:
if
(
visit_playlist
)
{
/* Note: I've yet to see a
playlist item (playlists
seem to be usually handled
as containers, so I'll
decide what to do when I
see one... */
}
break
;
case
UPnPDirObject
:
:
ItemClass
::
UNKNOWN
:
break
;
}
}
}
...
...
src/db/upnp/Directory.cxx
View file @
09b00fa4
...
...
@@ -56,9 +56,9 @@ public:
:
m_dir
(
dir
)
{
m_okitems
[
"object.item.audioItem.musicTrack"
]
=
UPnPDirObject
::
audioItem_musicTrack
;
UPnPDirObject
::
ItemClass
::
MUSIC
;
m_okitems
[
"object.item.playlistItem"
]
=
UPnPDirObject
::
audioItem_playlist
;
UPnPDirObject
::
ItemClass
::
PLAYLIST
;
}
UPnPDirContent
&
m_dir
;
...
...
@@ -74,7 +74,7 @@ protected:
case
'c'
:
if
(
!
strcmp
(
name
,
"container"
))
{
m_tobj
.
clear
();
m_tobj
.
m_type
=
UPnPDirObject
::
container
;
m_tobj
.
type
=
UPnPDirObject
::
Type
::
CONTAINER
;
m_tobj
.
m_id
=
m_path
.
back
().
attributes
[
"id"
];
m_tobj
.
m_pid
=
m_path
.
back
().
attributes
[
"parentID"
];
}
...
...
@@ -82,7 +82,7 @@ protected:
case
'i'
:
if
(
!
strcmp
(
name
,
"item"
))
{
m_tobj
.
clear
();
m_tobj
.
m_type
=
UPnPDirObject
::
item
;
m_tobj
.
type
=
UPnPDirObject
::
Type
::
ITEM
;
m_tobj
.
m_id
=
m_path
.
back
().
attributes
[
"id"
];
m_tobj
.
m_pid
=
m_path
.
back
().
attributes
[
"parentID"
];
}
...
...
@@ -96,14 +96,14 @@ protected:
bool
ok
=
!
m_tobj
.
m_id
.
empty
()
&&
!
m_tobj
.
m_pid
.
empty
()
&&
!
m_tobj
.
m_title
.
empty
();
if
(
ok
&&
m_tobj
.
m_type
==
UPnPDirObject
::
item
)
{
if
(
ok
&&
m_tobj
.
type
==
UPnPDirObject
::
Type
::
ITEM
)
{
auto
it
=
m_okitems
.
find
(
m_tobj
.
m_props
[
"upnp:class"
]);
if
(
it
==
m_okitems
.
end
())
{
PLOGINF
(
"checkobjok: found object of unknown class: [%s]
\n
"
,
m_tobj
.
m_props
[
"upnp:class"
].
c_str
());
ok
=
false
;
}
else
{
m_tobj
.
m_i
class
=
it
->
second
;
m_tobj
.
item_
class
=
it
->
second
;
}
}
...
...
src/db/upnp/Object.hxx
View file @
09b00fa4
...
...
@@ -30,7 +30,12 @@
*/
class
UPnPDirObject
{
public
:
enum
ObjType
{
item
,
container
};
enum
class
Type
{
UNKNOWN
,
ITEM
,
CONTAINER
,
};
// There are actually several kinds of containers:
// object.container.storageFolder, object.container.person,
// object.container.playlistContainer etc., but they all seem to
...
...
@@ -38,13 +43,17 @@ public:
// items are special to us, and so should playlists, but I've not
// seen one of the latter yet (servers seem to use containers for
// playlists).
enum
ItemClass
{
audioItem_musicTrack
,
audioItem_playlist
};
enum
class
ItemClass
{
UNKNOWN
,
MUSIC
,
PLAYLIST
,
};
std
::
string
m_id
;
// ObjectId
std
::
string
m_pid
;
// Parent ObjectId
std
::
string
m_title
;
// dc:title. Directory name for a container.
ObjType
m_type
;
// item or container
ItemClass
m_i
class
;
Type
type
;
ItemClass
item_
class
;
// Properties as gathered from the XML document (url, artist, etc.)
// The map keys are the XML tag or attribute names.
std
::
map
<
std
::
string
,
std
::
string
>
m_props
;
...
...
@@ -68,8 +77,8 @@ public:
m_id
.
clear
();
m_pid
.
clear
();
m_title
.
clear
();
m_type
=
(
ObjType
)
-
1
;
m_iclass
=
(
ItemClass
)
-
1
;
type
=
Type
::
UNKNOWN
;
item_class
=
ItemClass
::
UNKNOWN
;
m_props
.
clear
();
}
};
...
...
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