Commit 6d7d0737 authored by Adrien Béraud's avatar Adrien Béraud Committed by Guillaume Roguez
Browse files

accounts: add API-controlable "active" property

* add "active" runtime property to accounts
* accounts can only be used when active
* "active" state is not persistans
* add "active" state to volatile properties map
* add setAccountActive API
* "active" is the default state (backward compatibility)

The active state can be used to manage runtime states
defining if an account should be used (e.g. on Wifi/3G etc.)

Tuleap: #9
Tuleap: #42
Change-Id: Ie3b3aaadea6e43237fc22f6a1f96de8cbfe2bd95
parent ff570fc9
......@@ -106,6 +106,23 @@
</arg>
</method>
<method name="setAccountActive" tp:name-for-bindings="setAccountActive">
<tp:docstring>
Set if this account is currently enabled (can be used).
It is only a runtime proprety with no impact on the "enabled" state of the account.
</tp:docstring>
<arg type="s" name="accountID" direction="in">
<tp:docstring>
The account ID
</tp:docstring>
</arg>
<arg type="b" name="enable" direction="in">
<tp:docstring>
<p>Set if enabled.</p>
</tp:docstring>
</arg>
</method>
<method name="setCredentials" tp:name-for-bindings="setCredentials">
<arg type="s" name="accountID" direction="in">
</arg>
......
......@@ -49,6 +49,12 @@ DBusConfigurationManager::setAccountDetails(const std::string& accountID, const
DRing::setAccountDetails(accountID, details);
}
void
DBusConfigurationManager::setAccountActive(const std::string& accountID, const bool& active)
{
DRing::setAccountActive(accountID, active);
}
auto
DBusConfigurationManager::getAccountTemplate(const std::string& accountType) -> decltype(DRing::getAccountTemplate(accountType))
{
......
......@@ -59,6 +59,7 @@ class DBusConfigurationManager :
std::map<std::string, std::string> getAccountDetails(const std::string& accountID);
std::map<std::string, std::string> getVolatileAccountDetails(const std::string& accountID);
void setAccountDetails(const std::string& accountID, const std::map<std::string, std::string>& details);
void setAccountActive(const std::string& accountID, const bool& active);
std::map<std::string, std::string> getAccountTemplate(const std::string& accountType);
std::string addAccount(const std::map<std::string, std::string>& details);
void removeAccount(const std::string& accoundID);
......
......@@ -304,7 +304,8 @@ std::map<std::string, std::string>
Account::getVolatileAccountDetails() const
{
return {
{Conf::CONFIG_ACCOUNT_REGISTRATION_STATUS, mapStateNumberToString(registrationState_)}
{Conf::CONFIG_ACCOUNT_REGISTRATION_STATUS, mapStateNumberToString(registrationState_)},
{DRing::Account::VolatileProperties::ACTIVE, enabled_ ? TRUE_STR : FALSE_STR}
};
}
......
......@@ -153,19 +153,34 @@ class Account : public Serializable, public std::enable_shared_from_this<Account
/**
* Tell if the account is enable or not.
* @return true if enabled
* false otherwise
* @return true if enabled, false otherwise
*/
bool isEnabled() const {
bool isEnabled() const noexcept {
return enabled_;
}
bool isVideoEnabled() const {
return videoEnabled_;
void setEnabled(bool enable) noexcept {
enabled_ = enable;
}
void setEnabled(bool enable) {
enabled_ = enable;
/**
* Tell if the account is activated
* (can currently be used).
*/
bool isActive() const noexcept {
return active_;
}
void setActive(bool active) noexcept {
active_ = active;
}
bool isUsable() const noexcept {
return enabled_ and active_;
}
bool isVideoEnabled() const noexcept {
return videoEnabled_;
}
/**
......@@ -340,12 +355,19 @@ class Account : public Serializable, public std::enable_shared_from_this<Account
std::string alias_;
/**
* Tells if the link is enabled, active.
* Tells if the account is enabled.
* This implies the link will be initialized on startup.
* Modified by the configuration (key: ENABLED)
*/
bool enabled_;
/**
* Tells if the account is active now.
* This allows doRegister to be called.
* When an account is unactivated, doUnregister must be called.
*/
bool active_ {true};
/* If true, automatically answer calls to this account */
bool autoAnswerEnabled_;
......
......@@ -258,6 +258,12 @@ setAccountDetails(const std::string& accountID, const std::map<std::string, std:
ring::Manager::instance().setAccountDetails(accountID, details);
}
void
setAccountActive(const std::string& accountID, bool enable)
{
ring::Manager::instance().setAccountActive(accountID, enable);
}
void
sendRegister(const std::string& accountID, bool enable)
{
......
......@@ -60,6 +60,8 @@ constexpr static const char REQUEST_TIMEOUT [] = "Request Timeout";
namespace VolatileProperties {
constexpr static const char ACTIVE [] = "Account.active";
// Volatile parameters
namespace Registration {
......
......@@ -41,9 +41,11 @@ void registerConfHandlers(const std::map<std::string, std::shared_ptr<CallbackWr
std::map<std::string, std::string> getAccountDetails(const std::string& accountID);
std::map<std::string, std::string> getVolatileAccountDetails(const std::string& accountID);
void setAccountDetails(const std::string& accountID, const std::map<std::string, std::string>& details);
void setAccountActive(const std::string& accountID, bool active);
std::map<std::string, std::string> getAccountTemplate(const std::string& accountType);
std::string addAccount(const std::map<std::string, std::string>& details);
void removeAccount(const std::string& accountID);
void setAccountEnabled(const std::string& accountID, bool enable);
std::vector<std::string> getAccountList();
void sendRegister(const std::string& accountID, bool enable);
void registerAllAccounts(void);
......
......@@ -2382,9 +2382,9 @@ Manager::setAccountDetails(const std::string& accountID,
// Serialize configuration to disk once it is done
saveConfig();
if (account->isEnabled()) {
if (account->isUsable())
account->doRegister();
} else
else
account->doUnregister();
// Update account details to the client side
......@@ -2668,9 +2668,8 @@ Manager::registerAccounts()
a->loadConfig();
if (a->isEnabled()) {
if (a->isUsable())
a->doRegister();
}
}
}
......@@ -2710,6 +2709,21 @@ Manager::sendTextMessage(const std::string& accountID, const std::string& to, co
acc->sendTextMessage(to, message);
}
void
Manager::setAccountActive(const std::string& accountID, bool active)
{
const auto acc = getAccount(accountID);
if (!acc || acc->isActive() == active)
return;
acc->setActive(active);
if (acc->isEnabled()) {
if (active)
acc->doRegister();
else
acc->doUnregister();
}
}
std::shared_ptr<AudioLayer>
Manager::getAudioDriver()
{
......@@ -2748,7 +2762,7 @@ Manager::newOutgoingCall(const std::string& toUrl,
} else
RING_WARN("IP Url detected, using IP2IP account");
if (!account) {
if (!account or !account->isUsable()) {
RING_ERR("No suitable account found to create outgoing call");
return nullptr;
}
......
......@@ -490,6 +490,8 @@ class Manager {
void setAccountDetails(const std::string& accountID,
const std::map<std::string, ::std::string > &details);
void setAccountActive(const std::string& accountID, bool active);
/**
* Add a new account, and give it a new account ID automatically
* @param details The new account parameters
......
......@@ -679,8 +679,8 @@ bool RingAccount::mapPortUPnP()
void RingAccount::doRegister()
{
if (not isEnabled()) {
RING_WARN("Account must be enabled to register, ignoring");
if (not isUsable()) {
RING_WARN("Account must be enabled and active to register, ignoring");
return;
}
......
......@@ -716,8 +716,8 @@ bool SIPAccount::mapPortUPnP()
void SIPAccount::doRegister()
{
if (not isEnabled()) {
RING_WARN("Account must be enabled to register, ignoring");
if (not isUsable()) {
RING_WARN("Account must be enabled and active to register, ignoring");
return;
}
......@@ -943,8 +943,8 @@ void SIPAccount::stopKeepAliveTimer()
void
SIPAccount::sendRegister()
{
if (not isEnabled()) {
RING_WARN("Account must be enabled to register, ignoring");
if (not isUsable()) {
RING_WARN("Account must be enabled and active to register, ignoring");
return;
}
......@@ -1130,6 +1130,7 @@ SIPAccount::sendUnregister()
// Make sure to cancel any ongoing timers before unregister
stopKeepAliveTimer();
setRegister(false);
pjsip_regc *regc = getRegistrationInfo();
if (!regc)
......@@ -1145,8 +1146,6 @@ SIPAccount::sendUnregister()
sip_utils::sip_strerror(status).c_str());
throw VoipLinkException("Unable to send request to unregister sip account");
}
setRegister(false);
}
#if HAVE_TLS
......@@ -2024,7 +2023,7 @@ SIPAccount::autoReregTimerCb(pj_timer_heap_t * /*th*/, pj_timer_entry *te)
void
SIPAccount::scheduleReregistration(pjsip_endpoint *endpt)
{
if (!isEnabled())
if (!isUsable())
return;
/* Cancel any re-registration timer */
......
Supports Markdown
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