mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
agent: Add wait-for-call-state
Change-Id: I692df9c8e315e703fb079e136962905b9e83dce8
This commit is contained in:
@ -318,6 +318,32 @@ Agent::ensureAccount()
|
||||
AGENT_INFO("Using account %s - %s", accountID_.c_str(), peerID_.c_str());
|
||||
}
|
||||
|
||||
void
|
||||
Agent::waitForCallState(const std::string& wanted)
|
||||
{
|
||||
LOG_AGENT_STATE();
|
||||
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
std::unique_lock lk(mtx);
|
||||
|
||||
onCallStateChanged_.add([&](const std::string& /* call_id */,
|
||||
const std::string& state,
|
||||
signed /* code */) {
|
||||
|
||||
|
||||
if (wanted == state) {
|
||||
std::unique_lock lk(mtx);
|
||||
cv.notify_one();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
cv.wait(lk);
|
||||
}
|
||||
|
||||
Agent&
|
||||
Agent::instance()
|
||||
|
@ -122,6 +122,7 @@ public:
|
||||
void ensureAccount();
|
||||
void waitForAnnouncement(std::chrono::seconds timeout=std::chrono::seconds(30));
|
||||
void activate(bool state);
|
||||
void waitForCallState(const std::string& wanted="CURRENT");
|
||||
|
||||
void init();
|
||||
void fini();
|
||||
|
@ -262,6 +262,14 @@ disable_binding()
|
||||
return SCM_UNDEFINED;
|
||||
}
|
||||
|
||||
static SCM
|
||||
wait_for_call_state(SCM wanted_state_str)
|
||||
{
|
||||
Agent::instance().waitForCallState(from_guile(wanted_state_str));
|
||||
|
||||
return SCM_UNDEFINED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Register Guile bindings here.
|
||||
*
|
||||
@ -308,4 +316,5 @@ install_scheme_primitives()
|
||||
define_primitive("archive->agent", 1, 0, 0, (void*) import_from_archive_binding);
|
||||
define_primitive("agent:enable", 0, 0, 0, (void*) enable_binding);
|
||||
define_primitive("agent:disable", 0, 0, 0, (void*) disable_binding);
|
||||
define_primitive("agent:wait-for-call-state", 1, 0, 0, (void*) wait_for_call_state);
|
||||
}
|
||||
|
Reference in New Issue
Block a user