Add a new object-oriented wrapper for building object references.
[cumulus.git] / store.cc
index 00fd26c..0533630 100644 (file)
--- a/store.cc
+++ b/store.cc
@@ -6,13 +6,13 @@
  * is built on top of libtar, and represents segments as TAR files and objects
  * as files within them. */
 
+#include <assert.h>
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <time.h>
-#include <uuid/uuid.h>
 
 #include <list>
 #include <set>
@@ -20,6 +20,7 @@
 #include <iostream>
 
 #include "store.h"
+#include "ref.h"
 
 using std::list;
 using std::set;
@@ -115,11 +116,7 @@ string TarSegmentStore::write_object(const char *data, size_t len, const
     if (segments.find(group) == segments.end()) {
         segment = new segment_info;
 
-        uint8_t uuid[16];
-        char uuid_buf[40];
-        uuid_generate(uuid);
-        uuid_unparse_lower(uuid, uuid_buf);
-        segment->name = uuid_buf;
+        segment->name = generate_uuid();
 
         string filename = path + "/" + segment->name + ".tar";
         segment->file = new Tarfile(filename, segment->name);
@@ -183,3 +180,33 @@ string TarSegmentStore::object_reference_to_segment(const string &object)
 {
     return object;
 }
+
+LbsObject::LbsObject()
+    : group(""), data(NULL), data_len(0), written(false)
+{
+}
+
+LbsObject::~LbsObject()
+{
+}
+
+void LbsObject::add_reference(const LbsObject *o)
+{
+    refs.insert(o->get_name());
+}
+
+void LbsObject::write(TarSegmentStore *store)
+{
+    assert(data != NULL);
+    assert(!written);
+
+    list<string> reflist;
+    for (set<string>::iterator i = refs.begin(); i != refs.end(); ++i) {
+        reflist.push_back(*i);
+    }
+
+    name = store->write_object(data, data_len, group, reflist);
+
+    written = true;
+    data = NULL;
+}