more fixes for EPA madness

git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@8467 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2011-01-06 18:37:13 +00:00
parent 3da0361480
commit 8fd752b7e8
6 changed files with 90 additions and 26 deletions

View file

@ -6,6 +6,7 @@
#include <glibmm.h>
#include <gtkmm/messagedialog.h>
#include <pbd/xml++.h>
#include <pbd/epa.h>
#ifdef __APPLE__
#include <CoreAudio/CoreAudio.h>
@ -560,6 +561,18 @@ EngineControl::build_command_line (vector<string>& cmd)
bool
EngineControl::engine_running ()
{
EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa ();
EnvironmentalProtectionAgency current_epa (true); /* will restore settings when we leave scope */
/* revert all environment settings back to whatever they were when ardour started
*/
cerr << "STarting JACK, global EPA = " << global_epa << endl;
if (global_epa) {
global_epa->restore ();
}
jack_status_t status;
jack_client_t* c = jack_client_open ("ardourprobe", JackNoStartServer, &status);

View file

@ -111,7 +111,6 @@ string
ExportRangeMarkersDialog::get_target_filepath(string path, string filename, string postfix)
{
string target_filepath = Glib::build_filename (path, filename + postfix);
struct stat statbuf;
for (int counter=1; Glib::file_test (target_filepath, Glib::FILE_TEST_EXISTS); counter++) {
// while file exists

View file

@ -273,7 +273,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

@ -1130,6 +1130,8 @@ AudioEngine::connect_to_jack (string client_name)
/* revert all environment settings back to whatever they were when ardour started
*/
cerr << "STarting JACK, global EPA = " << global_epa << endl;
if (global_epa) {
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,22 +57,69 @@ EnvironmentalProtectionAgency::save ()
{
e.clear ();
for (size_t i = 0; environ[i]; ++i) {
if (!_envname.empty()) {
/* fetch environment from named environment string
*/
string estring = environ[i];
string::size_type equal = estring.find_first_of ('=');
cerr << "Look for " << _envname << endl;
if (equal == string::npos) {
/* say what? an environ value without = ? */
continue;
const char* estr = getenv (_envname.c_str());
cerr << " result = [" << estr << ']' << endl;
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;
cerr << "Parsed to " << lines.size() << " lines\n";
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);
cerr << "EN:Save [" << before << "] = " << after << endl;
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);
cerr << "Save [" << before << "] = " << after << endl;
e.insert (pair<string,string>(before,after));
}
}
}
void

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;
};
}