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
b8e382b0
Commit
b8e382b0
authored
Jan 23, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp/Discovery: use std::list instead of std::map
There will only be very few items, and that does not justify the bloat of std::map.
parent
c9af358e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
16 deletions
+33
-16
Discovery.cxx
src/db/upnp/Discovery.cxx
+25
-11
Discovery.hxx
src/db/upnp/Discovery.hxx
+8
-5
No files found.
src/db/upnp/Discovery.cxx
View file @
b8e382b0
...
...
@@ -54,19 +54,32 @@ isMSDevice(const char *st)
}
inline
void
UPnPDeviceDirectory
::
LockAdd
(
std
::
string
&&
id
,
ContentDirectoryDescriptor
&&
d
)
UPnPDeviceDirectory
::
LockAdd
(
ContentDirectoryDescriptor
&&
d
)
{
const
ScopeLock
protect
(
mutex
);
directories
[
std
::
move
(
id
)]
=
std
::
move
(
d
);
for
(
auto
&
i
:
directories
)
{
if
(
i
.
id
==
d
.
id
)
{
i
=
std
::
move
(
d
);
return
;
}
}
directories
.
emplace_back
(
std
::
move
(
d
));
}
inline
void
UPnPDeviceDirectory
::
LockRemove
(
const
std
::
string
&
id
)
{
const
ScopeLock
protect
(
mutex
);
auto
i
=
directories
.
find
(
id
);
if
(
i
!=
directories
.
end
())
directories
.
erase
(
i
);
for
(
auto
i
=
directories
.
begin
(),
end
=
directories
.
end
();
i
!=
end
;
++
i
)
{
if
(
i
->
id
==
id
)
{
directories
.
erase
(
i
);
break
;
}
}
}
inline
void
...
...
@@ -91,7 +104,8 @@ UPnPDeviceDirectory::discoExplorer()
}
// Update or insert the device
ContentDirectoryDescriptor
d
(
MonotonicClockS
(),
tsk
->
expires
);
ContentDirectoryDescriptor
d
(
std
::
move
(
tsk
->
deviceId
),
MonotonicClockS
(),
tsk
->
expires
);
{
Error
error2
;
...
...
@@ -104,7 +118,7 @@ UPnPDeviceDirectory::discoExplorer()
}
}
LockAdd
(
std
::
move
(
tsk
->
deviceId
),
std
::
move
(
d
));
LockAdd
(
std
::
move
(
d
));
delete
tsk
;
}
}
...
...
@@ -180,7 +194,7 @@ UPnPDeviceDirectory::expireDevices(Error &error)
for
(
auto
it
=
directories
.
begin
();
it
!=
directories
.
end
();)
{
if
(
now
>
it
->
second
.
expires
)
{
if
(
now
>
it
->
expires
)
{
it
=
directories
.
erase
(
it
);
didsomething
=
true
;
}
else
{
...
...
@@ -263,9 +277,9 @@ UPnPDeviceDirectory::getDirServices(std::vector<ContentDirectoryService> &out,
for
(
auto
dit
=
directories
.
begin
();
dit
!=
directories
.
end
();
dit
++
)
{
for
(
const
auto
&
service
:
dit
->
second
.
device
.
services
)
{
for
(
const
auto
&
service
:
dit
->
device
.
services
)
{
if
(
isCDService
(
service
.
serviceType
.
c_str
()))
{
out
.
emplace_back
(
dit
->
second
.
device
,
service
);
out
.
emplace_back
(
dit
->
device
,
service
);
}
}
}
...
...
@@ -285,7 +299,7 @@ UPnPDeviceDirectory::getServer(const char *friendlyName,
const
ScopeLock
protect
(
mutex
);
for
(
const
auto
&
i
:
directories
)
{
const
auto
&
device
=
i
.
second
.
device
;
const
auto
&
device
=
i
.
device
;
if
(
device
.
friendlyName
!=
friendlyName
)
continue
;
...
...
src/db/upnp/Discovery.hxx
View file @
b8e382b0
...
...
@@ -27,7 +27,7 @@
#include <upnp/upnp.h>
#include <
map
>
#include <
list
>
#include <vector>
#include <string>
...
...
@@ -63,6 +63,8 @@ class UPnPDeviceDirectory {
*/
class
ContentDirectoryDescriptor
{
public
:
std
::
string
id
;
UPnPDevice
device
;
/**
...
...
@@ -73,8 +75,9 @@ class UPnPDeviceDirectory {
ContentDirectoryDescriptor
()
=
default
;
ContentDirectoryDescriptor
(
unsigned
last
,
int
exp
)
:
expires
(
last
+
exp
+
20
)
{}
ContentDirectoryDescriptor
(
std
::
string
&&
_id
,
unsigned
last
,
int
exp
)
:
id
(
std
::
move
(
_id
)),
expires
(
last
+
exp
+
20
)
{}
bool
Parse
(
const
std
::
string
&
url
,
const
char
*
description
,
Error
&
_error
)
{
...
...
@@ -85,7 +88,7 @@ class UPnPDeviceDirectory {
LibUPnP
*
const
lib
;
Mutex
mutex
;
std
::
map
<
std
::
string
,
ContentDirectoryDescriptor
>
directories
;
std
::
list
<
ContentDirectoryDescriptor
>
directories
;
WorkQueue
<
DiscoveredTask
*>
discoveredQueue
;
/**
...
...
@@ -129,7 +132,7 @@ private:
*/
bool
expireDevices
(
Error
&
error
);
void
LockAdd
(
std
::
string
&&
id
,
ContentDirectoryDescriptor
&&
d
);
void
LockAdd
(
ContentDirectoryDescriptor
&&
d
);
void
LockRemove
(
const
std
::
string
&
id
);
/**
...
...
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