From: Michal 'vorner' Vaner Date: Mon, 18 Feb 2013 12:28:04 +0000 (+0100) Subject: [2768] Interface of the ModuleCCSession::rpcCall X-Git-Tag: bind10-1.1.0beta1-release~50^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2fb30723fa35fa5a9ffae03b0715650a76a5f20a;p=thirdparty%2Fkea.git [2768] Interface of the ModuleCCSession::rpcCall --- diff --git a/src/lib/config/ccsession.h b/src/lib/config/ccsession.h index b4a44d0afd..b21fef20ee 100644 --- a/src/lib/config/ccsession.h +++ b/src/lib/config/ccsession.h @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -146,6 +147,33 @@ public: isc::Exception(file, line, what) {} }; +/// \brief Exception thrown when there's a problem with the remote call. +/// +/// This usually means either the command couldn't be called or the remote +/// side sent an error as a response. +class RPCError: public CCSessionError { +public: + RPCError(const char* file, size_t line, const char* what, int rcode) : + CCSessionError(file, line, what), + rcode_(rcode) + {} + /// \brief The error code for the error. + int rcode() const { + return (rcode_); + } +private: + int rcode_; +}; + +/// \brief Specific version of RPCError for the case the recipient of command +/// doesn't exist. +class RPCRecipientMissing: public RPCError { +public: + RPCRecipientMissing(const char* file, size_t line, const char* what) : + RPCError(file, line, what, isc::cc::CC_REPLY_NO_RECPT) + {} +}; + /// /// \brief This module keeps a connection to the command channel, /// holds configuration information, and handles messages from @@ -361,6 +389,35 @@ public: return (session_.group_recvmsg(envelope, msg, nonblock, seq)); }; + /// \brief Send a command message and wait for the answer. + /// + /// This is mostly a convenience wrapper around groupSendMsg + /// and groupRecvMsg, with some error handling. + /// + /// \param command Name of the command to call. + /// \param group Name of the remote module to call the command on. + /// \param instance Instance part of recipient address. + /// \param to The lname to send it to. Can be used to override the + /// addressing and use a direct recipient. + /// \param params Parameters for the command. Can be left NULL if + /// no parameters are needed. + /// \return Return value of the successfull remote call. It can be + /// NULL if the remote command is void function (returns nothing). + /// \throw RPCError if the call fails (for example when the other + /// side responds with error code). + /// \throw RPCRecipientMissing if the recipient doesn't exist. + /// \throw CCSessionError if some lower-level error happens (eg. + /// the response was malformed). + isc::data::ConstElementPtr rpcCall(const std::string& command, + const std::string& group, + const std::string& instance = + isc::cc::CC_INSTANCE_WILDCARD, + const std::string& to = + isc::cc::CC_TO_WILDCARD, + const isc::data::ConstElementPtr& + params = + isc::data::ConstElementPtr()); + /// \brief Forward declaration of internal data structure. /// /// This holds information about one asynchronous request to receive