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
ca43e634
Commit
ca43e634
authored
Jan 13, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp: use std::function for the libupnp callback
Replaces the bloated std::map.
parent
85324f80
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
31 deletions
+16
-31
Discovery.cxx
src/db/upnp/Discovery.cxx
+4
-6
upnpplib.cxx
src/db/upnp/upnpplib.cxx
+3
-13
upnpplib.hxx
src/db/upnp/upnpplib.hxx
+9
-12
No files found.
src/db/upnp/Discovery.cxx
View file @
ca43e634
...
...
@@ -158,7 +158,7 @@ discoExplorer(void *)
// mutex just for clarifying the message printing, the workqueue is
// mt-safe of course.
static
int
cluCallBack
(
Upnp_EventType
et
,
void
*
evp
,
void
*
)
cluCallBack
(
Upnp_EventType
et
,
void
*
evp
)
{
static
Mutex
cblock
;
const
ScopeLock
protect
(
cblock
);
...
...
@@ -231,11 +231,9 @@ UPnPDeviceDirectory::UPnPDeviceDirectory()
if
(
lib
==
nullptr
)
return
;
lib
->
registerHandler
(
UPNP_DISCOVERY_SEARCH_RESULT
,
cluCallBack
,
this
);
lib
->
registerHandler
(
UPNP_DISCOVERY_ADVERTISEMENT_ALIVE
,
cluCallBack
,
this
);
lib
->
registerHandler
(
UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE
,
cluCallBack
,
this
);
lib
->
SetHandler
([](
Upnp_EventType
type
,
void
*
event
){
cluCallBack
(
type
,
event
);
});
search
();
}
...
...
src/db/upnp/upnpplib.cxx
View file @
ca43e634
...
...
@@ -65,15 +65,6 @@ LibUPnP::LibUPnP()
ixmlRelaxParser
(
1
);
}
void
LibUPnP
::
registerHandler
(
Upnp_EventType
et
,
Upnp_FunPtr
handler
,
void
*
cookie
)
{
if
(
handler
==
nullptr
)
m_handlers
.
erase
(
et
);
else
m_handlers
.
emplace
(
et
,
Handler
(
handler
,
cookie
));
}
int
LibUPnP
::
o_callback
(
Upnp_EventType
et
,
void
*
evp
,
void
*
cookie
)
{
...
...
@@ -83,10 +74,9 @@ LibUPnP::o_callback(Upnp_EventType et, void* evp, void* cookie)
ulib
=
theLib
;
}
auto
it
=
ulib
->
m_handlers
.
find
(
et
);
if
(
it
!=
ulib
->
m_handlers
.
end
())
{
(
it
->
second
.
handler
)(
et
,
evp
,
it
->
second
.
cookie
);
}
if
(
ulib
->
handler
)
ulib
->
handler
(
et
,
evp
);
return
UPNP_E_SUCCESS
;
}
...
...
src/db/upnp/upnpplib.hxx
View file @
ca43e634
...
...
@@ -22,24 +22,18 @@
#include "util/Error.hxx"
#include <map>
#include <upnp/upnp.h>
#include <functional>
/** Our link to libupnp. Initialize and keep the handle around */
class
LibUPnP
{
// A Handler object records the data from registerHandler.
class
Handler
{
public
:
Handler
(
Upnp_FunPtr
h
,
void
*
c
)
:
handler
(
h
),
cookie
(
c
)
{}
Upnp_FunPtr
handler
;
void
*
cookie
;
};
typedef
std
::
function
<
void
(
Upnp_EventType
type
,
void
*
event
)
>
Handler
;
Error
init_error
;
UpnpClient_Handle
m_clh
;
std
::
map
<
Upnp_EventType
,
Handler
>
m_handlers
;
Handler
handler
;
LibUPnP
();
...
...
@@ -65,7 +59,10 @@ public:
return
init_error
;
}
void
registerHandler
(
Upnp_EventType
et
,
Upnp_FunPtr
handler
,
void
*
cookie
);
template
<
typename
T
>
void
SetHandler
(
T
&&
_handler
)
{
handler
=
std
::
forward
<
T
>
(
_handler
);
}
UpnpClient_Handle
getclh
()
{
...
...
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