From be1d42e6c24e7116f92945dc93e6d984a0eba0fa Mon Sep 17 00:00:00 2001 From: jpbl <jpbl> Date: Wed, 13 Jul 2005 21:21:35 +0000 Subject: [PATCH] Manager is now a singleton --- admin/acinclude.m4.in | 2 +- configure.ac | 19 +- src/Makefile.am | 13 +- src/audio/Makefile.am | 2 +- src/audio/audiocodec.cpp | 5 - src/audio/audiolayer.cpp | 130 ++++++------- src/audio/audiolayer.h | 25 ++- src/audio/audiortp.cpp | 62 ++++--- src/audio/audiortp.h | 9 +- src/audio/dtmfgenerator.cpp | 10 +- src/audio/tonegenerator.cpp | 39 ++-- src/audio/tonegenerator.h | 9 +- src/call.cpp | 3 +- src/call.h | 4 +- src/error.cpp | 15 +- src/error.h | 4 +- src/gui/Makefile.am | 1 + src/gui/guiframework.cpp | 38 ++-- src/gui/guiframework.h | 5 +- src/gui/qt/Makefile.am | 5 +- src/gui/qt/configurationpanel.ui.h | 8 +- src/gui/qt/qtGUImainwindow.cpp | 81 ++++---- src/gui/qt/qtGUImainwindow.h | 4 +- src/main.cpp | 25 ++- src/manager.h | 285 +---------------------------- src/sipvoiplink.cpp | 90 +++++---- src/sipvoiplink.h | 4 +- src/voIPLink.cpp | 3 +- src/voIPLink.h | 4 +- 29 files changed, 299 insertions(+), 605 deletions(-) diff --git a/admin/acinclude.m4.in b/admin/acinclude.m4.in index 0455b5b37b..ae70a8605a 100644 --- a/admin/acinclude.m4.in +++ b/admin/acinclude.m4.in @@ -3054,7 +3054,7 @@ AC_DEFUN([AC_CHECK_COMPILERS], AC_PROG_CXX - KDE_CHECK_FOR_BAD_COMPILER + dnl KDE_CHECK_FOR_BAD_COMPILER if test "$GXX" = "yes" || test "$CXX" = "KCC"; then if test "$kde_use_debug_code" != "no"; then diff --git a/configure.ac b/configure.ac index 690a996d0f..741fd3d5da 100644 --- a/configure.ac +++ b/configure.ac @@ -35,7 +35,7 @@ AM_DISABLE_LIBRARIES AC_PROG_LIBTOOL AC_CHECK_COMPILERS -CXXFLAGS="$CXXFLAGS $USE_EXCEPTIONS " +CXXFLAGS="$CXXFLAGS $USE_EXCEPTIONS" SFLPHONE_CXXFLAGS="" @@ -81,7 +81,10 @@ SFLPHONE_LIBS="$SFLPHONE_LIBS $libosip2_LIBS" if test $ac_cv_header_eXosip_eXosip_h = no; then AC_MSG_ERROR([*** missing eXipsip/eXosip.h. You need a working eXosip installation. See http://savannah.nongnu.org/projects/exosip/]) fi -SFLPHONE_LIBS="$SFLPHONE_LIBS -leXosip" +libexosip_LIBS="-leXosip " +SFLPHONE_LIBS="$SFLPHONE_LIBS $libexosip_LIBS" + +AC_SUBST(LIBQT) dnl if test $ac_cv_header_gsm_h = no; then dnl AC_MSG_ERROR([*** missing gsm.h. You need a working GSM 06.10 lossy speech compression installation. See http://kbs.cs.tu-berlin.de/~jutta/toast.html]) @@ -109,17 +112,17 @@ AM_CONDITIONAL(MAINTENER_CODE, test x$maintener = xyes) if test $ac_cv_header_portaudio_h = no; then AC_MSG_ERROR([*** missing portaudio.h. You need a working PortAudio installation. See http://www.portaudio.com]) fi -SFLPHONE_LIBS="$SFLPHONE_LIBS -lportaudio" -CXXFLAGS="$CXXFLAGS -DAUDIO_PORTAUDIO" - +portaudio_LIBS="-lportaudio " +portaudio_CFLAGS="-DAUDIO_PORTAUDIO " +SFLPHONE_LIBS="$SFLPHONE_LIBS $portaudio_LIBS" +SFLPHONE_CXXFLAGS=="$SFLPHONE_CXXFLAGS $portaudio_CFLAGS" +AC_SUBST(portaudio_CFLAGS) +AC_SUBST(portaudio_LIB) AC_SUBST(SFLPHONE_CXXFLAGS) AC_SUBST(SFLPHONE_LIBS) -CXXFLAGS="$CXXFLAGS $SFLPHONE_CXXFLAGS" -LIBS="$LIBS $SFLPHONE_LIBS $LIBQT" - dnl AC_CONFIG_FILES( AC_OUTPUT( sflphone.spec \ diff --git a/src/Makefile.am b/src/Makefile.am index 877193b94e..e1e586c066 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,7 +6,6 @@ sflphone_SOURCES = \ configitem.cpp \ configuration.cpp \ configurationtree.cpp \ - manager.cpp \ call.cpp \ eventthread.cpp \ error.cpp \ @@ -15,6 +14,8 @@ sflphone_SOURCES = \ voIPLink.cpp \ sipcall.cpp \ skin.cpp \ + managerimpl.cpp \ + managerimpl.h \ manager.h \ global.h \ configitem.h \ @@ -35,12 +36,10 @@ sflphone_SOURCES = \ sflphone_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" -sflphone_LDFLAGS = $(QT_LDFLAGS) $(X_LDFLAGS) -sflphone_LDADD = gui/libguiframework.la audio/libaudio.la ../stund/libstun.la -lpthread - - -KDE_CXXFLAGS = $(USE_EXCEPTIONS) -AM_CPPFLAGS = $(QT_INCLUDES) $(X_INCLUDES) -Iaudio/pacpp/include +sflphone_LDFLAGS = $(QT_LDFLAGS) $(X_LDFLAGS) +sflphone_LDADD = gui/libguiframework.la audio/libaudio.la ../stund/libstun.la -lpthread $(LIBQT) $(SFLPHONE_LIBS) +KDE_CXXFLAGS = $(USE_EXCEPTIONS) +AM_CPPFLAGS = $(QT_INCLUDES) $(X_INCLUDES) -Iaudio/pacpp/include $(libccext2_CFLAGS) $(libccgnu2_CFLAGS) $(portaudio_CFLAGS) diff --git a/src/audio/Makefile.am b/src/audio/Makefile.am index 37345c6b1d..8bd1b8fc92 100644 --- a/src/audio/Makefile.am +++ b/src/audio/Makefile.am @@ -18,6 +18,6 @@ libaudio_la_SOURCES = \ tonegenerator.cpp tonegenerator.h \ ulaw.cpp ulaw.h -AM_CXXFLAGS = -Ipacpp/include/ +AM_CXXFLAGS = -Ipacpp/include/ $(libccext2_CFLAGS) $(libccrtp1_CFLAGS) $(portaudio_CFLAGS) libaudio_la_LIBADD = gsm/libgsm.la pacpp/source/portaudiocpp/libportaudiocpp.la diff --git a/src/audio/audiocodec.cpp b/src/audio/audiocodec.cpp index 6a7e124ad0..f38317839e 100644 --- a/src/audio/audiocodec.cpp +++ b/src/audio/audiocodec.cpp @@ -27,12 +27,7 @@ #include <iostream> #include <string> -#include "portaudio.h" - -#include "../global.h" - #include "audiocodec.h" -#include "../configuration.h" using namespace std; diff --git a/src/audio/audiolayer.cpp b/src/audio/audiolayer.cpp index bfc626bcb6..6f110b7056 100644 --- a/src/audio/audiolayer.cpp +++ b/src/audio/audiolayer.cpp @@ -24,113 +24,113 @@ #include <string.h> #include "audiolayer.h" -#include "ringbuffer.h" #include "../error.h" #include "../global.h" #include "../manager.h" using namespace std; -AudioLayer::AudioLayer (Manager* manager) { - _manager = manager; - initDevice(); - - _urgentRingBuffer = new RingBuffer(SIZEBUF); - _mainSndRingBuffer = new RingBuffer(SIZEBUF); - _micRingBuffer = new RingBuffer(SIZEBUF); -} +AudioLayer::AudioLayer () + : _urgentRingBuffer(SIZEBUF) + , _mainSndRingBuffer(SIZEBUF) + , _micRingBuffer(SIZEBUF) + , _stream(NULL) +{} // Destructor AudioLayer::~AudioLayer (void) { - closeStream(); - autoSys->terminate(); - - delete autoSys; - delete _urgentRingBuffer; - delete _mainSndRingBuffer; - delete _micRingBuffer; - + closeStream(); } void -AudioLayer::initDevice (void) { - autoSys = new portaudio::AutoSystem(); - autoSys->initialize(); -} - -void -AudioLayer::closeStream (void) { +AudioLayer::closeStream (void) +{ + if(_stream) { _stream->close(); + delete _stream; + } } void AudioLayer::openDevice (int index) { - // Set up the System: - portaudio::System &sys = portaudio::System::instance(); - - // Set up the parameters required to open a (Callback)Stream: - portaudio::DirectionSpecificStreamParameters outParams( - sys.deviceByIndex(index), 2, portaudio::INT16, true, - sys.deviceByIndex(index).defaultLowOutputLatency(), NULL); + closeStream(); + // Set up the parameters required to open a (Callback)Stream: + portaudio::DirectionSpecificStreamParameters + outParams(portaudio::System::instance().deviceByIndex(index), + 2, portaudio::INT16, true, + portaudio::System::instance().deviceByIndex(index).defaultLowOutputLatency(), + NULL); - portaudio::DirectionSpecificStreamParameters inParams( - sys.deviceByIndex(index), 2, portaudio::INT16, true, - sys.deviceByIndex(index).defaultLowInputLatency(), NULL); + portaudio::DirectionSpecificStreamParameters + inParams(portaudio::System::instance().deviceByIndex(index), + 2, portaudio::INT16, true, + portaudio::System::instance().deviceByIndex(index).defaultLowInputLatency(), + NULL); - portaudio::StreamParameters const params(inParams, outParams, - SAMPLING_RATE, FRAME_PER_BUFFER, paNoFlag); + portaudio::StreamParameters const params(inParams, outParams, + SAMPLING_RATE, FRAME_PER_BUFFER, paNoFlag); - // Create (and open) a new Stream, using the AudioLayer::audioCallback - _stream = new portaudio::MemFunCallbackStream<AudioLayer>( - params, *this, &AudioLayer::audioCallback); + // Create (and open) a new Stream, using the AudioLayer::audioCallback + _stream = new portaudio::MemFunCallbackStream<AudioLayer>(params, + *this, + &AudioLayer::audioCallback); } void AudioLayer::startStream(void) { - if (_manager->isDriverLoaded()) { - if (!_stream->isActive()) { - _stream->start(); - } - } + if (Manager::instance().isDriverLoaded()) { + if (_stream && !_stream->isActive()) { + _stream->start(); + } + } } void AudioLayer::stopStream(void) { - if (_manager->isDriverLoaded()) { - if (!_stream->isStopped()) { - _stream->stop(); - } - } + if (Manager::instance().isDriverLoaded()) { + if (_stream && !_stream->isStopped()) { + _stream->stop(); + } + } } void AudioLayer::sleep(int msec) { - portaudio::System &sys = portaudio::System::instance(); - sys.sleep(msec); + portaudio::System::instance().sleep(msec); } -int +bool AudioLayer::isStreamActive (void) { - return _stream->isActive(); + if(_stream && _stream->isActive()) { + return true; + } + else { + return false; + } } -int +bool AudioLayer::isStreamStopped (void) { - return _stream->isStopped(); + if(_stream && _stream->isStopped()) { + return true; + } + else { + return false; + } } int AudioLayer::audioCallback (const void *inputBuffer, void *outputBuffer, - unsigned long framesPerBuffer, - const PaStreamCallbackTimeInfo *timeInfo, - PaStreamCallbackFlags statusFlags) { + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo *timeInfo, + PaStreamCallbackFlags statusFlags) { (void) timeInfo; (void) statusFlags; @@ -138,7 +138,7 @@ AudioLayer::audioCallback (const void *inputBuffer, void *outputBuffer, int16 *out = (int16 *) outputBuffer; int toGet, toPut, urgentAvail, normalAvail, micAvailPut; - urgentAvail = _urgentRingBuffer->AvailForGet(); + urgentAvail = _urgentRingBuffer.AvailForGet(); if (urgentAvail > 0) { // Urgent data (dtmf, incoming call signal) come first. if (urgentAvail < (int)framesPerBuffer) { @@ -146,24 +146,24 @@ AudioLayer::audioCallback (const void *inputBuffer, void *outputBuffer, } else { toGet = framesPerBuffer; } - _urgentRingBuffer->Get(out, SAMPLES_SIZE(toGet)); + _urgentRingBuffer.Get(out, SAMPLES_SIZE(toGet)); // Consume the regular one as well - _mainSndRingBuffer->Discard(SAMPLES_SIZE(toGet)); + _mainSndRingBuffer.Discard(SAMPLES_SIZE(toGet)); } else { // If nothing urgent, play the regular sound samples - normalAvail = _mainSndRingBuffer->AvailForGet(); + normalAvail = _mainSndRingBuffer.AvailForGet(); toGet = (normalAvail < (int)framesPerBuffer) ? normalAvail : framesPerBuffer; - _mainSndRingBuffer->Get(out, SAMPLES_SIZE(toGet)); + _mainSndRingBuffer.Get(out, SAMPLES_SIZE(toGet)); } // Additionally handle the mike's audio stream - micAvailPut = _micRingBuffer->AvailForPut(); + micAvailPut = _micRingBuffer.AvailForPut(); toPut = (micAvailPut <= (int)framesPerBuffer) ? micAvailPut : framesPerBuffer; - _micRingBuffer->Put(in, SAMPLES_SIZE(toPut)); + _micRingBuffer.Put(in, SAMPLES_SIZE(toPut)); return paContinue; } diff --git a/src/audio/audiolayer.h b/src/audio/audiolayer.h index 4ff749efd6..165e455fa8 100644 --- a/src/audio/audiolayer.h +++ b/src/audio/audiolayer.h @@ -26,6 +26,7 @@ #include "../global.h" +#include "ringbuffer.h" #define FRAME_PER_BUFFER 160 #define MIC_CHANNELS 2 // 1=mono 2=stereo @@ -34,37 +35,35 @@ class RingBuffer; -class Manager; + class AudioLayer { public: - AudioLayer (Manager*); + AudioLayer(); ~AudioLayer (void); - void initDevice (void); void openDevice (int); void startStream (void); void stopStream (void); void sleep (int); - int isStreamActive (void); - int isStreamStopped (void); + bool isStreamActive (void); + bool isStreamStopped (void); int audioCallback (const void *, void *, unsigned long, const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags); - inline RingBuffer* urgentRingBuffer(void) { return _urgentRingBuffer; } - inline RingBuffer* mainSndRingBuffer(void) { return _mainSndRingBuffer; } - inline RingBuffer* micRingBuffer(void) { return _micRingBuffer; } + inline RingBuffer &urgentRingBuffer(void) { return _urgentRingBuffer; } + inline RingBuffer &mainSndRingBuffer(void) { return _mainSndRingBuffer; } + inline RingBuffer &micRingBuffer(void) { return _micRingBuffer; } private: void closeStream (void); - Manager* _manager; - RingBuffer* _urgentRingBuffer; - RingBuffer* _mainSndRingBuffer; - RingBuffer* _micRingBuffer; + RingBuffer _urgentRingBuffer; + RingBuffer _mainSndRingBuffer; + RingBuffer _micRingBuffer; portaudio::MemFunCallbackStream<AudioLayer> *_stream; - portaudio::AutoSystem *autoSys; + portaudio::AutoSystem autoSys; }; #endif // _AUDIO_LAYER_H_ diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp index 83400b2f7f..be4018f531 100644 --- a/src/audio/audiortp.cpp +++ b/src/audio/audiortp.cpp @@ -24,14 +24,14 @@ #include <iostream> #include <string> +#include "../global.h" +#include "../manager.h" #include "audiocodec.h" #include "audiortp.h" #include "audiolayer.h" #include "codecDescriptor.h" #include "ringbuffer.h" #include "../configuration.h" -#include "../manager.h" -#include "../global.h" #include "../user_cfg.h" #include "../sipcall.h" #include "../../stund/stun.h" @@ -43,9 +43,17 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// // AudioRtp //////////////////////////////////////////////////////////////////////////////// -AudioRtp::AudioRtp (Manager *manager) { - _manager = manager; +AudioRtp::AudioRtp () { + string svr; + _RTXThread = NULL; + + if (!Manager::instance().useStun() && + get_config_fields_str(SIGNALISATION, PROXY).empty()) { + svr = get_config_fields_str(SIGNALISATION, PROXY); + } else { + svr = get_config_fields_str(SIGNALISATION, HOST_PART); + } } AudioRtp::~AudioRtp (void) { @@ -56,18 +64,19 @@ int AudioRtp::createNewSession (SipCall *ca) { // Start RTP Send/Receive threads ca->enable_audio = 1; - if (!_manager->useStun()) { + if (!Manager::instance().useStun()) { _symetric = false; } else { _symetric = true; } - _RTXThread = new AudioRtpRTX (ca, _manager->getAudioDriver(), - _manager, _symetric); + _RTXThread = new AudioRtpRTX (ca, + Manager::instance().getAudioDriver(), + _symetric); // Start PortAudio - _manager->getAudioDriver()->micRingBuffer()->flush(); - _manager->getAudioDriver()->startStream(); + Manager::instance().getAudioDriver()->micRingBuffer().flush(); + Manager::instance().getAudioDriver()->startStream(); if (_RTXThread->start() != 0) { return -1; @@ -89,18 +98,18 @@ AudioRtp::closeRtpSession (SipCall *ca) { } // Stop portaudio and flush ringbuffer - _manager->getAudioDriver()->stopStream(); - _manager->getAudioDriver()->mainSndRingBuffer()->flush(); + Manager::instance().getAudioDriver()->stopStream(); + Manager::instance().getAudioDriver()->mainSndRingBuffer().flush(); } } //////////////////////////////////////////////////////////////////////////////// // AudioRtpRTX Class // //////////////////////////////////////////////////////////////////////////////// -AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, AudioLayer* driver, - Manager *mngr, bool sym) { +AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, + AudioLayer* driver, + bool sym) { time = new Time(); - _manager = mngr; _ca = sipcall; _sym =sym; _audioDevice = driver; @@ -197,14 +206,14 @@ AudioRtpRTX::sendSessionFromMic (unsigned char* data_to_send, int16* data_from_m int k; int compSize; - if (_manager->getCall(_ca->getId())->isOnMute() or - !_manager->isCurrentId(_ca->getId())) { + if (Manager::instance().getCall(_ca->getId())->isOnMute() or + !Manager::instance().isCurrentId(_ca->getId())) { // Mute :send 0's over the network. - _manager->getAudioDriver()->micRingBuffer()->Get(data_from_mic, + Manager::instance().getAudioDriver()->micRingBuffer().Get(data_from_mic, RTP_FRAMES2SEND*2*sizeof(int16)); } else { // Control volume for micro - int availFromMic = _manager->getAudioDriver()->micRingBuffer()->AvailForGet(); + int availFromMic = Manager::instance().getAudioDriver()->micRingBuffer().AvailForGet(); int bytesAvail; if (availFromMic < (int)RTP_FRAMES2SEND) { bytesAvail = availFromMic; @@ -213,7 +222,7 @@ AudioRtpRTX::sendSessionFromMic (unsigned char* data_to_send, int16* data_from_m } // Get bytes from micRingBuffer to data_from_mic - _manager->getAudioDriver()->micRingBuffer()->Get(data_from_mic, + Manager::instance().getAudioDriver()->micRingBuffer().Get(data_from_mic, SAMPLES_SIZE(bytesAvail)); // control volume and stereo->mono for (int j = 0; j < RTP_FRAMES2SEND; j++) { @@ -272,20 +281,20 @@ AudioRtpRTX::receiveSessionForSpkr (int16* data_for_speakers, } // If the current call is the call which is answered - if (_manager->isCurrentId(_ca->getId())) { + if (Manager::instance().isCurrentId(_ca->getId())) { // Set decoded data to sound device - _manager->getAudioDriver()->mainSndRingBuffer()->Put(data_for_speakers_tmp, SAMPLES_SIZE(RTP_FRAMES2SEND)); + Manager::instance().getAudioDriver()->mainSndRingBuffer().Put(data_for_speakers_tmp, SAMPLES_SIZE(RTP_FRAMES2SEND)); } // Notify (with a bip) an incoming call when there is already a call countTime += time->getSecond(); - if (_manager->getNumberOfCalls() > 0 and _manager->getbRingtone()) { + if (Manager::instance().getNumberOfCalls() > 0 and Manager::instance().getbRingtone()) { countTime = countTime % 2000; if (countTime < 10 and countTime > 0) { - _manager->notificationIncomingCall(); + Manager::instance().notificationIncomingCall(); } } - _manager->getAudioDriver()->startStream(); + Manager::instance().getAudioDriver()->startStream(); delete cd; delete adu; @@ -326,9 +335,8 @@ AudioRtpRTX::run (void) { } while (_ca->enable_audio != -1) { - // Store volume values - micVolume = _manager->getMicroVolume(); - spkrVolume = _manager->getSpkrVolume(); + micVolume = Manager::instance().getMicroVolume(); + spkrVolume = Manager::instance().getSpkrVolume(); //////////////////////////// // Send session diff --git a/src/audio/audiortp.h b/src/audio/audiortp.h index 2bc9f8cee8..3288ae9743 100644 --- a/src/audio/audiortp.h +++ b/src/audio/audiortp.h @@ -32,7 +32,6 @@ using namespace ost; #define SIZEDATA SAMPLES_SIZE(RTP_FRAMES2SEND) class AudioLayer; -class Manager; class SipCall; /////////////////////////////////////////////////////////////////////////////// @@ -40,7 +39,7 @@ class SipCall; /////////////////////////////////////////////////////////////////////////////// class AudioRtpRTX : public Thread, public TimerPort { public: - AudioRtpRTX (SipCall *, AudioLayer*, Manager *, bool); + AudioRtpRTX (SipCall *, AudioLayer*, bool); ~AudioRtpRTX(); Time *time; // For incoming call notification @@ -52,7 +51,6 @@ private: RTPSession* _sessionSend; RTPSession* _sessionRecv; SymmetricRTPSession* _session; - Manager* _manager; bool _sym; void initAudioRtpSession (void); @@ -65,15 +63,14 @@ private: /////////////////////////////////////////////////////////////////////////////// class AudioRtp { public: - AudioRtp (Manager *); - ~AudioRtp (void); + AudioRtp(); + ~AudioRtp(); int createNewSession (SipCall *); void closeRtpSession (SipCall *); private: AudioRtpRTX* _RTXThread; - Manager* _manager; bool _symetric; }; diff --git a/src/audio/dtmfgenerator.cpp b/src/audio/dtmfgenerator.cpp index 7d1d87e57a..cfb6764456 100644 --- a/src/audio/dtmfgenerator.cpp +++ b/src/audio/dtmfgenerator.cpp @@ -95,7 +95,7 @@ DTMFGenerator::~DTMFGenerator() { void DTMFGenerator::getSamples(int16* buffer, size_t n, unsigned char code) throw(DTMFException) { size_t i; if (!buffer) { - throw DTMFException("Invalid parameter value"); + throw DTMFException("Invalid parameter value"); } switch(code) { @@ -142,17 +142,15 @@ void DTMFGenerator::getNextSamples(int16* buffer, size_t n) throw(DTMFException) size_t i; if (!buffer) { - throw DTMFException("Invalid parameter"); - return; + throw DTMFException("Invalid parameter"); } if (state.sample == 0) { - throw DTMFException("DTMF generator not initialized"); - return; + throw DTMFException("DTMF generator not initialized"); } for(i = 0; i < n; i++) { - buffer[i] = state.sample[(state.offset + i) % SAMPLING_RATE]; + buffer[i] = state.sample[(state.offset + i) % SAMPLING_RATE]; } state.offset = (state.offset + i) % SAMPLING_RATE; diff --git a/src/audio/tonegenerator.cpp b/src/audio/tonegenerator.cpp index 198f1c0fd2..8a62cf23c9 100644 --- a/src/audio/tonegenerator.cpp +++ b/src/audio/tonegenerator.cpp @@ -41,8 +41,7 @@ int AMPLITUDE = 8192; /////////////////////////////////////////////////////////////////////////////// // ToneThread implementation /////////////////////////////////////////////////////////////////////////////// -ToneThread::ToneThread (Manager *mngr, int16 *buf, int size) : Thread () { - this->mngr = mngr; +ToneThread::ToneThread (int16 *buf, int size) : Thread () { this->buffer = buf; this->size = size; this->buf_ctrl_vol = new int16[size*CHANNELS]; @@ -56,19 +55,19 @@ void ToneThread::run (void) { int k; int spkrVolume; - while (mngr->getZonetone()) { - spkrVolume = mngr->getSpkrVolume(); + while (Manager::instance().getZonetone()) { + spkrVolume = Manager::instance().getSpkrVolume(); // control volume + mono->stereo for (int j = 0; j < size; j++) { k = j*2; buf_ctrl_vol[k] = buf_ctrl_vol[k+1] = buffer[j] * spkrVolume/100; } - if (mngr->getAudioDriver()->mainSndRingBuffer()->Len() == 0) { - mngr->getAudioDriver()->mainSndRingBuffer()->Put(buf_ctrl_vol, + if (Manager::instance().getAudioDriver()->mainSndRingBuffer().Len() == 0) { + Manager::instance().getAudioDriver()->mainSndRingBuffer().Put(buf_ctrl_vol, SAMPLES_SIZE(size)); } - mngr->getAudioDriver()->startStream(); + Manager::instance().getAudioDriver()->startStream(); } } @@ -76,20 +75,12 @@ ToneThread::run (void) { // ToneGenerator implementation /////////////////////////////////////////////////////////////////////////////// -ToneGenerator::ToneGenerator (Manager *mngr) { - this->initTone(); - this->manager = mngr; - buf = new int16[SIZEBUF]; - tonethread = NULL; -} - ToneGenerator::ToneGenerator () { - this->initTone(); + this->initTone(); tonethread = NULL; } ToneGenerator::~ToneGenerator (void) { - delete[] buf; delete tonethread; } @@ -256,13 +247,13 @@ ToneGenerator::toneHandle (int idr) { // New thread for the tone if (tonethread == NULL) { - tonethread = new ToneThread (manager, buf, totalbytes); + tonethread = new ToneThread (buf, totalbytes); tonethread->start(); } - if (!manager->getZonetone()) { - manager->getAudioDriver()->stopStream(); - manager->getAudioDriver()->mainSndRingBuffer()->flush(); + if (!Manager::instance().getZonetone()) { + Manager::instance().getAudioDriver()->stopStream(); + Manager::instance().getAudioDriver()->mainSndRingBuffer().flush(); if (tonethread != NULL) { delete tonethread; tonethread = NULL; @@ -305,12 +296,12 @@ ToneGenerator::playRingtone (const char *fileName) { expandedsize = ulaw->codecDecode (dst, (unsigned char *)src, length); if (tonethread == NULL) { - tonethread = new ToneThread (manager, (int16*)dst, expandedsize); + tonethread = new ToneThread ((int16*)dst, expandedsize); tonethread->start(); } - if (!manager->getZonetone()) { - manager->getAudioDriver()->stopStream(); - manager->getAudioDriver()->mainSndRingBuffer()->flush(); + if (!Manager::instance().getZonetone()) { + Manager::instance().getAudioDriver()->stopStream(); + Manager::instance().getAudioDriver()->mainSndRingBuffer().flush(); if (tonethread != NULL) { delete tonethread; tonethread = NULL; diff --git a/src/audio/tonegenerator.h b/src/audio/tonegenerator.h index 636119ddeb..26f67275ff 100644 --- a/src/audio/tonegenerator.h +++ b/src/audio/tonegenerator.h @@ -51,12 +51,11 @@ using namespace ost; /////////////////////////////////////////////////////////////////////////////// class ToneThread : public Thread { public: - ToneThread (Manager *, int16 *, int); - ~ToneThread (void); + ToneThread (int16 *, int); + virtual ~ToneThread (void); virtual void run (); private: - Manager* mngr; int16* buffer; int16* buf_ctrl_vol; int size; @@ -67,7 +66,6 @@ private: /////////////////////////////////////////////////////////////////////////////// class ToneGenerator { public: - ToneGenerator (Manager *); ToneGenerator (); ~ToneGenerator (void); @@ -86,7 +84,7 @@ public: int time; int totalbytes; - int16 *buf; + int16 buf[SIZEBUF]; private: /* * Initialisation of the supported tones according to the countries. @@ -102,7 +100,6 @@ private: */ int contains(const string& str, char c); - Manager* manager; ToneThread* tonethread; }; diff --git a/src/call.cpp b/src/call.cpp index 415d8172d1..89ce0d2d41 100644 --- a/src/call.cpp +++ b/src/call.cpp @@ -25,12 +25,11 @@ #include "voIPLink.h" -Call::Call (Manager* manager, short id, CallType type, VoIPLink* voiplink) +Call::Call (short id, CallType type, VoIPLink* voiplink) { initConstructor(); _id = id; _type = type; - _manager = manager; _voIPLink = voiplink; switch (_type) { diff --git a/src/call.h b/src/call.h index 78076145d2..177e8f0275 100644 --- a/src/call.h +++ b/src/call.h @@ -48,12 +48,11 @@ enum CallType { }; -class Manager; class VoIPLink; class Call { public: - Call(Manager* manager, short id, CallType type, VoIPLink* voiplink); + Call(short id, CallType type, VoIPLink* voiplink); ~Call(void); @@ -111,7 +110,6 @@ public: private: void initConstructor (void); - Manager* _manager; VoIPLink* _voIPLink; short _id; diff --git a/src/error.cpp b/src/error.cpp index 9de2b7fc78..1e39e3e420 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -25,8 +25,7 @@ using namespace std; -Error::Error (Manager *mngr){ - _mngr = mngr; +Error::Error (){ issetError = 0; } @@ -36,31 +35,31 @@ Error::errorName (Error_enum num_name) { switch (num_name){ // Handle opening device errors case OPEN_FAILED_DEVICE: - _mngr->displayErrorText("Open device failed "); + Manager::instance().displayErrorText("Open device failed "); issetError = 2; break; // Handle setup errors case HOST_PART_FIELD_EMPTY: - _mngr->displayError("Fill host part field"); + Manager::instance().displayError("Fill host part field"); issetError = 2; break; case USER_PART_FIELD_EMPTY: - _mngr->displayError("Fill user part field"); + Manager::instance().displayError("Fill user part field"); issetError = 2; break; case PASSWD_FIELD_EMPTY: - _mngr->displayError("Fill password field"); + Manager::instance().displayError("Fill password field"); issetError = 2; break; // Handle sip uri case FROM_ERROR: - _mngr->displayError("Error for 'From' header"); + Manager::instance().displayError("Error for 'From' header"); issetError = 1; break; case TO_ERROR: - _mngr->displayError("Error for 'To' header"); + Manager::instance().displayError("Error for 'To' header"); issetError = 1; break; diff --git a/src/error.h b/src/error.h index b879946443..5817839470 100644 --- a/src/error.h +++ b/src/error.h @@ -35,10 +35,9 @@ typedef enum { } Error_enum; -class Manager; class Error { public: - Error (Manager *mngr); + Error (); ~Error (void) {}; int errorName (Error_enum); @@ -46,7 +45,6 @@ public: inline void setError(int err) { issetError = err; } private: - Manager *_mngr; int issetError; }; diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index fa1adf08b2..4c0431e0b1 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -5,4 +5,5 @@ noinst_LTLIBRARIES = libguiframework.la libguiframework_la_SOURCES = \ guiframework.cpp guiframework.h +libguiframework_la_CXXFLAGS = $(libccext2_CFLAGS) libguiframework_la_LIBADD = qt/libsflphoneqt.la \ No newline at end of file diff --git a/src/gui/guiframework.cpp b/src/gui/guiframework.cpp index c4e5cd6982..08a8ba0ce4 100644 --- a/src/gui/guiframework.cpp +++ b/src/gui/guiframework.cpp @@ -23,23 +23,21 @@ using namespace std; #include "guiframework.h" #include "../manager.h" -GuiFramework::GuiFramework (Manager* manager) -{ - _manager = manager; -} +GuiFramework::GuiFramework () +{} GuiFramework::~GuiFramework (void) {} int GuiFramework::outgoingCall (const string& to) { - return _manager->outgoingCall(to); + return Manager::instance().outgoingCall(to); } int GuiFramework::hangupCall (short id) { - if (_manager->hangupCall(id) == 0) { + if (Manager::instance().hangupCall(id) == 0) { return 1; } else { return 0; @@ -49,7 +47,7 @@ GuiFramework::hangupCall (short id) int GuiFramework::cancelCall (short id) { - if (_manager->cancelCall(id) == 0) { + if (Manager::instance().cancelCall(id) == 0) { return 1; } else { return 0; @@ -59,7 +57,7 @@ GuiFramework::cancelCall (short id) int GuiFramework::answerCall (short id) { - if (_manager->answerCall(id) == 0) { + if (Manager::instance().answerCall(id)) { return 1; } else { return 0; @@ -69,7 +67,7 @@ GuiFramework::answerCall (short id) int GuiFramework::onHoldCall (short id) { - if (_manager->onHoldCall(id) == 0) { + if (Manager::instance().onHoldCall(id) == 0) { return 1; } else { return 0; @@ -79,7 +77,7 @@ GuiFramework::onHoldCall (short id) int GuiFramework::offHoldCall (short id) { - if (_manager->offHoldCall(id) == 0) { + if (Manager::instance().offHoldCall(id) == 0) { return 1; } else { return 0; @@ -89,7 +87,7 @@ GuiFramework::offHoldCall (short id) int GuiFramework::transferCall (short id, const string& to) { - if (_manager->transferCall(id, to) == 1) { + if (Manager::instance().transferCall(id, to) == 1) { return 1; } else { return 0; @@ -99,19 +97,19 @@ GuiFramework::transferCall (short id, const string& to) void GuiFramework::muteOn (short id) { - _manager->muteOn(id); + Manager::instance().muteOn(id); } void GuiFramework::muteOff (short id) { - _manager->muteOff(id); + Manager::instance().muteOff(id); } int GuiFramework::refuseCall (short id) { - if (_manager->refuseCall(id) == 0) { + if (Manager::instance().refuseCall(id) == 0) { return 1; } else { return 0; @@ -121,7 +119,7 @@ GuiFramework::refuseCall (short id) int GuiFramework::saveConfig (void) { - if (_manager->saveConfig()) { + if (Manager::instance().saveConfig()) { return 1; } else { return 0; @@ -131,7 +129,7 @@ GuiFramework::saveConfig (void) int GuiFramework::registerVoIPLink (void) { - if (_manager->registerVoIPLink()) { + if (Manager::instance().registerVoIPLink()) { return 1; } else { return 0; @@ -141,26 +139,26 @@ GuiFramework::registerVoIPLink (void) void GuiFramework::sendDtmf (short id, char code) { - _manager->sendDtmf(id, code); + Manager::instance().sendDtmf(id, code); } int GuiFramework::quitApplication (void) { - return (_manager->quitApplication() ? 1 : 0); + return (Manager::instance().quitApplication() ? 1 : 0); } int GuiFramework::sendTextMessage (short id, const string& message) { - _manager->sendTextMessage(id, message); + Manager::instance().sendTextMessage(id, message); return 1; } int GuiFramework::accessToDirectory (void) { - _manager->accessToDirectory(); + Manager::instance().accessToDirectory(); return 1; } diff --git a/src/gui/guiframework.h b/src/gui/guiframework.h index 25d68106d3..738314234f 100644 --- a/src/gui/guiframework.h +++ b/src/gui/guiframework.h @@ -26,10 +26,9 @@ #include <string> using namespace std; -class Manager; class GuiFramework { public: - GuiFramework (Manager* manager); + GuiFramework (); virtual ~GuiFramework (void); /* Parent class to child class */ @@ -69,8 +68,6 @@ public: protected: string _message; -private: - Manager* _manager; }; #endif // __GUI_FRAMEWORK_H__ diff --git a/src/gui/qt/Makefile.am b/src/gui/qt/Makefile.am index e1ed20325b..d0b660fb58 100644 --- a/src/gui/qt/Makefile.am +++ b/src/gui/qt/Makefile.am @@ -33,10 +33,11 @@ libsflphoneqt_la_SOURCES = \ CLEANFILES = \ $(BUILT_SOURCES) -libsflphoneqt_la_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" +libsflphoneqt_la_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" $(portaudio_CFLAGS) +libsflphoneqt_la_LIBADD = $(portaudio_LIBS) KDE_CXXFLAGS = $(USE_EXCEPTIONS) -AM_CPPFLAGS = -I../../audio/pacpp/include/ $(QT_INCLUDES) $(X_INCLUDES) +AM_CPPFLAGS = -I../../audio/pacpp/include/ $(QT_INCLUDES) $(X_INCLUDES) $(libccext2_CFLAGS) $(portaudio_CFLAGS) %.h: %.ui diff --git a/src/gui/qt/configurationpanel.ui.h b/src/gui/qt/configurationpanel.ui.h index 14f3c5d010..bb6f96b784 100644 --- a/src/gui/qt/configurationpanel.ui.h +++ b/src/gui/qt/configurationpanel.ui.h @@ -65,13 +65,13 @@ void ConfigurationPanel::init() const char* hostapiname; int top = 0; - device_t devStruct; + AudioDevice devStruct; portaudio::AutoSystem autoSys; // For each device - for (int i = 0; i < Manager::deviceCount(); i++) { + for (int i = 0; i < Manager::instance().deviceCount(); i++) { // Fill the device structure - devStruct = Manager::deviceList(i); + devStruct = Manager::instance().deviceList(i); hostapiname = devStruct.hostApiName; devicename = devStruct.deviceName; @@ -89,7 +89,7 @@ void ConfigurationPanel::init() QToolTip::add(device , devicename ); top += 30; - if (Manager::defaultDevice(i)) { + if (Manager::instance().defaultDevice(i)) { device->setChecked(true); } } diff --git a/src/gui/qt/qtGUImainwindow.cpp b/src/gui/qt/qtGUImainwindow.cpp index 4c480ecdab..718b318f85 100644 --- a/src/gui/qt/qtGUImainwindow.cpp +++ b/src/gui/qt/qtGUImainwindow.cpp @@ -96,12 +96,12 @@ MyTrayIcon::mousePressEvent (QMouseEvent *e) * Default Constructor * Init, Connections */ -QtGUIMainWindow::QtGUIMainWindow (QWidget *parent, const char *name, WFlags f, - Manager *mngr) - : TransQWidget (parent, name, f), - GuiFramework(mngr) { - - for (int i = 0; i < NUMBER_OF_LINES; i++) { +QtGUIMainWindow::QtGUIMainWindow (QWidget *parent, + const char *name, + WFlags f) + : TransQWidget (parent, name, f), + GuiFramework() { + for (int i = 0; i < NUMBER_OF_LINES; i++) { phLines[i] = new PhoneLine(); phLines[i]->setState(FREE); _TabIncomingCalls[i] = -1; @@ -113,8 +113,6 @@ QtGUIMainWindow::QtGUIMainWindow (QWidget *parent, const char *name, WFlags f, // URL input dialog _urlinput = new URL_Input (this); - // For managing - _callmanager = mngr; // For DTMF _key = new DTMF (); @@ -190,7 +188,6 @@ QtGUIMainWindow::~QtGUIMainWindow(void) { delete _keypad; delete _lcd; delete _urlinput; - delete _callmanager; delete _mypop; delete _trayicon; delete pt; @@ -343,8 +340,8 @@ QtGUIMainWindow::initMicVolumePosition (void) { void QtGUIMainWindow::initVolume (void) { - _callmanager->setSpkrVolume(spkrVolVector->Y() - vol_spkr_y); - _callmanager->setMicroVolume(micVolVector->Y() - vol_mic_y); + Manager::instance().setSpkrVolume(spkrVolVector->Y() - vol_spkr_y); + Manager::instance().setMicroVolume(micVolVector->Y() - vol_mic_y); } /** @@ -618,14 +615,14 @@ QtGUIMainWindow::putOnHoldBusyLine (int line) void QtGUIMainWindow::dialtone (bool var) { - if (_callmanager->isDriverLoaded()) { + if (Manager::instance().isDriverLoaded()) { if (_dialtone != var) { _dialtone = var; } - _callmanager->setZonetone(var); - _callmanager->getTonegenerator()->toneHandle(ZT_TONE_DIALTONE); + Manager::instance().setZonetone(var); + Manager::instance().getTonegenerator()->toneHandle(ZT_TONE_DIALTONE); } else { - _callmanager->error()->errorName(OPEN_FAILED_DEVICE); + Manager::instance().error()->errorName(OPEN_FAILED_DEVICE); } } @@ -671,8 +668,8 @@ QtGUIMainWindow::callIsBusy (Call* call, int id, int line, int busyLine) changeLineStatePixmap(line, ONHOLD); displayStatus(ONHOLD_STATUS); if (qt_onHoldCall(id) != 1) { - _callmanager->displayErrorText("On-hold call failed !\n"); - return -1; + Manager::instance().displayErrorText("On-hold call failed !\n"); + return -1; } } return 1; @@ -691,7 +688,7 @@ QtGUIMainWindow::callIsOnHold(int id, int line, int busyLine) } _lcd->setInFunction(true); if (qt_offHoldCall(id) != 1) { - _callmanager->displayErrorText("Off-hold call failed !\n"); + Manager::instance().displayErrorText("Off-hold call failed !\n"); return -1; } displayContext(id); @@ -704,7 +701,7 @@ QtGUIMainWindow::callIsIncoming (int id, int line, int busyLine) changeLineStatePixmap(line, BUSY); putOnHoldBusyLine(busyLine); if (qt_answerCall(id) != 1) { - _callmanager->displayErrorText("Answered call failed !\n"); + Manager::instance().displayErrorText("Answered call failed !\n"); return -1; } return 1; @@ -737,7 +734,7 @@ QtGUIMainWindow::clickOnFreeLine(int line, int busyLine) Call* QtGUIMainWindow::getCall (short id) { - return _callmanager->getCall(id); + return Manager::instance().getCall(id); } int @@ -842,7 +839,7 @@ QtGUIMainWindow::peerAnsweredCall (short id) getPhoneLine(id)->setStatus(QString(getCall(id)->getStatus())); // Afficher call-timer startCallTimer(id); - _callmanager->displayStatus(CONNECTED_STATUS); + Manager::instance().displayStatus(CONNECTED_STATUS); setChooseLine(false); } @@ -861,7 +858,7 @@ QtGUIMainWindow::peerHungupCall (short id) if (line == getCurrentLine() or getCurrentLine() == -1) { stopCallTimer(id); - _callmanager->displayStatus(HUNGUP_STATUS); + Manager::instance().displayStatus(HUNGUP_STATUS); setCurrentLine(-1); } else { // Stop the call timer when hang up @@ -951,12 +948,12 @@ QtGUIMainWindow::qt_outgoingCall (void) int id; int line = -1; if (_lcd->getTextBuffer() == NULL) { - _callmanager->displayStatus(ENTER_NUMBER_STATUS); + Manager::instance().displayStatus(ENTER_NUMBER_STATUS); return -1; } const string to(_lcd->getTextBuffer().ascii()); if (to.empty()) { - _callmanager->displayStatus(ENTER_NUMBER_STATUS); + Manager::instance().displayStatus(ENTER_NUMBER_STATUS); return -1; } @@ -967,7 +964,7 @@ QtGUIMainWindow::qt_outgoingCall (void) setCurrentLine(line); displayStatus(TRYING_STATUS); - _callmanager->getCall(id)->setCallerIdNumber(to); + Manager::instance().getCall(id)->setCallerIdNumber(to); changeLineStatePixmap(line, BUSY); } @@ -1156,7 +1153,7 @@ QtGUIMainWindow::dial (void) } else if (getTransfer()){ // If call transfer if(qt_transferCall (line2id(getCurrentLine()) != 1)) { - _callmanager->displayErrorText("Transfer failed !\n"); + Manager::instance().displayErrorText("Transfer failed !\n"); } } else { // If new outgoing call @@ -1181,15 +1178,15 @@ QtGUIMainWindow::hangupLine (void) int line = getCurrentLine(); int id = phLines[line]->getCallId(); - if (_callmanager->getbCongestion()) { + if (Manager::instance().getbCongestion()) { // If congestion tone if (qt_hangupCall(id)) { changeLineStatePixmap(line, FREE); _lcd->clear(QString(ENTER_NUMBER_STATUS)); - _callmanager->congestion(false); + Manager::instance().congestion(false); phLines[line]->setCallId(0); } else { - _callmanager->displayErrorText("Hangup call failed !\n"); + Manager::instance().displayErrorText("Hangup call failed !\n"); } } else if (line >= 0 and id > 0 and getCall(id)->isProgressing()) { // If I want to cancel a call before ringing. @@ -1198,7 +1195,7 @@ QtGUIMainWindow::hangupLine (void) phLines[line]->setCallId(0); setChooseLine(false); } else { - _callmanager->displayErrorText("Cancelled call failed !\n"); + Manager::instance().displayErrorText("Cancelled call failed !\n"); } } else if (line >= 0 and id > 0) { // If hangup current line normally @@ -1208,7 +1205,7 @@ QtGUIMainWindow::hangupLine (void) phLines[line]->setCallId(0); setChooseLine(false); } else { - _callmanager->displayErrorText("Hangup call failed !\n"); + Manager::instance().displayErrorText("Hangup call failed !\n"); } } else if ((i = isThereIncomingCall()) > 0){ // To refuse new incoming call @@ -1216,7 +1213,7 @@ QtGUIMainWindow::hangupLine (void) if (qt_refuseCall(i)) { changeLineStatePixmap(id2line(i), FREE); } else { - _callmanager->displayErrorText("Refused call failed !\n"); + Manager::instance().displayErrorText("Refused call failed !\n"); } } else if (line >= 0) { _debug("Just load free pixmap for the line %d\n", line); @@ -1274,12 +1271,12 @@ QtGUIMainWindow::startCallTimer (short id) { /////////////////////////////////////////////////////////////////////////////// void QtGUIMainWindow::volumeSpkrChanged (int val) { - _callmanager->setSpkrVolume(val); + Manager::instance().setSpkrVolume(val); } void QtGUIMainWindow::volumeMicChanged (int val) { - _callmanager->setMicroVolume(val); + Manager::instance().setMicroVolume(val); } void @@ -1375,7 +1372,7 @@ QtGUIMainWindow::button_mute(void) int id = line2id(getCurrentLine()); - if (_callmanager->getNumberOfCalls() > 0) { + if (Manager::instance().getNumberOfCalls() > 0) { // If there is at least a pending call if(!isOn) { qt_muteOff(id); @@ -1588,7 +1585,7 @@ QtGUIMainWindow::pressedKeySlot (int id) { callid = line2id(getCurrentLine()); if (callid != -1 and getCall(callid)->isBusy()) { sendDtmf(callid, code); // pour envoyer DTMF - } else if (_callmanager->isDriverLoaded()) { + } else if (Manager::instance().isDriverLoaded()) { _lcd->appendText (code); } @@ -1601,7 +1598,7 @@ QtGUIMainWindow::pressedKeySlot (int id) { int size = pulselen * (OCTETS /1000); buf_ctrl_vol = new int16[size*CHANNELS]; - spkrVolume = _callmanager->getSpkrVolume(); + spkrVolume = Manager::instance().getSpkrVolume(); // Control volume and format mono->stereo for (int j = 0; j < size; j++) { @@ -1610,13 +1607,13 @@ QtGUIMainWindow::pressedKeySlot (int id) { } // Counters reset - _callmanager->getAudioDriver()->urgentRingBuffer()->flush(); + Manager::instance().getAudioDriver()->urgentRingBuffer().flush(); // Put buffer to urgentRingBuffer - _callmanager->getAudioDriver()->urgentRingBuffer()->Put(buf_ctrl_vol, + Manager::instance().getAudioDriver()->urgentRingBuffer().Put(buf_ctrl_vol, size * CHANNELS); - _callmanager->getAudioDriver()->startStream(); - _callmanager->getAudioDriver()->sleep(pulselen); - _callmanager->getAudioDriver()->stopStream(); + Manager::instance().getAudioDriver()->startStream(); + Manager::instance().getAudioDriver()->sleep(pulselen); + Manager::instance().getAudioDriver()->stopStream(); delete[] buf_ctrl_vol; } diff --git a/src/gui/qt/qtGUImainwindow.h b/src/gui/qt/qtGUImainwindow.h index be10e39519..a47f746526 100644 --- a/src/gui/qt/qtGUImainwindow.h +++ b/src/gui/qt/qtGUImainwindow.h @@ -42,7 +42,6 @@ class Call; class DTMF; class JPushButton; class MyDisplay; -class Manager; class MyTrayIcon; class NumericKeypad; class PhoneLine; @@ -77,7 +76,7 @@ class QtGUIMainWindow : public TransQWidget, public GuiFramework { Q_OBJECT public: // Default Constructor and destructor - QtGUIMainWindow (QWidget* = 0, const char* = 0,WFlags = 0,Manager * = NULL); + QtGUIMainWindow (QWidget* = 0, const char* = 0,WFlags = 0); ~QtGUIMainWindow(void); QPixmap TabLinePixmap[NUMBER_OF_LINES][NUMBER_OF_STATES]; @@ -229,7 +228,6 @@ private: QTimer* _blinkTimer; URL_Input* _urlinput; ConfigurationPanel* _panel; - Manager* _callmanager; QPopupMenu* _mypop; MyTrayIcon* _trayicon; DTMF* _key; diff --git a/src/main.cpp b/src/main.cpp index 8fdfb0f301..060fa72265 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,23 +38,20 @@ int main (int argc, char **argv) { - Manager* manager; - Config::setTree(new ConfigurationTree()); - manager = new Manager(); - GuiFramework *GUI; + Config::setTree(new ConfigurationTree()); + GuiFramework *GUI; #if defined(GUI_QT) - QApplication a(argc, argv); - GUI = new QtGUIMainWindow (0, 0 , - Qt::WDestructiveClose | - Qt::WStyle_Customize | - Qt::WStyle_NoBorder, - manager); - manager->setGui(GUI); - manager->init(); + QApplication a(argc, argv); + GUI = new QtGUIMainWindow (0, 0 , + Qt::WDestructiveClose | + Qt::WStyle_Customize | + Qt::WStyle_NoBorder); + Manager::instance().setGui(GUI); + Manager::instance().init(); - a.setMainWidget((QtGUIMainWindow*)GUI); - return a.exec(); + a.setMainWidget((QtGUIMainWindow*)GUI); + return a.exec(); #endif } diff --git a/src/manager.h b/src/manager.h index 8ab71ca331..eb0a0cffd4 100644 --- a/src/manager.h +++ b/src/manager.h @@ -1,6 +1,7 @@ /** * Copyright (C) 2004-2005 Savoir-Faire Linux inc. - * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> + * Author : Jean-Philippe Barrette-LaPierre + * <jean-philippe.barrette-lapierre@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,285 +18,15 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef __MANAGER_H__ -#define __MANAGER_H__ +#ifndef SFLPHONE_MANAGER_H +#define SFLPHONE_MANAGER_H -#include <cc++/thread.h> +#include "utilspp/singleton_holder.hpp" +#include "managerimpl.h" -#include <string> -#include <vector> -#include "../stund/stun.h" -#include "call.h" +typedef utilspp::singleton_holder< ManagerImpl > Manager; -using namespace std; -using namespace ost; -class AudioLayer; -class CodecDescriptor; -class Error; -class GuiFramework; -class ToneGenerator; -class VoIPLink; +#endif -#define NOTIFICATION_LEN 250 -// Status -#define CONNECTED_STATUS "Connected" -#define LOGGED_IN_STATUS "Logged in" -#define RINGING_STATUS "Ringing" -#define TRYING_STATUS "Trying ..." -#define HUNGUP_STATUS "Hung up" -#define ONHOLD_STATUS "On hold ..." -#define TRANSFER_STATUS "Transfer to:" -#define MUTE_ON_STATUS "Mute on" -#define ENTER_NUMBER_STATUS "Enter Phone Number:" - -/* - * Define a type for a list of call - */ -typedef vector<Call*, allocator<Call*> > CallVector; - -/* - * Define a type for a list of VoIPLink - */ -typedef vector<VoIPLink*, allocator<VoIPLink*> > VoIPLinkVector; - -/* - * Define a type for a list of CodecDescriptor - */ -typedef vector<CodecDescriptor*, allocator<CodecDescriptor*> > CodecDescriptorVector; - -struct device_t{ - const char* hostApiName; - const char* deviceName; -}; - -class Manager { -public: - Manager (void); - ~Manager (void); - - static device_t deviceParam; - - void init (void); - void setGui (GuiFramework* gui); - ToneGenerator* getTonegenerator(void); - Error* error(void); - AudioLayer* getAudioDriver(void); - - // Accessor to number of calls - unsigned int getNumberOfCalls (void); - // Modifior of number of calls - void setNumberOfCalls (unsigned int nCalls); - - // Accessor to current call id - short getCurrentCallId (void); - // Modifior of current call id - void setCurrentCallId (short currentCallId); - - // Accessor to the Call vector - CallVector* getCallVector (void); - // Accessor to the Call with the id 'id' - Call* getCall (short id); - - unsigned int getNumberOfCodecs (void); - void setNumberOfCodecs (unsigned int nb_codec); - - VoIPLinkVector* getVoIPLinkVector (void); - - CodecDescriptorVector* getCodecDescVector(void); - - inline bool getZonetone (void) { return _zonetone; } - inline void setZonetone (bool b) { _zonetone = b; } - - /* - * Attribute a new random id for a new call - * and check if it's already attributed to existing calls. - * If not exists, returns 'id' otherwise return 0 - */ - short generateNewCallId (void); - - /* - * Add a new call at the end of the CallVector with identifiant 'id' - */ - void pushBackNewCall (short id, enum CallType type); - - /* - * Erase the Call(id) from the CallVector - */ - void deleteCall (short id); - - /* - * Functions which occur with a user's action - */ - int outgoingCall (const string& to); - int hangupCall (short id); - int cancelCall (short id); - int answerCall (short id); - int onHoldCall (short id); - int offHoldCall (short id); - int transferCall (short id, const string& to); - void muteOn (short id); - void muteOff (short id); - int refuseCall (short id); - - int saveConfig (void); - int registerVoIPLink (void); - int quitApplication (void); - int sendTextMessage (short id, const string& message); - int accessToDirectory (void); - - /** - * Handle choice of the DTMF-send-way - * - * @param id: callid of the line. - * @param code: pressed key. - */ - int sendDtmf (short id, char code); - - - int incomingCall (short id); - void peerAnsweredCall (short id); - int peerRingingCall (short id); - int peerHungupCall (short id); - void displayTextMessage (short id, const string& message); - void displayErrorText (const string& message); - void displayError (const string& error); - void displayStatus (const string& status); - int selectedCall (void); - bool isCurrentId (short id); - - /* - * Handle audio sounds heard by a caller while they wait for their - * connection to a called party to be completed. - */ - void ringback (bool var); - - /* - * Handle played music when an incoming call occurs - */ - void ringtone (bool var); - - void congestion (bool var); - - /* - * Notification of incoming call when you are already busy - */ - void notificationIncomingCall (void); - - /* - * Get information about firewall - * @param stunSvrAddr: stun server - */ - void getStunInfo (StunAddress4& stunSvrAddr); - bool useStun (void); - - inline bool getbCongestion (void) { return _congestion; } - inline bool getbRingback (void) { return _ringback; } - inline bool getbRingtone (void) { return _ringtone; } - - inline int getSpkrVolume (void) { return _spkr_volume; } - inline void setSpkrVolume (int spkr_vol) { _spkr_volume = spkr_vol; } - inline int getMicroVolume (void) { return _mic_volume; } - inline void setMicroVolume (int mic_vol) { _mic_volume = mic_vol; } - - inline int getFirewallPort (void) { return _firewallPort; } - inline void setFirewallPort (int port) { _firewallPort = port; } - inline string getFirewallAddress (void) { return _firewallAddr; } - - inline bool isDriverLoaded (void) { return _loaded; } - inline void loaded (bool l) { _loaded = l; } - - /* - * Functions about audio device - */ - static device_t deviceList (int); - static int deviceCount (void); - static bool defaultDevice (int); - -private: - - /* - * Returns the number of calls in the vector - */ - unsigned int callVectorSize (void); - - /** - * Create .PROGNAME directory in home user and create - * configuration tree from the settings file if this file exists. - * - * @return 0 if creating file failed - * 1 if config-file exists - * 2 if file doesn't exist yet. - */ - int createSettingsPath (void); - - /* - * Init default values for the different fields - */ - void initConfigFile (void); - - void initAudioCodec(void); - void selectAudioDriver (void); - -///////////////////// -// Private variables -///////////////////// - ToneGenerator* _tone; - Error* _error; - GuiFramework* _gui; - AudioLayer* _audiodriverPA; - - /* - * Vector of VoIPLink - */ - VoIPLinkVector* _voIPLinkVector; - - /* - * Vector of calls - */ - CallVector* _callVector; - - /* - * Vector of CodecDescriptor - */ - CodecDescriptorVector* _codecDescVector; - - /* - * Mutex to protect access to code section - */ - Mutex _mutex; - - unsigned int _nCalls; - short _currentCallId; - - /* - * For the call timer - */ - unsigned int _startTime; - unsigned int _endTime; - - /* Path of the ConfigFile - */ - string _path; - int _exist; - - unsigned int _nCodecs; - bool _zonetone; - bool _congestion; - bool _ringback; - bool _ringtone; - - // To handle volume control - int _spkr_volume; - int _mic_volume; - - // To handle firewall - int _firewallPort; - string _firewallAddr; - - // Variables used in exception - bool _loaded; -}; - -#endif // __MANAGER_H__ diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index 592388a403..af8cc18824 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -51,15 +51,14 @@ using namespace std; #define RANDOM_LOCAL_PORT ((rand() % 27250) + 5250)*2 -SipVoIPLink::SipVoIPLink (short id, Manager* manager) : VoIPLink (id, manager) +SipVoIPLink::SipVoIPLink (short id) : VoIPLink (id) { setId(id); _localPort = 0; _cid = 0; - _manager = manager; _evThread = new EventThread (this); _sipcallVector = new SipCallVector(); - _audiortp = new AudioRtp(_manager); + _audiortp = new AudioRtp(); } SipVoIPLink::~SipVoIPLink (void) @@ -99,13 +98,13 @@ SipVoIPLink::init (void) } } // If use STUN server, firewall address setup - if (_manager->useStun()) { + if (Manager::instance().useStun()) { eXosip_set_user_agent(tmp.data()); if (behindNat() != 1) { return 0; } - eXosip_set_firewallip((_manager->getFirewallAddress()).data()); + eXosip_set_firewallip((Manager::instance().getFirewallAddress()).data()); } eXosip_set_user_agent(tmp.data()); @@ -139,14 +138,14 @@ SipVoIPLink::initRtpmapCodec (void) eXosip_sdp_negotiation_remove_audio_payloads(); // Set rtpmap according to the supported codec order - nb = _manager->getNumberOfCodecs(); + nb = Manager::instance().getNumberOfCodecs(); for (unsigned int i = 0; i < nb; i++) { - payload = _manager->getCodecDescVector()->at(i)->getPayload(); + payload = Manager::instance().getCodecDescVector()->at(i)->getPayload(); // Add payload to rtpmap if it is not already added - if (!isInRtpmap(i, payload, _manager->getCodecDescVector())) { + if (!isInRtpmap(i, payload, Manager::instance().getCodecDescVector())) { snprintf(rtpmap, 127, "%d %s/%d", payload, - _manager->getCodecDescVector()->at(i)->rtpmapPayload(payload).data(), SAMPLING_RATE); + Manager::instance().getCodecDescVector()->at(i)->rtpmapPayload(payload).data(), SAMPLING_RATE); snprintf(tmp, 63, "%d", payload); eXosip_sdp_negotiation_add_codec( osip_strdup(tmp), NULL, @@ -175,11 +174,11 @@ SipVoIPLink::setRegister (void) get_config_fields_str(SIGNALISATION, HOST_PART)); if (get_config_fields_str(SIGNALISATION, HOST_PART).empty()) { - _manager->error()->errorName(HOST_PART_FIELD_EMPTY); + Manager::instance().error()->errorName(HOST_PART_FIELD_EMPTY); return -1; } if (get_config_fields_str(SIGNALISATION, USER_PART).empty()) { - _manager->error()->errorName(USER_PART_FIELD_EMPTY); + Manager::instance().error()->errorName(USER_PART_FIELD_EMPTY); return -1; } @@ -287,7 +286,7 @@ int SipVoIPLink::hangup (short id) { int i = 1; - if (!_manager->getbCongestion()) { + if (!Manager::instance().getbCongestion()) { _debug("Hang up call [id = %d, cid = %d, did = %d]\n", id, getSipCall(id)->getCid(), getSipCall(id)->getDid()); // Release SIP stack. @@ -308,7 +307,7 @@ int SipVoIPLink::cancel (short id) { int i = 1; - if (!_manager->getbCongestion()) { + if (!Manager::instance().getbCongestion()) { _debug("Cancel call [id = %d, cid = %d]\n", id, getCid()); // Release SIP stack. eXosip_lock(); @@ -398,20 +397,19 @@ SipVoIPLink::getEvent (void) // IP-Phone user receives a new call case EXOSIP_CALL_NEW: // // Set local random port for incoming call - if (!_manager->useStun()) { - // If no firewall + if (!Manager::instance().useStun()) { setLocalPort(RANDOM_LOCAL_PORT); } else { // If there is a firewall if (behindNat() != 0) { - setLocalPort(_manager->getFirewallPort()); + setLocalPort(Manager::instance().getFirewallPort()); } else { return -1; } } - id = _manager->generateNewCallId(); - _manager->pushBackNewCall(id, Incoming); + id = Manager::instance().generateNewCallId(); + Manager::instance().pushBackNewCall(id, Incoming); _debug("Incoming Call with identifiant %d [cid = %d, did = %d]\n", id, event->cid, event->did); _debug("Local audio port: %d\n", _localPort); @@ -421,9 +419,9 @@ SipVoIPLink::getEvent (void) osip_from_init(&from); osip_from_parse(from, event->remote_uri); name = osip_from_get_displayname(from); - _manager->displayTextMessage(id, name); - if (_manager->getCall(id) != NULL) { - _manager->getCall(id)->setCallerIdName(name); + Manager::instance().displayTextMessage(id, name); + if (Manager::instance().getCall(id) != NULL) { + Manager::instance().getCall(id)->setCallerIdName(name); } else { return -1; } @@ -431,8 +429,8 @@ SipVoIPLink::getEvent (void) osip_from_free(from); getSipCall(id)->newIncomingCall(event); - if (_manager->incomingCall(id) < 0) { - _manager->displayErrorText("Incoming call failed"); + if (Manager::instance().incomingCall(id) < 0) { + Manager::instance().displayErrorText("Incoming call failed"); return -1; } @@ -451,11 +449,11 @@ SipVoIPLink::getEvent (void) id, event->cid, event->did,getSipCall(id)->getLocalAudioPort()); // Answer - if (id > 0 and !_manager->getCall(id)->isOnHold() - and !_manager->getCall(id)->isOffHold()) { + if (id > 0 and !Manager::instance().getCall(id)->isOnHold() + and !Manager::instance().getCall(id)->isOffHold()) { getSipCall(id)->setStandBy(false); if (getSipCall(id)->answeredCall(event) != -1) { - _manager->peerAnsweredCall(id); + Manager::instance().peerAnsweredCall(id); // Outgoing call is answered, start the sound channel. if (_audiortp->createNewSession (getSipCall(id)) < 0) { @@ -475,7 +473,7 @@ SipVoIPLink::getEvent (void) if (id > 0) { getSipCall(id)->ringingCall(event); - _manager->peerRingingCall(id); + Manager::instance().peerRingingCall(id); } else { return -1; } @@ -491,10 +489,10 @@ SipVoIPLink::getEvent (void) id, event->cid, event->did); if (id > 0) { - if (!_manager->getCall(id)->isProgressing()) { + if (!Manager::instance().getCall(id)->isProgressing()) { _audiortp->closeRtpSession(getSipCall(id)); } - _manager->peerHungupCall(id); + Manager::instance().peerHungupCall(id); deleteSipCall(id); } else { return -1; @@ -543,8 +541,8 @@ SipVoIPLink::getEvent (void) case ADDR_INCOMPLETE: case BUSY_HERE: // Display error on the screen phone - _manager->displayError(event->reason_phrase); - _manager->congestion(true); + Manager::instance().displayError(event->reason_phrase); + Manager::instance().congestion(true); break; case REQ_TERMINATED: break; @@ -557,8 +555,8 @@ SipVoIPLink::getEvent (void) // Handle 5XX errors switch (event->status_code) { case SERVICE_UNAVAILABLE: - _manager->ringback(false); - _manager->congestion(true); + Manager::instance().ringback(false); + Manager::instance().congestion(true); break; default: break; @@ -570,8 +568,8 @@ SipVoIPLink::getEvent (void) switch (event->status_code) { case BUSY_EVERYWHERE: case DECLINE: - _manager->ringback(false); - _manager->congestion(true); + Manager::instance().ringback(false); + Manager::instance().congestion(true); break; default: break; @@ -580,7 +578,7 @@ SipVoIPLink::getEvent (void) case EXOSIP_REGISTRATION_SUCCESS: _debug("-- Registration succeeded --\n"); - _manager->displayStatus(LOGGED_IN_STATUS); + Manager::instance().displayStatus(LOGGED_IN_STATUS); break; case EXOSIP_REGISTRATION_FAILURE: @@ -682,7 +680,7 @@ void SipVoIPLink::newOutgoingCall (short callid) { _sipcallVector->push_back(new SipCall(callid, - _manager->getCodecDescVector())); + Manager::instance().getCodecDescVector())); if (getSipCall(callid) != NULL) { getSipCall(callid)->setStandBy(true); } @@ -691,7 +689,7 @@ SipVoIPLink::newOutgoingCall (short callid) void SipVoIPLink::newIncomingCall (short callid) { - SipCall* sipcall = new SipCall(callid, _manager->getCodecDescVector()); + SipCall* sipcall = new SipCall(callid, Manager::instance().getCodecDescVector()); _sipcallVector->push_back(sipcall); } @@ -751,7 +749,7 @@ SipVoIPLink::behindNat (void) // Firewall address _debug("STUN server: %s\n", svr.data()); - _manager->getStunInfo(stunSvrAddr); + Manager::instance().getStunInfo(stunSvrAddr); return 1; } @@ -799,7 +797,7 @@ SipVoIPLink::setAuthentication (void) } pass = get_config_fields_str(SIGNALISATION, PASSWORD); if (pass.empty()) { - _manager->error()->errorName(PASSWD_FIELD_EMPTY); + Manager::instance().error()->errorName(PASSWD_FIELD_EMPTY); return -1; } @@ -836,11 +834,11 @@ SipVoIPLink::startCall (short id, const string& from, const string& to, int i; if (checkUrl(from) != 0) { - _manager->error()->errorName(FROM_ERROR); + Manager::instance().error()->errorName(FROM_ERROR); return -1; } if (checkUrl(to) != 0) { - _manager->error()->errorName(TO_ERROR); + Manager::instance().error()->errorName(TO_ERROR); return -1; } @@ -853,15 +851,15 @@ SipVoIPLink::startCall (short id, const string& from, const string& to, eXosip_lock(); char port[64]; - if (!_manager->useStun()) { + if (!Manager::instance().useStun()) { // Set random port for outgoing call setLocalPort(RANDOM_LOCAL_PORT); _debug("Local audio port: %d\n",_localPort); } else { // If use Stun server if (behindNat() != 0) { - _debug("sip invite: firewall port = %d\n",_manager->getFirewallPort()); - setLocalPort(_manager->getFirewallPort()); + _debug("sip invite: firewall port = %d\n",Manager::instance().getFirewallPort()); + setLocalPort(Manager::instance().getFirewallPort()); } else { return -1; } @@ -909,7 +907,7 @@ short SipVoIPLink::findCallIdWhenRinging (void) { unsigned int k; - int i = _manager->selectedCall(); + int i = Manager::instance().selectedCall(); if (i != -1) { return i; diff --git a/src/sipvoiplink.h b/src/sipvoiplink.h index 66e9f9e7ea..ae34952765 100644 --- a/src/sipvoiplink.h +++ b/src/sipvoiplink.h @@ -55,7 +55,6 @@ class AudioCodec; class AudioRtp; class CodecDescriptor; class EventThread; -class Manager; class SipCall; typedef vector<SipCall*, allocator<SipCall*> > SipCallVector; @@ -63,7 +62,7 @@ typedef vector<CodecDescriptor*, allocator<CodecDescriptor*> > CodecDescriptorVe class SipVoIPLink : public VoIPLink { public: - SipVoIPLink (short id, Manager* manager); + SipVoIPLink (short id); virtual ~SipVoIPLink (void); virtual int init (void); @@ -124,7 +123,6 @@ private: short findCallIdWhenRinging (void); bool isInRtpmap (int index, int payload, CodecDescriptorVector* cdv); - Manager* _manager; EventThread* _evThread; SipCallVector* _sipcallVector; AudioRtp* _audiortp; diff --git a/src/voIPLink.cpp b/src/voIPLink.cpp index fd50a2f646..64f29b96ac 100644 --- a/src/voIPLink.cpp +++ b/src/voIPLink.cpp @@ -26,10 +26,9 @@ using namespace std; -VoIPLink::VoIPLink (short id, Manager* manager) +VoIPLink::VoIPLink (short id) { _id = id; - _manager = manager; initConstructor(); } diff --git a/src/voIPLink.h b/src/voIPLink.h index d5a976c674..8b5555638a 100644 --- a/src/voIPLink.h +++ b/src/voIPLink.h @@ -31,10 +31,9 @@ enum VoIPLinkType { class AudioCodec; class Call; -class Manager; class VoIPLink { public: - VoIPLink (short id, Manager* manager); + VoIPLink (short id); virtual ~VoIPLink (void); virtual int getEvent (void) = 0; @@ -75,7 +74,6 @@ protected: private: void initConstructor(void); - Manager* _manager; short _id; VoIPLinkType _type; string _fullname; -- GitLab