Basic implementation of ObjectDb and ObjectManager.  Local files can be
put as a set of fully formatted ContentObjects to the ObjectDb, and
extracted from this Db.
diff --git a/src/object-manager.cc b/src/object-manager.cc
index a2de9f1..7f66b2a 100644
--- a/src/object-manager.cc
+++ b/src/object-manager.cc
@@ -22,6 +22,7 @@
 #include "object-manager.h"
 #include "ccnx-name.h"
 #include "ccnx-common.h"
+#include "ccnx-pco.h"
 #include "object-db.h"
 
 #include <sys/stat.h>
@@ -29,6 +30,7 @@
 #include <fstream>
 #include <boost/lexical_cast.hpp>
 #include <boost/throw_exception.hpp>
+#include <boost/filesystem/fstream.hpp>
 
 using namespace Ccnx;
 using namespace boost;
@@ -37,9 +39,8 @@
 
 const int MAX_FILE_SEGMENT_SIZE = 1024;
 
-ObjectManager::ObjectManager (Ccnx::CcnxWrapperPtr ccnx, const Ccnx::Name &localDeviceName, const fs::path &folder)
+ObjectManager::ObjectManager (Ccnx::CcnxWrapperPtr ccnx, const fs::path &folder)
   : m_ccnx (ccnx)
-  , m_localDeviceName (localDeviceName)
   , m_folder (folder / ".chronoshare")
 {
   fs::create_directories (m_folder);
@@ -50,30 +51,64 @@
 }
 
 HashPtr
-ObjectManager::storeLocalFile (const fs::path &file)
+ObjectManager::localFileToObjects (const fs::path &file, const Ccnx::Name &deviceName)
 {
   HashPtr fileHash = Hash::FromFileContent (file);
   ObjectDb fileDb (m_folder, lexical_cast<string> (*fileHash));
   
-  ifstream iff (file.c_str (), std::ios::in | std::ios::binary);
-  int segment = 0;
+  fs::ifstream iff (file, std::ios::in | std::ios::binary);
+  sqlite3_int64 segment = 0;
   while (iff.good ())
     {
       char buf[MAX_FILE_SEGMENT_SIZE];
       iff.read (buf, MAX_FILE_SEGMENT_SIZE);
 
-
-      Name name (m_localDeviceName);
+      Name name (deviceName);
       name
         .appendComp ("file")
         .appendComp (fileHash->GetHash (), fileHash->GetHashBytes ())
         .appendComp (segment);
 
-      cout << *fileHash << endl;
-      cout << name << endl;
+      // cout << *fileHash << endl;
+      // cout << name << endl;
+
+      Bytes data = m_ccnx->createContentObject (name, buf, iff.gcount ());
+      fileDb.saveContentObject (deviceName, segment, data);
       
       segment ++;
     }
   
   return fileHash;
 }
+
+bool
+ObjectManager::objectsToLocalFile (/*in*/const Ccnx::Name &deviceName, /*in*/const Hash &fileHash, /*out*/ const fs::path &file)
+{
+  string hashStr = lexical_cast<string> (fileHash);
+  if (!ObjectDb::DoesExist (m_folder, deviceName, hashStr))
+    {
+      cout << "Brr" << endl;
+      // file does not exist or not all segments are available
+      return false;
+    }
+
+  fs::ofstream off (file, std::ios::out | std::ios::binary);
+  ObjectDb fileDb (m_folder, hashStr);
+
+  sqlite3_int64 segment = 0;
+  BytesPtr bytes = fileDb.fetchSegment (deviceName, 0);
+  while (bytes != BytesPtr())
+    {
+      ParsedContentObject obj (*bytes);
+      BytesPtr data = obj.contentPtr ();
+
+      off.write (reinterpret_cast<const char*> (head(*data)), data->size());
+      
+      segment ++;
+      bytes = fileDb.fetchSegment (deviceName, segment);
+    }
+
+  // permission and timestamp should be assigned somewhere else (ObjectManager has no idea about that)
+  
+  return true;
+}