Commit 5d220d23 authored by Gabriel Margiani's avatar Gabriel Margiani

One more argument for eventhook and reasons on disconnection events.

parent 1b9c300e
......@@ -2,8 +2,8 @@
pkill -SIGRTMIN+7 i3blocks
case $1 in
"disconnected") # id, nr
twmnc -t "Call $2 Terminated" -c "$3"
"disconnected") # id, nr, reasonCode, reasonText
twmnc -t "Call $2 Terminated" -c "$3: $5 ($4)"
;;
"calling") # id, nr
twmnc -t "calling $3" -c "id $2"
......
......@@ -44,7 +44,13 @@ void p3::call::onCallState(pj::OnCallStateParam& prm) {
pj::CallInfo ci = getInfo();
switch (ci.state) {
case PJSIP_INV_STATE_DISCONNECTED:
phone.get_event_hook().run_call_hook("disconnected", p3id, get_nr());
phone.get_event_hook().run_call_hook(
"disconnected",
p3id,
get_nr(),
std::to_string(ci.lastStatusCode),
ci.lastReason
);
state = p3::callState::NONE;
phone.delete_call(p3id);
break;
......
......@@ -74,9 +74,9 @@ void p3::eventHook::event_worker() {
}
}
void p3::eventHook::handle_event(const std::array<std::string, 4>& args) {
void p3::eventHook::handle_event(const std::array<std::string, 5>& args) {
for (auto c : callbacks) {
c(args[0], args[1], args[2], args[3]);
c(args[0], args[1], args[2], args[3], args[4]);
}
if (command.empty()) {
......@@ -91,19 +91,20 @@ void p3::eventHook::handle_event(const std::array<std::string, 4>& args) {
args[0].c_str(),
args[1].c_str(),
args[2].c_str(),
args[2].c_str(),
args[3].c_str(),
args[4].c_str(),
(char *)0
);
}
}
void p3::eventHook::run_call_hook(const std::string& event, int cid, const std::string& nr, const std::string& data) {
run_hook(event, std::to_string(cid), book.address_by_nr(nr), data);
void p3::eventHook::run_call_hook(const std::string& event, int cid, const std::string& nr, const std::string& data1, const std::string& data2) {
run_hook(event, std::to_string(cid), book.address_by_nr(nr), data1, data2);
}
void p3::eventHook::run_hook(const std::string& event, const std::string& a2, const std::string& a3, const std::string& a4) {
void p3::eventHook::run_hook(const std::string& event, const std::string& a2, const std::string& a3, const std::string& a4, const std::string& a5) {
std::lock_guard<std::mutex> g(queue_mutex);
event_queue.push_back({event, a2, a3, a4});
event_queue.push_back({event, a2, a3, a4, a5});
worker_condition.notify_all();
}
......@@ -50,7 +50,13 @@ namespace p3 {
class eventHook {
public:
// callback functions need to have same signature as run_hook.
typedef std::function<void(const std::string&, const std::string&, const std::string&, const std::string&)> callback_type;
typedef std::function<void(
const std::string&,
const std::string&,
const std::string&,
const std::string&,
const std::string&
)> callback_type;
private:
config& conf;
......@@ -61,7 +67,7 @@ namespace p3 {
std::list<callback_type> callbacks;
std::mutex callback_mutex;
std::list<std::array<std::string, 4> > event_queue;
std::list<std::array<std::string, 5> > event_queue;
std::mutex queue_mutex;
std::thread * worker_thread;
......@@ -75,11 +81,11 @@ namespace p3 {
eventHook(const eventHook &) = delete;
void run_hook(const std::string& event, const std::string& a2 = "", const std::string& a3 = "", const std::string& a4 = "");
void run_call_hook(const std::string& event, int call_id = 0, const std::string& nr = "", const std::string& data = "");
void run_hook(const std::string& event, const std::string& a2 = "", const std::string& a3 = "", const std::string& a4 = "", const std::string& a5 = "");
void run_call_hook(const std::string& event, int call_id = 0, const std::string& nr = "", const std::string& data1 = "", const std::string& data2 = "");
void event_worker();
void handle_event(const std::array<std::string, 4>& args);
void handle_event(const std::array<std::string, 5>& args);
std::list<callback_type>::iterator register_callback(const callback_type& callback);
void unregister_callback(const std::list<callback_type>::iterator& id);
......
......@@ -338,7 +338,8 @@ void p3::clientHandler::handle_start_push_events() {
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_3,
std::placeholders::_4
std::placeholders::_4,
std::placeholders::_5
)
);
connection.send(p3::protocol::OK, "Events enabled");
......@@ -358,7 +359,8 @@ void p3::clientHandler::push_event(
const std::string& e,
const std::string& a2,
const std::string& a3,
const std::string& a4
const std::string& a4,
const std::string& a5
) {
std::lock_guard<std::recursive_mutex> g(connection_write_mutex);
......@@ -374,6 +376,9 @@ void p3::clientHandler::push_event(
if (!a4.empty()) {
connection.send(p3::protocol::TEXT, a4, 1);
}
if (!a5.empty()) {
connection.send(p3::protocol::TEXT, a5, 1);
}
connection.send(p3::protocol::ENDTEXT, "End Event", 1);
} catch (p3::perror & e) {
hook.unregister_callback(push_event_callback);
......
......@@ -146,7 +146,8 @@ namespace p3 {
const std::string& event,
const std::string& a2 = "",
const std::string& a3 = "",
const std::string& a4 = ""
const std::string& a4 = "",
const std::string& a5 = ""
);
public:
......
Markdown is supported
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