13
0

forward port EPA changes from 2.X

git-svn-id: svn://localhost/ardour2/branches/3.0@8473 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2011-01-07 16:25:57 +00:00
parent 5bff882ce1
commit 603d07a80b
5 changed files with 84 additions and 32 deletions

View File

@ -22,8 +22,12 @@
#include <fstream>
#include <map>
#include <boost/scoped_ptr.hpp>
#include <glibmm.h>
#include <gtkmm/messagedialog.h>
#include "pbd/epa.h"
#include "pbd/xml++.h"
#ifdef __APPLE__
@ -619,6 +623,17 @@ EngineControl::build_command_line (vector<string>& cmd)
bool
EngineControl::engine_running ()
{
EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
boost::scoped_ptr<EnvironmentalProtectionAgency> current_epa;
/* revert all environment settings back to whatever they were when ardour started
*/
if (global_epa) {
current_epa.reset (new EnvironmentalProtectionAgency(true)); /* will restore settings when we leave scope */
global_epa->restore ();
}
jack_status_t status;
jack_client_t* c = jack_client_open ("ardourprobe", JackNoStartServer, &status);

View File

@ -112,7 +112,7 @@ fixup_bundle_environment ()
return;
}
EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true));
EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true, "PREBUNDLE_ENV"));
set_language_preference ();
@ -311,7 +311,7 @@ fixup_bundle_environment (int argc, char* argv[])
return;
}
EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true));
EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true, "PREBUNDLE_ENV"));
Glib::ustring exec_path = argv[0];
Glib::ustring dir_path = Glib::path_get_dirname (Glib::path_get_dirname (exec_path));

View File

@ -1278,19 +1278,17 @@ AudioEngine::remove_all_ports ()
int
AudioEngine::connect_to_jack (string client_name, string session_uuid)
{
EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
boost::scoped_ptr<EnvironmentalProtectionAgency> current_epa;
jack_options_t options = JackNullOption;
jack_status_t status;
const char *server_name = NULL;
EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
EnvironmentalProtectionAgency current_epa (false);
/* revert all environment settings back to whatever they were when ardour started
*/
if (global_epa) {
current_epa.arm ();
current_epa.save ();
current_epa.reset (new EnvironmentalProtectionAgency(true)); /* will restore settings when we leave scope */
global_epa->restore ();
}

View File

@ -21,6 +21,7 @@
#include <iostream>
#include "pbd/epa.h"
#include "pbd/strsplit.h"
extern char** environ;
@ -29,8 +30,9 @@ using namespace std;
EnvironmentalProtectionAgency* EnvironmentalProtectionAgency::_global_epa = 0;
EnvironmentalProtectionAgency::EnvironmentalProtectionAgency (bool arm)
EnvironmentalProtectionAgency::EnvironmentalProtectionAgency (bool arm, const std::string& envname)
: _armed (arm)
, _envname (envname)
{
if (_armed) {
save ();
@ -55,29 +57,65 @@ EnvironmentalProtectionAgency::save ()
{
e.clear ();
for (size_t i = 0; environ[i]; ++i) {
if (!_envname.empty()) {
/* fetch environment from named environment variable, rather than "environ"
*/
string estring = environ[i];
string::size_type equal = estring.find_first_of ('=');
const char* estr = getenv (_envname.c_str());
if (equal == string::npos) {
/* say what? an environ value without = ? */
continue;
if (!estr) {
return;
}
/* parse line by line, and save into "e"
*/
string before = estring.substr (0, equal);
string after = estring.substr (equal+1);
vector<string> lines;
split (estr, lines, '\n');
cerr << "Save [" << before << "] = " << after << endl;
for (vector<string>::iterator i = lines.begin(); i != lines.end(); ++i) {
e.insert (pair<string,string>(before,after));
string estring = *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);
e.insert (pair<string,string>(before,after));
}
} else {
/* fetch environment from "environ"
*/
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);
e.insert (pair<string,string>(before,after));
}
}
}
void
EnvironmentalProtectionAgency::restore () const
{
for (map<string,string>::const_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);
}
}

View File

@ -27,20 +27,21 @@ namespace PBD {
class EnvironmentalProtectionAgency {
public:
EnvironmentalProtectionAgency (bool arm=true);
~EnvironmentalProtectionAgency ();
void arm ();
void save ();
void restore () const;
static EnvironmentalProtectionAgency* get_global_epa () { return _global_epa; }
static void set_global_epa (EnvironmentalProtectionAgency* epa) { _global_epa = epa; }
EnvironmentalProtectionAgency (bool arm = true, const std::string& envname = std::string());
~EnvironmentalProtectionAgency ();
void arm ();
void save ();
void restore () const;
static EnvironmentalProtectionAgency* get_global_epa () { return _global_epa; }
static void set_global_epa (EnvironmentalProtectionAgency* epa) { _global_epa = epa; }
private:
bool _armed;
std::map<std::string,std::string> e;
static EnvironmentalProtectionAgency* _global_epa;
bool _armed;
std::string _envname;
std::map<std::string,std::string> e;
static EnvironmentalProtectionAgency* _global_epa;
};
}