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
3d446d32
Commit
3d446d32
authored
Feb 02, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/upnp/Discovery: apply naming convention
parent
e660229c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
41 deletions
+41
-41
UpnpDatabasePlugin.cxx
src/db/plugins/upnp/UpnpDatabasePlugin.cxx
+4
-4
ContentDirectoryService.hxx
src/lib/upnp/ContentDirectoryService.hxx
+2
-1
Discovery.cxx
src/lib/upnp/Discovery.cxx
+23
-23
Discovery.hxx
src/lib/upnp/Discovery.hxx
+11
-12
UpnpNeighborPlugin.cxx
src/neighbor/plugins/UpnpNeighborPlugin.cxx
+1
-1
No files found.
src/db/plugins/upnp/UpnpDatabasePlugin.cxx
View file @
3d446d32
...
@@ -222,7 +222,7 @@ UpnpDatabase::GetSong(const char *uri, Error &error) const
...
@@ -222,7 +222,7 @@ UpnpDatabase::GetSong(const char *uri, Error &error) const
}
}
ContentDirectoryService
server
;
ContentDirectoryService
server
;
if
(
!
discovery
->
g
etServer
(
vpath
.
front
().
c_str
(),
server
,
error
))
if
(
!
discovery
->
G
etServer
(
vpath
.
front
().
c_str
(),
server
,
error
))
return
nullptr
;
return
nullptr
;
vpath
.
pop_front
();
vpath
.
pop_front
();
...
@@ -689,7 +689,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
...
@@ -689,7 +689,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
auto
vpath
=
stringToTokens
(
selection
.
uri
,
"/"
,
true
);
auto
vpath
=
stringToTokens
(
selection
.
uri
,
"/"
,
true
);
if
(
vpath
.
empty
())
{
if
(
vpath
.
empty
())
{
std
::
vector
<
ContentDirectoryService
>
servers
;
std
::
vector
<
ContentDirectoryService
>
servers
;
if
(
!
discovery
->
getDirServic
es
(
servers
,
error
))
if
(
!
discovery
->
GetDirectori
es
(
servers
,
error
))
return
false
;
return
false
;
for
(
const
auto
&
server
:
servers
)
{
for
(
const
auto
&
server
:
servers
)
{
...
@@ -714,7 +714,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
...
@@ -714,7 +714,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
vpath
.
pop_front
();
vpath
.
pop_front
();
ContentDirectoryService
server
;
ContentDirectoryService
server
;
if
(
!
discovery
->
g
etServer
(
servername
.
c_str
(),
server
,
error
))
if
(
!
discovery
->
G
etServer
(
servername
.
c_str
(),
server
,
error
))
return
false
;
return
false
;
return
VisitServer
(
server
,
vpath
,
selection
,
return
VisitServer
(
server
,
vpath
,
selection
,
...
@@ -733,7 +733,7 @@ UpnpDatabase::VisitUniqueTags(const DatabaseSelection &selection,
...
@@ -733,7 +733,7 @@ UpnpDatabase::VisitUniqueTags(const DatabaseSelection &selection,
return
true
;
return
true
;
std
::
vector
<
ContentDirectoryService
>
servers
;
std
::
vector
<
ContentDirectoryService
>
servers
;
if
(
!
discovery
->
getDirServic
es
(
servers
,
error
))
if
(
!
discovery
->
GetDirectori
es
(
servers
,
error
))
return
false
;
return
false
;
std
::
set
<
std
::
string
>
values
;
std
::
set
<
std
::
string
>
values
;
...
...
src/lib/upnp/ContentDirectoryService.hxx
View file @
3d446d32
...
@@ -62,7 +62,8 @@ public:
...
@@ -62,7 +62,8 @@ public:
/**
/**
* Construct by copying data from device and service objects.
* Construct by copying data from device and service objects.
*
*
* The discovery service does this: use getDirServices()
* The discovery service does this: use
* UPnPDeviceDirectory::GetDirectories()
*/
*/
ContentDirectoryService
(
const
UPnPDevice
&
device
,
ContentDirectoryService
(
const
UPnPDevice
&
device
,
const
UPnPService
&
service
);
const
UPnPService
&
service
);
...
...
src/lib/upnp/Discovery.cxx
View file @
3d446d32
...
@@ -107,12 +107,12 @@ UPnPDeviceDirectory::LockRemove(const std::string &id)
...
@@ -107,12 +107,12 @@ UPnPDeviceDirectory::LockRemove(const std::string &id)
}
}
inline
void
inline
void
UPnPDeviceDirectory
::
discoExplorer
()
UPnPDeviceDirectory
::
Explore
()
{
{
for
(;;)
{
for
(;;)
{
DiscoveredTask
*
tsk
=
0
;
DiscoveredTask
*
tsk
=
0
;
if
(
!
discoveredQ
ueue
.
take
(
tsk
))
{
if
(
!
q
ueue
.
take
(
tsk
))
{
discoveredQ
ueue
.
workerExit
();
q
ueue
.
workerExit
();
return
;
return
;
}
}
...
@@ -128,7 +128,7 @@ UPnPDeviceDirectory::discoExplorer()
...
@@ -128,7 +128,7 @@ UPnPDeviceDirectory::discoExplorer()
}
}
// Update or insert the device
// Update or insert the device
ContentDirectoryDescriptor
d
(
std
::
move
(
tsk
->
device
I
d
),
ContentDirectoryDescriptor
d
(
std
::
move
(
tsk
->
device
_i
d
),
MonotonicClockS
(),
tsk
->
expires
);
MonotonicClockS
(),
tsk
->
expires
);
{
{
...
@@ -148,10 +148,10 @@ UPnPDeviceDirectory::discoExplorer()
...
@@ -148,10 +148,10 @@ UPnPDeviceDirectory::discoExplorer()
}
}
void
*
void
*
UPnPDeviceDirectory
::
discoExplorer
(
void
*
ctx
)
UPnPDeviceDirectory
::
Explore
(
void
*
ctx
)
{
{
UPnPDeviceDirectory
&
directory
=
*
(
UPnPDeviceDirectory
*
)
ctx
;
UPnPDeviceDirectory
&
directory
=
*
(
UPnPDeviceDirectory
*
)
ctx
;
directory
.
discoExplorer
();
directory
.
Explore
();
return
(
void
*
)
1
;
return
(
void
*
)
1
;
}
}
...
@@ -161,7 +161,7 @@ UPnPDeviceDirectory::OnAlive(Upnp_Discovery *disco)
...
@@ -161,7 +161,7 @@ UPnPDeviceDirectory::OnAlive(Upnp_Discovery *disco)
if
(
isMSDevice
(
disco
->
DeviceType
)
||
if
(
isMSDevice
(
disco
->
DeviceType
)
||
isCDService
(
disco
->
ServiceType
))
{
isCDService
(
disco
->
ServiceType
))
{
DiscoveredTask
*
tp
=
new
DiscoveredTask
(
disco
);
DiscoveredTask
*
tp
=
new
DiscoveredTask
(
disco
);
if
(
discoveredQ
ueue
.
put
(
tp
))
if
(
q
ueue
.
put
(
tp
))
return
UPNP_E_FINISH
;
return
UPNP_E_FINISH
;
}
}
...
@@ -210,7 +210,7 @@ UPnPDeviceDirectory::Invoke(Upnp_EventType et, void *evp)
...
@@ -210,7 +210,7 @@ UPnPDeviceDirectory::Invoke(Upnp_EventType et, void *evp)
}
}
bool
bool
UPnPDeviceDirectory
::
e
xpireDevices
(
Error
&
error
)
UPnPDeviceDirectory
::
E
xpireDevices
(
Error
&
error
)
{
{
const
ScopeLock
protect
(
mutex
);
const
ScopeLock
protect
(
mutex
);
const
unsigned
now
=
MonotonicClockS
();
const
unsigned
now
=
MonotonicClockS
();
...
@@ -227,7 +227,7 @@ UPnPDeviceDirectory::expireDevices(Error &error)
...
@@ -227,7 +227,7 @@ UPnPDeviceDirectory::expireDevices(Error &error)
}
}
if
(
didsomething
)
if
(
didsomething
)
return
s
earch
(
error
);
return
S
earch
(
error
);
return
true
;
return
true
;
}
}
...
@@ -236,8 +236,8 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(UpnpClient_Handle _handle,
...
@@ -236,8 +236,8 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(UpnpClient_Handle _handle,
UPnPDiscoveryListener
*
_listener
)
UPnPDiscoveryListener
*
_listener
)
:
handle
(
_handle
),
:
handle
(
_handle
),
listener
(
_listener
),
listener
(
_listener
),
discoveredQ
ueue
(
"DiscoveredQueue"
),
q
ueue
(
"DiscoveredQueue"
),
m_searchTimeout
(
2
),
m_lastS
earch
(
0
)
search_timeout
(
2
),
last_s
earch
(
0
)
{
{
}
}
...
@@ -249,24 +249,24 @@ UPnPDeviceDirectory::~UPnPDeviceDirectory()
...
@@ -249,24 +249,24 @@ UPnPDeviceDirectory::~UPnPDeviceDirectory()
bool
bool
UPnPDeviceDirectory
::
Start
(
Error
&
error
)
UPnPDeviceDirectory
::
Start
(
Error
&
error
)
{
{
if
(
!
discoveredQueue
.
start
(
1
,
discoExplorer
,
this
))
{
if
(
!
queue
.
start
(
1
,
Explore
,
this
))
{
error
.
Set
(
upnp_domain
,
"Discover work queue start failed"
);
error
.
Set
(
upnp_domain
,
"Discover work queue start failed"
);
return
false
;
return
false
;
}
}
return
s
earch
(
error
);
return
S
earch
(
error
);
}
}
bool
bool
UPnPDeviceDirectory
::
s
earch
(
Error
&
error
)
UPnPDeviceDirectory
::
S
earch
(
Error
&
error
)
{
{
const
unsigned
now
=
MonotonicClockS
();
const
unsigned
now
=
MonotonicClockS
();
if
(
now
-
m_lastS
earch
<
10
)
if
(
now
-
last_s
earch
<
10
)
return
true
;
return
true
;
m_lastS
earch
=
now
;
last_s
earch
=
now
;
// We search both for device and service just in case.
// We search both for device and service just in case.
int
code
=
UpnpSearchAsync
(
handle
,
m_searchT
imeout
,
int
code
=
UpnpSearchAsync
(
handle
,
search_t
imeout
,
ContentDirectorySType
,
GetUpnpCookie
());
ContentDirectorySType
,
GetUpnpCookie
());
if
(
code
!=
UPNP_E_SUCCESS
)
{
if
(
code
!=
UPNP_E_SUCCESS
)
{
error
.
Format
(
upnp_domain
,
code
,
error
.
Format
(
upnp_domain
,
code
,
...
@@ -275,7 +275,7 @@ UPnPDeviceDirectory::search(Error &error)
...
@@ -275,7 +275,7 @@ UPnPDeviceDirectory::search(Error &error)
return
false
;
return
false
;
}
}
code
=
UpnpSearchAsync
(
handle
,
m_searchT
imeout
,
code
=
UpnpSearchAsync
(
handle
,
search_t
imeout
,
MediaServerDType
,
GetUpnpCookie
());
MediaServerDType
,
GetUpnpCookie
());
if
(
code
!=
UPNP_E_SUCCESS
)
{
if
(
code
!=
UPNP_E_SUCCESS
)
{
error
.
Format
(
upnp_domain
,
code
,
error
.
Format
(
upnp_domain
,
code
,
...
@@ -288,11 +288,11 @@ UPnPDeviceDirectory::search(Error &error)
...
@@ -288,11 +288,11 @@ UPnPDeviceDirectory::search(Error &error)
}
}
bool
bool
UPnPDeviceDirectory
::
getDirServic
es
(
std
::
vector
<
ContentDirectoryService
>
&
out
,
UPnPDeviceDirectory
::
GetDirectori
es
(
std
::
vector
<
ContentDirectoryService
>
&
out
,
Error
&
error
)
Error
&
error
)
{
{
// Has locking, do it before our own lock
// Has locking, do it before our own lock
if
(
!
e
xpireDevices
(
error
))
if
(
!
E
xpireDevices
(
error
))
return
false
;
return
false
;
const
ScopeLock
protect
(
mutex
);
const
ScopeLock
protect
(
mutex
);
...
@@ -310,12 +310,12 @@ UPnPDeviceDirectory::getDirServices(std::vector<ContentDirectoryService> &out,
...
@@ -310,12 +310,12 @@ UPnPDeviceDirectory::getDirServices(std::vector<ContentDirectoryService> &out,
}
}
bool
bool
UPnPDeviceDirectory
::
getServer
(
const
char
*
friendlyN
ame
,
UPnPDeviceDirectory
::
GetServer
(
const
char
*
friendly_n
ame
,
ContentDirectoryService
&
server
,
ContentDirectoryService
&
server
,
Error
&
error
)
Error
&
error
)
{
{
// Has locking, do it before our own lock
// Has locking, do it before our own lock
if
(
!
e
xpireDevices
(
error
))
if
(
!
E
xpireDevices
(
error
))
return
false
;
return
false
;
const
ScopeLock
protect
(
mutex
);
const
ScopeLock
protect
(
mutex
);
...
@@ -323,7 +323,7 @@ UPnPDeviceDirectory::getServer(const char *friendlyName,
...
@@ -323,7 +323,7 @@ UPnPDeviceDirectory::getServer(const char *friendlyName,
for
(
const
auto
&
i
:
directories
)
{
for
(
const
auto
&
i
:
directories
)
{
const
auto
&
device
=
i
.
device
;
const
auto
&
device
=
i
.
device
;
if
(
device
.
friendlyName
!=
friendly
N
ame
)
if
(
device
.
friendlyName
!=
friendly
_n
ame
)
continue
;
continue
;
for
(
const
auto
&
service
:
device
.
services
)
{
for
(
const
auto
&
service
:
device
.
services
)
{
...
...
src/lib/upnp/Discovery.hxx
View file @
3d446d32
...
@@ -55,12 +55,12 @@ class UPnPDeviceDirectory final : UpnpCallback {
...
@@ -55,12 +55,12 @@ class UPnPDeviceDirectory final : UpnpCallback {
*/
*/
struct
DiscoveredTask
{
struct
DiscoveredTask
{
std
::
string
url
;
std
::
string
url
;
std
::
string
device
I
d
;
std
::
string
device
_i
d
;
unsigned
expires
;
// Seconds valid
unsigned
expires
;
// Seconds valid
DiscoveredTask
(
const
Upnp_Discovery
*
disco
)
DiscoveredTask
(
const
Upnp_Discovery
*
disco
)
:
url
(
disco
->
Location
),
:
url
(
disco
->
Location
),
deviceI
d
(
disco
->
DeviceId
),
device_i
d
(
disco
->
DeviceId
),
expires
(
disco
->
Expires
)
{}
expires
(
disco
->
Expires
)
{}
};
};
...
@@ -97,19 +97,19 @@ class UPnPDeviceDirectory final : UpnpCallback {
...
@@ -97,19 +97,19 @@ class UPnPDeviceDirectory final : UpnpCallback {
Mutex
mutex
;
Mutex
mutex
;
std
::
list
<
ContentDirectoryDescriptor
>
directories
;
std
::
list
<
ContentDirectoryDescriptor
>
directories
;
WorkQueue
<
DiscoveredTask
*>
discoveredQ
ueue
;
WorkQueue
<
DiscoveredTask
*>
q
ueue
;
/**
/**
* The UPnP device search timeout, which should actually be
* The UPnP device search timeout, which should actually be
* called delay because it's the base of a random delay that
* called delay because it's the base of a random delay that
* the devices apply to avoid responding all at the same time.
* the devices apply to avoid responding all at the same time.
*/
*/
int
m_searchT
imeout
;
int
search_t
imeout
;
/**
/**
* The MonotonicClockS() time stamp of the last search.
* The MonotonicClockS() time stamp of the last search.
*/
*/
unsigned
m_lastS
earch
;
unsigned
last_s
earch
;
public
:
public
:
UPnPDeviceDirectory
(
UpnpClient_Handle
_handle
,
UPnPDeviceDirectory
(
UpnpClient_Handle
_handle
,
...
@@ -122,24 +122,24 @@ public:
...
@@ -122,24 +122,24 @@ public:
bool
Start
(
Error
&
error
);
bool
Start
(
Error
&
error
);
/** Retrieve the directory services currently seen on the network */
/** Retrieve the directory services currently seen on the network */
bool
getDirServic
es
(
std
::
vector
<
ContentDirectoryService
>
&
,
Error
&
);
bool
GetDirectori
es
(
std
::
vector
<
ContentDirectoryService
>
&
,
Error
&
);
/**
/**
* Get server by friendly name.
* Get server by friendly name.
*/
*/
bool
getServer
(
const
char
*
friendlyN
ame
,
bool
GetServer
(
const
char
*
friendly_n
ame
,
ContentDirectoryService
&
server
,
ContentDirectoryService
&
server
,
Error
&
error
);
Error
&
error
);
private
:
private
:
bool
s
earch
(
Error
&
error
);
bool
S
earch
(
Error
&
error
);
/**
/**
* Look at the devices and get rid of those which have not
* Look at the devices and get rid of those which have not
* been seen for too long. We do this when listing the top
* been seen for too long. We do this when listing the top
* directory.
* directory.
*/
*/
bool
e
xpireDevices
(
Error
&
error
);
bool
E
xpireDevices
(
Error
&
error
);
void
LockAdd
(
ContentDirectoryDescriptor
&&
d
);
void
LockAdd
(
ContentDirectoryDescriptor
&&
d
);
void
LockRemove
(
const
std
::
string
&
id
);
void
LockRemove
(
const
std
::
string
&
id
);
...
@@ -149,12 +149,11 @@ private:
...
@@ -149,12 +149,11 @@ private:
* devices appearing and disappearing, and update the
* devices appearing and disappearing, and update the
* directory pool accordingly.
* directory pool accordingly.
*/
*/
static
void
*
discoExplorer
(
void
*
);
static
void
*
Explore
(
void
*
);
void
discoExplorer
();
void
Explore
();
int
OnAlive
(
Upnp_Discovery
*
disco
);
int
OnAlive
(
Upnp_Discovery
*
disco
);
int
OnByeBye
(
Upnp_Discovery
*
disco
);
int
OnByeBye
(
Upnp_Discovery
*
disco
);
int
cluCallBack
(
Upnp_EventType
et
,
void
*
evp
);
/* virtual methods from class UpnpCallback */
/* virtual methods from class UpnpCallback */
virtual
int
Invoke
(
Upnp_EventType
et
,
void
*
evp
)
override
;
virtual
int
Invoke
(
Upnp_EventType
et
,
void
*
evp
)
override
;
...
...
src/neighbor/plugins/UpnpNeighborPlugin.cxx
View file @
3d446d32
...
@@ -100,7 +100,7 @@ UpnpNeighborExplorer::GetList() const
...
@@ -100,7 +100,7 @@ UpnpNeighborExplorer::GetList() const
{
{
Error
error
;
Error
error
;
if
(
!
discovery
->
getDirServic
es
(
tmp
,
error
))
if
(
!
discovery
->
GetDirectori
es
(
tmp
,
error
))
LogError
(
error
);
LogError
(
error
);
}
}
...
...
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