Commit c205a4a4 authored by Gabriel Margiani's avatar Gabriel Margiani
Browse files

added status command.

parent 69c2410e
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ namespace p3 {
		};

		bool interactive;
		bool verbose;
		int verbose;

		std::string get_input(std::string question, inputType is_command);

+7 −6
Original line number Diff line number Diff line
@@ -38,8 +38,8 @@ void print_usage() {
		<< "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 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
@@ -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() {
+14 −0
Original line number Diff line number Diff line
@@ -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) {
+1 −0
Original line number Diff line number Diff line
@@ -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,
Loading