2013-08-09 08:03:39 -04:00
|
|
|
/*
|
2019-08-02 23:10:55 -04:00
|
|
|
* Copyright (C) 2013-2015 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2014-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2019 Robin Gareus <robin@gareus.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.
|
|
|
|
*/
|
2013-08-09 08:03:39 -04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
2014-12-02 08:36:14 -05:00
|
|
|
#include <string>
|
2013-08-09 08:03:39 -04:00
|
|
|
|
2014-11-04 20:24:39 -05:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
2013-08-09 08:13:50 -04:00
|
|
|
#include <giomm.h>
|
|
|
|
|
2013-08-09 08:03:39 -04:00
|
|
|
#include <glibmm/thread.h>
|
|
|
|
|
|
|
|
#include "pbd/pbd.h"
|
|
|
|
#include "pbd/debug.h"
|
2014-12-04 11:05:33 -05:00
|
|
|
#include "pbd/error.h"
|
2013-08-09 08:03:39 -04:00
|
|
|
#include "pbd/id.h"
|
|
|
|
#include "pbd/enumwriter.h"
|
2015-09-12 14:05:25 -04:00
|
|
|
#include "pbd/fpu.h"
|
2019-12-31 14:05:06 -05:00
|
|
|
#include "pbd/xml++.h"
|
2013-08-09 08:03:39 -04:00
|
|
|
|
2014-12-04 10:07:11 -05:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
#include <winsock2.h>
|
2015-09-13 23:47:38 -04:00
|
|
|
#include "pbd/windows_timer_utils.h"
|
|
|
|
#include "pbd/windows_mmcss.h"
|
2014-12-04 10:07:11 -05:00
|
|
|
#endif
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2013-08-09 08:03:39 -04:00
|
|
|
|
2013-07-25 22:04:40 -04:00
|
|
|
extern void setup_libpbd_enums ();
|
|
|
|
|
2013-08-09 08:03:39 -04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
static bool libpbd_initialized = false;
|
|
|
|
|
2015-09-13 23:59:04 -04:00
|
|
|
static
|
2014-12-02 08:36:14 -05:00
|
|
|
void
|
|
|
|
set_debug_options_from_env ()
|
|
|
|
{
|
|
|
|
bool set;
|
|
|
|
std::string options;
|
|
|
|
|
|
|
|
options = Glib::getenv ("PBD_DEBUG", set);
|
|
|
|
if (set) {
|
2015-09-13 23:54:00 -04:00
|
|
|
std::cerr << X_("PBD_DEBUG=") << options << std::endl;
|
2014-12-02 08:36:14 -05:00
|
|
|
PBD::parse_debug_options (options.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-13 21:24:33 -04:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2015-09-13 23:59:04 -04:00
|
|
|
static
|
2015-09-13 21:24:33 -04:00
|
|
|
void
|
|
|
|
test_timers_from_env ()
|
|
|
|
{
|
|
|
|
bool set;
|
|
|
|
std::string options;
|
|
|
|
|
|
|
|
options = Glib::getenv ("PBD_TEST_TIMERS", set);
|
|
|
|
if (set) {
|
|
|
|
if (!PBD::QPC::check_timer_valid ()) {
|
2015-09-13 23:54:00 -04:00
|
|
|
PBD::error << X_("Windows QPC Timer source not usable") << endmsg;
|
2015-09-13 21:24:33 -04:00
|
|
|
} else {
|
2015-09-13 23:54:00 -04:00
|
|
|
PBD::info << X_("Windows QPC Timer source usable") << endmsg;
|
2015-09-13 21:24:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-09-13 23:59:04 -04:00
|
|
|
} // namespace
|
|
|
|
|
2013-08-09 08:03:39 -04:00
|
|
|
bool
|
|
|
|
PBD::init ()
|
|
|
|
{
|
|
|
|
if (libpbd_initialized) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-04 20:24:39 -05:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
// Essential!! Make sure that any files used by Ardour
|
|
|
|
// will be created or opened in BINARY mode!
|
|
|
|
_fmode = O_BINARY;
|
2014-12-04 10:07:11 -05:00
|
|
|
|
2019-04-13 13:19:29 -04:00
|
|
|
WSADATA wsaData;
|
2014-12-04 10:07:11 -05:00
|
|
|
|
|
|
|
/* Initialize windows socket DLL for PBD::CrossThreadChannel
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-12-04 10:07:11 -05:00
|
|
|
if (WSAStartup(MAKEWORD(1,1),&wsaData) != 0) {
|
2017-07-03 08:45:41 -04:00
|
|
|
error << X_("Windows socket initialization failed with error: ") << WSAGetLastError() << endmsg;
|
2014-12-04 11:13:43 -05:00
|
|
|
return false;
|
2014-12-04 10:07:11 -05:00
|
|
|
}
|
2015-09-13 21:24:33 -04:00
|
|
|
|
2015-09-16 09:21:38 -04:00
|
|
|
QPC::initialize();
|
2015-09-13 21:24:33 -04:00
|
|
|
test_timers_from_env ();
|
2015-09-13 23:47:38 -04:00
|
|
|
|
|
|
|
if (!PBD::MMCSS::initialize()) {
|
2015-09-13 23:54:00 -04:00
|
|
|
PBD::info << X_("Unable to initialize MMCSS") << endmsg;
|
2015-09-13 23:47:38 -04:00
|
|
|
} else {
|
2015-09-13 23:54:00 -04:00
|
|
|
PBD::info << X_("MMCSS Initialized") << endmsg;
|
2015-09-13 23:47:38 -04:00
|
|
|
}
|
2014-11-04 20:24:39 -05:00
|
|
|
#endif
|
|
|
|
|
2013-08-09 08:03:39 -04:00
|
|
|
if (!Glib::thread_supported()) {
|
|
|
|
Glib::thread_init();
|
|
|
|
}
|
|
|
|
|
2013-08-09 08:13:50 -04:00
|
|
|
Gio::init ();
|
|
|
|
|
2013-08-09 08:03:39 -04:00
|
|
|
PBD::ID::init ();
|
|
|
|
|
2013-07-25 22:04:40 -04:00
|
|
|
setup_libpbd_enums ();
|
|
|
|
|
2014-12-02 08:36:14 -05:00
|
|
|
set_debug_options_from_env ();
|
|
|
|
|
2013-08-09 08:03:39 -04:00
|
|
|
libpbd_initialized = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PBD::cleanup ()
|
|
|
|
{
|
2014-12-04 10:07:11 -05:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2015-09-13 23:47:38 -04:00
|
|
|
PBD::MMCSS::deinitialize ();
|
2014-12-04 10:07:11 -05:00
|
|
|
WSACleanup();
|
2015-10-05 10:17:49 -04:00
|
|
|
#endif
|
2014-12-04 10:07:11 -05:00
|
|
|
|
2013-08-09 08:03:39 -04:00
|
|
|
EnumWriter::destroy ();
|
2015-09-12 14:05:25 -04:00
|
|
|
FPU::destroy ();
|
2013-08-09 08:03:39 -04:00
|
|
|
}
|