[Box Backup-commit] COMMIT r2172 - box/trunk/lib/server

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Wed, 28 May 2008 13:33:42 +0100 (BST)


Author: chris
Date: 2008-05-28 13:33:42 +0100 (Wed, 28 May 2008)
New Revision: 2172

Modified:
   box/trunk/lib/server/makeprotocol.pl.in
Log:
Add a GetMessage() method to Protocol objects to return a stringified 
message as a string.

Fix a typo in a comment.


Modified: box/trunk/lib/server/makeprotocol.pl.in
===================================================================
--- box/trunk/lib/server/makeprotocol.pl.in	2008-05-28 12:15:56 UTC (rev 2171)
+++ box/trunk/lib/server/makeprotocol.pl.in	2008-05-28 12:33:42 UTC (rev 2172)
@@ -178,6 +178,9 @@
 // Auto-generated file -- do not edit
 
 #include "Box.h"
+
+#include <sstream>
+
 #include "$h_filename"
 #include "IOStream.h"
 
@@ -273,7 +276,7 @@
 
 if($derive_objects_from ne 'ProtocolObject')
 {	
-	# output a definition for the protocol object derviced class
+	# output a definition for the protocol object derived class
 	print H <<__E;
 class ${protocol_name}ProtocolServer;
 	
@@ -338,6 +341,7 @@
 	if(obj_is_type($cmd,'IsError'))
 	{
 		print H "\tbool IsError(int &rTypeOut, int &rSubTypeOut) const;\n";
+		print H "\tstd::string GetMessage() const;\n";
 	}
 	if($type eq 'Server' && obj_is_type($cmd, 'Command'))
 	{
@@ -498,8 +502,29 @@
 	rSubTypeOut = m$mem_subtype;
 	return true;
 }
+std::string ${class}GetMessage() const
+{
+	switch(m$mem_subtype)
+	{
 __E
+		foreach my $const (@{$cmd_constants{$cmd}})
+		{
+			next unless $const =~ /^Err_(.*)/;
+			my $shortname = $1;
+			$const =~ s/ = .*//;
+			print CPP <<__E;
+		case $const: return "$shortname";
+__E
+		}
+		print CPP <<__E;
+		default:
+			std::ostringstream out;
+			out << "Unknown subtype " << m$mem_subtype;
+			return out.str();
 	}
+}
+__E
+	}
 
 	if($implement_syslog)
 	{
@@ -890,13 +915,15 @@
 		if(preply->IsError(type, subType))
 		{
 			SetError(type, subType);
-			BOX_WARNING("Protocol: Received error " << type <<
-				"/" << subType);
+			BOX_WARNING("$cmd command failed: received error " <<
+				((${classname_base}Error&)*preply).GetMessage());
 		}
 		else
 		{
 			SetError(Protocol::UnknownError, Protocol::UnknownError);
-			BOX_WARNING("Protocol: Received unknown error");
+			BOX_WARNING("$cmd command failed: received "
+				"unexpected response type " <<
+				preply->GetType());
 		}
 		
 		// Throw an exception