summaryrefslogtreecommitdiff
path: root/lib/server/makeprotocol.pl.in
diff options
context:
space:
mode:
Diffstat (limited to 'lib/server/makeprotocol.pl.in')
-rwxr-xr-xlib/server/makeprotocol.pl.in161
1 files changed, 103 insertions, 58 deletions
diff --git a/lib/server/makeprotocol.pl.in b/lib/server/makeprotocol.pl.in
index 269ff3f5..91ba55b0 100755
--- a/lib/server/makeprotocol.pl.in
+++ b/lib/server/makeprotocol.pl.in
@@ -178,6 +178,9 @@ print CPP <<__E;
// Auto-generated file -- do not edit
#include "Box.h"
+
+#include <sstream>
+
#include "$h_filename"
#include "IOStream.h"
@@ -273,7 +276,7 @@ __E
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 @@ __E
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,6 +502,27 @@ bool ${class}IsError(int &rTypeOut, int &rSubTypeOut) const
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
}
@@ -513,11 +538,13 @@ __E
}
if($implement_filelog)
{
- my ($format,$args) = make_log_strings($cmd);
+ my ($log) = make_log_strings_framework($cmd);
print CPP <<__E;
void ${class}LogFile(const char *Action, FILE *File) const
{
- ::fprintf(File,"%s $format\\n",Action$args);
+ std::ostringstream oss;
+ oss << $log;
+ ::fprintf(File, "%s\\n", oss.str().c_str());
::fflush(File);
}
__E
@@ -620,16 +647,16 @@ protected:
__E
-my $construtor_extra = '';
-$construtor_extra .= ', mLogToSysLog(false)' if $implement_syslog;
-$construtor_extra .= ', mLogToFile(0)' if $implement_filelog;
+my $constructor_extra = '';
+$constructor_extra .= ', mLogToSysLog(false)' if $implement_syslog;
+$constructor_extra .= ', mLogToFile(0)' if $implement_filelog;
my $destructor_extra = ($type eq 'Server')?"\n\tDeleteStreamsToSend();":'';
my $prefix = $classname_base.'::';
print CPP <<__E;
$prefix$classname_base(IOStream &rStream)
- : Protocol(rStream)$construtor_extra
+ : Protocol(rStream)$constructor_extra
{
}
$prefix~$classname_base()
@@ -661,7 +688,7 @@ print CPP <<__E;
}
}
__E
-# write receieve and send functions
+# write receive and send functions
print CPP <<__E;
std::auto_ptr<$derive_objects_from> ${prefix}Receive()
{
@@ -734,51 +761,9 @@ void ${prefix}DoServer($context_class &rContext)
// Get an object from the conversation
std::auto_ptr<${derive_objects_from}> pobj(Receive());
-__E
- if($implement_syslog)
- {
- print CPP <<__E;
- if(mLogToSysLog)
- {
- pobj->LogSysLog("Receive");
- }
-__E
- }
- if($implement_filelog)
- {
- print CPP <<__E;
- if(mLogToFile != 0)
- {
- pobj->LogFile("Receive", mLogToFile);
- }
-__E
- }
- print CPP <<__E;
-
// Run the command
std::auto_ptr<${derive_objects_from}> preply((${derive_objects_from}*)(pobj->DoCommand(*this, rContext).release()));
-__E
- if($implement_syslog)
- {
- print CPP <<__E;
- if(mLogToSysLog)
- {
- preply->LogSysLog("Send");
- }
-__E
- }
- if($implement_filelog)
- {
- print CPP <<__E;
- if(mLogToFile != 0)
- {
- preply->LogFile("Send", mLogToFile);
- }
-__E
- }
- print CPP <<__E;
-
// Send the reply
Send(*(preply.get()));
@@ -824,13 +809,57 @@ if($implement_filelog || $implement_syslog)
if($implement_syslog)
{
- $fR .= qq~\tif(mLogToSysLog) { ::syslog(LOG_INFO, (Size==Protocol::ProtocolStream_SizeUncertain)?"Receiving stream, size uncertain":"Receiving stream, size %d", Size); }\n~;
- $fS .= qq~\tif(mLogToSysLog) { ::syslog(LOG_INFO, (Size==Protocol::ProtocolStream_SizeUncertain)?"Sending stream, size uncertain":"Sending stream, size %d", Size); }\n~;
+ $fR .= <<__E;
+ if(mLogToSysLog)
+ {
+ if(Size==Protocol::ProtocolStream_SizeUncertain)
+ {
+ BOX_TRACE("Receiving stream, size uncertain");
+ }
+ else
+ {
+ BOX_TRACE("Receiving stream, size " << Size);
+ }
}
+__E
+
+ $fS .= <<__E;
+ if(mLogToSysLog)
+ {
+ if(Size==Protocol::ProtocolStream_SizeUncertain)
+ {
+ BOX_TRACE("Sending stream, size uncertain");
+ }
+ else
+ {
+ BOX_TRACE("Sending stream, size " << Size);
+ }
+ }
+__E
+ }
+
if($implement_filelog)
{
- $fR .= qq~\tif(mLogToFile) { ::fprintf(mLogToFile, (Size==Protocol::ProtocolStream_SizeUncertain)?"Receiving stream, size uncertain\\n":"Receiving stream, size %d\\n", Size); ::fflush(mLogToFile); }\n~;
- $fS .= qq~\tif(mLogToFile) { ::fprintf(mLogToFile, (Size==Protocol::ProtocolStream_SizeUncertain)?"Sending stream, size uncertain\\n":"Sending stream, size %d\\n", Size); ::fflush(mLogToFile); }\n~;
+ $fR .= <<__E;
+ if(mLogToFile)
+ {
+ ::fprintf(mLogToFile,
+ (Size==Protocol::ProtocolStream_SizeUncertain)
+ ?"Receiving stream, size uncertain\\n"
+ :"Receiving stream, size %d\\n", Size);
+ ::fflush(mLogToFile);
+ }
+__E
+ $fS .= <<__E;
+ if(mLogToFile)
+ {
+ ::fprintf(mLogToFile,
+ (Size==Protocol::ProtocolStream_SizeUncertain)
+ ?"Sending stream, size uncertain\\n"
+ :"Sending stream, size %d\\n", Size);
+ ::fflush(mLogToFile);
+ }
+__E
}
print CPP <<__E;
@@ -888,11 +917,15 @@ std::auto_ptr<$classname_base$reply> ${classname_base}::Query(const $classname_b
if(preply->IsError(type, subType))
{
SetError(type, subType);
- TRACE2("Protocol: Error received %d/%d\\n", type, subType);
+ BOX_WARNING("$cmd command failed: received error " <<
+ ((${classname_base}Error&)*preply).GetMessage());
}
else
{
SetError(Protocol::UnknownError, Protocol::UnknownError);
+ BOX_WARNING("$cmd command failed: received "
+ "unexpected response type " <<
+ preply->GetType());
}
// Throw an exception
@@ -1020,10 +1053,22 @@ sub make_log_strings_framework
my ($format,$arg) = @{$log_display_types{$ty}};
$arg =~ s/VAR/m$nm/g;
- if ($format =~ m'x$')
+ if ($format eq '\\"%s\\"')
+ {
+ $arg = "\"\\\"\" << $arg << \"\\\"\"";
+ }
+ elsif ($format =~ m'x$')
{
- $arg = "std::hex << std::showbase " .
- "<< $arg << std::dec";
+ # my $width = 0;
+ # $ty =~ /^int(\d+)$/ and $width = $1 / 4;
+ $arg = "($arg == 0 ? \"0x\" : \"\") " .
+ "<< std::hex " .
+ "<< std::showbase " .
+ # "<< std::setw($width) " .
+ # "<< std::setfill('0') " .
+ # "<< std::internal " .
+ "<< $arg " .
+ "<< std::dec";
}
push @args, $arg;