Changeset 2172


Ignore:
Timestamp:
28/05/2008 13:33:42 (4 years ago)
Author:
chris
Message:

Add a GetMessage?() method to Protocol objects to return a stringified
message as a string.

Fix a typo in a comment.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/server/makeprotocol.pl.in

    r2084 r2172  
    179179 
    180180#include "Box.h" 
     181 
     182#include <sstream> 
     183 
    181184#include "$h_filename" 
    182185#include "IOStream.h" 
     
    274277if($derive_objects_from ne 'ProtocolObject') 
    275278{        
    276         # output a definition for the protocol object derviced class 
     279        # output a definition for the protocol object derived class 
    277280        print H <<__E; 
    278281class ${protocol_name}ProtocolServer; 
     
    339342        { 
    340343                print H "\tbool IsError(int &rTypeOut, int &rSubTypeOut) const;\n"; 
     344                print H "\tstd::string GetMessage() const;\n"; 
    341345        } 
    342346        if($type eq 'Server' && obj_is_type($cmd, 'Command')) 
     
    498502        rSubTypeOut = m$mem_subtype; 
    499503        return true; 
     504} 
     505std::string ${class}GetMessage() const 
     506{ 
     507        switch(m$mem_subtype) 
     508        { 
     509__E 
     510                foreach my $const (@{$cmd_constants{$cmd}}) 
     511                { 
     512                        next unless $const =~ /^Err_(.*)/; 
     513                        my $shortname = $1; 
     514                        $const =~ s/ = .*//; 
     515                        print CPP <<__E; 
     516                case $const: return "$shortname"; 
     517__E 
     518                } 
     519                print CPP <<__E; 
     520                default: 
     521                        std::ostringstream out; 
     522                        out << "Unknown subtype " << m$mem_subtype; 
     523                        return out.str(); 
     524        } 
    500525} 
    501526__E 
     
    891916                { 
    892917                        SetError(type, subType); 
    893                         BOX_WARNING("Protocol: Received error " << type << 
    894                                 "/" << subType); 
     918                        BOX_WARNING("$cmd command failed: received error " << 
     919                                ((${classname_base}Error&)*preply).GetMessage()); 
    895920                } 
    896921                else 
    897922                { 
    898923                        SetError(Protocol::UnknownError, Protocol::UnknownError); 
    899                         BOX_WARNING("Protocol: Received unknown error"); 
     924                        BOX_WARNING("$cmd command failed: received " 
     925                                "unexpected response type " << 
     926                                preply->GetType()); 
    900927                } 
    901928                 
Note: See TracChangeset for help on using the changeset viewer.