Commit 4602105d authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

sip: move transport state change C++ trampoline

- move tp_state_callback from SipTransportBroker to SIPVoIPLink.
- install/deinstall it in SIPVoIPLink constructor/destructor.

Rationale:
It's a endpoint related callback and SIPVoIPLink is the endpoint manager.

Refs

Change-Id: Iea2fdf1a7ce8681bc0cdf732eb6033314cb2cdf9
parent 83e18d59
......@@ -167,13 +167,6 @@ SipTransportBroker::SipTransportBroker(pjsip_endpoint *endpt,
pj_caching_pool& cp, pj_pool_t& pool)
: cp_(cp), pool_(pool), endpt_(endpt)
{
auto status = pjsip_tpmgr_set_state_cb(pjsip_endpt_get_tpmgr(endpt_),
SipTransportBroker::tp_state_callback);
if (status != PJ_SUCCESS) {
RING_ERR("Can't set transport callback");
sip_utils::sip_strerror(status);
}
#if HAVE_DHT
pjsip_transport_register_type(PJSIP_TRANSPORT_DATAGRAM, "ICE",
pjsip_transport_get_default_port_for_type(PJSIP_TRANSPORT_UDP),
......@@ -186,7 +179,6 @@ SipTransportBroker::~SipTransportBroker()
RING_DBG("~SipTransportBroker@%p", this);
shutdown();
pjsip_tpmgr_set_state_cb(pjsip_endpt_get_tpmgr(endpt_), nullptr);
udpTransports_.clear();
transports_.clear();
......@@ -202,23 +194,6 @@ SipTransportBroker::~SipTransportBroker()
RING_DBG("destroying SipTransportBroker@%p", this);
}
/** static method (so C callable) used by PJSIP making interface to C++ */
void
SipTransportBroker::tp_state_callback(pjsip_transport* tp,
pjsip_transport_state state,
const pjsip_transport_state_info* info)
{
// There is no way (at writing) to link a user data to a PJSIP transport.
// So we obtain it from the global SIPVoIPLink instance that owns it.
// Be sure the broker's owner is not deleted during proccess
if (auto sipLink = getSIPVoIPLink()) {
if (auto& broker = sipLink->sipTransportBroker)
broker->transportStateChanged(tp, state, info);
else
RING_ERR("SIPVoIPLink with invalid SipTransportBroker");
}
}
void
SipTransportBroker::transportStateChanged(pjsip_transport* tp,
pjsip_transport_state state,
......
......@@ -172,6 +172,8 @@ public:
*/
void shutdown();
void transportStateChanged(pjsip_transport*, pjsip_transport_state, const pjsip_transport_state_info*);
private:
NON_COPYABLE(SipTransportBroker);
......@@ -183,10 +185,6 @@ private:
*/
std::shared_ptr<SipTransport> createUdpTransport(const SipTransportDescr&);
static void tp_state_callback(pjsip_transport*, pjsip_transport_state, const pjsip_transport_state_info*);
void transportStateChanged(pjsip_transport*, pjsip_transport_state, const pjsip_transport_state_info*);
/**
* List of transports so we can bubble the events up.
*/
......
......@@ -463,6 +463,22 @@ transaction_request_cb(pjsip_rx_data *rdata)
return PJ_FALSE;
}
static void
tp_state_callback(pjsip_transport* tp, pjsip_transport_state state,
const pjsip_transport_state_info* info)
{
// There is no way (at writing) to link a user data to a PJSIP transport.
// So we obtain it from the global SIPVoIPLink instance that owns it.
// Be sure the broker's owner is not deleted during proccess
if (auto sipLink = getSIPVoIPLink()) {
if (auto& broker = sipLink->sipTransportBroker)
broker->transportStateChanged(tp, state, info);
else
RING_ERR("SIPVoIPLink with invalid SipTransportBroker");
} else
RING_ERR("no more VoIP link");
}
/*************************************************************************************************/
pjsip_endpoint * SIPVoIPLink::getEndpoint()
......@@ -513,6 +529,13 @@ SIPVoIPLink::SIPVoIPLink()
sipTransportBroker.reset(new SipTransportBroker(endpt_, *cp_, *pool_));
auto status = pjsip_tpmgr_set_state_cb(pjsip_endpt_get_tpmgr(endpt_),
tp_state_callback);
if (status != PJ_SUCCESS) {
RING_ERR("Can't set transport callback");
sip_utils::sip_strerror(status);
}
if (!ip_utils::getLocalAddr())
throw VoipLinkException("UserAgent: Unable to determine network capabilities");
......@@ -594,6 +617,8 @@ SIPVoIPLink::~SIPVoIPLink()
RING_ERR("%d SIP calls remains!",
Manager::instance().callFactory.callCount<SIPCall>());
pjsip_tpmgr_set_state_cb(pjsip_endpt_get_tpmgr(endpt_), nullptr);
// destroy SIP transport before endpoint
sipTransportBroker.reset();
......
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