getcallstatus support corrected

No segmentation fault on refuse a non-progressing call
No segmentation fault on opening two sflphone(d)
This commit is contained in:
yanmorin
2005-09-30 15:42:42 +00:00
parent fddfca0ac1
commit d284ed42e9
12 changed files with 144 additions and 72 deletions

View File

@ -150,6 +150,8 @@ ConfigTree::setConfigTreeItem(const std::string& section, const std::string& ite
}
// Save config to a file (ini format)
// return false if empty, no config, or enable to open
// return true if everything is ok
bool
ConfigTree::saveConfigTree(const std::string& fileName) {
if (fileName.empty() && _sections.begin() == _sections.end() ) {
@ -178,7 +180,7 @@ ConfigTree::saveConfigTree(const std::string& fileName) {
}
file.close();
return false;
return true;
}
// Create the tree from an existing ini file

View File

@ -51,11 +51,10 @@ public:
virtual void sendVoiceNbMessage(const std::string& nb_msg) = 0;
virtual void sendMessage(const std::string& code, const std::string& seqId, TokenList& arg) = 0;
virtual void sendCallMessage(const std::string& seqId,
short id,
const std::string& accountId,
const std::string& status
) = 0;
virtual void sendCallMessage(const std::string& code,
const std::string& sequenceId,
short id,
TokenList arg) = 0;
/* Child class to parent class */
int outgoingCall (const std::string& to);

View File

@ -1677,7 +1677,7 @@ QtGUIMainWindow::pressedKeySlot (int id) {
_lcd->setIsScrolling(false);
phLines[getCurrentLine()]->setScrolling(false);
}
AudioLayer* audiolayer = Manager::instance().getAudioDriver();
// To generate the dtmf if there is no error in configuration
if (Manager::instance().error()->getError() == 0) {
// Handle dtmf
@ -1697,19 +1697,19 @@ QtGUIMainWindow::pressedKeySlot (int id) {
buf_ctrl_vol[k] = buf_ctrl_vol[k+1] = _buf[j] * spkrVolume/100;
}
Manager::instance().getAudioDriver()->urgentRingBuffer().flush();
audiolayer->urgentRingBuffer().flush();
// Put buffer to urgentRingBuffer
Manager::instance().getAudioDriver()->urgentRingBuffer().Put(buf_ctrl_vol,
audiolayer->urgentRingBuffer().Put(buf_ctrl_vol,
size * CHANNELS);
// We activate the stream if it's not active yet.
if (!Manager::instance().getAudioDriver()->isStreamActive()) {
Manager::instance().getAudioDriver()->startStream();
Manager::instance().getAudioDriver()->sleep(pulselen);
Manager::instance().getAudioDriver()->stopStream();
Manager::instance().getAudioDriver()->urgentRingBuffer().flush();
if (!audiolayer->isStreamActive()) {
audiolayer->startStream();
audiolayer->sleep(pulselen);
audiolayer->stopStream();
audiolayer->urgentRingBuffer().flush();
} else {
Manager::instance().getAudioDriver()->sleep(pulselen);
audiolayer->sleep(pulselen);
}
delete[] buf_ctrl_vol;

View File

@ -97,11 +97,10 @@ public:
virtual std::string getRingtoneFile (void);
virtual void setup (void);
virtual void sendMessage(const std::string& code, const std::string& seqId, TokenList& arg) {}
virtual void sendCallMessage(const std::string& seqId,
short id,
const std::string& accountId,
const std::string& status
) {}
virtual void sendCallMessage(const std::string& code,
const std::string& sequenceId,
short id,
TokenList arg) {}

View File

@ -389,19 +389,15 @@ GUIServerImpl::sendMessage(const std::string& code, const std::string& seqId, To
}
void
GUIServerImpl::sendCallMessage(const std::string& seqId,
short id,
const std::string& accountId,
const std::string& status
)
GUIServerImpl::sendCallMessage(const std::string& code,
const std::string& sequenceId,
short id,
TokenList arg)
{
try {
std::string callid = getCallIdFromId(id);
TokenList arg;
arg.push_back(callid);
arg.push_back(accountId);
arg.push_back(status);
_requestManager.sendResponse(ResponseMessage("100", seqId, arg));
arg.push_front(callid);
_requestManager.sendResponse(ResponseMessage(code, sequenceId, arg));
} catch(...) {
// no callid found
}

View File

@ -59,11 +59,10 @@ public:
void sendMessage(const std::string& code, const std::string& seqId, TokenList&
arg);
void sendCallMessage(const std::string& seqId,
short id,
const std::string& accountId,
const std::string& status
);
void sendCallMessage(const std::string& code,
const std::string& sequenceId,
short id,
TokenList arg);
bool getEvents(const std::string& sequenceId);
bool sendGetEventsEnd();

View File

@ -52,16 +52,18 @@ ResponseMessage
RequestCallStatus::execute()
{
GUIServer::instance().sendGetEventsEnd();
TokenList tk;
tk.push_back("OK");
std::string code = "205";
GUIServer::instance().getCallStatus(_sequenceId);
std::string callid;
if (GUIServer::instance().getCurrentCallId(callid)) {
GUIServer::instance().getCallStatus(_sequenceId);
TokenList tk;
tk.push_back(callid);
tk.push_back("OK");
return message("205", tk);
tk.push_front(callid);
} else {
return message("206","OK");
code = "206";
}
return message(code, tk);
}
ResponseMessage

View File

@ -87,7 +87,7 @@ RequestManager::exec()
} // end while
} catch(ost::Socket *e) {
std::cerr << e->getErrorString() << std::endl;
std::cerr << "Exception: " << e->getErrorString() << std::endl;
}
return 0;
}

View File

@ -20,10 +20,10 @@ TCPSessionIO::TCPSessionIO() : SessionIO()
ost::InetAddress addr(IP);
//Creating a listening socket
_serverSocket = new ost::TCPSocket(addr, PORT);
if (_serverSocket == 0 ) {
throw new ost::SockException(ost::String("Unable to bind port"),
ost::Socket::errBindingFailed);
try {
_serverSocket = new ost::TCPSocket(addr, PORT);
} catch( ost::Socket *e ) {
throw e;
}
}

View File

@ -42,21 +42,25 @@ main (int argc, char **argv) {
#if defined(ENABLE_MAINTENER)
{
Manager::instance().initConfigFile();
bool initOK = false;
try {
Manager::instance().initConfigFile();
Manager::instance().init();
initOK = true;
}
catch (...) {
std::cerr <<
"An unknown exception occured when initializing the system." <<
std::endl;
"An exception occured when initializing the system." <<
std::endl;
}
GUI = &(GUIServer::instance());
Manager::instance().setGui(GUI);
exit_code = GUIServer::instance().exec();
Manager::instance().terminate();
delete GUI;
}
if (initOK) {
GUI = &(GUIServer::instance());
Manager::instance().setGui(GUI);
exit_code = GUIServer::instance().exec();
Manager::instance().terminate();
delete GUI;
}
}
#elif defined(GUI_QT)
{
QApplication a(argc, argv);

View File

@ -114,9 +114,12 @@ ManagerImpl::~ManagerImpl (void)
delete *pos;
}
unloadAudioCodec();
delete _error;
delete _tone;
delete _audiodriverPA;
#ifdef USE_ZEROCONF
delete _DNSService;
#endif
@ -129,15 +132,10 @@ ManagerImpl::init (void)
initZeroconf();
initVolume();
// 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");
}
initAudioCodec();
try {
selectAudioDriver();
loaded(true);
@ -145,24 +143,30 @@ ManagerImpl::init (void)
catch (const portaudio::PaException &e)
{
displayError(e.paErrorText());
throw e;
}
catch (const portaudio::PaCppException &e)
{
displayError(e.what());
throw e;
}
catch (const exception &e)
{
displayError(e.what());
throw e;
}
catch (...)
{
displayError("An unknown exception occured.");
throw;
}
initAudioCodec();
// Set a sip voip link by default
_voIPLinkVector.push_back(new SipVoIPLink(DFT_VOIP_LINK));
_voIPLinkVector.at(DFT_VOIP_LINK)->init();
if (_voIPLinkVector.at(DFT_VOIP_LINK)->checkNetwork()) {
// If network is available
@ -336,6 +340,7 @@ ManagerImpl::outgoingCall (const string& to)
call->setStatus(string(TRYING_STATUS));
call->setState(Progressing);
call->setCallerIdNumber(to);
if (call->outgoingCall(to) == 0) {
return id;
} else {
@ -438,6 +443,7 @@ ManagerImpl::transferCall (short id, const string& to)
return -1;
call->setStatus(string(TRANSFER_STATUS));
call->setState(Transfered);
setCurrentCallId(0);
return call->transfer(to);
}
void
@ -480,13 +486,18 @@ ManagerImpl::refuseCall (short id)
call = getCall(id);
if (call == NULL)
return -1;
call->setStatus(string(HUNGUP_STATUS));
call->setState(Refused);
ringtone(false);
_mutex.enterMutex();
_nCalls -= 1;
_mutex.leaveMutex();
deleteCall(id);
// don't cause a very bad segmentation fault
// we refuse the call when we are trying to establish connection
if ( call->getState() != Progressing )
return -1;
call->setStatus(string(HUNGUP_STATUS));
call->setState(Refused);
ringtone(false);
_mutex.enterMutex();
_nCalls -= 1;
_mutex.leaveMutex();
deleteCall(id);
setCurrentCallId(0);
return call->refuse();
}
@ -665,6 +676,7 @@ ManagerImpl::peerAnsweredCall (short id)
call->setState(Answered);
//if (isCurrentId(id)) {
setCurrentCallId(id);
_gui->peerAnsweredCall(id);
//}
}
@ -979,8 +991,6 @@ ManagerImpl::createSettingsPath (void) {
void
ManagerImpl::initConfigFile (void)
{
_exist = createSettingsPath();
std::string type_str("string");
std::string type_int("int");
@ -1020,6 +1030,8 @@ ManagerImpl::initConfigFile (void)
fill_config_str(VOICEMAIL_NUM, DFT_VOICEMAIL);
fill_config_int(CONFIG_ZEROCONF, CONFIG_ZEROCONF_DEFAULT_STR);
_exist = createSettingsPath();
// old way
fill_config_fields_int(SIGNALISATION, VOIP_LINK_ID, DFT_VOIP_LINK);
fill_config_fields_str(SIGNALISATION, FULL_NAME, EMPTY_FIELD);
@ -1074,13 +1086,30 @@ ManagerImpl::initAudioCodec (void)
get_config_fields_str(AUDIO, CODEC3)));
}
void
ManagerImpl::unloadAudioCodec()
{
CodecDescriptorVector::iterator iter = _codecDescVector.begin();
while(iter!=_codecDescVector.end()) {
delete *iter;
*iter = NULL;
_codecDescVector.erase(iter);
iter++;
}
}
void
ManagerImpl::selectAudioDriver (void)
{
#if defined(AUDIO_PORTAUDIO)
try {
_audiodriverPA = new AudioLayer();
_audiodriverPA->openDevice(get_config_fields_int(AUDIO, DRIVER_NAME));
} catch(...) {
throw;
}
#else
# error You must define one AUDIO driver to use.
#endif
@ -1170,11 +1199,52 @@ ManagerImpl::getCallStatus(const std::string& sequenceId)
{
// TODO: implement account
std::string accountId = "acc1";
std::string code;
TokenList tk;
Call* call;
if (_gui!=NULL) {
CallVector::iterator iter = _callVector.begin();
while(iter!=_callVector.end()){
_gui->sendCallMessage(sequenceId, (*iter)->getId(), accountId, (*iter)->getStatus());
call = (*iter);
std::string status = call->getStatus();
switch( call->getState() ) {
case Busy:
code="113";
break;
case Answered:
code="112";
status = "Established";
break;
case Ringing:
code="111";
break;
case Progressing:
code="110";
status="Trying";
break;
default:
code="115";
}
// No Congestion
// No Wrong Number
// 116 <CSeq> <call-id> <acc> <destination> Busy
std::string destination = call->getCallerIdName();
std::string number = call->getCallerIdNumber();
if (number!="") {
destination.append(" <");
destination.append(number);
destination.append(">");
}
tk.push_back(accountId);
tk.push_back(destination);
tk.push_back(status);
_gui->sendCallMessage(code, sequenceId, (*iter)->getId(), tk);
iter++;
tk.clear();
}
}
return true;

View File

@ -290,6 +290,7 @@ private:
* Initialize audiocodec
*/
void initAudioCodec(void);
void unloadAudioCodec(void);
/*
* Initialize audiodriver