Commit 02e65ffd authored by Sébastien Blin's avatar Sébastien Blin Committed by Andreas Traczyk

misc: initial format

Change-Id: I193328586ea401c16d64393eb0dfb2ebb0d80e9d
parent 85510893
......@@ -91,8 +91,8 @@ PenaltyExcessCharacter: 50
PenaltyReturnTypeOnItsOwnLine: 300
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
......
......@@ -9,12 +9,12 @@ command_exists ()
CFVERSION="9"
CLANGFORMAT=""
if command_exists clang-format; then
CLANGFORMAT=clang-format
if command_exists clang-format-${CFVERSION}; then
CLANGFORMAT=clang-format-${CFVERSION}
else
if command_exists clang-format-${CFVERSION}; then
CLANGFORMAT=clang-format-${CFVERSION}
fi
if command_exists clang-format; then
CLANGFORMAT=clang-format
fi
fi
if ! command -v $CLANGFORMAT &> /dev/null; then
......@@ -25,7 +25,7 @@ fi
format_file()
{
if [ -f "${1}" ]; then
$CLANGFORMAT -i -style=file "${1}"
$CLANGFORMAT -i -style=file "${1}" || true
fi
}
......@@ -76,7 +76,7 @@ fi
case "${1}" in
--all )
files=$(find src -regex '.*\.\(cpp\|hpp\|cc\|cxx\|h\|mm\)') || true
files=$(find src -regex '.*\.\(cpp\|hpp\|cc\|cxx\|h\)') || true
echo Formatting all source files...
format_files "$files"
;;
......@@ -84,7 +84,7 @@ case "${1}" in
install_hook
;;
* )
files=$(git diff-index --cached --name-only HEAD | grep -iE '\.(cpp|cxx|cc|h|hpp|mm)') || exit_if_no_files
files=$(git diff-index --cached --name-only HEAD | grep -iE '\.(cpp|cxx|cc|h|hpp)') || exit_if_no_files
echo Formatting committed source files...
format_files "$files"
;;
......
This diff is collapsed.
This diff is collapsed.
......@@ -35,35 +35,38 @@ const char* const AccountFactory::DEFAULT_ACCOUNT_TYPE = SIPAccount::ACCOUNT_TYP
AccountFactory::AccountFactory()
{
auto sipfunc = [](const std::string& id){ return std::make_shared<SIPAccount>(id, true); };
auto sipfunc = [](const std::string& id) {
return std::make_shared<SIPAccount>(id, true);
};
generators_.insert(std::make_pair(SIPAccount::ACCOUNT_TYPE, sipfunc));
auto dhtfunc = [](const std::string& id){ return std::make_shared<JamiAccount>(id, false); };
auto dhtfunc = [](const std::string& id) {
return std::make_shared<JamiAccount>(id, false);
};
generators_.insert(std::make_pair(JamiAccount::ACCOUNT_TYPE, dhtfunc));
}
std::shared_ptr<Account>
AccountFactory::createAccount(const char* const accountType,
const std::string& id)
AccountFactory::createAccount(const char* const accountType, const std::string& id)
{
if (hasAccount(id)) {
JAMI_ERR("Existing account %s", id.c_str());
return nullptr;
}
std::shared_ptr<Account> account;
{
const auto& it = generators_.find(accountType);
if (it != generators_.cend())
account = it->second(id);
}
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
accountMaps_[accountType].insert(std::make_pair(id, account));
}
return account;
}
if (hasAccount(id)) {
JAMI_ERR("Existing account %s", id.c_str());
return nullptr;
}
std::shared_ptr<Account> account;
{
const auto& it = generators_.find(accountType);
if (it != generators_.cend())
account = it->second(id);
}
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
accountMaps_[accountType].insert(std::make_pair(id, account));
}
return account;
}
bool
AccountFactory::isSupportedType(const char* const name) const
......@@ -95,7 +98,8 @@ AccountFactory::removeAccount(const std::string& id)
JAMI_ERR("No account with ID %s", id.c_str());
}
template <> bool
template<>
bool
AccountFactory::hasAccount(const std::string& id) const
{
std::lock_guard<std::recursive_mutex> lk(mutex_);
......@@ -109,19 +113,20 @@ AccountFactory::hasAccount(const std::string& id) const
return false;
}
template <> void
template<>
void
AccountFactory::clear()
{
std::lock_guard<std::recursive_mutex> lk(mutex_);
accountMaps_.clear();
}
template <>
std::vector<std::shared_ptr<Account> >
template<>
std::vector<std::shared_ptr<Account>>
AccountFactory::getAllAccounts() const
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::vector<std::shared_ptr<Account> > v;
std::vector<std::shared_ptr<Account>> v;
for (const auto& itemmap : accountMaps_) {
const auto& map = itemmap.second;
......@@ -133,14 +138,14 @@ AccountFactory::getAllAccounts() const
return v;
}
template <>
template<>
std::shared_ptr<Account>
AccountFactory::getAccount(const std::string& id) const
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (const auto& item : accountMaps_) {
const auto& map = item.second;
const auto& map = item.second;
const auto& iter = map.find(id);
if (iter != map.cend())
return iter->second;
......@@ -149,7 +154,7 @@ AccountFactory::getAccount(const std::string& id) const
return nullptr;
}
template <>
template<>
bool
AccountFactory::empty() const
{
......@@ -164,7 +169,7 @@ AccountFactory::empty() const
return true;
}
template <>
template<>
std::size_t
AccountFactory::accountCount() const
{
......
......@@ -34,125 +34,129 @@ namespace jami {
class Account;
class AccountGeneratorBase;
template <class T> using AccountMap = std::map<std::string, std::shared_ptr<T> >;
template<class T>
using AccountMap = std::map<std::string, std::shared_ptr<T>>;
class AccountFactory {
public:
static const char* const DEFAULT_ACCOUNT_TYPE;
class AccountFactory
{
public:
static const char* const DEFAULT_ACCOUNT_TYPE;
AccountFactory();
AccountFactory();
bool isSupportedType(const char* const accountType) const;
bool isSupportedType(const char* const accountType) const;
std::shared_ptr<Account> createAccount(const char* const accountType,
const std::string& id);
std::shared_ptr<Account> createAccount(const char* const accountType, const std::string& id);
void removeAccount(Account& account);
void removeAccount(Account& account);
void removeAccount(const std::string& id);
void removeAccount(const std::string& id);
template <class T=Account>
bool hasAccount(const std::string& id) const {
std::lock_guard<std::recursive_mutex> lk(mutex_);
template<class T = Account>
bool hasAccount(const std::string& id) const
{
std::lock_guard<std::recursive_mutex> lk(mutex_);
const auto map = getMap_<T>();
return map and map->find(id) != map->cend();
}
const auto map = getMap_<T>();
return map and map->find(id) != map->cend();
}
template <class T=Account>
void clear() {
std::lock_guard<std::recursive_mutex> lk(mutex_);
template<class T = Account>
void clear()
{
std::lock_guard<std::recursive_mutex> lk(mutex_);
auto map = getMap_<T>();
if (!map) return;
auto map = getMap_<T>();
if (!map)
return;
map->clear();
}
map->clear();
}
template <class T=Account>
bool empty() const {
std::lock_guard<std::recursive_mutex> lock(mutex_);
template<class T = Account>
bool empty() const
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
const auto map = getMap_<T>();
return map and map->empty();
}
const auto map = getMap_<T>();
return map and map->empty();
}
template <class T=Account>
std::size_t accountCount() const {
std::lock_guard<std::recursive_mutex> lock(mutex_);
template<class T = Account>
std::size_t accountCount() const
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
const auto map = getMap_<T>();
if (!map) return 0;
const auto map = getMap_<T>();
if (!map)
return 0;
return map->size();
}
return map->size();
}
template<class T = Account>
std::shared_ptr<T> getAccount(const std::string& id) const
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
template <class T=Account>
std::shared_ptr<T>
getAccount(const std::string& id) const {
std::lock_guard<std::recursive_mutex> lock(mutex_);
const auto map = getMap_<T>();
if (!map)
return nullptr;
const auto map = getMap_<T>();
if (!map) return nullptr;
const auto& it = map->find(id);
if (it == map->cend())
return nullptr;
const auto& it = map->find(id);
if (it == map->cend())
return nullptr;
return std::static_pointer_cast<T>(it->second);
}
return std::static_pointer_cast<T>(it->second);
}
template<class T = Account>
std::vector<std::shared_ptr<T>> getAllAccounts() const
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::vector<std::shared_ptr<T>> v;
template <class T=Account>
std::vector<std::shared_ptr<T> > getAllAccounts() const {
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::vector<std::shared_ptr<T> > v;
if (const auto map = getMap_<T>()) {
v.reserve(map->size());
for (const auto& it : *map)
v.push_back(std::static_pointer_cast<T>(it.second));
}
return v;
if (const auto map = getMap_<T>()) {
v.reserve(map->size());
for (const auto& it : *map)
v.push_back(std::static_pointer_cast<T>(it.second));
}
return v;
}
private:
mutable std::recursive_mutex mutex_ {};
std::map<std::string, std::function<std::shared_ptr<Account>(const std::string&)> > generators_ {};
std::map<std::string, AccountMap<Account> > accountMaps_ {};
private:
mutable std::recursive_mutex mutex_ {};
std::map<std::string, std::function<std::shared_ptr<Account>(const std::string&)>> generators_ {};
std::map<std::string, AccountMap<Account>> accountMaps_ {};
template <class T>
const AccountMap<Account>* getMap_() const {
const auto& itermap = accountMaps_.find(T::ACCOUNT_TYPE);
template<class T>
const AccountMap<Account>* getMap_() const
{
const auto& itermap = accountMaps_.find(T::ACCOUNT_TYPE);
if (itermap != accountMaps_.cend())
return &itermap->second;
if (itermap != accountMaps_.cend())
return &itermap->second;
return nullptr;
}
return nullptr;
}
};
template <>
bool
AccountFactory::hasAccount(const std::string& id) const;
template<>
bool AccountFactory::hasAccount(const std::string& id) const;
template <>
void
AccountFactory::clear();
template<>
void AccountFactory::clear();
template <>
std::vector<std::shared_ptr<Account> >
AccountFactory::getAllAccounts() const;
template<>
std::vector<std::shared_ptr<Account>> AccountFactory::getAllAccounts() const;
template <>
std::shared_ptr<Account>
AccountFactory::getAccount(const std::string& accountId) const;
template<>
std::shared_ptr<Account> AccountFactory::getAccount(const std::string& accountId) const;
template <>
bool
AccountFactory::empty() const;
template<>
bool AccountFactory::empty() const;
template <>
std::size_t
AccountFactory::accountCount() const;
template<>
std::size_t AccountFactory::accountCount() const;
} // namespace jami
......@@ -27,87 +27,89 @@
* @brief Account specific keys/constants that must be shared in daemon and clients.
*/
namespace jami { namespace Conf {
namespace jami {
namespace Conf {
// Common account parameters
static const char *const CONFIG_ACCOUNT_TYPE = "Account.type";
static const char *const CONFIG_ACCOUNT_ALIAS = "Account.alias";
static const char *const CONFIG_ACCOUNT_DISPLAYNAME = "Account.displayName";
static const char *const CONFIG_ACCOUNT_MAILBOX = "Account.mailbox";
static const char *const CONFIG_ACCOUNT_ENABLE = "Account.enable";
static const char *const CONFIG_ACCOUNT_AUTOANSWER = "Account.autoAnswer";
static const char *const CONFIG_ACCOUNT_ISRENDEZVOUS = "Account.rendezVous";
static const char *const CONFIG_ACCOUNT_REGISTRATION_EXPIRE = "Account.registrationExpire";
static const char *const CONFIG_ACCOUNT_DTMF_TYPE = "Account.dtmfType";
static const char *const CONFIG_RINGTONE_PATH = "Account.ringtonePath";
static const char *const CONFIG_RINGTONE_ENABLED = "Account.ringtoneEnabled";
static const char *const CONFIG_VIDEO_ENABLED = "Account.videoEnabled";
static const char *const CONFIG_KEEP_ALIVE_ENABLED = "Account.keepAliveEnabled";
static const char *const CONFIG_PRESENCE_ENABLED = "Account.presenceEnabled";
static const char *const CONFIG_PRESENCE_PUBLISH_SUPPORTED = "Account.presencePublishSupported";
static const char *const CONFIG_PRESENCE_SUBSCRIBE_SUPPORTED = "Account.presenceSubscribeSupported";
static const char *const CONFIG_PRESENCE_STATUS = "Account.presenceStatus";
static const char *const CONFIG_PRESENCE_NOTE = "Account.presenceNote";
static const char* const CONFIG_ACCOUNT_TYPE = "Account.type";
static const char* const CONFIG_ACCOUNT_ALIAS = "Account.alias";
static const char* const CONFIG_ACCOUNT_DISPLAYNAME = "Account.displayName";
static const char* const CONFIG_ACCOUNT_MAILBOX = "Account.mailbox";
static const char* const CONFIG_ACCOUNT_ENABLE = "Account.enable";
static const char* const CONFIG_ACCOUNT_AUTOANSWER = "Account.autoAnswer";
static const char* const CONFIG_ACCOUNT_ISRENDEZVOUS = "Account.rendezVous";
static const char* const CONFIG_ACCOUNT_REGISTRATION_EXPIRE = "Account.registrationExpire";
static const char* const CONFIG_ACCOUNT_DTMF_TYPE = "Account.dtmfType";
static const char* const CONFIG_RINGTONE_PATH = "Account.ringtonePath";
static const char* const CONFIG_RINGTONE_ENABLED = "Account.ringtoneEnabled";
static const char* const CONFIG_VIDEO_ENABLED = "Account.videoEnabled";
static const char* const CONFIG_KEEP_ALIVE_ENABLED = "Account.keepAliveEnabled";
static const char* const CONFIG_PRESENCE_ENABLED = "Account.presenceEnabled";
static const char* const CONFIG_PRESENCE_PUBLISH_SUPPORTED = "Account.presencePublishSupported";
static const char* const CONFIG_PRESENCE_SUBSCRIBE_SUPPORTED = "Account.presenceSubscribeSupported";
static const char* const CONFIG_PRESENCE_STATUS = "Account.presenceStatus";
static const char* const CONFIG_PRESENCE_NOTE = "Account.presenceNote";
static const char *const CONFIG_ACCOUNT_HOSTNAME = "Account.hostname";
static const char *const CONFIG_ACCOUNT_USERNAME = "Account.username";
static const char *const CONFIG_ACCOUNT_ROUTESET = "Account.routeset";
static const char *const CONFIG_ACCOUNT_PASSWORD = "Account.password";
static const char *const CONFIG_ACCOUNT_REALM = "Account.realm";
static const char *const CONFIG_ACCOUNT_USERAGENT = "Account.useragent";
static const char *const CONFIG_ACCOUNT_HAS_CUSTOM_USERAGENT = "Account.hasCustomUserAgent";
static const char *const CONFIG_ACCOUNT_AUDIO_PORT_MIN = "Account.audioPortMin";
static const char *const CONFIG_ACCOUNT_AUDIO_PORT_MAX = "Account.audioPortMax";
static const char *const CONFIG_ACCOUNT_VIDEO_PORT_MIN = "Account.videoPortMin";
static const char *const CONFIG_ACCOUNT_VIDEO_PORT_MAX = "Account.videoPortMax";
static const char* const CONFIG_ACCOUNT_HOSTNAME = "Account.hostname";
static const char* const CONFIG_ACCOUNT_USERNAME = "Account.username";
static const char* const CONFIG_ACCOUNT_ROUTESET = "Account.routeset";
static const char* const CONFIG_ACCOUNT_PASSWORD = "Account.password";
static const char* const CONFIG_ACCOUNT_REALM = "Account.realm";
static const char* const CONFIG_ACCOUNT_USERAGENT = "Account.useragent";
static const char* const CONFIG_ACCOUNT_HAS_CUSTOM_USERAGENT = "Account.hasCustomUserAgent";
static const char* const CONFIG_ACCOUNT_AUDIO_PORT_MIN = "Account.audioPortMin";
static const char* const CONFIG_ACCOUNT_AUDIO_PORT_MAX = "Account.audioPortMax";
static const char* const CONFIG_ACCOUNT_VIDEO_PORT_MIN = "Account.videoPortMin";