Commit 0f524801 authored by Guillaume Roguez's avatar Guillaume Roguez

PJSIP support to std::error_code and std::system_error

Some practical C++ additions:
* class PjsipErrorCategory as error category for std::error_code.
* class PjsipFailure inheriting from std::system_error exception.

Change-Id: I957cd36d06cf49ae98cb6634f5e4d5dcac666be8
parent 94a48eb9
......@@ -44,6 +44,15 @@
namespace ring { namespace sip_utils {
std::string
PjsipErrorCategory::message( int condition ) const
{
std::string err_msg;
err_msg.reserve(PJ_ERR_MSG_SIZE);
err_msg.resize(pj_strerror(condition, &err_msg[0], err_msg.size()).slen);
return err_msg;
}
std::string
fetchHeaderValue(pjsip_msg *msg, const std::string &field)
{
......
......@@ -47,6 +47,29 @@ static constexpr int DEFAULT_SIP_TLS_PORT {5061};
enum class KeyExchangeProtocol { NONE, SDES };
/// PjsipErrorCategory - a PJSIP error category for std::error_code
class PjsipErrorCategory final : public std::error_category
{
public:
const char* name() const noexcept override { return "pjsip"; }
std::string message( int condition ) const override;
};
/// PJSIP related exception
/// Based on std::system_error with code() returning std::error_code with PjsipErrorCategory category
class PjsipFailure : public std::system_error
{
private:
static constexpr const char* what_ = "PJSIP call failed";
public:
PjsipFailure()
: std::system_error(std::error_code(PJ_EUNKNOWN, PjsipErrorCategory()), what_) {}
explicit PjsipFailure(pj_status_t status)
: std::system_error(std::error_code(status, PjsipErrorCategory()), what_) {}
};
static constexpr const char* getKeyExchangeName(KeyExchangeProtocol kx) {
return kx == KeyExchangeProtocol::SDES ? "sdes" : "";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment