Skip to content
Snippets Groups Projects
Commit fddb2ef8 authored by Olivier Dion's avatar Olivier Dion
Browse files

agent: Add wait-for-call-state

Change-Id: I692df9c8e315e703fb079e136962905b9e83dce8
parent c4da9deb
No related branches found
No related tags found
No related merge requests found
...@@ -318,6 +318,32 @@ Agent::ensureAccount() ...@@ -318,6 +318,32 @@ Agent::ensureAccount()
AGENT_INFO("Using account %s - %s", accountID_.c_str(), peerID_.c_str()); 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&
Agent::instance() Agent::instance()
......
...@@ -122,6 +122,7 @@ public: ...@@ -122,6 +122,7 @@ public:
void ensureAccount(); void ensureAccount();
void waitForAnnouncement(std::chrono::seconds timeout=std::chrono::seconds(30)); void waitForAnnouncement(std::chrono::seconds timeout=std::chrono::seconds(30));
void activate(bool state); void activate(bool state);
void waitForCallState(const std::string& wanted="CURRENT");
void init(); void init();
void fini(); void fini();
......
...@@ -262,6 +262,14 @@ disable_binding() ...@@ -262,6 +262,14 @@ disable_binding()
return SCM_UNDEFINED; 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. * Register Guile bindings here.
* *
...@@ -308,4 +316,5 @@ install_scheme_primitives() ...@@ -308,4 +316,5 @@ install_scheme_primitives()
define_primitive("archive->agent", 1, 0, 0, (void*) import_from_archive_binding); 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:enable", 0, 0, 0, (void*) enable_binding);
define_primitive("agent:disable", 0, 0, 0, (void*) disable_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);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment