From: Arvin Schnell Date: Fri, 4 Feb 2011 08:42:14 +0000 (+0100) Subject: - added factory for snapper X-Git-Tag: v0.1.3~519 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=6d6897ddf6ff72bd882e91caf9bb4c7169e7bd80;p=thirdparty%2Fsnapper.git - added factory for snapper --- diff --git a/examples/Create.cc b/examples/Create.cc index f2edc057..b509c37d 100644 --- a/examples/Create.cc +++ b/examples/Create.cc @@ -2,6 +2,7 @@ #include #include +#include #include using namespace snapper; @@ -10,7 +11,9 @@ using namespace std; int main(int argc, char** argv) { - getSnapper()->createSingleSnapshot("test"); + Snapper* sh = createSnapper(); + + sh->createSingleSnapshot("test"); exit(EXIT_SUCCESS); } diff --git a/examples/List.cc b/examples/List.cc index d24a499d..cbc8d758 100644 --- a/examples/List.cc +++ b/examples/List.cc @@ -2,6 +2,7 @@ #include #include +#include #include using namespace snapper; @@ -10,7 +11,9 @@ using namespace std; int main(int argc, char** argv) { - const Snapshots& snapshots = getSnapper()->getSnapshots(); + Snapper* sh = createSnapper(); + + const Snapshots& snapshots = sh->getSnapshots(); for (Snapshots::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it) { cout << *it << endl; diff --git a/snapper/Factory.cc b/snapper/Factory.cc new file mode 100644 index 00000000..e310164b --- /dev/null +++ b/snapper/Factory.cc @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2011 Novell, Inc. + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * 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, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#include "assert.h" +#include "auto_ptr.h" + +#include "snapper/Snapper.h" + + +namespace snapper +{ + + std::auto_ptr haha; + + + Snapper* + createSnapper() + { + assert(!haha.get()); + haha.reset(new Snapper); + return haha.get(); + } + + + Snapper* + getSnapper() + { + assert(haha.get()); + return haha.get(); + } + + + void + deleteSnapper(Snapper* s) + { + assert(haha.get()); + assert(s == haha.get()); + haha.reset(); + } + +} diff --git a/snapper/Factory.h b/snapper/Factory.h new file mode 100644 index 00000000..c0932d9a --- /dev/null +++ b/snapper/Factory.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2011 Novell, Inc. + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * 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, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#include "snapper/Snapper.h" + + +namespace snapper +{ + + // Only one Snapper can be created at a time. + + Snapper* createSnapper(); + + Snapper* getSnapper(); + + void deleteSnapper(Snapper*); + +} diff --git a/snapper/File.cc b/snapper/File.cc index 2c85c790..1e979184 100644 --- a/snapper/File.cc +++ b/snapper/File.cc @@ -27,6 +27,7 @@ #include "snapper/File.h" #include "snapper/Snapper.h" +#include "snapper/Factory.h" #include "snapper/AppUtil.h" #include "snapper/XmlFile.h" #include "snapper/Enum.h" diff --git a/snapper/Makefile.am b/snapper/Makefile.am index 75860f20..3bccaeb9 100644 --- a/snapper/Makefile.am +++ b/snapper/Makefile.am @@ -8,6 +8,7 @@ AM_CXXFLAGS = -D_FILE_OFFSET_BITS=64 libsnapper_la_SOURCES = \ Snapper.cc Snapper.h \ + Factory.cc Factory.h \ Snapshot.cc Snapshot.h \ File.cc File.h \ XmlFile.cc XmlFile.h \ @@ -15,7 +16,8 @@ libsnapper_la_SOURCES = \ AppUtil.cc AppUtil.h \ Compare.cc Compare.h \ SystemCmd.cc SystemCmd.h \ - SnapperTmpl.h SnapperDefines.h + SnapperTmpl.h \ + SnapperDefines.h libsnapper_la_LDFLAGS = -version-info 2:0 libsnapper_la_LIBADD = -lblocxx -lxml2 @@ -24,6 +26,7 @@ pkgincludedir = $(includedir)/snapper pkginclude_HEADERS = \ Snapper.h \ + Factory.h \ Snapshot.h \ File.h diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 115a0ba8..308e343f 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -40,19 +40,6 @@ namespace snapper using namespace std; - Snapper* snapper_singleton = NULL; - - - Snapper* - getSnapper() - { - if (!snapper_singleton) - snapper_singleton = new Snapper(); - - return snapper_singleton; - } - - Snapper::Snapper() : compare_callback(NULL) { diff --git a/snapper/Snapper.h b/snapper/Snapper.h index 3648c6eb..52e2b314 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -84,9 +84,6 @@ namespace snapper }; - - Snapper* getSnapper(); - }; diff --git a/tools/snapper.cc b/tools/snapper.cc index ddde0c33..491f8f3e 100644 --- a/tools/snapper.cc +++ b/tools/snapper.cc @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -197,7 +198,7 @@ main(int argc, char** argv) cmds["diff"] = showDifference; cmds["rollback"] = doRollback; - sh = getSnapper(); + sh = createSnapper(); sh->setCompareCallback(&compare_callback_impl); @@ -219,5 +220,8 @@ main(int argc, char** argv) ++cnt; } } + + deleteSnapper(sh); + exit(EXIT_SUCCESS); }