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

Added some documentation to the code.

parent 28a5878f
Loading
Loading
Loading
Loading
+69 −2
Original line number Diff line number Diff line
@@ -16,16 +16,22 @@
 * along with 3phone.  If not, see <http://www.gnu.org/licenses/>.
 **/

#include <iostream>

#include "call.h"
#include "sipphone.h"
#include "phonebook.h"
#include "error.h"

p3::call::call(int i, p3::sipphone &p, p3::account &acc, int call_id) :
	Call(acc, call_id),
	phone(p),
	p3id(i),
	state(p3::callState::NONE),
	ringing(false)
	ringing(false),
	hold(false),
	mute(false),
	aud_med(nullptr)
{}

p3::call::~call() {
@@ -74,13 +80,17 @@ void p3::call::onCallState(pj::OnCallStateParam& prm) {
void p3::call::onCallMediaState(pj::OnCallMediaStateParam& prm) {
	pj::CallInfo ci = getInfo();

	aud_med = nullptr;
    for (unsigned i = 0; i < ci.media.size(); i++) {
        if (ci.media[i].type==PJMEDIA_TYPE_AUDIO && getMedia(i)) {
			pj::AudioMedia *aud_med = static_cast<pj::AudioMedia*>(getMedia(i));
			std::cout << "media reconnect." << std::endl;
			aud_med = static_cast<pj::AudioMedia*>(getMedia(i));

			pj::AudDevManager& mgr = pj::Endpoint::instance().audDevManager();
            aud_med->startTransmit(mgr.getPlaybackDevMedia());
            mgr.getCaptureDevMedia().startTransmit(*aud_med);

			break;
        }
    }
}
@@ -100,3 +110,60 @@ p3::callState p3::call::get_state() {
char p3::call::get_state_char() {
	return static_cast<char>(state);
}

void p3::call::hold_toggle() {
	try {
		std::cout << "holdtx" << std::endl;
		pj::AudDevManager& mgr = pj::Endpoint::instance().audDevManager();
		pj::CallOpParam o;
		if (hold) {
			if (phone.hold_music == nullptr) {
				reinvite(o);
			} else if (aud_med != nullptr) {
				phone.hold_music->stopTransmit(*aud_med);
				aud_med->startTransmit(mgr.getPlaybackDevMedia());
				mgr.getCaptureDevMedia().startTransmit(*aud_med);
			}
			hold = false;
		} else {
			if (phone.hold_music == nullptr) {
				setHold(o);
			} else if (aud_med != nullptr) {
				aud_med->stopTransmit(mgr.getPlaybackDevMedia());
				mgr.getCaptureDevMedia().stopTransmit(*aud_med);
				phone.hold_music->startTransmit(*aud_med);
			}
			hold = true;
		}
	} catch (pj::Error& e) {
		throw p3::perror("call:hold toggle", e.info());
	}
}

void p3::call::mute_toggle() {
	if (ringing) {
		phone.stop_ringing();
		ringing = false;
		return;
	}
	try {
		if (mute) {
			if (aud_med != nullptr) {
				aud_med->adjustRxLevel(1);
			}
			mute = false;
		} else {
			if (aud_med != nullptr) {
				std::cout << "mutetx" << std::endl;
				aud_med->adjustRxLevel(0);
			}
			mute = true;
		}
	} catch (pj::Error& e) {
		throw p3::perror("call:hold toggle", e.info());
	}
}

pj::AudioMedia* p3::call::get_audio_media() {
	return aud_med;
}
+10 −0
Original line number Diff line number Diff line
@@ -45,6 +45,11 @@ namespace p3 {
		callState state;

		bool ringing;
		bool hold;
		bool mute;

		pj::AudioMedia* aud_med;


		public:
			call(int id, sipphone& p, account& acc, int call_id = PJSUA_INVALID_ID);
@@ -55,11 +60,16 @@ namespace p3 {

			void onCallMediaState(pj::OnCallMediaStateParam &prm);

			pj::AudioMedia* get_audio_media();

			int get_id();
			std::string get_nr();

			callState get_state();
			char get_state_char();

			void hold_toggle();
			void mute_toggle();
	};
}

+8 −0
Original line number Diff line number Diff line
@@ -28,8 +28,16 @@
std::map<std::string, std::string> p3::client::command_shorthands {
	{"c", "call"},
	{"h", "hangup"},
	{"ha", "hangupall"},
	{"p", "hold"},
	{"pause", "hold"},
	{"m", "mute"},
	{"ma", "muteall"},
	{"a", "answer"},
	{"l", "list"},
	{"j", "conference"},
	{"t", "transfer"},
	{"join", "conference"},
	{"q", "quit"},
	{"x", "exit"}
};
+10 −0
Original line number Diff line number Diff line
@@ -27,6 +27,16 @@

namespace p3 {

	/**
	 * Basic client for 3phone server. Just opens a connection to the server,
	 * sends any command given on the commandline, asks for more information
	 * if needed, prints the server response and exits.
	 * There is a interactive mode where commands can be entered on stdin.
	 *
	 * This is nothing more than a fronted to the very uncomfortable message
	 * queue based ui of the server.
	 */

	class client {

		mQueue * connection;
+24 −7
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@

#include <fstream>
#include <sstream>
#include <iostream>

#include <boost/algorithm/string.hpp>

#include "config.h"
#include "error.h"

p3::config::config(std::string p, std::map<std::string, std::string>& d) : data(d), defaults(d), filename(p) {
	load_config();
@@ -62,15 +64,30 @@ void p3::config::save_config() {
	f.close();
}

std::string p3::config::get_string(std::string k) {
std::string p3::config::get_string(const std::string& k) {
	try {
		return data.at(k);
	} catch (std::out_of_range& e) {
		std::cout << "!! config::get_string(): Invalide configuration key: " << k << std::endl;
		throw;
	}
}

int p3::config::get_int(std::string k) {
int p3::config::get_int(const std::string& k) {
	try {
		return std::stoi(data.at(k));
	} catch (std::out_of_range& e) {
		std::cout << "!! config::get_string(): Invalide configuration key: " << k << std::endl;
		throw;
	}
}

bool p3::config::get_bool(std::string k) {
bool p3::config::get_bool(const std::string& k) {
	try {
		std::string s = data.at(k);
		return (s == "true" || s == "True" || s == "1");
	} catch (std::out_of_range& e) {
		std::cout << "!! config::get_string(): Invalide configuration key: " << k << std::endl;
		throw;
	}
}
Loading