00001
00002
00003
00005
00006
00008 #include "Config/ConfigEditor.h"
00009 #include "Config/Config.h"
00010 #include "Config/Table.h"
00011 #include "Config/Observer.h"
00012 #include "Config/Exception.h"
00013 #include <cstdlib>
00014 extern "C" {
00015 #include <unistd.h>
00016 }
00017
00018
00019
00020 cfg::ConfigEditor::ConfigEditor(cfg::Config* config) :
00021 fNewConfig ( false ),
00022 fConfig ( config ),
00023 fConfigCopy( 0 )
00024 { }
00025
00026
00027
00028 cfg::ConfigEditor::~ConfigEditor()
00029 {
00030
00031
00032
00033 if (fConfigCopy) { delete fConfigCopy; fConfigCopy = 0; }
00034 }
00035
00036
00037
00038 void cfg::ConfigEditor::Edit()
00039 {
00040
00041
00042
00043
00044
00045 if (fConfig->EditOK()==false) return;
00046
00047
00048 fConfigCopy = new cfg::Config(fConfig->GetName(),"dummy","dummy");
00049 cfg::Config::Copy(*fConfigCopy,
00050 *fConfig,
00051 fConfig->GetVersion(),
00052 fConfig->GetSource());
00053
00054
00055 int apply = this->EditConfig(*fConfig);
00056
00057
00058 if (apply==0) this->Cancel();
00059 else this->Apply();
00060 }
00061
00062
00063
00064 int cfg::ConfigEditor::EditConfig(cfg::Config& )
00065 {
00066
00067
00068
00069 return 0;
00070
00071 }
00072
00073
00074
00075 void cfg::ConfigEditor::Apply()
00076 {
00077
00078
00079
00080 cfg::Table& t = cfg::Table::Instance();
00081
00082
00083 if (fNewConfig) t.AdoptConfig(fConfig);
00084
00085
00086
00087 cfg::Table::ObsList olist;
00088 t.GetObservers(fConfig->GetName(), fConfig->GetVersion(), olist);
00089
00090 cfg::Table::ObsList::iterator itr(olist.begin());
00091 cfg::Table::ObsList::iterator itrEnd(olist.end());
00092 for (; itr!=itrEnd; ++itr) try {(*itr)->Update(*fConfig); }
00093 catch (cfg::Exception e) {
00094 std::cout << " *-> " << fConfig->GetName() << "."
00095 << fConfig->GetVersion() << " ";
00096 e.Print();
00097 exit(-1);
00098 }
00099 }
00100
00101
00102
00103 void cfg::ConfigEditor::Reset()
00104 {
00105
00106
00107
00108 cfg::Config::Copy(*fConfig,
00109 *fConfigCopy,
00110 fConfigCopy->GetVersion(),
00111 fConfigCopy->GetSource());
00112 }
00113
00114
00115
00116 void cfg::ConfigEditor::Cancel()
00117 {
00118
00119
00120
00121 cfg::Config::Copy(*fConfig,
00122 *fConfigCopy,
00123 fConfigCopy->GetVersion(),
00124 fConfigCopy->GetSource());
00125 if (fNewConfig) { delete fConfig; fConfig = 0; }
00126 }
00127