Commit 02d6fbf0 authored by Gabriel Margiani's avatar Gabriel Margiani
Browse files

Telefon.

parent 70bc1292
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
--language=c++
--enable=all
--suppress=unusedFunction
+13 −2
Original line number Diff line number Diff line
@@ -17,13 +17,24 @@
 **/

#include "account.h"
#include "call.h"
#include "sipphone.h"

p3::account::account() {};
p3::account::account(sipphone& p) : phone(p){};
p3::account::~account() {};

void p3::account::onRegState(pj::OnRegStateParam &prm) {
}

void p3::account::onIncomingCall(pj::OnIncomingCallParam &iprm) {

	p3::call* c = phone.register_new_call(iprm.callId);
	phone.register_number(c->get_nr(), c->get_id());
	pj::CallOpParam o;
	if (phone.get_call_count() < 1) {
		o.statusCode = PJSIP_SC_BUSY_HERE;
		c->answer(o);
	} else {
		o.statusCode = PJSIP_SC_RINGING;
		c->answer(o);
	}
}
+6 −1
Original line number Diff line number Diff line
@@ -23,9 +23,14 @@
#include <pjsua2.hpp>

namespace p3 {
	class sipphone;

	class account : public pj::Account {

		sipphone& phone;

		public:
			account();
			explicit account(sipphone& p);
			~account();

			virtual void onRegState(pj::OnRegStateParam &prm);
+57 −4
Original line number Diff line number Diff line
@@ -18,19 +18,56 @@

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

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

p3::call::~call() {
	if (ringing) {
		phone.stop_ringing();
	}
}

void p3::call::onCallState(pj::OnCallStateParam& prm) {
	pj::CallInfo ci = getInfo();
    if (ci.state == PJSIP_INV_STATE_DISCONNECTED) {
		phone.delete_call(getId());
    switch (ci.state) {
		case PJSIP_INV_STATE_DISCONNECTED:
			phone.get_event_hook().run_hook("disconnected", p3id, get_nr());
			state = p3::callState::NONE;
			phone.delete_call(p3id);
			break;
		case PJSIP_INV_STATE_CALLING:
			state = p3::callState::CALLING;
			phone.get_event_hook().run_hook("calling", p3id, get_nr());
			break;
		case PJSIP_INV_STATE_CONFIRMED:
			state = p3::callState::RUNNING;
			if (ringing) {
				phone.stop_ringing();
				ringing = false;
			}
			break;
		case PJSIP_INV_STATE_EARLY:
			if (ci.role == PJSIP_ROLE_UAS) {
				if (!ringing) {
					phone.start_ringing();
					ringing = true;
				}
				state = p3::callState::INCOMMING;
				phone.get_event_hook().run_hook("incomming", p3id, get_nr());
			}
			break;
		case PJSIP_INV_STATE_NULL:
		case PJSIP_INV_STATE_INCOMING:
		case PJSIP_INV_STATE_CONNECTING:
		default:
			break;
    }
}

@@ -47,3 +84,19 @@ void p3::call::onCallMediaState(pj::OnCallMediaStateParam& prm) {
        }
    }
}

int p3::call::get_id() {
	return p3id;
}

std::string p3::call::get_nr() {
	return p3::phonebook::normalize_number(getInfo().remoteUri);
}

p3::callState p3::call::get_state() {
	return state;
}

char p3::call::get_state_char() {
	return static_cast<char>(state);
}
+23 −1
Original line number Diff line number Diff line
@@ -22,22 +22,44 @@
#include <pjsua2.hpp>

#include "account.h"
#include "eventhook.h"

namespace p3 {

	class sipphone;

	enum class callState: char {
		NONE = 'X',
		CALLING = 'c',
		INCOMMING = '*',
		RUNNING = ' ',
		HOLDING = '&'
	};

	class call : public pj::Call {

		p3::sipphone & phone;

		int p3id;

		callState state;

		bool ringing;

		public:
			call(sipphone& p, account& acc, int call_id = PJSUA_INVALID_ID);
			call(int id, sipphone& p, account& acc, int call_id = PJSUA_INVALID_ID);

			~call();

			void onCallState(pj::OnCallStateParam &prm);

			void onCallMediaState(pj::OnCallMediaStateParam &prm);

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

			callState get_state();
			char get_state_char();
	};
}

Loading