Commit 08fd8065 authored by Gabriel Margiani's avatar Gabriel Margiani

call hook on new reverse lookup result.

parent 3111b395
......@@ -24,10 +24,11 @@
#include <cstdio>
#include "phonebook.h"
#include "eventhook.h"
p3::config* p3::phonebook::conf = nullptr;
p3::phonebook::phonebook() : id_count(0), add_stop(false) {
p3::phonebook::phonebook() : hook(nullptr), id_count(0), add_stop(false) {
add_thread = new std::thread(&p3::phonebook::add_worker, this);
}
......@@ -79,6 +80,10 @@ void p3::phonebook::set_config(p3::config& c) {
conf = &c;
}
void p3::phonebook::set_hook(p3::eventHook& h) {
hook = &h;
}
void p3::phonebook::add_worker() {
while (true) {
{
......@@ -133,6 +138,9 @@ void p3::phonebook::add_number(const std::string& nr) {
boost::trim(name);
std::cout << "PHONEBOOK: Got name for '" << nr << "': '" << name << "'" << std::endl;
if (hook && !name.empty()) {
hook->run_hook("reverse_lookup_result", nr, name);
}
g.lock();
......
......@@ -32,6 +32,8 @@
namespace p3 {
class eventHook;
/**
* The phonebook class represents a simple phone-book with the
* functionality to convert between sip uri's, simple phone numbers,
......@@ -45,6 +47,7 @@ namespace p3 {
class phonebook {
static config* conf;
eventHook* hook;
int id_count;
std::map<int, std::array<std::string, 3> > data;
......@@ -73,6 +76,7 @@ namespace p3 {
~phonebook();
static void set_config(config& conf);
void set_hook(eventHook& hook);
// Load the phonebook from disc
void load();
......
......@@ -57,6 +57,7 @@ p3::server::server(bool& r) :
{
restart_flag = false;
p3::phonebook::set_config(conf);
book.set_hook(hook);
book.load();
}
......
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