Commit 3d6f267f authored by Gabriel Margiani's avatar Gabriel Margiani

Implemented dtmf send functionality

parent b46d6ca0
......@@ -38,6 +38,7 @@ std::map<std::string, std::string> p3::client::command_shorthands {
{"j", "conference"},
{"t", "transfer"},
{"join", "conference"},
{"d", "dtmf"},
{"q", "quit"},
{"x", "exit"}
};
......@@ -112,6 +113,9 @@ void p3::client::run() {
p3::mQueueMessage m = connection->receive(-1);
bool print_list = true;
switch (m.get_command()) {
case p3::protocol::ASK:
connection->send(p3::protocol::ANSWER, get_input(m.get_value(), WORD));
continue;
case p3::protocol::ASK_NUMBER:
connection->send(p3::protocol::ANSWER, get_input(m.get_value(), NUMBER));
continue;
......
......@@ -49,7 +49,8 @@ namespace p3 {
enum inputType {
COMMAND,
NUMBER,
ID
ID,
WORD
};
bool interactive;
......
......@@ -48,6 +48,7 @@ void print_usage() {
<< "p3 ma muteall - mute microphone for all calls." << std::endl
<< "p3 j oin - conference current calls" << std::endl
<< "p3 t ransfer [id] [nr] - forward call" << std::endl
<< "p3 d tmf [dgts] [id] - dial dtfm digits" << std::endl
<< "p3 r ecord [file] - record" << std::endl
<< "-I for an interactive shell" << std::endl;
}
......
......@@ -170,6 +170,8 @@ void p3::clientHandler::parse_command(const std::string& c) {
handle_list();
} else if ("reload" == c) {
handle_reload();
} else if ("dtmf" == c) {
handle_dtmf();
} else {
std::cout << "Unknown command received: " << c << std::endl;
connection.send(p3::protocol::ERROR, "Invalid Command '" + c + "'");
......@@ -247,6 +249,16 @@ void p3::clientHandler::handle_reload() {
connection.send(p3::protocol::OK, "reload OK");
}
void p3::clientHandler::handle_dtmf() {
connection.send(p3::protocol::ASK, "Digits to send");
p3::mQueueMessage n = connection.receive(listenTimeout);
phone.dial_dtmf(
get_call_id("Call do dial on (id)", p3::callState::RUNNING),
n.get_value()
);
connection.send(p3::protocol::OK, "dtmf OK");
}
int p3::clientHandler::get_call_id(const std::string& q, p3::callState filter) {
int nr = phone.get_call_count(filter);
if (nr == 1) {
......
......@@ -116,6 +116,7 @@ namespace p3 {
void handle_reload();
void handle_conference();
void handle_transfer();
void handle_dtmf();
void send_calls_list(
callState filter = callState::NONE,
......
......@@ -299,6 +299,15 @@ void p3::sipphone::transfer(int id, int destId) {
}
}
void p3::sipphone::dial_dtmf(int id, const std::string& digits) {
std::lock_guard<std::mutex> g(calls_mutex);
try {
get_call_by_id(id)->dialDtmf(digits);
} catch (pj::Error &e) {
throw p3::perror("sipphone:dial_dtmf", e.info());
}
}
p3::call* p3::sipphone::get_call_by_id(int id, p3::callState f, bool update_active) {
bool id_given = (id != -1);
id = (id == -1) ? active_call.load() : id;
......
......@@ -94,6 +94,7 @@ namespace p3 {
void global_mute_toggle();
void conference();
void transfer(int id, int destId = -1);
void dial_dtmf(int id, const std::string& digits);
int get_call_count(callState filter = callState::NONE);
std::map<int, std::pair<std::string, char> > get_call_list(callState filter = callState::NONE);
......
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