[Box Backup-commit] COMMIT r3380 - in box/trunk: bin/bbackupd bin/bbackupquery lib/server test/bbackupd

subversion at boxbackup.org subversion at boxbackup.org
Thu Sep 4 02:36:19 BST 2014


Author: chris
Date: 2014-09-04 02:36:19 +0100 (Thu, 04 Sep 2014)
New Revision: 3380

Modified:
   box/trunk/bin/bbackupd/BackupClientContext.cpp
   box/trunk/bin/bbackupd/BackupClientContext.h
   box/trunk/bin/bbackupd/BackupClientDeleteList.cpp
   box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp
   box/trunk/bin/bbackupquery/BackupQueries.cpp
   box/trunk/bin/bbackupquery/BackupQueries.h
   box/trunk/bin/bbackupquery/CommandCompletion.cpp
   box/trunk/lib/server/makeprotocol.pl.in
   box/trunk/test/bbackupd/testbbackupd.cpp
Log:
Changed many uses of BackupProtocolClient to BackupProtocolCallable.

Makes way for more use of local protocol objects and protocol subclasses.

Merged back changes from the test refactor branch to reduce diffs.

Modified: box/trunk/bin/bbackupd/BackupClientContext.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupClientContext.cpp	2014-09-04 01:36:15 UTC (rev 3379)
+++ box/trunk/bin/bbackupd/BackupClientContext.cpp	2014-09-04 01:36:19 UTC (rev 3380)
@@ -107,7 +107,7 @@
 //		Created: 2003/10/08
 //
 // --------------------------------------------------------------------------
-BackupProtocolClient &BackupClientContext::GetConnection()
+BackupProtocolCallable &BackupClientContext::GetConnection()
 {
 	// Already got it? Just return it.
 	if(mapConnection.get())
@@ -144,10 +144,14 @@
 			apSocket.reset(mpNice);
 		}
 
-		mapConnection.reset(new BackupProtocolClient(apSocket));
+		// We need to call some methods that aren't defined in
+		// BackupProtocolCallable, so we need to hang onto a more
+		// strongly typed pointer (to avoid far too many casts).
+		BackupProtocolClient *pClient = new BackupProtocolClient(apSocket);
+		mapConnection.reset(pClient);
 
 		// Set logging option
-		mapConnection->SetLogToSysLog(mExtendedLogging);
+		pClient->SetLogToSysLog(mExtendedLogging);
 
 		if (mExtendedLogToFile)
 		{
@@ -163,12 +167,12 @@
 			}
 			else
 			{
-				mapConnection->SetLogToFile(mpExtendedLogFileHandle);
+				pClient->SetLogToFile(mpExtendedLogFileHandle);
 			}
 		}
 
 		// Handshake
-		mapConnection->Handshake();
+		pClient->Handshake();
 
 		// Check the version of the server
 		{
@@ -405,7 +409,7 @@
 	bool &rIsCurrentVersionOut, box_time_t *pModTimeOnServer, box_time_t *pAttributesHashOnServer, BackupStoreFilenameClear *pLeafname)
 {
 	// Make a connection to the server
-	BackupProtocolClient &connection(GetConnection());
+	BackupProtocolCallable &connection(GetConnection());
 
 	// Request filenames from the server, in a "safe" manner to ignore errors properly
 	{

Modified: box/trunk/bin/bbackupd/BackupClientContext.h
===================================================================
--- box/trunk/bin/bbackupd/BackupClientContext.h	2014-09-04 01:36:15 UTC (rev 3379)
+++ box/trunk/bin/bbackupd/BackupClientContext.h	2014-09-04 01:36:19 UTC (rev 3380)
@@ -58,7 +58,7 @@
 	BackupClientContext(const BackupClientContext &);
 public:
 
-	BackupProtocolClient &GetConnection();
+	virtual BackupProtocolCallable &GetConnection();
 	void CloseAnyOpenConnection();
 	int GetTimeout() const;
 	BackupClientDeleteList &GetDeleteList();
@@ -223,7 +223,7 @@
 	std::string mHostname;
 	int mPort;
 	uint32_t mAccountNumber;
-	std::auto_ptr<BackupProtocolClient> mapConnection;
+	std::auto_ptr<BackupProtocolCallable> mapConnection;
 	bool mExtendedLogging;
 	bool mExtendedLogToFile;
 	std::string mExtendedLogFile;

Modified: box/trunk/bin/bbackupd/BackupClientDeleteList.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupClientDeleteList.cpp	2014-09-04 01:36:15 UTC (rev 3379)
+++ box/trunk/bin/bbackupd/BackupClientDeleteList.cpp	2014-09-04 01:36:19 UTC (rev 3380)
@@ -132,7 +132,7 @@
 	}
 	
 	// Get a connection
-	BackupProtocolClient &connection(rContext.GetConnection());
+	BackupProtocolCallable &connection(rContext.GetConnection());
 	
 	// Do the deletes
 	for(std::vector<DirToDelete>::iterator i(mDirectoryList.begin());

Modified: box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp	2014-09-04 01:36:15 UTC (rev 3379)
+++ box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp	2014-09-04 01:36:19 UTC (rev 3380)
@@ -711,7 +711,7 @@
 	if(updateAttr)
 	{
 		// Get connection to store
-		BackupProtocolClient &connection(rParams.mrContext.GetConnection());
+		BackupProtocolCallable &connection(rParams.mrContext.GetConnection());
 
 		// Exception thrown if this doesn't work
 		std::auto_ptr<IOStream> attrStream(new MemBlockStream(attr));
@@ -898,7 +898,7 @@
 							// Therefore we can safely rename it to this new file.
 
 							// Get the connection to the server 
-							BackupProtocolClient &connection(rContext.GetConnection());
+							BackupProtocolCallable &connection(rContext.GetConnection());
 
 							// Only do this step if there is room on the server.
 							// This step will be repeated later when there is space available
@@ -1169,7 +1169,7 @@
 			// been downloaded, and the entry will be available.
 
 			// Get connection
-			BackupProtocolClient &connection(rContext.GetConnection());
+			BackupProtocolCallable &connection(rContext.GetConnection());
 
 			// Only do this step if there is room on the server.
 			// This step will be repeated later when there is
@@ -1327,7 +1327,7 @@
 		{
 			// Entry exists, but is not a directory. Bad.
 			// Get rid of it.
-			BackupProtocolClient &connection(rContext.GetConnection());
+			BackupProtocolCallable &connection(rContext.GetConnection());
 			connection.QueryDeleteFile(mObjectID /* in directory */, storeFilename);
 
 			std::string filenameClear = DecryptFilename(en,
@@ -1577,7 +1577,7 @@
 	}
 
 	// Get connection
-	BackupProtocolClient &connection(rParams.mrContext.GetConnection());
+	BackupProtocolCallable &connection(rParams.mrContext.GetConnection());
 
 	// Don't do a check for storage limit exceeded here, because if we get to this
 	// stage, a connection will have been opened, and the status known, so the check
@@ -1668,7 +1668,7 @@
 	const std::string &rFilename)
 {
 	// First, delete the directory
-	BackupProtocolClient &connection(rParams.mrContext.GetConnection());
+	BackupProtocolCallable &connection(rParams.mrContext.GetConnection());
 	connection.QueryDeleteDirectory(pEntry->GetObjectID());
 
 	BackupStoreFilenameClear clear(pEntry->GetName());
@@ -1720,7 +1720,7 @@
 	ProgressNotifier& rNotifier(rContext.GetProgressNotifier());
 
 	// Get the connection
-	BackupProtocolClient &connection(rContext.GetConnection());
+	BackupProtocolCallable &connection(rContext.GetConnection());
 
 	// Info
 	int64_t objID = 0;

Modified: box/trunk/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.cpp	2014-09-04 01:36:15 UTC (rev 3379)
+++ box/trunk/bin/bbackupquery/BackupQueries.cpp	2014-09-04 01:36:19 UTC (rev 3380)
@@ -72,7 +72,7 @@
 //		Created: 2003/10/10
 //
 // --------------------------------------------------------------------------
-BackupQueries::BackupQueries(BackupProtocolClient &rConnection,
+BackupQueries::BackupQueries(BackupProtocolCallable &rConnection,
 	const Configuration &rConfiguration, bool readWrite)
 	: mReadWrite(readWrite),
 	  mrConnection(rConnection),

Modified: box/trunk/bin/bbackupquery/BackupQueries.h
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.h	2014-09-04 01:36:15 UTC (rev 3379)
+++ box/trunk/bin/bbackupquery/BackupQueries.h	2014-09-04 01:36:19 UTC (rev 3380)
@@ -18,7 +18,7 @@
 #include "BoxBackupCompareParams.h"
 #include "BackupStoreDirectory.h"
 
-class BackupProtocolClient;
+class BackupProtocolCallable;
 class Configuration;
 class ExcludeList;
 
@@ -55,7 +55,7 @@
 class BackupQueries
 {
 public:
-	BackupQueries(BackupProtocolClient &rConnection,
+	BackupQueries(BackupProtocolCallable &rConnection,
 		const Configuration &rConfiguration,
 		bool readWrite);
 	~BackupQueries();
@@ -396,7 +396,7 @@
 
 private:
 	bool mReadWrite;
-	BackupProtocolClient &mrConnection;
+	BackupProtocolCallable &mrConnection;
 	const Configuration &mrConfiguration;
 	bool mQuitNow;
 	std::vector<std::pair<std::string, int64_t> > mDirStack;
@@ -407,14 +407,14 @@
 
 typedef std::vector<std::string> (*CompletionHandler)
 	(BackupQueries::ParsedCommand& rCommand, const std::string& prefix,
-	BackupProtocolClient& rProtocol, const Configuration& rConfig,
+	BackupProtocolCallable& rProtocol, const Configuration& rConfig,
 	BackupQueries& rQueries);
 
 std::vector<std::string> CompleteCommand(BackupQueries::ParsedCommand& rCommand,
-	const std::string& prefix, BackupProtocolClient& rProtocol,
+	const std::string& prefix, BackupProtocolCallable& rProtocol,
 	const Configuration& rConfig, BackupQueries& rQueries);
 std::vector<std::string> CompleteOptions(BackupQueries::ParsedCommand& rCommand,
-	const std::string& prefix, BackupProtocolClient& rProtocol,
+	const std::string& prefix, BackupProtocolCallable& rProtocol,
 	const Configuration& rConfig, BackupQueries& rQueries);
 
 #define MAX_COMPLETION_HANDLERS 4

Modified: box/trunk/bin/bbackupquery/CommandCompletion.cpp
===================================================================
--- box/trunk/bin/bbackupquery/CommandCompletion.cpp	2014-09-04 01:36:15 UTC (rev 3379)
+++ box/trunk/bin/bbackupquery/CommandCompletion.cpp	2014-09-04 01:36:19 UTC (rev 3380)
@@ -45,7 +45,7 @@
 std::vector<std::string> Complete ## name( \
 	BackupQueries::ParsedCommand& rCommand, \
 	const std::string& prefix, \
-	BackupProtocolClient& rProtocol, const Configuration& rConfig, \
+	BackupProtocolCallable& rProtocol, const Configuration& rConfig, \
 	BackupQueries& rQueries) \
 { \
 	std::vector<std::string> completions; \
@@ -170,7 +170,7 @@
 
 std::vector<std::string> CompleteRemoteFileOrDirectory(
 	BackupQueries::ParsedCommand& rCommand,
-	const std::string& prefix, BackupProtocolClient& rProtocol,
+	const std::string& prefix, BackupProtocolCallable& rProtocol,
 	BackupQueries& rQueries, int16_t includeFlags)
 {
 	std::vector<std::string> completions;

Modified: box/trunk/lib/server/makeprotocol.pl.in
===================================================================
--- box/trunk/lib/server/makeprotocol.pl.in	2014-09-04 01:36:15 UTC (rev 3379)
+++ box/trunk/lib/server/makeprotocol.pl.in	2014-09-04 01:36:19 UTC (rev 3380)
@@ -216,6 +216,7 @@
 my $client_server_base_class = $protocol_name."ProtocolClientServer";
 my $replyable_base_class = $protocol_name."ProtocolReplyable";
 my $callable_base_class = $protocol_name."ProtocolCallable";
+my $send_receive_class = $protocol_name."ProtocolSendReceive";
 
 print H <<__E;
 class $custom_protocol_subclass;
@@ -241,6 +242,12 @@
 {
 };
 
+class $send_receive_class {
+public:
+	virtual void Send(const $message_base_class &rObject) = 0;
+	virtual std::auto_ptr<$message_base_class> Receive() = 0;
+};
+
 class $custom_protocol_subclass : public Protocol
 {
 public:
@@ -740,7 +747,8 @@
 # the callable protocol interface (implemented by Client and Local classes)
 # with Query methods that don't take a context parameter
 print H <<__E;
-class $callable_base_class : public virtual $client_server_base_class
+class $callable_base_class : public virtual $client_server_base_class,
+	public $send_receive_class
 {
 public:
 	virtual int GetTimeout() = 0;
@@ -837,15 +845,13 @@
 	$server_or_client_class($context_class &rContext);
 __E
 	}
-	else
-	{
-		print H <<__E;
+
+	print H <<__E;
 	$server_or_client_class(std::auto_ptr<SocketStream> apConn);
 	std::auto_ptr<$message_base_class> Receive();
 	void Send(const $message_base_class &rObject);
 __E
-	}
-	
+
 	if($writing_server)
 	{
 		# need to put in the conversation function
@@ -877,6 +883,7 @@
 		print H <<__E;
 private:
 	$context_class &mrContext;
+	std::auto_ptr<$message_base_class> mapLastReply;
 public:
 	virtual std::auto_ptr<IOStream> ReceiveStream()
 	{
@@ -971,11 +978,24 @@
 __E
 
 	# write receive and send functions
-	if(not $writing_local)
+	if($writing_local)
 	{
 		print CPP <<__E;
 std::auto_ptr<$message_base_class> $server_or_client_class\::Receive()
 {
+	return mapLastReply;
+}
+void $server_or_client_class\::Send(const $message_base_class &rObject)
+{
+	mapLastReply = rObject.DoCommand(*this, mrContext);
+}
+__E
+	}
+	else
+	{
+		print CPP <<__E;
+std::auto_ptr<$message_base_class> $server_or_client_class\::Receive()
+{
 	std::auto_ptr<$message_base_class> apReply;
 
 	try

Modified: box/trunk/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/trunk/test/bbackupd/testbbackupd.cpp	2014-09-04 01:36:15 UTC (rev 3379)
+++ box/trunk/test/bbackupd/testbbackupd.cpp	2014-09-04 01:36:19 UTC (rev 3380)
@@ -1096,7 +1096,7 @@
 	printf("\n==== Testing that ReadDirectory on nonexistent directory "
 		"does not crash\n");
 	{
-		std::auto_ptr<BackupProtocolClient> client = ConnectAndLogin(
+		std::auto_ptr<BackupProtocolCallable> client = connect_and_login(
 			context, 0 /* read-write */);
 		
 		{
@@ -1113,8 +1113,8 @@
 	printf("\n==== Testing that GetObject on nonexistent file outputs the "
 		"correct error message\n");
 	{
-		std::auto_ptr<BackupProtocolClient> connection = ConnectAndLogin(
-			context, 0 /* read-write */);
+		std::auto_ptr<BackupProtocolCallable> connection =
+			connect_and_login(context, 0 /* read-write */);
 		std::string errs;
 		std::auto_ptr<Configuration> config(
 			Configuration::LoadAndVerify
@@ -1520,8 +1520,8 @@
 		int expected_blocks_old = 6;
 #endif
 
-		std::auto_ptr<BackupProtocolClient> client =
-			ConnectAndLogin(context, 0 /* read-write */);
+		std::auto_ptr<BackupProtocolCallable> client =
+			connect_and_login(context, 0 /* read-write */);
 		TEST_THAT(check_num_files(5, expected_num_old, 0, 9));
 		TEST_THAT(check_num_blocks(*client, 10, expected_blocks_old,
 			0, 18, 28 + expected_blocks_old));
@@ -2188,9 +2188,9 @@
 		TEST_THAT(!TestFileExists("testfiles/notifyran.backup-finish.2"));
 		
 		// Did it actually get created? Should not have been!
-		std::auto_ptr<BackupProtocolClient> client =
-			ConnectAndLogin(context,
-			BackupProtocolLogin::Flags_ReadOnly);
+		std::auto_ptr<BackupProtocolCallable> client =
+			connect_and_login(context,
+				BackupProtocolLogin::Flags_ReadOnly);
 		
 		std::auto_ptr<BackupStoreDirectory> dir = 
 			ReadDirectory(*client);
@@ -2218,9 +2218,9 @@
 
 	// BLOCK
 	{
-		std::auto_ptr<BackupProtocolClient> client =
-			ConnectAndLogin(context,
-			BackupProtocolLogin::Flags_ReadOnly);
+		std::auto_ptr<BackupProtocolCallable> client =
+			connect_and_login(context,
+				BackupProtocolLogin::Flags_ReadOnly);
 		
 		std::auto_ptr<BackupStoreDirectory> dir = 
 			ReadDirectory(*client,
@@ -2260,10 +2260,10 @@
 		// not yet! should still be there
 
 		{
-			std::auto_ptr<BackupProtocolClient> client =
-				ConnectAndLogin(context,
-				BackupProtocolLogin::Flags_ReadOnly);
-			
+			std::auto_ptr<BackupProtocolCallable> client =
+				connect_and_login(context,
+					BackupProtocolLogin::Flags_ReadOnly);
+
 			std::auto_ptr<BackupStoreDirectory> dir = 
 				ReadDirectory(*client);
 			int64_t testDirId = SearchDir(*dir, "Test2");
@@ -2277,10 +2277,10 @@
 		// NOW it should be gone
 
 		{
-			std::auto_ptr<BackupProtocolClient> client =
-				ConnectAndLogin(context,
-				BackupProtocolLogin::Flags_ReadOnly);
-			
+			std::auto_ptr<BackupProtocolCallable> client =
+				connect_and_login(context,
+					BackupProtocolLogin::Flags_ReadOnly);
+
 			std::auto_ptr<BackupStoreDirectory> root_dir = 
 				ReadDirectory(*client);
 
@@ -3738,9 +3738,9 @@
 
 			printf("\n==== Resume restore\n");
 
-			std::auto_ptr<BackupProtocolClient> client = 
-				ConnectAndLogin(context,
-				BackupProtocolLogin::Flags_ReadOnly);
+			std::auto_ptr<BackupProtocolCallable> client =
+				connect_and_login(context,
+					BackupProtocolLogin::Flags_ReadOnly);
 
 			// Check that the restore fn returns resume possible,
 			// rather than doing anything




More information about the Boxbackup-commit mailing list