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
7d696a70
Commit
7d696a70
authored
Jan 18, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp/Discovery: eliminate Error attribute
Move code to method Start() and add Error& parameters to several methods.
parent
53573e95
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
51 deletions
+32
-51
UpnpDatabasePlugin.cxx
src/db/UpnpDatabasePlugin.cxx
+4
-21
Discovery.cxx
src/db/upnp/Discovery.cxx
+21
-14
Discovery.hxx
src/db/upnp/Discovery.hxx
+7
-16
No files found.
src/db/UpnpDatabasePlugin.cxx
View file @
7d696a70
...
...
@@ -165,8 +165,7 @@ UpnpDatabase::Open(Error &error)
}
m_superdir
=
new
UPnPDeviceDirectory
(
m_lib
);
if
(
!
m_superdir
->
ok
())
{
error
.
Set
(
m_superdir
->
GetError
());
if
(
!
m_superdir
->
Start
(
error
))
{
delete
m_superdir
;
delete
m_lib
;
return
false
;
...
...
@@ -215,20 +214,12 @@ upnpItemToSong(const UPnPDirObject &dirent, const char *uri)
Song
*
UpnpDatabase
::
GetSong
(
const
char
*
uri
,
Error
&
error
)
const
{
if
(
!
m_superdir
->
ok
())
{
error
.
Set
(
upnp_domain
,
"UpnpDatabase::GetSong() superdir is sick"
);
return
nullptr
;
}
Song
*
song
=
nullptr
;
auto
vpath
=
stringToTokens
(
uri
,
"/"
,
true
);
if
(
vpath
.
size
()
>=
2
)
{
ContentDirectoryService
server
;
if
(
!
m_superdir
->
getServer
(
vpath
[
0
].
c_str
(),
server
))
{
error
.
Set
(
upnp_domain
,
"server not found"
);
if
(
!
m_superdir
->
getServer
(
vpath
[
0
].
c_str
(),
server
,
error
))
return
nullptr
;
}
vpath
.
erase
(
vpath
.
begin
());
UPnPDirObject
dirent
;
...
...
@@ -688,12 +679,8 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
Error
&
error
)
const
{
std
::
vector
<
ContentDirectoryService
>
servers
;
if
(
!
m_superdir
->
ok
()
||
!
m_superdir
->
getDirServices
(
servers
))
{
error
.
Set
(
upnp_domain
,
"UpnpDatabase::Visit() superdir is sick"
);
if
(
!
m_superdir
->
getDirServices
(
servers
,
error
))
return
false
;
}
auto
vpath
=
stringToTokens
(
selection
.
uri
,
"/"
,
true
);
if
(
vpath
.
empty
())
{
...
...
@@ -748,12 +735,8 @@ UpnpDatabase::VisitUniqueTags(const DatabaseSelection &selection,
return
true
;
std
::
vector
<
ContentDirectoryService
>
servers
;
if
(
!
m_superdir
->
ok
()
||
!
m_superdir
->
getDirServices
(
servers
))
{
error
.
Set
(
upnp_domain
,
"UpnpDatabase::Visit() superdir is sick"
);
if
(
!
m_superdir
->
getDirServices
(
servers
,
error
))
return
false
;
}
std
::
set
<
std
::
string
>
values
;
for
(
auto
&
server
:
servers
)
{
...
...
src/db/upnp/Discovery.cxx
View file @
7d696a70
...
...
@@ -160,8 +160,8 @@ UPnPDeviceDirectory::cluCallBack(Upnp_EventType et, void *evp)
return
UPNP_E_SUCCESS
;
}
void
UPnPDeviceDirectory
::
expireDevices
()
bool
UPnPDeviceDirectory
::
expireDevices
(
Error
&
error
)
{
const
ScopeLock
protect
(
mutex
);
time_t
now
=
time
(
0
);
...
...
@@ -178,7 +178,9 @@ UPnPDeviceDirectory::expireDevices()
}
if
(
didsomething
)
search
();
return
search
(
error
);
return
true
;
}
UPnPDeviceDirectory
::
UPnPDeviceDirectory
(
LibUPnP
*
_lib
)
...
...
@@ -186,20 +188,25 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(LibUPnP *_lib)
discoveredQueue
(
"DiscoveredQueue"
),
m_searchTimeout
(
2
),
m_lastSearch
(
0
)
{
}
bool
UPnPDeviceDirectory
::
Start
(
Error
&
error
)
{
if
(
!
discoveredQueue
.
start
(
1
,
discoExplorer
,
this
))
{
error
.
Set
(
upnp_domain
,
"Discover work queue start failed"
);
return
;
return
false
;
}
lib
->
SetHandler
([
this
](
Upnp_EventType
type
,
void
*
event
){
cluCallBack
(
type
,
event
);
});
search
(
);
return
search
(
error
);
}
bool
UPnPDeviceDirectory
::
search
()
UPnPDeviceDirectory
::
search
(
Error
&
error
)
{
time_t
now
=
time
(
0
);
if
(
now
-
m_lastSearch
<
10
)
...
...
@@ -229,13 +236,12 @@ UPnPDeviceDirectory::search()
}
bool
UPnPDeviceDirectory
::
getDirServices
(
std
::
vector
<
ContentDirectoryService
>
&
out
)
UPnPDeviceDirectory
::
getDirServices
(
std
::
vector
<
ContentDirectoryService
>
&
out
,
Error
&
error
)
{
if
(
!
ok
())
return
false
;
// Has locking, do it before our own lock
expireDevices
();
if
(
!
expireDevices
(
error
))
return
false
;
const
ScopeLock
protect
(
mutex
);
...
...
@@ -253,12 +259,12 @@ UPnPDeviceDirectory::getDirServices(std::vector<ContentDirectoryService> &out)
bool
UPnPDeviceDirectory
::
getServer
(
const
char
*
friendlyName
,
ContentDirectoryService
&
server
)
ContentDirectoryService
&
server
,
Error
&
error
)
{
std
::
vector
<
ContentDirectoryService
>
ds
;
if
(
!
getDirServices
(
ds
))
{
if
(
!
getDirServices
(
ds
,
error
))
return
false
;
}
for
(
const
auto
&
i
:
ds
)
{
if
(
strcmp
(
friendlyName
,
i
.
getFriendlyName
())
==
0
)
{
...
...
@@ -267,5 +273,6 @@ UPnPDeviceDirectory::getServer(const char *friendlyName,
}
}
error
.
Set
(
upnp_domain
,
"Server not found"
);
return
false
;
}
src/db/upnp/Discovery.hxx
View file @
7d696a70
...
...
@@ -82,8 +82,6 @@ class UPnPDeviceDirectory {
LibUPnP
*
const
lib
;
Error
error
;
Mutex
mutex
;
std
::
map
<
std
::
string
,
ContentDirectoryDescriptor
>
directories
;
WorkQueue
<
DiscoveredTask
*>
discoveredQueue
;
...
...
@@ -103,8 +101,10 @@ public:
UPnPDeviceDirectory
(
const
UPnPDeviceDirectory
&
)
=
delete
;
UPnPDeviceDirectory
&
operator
=
(
const
UPnPDeviceDirectory
&
)
=
delete
;
bool
Start
(
Error
&
error
);
/** Retrieve the directory services currently seen on the network */
bool
getDirServices
(
std
::
vector
<
ContentDirectoryService
>
&
);
bool
getDirServices
(
std
::
vector
<
ContentDirectoryService
>
&
,
Error
&
);
/**
* Get server by friendly name. It's a bit wasteful to copy
...
...
@@ -112,27 +112,18 @@ public:
* there isn't going to be millions...
*/
bool
getServer
(
const
char
*
friendlyName
,
ContentDirectoryService
&
server
);
/** My health */
bool
ok
()
const
{
return
!
error
.
IsDefined
();
}
/** My diagnostic if health is bad */
const
Error
&
GetError
()
const
{
return
error
;
}
ContentDirectoryService
&
server
,
Error
&
error
);
private
:
bool
search
();
bool
search
(
Error
&
error
);
/**
* Look at the devices and get rid of those which have not
* been seen for too long. We do this when listing the top
* directory.
*/
void
expireDevices
(
);
bool
expireDevices
(
Error
&
error
);
/**
* Worker routine for the discovery queue. Get messages about
...
...
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