Commit f079c6f2 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

* #6554 : more *voiplink cleanup

parent f24aa899
......@@ -45,7 +45,6 @@ IAXAccount::IAXAccount (const std::string& accountID)
IAXAccount::~IAXAccount()
{
delete _link;
_link = NULL;
}
void IAXAccount::serialize (Conf::YamlEmitter *emitter)
......@@ -172,7 +171,7 @@ int IAXAccount::registerVoIPLink()
setHostname (_hostname);
setUsername (_username);
_link->sendRegister (_accountID);
_link->sendRegister (this);
}
catch(VoipLinkException &e) {
_error("IAXAccount: %s", e.what());
......@@ -185,7 +184,7 @@ int
IAXAccount::unregisterVoIPLink()
{
try {
_link->sendUnregister (_accountID);
_link->sendUnregister (this);
_link->terminate();
return 0;
......
......@@ -88,14 +88,12 @@ IAXVoIPLink::~IAXVoIPLink()
delete converter;
}
bool
void
IAXVoIPLink::init()
{
// If it was done, don't do it again, until we call terminate()
if (initDone())
return false;
bool returnValue = false;
if (_initDone)
return;
// _localAddress = "127.0.0.1";
// port 0 is default
......@@ -119,7 +117,6 @@ IAXVoIPLink::init()
} else {
_debug ("IAX Info: listening on port %d", last_port);
_localPort = last_port;
returnValue = true;
_evThread->start();
audiolayer = Manager::instance().getAudioDriver();
......@@ -132,23 +129,21 @@ IAXVoIPLink::init()
nbTry--;
initDone (true);
_initDone = true;
}
if (port == IAX_FAILURE || nbTry==0) {
_debug ("Fail to initialize iax");
initDone (false);
_initDone = false;
}
return returnValue;
}
void
IAXVoIPLink::terminate()
{
// If it was done, don't do it again, until we call init()
if (!initDone())
if (!_initDone)
return;
// iaxc_shutdown();
......@@ -156,7 +151,7 @@ IAXVoIPLink::terminate()
// Hangup all calls
terminateIAXCall();
initDone (false);
_initDone = false;
}
void
......@@ -222,16 +217,6 @@ IAXVoIPLink::getEvent()
sendAudioFromMic();
// Manager::instance().getAudioLayerMutex()->leave();
// Do the doodle-moodle to send audio from the microphone to the IAX channel.
// sendAudioFromMic();
// Refresh registration.
if (_nextRefreshStamp && _nextRefreshStamp - 2 < time (NULL)) {
sendRegister ("");
}
// thread wait 3 millisecond
_evThread->sleep (3);
......@@ -314,15 +299,11 @@ IAXVoIPLink::getIAXCall (const std::string& id)
void
IAXVoIPLink::sendRegister (std::string id UNUSED) throw(VoipLinkException)
IAXVoIPLink::sendRegister (Account *a) throw(VoipLinkException)
{
_debug ("IAX: Sending registration");
IAXAccount *account = getAccountPtr();
if (!account) {
throw VoipLinkException("Account is NULL in send register");
}
IAXAccount *account = (IAXAccount*)a;
if (account->getHostname().empty()) {
throw VoipLinkException("Account hostname is empty");
......@@ -360,15 +341,11 @@ IAXVoIPLink::sendRegister (std::string id UNUSED) throw(VoipLinkException)
}
void
IAXVoIPLink::sendUnregister (std::string id UNUSED) throw(VoipLinkException)
IAXVoIPLink::sendUnregister (Account *a)
{
_debug ("IAXVoipLink: Send unregister");
IAXAccount *account = getAccountPtr();
if (!account) {
throw VoipLinkException("Account is NULL in send unregister");
}
IAXAccount *account = (IAXAccount*)a;
_mutexIAX.enterMutex();
......@@ -410,16 +387,14 @@ IAXVoIPLink::newOutgoingCall (const std::string& id, const std::string& toUrl) t
}
bool
IAXVoIPLink::answer (const std::string& id) throw (VoipLinkException)
void
IAXVoIPLink::answer (Call *c) throw (VoipLinkException)
{
IAXCall* call = getIAXCall (id);
IAXCall* call = (IAXCall*) c;
call->setCodecMap (Manager::instance().getAudioCodecFactory());
Manager::instance().addStream (call->getCallId());
CHK_VALID_CALL;
_mutexIAX.enterMutex();
iax_answer (call->getSession());
_mutexIAX.leaveMutex();
......@@ -429,11 +404,9 @@ IAXVoIPLink::answer (const std::string& id) throw (VoipLinkException)
// Flush main buffer
audiolayer->flushMain();
return true;
}
bool
void
IAXVoIPLink::hangup (const std::string& id) throw (VoipLinkException)
{
_debug ("IAXVoIPLink: Hangup");
......@@ -443,8 +416,6 @@ IAXVoIPLink::hangup (const std::string& id) throw (VoipLinkException)
throw VoipLinkException("Could not find call");
}
CHK_VALID_CALL;
Manager::instance().getMainBuffer()->unBindAll (call->getCallId());
_mutexIAX.enterMutex();
......@@ -454,11 +425,10 @@ IAXVoIPLink::hangup (const std::string& id) throw (VoipLinkException)
call->setSession (NULL);
removeCall (id);
return true;
}
bool
void
IAXVoIPLink::peerHungup (const std::string& id) throw (VoipLinkException)
{
_debug ("IAXVoIPLink: Peer hung up");
......@@ -468,14 +438,11 @@ IAXVoIPLink::peerHungup (const std::string& id) throw (VoipLinkException)
throw VoipLinkException("Could not find call");
}
CHK_VALID_CALL;
Manager::instance().getMainBuffer()->unBindAll (call->getCallId());
call->setSession (NULL);
removeCall (id);
return true;
}
......@@ -488,8 +455,6 @@ IAXVoIPLink::onhold (const std::string& id) throw (VoipLinkException)
throw VoipLinkException("Call does not exist");
}
CHK_VALID_CALL;
Manager::instance().getMainBuffer()->unBindAll (call->getCallId());
//if (call->getState() == Call::Hold) { _debug("Call is already on hold"); return false; }
......@@ -506,7 +471,6 @@ bool
IAXVoIPLink::offhold (const std::string& id) throw (VoipLinkException)
{
IAXCall* call = getIAXCall (id);
CHK_VALID_CALL;
Manager::instance().addStream (call->getCallId());
......@@ -524,7 +488,6 @@ bool
IAXVoIPLink::transfer (const std::string& id, const std::string& to) throw (VoipLinkException)
{
IAXCall* call = getIAXCall (id);
CHK_VALID_CALL;
char callto[to.length() +1];
......@@ -551,7 +514,6 @@ bool
IAXVoIPLink::refuse (const std::string& id)
{
IAXCall* call = getIAXCall (id);
CHK_VALID_CALL;
_mutexIAX.enterMutex();
......@@ -568,7 +530,6 @@ bool
IAXVoIPLink::carryingDTMFdigits (const std::string& id, char code)
{
IAXCall* call = getIAXCall (id);
CHK_VALID_CALL;
_mutexIAX.enterMutex();
......@@ -584,7 +545,6 @@ IAXVoIPLink::sendTextMessage (sfl::InstantMessaging *module,
const std::string& /*from*/)
{
IAXCall* call = getIAXCall (callID);
CHK_VALID_CALL;
// Must active the mutex for this session
......
......@@ -78,10 +78,8 @@ class IAXVoIPLink : public VoIPLink
/**
* Init the voip link
* @return true if successful
* false otherwise
*/
virtual bool init (void);
virtual void init (void);
/**
* Terminate a voip link by clearing the call list
......@@ -90,18 +88,15 @@ class IAXVoIPLink : public VoIPLink
/**
* Send out registration
* @return bool The new registration state (are we registered ?)
*/
virtual void sendRegister (std::string id) throw(VoipLinkException);
virtual void sendRegister (Account *a) throw(VoipLinkException);
/**
* Destroy registration session
* @todo Send an IAX_COMMAND_REGREL to force unregistration upstream.
* Urgency: low
* @return bool true if we're registered upstream
* false otherwise
*/
virtual void sendUnregister (std::string id) throw(VoipLinkException);
virtual void sendUnregister (Account *a);
/**
* Create a new outgoing call
......@@ -113,37 +108,27 @@ class IAXVoIPLink : public VoIPLink
/**
* Answer a call
* @param id The ID of the call
* @return bool true on success
* false otherwise
* @param c The call
*/
virtual bool answer (const std::string& id) throw (VoipLinkException);
virtual void answer (Call *c) throw (VoipLinkException);
/**
* Hangup a call
* @param id The ID of the call
* @return bool true on success
* false otherwise
*/
virtual bool hangup (const std::string& id) throw (VoipLinkException);
virtual void hangup (const std::string& id) throw (VoipLinkException);
/**
* Peer Hungup a call
* @param id The ID of the call
* @return bool true on success
* false otherwise
*/
virtual bool peerHungup (const std::string& id) throw (VoipLinkException);
virtual void peerHungup (const std::string& id) throw (VoipLinkException);
/**
* Cancel a call
* @param id The ID of the call
* @return bool true on success
* false otherwise
*/
virtual bool cancel (const std::string& id UNUSED) throw (VoipLinkException){
return false;
}
virtual void cancel (const std::string& id UNUSED) throw (VoipLinkException){}
/**
* Put a call on hold
......
......@@ -111,7 +111,7 @@ int InstantMessaging::closeArchive (std::string& id)
return (int) imFiles.size ();
}
bool InstantMessaging::saveMessage (const std::string& message, const std::string& author, std::string& id, int mode)
bool InstantMessaging::saveMessage (const std::string& message, const std::string& author, const std::string& id, int mode)
{
// We need here to write the text message in the right file.
......@@ -158,7 +158,7 @@ pj_status_t InstantMessaging::notify (const std::string& /*id*/)
return PJ_SUCCESS;
}
pj_status_t InstantMessaging::sip_send (pjsip_inv_session *session, std::string& id, const std::string& text)
pj_status_t InstantMessaging::sip_send (pjsip_inv_session *session, const std::string& id, const std::string& text)
{
pjsip_method msg_method;
......@@ -219,7 +219,7 @@ pj_status_t InstantMessaging::sip_send (pjsip_inv_session *session, std::string&
return PJ_SUCCESS;
}
pj_status_t InstantMessaging::send_sip_message (pjsip_inv_session *session, std::string& id, const std::string& message)
pj_status_t InstantMessaging::send_sip_message (pjsip_inv_session *session, const std::string& id, const std::string& message)
{
/* Check the length of the message */
......
......@@ -133,7 +133,7 @@ class InstantMessaging
* @param id The current call
* @return True if the message could have been successfully saved, False otherwise
*/
bool saveMessage (const std::string& message, const std::string& author, std::string& id, int mode = MODE_APPEND);
bool saveMessage (const std::string& message, const std::string& author, const std::string& id, int mode = MODE_APPEND);
/*
* Receive a string SIP message, for a specific call
......@@ -152,9 +152,9 @@ class InstantMessaging
* @return pj_status_t 0 on success
* 1 otherwise
*/
pj_status_t sip_send (pjsip_inv_session*, std::string& id, const std::string&);
pj_status_t sip_send (pjsip_inv_session*, const std::string& id, const std::string&);
pj_status_t send_sip_message (pjsip_inv_session*, std::string& id, const std::string&);
pj_status_t send_sip_message (pjsip_inv_session*, const std::string& id, const std::string&);
bool iax_send (iax_session* session, const std::string& id, const std::string& message);
......
......@@ -313,10 +313,7 @@ bool ManagerImpl::answerCall (const std::string& call_id)
}
try {
if (!getAccountLink (account_id)->answer (call_id)) {
removeCallAccount (call_id);
return false;
}
getAccountLink (account_id)->answer (call);
}
catch (const VoipLinkException &e) {
_error("Manager: Error: %s", e.what());
......@@ -350,10 +347,8 @@ bool ManagerImpl::answerCall (const std::string& call_id)
}
//THREAD=Main
bool ManagerImpl::hangupCall (const std::string& callId)
void ManagerImpl::hangupCall (const std::string& callId)
{
bool returnValue = true;
_info ("Manager: Hangup call %s", callId.c_str());
// First stop audio layer if there is no call anymore
......@@ -364,7 +359,7 @@ bool ManagerImpl::hangupCall (const std::string& callId)
if(_audiodriver == NULL) {
audioLayerMutexUnlock();
_error("Manager: Error: Audio layer was not instantiated");
return returnValue;
return;
}
_debug ("Manager: stop audio stream, there is no call remaining");
......@@ -383,7 +378,7 @@ bool ManagerImpl::hangupCall (const std::string& callId)
if (not isValidCall(callId) and not getConfigFromCall(callId) == Call::IPtoIP) {
_error("Manager: Error: Could not hang up call, call not valid");
return false;
return;
}
// Disconnect streams
......@@ -405,23 +400,20 @@ bool ManagerImpl::hangupCall (const std::string& callId)
if (getConfigFromCall (callId) == Call::IPtoIP) {
/* Direct IP to IP call */
try {
returnValue = SIPVoIPLink::instance()->hangup (callId);
SIPVoIPLink::instance()->hangup (callId);
}
catch (const VoipLinkException &e)
{
_error("%s", e.what());
returnValue = 1;
}
}
else {
std::string accountId (getAccountFromCall (callId));
returnValue = getAccountLink (accountId)->hangup (callId);
getAccountLink (accountId)->hangup (callId);
removeCallAccount (callId);
}
getMainBuffer()->stateInfo();
return returnValue;
}
bool ManagerImpl::hangupConference (const std::string& id)
......@@ -454,45 +446,6 @@ bool ManagerImpl::hangupConference (const std::string& id)
return true;
}
//THREAD=Main
bool ManagerImpl::cancelCall (const std::string& id)
{
std::string accountid;
bool returnValue;
_debug ("Manager: Cancel call");
stopTone();
/* Direct IP to IP call */
if (getConfigFromCall (id) == Call::IPtoIP)
returnValue = SIPVoIPLink::instance()->cancel (id);
else {
/* Classic call, attached to an account */
accountid = getAccountFromCall (id);
if (accountid.empty()) {
_debug ("! Manager Cancel Call: Call doesn't exists");
return false;
}
returnValue = getAccountLink (accountid)->cancel (id);
removeCallAccount (id);
}
// it could be a waiting call?
removeWaitingCall (id);
removeStream (id);
switchCall ("");
getMainBuffer()->stateInfo();
return returnValue;
}
//THREAD=Main
bool ManagerImpl::onHoldCall (const std::string& callId)
......@@ -1772,15 +1725,7 @@ void ManagerImpl::incomingMessage (const std::string& callID,
_debug ("Manager: Failed to get account while sending instant message");
return;
}
if (account->getType() == "SIP")
dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (_imModule, callID, message, from);
else if (account->getType() == "IAX")
dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, callID, message, from);
else {
_debug ("Manager: Failed to get voip link while sending instant message");
return;
}
account->getVoIPLink()->sendTextMessage (_imModule, callID, message, from);
}
// in case of a conference we must notify client using conference id
......@@ -1822,16 +1767,7 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string&
return false;
}
if (account->getType() == "SIP")
// link = dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId));
dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (_imModule, *iter_participant, message, from);
else if (account->getType() == "IAX")
// link = dynamic_cast<IAXVoIPLink *> (account->getVoIPLink());
dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, *iter_participant, message, from);
else {
_debug ("Manager: Failed to get voip link while sending instant message");
return false;
}
account->getVoIPLink()->sendTextMessage (_imModule, *iter_participant, message, from);
}
return true;
......@@ -1858,14 +1794,7 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string&
return false;
}
if (account->getType() == "SIP")
dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (_imModule, *iter_participant, message, from);
else if (account->getType() == "IAX")
dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, *iter_participant, message, from);
else {
_debug ("Manager: Failed to get voip link while sending instant message");
return false;
}
account->getVoIPLink()->sendTextMessage (_imModule, *iter_participant, message, from);
}
} else {
......@@ -1878,14 +1807,7 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string&
return false;
}
if (account->getType() == "SIP")
dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (_imModule, callID, message, from);
else if (account->getType() == "IAX")
dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, callID, message, from);
else {
_debug ("Manager: Failed to get voip link while sending instant message");
return false;
}
account->getVoIPLink()->sendTextMessage (_imModule, callID, message, from);
}
return true;
......
......@@ -204,9 +204,8 @@ class ManagerImpl
* Functions which occur with a user's action
* Hangup the call
* @param id The call identifier
* @return true on success
*/
bool hangupCall (const std::string& id);
void hangupCall (const std::string& id);
/**
......@@ -216,13 +215,6 @@ class ManagerImpl
*/
bool hangupConference (const std::string& id);
/**
* Functions which occur with a user's action
* Cancel the call
* @param id The call identifier
*/
bool cancelCall (const std::string& id);
/**
* Functions which occur with a user's action
* Put the call on hold
......
......@@ -566,7 +566,7 @@ int SIPAccount::registerVoIPLink()
// In our definition of the ip2ip profile (aka Direct IP Calls),
// no registration should be performed
if (_accountID != IP2IP_PROFILE) {
_link->sendRegister (_accountID);
_link->sendRegister (this);
}
}
catch(VoipLinkException &e) {
......@@ -583,7 +583,7 @@ int SIPAccount::unregisterVoIPLink()
}
try {
_link->sendUnregister (_accountID);
_link->sendUnregister (this);
setRegistrationInfo (NULL);
}
catch(VoipLinkException &e) {
......
......@@ -284,8 +284,6 @@ SIPVoIPLink::SIPVoIPLink ()
SIPVoIPLink::~SIPVoIPLink()
{
_debug ("UserAgent: SIPVoIPLink destructor called");
terminate();
}
......@@ -303,20 +301,16 @@ SIPVoIPLink* SIPVoIPLink::instance ()
void SIPVoIPLink::decrementClients (void)
{
_clients--;
if (_clients == 0) {
if (--_clients == 0) {
_debug ("UserAgent: No SIP account anymore, terminate SIPVoIPLink");
// terminate();
delete SIPVoIPLink::_instance;
}
}
bool SIPVoIPLink::init()
void SIPVoIPLink::init()
{
if (initDone())
return false;
if (_initDone)