00001 #include <config/Configuration.h>
00002
00003
00004
00005
00006 #include <boost/bind.hpp>
00007 #include <boost/thread.hpp>
00008
00009 #include "DAL/Partition.h"
00010
00011 static void cb1(const std::vector<ConfigurationChange *> & changes, void * dummyParameter);
00012 static std::string buildString(std::string base, int number);
00013
00014 void changeThread(Configuration &conf) {
00015 ConfigurationSubscriptionCriteria crit;
00016
00017 Configuration::CallbackId callback = conf.subscribe(crit, cb1, NULL, true);
00018 }
00019
00020 int main() {
00021 Configuration conf("oksconfig");
00022
00023 std::list<std::string> includes;
00024 includes.push_back("sectorSchema.xml");
00025
00026
00027 const char * db_name = "test-data3.xml";
00028 if(conf.create("", db_name, includes) == false) {
00029 std::cerr << "ERROR: failed to create file \'" << db_name << "\'\n";
00030 conf.abort();
00031 }
00032
00033
00034
00035
00036
00037
00038 const SCTDAL::Partition * host = conf.create<SCTDAL::Partition>(db_name, "partition-1");
00039 if(host == 0) {
00040 std::cerr << "ERROR: failed to create object \'host-1\' at \'" << db_name << "\'\n";
00041 }
00042 else {
00043 if(conf.create<SCTDAL::Partition>(*host, "partition-2") == 0) {
00044 std::cerr << "ERROR: failed to create object \'host-2\' at file of " << host;
00045 }
00046 }
00047
00048 conf.check_notification();
00049
00050 bool success = true;
00051
00052 if(success) {
00053 std::cout << "commit changes\n";
00054 conf.commit();
00055 }
00056 else {
00057 std::cout << "ERROR: something was wrong, abort changes\n";
00058 conf.abort();
00059 }
00060
00061
00062 const_cast<SCTDAL::Partition*>(host)->set_name("Hello world");
00063 conf.check_notification();
00064
00065 conf.commit();
00066 conf.check_notification();
00067
00068
00069 std::cout << "Leaving...\n";
00070 }
00071
00076 static void cb1(const std::vector<ConfigurationChange *> & changes, void * dummyParameter) {
00077 std::cout << "CALLBACK 1 (report all changes):\n";
00078
00079 for(std::vector<ConfigurationChange *>::const_iterator j = changes.begin();
00080 j != changes.end(); ++j) {
00081
00082 const std::string& class_name = (*j)->get_class_name();
00083 std::cout << "- there are changes in class \"" << class_name << "\"\n";
00084 std::vector<std::string>::const_iterator i;
00085
00086 for(i = (*j)->get_modified_objs().begin();
00087 i != (*j)->get_modified_objs().end(); ++i) {
00088 std::cout << " * object \"" << *i << "\" was modified\n";
00089 }
00090
00091 for(i = (*j)->get_removed_objs().begin();
00092 i != (*j)->get_removed_objs().end(); ++i) {
00093 std::cout << " * object \"" << *i << "\" was removed\n";
00094 }
00095
00096 for(std::vector<std::string>::const_iterator i = (*j)->get_created_objs().begin(); i != (*j)->get_created_objs().end(); ++i) {
00097 std::cout << " * object \"" << *i << "\" was created\n";
00098 }
00099 }
00100 }
00101