13
0

add EPA stuff from 2.X

git-svn-id: svn://localhost/ardour2/branches/3.0@8337 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2010-12-23 04:17:45 +00:00
parent 4336bb25d7
commit e99087a273
4 changed files with 132 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#include <gtkmm/settings.h>
#include "pbd/error.h"
#include "pbd/epa.h"
#include "pbd/file_utils.h"
#include "pbd/textreceiver.h"
#include "pbd/failed_constructor.h"
@ -308,6 +309,8 @@ fixup_bundle_environment (int argc, char* argv[])
return;
}
EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency);
Glib::ustring exec_path = argv[0];
Glib::ustring dir_path = Glib::path_get_dirname (Glib::path_get_dirname (exec_path));
Glib::ustring path;

View File

@ -31,6 +31,7 @@
#include "pbd/pthread_utils.h"
#include "pbd/stacktrace.h"
#include "pbd/unknown_type.h"
#include "pbd/epa.h"
#include "midi++/port.h"
#include "midi++/mmc.h"
@ -1261,6 +1262,16 @@ AudioEngine::connect_to_jack (string client_name, string session_uuid)
jack_status_t status;
const char *server_name = NULL;
EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
EnvironmentalProtectionAgency current_epa; // saves current settings and restores on exit from this scope
/* revert all environment settings back to whatever they were when ardour started
*/
if (global_epa) {
global_epa->restore ();
}
jack_client_name = client_name; /* might be reset below */
#ifdef HAVE_JACK_SESSION
if (! session_uuid.empty())

72
libs/pbd/epa.cc Normal file
View File

@ -0,0 +1,72 @@
/*
Copyright (C) 2010 Paul Davis
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <cstdlib>
#include <iostream>
#include "pbd/epa.h"
extern char** environ;
using namespace PBD;
using namespace std;
EnvironmentalProtectionAgency* EnvironmentalProtectionAgency::_global_epa = 0;
EnvironmentalProtectionAgency::EnvironmentalProtectionAgency ()
{
save ();
}
EnvironmentalProtectionAgency::~EnvironmentalProtectionAgency()
{
restore ();
}
void
EnvironmentalProtectionAgency::save ()
{
e.clear ();
for (size_t i = 0; environ[i]; ++i) {
string estring = environ[i];
string::size_type equal = estring.find_first_of ('=');
if (equal == string::npos) {
/* say what? an environ value without = ? */
continue;
}
string before = estring.substr (0, equal);
string after = estring.substr (equal+1);
cerr << "Save [" << before << "] = " << after << endl;
e.insert (pair<string,string>(before,after));
}
}
void
EnvironmentalProtectionAgency::restore ()
{
for (map<string,string>::iterator i = e.begin(); i != e.end(); ++i) {
cerr << "Restore [" << i->first << "] = " << i->second << endl;
setenv (i->first.c_str(), i->second.c_str(), 1);
}
}

46
libs/pbd/pbd/epa.h Normal file
View File

@ -0,0 +1,46 @@
/*
Copyright (C) 2010 Paul Davis
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __libpbd_epa_h__
#define __libpbd_epa_h__
#include <map>
#include <string>
namespace PBD {
class EnvironmentalProtectionAgency {
public:
EnvironmentalProtectionAgency ();
~EnvironmentalProtectionAgency ();
void restore ();
void save ();
static EnvironmentalProtectionAgency* get_global_epa () { return _global_epa; }
static void set_global_epa (EnvironmentalProtectionAgency* epa) { _global_epa = epa; }
private:
std::map<std::string,std::string> e;
static EnvironmentalProtectionAgency* _global_epa;
};
}
#endif /* __libpbd_epa_h__ */