Commit c205a4a4 authored by Gabriel Margiani's avatar Gabriel Margiani

added status command.

parent 69c2410e
......@@ -43,11 +43,12 @@ std::map<std::string, std::string> p3::client::command_shorthands {
{"d", "dtmf"},
{"rr", "reregister"},
{"rl", "reload"},
{"st", "status"},
{"q", "quit"},
{"x", "exit"}
};
p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false), verbose(false) {
p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false), verbose(0) {
argv.pop_front();
auto i = std::find(argv.begin(), argv.end(), "-I");
if (i != argv.end()) {
......@@ -55,9 +56,8 @@ p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false), ve
argv.erase(i);
}
i = std::find(argv.begin(), argv.end(), "-v");
if (i != argv.end()) {
verbose = true;
while ((i = std::find(argv.begin(), argv.end(), "-v")) != argv.end()) {
verbose += 1;
argv.erase(i);
}
......@@ -68,10 +68,10 @@ p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false), ve
connection = nullptr;
try {
if (verbose) std::cout << "connecting..." << std::endl;
p3::mQueue ma(p3::mQueue::DefaultId, false, verbose);
if (verbose >= 2) std::cout << "connecting..." << std::endl;
p3::mQueue ma(p3::mQueue::DefaultId, false, (verbose >= 3));
connection = new mQueue(id, true, verbose);
connection = new mQueue(id, true, (verbose >= 4));
ma.send(p3::protocol::HELLO, id);
p3::mQueueMessage m = connection->receive(30);
......@@ -146,7 +146,7 @@ void p3::client::run() {
}
continue;
case p3::protocol::OK:
std::cout << m.get_value() << std::endl;
if (verbose >= 1) std::cout << m.get_value() << std::endl;
break;
case p3::protocol::ERROR:
std::cout << "ERROR: " << m.get_value() << std::endl;
......
......@@ -54,7 +54,7 @@ namespace p3 {
};
bool interactive;
bool verbose;
int verbose;
std::string get_input(std::string question, inputType is_command);
......
......@@ -37,13 +37,13 @@ void print_usage() {
std::cout << "3phone - p3 usage: " << std::endl
<< "p3 s erve - start the server" << std::endl
<< "p3 quit, stop - terminate server" << std::endl
<< "p3 restart - restart server" << std::endl
<< "p3 reload - reload phonebook and some parts of the configuration." << std::endl
<< "p3 reregister - renew registration on sip server." << std::endl
<< "p3 restart - restart server" << std::endl
<< "p3 reload (rl) - reload phonebook and some parts of the configuration." << std::endl
<< "p3 reregister (rr) - renew registration on sip server." << std::endl
<< "p3 c all [nr] - call someone" << std::endl
<< "p3 a nswer - answer a currently ringing call" << std::endl
<< "p3 b usy - answer busy to a currently ringing call" << std::endl
<< "p3 b usyall - toggle: answer all incoming calls with busy" << std::endl
<< "p3 b usy - answer busy to a currently ringing call" << std::endl
<< "p3 b usyall - toggle: answer all incoming calls with busy" << std::endl
<< "p3 l ist - list current calls" << std::endl
<< "p3 h angup [id] - hanup" << std::endl
<< "p3 ha ngupall - hanup all current calls" << std::endl
......@@ -53,8 +53,9 @@ void print_usage() {
<< "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 st atus - dump server status" << std::endl
<< "-I for an interactive shell" << std::endl
<< "-v for verbose output (not with serve)" << std::endl;
<< "-v for verbose output (not with serve, can be specified multiple times for more output)" << std::endl;
}
int run_server() {
......
......@@ -192,6 +192,8 @@ void p3::clientHandler::parse_command(const std::string& c) {
handle_reload();
} else if ("dtmf" == c) {
handle_dtmf();
} else if ("status" == c) {
handle_status();
} else {
std::cout << "Unknown command received: " << c << std::endl;
connection.send(p3::protocol::ERROR, "Invalid Command '" + c + "'");
......@@ -297,6 +299,18 @@ void p3::clientHandler::handle_dtmf() {
connection.send(p3::protocol::OK, "dtmf OK");
}
void p3::clientHandler::handle_status() {
connection.send(p3::protocol::BEGINTEXT, "Begin Status");
auto l = phone.get_status_dump();
for (auto v : l) {
connection.send(p3::protocol::TEXT, "p3" + v.first + "='" + v.second + "'");
}
connection.send(p3::protocol::ENDTEXT, "End Status");
connection.send(p3::protocol::OK, "Status OK");
}
int p3::clientHandler::get_call_id(const std::string& q, p3::callState filter) {
int nr = phone.get_call_count(filter);
if (nr == 1) {
......
......@@ -123,6 +123,7 @@ namespace p3 {
void handle_conference();
void handle_transfer();
void handle_dtmf();
void handle_status();
void send_calls_list(
callState filter = callState::NONE,
......
......@@ -420,6 +420,28 @@ std::map<int, std::pair<std::string, char> > p3::sipphone::get_call_list(p3::cal
return s;
}
std::map<std::string, std::string> p3::sipphone::get_status_dump() {
std::map<std::string, std::string> l;
// Registration status
pj::AccountInfo ri = acc->getInfo();
l["regURI"] = ri.uri;
l["regStatus"] = std::to_string(ri.regStatus);
l["regStatusText"] = ri.regStatusText;
l["regError"] = ri.regLastErr;
// calls
l["callCount"] = std::to_string(get_call_count());
l["callActiveCount"] = std::to_string(get_call_count(p3::callState::RUNNING));
l["callRingingCount"] = std::to_string(get_call_count(p3::callState::INCOMING));
// Global toggles
l["allMute"] = std::to_string(mute);
l["allBusy"] = std::to_string(always_busy);
return l;
}
p3::eventHook& p3::sipphone::get_event_hook() {
......
......@@ -112,6 +112,7 @@ namespace p3 {
int get_id_by_nr(const std::string& nr);
std::string get_nr_by_id(int id = -1);
std::map<std::string, std::string> get_status_dump();
friend class call;
friend class account;
......
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