From 603d07a80bb293cb7819e50397111674a96b142c Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 7 Jan 2011 16:25:57 +0000 Subject: [PATCH] forward port EPA changes from 2.X git-svn-id: svn://localhost/ardour2/branches/3.0@8473 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/engine_dialog.cc | 15 +++++++++ gtk2_ardour/main.cc | 4 +-- libs/ardour/audioengine.cc | 8 ++--- libs/pbd/epa.cc | 62 +++++++++++++++++++++++++++++------- libs/pbd/pbd/epa.h | 27 ++++++++-------- 5 files changed, 84 insertions(+), 32 deletions(-) diff --git a/gtk2_ardour/engine_dialog.cc b/gtk2_ardour/engine_dialog.cc index a3c3edd1cc..d54f6100a9 100644 --- a/gtk2_ardour/engine_dialog.cc +++ b/gtk2_ardour/engine_dialog.cc @@ -22,8 +22,12 @@ #include #include +#include + #include #include + +#include "pbd/epa.h" #include "pbd/xml++.h" #ifdef __APPLE__ @@ -619,6 +623,17 @@ EngineControl::build_command_line (vector& cmd) bool EngineControl::engine_running () { + EnvironmentalProtectionAgency* global_epa = EnvironmentalProtectionAgency::get_global_epa (); + boost::scoped_ptr 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); diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc index 0a90c147ef..6f03c5828d 100644 --- a/gtk2_ardour/main.cc +++ b/gtk2_ardour/main.cc @@ -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)); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index b2241f5c2f..ef94d0d740 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -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 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 (); } diff --git a/libs/pbd/epa.cc b/libs/pbd/epa.cc index 8665823d77..3d3f7477d7 100644 --- a/libs/pbd/epa.cc +++ b/libs/pbd/epa.cc @@ -21,6 +21,7 @@ #include #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 lines; + split (estr, lines, '\n'); - cerr << "Save [" << before << "] = " << after << endl; + for (vector::iterator i = lines.begin(); i != lines.end(); ++i) { - e.insert (pair(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(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(before,after)); + } } } void EnvironmentalProtectionAgency::restore () const { for (map::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); } } diff --git a/libs/pbd/pbd/epa.h b/libs/pbd/pbd/epa.h index b2708fbd4c..ffcd78504a 100644 --- a/libs/pbd/pbd/epa.h +++ b/libs/pbd/pbd/epa.h @@ -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 e; - static EnvironmentalProtectionAgency* _global_epa; + bool _armed; + std::string _envname; + std::map e; + static EnvironmentalProtectionAgency* _global_epa; }; }