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
01f7abfc
Commit
01f7abfc
authored
Jan 26, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upnp: move library initialization to Init.cxx
Allow calling UpnpGlobalInit() multiple times.
parent
e57e89b9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
17 deletions
+112
-17
Makefile.am
Makefile.am
+1
-0
Init.cxx
src/lib/upnp/Init.cxx
+73
-0
Init.hxx
src/lib/upnp/Init.hxx
+33
-0
upnpplib.cxx
src/lib/upnp/upnpplib.cxx
+5
-17
No files found.
Makefile.am
View file @
01f7abfc
...
...
@@ -217,6 +217,7 @@ src_mpd_SOURCES = \
src/Timer.cxx
UPNP_SOURCES
=
\
src/lib/upnp/Init.cxx src/lib/upnp/Init.hxx
\
src/lib/upnp/Device.cxx src/lib/upnp/Device.hxx
\
src/lib/upnp/ContentDirectoryService.cxx src/lib/upnp/ContentDirectoryService.hxx
\
src/lib/upnp/Discovery.cxx src/lib/upnp/Discovery.hxx
\
...
...
src/lib/upnp/Init.cxx
0 → 100644
View file @
01f7abfc
/*
* Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "Init.hxx"
#include "Domain.hxx"
#include "thread/Mutex.hxx"
#include "util/Error.hxx"
#include <upnp/upnp.h>
#include <upnp/upnptools.h>
#include <upnp/ixml.h>
static
Mutex
upnp_init_mutex
;
static
unsigned
upnp_ref
;
static
bool
DoInit
(
Error
&
error
)
{
auto
code
=
UpnpInit
(
0
,
0
);
if
(
code
!=
UPNP_E_SUCCESS
)
{
error
.
Format
(
upnp_domain
,
code
,
"UpnpInit() failed: %s"
,
UpnpGetErrorMessage
(
code
));
return
false
;
}
UpnpSetMaxContentLength
(
2000
*
1024
);
// Servers sometimes make error (e.g.: minidlna returns bad utf-8)
ixmlRelaxParser
(
1
);
return
true
;
}
bool
UpnpGlobalInit
(
Error
&
error
)
{
const
ScopeLock
protect
(
upnp_init_mutex
);
if
(
upnp_ref
==
0
&&
!
DoInit
(
error
))
return
false
;
++
upnp_ref
;
return
true
;
}
void
UpnpGlobalFinish
()
{
const
ScopeLock
protect
(
upnp_init_mutex
);
assert
(
upnp_ref
>
0
);
if
(
--
upnp_ref
==
0
)
UpnpFinish
();
}
src/lib/upnp/Init.hxx
0 → 100644
View file @
01f7abfc
/*
* Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_UPNP_INIT_HXX
#define MPD_UPNP_INIT_HXX
#include "check.h"
class
Error
;
bool
UpnpGlobalInit
(
Error
&
error
);
void
UpnpGlobalFinish
();
#endif
src/lib/upnp/upnpplib.cxx
View file @
01f7abfc
...
...
@@ -21,33 +21,24 @@
#include "upnpplib.hxx"
#include "Callback.hxx"
#include "Domain.hxx"
#include "Init.hxx"
#include "Log.hxx"
#include <upnp/ixml.h>
#include <upnp/upnptools.h>
LibUPnP
::
LibUPnP
()
{
auto
code
=
UpnpInit
(
0
,
0
);
if
(
code
!=
UPNP_E_SUCCESS
)
{
init_error
.
Format
(
upnp_domain
,
code
,
"UpnpInit() failed: %s"
,
UpnpGetErrorMessage
(
code
));
if
(
!
UpnpGlobalInit
(
init_error
))
return
;
}
UpnpSetMaxContentLength
(
2000
*
1024
);
code
=
UpnpRegisterClient
(
o_callback
,
nullptr
,
&
m_clh
);
auto
code
=
UpnpRegisterClient
(
o_callback
,
nullptr
,
&
m_clh
);
if
(
code
!=
UPNP_E_SUCCESS
)
{
UpnpGlobalFinish
();
init_error
.
Format
(
upnp_domain
,
code
,
"UpnpRegisterClient() failed: %s"
,
UpnpGetErrorMessage
(
code
));
return
;
}
// Servers sometimes make error (e.g.: minidlna returns bad utf-8)
ixmlRelaxParser
(
1
);
}
int
...
...
@@ -65,8 +56,5 @@ LibUPnP::o_callback(Upnp_EventType et, void* evp, void* cookie)
LibUPnP
::~
LibUPnP
()
{
int
error
=
UpnpFinish
();
if
(
error
!=
UPNP_E_SUCCESS
)
FormatError
(
upnp_domain
,
"UpnpFinish() failed: %s"
,
UpnpGetErrorMessage
(
error
));
UpnpGlobalFinish
();
}
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