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