Add a new object-oriented wrapper for building object references.
[cumulus.git] / store.cc
index 804992f..0533630 100644 (file)
--- a/store.cc
+++ b/store.cc
@@ -13,7 +13,6 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <time.h>
-#include <uuid/uuid.h>
 
 #include <list>
 #include <set>
@@ -21,6 +20,7 @@
 #include <iostream>
 
 #include "store.h"
+#include "ref.h"
 
 using std::list;
 using std::set;
@@ -116,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);
@@ -196,7 +192,7 @@ LbsObject::~LbsObject()
 
 void LbsObject::add_reference(const LbsObject *o)
 {
-    // TODO: Implement
+    refs.insert(o->get_name());
 }
 
 void LbsObject::write(TarSegmentStore *store)
@@ -204,7 +200,12 @@ void LbsObject::write(TarSegmentStore *store)
     assert(data != NULL);
     assert(!written);
 
-    name = store->write_object(data, data_len, group);
+    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;