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
+ 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 ();
global_epa->restore ();
}
EnvironmentalProtectionAgency* EnvironmentalProtectionAgency::_global_epa = 0;
-EnvironmentalProtectionAgency::EnvironmentalProtectionAgency ()
+EnvironmentalProtectionAgency::EnvironmentalProtectionAgency (bool arm)
+ : _armed (arm)
{
- save ();
+ if (_armed) {
+ save ();
+ }
}
EnvironmentalProtectionAgency::~EnvironmentalProtectionAgency()
{
- restore ();
+ if (_armed) {
+ restore ();
+ }
+}
+
+void
+EnvironmentalProtectionAgency::arm ()
+{
+ _armed = true;
}
void
}
}
void
-EnvironmentalProtectionAgency::restore ()
+EnvironmentalProtectionAgency::restore () const
{
- for (map<string,string>::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);
}
class EnvironmentalProtectionAgency {
public:
- EnvironmentalProtectionAgency ();
+ EnvironmentalProtectionAgency (bool arm=true);
~EnvironmentalProtectionAgency ();
- void restore ();
+ 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;
};