20 #ifndef MIR_FRONTEND_TEMPLATE_PROTOBUF_MESSAGE_PROCESSOR_H_ 21 #define MIR_FRONTEND_TEMPLATE_PROTOBUF_MESSAGE_PROCESSOR_H_ 27 #include "mir_protobuf.pb.h" 29 #include <google/protobuf/stubs/common.h> 30 #include <boost/exception/diagnostic_information.hpp> 46 { typedef ::google::protobuf::MessageLite*
type; };
50 template<
class Self,
class Server,
class ServerX,
class ParameterMessage,
class ResultMessage>
54 void (ServerX::*
function)(
55 ParameterMessage
const* request,
56 ResultMessage* response,
57 ::google::protobuf::Closure* done),
60 ParameterMessage parameter_message;
61 if (!parameter_message.ParseFromString(invocation.
parameters()))
62 BOOST_THROW_EXCEPTION(std::runtime_error(
"Failed to parse message parameters!"));
63 ResultMessage result_message;
67 std::unique_ptr<google::protobuf::Closure> callback(
68 google::protobuf::NewPermanentCallback<
70 ::google::protobuf::uint32,
88 auto client_error = result_message.mutable_structured_error();
89 client_error->set_code(error.
code());
90 client_error->set_domain(error.
domain());
91 self->send_response(invocation.
id(), &result_message);
93 catch (std::exception
const& x)
95 using namespace std::literals::string_literals;
96 result_message.set_error(
"Error processing request: "s +
97 x.what() +
"\nInternal error details: " + boost::diagnostic_information(x));
98 self->send_response(invocation.
id(), &result_message);
All things Mir.
Definition: atomic_callback.h:25
Definition: message_processor.h:40
Base class for exceptions which might be visible to clients.
Definition: client_visible_error.h:36
Customise and run a Mir server.
Definition: server.h:78
Definition: authority.h:35
google::protobuf::uint32 id() const
void invoke(Self *self, Server *server, void(ServerX::*function)(ParameterMessage const *request, ResultMessage *response,::google::protobuf::Closure *done), Invocation const &invocation)
Definition: template_protobuf_message_processor.h:51
const ::std::string & parameters() const
error
Definition: connector_report_tp.h:56
Definition: template_protobuf_message_processor.h:45
::google::protobuf::MessageLite * type
Definition: template_protobuf_message_processor.h:46
virtual uint32_t code() const noexcept=0
Error code within the domain().
virtual MirErrorDomain domain() const noexcept=0
Client-visible error domain.