]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added factory for snapper
authorArvin Schnell <aschnell@suse.de>
Fri, 4 Feb 2011 08:42:14 +0000 (09:42 +0100)
committerArvin Schnell <aschnell@suse.de>
Fri, 4 Feb 2011 08:42:14 +0000 (09:42 +0100)
examples/Create.cc
examples/List.cc
snapper/Factory.cc [new file with mode: 0644]
snapper/Factory.h [new file with mode: 0644]
snapper/File.cc
snapper/Makefile.am
snapper/Snapper.cc
snapper/Snapper.h
tools/snapper.cc

index f2edc057bd1636ed3bcb41e20beb4c58415a9342..b509c37d3800ff7cc43fb6775e417d0bb57c5348 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <iostream>
 
+#include <snapper/Factory.h>
 #include <snapper/Snapper.h>
 
 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);
 }
index d24a499d2984094c1f30851746cd59636fdac7dc..cbc8d758ff4eb0d08caac91e9f71b23e87bebc7a 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <iostream>
 
+#include <snapper/Factory.h>
 #include <snapper/Snapper.h>
 
 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 (file)
index 0000000..e310164
--- /dev/null
@@ -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<Snapper> 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 (file)
index 0000000..c0932d9
--- /dev/null
@@ -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*);
+
+}
index 2c85c79062de0aa27f40bf1ed4a8018197111045..1e97918423f5b6b9041f80075f976d123013e361 100644 (file)
@@ -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"
index 75860f207652ef4f38d0df72d8150afe0e6a9510..3bccaeb968a1ff601a0f5fb5db0c298aa02c6248 100644 (file)
@@ -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
 
index 115a0ba80e92a40c9df09b9c2ede6a49d31128a4..308e343ff13ae7fd336889b045e0ddf35271ca58 100644 (file)
@@ -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)
     {
index 3648c6ebe5ef91bb2db7d0aae47919a2263a6758..52e2b314b8ae500f3b3c93a7737ed70635be5866 100644 (file)
@@ -84,9 +84,6 @@ namespace snapper
 
     };
 
-
-    Snapper* getSnapper();
-
 };
 
 
index ddde0c3388504320cbc225e999b1e2957068f155..491f8f3ef9c153fa30ae5975e813f56c4f5eccc1 100644 (file)
@@ -3,6 +3,7 @@
 #include <getopt.h>
 #include <iostream>
 
+#include <snapper/Factory.h>
 #include <snapper/Snapper.h>
 #include <snapper/Snapshot.h>
 #include <snapper/File.h>
@@ -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);
 }