add EPA stuff from 2.X
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 23 Dec 2010 04:17:45 +0000 (04:17 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 23 Dec 2010 04:17:45 +0000 (04:17 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@8337 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/main.cc
libs/ardour/audioengine.cc
libs/pbd/epa.cc [new file with mode: 0644]
libs/pbd/pbd/epa.h [new file with mode: 0644]

index 899e8b578975af1cd07dc8888715757e2d2d69a8..827425c321a0cd1227339bc27ae91168a1a27cc7 100644 (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;
index 7da687657759603ce29b1a5e6916d33be683c081..9feb87ba95440370ea53ee6d7c37fe9f0084e350 100644 (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())
diff --git a/libs/pbd/epa.cc b/libs/pbd/epa.cc
new file mode 100644 (file)
index 0000000..71387b4
--- /dev/null
@@ -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);
+        }
+}                         
diff --git a/libs/pbd/pbd/epa.h b/libs/pbd/pbd/epa.h
new file mode 100644 (file)
index 0000000..3977331
--- /dev/null
@@ -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__ */