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 <fstream>
#include <map> #include <map>
#include <boost/scoped_ptr.hpp>
#include <glibmm.h> #include <glibmm.h>
#include <gtkmm/messagedialog.h> #include <gtkmm/messagedialog.h>
#include "pbd/epa.h"
#include "pbd/xml++.h" #include "pbd/xml++.h"
#ifdef __APPLE__ #ifdef __APPLE__
@ -619,6 +623,17 @@ EngineControl::build_command_line (vector<string>& cmd)
bool bool
EngineControl::engine_running () 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_status_t status;
jack_client_t* c = jack_client_open ("ardourprobe", JackNoStartServer, &status); jack_client_t* c = jack_client_open ("ardourprobe", JackNoStartServer, &status);

View file

@ -112,7 +112,7 @@ fixup_bundle_environment ()
return; return;
} }
EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true)); EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true, "PREBUNDLE_ENV"));
set_language_preference (); set_language_preference ();
@ -311,7 +311,7 @@ fixup_bundle_environment (int argc, char* argv[])
return; 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 exec_path = argv[0];
Glib::ustring dir_path = Glib::path_get_dirname (Glib::path_get_dirname (exec_path)); 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 int
AudioEngine::connect_to_jack (string client_name, string session_uuid) 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_options_t options = JackNullOption;
jack_status_t status; jack_status_t status;
const char *server_name = NULL; 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 /* revert all environment settings back to whatever they were when ardour started
*/ */
if (global_epa) { if (global_epa) {
current_epa.arm (); current_epa.reset (new EnvironmentalProtectionAgency(true)); /* will restore settings when we leave scope */
current_epa.save ();
global_epa->restore (); global_epa->restore ();
} }

View file

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

View file

@ -27,7 +27,7 @@ namespace PBD {
class EnvironmentalProtectionAgency { class EnvironmentalProtectionAgency {
public: public:
EnvironmentalProtectionAgency (bool arm=true); EnvironmentalProtectionAgency (bool arm = true, const std::string& envname = std::string());
~EnvironmentalProtectionAgency (); ~EnvironmentalProtectionAgency ();
void arm (); void arm ();
@ -39,6 +39,7 @@ class EnvironmentalProtectionAgency {
private: private:
bool _armed; bool _armed;
std::string _envname;
std::map<std::string,std::string> e; std::map<std::string,std::string> e;
static EnvironmentalProtectionAgency* _global_epa; static EnvironmentalProtectionAgency* _global_epa;
}; };