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
9f3ba737
Commit
9f3ba737
authored
Jan 26, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upnp/Discovery: add listener interface
parent
f86f5ad2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
2 deletions
+36
-2
Discovery.cxx
src/lib/upnp/Discovery.cxx
+27
-1
Discovery.hxx
src/lib/upnp/Discovery.hxx
+9
-1
No files found.
src/lib/upnp/Discovery.cxx
View file @
9f3ba737
...
...
@@ -53,6 +53,24 @@ isMSDevice(const char *st)
return
memcmp
(
MediaServerDType
,
st
,
sz
)
==
0
;
}
static
void
AnnounceFoundUPnP
(
UPnPDiscoveryListener
&
listener
,
const
UPnPDevice
&
device
)
{
for
(
const
auto
&
service
:
device
.
services
)
if
(
isCDService
(
service
.
serviceType
.
c_str
()))
listener
.
FoundUPnP
(
ContentDirectoryService
(
device
,
service
));
}
static
void
AnnounceLostUPnP
(
UPnPDiscoveryListener
&
listener
,
const
UPnPDevice
&
device
)
{
for
(
const
auto
&
service
:
device
.
services
)
if
(
isCDService
(
service
.
serviceType
.
c_str
()))
listener
.
LostUPnP
(
ContentDirectoryService
(
device
,
service
));
}
inline
void
UPnPDeviceDirectory
::
LockAdd
(
ContentDirectoryDescriptor
&&
d
)
{
...
...
@@ -66,6 +84,9 @@ UPnPDeviceDirectory::LockAdd(ContentDirectoryDescriptor &&d)
}
directories
.
emplace_back
(
std
::
move
(
d
));
if
(
listener
!=
nullptr
)
AnnounceFoundUPnP
(
*
listener
,
directories
.
back
().
device
);
}
inline
void
...
...
@@ -76,6 +97,9 @@ UPnPDeviceDirectory::LockRemove(const std::string &id)
for
(
auto
i
=
directories
.
begin
(),
end
=
directories
.
end
();
i
!=
end
;
++
i
)
{
if
(
i
->
id
==
id
)
{
if
(
listener
!=
nullptr
)
AnnounceLostUPnP
(
*
listener
,
i
->
device
);
directories
.
erase
(
i
);
break
;
}
...
...
@@ -208,8 +232,10 @@ UPnPDeviceDirectory::expireDevices(Error &error)
return
true
;
}
UPnPDeviceDirectory
::
UPnPDeviceDirectory
(
LibUPnP
*
_lib
)
UPnPDeviceDirectory
::
UPnPDeviceDirectory
(
LibUPnP
*
_lib
,
UPnPDiscoveryListener
*
_listener
)
:
lib
(
_lib
),
listener
(
_listener
),
discoveredQueue
(
"DiscoveredQueue"
),
m_searchTimeout
(
2
),
m_lastSearch
(
0
)
{
...
...
src/lib/upnp/Discovery.hxx
View file @
9f3ba737
...
...
@@ -34,6 +34,12 @@
class
LibUPnP
;
class
ContentDirectoryService
;
class
UPnPDiscoveryListener
{
public
:
virtual
void
FoundUPnP
(
const
ContentDirectoryService
&
service
)
=
0
;
virtual
void
LostUPnP
(
const
ContentDirectoryService
&
service
)
=
0
;
};
/**
* Manage UPnP discovery and maintain a directory of active devices. Singleton.
*
...
...
@@ -86,6 +92,7 @@ class UPnPDeviceDirectory {
};
LibUPnP
*
const
lib
;
UPnPDiscoveryListener
*
const
listener
;
Mutex
mutex
;
std
::
list
<
ContentDirectoryDescriptor
>
directories
;
...
...
@@ -104,7 +111,8 @@ class UPnPDeviceDirectory {
unsigned
m_lastSearch
;
public
:
UPnPDeviceDirectory
(
LibUPnP
*
_lib
);
UPnPDeviceDirectory
(
LibUPnP
*
_lib
,
UPnPDiscoveryListener
*
_listener
=
nullptr
);
~
UPnPDeviceDirectory
();
UPnPDeviceDirectory
(
const
UPnPDeviceDirectory
&
)
=
delete
;
...
...
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