[Box Backup-dev] COMMIT r351 - in box/chris/bb-save-state: bin/bbackupd lib/common

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Mon, 30 Jan 2006 18:58:50 +0000 (GMT)


Author: ben
Date: 2006-01-30 18:58:48 +0000 (Mon, 30 Jan 2006)
New Revision: 351

Modified:
   box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.cpp
   box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.h
   box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp
   box/chris/bb-save-state/bin/bbackupd/BackupDaemon.h
   box/chris/bb-save-state/lib/common/Archive.h
   box/chris/bb-save-state/lib/common/ExcludeList.cpp
   box/chris/bb-save-state/lib/common/ExcludeList.h
Log:
Simplify Archive to minimum requirements, style, use class Archive; in headers

Modified: box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.cpp
===================================================================
--- box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.cpp	2006-01-29 22:40:45 UTC (rev 350)
+++ box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.cpp	2006-01-30 18:58:48 UTC (rev 351)
@@ -25,6 +25,7 @@
 #include "FileModificationTime.h"
 #include "BackupDaemon.h"
 #include "BackupStoreException.h"
+#include "Archive.h"
 
 #include "MemLeakFindOn.h"
 

Modified: box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.h
===================================================================
--- box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.h	2006-01-29 22:40:45 UTC (rev 350)
+++ box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.h	2006-01-30 18:58:48 UTC (rev 351)
@@ -18,8 +18,7 @@
 #include "BackupStoreDirectory.h"
 #include "MD5Digest.h"
 
-#include "Archive.h"
-
+class Archive;
 class BackupClientContext;
 class BackupDaemon;
 

Modified: box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp	2006-01-29 22:40:45 UTC (rev 350)
+++ box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp	2006-01-30 18:58:48 UTC (rev 351)
@@ -68,6 +68,7 @@
 #include "LocalProcessStream.h"
 #include "IOStreamGetLine.h"
 #include "Conversion.h"
+#include "Archive.h"
 
 #include "MemLeakFindOn.h"
 
@@ -1909,7 +1910,7 @@
 //		Created: 2005/04/11
 //
 // --------------------------------------------------------------------------
-void BackupDaemon::Location::Deserialize(Archive & rArchive)
+void BackupDaemon::Location::Deserialize(Archive &rArchive)
 {
 	//
 	//
@@ -2136,7 +2137,7 @@
 	{
 		FileStream aFile(StoreObjectInfoFile.c_str(), 
 			O_WRONLY | O_CREAT | O_TRUNC);
-		IOStreamArchive anArchive(aFile, 0);
+		Archive anArchive(aFile, 0);
 
 		anArchive.Write(STOREOBJECTINFO_MAGIC_ID_VALUE);
 		anArchive.Write(STOREOBJECTINFO_MAGIC_ID_STRING); 
@@ -2217,7 +2218,7 @@
 	try
 	{
 		FileStream aFile(StoreObjectInfoFile.c_str(), O_RDONLY);
-		IOStreamArchive anArchive(aFile, 0);
+		Archive anArchive(aFile, 0);
 
 		//
 		// see if the content looks like a valid serialised archive

Modified: box/chris/bb-save-state/bin/bbackupd/BackupDaemon.h
===================================================================
--- box/chris/bb-save-state/bin/bbackupd/BackupDaemon.h	2006-01-29 22:40:45 UTC (rev 350)
+++ box/chris/bb-save-state/bin/bbackupd/BackupDaemon.h	2006-01-30 18:58:48 UTC (rev 351)
@@ -14,7 +14,6 @@
 #include <string>
 #include <memory>
 
-#include "Archive.h"
 #include "BoxTime.h"
 #include "Daemon.h"
 #include "Socket.h"
@@ -28,6 +27,7 @@
 class BackupClientInodeToIDMap;
 class ExcludeList;
 class IOStreamGetLine;
+class Archive;
 
 // --------------------------------------------------------------------------
 //

Modified: box/chris/bb-save-state/lib/common/Archive.h
===================================================================
--- box/chris/bb-save-state/lib/common/Archive.h	2006-01-29 22:40:45 UTC (rev 350)
+++ box/chris/bb-save-state/lib/common/Archive.h	2006-01-30 18:58:48 UTC (rev 351)
@@ -25,166 +25,137 @@
 class Archive
 {
 public:
-	Archive()
+	Archive(IOStream &Stream, int Timeout)
+		: mrStream(Stream)
 	{
+		mTimeout = Timeout;
 	}
-	virtual ~Archive()
-	{
-	}
-	//
-	// primitive insertion operations
-	//
-	virtual void Write(bool bItem) = 0;
-	virtual void Write(int iItem) = 0;
-	virtual void Write(int64_t  iItem) = 0;
-	virtual void Write(uint64_t iItem) = 0;
-	virtual void Write(uint8_t iItem) = 0;
-	virtual void Write(const std::string & strItem) = 0;
-	//
-	// primitive extraction oprations
-	//
-	virtual void Read(bool & bItem) = 0;
-	virtual void Read(int & iItem) = 0;
-	virtual void Read(int64_t  & iItem) = 0;
-	virtual void Read(uint64_t & iItem) = 0;
-	virtual void Read(uint8_t & iItem) = 0;
-	virtual void Read(std::string & strItem) = 0;
 private:
+	// no copying
 	Archive(const Archive &);
 	Archive & operator=(const Archive &);
-};
-
-class IOStreamArchive : public Archive
-{
 public:
-	IOStreamArchive(IOStream & mStream, int Timeout) : mStream(mStream)
+	~Archive()
 	{
-		mTimeout = Timeout;
 	}
-	virtual ~IOStreamArchive()
-	{
-	}
 	//
 	//
 	//
-	virtual void Write(bool bItem)
+	void Write(bool Item)
 	{
-		Write((int) bItem);
+		Write((int) Item);
 	}
-	virtual void Write(int iItem)
+	void Write(int Item)
 	{
-		int32_t privItem = htonl(iItem);
-		mStream.Write(&privItem, sizeof(privItem));
+		int32_t privItem = htonl(Item);
+		mrStream.Write(&privItem, sizeof(privItem));
 	}
-	virtual void Write(int64_t iItem)
+	void Write(int64_t Item)
 	{
-		int64_t privItem = box_hton64(iItem);
-		mStream.Write(&privItem, sizeof(privItem));
+		int64_t privItem = box_hton64(Item);
+		mrStream.Write(&privItem, sizeof(privItem));
 	}
-	virtual void Write(uint64_t iItem)
+	void Write(uint64_t Item)
 	{
-		uint64_t privItem = box_hton64(iItem);
-		mStream.Write(&privItem, sizeof(privItem));
+		uint64_t privItem = box_hton64(Item);
+		mrStream.Write(&privItem, sizeof(privItem));
 	}
-	virtual void Write(uint8_t iItem)
+	void Write(uint8_t Item)
 	{
-		int privItem = iItem;
+		int privItem = Item;
 		Write(privItem);
 	}
-	virtual void Write(const std::string & strItem)
+	void Write(const std::string &Item)
 	{
-		int iSize = strItem.size();
-		Write(iSize);
-		mStream.Write(strItem.c_str(), iSize);
+		int size = Item.size();
+		Write(size);
+		mrStream.Write(Item.c_str(), size);
 	}
 	//
 	//
 	//
-	virtual void Read(bool & bItem)
+	void Read(bool &rItemOut)
 	{
 		int privItem;
 		Read(privItem);
 
 		if (privItem)
 		{
-			bItem = true;
+			rItemOut = true;
 		}
 		else
 		{
-			bItem = false;
+			rItemOut = false;
 		}
 	}
-	virtual void Read(int & iItem)
+	void Read(int &rItemOut)
 	{
 		int32_t privItem;
-		if(!mStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
+		if(!mrStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
 		{
 			THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead)
 		}
-		iItem = ntohl(privItem);
+		rItemOut = ntohl(privItem);
 	}
-	virtual void Read(int64_t  & iItem)
+	void Read(int64_t &rItemOut)
 	{
 		int64_t privItem;
-		if(!mStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
+		if(!mrStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
 		{
 			THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead)
 		}
-		iItem = box_ntoh64(privItem);
+		rItemOut = box_ntoh64(privItem);
 	}
-	virtual void Read(uint64_t & iItem)
+	void Read(uint64_t &rItemOut)
 	{
 		uint64_t privItem;
-		if(!mStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
+		if(!mrStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
 		{
 			THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead)
 		}
-		iItem = box_ntoh64(privItem);
+		rItemOut = box_ntoh64(privItem);
 	}
-	virtual void Read(uint8_t & iItem)
+	void Read(uint8_t &rItemOut)
 	{
 		int privItem;
 		Read(privItem);
-		iItem = privItem;
+		rItemOut = privItem;
 	}
-	virtual void Read(std::string & strItem)
+	void Read(std::string &rItemOut)
 	{
-		int iSize;
-		Read(iSize);
+		int size;
+		Read(size);
 
 		// Assume most strings are relatively small
 		char buf[256];
-		if(iSize < (int) sizeof(buf))
+		if(size < (int) sizeof(buf))
 		{
 			// Fetch rest of pPayload, relying on the Protocol to error on stupidly large sizes for us
-			if(!mStream.ReadFullBuffer(buf, iSize, 0 /* not interested in bytes read if this fails */, mTimeout))
+			if(!mrStream.ReadFullBuffer(buf, size, 0 /* not interested in bytes read if this fails */, mTimeout))
 			{
 				THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead)
 			}
-			// assign to this string, storing the header and the extra pPayload
-			strItem.assign(buf, iSize);
+			// assign to this string, storing the header and the extra payload
+			rItemOut.assign(buf, size);
 		}
 		else
 		{
 			// Block of memory to hold it
-			MemoryBlockGuard<char*> dataB(iSize);
-			char *pPayload = dataB;
+			MemoryBlockGuard<char*> dataB(size);
+			char *ppayload = dataB;
 
 			// Fetch rest of pPayload, relying on the Protocol to error on stupidly large sizes for us
-			if(!mStream.ReadFullBuffer(pPayload, iSize, 0 /* not interested in bytes read if this fails */, mTimeout))
+			if(!mrStream.ReadFullBuffer(ppayload, size, 0 /* not interested in bytes read if this fails */, mTimeout))
 			{
 				THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead)
 			}
 			// assign to this string, storing the header and the extra pPayload
-			strItem.assign(pPayload, iSize);
+			rItemOut.assign(ppayload, size);
 		}
 	}
-protected:
-	IOStream & mStream;
-	int mTimeout;
 private:
-	IOStreamArchive(const IOStreamArchive &);
-	IOStreamArchive & operator=(const IOStreamArchive &);
+	IOStream &mrStream;
+	int mTimeout;
 };
 
 #endif // ARCHIVE__H

Modified: box/chris/bb-save-state/lib/common/ExcludeList.cpp
===================================================================
--- box/chris/bb-save-state/lib/common/ExcludeList.cpp	2006-01-29 22:40:45 UTC (rev 350)
+++ box/chris/bb-save-state/lib/common/ExcludeList.cpp	2006-01-30 18:58:48 UTC (rev 351)
@@ -17,6 +17,7 @@
 #include "ExcludeList.h"
 #include "Utils.h"
 #include "Configuration.h"
+#include "Archive.h"
 
 #include "MemLeakFindOn.h"
 

Modified: box/chris/bb-save-state/lib/common/ExcludeList.h
===================================================================
--- box/chris/bb-save-state/lib/common/ExcludeList.h	2006-01-29 22:40:45 UTC (rev 350)
+++ box/chris/bb-save-state/lib/common/ExcludeList.h	2006-01-30 18:58:48 UTC (rev 351)
@@ -19,7 +19,7 @@
 	typedef int regex_t;
 #endif
 
-#include "Archive.h"
+class Archive;
 
 // --------------------------------------------------------------------------
 //