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) // Save config to a file (ini format)
// return false if empty, no config, or enable to open
// return true if everything is ok
bool bool
ConfigTree::saveConfigTree(const std::string& fileName) { ConfigTree::saveConfigTree(const std::string& fileName) {
if (fileName.empty() && _sections.begin() == _sections.end() ) { if (fileName.empty() && _sections.begin() == _sections.end() ) {
@ -178,7 +180,7 @@ ConfigTree::saveConfigTree(const std::string& fileName) {
} }
file.close(); file.close();
return false; return true;
} }
// Create the tree from an existing ini file // 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 sendVoiceNbMessage(const std::string& nb_msg) = 0;
virtual void sendMessage(const std::string& code, const std::string& seqId, TokenList& arg) = 0; virtual void sendMessage(const std::string& code, const std::string& seqId, TokenList& arg) = 0;
virtual void sendCallMessage(const std::string& seqId, virtual void sendCallMessage(const std::string& code,
short id, const std::string& sequenceId,
const std::string& accountId, short id,
const std::string& status TokenList arg) = 0;
) = 0;
/* Child class to parent class */ /* Child class to parent class */
int outgoingCall (const std::string& to); int outgoingCall (const std::string& to);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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