Commit 087e935b authored by yanmorin's avatar yanmorin

Terminate account when registrating a new one

parent 0c8dac16
......@@ -27,6 +27,7 @@ Account::Account(const AccountID& accountID) : _accountID(accountID)
_shouldRegisterOnStart = false;
_enabled = false;
_registered = false;
_state = false;
}
......
......@@ -102,6 +102,11 @@ public:
*/
bool isEnabled() { return _enabled; }
/**
* Tell if the latest registration succeed or failed
*/
bool setState(bool state) { _state = state; }
private:
/**
* Create a unique voIPLink() depending on the protocol
......@@ -145,6 +150,11 @@ protected:
*/
bool _registered;
/**
* The latest registration was a success or not
*/
bool _state;
};
#endif
......@@ -440,8 +440,19 @@ ManagerImpl::registerVoIPLink(const AccountID& accountId)
{
_debug("Register VoIP Link\n");
int returnValue = false;
if (accountExists( accountId ) ) {
returnValue = getAccount(accountId)->registerAccount();
// right now, we don't support two SIP account
// so we close everything before registring a new account
Account* account = getAccount(accountId);
if (account != 0) {
AccountMap::iterator iter = _accountMap.begin();
while ( iter != _accountMap.end() ) {
if ( iter->second ) {
iter->second->unregisterAccount();
iter->second->terminate();
}
iter++;
}
returnValue = account->registerAccount();
}
return returnValue;
}
......@@ -453,7 +464,7 @@ ManagerImpl::unregisterVoIPLink(const AccountID& accountId)
_debug("Unregister VoIP Link\n");
int returnValue = false;
if (accountExists( accountId ) ) {
returnValue = getAccount(accountId)->registerAccount();
returnValue = getAccount(accountId)->unregisterAccount();
}
return returnValue;
}
......@@ -739,20 +750,28 @@ void
ManagerImpl::stopVoiceMessageNotification(const AccountID& accountId)
{
if (_gui) _gui->sendVoiceNbMessage(accountId, std::string("0"));
}
}
//THREAD=VoIP
void
ManagerImpl::registrationSucceed(const AccountID& accountid)
{
if (_gui) _gui->sendRegistrationState(accountid, true);
Account* acc = getAccount(accountid);
if ( acc ) {
acc->setState(true);
if (_gui) _gui->sendRegistrationState(accountid, true);
}
}
//THREAD=VoIP
void
ManagerImpl::registrationFailed(const AccountID& accountid)
{
if (_gui) _gui->sendRegistrationState(accountid, false);
Account* acc = getAccount(accountid);
if ( acc ) {
acc->setState(false);
if (_gui) _gui->sendRegistrationState(accountid, false);
}
}
/**
......
......@@ -55,6 +55,7 @@ bool
SIPAccount::registerAccount()
{
if (_link) {
init(); // init if not enable
unregisterAccount();
SIPVoIPLink* tmplink = dynamic_cast<SIPVoIPLink*> (_link);
if (tmplink) {
......
......@@ -224,7 +224,7 @@ SIPVoIPLink::getEvent()
_debug("EXOSIP_REGISTRATION_REFRESHED event is not implemented\n");
break;
case EXOSIP_REGISTRATION_TERMINATED: /** 04 < UA is not registred any more. */
_debug("EXOSIP_REGISTRATION_TERMINATED event is not implmeneted\n");
_debug("EXOSIP_REGISTRATION_TERMINATED event is not implemented\n");
break;
/* INVITE related events within calls */
......
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