Skip to content

Commit

Permalink
manager: add LIBJAMI_FLAG_NO_AUTOLOAD
Browse files Browse the repository at this point in the history
This patch introduces an option to initialize
the daemon without loading any accounts or
conversations. Additionally, it offers the
capability to load accounts and conversations
as needed. This feature could be particularly
beneficial for iOS notification extensions to
decrease CPU and memory usage.

https://git.jami.net/savoirfairelinux/jami-client-ios/-/issues/345
Change-Id: Ib2ceef2a1f7d7cb7e7d4f94a18dd3bfdc3a8989f
  • Loading branch information
katekm committed Feb 15, 2024
1 parent 49ae553 commit a45a73d
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 189 deletions.
8 changes: 6 additions & 2 deletions src/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ class Account : public std::enable_shared_from_this<Account>
// once the backward compatibility is no more required.
bool isIceCompIdRfc5245Compliant() const { return iceCompIdRfc5245Compliant_; }
void enableIceCompIdRfc5245Compliance(bool enable) { iceCompIdRfc5245Compliant_ = enable; }
void enableAutoLoadConversations(bool enable) { autoLoadConversations_ = enable; }

std::shared_ptr<Call> getCall(const std::string& callId) const
{
Expand Down Expand Up @@ -486,12 +487,15 @@ class Account : public std::enable_shared_from_this<Account>

bool iceForMediaEnabled_ {true};
bool iceCompIdRfc5245Compliant_ {false};
/**
* Auto load conversations when creatinf convModule()
*/
bool autoLoadConversations_ {true};

/**
* private account codec searching functions
*/
std::shared_ptr<SystemCodecInfo> searchCodecByName(const std::string& name,
MediaType mediaType);
std::shared_ptr<SystemCodecInfo> searchCodecByName(const std::string& name, MediaType mediaType);
std::vector<unsigned> getAccountCodecInfoIdList(MediaType mediaType) const;
void setAllCodecsActive(MediaType mediaType, bool active);
void sortCodec();
Expand Down
26 changes: 18 additions & 8 deletions src/client/configurationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ setAccountActive(const std::string& accountId, bool enable, bool shutdownConnect
jami::Manager::instance().setAccountActive(accountId, enable, shutdownConnections);
}

void
loadAccountAndConversation(const std::string& accountID, const std::string& convID)
{
jami::Manager::instance().loadAccountAndConversation(accountID, convID);
}

void
sendRegister(const std::string& accountId, bool enable)
{
Expand All @@ -264,7 +270,6 @@ getPasswordKey(const std::string& accountID, const std::string& password)
return {};
}


void
registerAllAccounts()
{
Expand Down Expand Up @@ -343,9 +348,9 @@ exportOnRing(const std::string& accountId, const std::string& password)

bool
exportToFile(const std::string& accountId,
const std::string& destinationPath,
const std::string& scheme,
const std::string& password)
const std::string& destinationPath,
const std::string& scheme,
const std::string& password)
{
if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
return account->exportArchive(destinationPath, scheme, password);
Expand All @@ -354,7 +359,10 @@ exportToFile(const std::string& accountId,
}

bool
revokeDevice(const std::string& accountId, const std::string& deviceId, const std::string& scheme, const std::string& password)
revokeDevice(const std::string& accountId,
const std::string& deviceId,
const std::string& scheme,
const std::string& password)
{
if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
return account->revokeDevice(deviceId, scheme, password);
Expand Down Expand Up @@ -553,8 +561,7 @@ setCodecDetails(const std::string& accountId,
JAMI_WARN("parameters for %s changed ", foundCodec->name.c_str());
if (auto call = jami::Manager::instance().getCurrentCall()) {
if (call->getVideoCodec() == foundCodec) {
JAMI_WARN("%s running. Need to restart encoding",
foundCodec->name.c_str());
JAMI_WARN("%s running. Need to restart encoding", foundCodec->name.c_str());
call->restartMediaSender();
}
}
Expand Down Expand Up @@ -1045,7 +1052,10 @@ searchUser(const std::string& account, const std::string& query)
}

bool
registerName(const std::string& account, const std::string& name, const std::string& scheme, const std::string& password)
registerName(const std::string& account,
const std::string& name,
const std::string& scheme,
const std::string& password)
{
#if HAVE_RINGNS
if (auto acc = jami::Manager::instance().getAccount<JamiAccount>(account)) {
Expand Down
5 changes: 4 additions & 1 deletion src/jami/configurationmanager_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ LIBJAMI_PUBLIC void setAccountDetails(const std::string& accountId,
LIBJAMI_PUBLIC void setAccountActive(const std::string& accountId,
bool active,
bool shutdownConnections = false);
LIBJAMI_PUBLIC void loadAccountAndConversation(const std::string& accountID,
const std::string& convID);
LIBJAMI_PUBLIC std::map<std::string, std::string> getAccountTemplate(const std::string& accountType);
LIBJAMI_PUBLIC std::string addAccount(const std::map<std::string, std::string>& details,
const std::string& accountId = {});
Expand All @@ -84,7 +86,8 @@ LIBJAMI_PUBLIC bool changeAccountPassword(const std::string& accountId,
const std::string& password_old,
const std::string& password_new);
LIBJAMI_PUBLIC bool isPasswordValid(const std::string& accountId, const std::string& password);
LIBJAMI_PUBLIC std::vector<uint8_t> getPasswordKey(const std::string& accountId, const std::string& password);
LIBJAMI_PUBLIC std::vector<uint8_t> getPasswordKey(const std::string& accountId,
const std::string& password);

LIBJAMI_PUBLIC bool lookupName(const std::string& account,
const std::string& nameserver,
Expand Down
17 changes: 10 additions & 7 deletions src/jami/jami.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ enum InitFlag {
LIBJAMI_FLAG_NO_LOCAL_AUDIO = 1 << 6,
LIBJAMI_FLAG_NO_LOCAL_VIDEO = 1 << 7,
LIBJAMI_FLAG_NO_LOCAL_MEDIA = LIBJAMI_FLAG_NO_LOCAL_AUDIO | LIBJAMI_FLAG_NO_LOCAL_VIDEO,
LIBJAMI_FLAG_NO_AUTOSYNC = 1 << 8
LIBJAMI_FLAG_NO_AUTOSYNC = 1 << 8,
LIBJAMI_FLAG_NO_AUTOLOAD = 1 << 9 // disable auto loading of accounts and conversations
};

/**
Expand All @@ -69,6 +70,7 @@ LIBJAMI_PUBLIC bool init(enum InitFlag flags) noexcept;
* Start asynchronously daemon created by init().
* @returns true if daemon started successfully
*/

LIBJAMI_PUBLIC bool start(const std::filesystem::path& config_file = {}) noexcept;

/**
Expand Down Expand Up @@ -185,12 +187,13 @@ class SerializedCallbackWrapper : public CallbackWrapperBase

// This is quite a ugly method used to transmit templated TFunc with their arguments in the
// ioContext of the manager to avoid locks for signals.
template <typename TCallback>
template<typename TCallback>
auto ioContextWrapper(TCallback&& fun)
{
return [this, fun{std::move(fun)}](auto&&... args) -> decltype(fun(std::forward<decltype(args)>(args)...))
{
post([fun{std::move(fun)}, forwardArgs=std::make_tuple(std::move(args)...)]() mutable {
return [this, fun {std::move(fun)}](
auto&&... args) -> decltype(fun(std::forward<decltype(args)>(args)...)) {
post([fun {std::move(fun)},
forwardArgs = std::make_tuple(std::move(args)...)]() mutable {
std::apply(std::move(fun), std::move(forwardArgs));
});
};
Expand Down Expand Up @@ -255,8 +258,8 @@ exportable_callback(std::function<typename Ts::cb_type>&& func,
template<typename Ts>
std::pair<std::string, std::shared_ptr<CallbackWrapperBase>>
exportable_serialized_callback(std::function<typename Ts::cb_type>&& func,
const char* file = CURRENT_FILENAME(),
uint32_t linum = CURRENT_LINE())
const char* file = CURRENT_FILENAME(),
uint32_t linum = CURRENT_LINE())
{
return std::make_pair((const std::string&) Ts::name,
std::make_shared<SerializedCallbackWrapper<typename Ts::cb_type>>(
Expand Down
Loading

0 comments on commit a45a73d

Please sign in to comment.