Commit f0837450 authored by jpbl's avatar jpbl
Browse files

See ChangeLog

parent cefaab14
......@@ -13,6 +13,7 @@ Management of account (add, remove, ...)
Management of exceptions
Remove all warnings in compilation
Add unregister method when application is closed
Better handling for an reINVITE request.
For project dependencies:
------------------------
......
......@@ -27,10 +27,12 @@ using namespace std;
EventThread::EventThread (SipVoIPLink* sip) : Thread ()
{
_sipthread = sip;
setCancel(cancelDeferred);
}
EventThread::~EventThread (void)
{
terminate();
}
/**
......@@ -39,8 +41,8 @@ EventThread::~EventThread (void)
void
EventThread::run (void)
{
while(1) {
_sipthread->getEvent();
}
while(testCancel()) {
_sipthread->getEvent();
}
}
......@@ -36,14 +36,12 @@
int
main (int argc, char **argv) {
int exit_code;
int exit_code = 0;
Config::setTree(new ConfigurationTree());
GuiFramework *GUI;
#if defined(GUI_QT)
{
utilspp::LifetimeLibraryGuard< utilspp::LifetimeLibrarySingleton > guard();
(void)guard;
QApplication a(argc, argv);
Manager::instance().initConfigFile();
GUI = new QtGUIMainWindow (0, 0 ,
......@@ -55,6 +53,7 @@ main (int argc, char **argv) {
a.setMainWidget((QtGUIMainWindow*)GUI);
exit_code = a.exec();
Manager::instance().terminate();
}
#endif
......
......@@ -25,10 +25,7 @@
#include "managerimpl.h"
typedef utilspp::SingletonHolder< ManagerImpl,
utilspp::CreationUsingNew,
utilspp::LifetimeLibrary,
utilspp::ThreadingSingle > Manager;
typedef utilspp::SingletonHolder< ManagerImpl > Manager;
#endif
......@@ -55,86 +55,109 @@ using namespace ost;
ManagerImpl::ManagerImpl (void)
{
// initialize random generator
srand (time(NULL));
// Init private variables
_callVector = new CallVector();
_voIPLinkVector = new VoIPLinkVector();
_error = new Error();
_tone = new ToneGenerator();
_nCalls = 0;
_nCodecs = 0;
_currentCallId = 0;
_startTime = 0;
_endTime = 0;
_path = "";
_zonetone = false;
_congestion = false;
_ringtone = false;
_ringback = false;
_exist = 0;
_loaded = false;
// initialize random generator
srand (time(NULL));
// Init private variables
_error = new Error();
_tone = new ToneGenerator();
_nCalls = 0;
_nCodecs = 0;
_currentCallId = 0;
_startTime = 0;
_endTime = 0;
_path = "";
_zonetone = false;
_congestion = false;
_ringtone = false;
_ringback = false;
_exist = 0;
_loaded = false;
}
ManagerImpl::~ManagerImpl (void)
{
delete _callVector;
delete _voIPLinkVector;
delete _error;
delete _tone;
delete _codecDescVector;
delete _audiodriverPA;
terminate();
for(VoIPLinkVector::iterator pos = _voIPLinkVector.begin();
pos != _voIPLinkVector.end();
pos++) {
delete *pos;
}
for(CallVector::iterator pos = _callVector.begin();
pos != _callVector.end();
pos++) {
delete *pos;
}
delete _error;
delete _tone;
delete _audiodriverPA;
}
void
ManagerImpl::init (void)
{
// Set a sip voip link by default
_voIPLinkVector->push_back(new SipVoIPLink(DFT_VOIP_LINK));
terminate();
// Set a sip voip link by default
_voIPLinkVector.push_back(new SipVoIPLink(DFT_VOIP_LINK));
if (_exist == 0) {
_debug("Cannot create config file in your home directory\n");
}
if (_exist == 2) {
// If config-file doesn't exist, launch configuration setup
_gui->setup();
}
initAudioCodec();
try {
selectAudioDriver();
loaded(true);
}
catch (const portaudio::PaException &e)
{
displayError(e.paErrorText());
}
catch (const portaudio::PaCppException &e)
{
displayError(e.what());
}
catch (const exception &e)
{
displayError(e.what());
}
catch (...)
{
displayError("An unknown exception occured.");
}
_voIPLinkVector.at(DFT_VOIP_LINK)->init();
if (_exist == 0) {
_debug("Cannot create config file in your home directory\n");
}
if (_exist == 2) {
// If config-file doesn't exist, launch configuration setup
_gui->setup();
}
initAudioCodec();
if (_voIPLinkVector.at(DFT_VOIP_LINK)->checkNetwork()) {
// If network is available
if (get_config_fields_int(SIGNALISATION, AUTO_REGISTER) == YES and
_exist == 1) {
if (registerVoIPLink() != 1) {
_debug("Registration failed\n");
}
}
}
}
try {
selectAudioDriver();
loaded(true);
}
catch (const portaudio::PaException &e)
{
displayError(e.paErrorText());
}
catch (const portaudio::PaCppException &e)
{
displayError(e.what());
}
catch (const exception &e)
{
displayError(e.what());
}
catch (...)
{
displayError("An unknown exception occured.");
}
_voIPLinkVector->at(DFT_VOIP_LINK)->init();
if (_voIPLinkVector->at(DFT_VOIP_LINK)->checkNetwork()) {
// If network is available
if (get_config_fields_int(SIGNALISATION, AUTO_REGISTER) == YES and
_exist == 1) {
if (registerVoIPLink() != 1) {
_debug("Registration failed\n");
}
}
}
void ManagerImpl::terminate()
{
for(VoIPLinkVector::iterator pos = _voIPLinkVector.begin();
pos != _voIPLinkVector.end();
pos++) {
(*pos)->terminate();
}
_voIPLinkVector.clear();
}
void
......@@ -188,16 +211,22 @@ ManagerImpl::setCurrentCallId (short currentCallId)
CallVector*
ManagerImpl::getCallVector (void)
{
return _callVector;
return &_callVector;
}
CodecDescriptorVector*
ManagerImpl::getCodecDescVector (void)
{
return &_codecDescVector;
}
Call*
ManagerImpl::getCall (short id)
{
if (id > 0 and _callVector->size() > 0) {
if (id > 0 and _callVector.size() > 0) {
for (unsigned int i = 0; i < _nCalls; i++) {
if (_callVector->at(i)->getId() == id) {
return _callVector->at(i);
if (_callVector.at(i)->getId() == id) {
return _callVector.at(i);
}
}
return NULL;
......@@ -222,30 +251,24 @@ ManagerImpl::setNumberOfCodecs (unsigned int nb_codec)
VoIPLinkVector*
ManagerImpl::getVoIPLinkVector (void)
{
return _voIPLinkVector;
}
CodecDescriptorVector*
ManagerImpl::getCodecDescVector (void)
{
return _codecDescVector;
return &_voIPLinkVector;
}
void
ManagerImpl::pushBackNewCall (short id, enum CallType type)
{
Call* call = new Call(id, type, _voIPLinkVector->at(DFT_VOIP_LINK));
Call* call = new Call(id, type, _voIPLinkVector.at(DFT_VOIP_LINK));
// Set the wanted voip-link (first of the list)
_callVector->push_back(call);
_callVector.push_back(call);
}
void
ManagerImpl::deleteCall (short id)
{
unsigned int i = 0;
while (i < _callVector->size()) {
if (_callVector->at(i)->getId() == id) {
_callVector->erase(_callVector->begin()+i);
while (i < _callVector.size()) {
if (_callVector.at(i)->getId() == id) {
_callVector.erase(_callVector.begin()+i);
return;
} else {
i++;
......@@ -422,7 +445,7 @@ ManagerImpl::saveConfig (void)
int
ManagerImpl::registerVoIPLink (void)
{
if (_voIPLinkVector->at(DFT_VOIP_LINK)->setRegister() == 0) {
if (_voIPLinkVector.at(DFT_VOIP_LINK)->setRegister() == 0) {
return 1;
} else {
return 0;
......@@ -432,7 +455,7 @@ ManagerImpl::registerVoIPLink (void)
int
ManagerImpl::unregisterVoIPLink (void)
{
if (_voIPLinkVector->at(DFT_VOIP_LINK)->setUnregister() == 0) {
if (_voIPLinkVector.at(DFT_VOIP_LINK)->setUnregister() == 0) {
return 1;
} else {
return 0;
......@@ -443,13 +466,8 @@ int
ManagerImpl::quitApplication (void)
{
// Quit VoIP-link library
_voIPLinkVector->at(DFT_VOIP_LINK)->quit();
if (saveConfig()) {
return 1;
} else {
return 0;
}
Config::deleteTree();
terminate();
Config::deleteTree();
}
int
......@@ -472,7 +490,7 @@ ManagerImpl::sendDtmf (short id, char code)
switch (sendType) {
// SIP INFO
case 0:
_voIPLinkVector->at(DFT_VOIP_LINK)->carryingDTMFdigits(id, code);
_voIPLinkVector.at(DFT_VOIP_LINK)->carryingDTMFdigits(id, code);
return 1;
break;
......@@ -783,7 +801,7 @@ ManagerImpl::generateNewCallId (void)
unsigned int
ManagerImpl::callVectorSize (void)
{
return _callVector->size();
return _callVector.size();
}
int
......@@ -857,15 +875,13 @@ void
ManagerImpl::initAudioCodec (void)
{
_nCodecs = get_config_fields_int(AUDIO, NB_CODEC);
_codecDescVector = new CodecDescriptorVector();
_codecDescVector->push_back(new CodecDescriptor(
_codecDescVector.push_back(new CodecDescriptor(
get_config_fields_str(AUDIO, CODEC1)));
_codecDescVector->push_back(new CodecDescriptor(
_codecDescVector.push_back(new CodecDescriptor(
get_config_fields_str(AUDIO, CODEC2)));
_codecDescVector->push_back(new CodecDescriptor(
_codecDescVector.push_back(new CodecDescriptor(
get_config_fields_str(AUDIO, CODEC3)));
}
......
......@@ -81,6 +81,7 @@ public:
// Init a new VoIPLink, audio codec and audio driver
void init (void);
void terminate (void);
// Set the graphic user interface
void setGui (GuiFramework* gui);
......@@ -285,17 +286,17 @@ private:
/*
* Vector of VoIPLink
*/
VoIPLinkVector* _voIPLinkVector;
VoIPLinkVector _voIPLinkVector;
/*
* Vector of calls
*/
CallVector* _callVector;
CallVector _callVector;
/*
* Vector of CodecDescriptor
*/
CodecDescriptorVector* _codecDescVector;
CodecDescriptorVector _codecDescVector;
/*
* Mutex to protect access to code section
......
......@@ -29,6 +29,7 @@
#include <vector>
#include "voIPLink.h"
#include "eventthread.h"
using namespace std;
......@@ -63,7 +64,6 @@ using namespace std;
class AudioCodec;
class AudioRtp;
class CodecDescriptor;
class EventThread;
class SipCall;
/*
......@@ -83,7 +83,7 @@ public:
virtual int init (void);
virtual bool checkNetwork (void);
virtual void quit (void);
virtual void terminate (void);
virtual int setRegister (void);
virtual int setUnregister (void);
virtual int outgoingInvite (short id, const string& to_url);
......@@ -215,7 +215,7 @@ private:
///////////////////////////
// Private member variables
///////////////////////////
EventThread* _evThread;
EventThread *_evThread;
SipCallVector* _sipcallVector;
AudioRtp* _audiortp;
int _localPort;
......
......@@ -41,7 +41,7 @@ public:
virtual int getEvent (void) = 0;
virtual int init (void) = 0;
virtual bool checkNetwork (void) = 0;
virtual void quit (void) = 0;
virtual void terminate (void) = 0;
virtual void newOutgoingCall (short callid) = 0;
virtual void newIncomingCall (short callid) = 0;
virtual void deleteSipCall (short callid) = 0;
......
......@@ -38,5 +38,6 @@ namespace utilspp
};
};
#include "LifetimeDefault.inl"
#endif
Supports Markdown
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