diff --git a/daemon/src/account.cpp b/daemon/src/account.cpp index 3441ffbb6d552984b3ece48006b4294555f746b3..62449007855df20161487cedf00b0e1d02446897 100644 --- a/daemon/src/account.cpp +++ b/daemon/src/account.cpp @@ -98,6 +98,5 @@ void Account::setActiveCodecs (const std::vector <std::string> &list) } // update the codec string according to new codec selection - _codecStr = Manager::instance ().serialize (list); - + _codecStr = ManagerImpl::serialize (list); } diff --git a/daemon/src/audio/audiortp/ZrtpSessionCallback.cpp b/daemon/src/audio/audiortp/ZrtpSessionCallback.cpp index 8f5fd3a4e3b8aa80a713bc6116e2f17934f3b1dd..f7ab8cc49edbc729afe6f046a5b85eb7903a8a80 100644 --- a/daemon/src/audio/audiortp/ZrtpSessionCallback.cpp +++ b/daemon/src/audio/audiortp/ZrtpSessionCallback.cpp @@ -33,6 +33,7 @@ #include "sip/sipcall.h" #include "dbus/dbusmanager.h" #include "dbus/callmanager.h" +#include "manager.h" #include <cstdlib> #include <string> @@ -127,21 +128,21 @@ void ZrtpSessionCallback::secureOn (std::string cipher) { _debug ("Zrtp: Secure mode is on with cipher %s", cipher.c_str()); - DBusManager::instance().getCallManager()->secureZrtpOn (_sipcall->getCallId(), cipher); + Manager::instance().getDbusManager()->getCallManager()->secureZrtpOn (_sipcall->getCallId(), cipher); } void ZrtpSessionCallback::secureOff (void) { _debug ("Zrtp: Secure mode is off"); - DBusManager::instance().getCallManager()->secureZrtpOff (_sipcall->getCallId()); + Manager::instance().getDbusManager()->getCallManager()->secureZrtpOff (_sipcall->getCallId()); } void ZrtpSessionCallback::showSAS (std::string sas, bool verified) { _debug ("Zrtp: SAS is: %s", sas.c_str()); - DBusManager::instance().getCallManager()->showSAS (_sipcall->getCallId(), sas, verified); + Manager::instance().getDbusManager()->getCallManager()->showSAS (_sipcall->getCallId(), sas, verified); } @@ -149,7 +150,7 @@ void ZrtpSessionCallback::zrtpNotSuppOther() { _debug ("Zrtp: Callee does not support ZRTP"); - DBusManager::instance().getCallManager()->zrtpNotSuppOther (_sipcall->getCallId()); + Manager::instance().getDbusManager()->getCallManager()->zrtpNotSuppOther (_sipcall->getCallId()); } @@ -214,12 +215,12 @@ ZrtpSessionCallback::zrtpNegotiationFailed (MessageSeverity severity, int subCod if (msg != NULL) { _debug ("%s", msg->c_str()); - DBusManager::instance().getCallManager()->zrtpNegotiationFailed (_sipcall->getCallId(), *msg, "ZRTP"); + Manager::instance().getDbusManager()->getCallManager()->zrtpNegotiationFailed (_sipcall->getCallId(), *msg, "ZRTP"); } } else { msg = _severeMap[subCode]; _debug ("%s", msg->c_str()); - DBusManager::instance().getCallManager()->zrtpNegotiationFailed (_sipcall->getCallId(), *msg, "severe"); + Manager::instance().getDbusManager()->getCallManager()->zrtpNegotiationFailed (_sipcall->getCallId(), *msg, "severe"); } } @@ -227,7 +228,7 @@ void ZrtpSessionCallback::confirmGoClear() { _debug ("Zrtp: Received go clear message. Until confirmation, ZRTP won't send any data"); - DBusManager::instance().getCallManager()->zrtpNotSuppOther (_sipcall->getCallId()); + Manager::instance().getDbusManager()->getCallManager()->zrtpNotSuppOther (_sipcall->getCallId()); } std::map<int32, std::string*>ZrtpSessionCallback::_infoMap; diff --git a/daemon/src/audio/audiortp/ZrtpSessionCallback.h b/daemon/src/audio/audiortp/ZrtpSessionCallback.h index 10152e371155465ddf145eafc6cf27c5576b6ce0..85e2a6172683e453fe9a949a2ed2ec59349c2a10 100644 --- a/daemon/src/audio/audiortp/ZrtpSessionCallback.h +++ b/daemon/src/audio/audiortp/ZrtpSessionCallback.h @@ -41,7 +41,6 @@ using std::ptrdiff_t; #include <map> class SIPCall; -class DBusManagerImpl; namespace sfl { diff --git a/daemon/src/dbus/Makefile.am b/daemon/src/dbus/Makefile.am index 41ee79d468e873feaeadf3e916f4dba2e5574481..cbfa036393012778ba78750ce2b7f39a07a6d9a4 100644 --- a/daemon/src/dbus/Makefile.am +++ b/daemon/src/dbus/Makefile.am @@ -15,7 +15,7 @@ libdbus_la_SOURCES = \ callmanager.cpp \ configurationmanager.cpp \ instance.cpp \ - dbusmanagerimpl.cpp \ + dbusmanager.cpp \ networkmanager.cpp if USE_NETWORKMANAGER @@ -34,7 +34,6 @@ noinst_HEADERS = \ configurationmanager.h \ instance.h \ dbusmanager.h \ - dbusmanagerimpl.h \ networkmanager_proxy.h \ networkmanager.h \ $(BUILT_SOURCES) diff --git a/daemon/src/dbus/dbusmanagerimpl.cpp b/daemon/src/dbus/dbusmanager.cpp similarity index 87% rename from daemon/src/dbus/dbusmanagerimpl.cpp rename to daemon/src/dbus/dbusmanager.cpp index 43c29f8af772adeb7e82d5e6de11362871023fdc..3d11869eda2d6b91511803b75fe6ebd9f2af9528 100644 --- a/daemon/src/dbus/dbusmanagerimpl.cpp +++ b/daemon/src/dbus/dbusmanager.cpp @@ -28,7 +28,7 @@ * as that of the covered work. */ -#include <dbusmanagerimpl.h> +#include <dbusmanager.h> #include "global.h" #include "manager.h" @@ -36,39 +36,25 @@ #include "configurationmanager.h" #include "networkmanager.h" -const char* DBusManagerImpl::SERVER_NAME = "org.sflphone.SFLphone"; - -void -DBusManagerImpl::exec() +DBusManager::DBusManager() { - DBus::default_dispatcher = &_dispatcher; DBus::Connection sessionConnection = DBus::Connection::SessionBus(); - DBus::Connection systemConnection = DBus::Connection::SystemBus(); - sessionConnection.request_name (SERVER_NAME); + sessionConnection.request_name ("org.sflphone.SFLphone"); _callManager = new CallManager (sessionConnection); _configurationManager = new ConfigurationManager (sessionConnection); _instanceManager = new Instance (sessionConnection); #ifdef USE_NETWORKMANAGER + DBus::Connection systemConnection = DBus::Connection::SystemBus(); _networkManager = new NetworkManager (systemConnection, "/org/freedesktop/NetworkManager", ""); #endif - - // Register accounts - Manager::instance().initRegisterAccounts(); //getEvents(); - - _debug ("Starting DBus event loop"); - _dispatcher.enter(); } -void -DBusManagerImpl::exit() +DBusManager::~DBusManager() { - - _dispatcher.leave(); - delete _callManager; delete _configurationManager; delete _instanceManager; @@ -76,6 +62,16 @@ DBusManagerImpl::exit() #ifdef USE_NETWORKMANAGER delete _networkManager; #endif +} + +void DBusManager::exec() +{ + _dispatcher.enter(); +} +void +DBusManager::exit() +{ + _dispatcher.leave(); } diff --git a/daemon/src/dbus/dbusmanager.h b/daemon/src/dbus/dbusmanager.h index aac0d5730d6df9790b70b42973a09cb5b33421fd..2c31a189374e41259e3f82805fbc1b00d1baf03c 100644 --- a/daemon/src/dbus/dbusmanager.h +++ b/daemon/src/dbus/dbusmanager.h @@ -28,12 +28,40 @@ * as that of the covered work. */ -#ifndef __DBUSMANAGERSINGLETON_H__ -#define __DBUSMANAGERSINGLETON_H__ +#ifndef __DBUSMANAGERIMPL_H__ +#define __DBUSMANAGERIMPL_H__ -#include "utilspp/Singleton.hpp" -#include "dbusmanagerimpl.h" +#include "instance.h" -typedef utilspp::SingletonHolder< DBusManagerImpl > DBusManager; +class ConfigurationManager; +class CallManager; +class NetworkManager; -#endif // __DBUSMANAGERSINGLETON_H__ +class DBusManager +{ + public: + DBusManager(); + ~DBusManager(); + + CallManager * getCallManager() const { + return _callManager; + }; + ConfigurationManager * getConfigurationManager() const { + return _configurationManager; + }; + + void exec(); + void exit(); + static const char* SERVER_NAME; + + private: + CallManager* _callManager; + ConfigurationManager* _configurationManager; + Instance* _instanceManager; + DBus::BusDispatcher _dispatcher; +#if USE_NETWORKMANAGER + NetworkManager* _networkManager; +#endif +}; + +#endif diff --git a/daemon/src/dbus/dbusmanagerimpl.h b/daemon/src/dbus/dbusmanagerimpl.h deleted file mode 100644 index 8324c42d4667de3c3ea7d4c201f1bd53c83e4397..0000000000000000000000000000000000000000 --- a/daemon/src/dbus/dbusmanagerimpl.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#ifndef __DBUSMANAGERIMPL_H__ -#define __DBUSMANAGERIMPL_H__ - -#include "instance.h" - -class ConfigurationManager; -class CallManager; -class NetworkManager; - -class DBusManagerImpl -{ - public: - CallManager * getCallManager() { - return _callManager; - }; - ConfigurationManager * getConfigurationManager() { - return _configurationManager; - }; - void exec(); - void exit(); - static const char* SERVER_NAME; - - private: - CallManager* _callManager; - ConfigurationManager* _configurationManager; - Instance* _instanceManager; - DBus::BusDispatcher _dispatcher; - NetworkManager* _networkManager; -}; - -#endif diff --git a/daemon/src/dbus/instance.cpp b/daemon/src/dbus/instance.cpp index 2e77e1108677647c37210d681d71001a306637a3..6a25a8e30f1f2b01ce8a4ab98a5ec00fbee1b765 100644 --- a/daemon/src/dbus/instance.cpp +++ b/daemon/src/dbus/instance.cpp @@ -55,20 +55,14 @@ Instance::Unregister (const int32_t& pid UNUSED) count --; if (count <= 0) { - - Manager::instance().terminate(); - - DBusManager::instance().exit(); - + Manager::instance().getDbusManager()->exit(); } } int32_t Instance::getRegistrationCount (void) { - return count; - } diff --git a/daemon/src/iax/iaxaccount.cpp b/daemon/src/iax/iaxaccount.cpp index d3667c7e604228201b868815633ee620558088b6..59d89755c033c67b3ba7952258a23ce36bcb4354 100644 --- a/daemon/src/iax/iaxaccount.cpp +++ b/daemon/src/iax/iaxaccount.cpp @@ -105,7 +105,7 @@ void IAXAccount::unserialize (Conf::MappingNode *map) map->getValue (codecsKey, &_codecStr); // Update codec list which one is used for SDP offer - setActiveCodecs (Manager::instance ().unserialize (_codecStr)); + setActiveCodecs (ManagerImpl::unserialize (_codecStr)); map->getValue (displayNameKey, &_displayName); } diff --git a/daemon/src/main.cpp b/daemon/src/main.cpp index b51d3e7b1849868989a8ff041568ece06a23426a..aed38a90410459cbb6e8dfe0b52f5b17f67fba6e 100644 --- a/daemon/src/main.cpp +++ b/daemon/src/main.cpp @@ -48,9 +48,11 @@ using namespace ost; +/* CommandOptionArg level ( "log-level", "l", "Log level (not yet implemented)" ); +*/ CommandOptionNoArg console ( "console", "c", "Log in console (instead of syslog)" @@ -90,15 +92,11 @@ main (int argc, char **argv) return 1; } - if (console.numSet) { - _info ("Console logging activated"); + if (console.numSet) Logger::setConsoleLog (true); - } - if (debug.numSet) { - _info ("Debug mode activated"); + if (debug.numSet) Logger::setDebugMode (true); - } FILE *fp; char homepid[128]; @@ -195,8 +193,8 @@ main (int argc, char **argv) try { // TODO Use $XDG_CONFIG_HOME to save the config file (which default to $HOME/.config) - Manager::instance().initConfigFile(); - Manager::instance().init(); + Manager::instance().initConfigFile(); + Manager::instance().init(); } catch (std::exception &e) { std::cerr << e.what() << std::endl; return 1; @@ -205,8 +203,9 @@ main (int argc, char **argv) return 1; } - Manager::instance().setDBusManager (&DBusManager::instance()); - DBusManager::instance().exec(); // UI Loop + _debug ("Starting DBus event loop"); + Manager::instance().getDbusManager()->exec(); + return 0; } diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 185bcc1ca13ea9b6b324909588f41e974c170444..6950dce94baa444c189335e9148c14072f47d3e1 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -79,7 +79,7 @@ ManagerImpl::ManagerImpl (void) : _currentCallMutex(), _audiodriver (NULL), _dtmfKey (NULL), _audioCodecFactory(), _toneMutex(), _telephoneTone (NULL), _audiofile (NULL), _spkr_volume (0), - _mic_volume (0), _mutex(), _dbus (NULL), _waitingCall(), + _mic_volume (0), _mutex(), _waitingCall(), _waitingCallMutex(), _nbIncomingWaitingCall (0), _path (""), _setupLoaded (false), _callAccountMap(), _callAccountMapMutex(), _callConfigMap(), _accountMap(), @@ -107,31 +107,16 @@ ManagerImpl::ManagerImpl (void) : // never call if we use only the singleton... ManagerImpl::~ManagerImpl (void) { - if (_audiofile) { - delete _audiofile; - _audiofile = NULL; - } - + delete _audiofile; delete _cleaner; - _cleaner = NULL; delete _history; - _history = NULL; delete _imModule; - _imModule = NULL; - - _debug ("Manager: %s stop correctly.", PROGNAME); } void ManagerImpl::init () { - - _debug ("Manager: Init"); - // Load accounts, init map buildConfiguration(); - - _debug ("Manager: account map loaded"); - initVolume(); initAudioDriver(); selectAudioDriver(); @@ -164,7 +149,8 @@ void ManagerImpl::init () // Init the instant messaging module _imModule->init(); - + // Register accounts + initRegisterAccounts(); //getEvents(); } void ManagerImpl::terminate () @@ -396,16 +382,11 @@ bool ManagerImpl::answerCall (const std::string& call_id) } // update call state on client side - if (_dbus == NULL) { - _error("Manager: Error: DBUS was not initialized"); - return false; - } - if(audioPreference.getIsAlwaysRecording()) { - _dbus->getCallManager()->callStateChanged (call_id, "RECORD"); + _dbus.getCallManager()->callStateChanged (call_id, "RECORD"); } else { - _dbus->getCallManager()->callStateChanged(call_id, "CURRENT"); + _dbus.getCallManager()->callStateChanged(call_id, "CURRENT"); } return true; @@ -437,11 +418,6 @@ bool ManagerImpl::hangupCall (const std::string& callId) } - if (_dbus == NULL) { - _error("Manager: Error: Dbus layer have not been instantiated"); - return false; - } - // store the current call id std::string currentCallId = getCurrentCallId(); @@ -449,7 +425,7 @@ bool ManagerImpl::hangupCall (const std::string& callId) /* Broadcast a signal over DBus */ _debug ("Manager: Send DBUS call state change (HUNGUP) for id %s", callId.c_str()); - _dbus->getCallManager()->callStateChanged (callId, "HUNGUP"); + _dbus.getCallManager()->callStateChanged (callId, "HUNGUP"); if (not isValidCall(callId) and not getConfigFromCall(callId) == Call::IPtoIP) { _error("Manager: Error: Could not hang up call, call not valid"); @@ -612,12 +588,7 @@ bool ManagerImpl::onHoldCall (const std::string& callId) switchCall (""); } - if (_dbus == NULL) { - _error("Manager: Error: DBUS not initialized"); - return false; - } - - _dbus->getCallManager()->callStateChanged (callId, "HOLD"); + _dbus.getCallManager()->callStateChanged (callId, "HOLD"); getMainBuffer()->stateInfo(); @@ -668,16 +639,7 @@ bool ManagerImpl::offHoldCall (const std::string& callId) returnValue = getAccountLink (accountId)->offhold (callId); } - if (_dbus == NULL) { - _error("Manager: Error: DBUS not initialized"); - } - - if (isRec) { - _dbus->getCallManager()->callStateChanged (callId, "UNHOLD_RECORD"); - } - else { - _dbus->getCallManager()->callStateChanged (callId, "UNHOLD_CURRENT"); - } + _dbus.getCallManager()->callStateChanged (callId, isRec ? "UNHOLD_RECORD" : "UNHOLD_CURRENT"); if (participToConference (callId)) { std::string currentAccountId; @@ -751,21 +713,12 @@ bool ManagerImpl::transferCall (const std::string& callId, const std::string& to void ManagerImpl::transferFailed () { - - _debug ("Manager: Transfer failed"); - - if (_dbus) - _dbus->getCallManager()->transferFailed(); + _dbus.getCallManager()->transferFailed(); } void ManagerImpl::transferSucceded () { - - _debug ("Manager: Transfer succeded"); - - if (_dbus) - _dbus->getCallManager()->transferSucceded(); - + _dbus.getCallManager()->transferSucceded(); } bool ManagerImpl::attendedTransfer(const std::string& transferID, const std::string& targetID) @@ -843,8 +796,7 @@ bool ManagerImpl::refuseCall (const std::string& id) if (returnValue) { removeWaitingCall (id); - if (_dbus) - _dbus->getCallManager()->callStateChanged (id, "HUNGUP"); + _dbus.getCallManager()->callStateChanged (id, "HUNGUP"); } // Disconnect streams @@ -869,9 +821,7 @@ ManagerImpl::createConference (const std::string& id1, const std::string& id2) _conferencemap.insert (std::pair<std::string, Conference*> (conf->getConfID(), conf)); // broadcast a signal over dbus - if (_dbus) { - _dbus->getCallManager()->conferenceCreated (conf->getConfID()); - } + _dbus.getCallManager()->conferenceCreated (conf->getConfID()); return conf; } @@ -897,9 +847,7 @@ void ManagerImpl::removeConference (const std::string& conference_id) } // broadcast a signal over dbus - if (_dbus) { - _dbus->getCallManager()->conferenceRemoved (conference_id); - } + _dbus.getCallManager()->conferenceRemoved (conference_id); // We now need to bind the audio to the remain participant @@ -983,17 +931,8 @@ void ManagerImpl::holdConference (const std::string& id) } - if(isRec) { - conf->setState(Conference::HOLD_REC); - } - else { - conf->setState (Conference::HOLD); - } - - if (_dbus) { - _dbus->getCallManager()->conferenceChanged (conf->getConfID(), conf->getStateStr()); - } - + conf->setState(isRec ? Conference::HOLD_REC : Conference::HOLD); + _dbus.getCallManager()->conferenceChanged (conf->getConfID(), conf->getStateStr()); } } @@ -1038,16 +977,8 @@ void ManagerImpl::unHoldConference (const std::string& id) } - if(isRec) { - conf->setState (Conference::ACTIVE_ATTACHED_REC); - } - else { - conf->setState (Conference::ACTIVE_ATTACHED); - } - - if (_dbus) { - _dbus->getCallManager()->conferenceChanged (conf->getConfID(), conf->getStateStr()); - } + conf->setState (isRec ? Conference::ACTIVE_ATTACHED_REC : Conference::ACTIVE_ATTACHED); + _dbus.getCallManager()->conferenceChanged (conf->getConfID(), conf->getStateStr()); } } @@ -1209,9 +1140,7 @@ void ManagerImpl::addMainParticipant (const std::string& conference_id) _warn("Manager: Warning: Invalid conference state while adding main participant"); } - if (_dbus) - _dbus->getCallManager()->conferenceChanged (conference_id, conf->getStateStr()); - + _dbus.getCallManager()->conferenceChanged (conference_id, conf->getStateStr()); } audioLayerMutexUnlock(); @@ -1339,49 +1268,44 @@ void ManagerImpl::createConfFromParticipantList(const std::vector< std::string > Conference *conf = new Conference(); for(unsigned int i = 0; i < participantList.size(); i++) { - std::string numberaccount = participantList[i]; - std::string tostr = numberaccount.substr(0, numberaccount.find(",")); - std::string account = numberaccount.substr(numberaccount.find(",")+1, numberaccount.size()); - - std::string generatedCallID = getNewCallID(); + std::string numberaccount = participantList[i]; + std::string tostr = numberaccount.substr(0, numberaccount.find(",")); + std::string account = numberaccount.substr(numberaccount.find(",")+1, numberaccount.size()); - // Manager methods may behave differently if the call id particip to a conference - conf->add(generatedCallID); + std::string generatedCallID = getNewCallID(); - switchCall(""); + // Manager methods may behave differently if the call id particip to a conference + conf->add(generatedCallID); - // Create call - callSuccess = outgoingCall(account, generatedCallID, tostr, conf->getConfID()); + switchCall(""); - // If not able to create call remove this participant from the conference - if(!callSuccess) - conf->remove(generatedCallID); + // Create call + callSuccess = outgoingCall(account, generatedCallID, tostr, conf->getConfID()); - if(_dbus && callSuccess) { - _dbus->getCallManager()->newCallCreated(account, generatedCallID, tostr); - successCounter++; - } + // If not able to create call remove this participant from the conference + if(!callSuccess) + conf->remove(generatedCallID); + else { + _dbus.getCallManager()->newCallCreated(account, generatedCallID, tostr); + successCounter++; + } } // Create the conference if and only if at least 2 calls have been successfully created if(successCounter >= 2 ) { _conferencemap.insert(std::pair<std::string, Conference *> (conf->getConfID(), conf)); - if (_dbus) { - _dbus->getCallManager()->conferenceCreated (conf->getConfID()); - } + _dbus.getCallManager()->conferenceCreated (conf->getConfID()); - audioLayerMutexLock(); - if(_audiodriver) { - conf->setRecordingSmplRate(_audiodriver->getSampleRate()); - } - audioLayerMutexUnlock(); + audioLayerMutexLock(); + if(_audiodriver) + conf->setRecordingSmplRate(_audiodriver->getSampleRate()); - getMainBuffer()->stateInfo(); - } - else { - delete conf; - conf = NULL; + audioLayerMutexUnlock(); + + getMainBuffer()->stateInfo(); + } else { + delete conf; } } @@ -1458,9 +1382,7 @@ void ManagerImpl::detachParticipant (const std::string& call_id, _warn("Manager: Warning: Undefined behavior, invalid conference state in detach participant"); } - if (_dbus) { - _dbus->getCallManager()->conferenceChanged (conf->getConfID(), conf->getStateStr()); - } + _dbus.getCallManager()->conferenceChanged (conf->getConfID(), conf->getStateStr()); switchCall (""); @@ -1906,9 +1828,7 @@ bool ManagerImpl::incomingCall (Call* call, const std::string& accountId) display.append (" "); display.append (from); - if (_dbus) { - _dbus->getCallManager()->incomingCall (accountId, call->getCallId(), display.c_str()); - } + _dbus.getCallManager()->incomingCall (accountId, call->getCallId(), display.c_str()); return true; } @@ -1959,16 +1879,11 @@ void ManagerImpl::incomingMessage (const std::string& callID, } // in case of a conference we must notify client using conference id - if (_dbus) { - _dbus->getCallManager()->incomingMessage (conf->getConfID(), from, message); - } + _dbus.getCallManager()->incomingMessage (conf->getConfID(), from, message); } else { - - if (_dbus) { - _dbus->getCallManager()->incomingMessage (callID, from, message); - } - } + _dbus.getCallManager()->incomingMessage (callID, from, message); + } } @@ -2104,36 +2019,21 @@ void ManagerImpl::peerAnsweredCall (const std::string& id) if(audioPreference.getIsAlwaysRecording()) { setRecordingCall(id); - } - - if(_dbus == NULL) { - _error("Manager: Error: DBUS not initialized"); - return; - } - - if(audioPreference.getIsAlwaysRecording()) { - _dbus->getCallManager()->callStateChanged (id, "RECORD"); - } - else { - _dbus->getCallManager()->callStateChanged(id, "CURRENT"); + _dbus.getCallManager()->callStateChanged (id, "RECORD"); + } else { + _dbus.getCallManager()->callStateChanged(id, "CURRENT"); } } //THREAD=VoIP Call=Outgoing void ManagerImpl::peerRingingCall (const std::string& id) { - _debug ("Manager: Peer call %s ringing", id.c_str()); - if (isCurrentCall (id)) { + if (isCurrentCall (id)) ringback(); - } - if (_dbus == NULL) { - _error("Manager: Error: DBUS not initialized"); - } - - _dbus->getCallManager()->callStateChanged (id, "RINGING"); + _dbus.getCallManager()->callStateChanged (id, "RINGING"); } //THREAD=VoIP Call=Outgoing/Ingoing @@ -2172,9 +2072,7 @@ void ManagerImpl::peerHungupCall (const std::string& call_id) } /* Broadcast a signal over DBus */ - if (_dbus) { - _dbus->getCallManager()->callStateChanged (call_id, "HUNGUP"); - } + _dbus.getCallManager()->callStateChanged (call_id, "HUNGUP"); removeWaitingCall (call_id); @@ -2200,9 +2098,7 @@ void ManagerImpl::callBusy (const std::string& id) { _debug ("Manager: Call %s busy", id.c_str()); - if (_dbus) { - _dbus->getCallManager()->callStateChanged (id, "BUSY"); - } + _dbus.getCallManager()->callStateChanged (id, "BUSY"); if (isCurrentCall (id)) { playATone (Tone::TONE_BUSY); @@ -2217,9 +2113,7 @@ void ManagerImpl::callBusy (const std::string& id) //THREAD=VoIP void ManagerImpl::callFailure (const std::string& call_id) { - if (_dbus) { - _dbus->getCallManager()->callStateChanged (call_id, "FAILURE"); - } + _dbus.getCallManager()->callStateChanged (call_id, "FAILURE"); if (isCurrentCall (call_id)) { playATone (Tone::TONE_BUSY); @@ -2256,9 +2150,7 @@ void ManagerImpl::callFailure (const std::string& call_id) void ManagerImpl::startVoiceMessageNotification (const std::string& accountId, int nb_msg) { - if (_dbus) { - _dbus->getCallManager()->voiceMailNotify (accountId, nb_msg); - } + _dbus.getCallManager()->voiceMailNotify (accountId, nb_msg); } void ManagerImpl::connectionStatusNotification () @@ -2266,9 +2158,7 @@ void ManagerImpl::connectionStatusNotification () _debug ("Manager: connectionStatusNotification"); - if (_dbus != NULL) { - _dbus->getConfigurationManager()->accountsChanged(); - } + _dbus.getConfigurationManager()->accountsChanged(); } /** @@ -2326,7 +2216,7 @@ void ManagerImpl::stopTone () if (_audiofile) { std::string filepath = _audiofile->getFilePath(); - _dbus->getCallManager()->recordPlaybackStoped(filepath); + _dbus.getCallManager()->recordPlaybackStoped(filepath); delete _audiofile; _audiofile = NULL; } @@ -2406,8 +2296,7 @@ void ManagerImpl::ringtone (const std::string& accountID) _toneMutex.enterMutex(); if (_audiofile) { - if(_dbus) - _dbus->getCallManager()->recordPlaybackStoped(_audiofile->getFilePath()); + _dbus.getCallManager()->recordPlaybackStoped(_audiofile->getFilePath()); delete _audiofile; _audiofile = NULL; } @@ -2492,45 +2381,33 @@ void ManagerImpl::notificationIncomingCall (void) /////////////////////////////////////////////////////////////////////////////// /** * Initialization: Main Thread - * @return 1: ok - -1: error directory */ -int ManagerImpl::createSettingsPath (void) +std::string ManagerImpl::getConfigFile (void) { - - std::string xdg_config, xdg_env; - - _debug ("XDG_CONFIG_HOME: %s", XDG_CONFIG_HOME); - - xdg_config = std::string (HOMEDIR) + DIR_SEPARATOR_STR + ".config" + std::string configdir = std::string (HOMEDIR) + DIR_SEPARATOR_STR + ".config" + DIR_SEPARATOR_STR + PROGDIR; if (XDG_CONFIG_HOME != NULL) { - xdg_env = std::string (XDG_CONFIG_HOME); - (xdg_env.length() > 0) ? _path = xdg_env : _path = xdg_config; - } else - _path = xdg_config; + std::string xdg_env = std::string (XDG_CONFIG_HOME); + if (xdg_env != "") + configdir = xdg_env; + } - if (mkdir (_path.data(), 0700) != 0) { + if (mkdir (configdir.data(), 0700) != 0) { // If directory creation failed if (errno != EEXIST) { _debug ("Cannot create directory: %m"); - return -1; } } - // Load user's configuration - _path = _path + DIR_SEPARATOR_STR + PROGNAME + ".yml"; - - return 1; + return configdir + DIR_SEPARATOR_STR + PROGNAME + ".yml"; } /** * Initialization: Main Thread */ -void ManagerImpl::initConfigFile (bool load_user_value, std::string alternate) +void ManagerImpl::initConfigFile (std::string alternate) { - _debug ("Manager: Init config file"); // Init display name to the username under which @@ -2541,12 +2418,7 @@ void ManagerImpl::initConfigFile (bool load_user_value, std::string alternate) user_info = getpwuid (uid); // Loads config from ~/.sflphone/sflphoned.yml or so.. - - if (createSettingsPath() == 1 && load_user_value) { - if (alternate != "") - _path = alternate; - } - + _path = (alternate != "") ? alternate : getConfigFile(); _debug ("Manager: configuration file path: %s", _path.c_str()); @@ -2642,12 +2514,10 @@ std::vector<std::string> ManagerImpl::unserialize (std::string s) std::string ManagerImpl::serialize (std::vector<std::string> v) { - unsigned int i; std::string res; - for (i = 0; i < v.size(); i++) { + for (unsigned int i = 0; i < v.size(); i++) res += v[i] + "/"; - } return res; } @@ -2968,8 +2838,7 @@ void ManagerImpl::setRecordingCall (const std::string& id) rec->setRecording(); - if(_dbus) - _dbus->getCallManager()->recordPlaybackFilepath(id, rec->getFileName()); + _dbus.getCallManager()->recordPlaybackFilepath(id, rec->getFileName()); } bool ManagerImpl::isRecording (const std::string& id) @@ -2998,8 +2867,7 @@ bool ManagerImpl::startRecordedFilePlayback(const std::string& filepath) _toneMutex.enterMutex(); if(_audiofile) { - if(_dbus) - _dbus->getCallManager()->recordPlaybackStoped(_audiofile->getFilePath()); + _dbus.getCallManager()->recordPlaybackStoped(_audiofile->getFilePath()); delete _audiofile; _audiofile = NULL; } @@ -3103,10 +2971,8 @@ int32_t ManagerImpl::getAudioManager (void) void ManagerImpl::notifyErrClient (const int32_t& errCode) { - if (_dbus) { - _debug ("Manager: NOTIFY ERR NUMBER %d" , errCode); - _dbus -> getConfigurationManager() -> errorAlert (errCode); - } + _debug ("Manager: NOTIFY ERR NUMBER %d" , errCode); + _dbus.getConfigurationManager() -> errorAlert (errCode); } int ManagerImpl::getAudioDeviceIndex (const std::string name) @@ -3550,10 +3416,6 @@ int ManagerImpl::getLocalIp2IpPort (void) */ bool ManagerImpl::getCallStatus (const std::string& sequenceId UNUSED) { - if (!_dbus) { - return false; - } - ost::MutexLock m (_callAccountMapMutex); CallAccountMap::iterator iter = _callAccountMap.begin(); @@ -3843,13 +3705,7 @@ void ManagerImpl::setAccountDetails (const std::string& accountID, } // Update account details to the client side - if (_dbus) { - _error("Manager: Error: Dbus not initialized"); - return; - } - - _dbus->getConfigurationManager()->accountsChanged(); - + _dbus.getConfigurationManager()->accountsChanged(); } std::string ManagerImpl::addAccount ( @@ -3911,8 +3767,7 @@ std::string ManagerImpl::addAccount ( saveConfig(); - if (_dbus) - _dbus->getConfigurationManager()->accountsChanged(); + _dbus.getConfigurationManager()->accountsChanged(); return accountID.str(); } @@ -3936,9 +3791,7 @@ void ManagerImpl::removeAccount (const std::string& accountID) _debug ("REMOVE ACCOUNT"); - if (_dbus) - _dbus->getConfigurationManager()->accountsChanged(); - + _dbus.getConfigurationManager()->accountsChanged(); } // ACCOUNT handling @@ -4304,7 +4157,7 @@ void ManagerImpl::setAddressbookList (const std::vector<std::string>& list) { _debug ("Manager: Set addressbook list"); - std::string s = serialize (list); + std::string s = ManagerImpl::serialize (list); _debug("Manager: New addressbook list: %s", s.c_str()); addressbookPreference.setList (s); @@ -4313,9 +4166,7 @@ void ManagerImpl::setAddressbookList (const std::vector<std::string>& list) std::vector<std::string> ManagerImpl::getAddressbookList (void) { - - std::string s = addressbookPreference.getList(); - return unserialize (s); + return unserialize (addressbookPreference.getList()); } std::map<std::string, std::string> ManagerImpl::getHookSettings () diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index 1dacee2839ed0fb2ab21de59a26d64dd1e85d9a1..05f891f1a8f1f2f46fa5e5a3347d89b3e0a35f08 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -164,14 +164,6 @@ class ManagerImpl */ void terminate (void); - /** - * Set user interface manager. - * @param man The DBUS interface implementation - */ - void setDBusManager (DBusManagerImpl* man) { - _dbus = man; - } - /** * Accessor to audiodriver. * it's multi-thread and use mutex internally @@ -383,13 +375,6 @@ class ManagerImpl */ bool saveConfig (void); - /** - * Send registration to all enabled accounts - * @return 0 on registration success - * 1 otherelse - */ - int initRegisterAccounts(); - /** * @return true if we tried to register once */ @@ -663,9 +648,9 @@ class ManagerImpl * Required format: payloads separated with one slash. * @return std::string The serializabled string */ - std::string serialize (std::vector<std::string> v); + static std::string serialize (std::vector<std::string> v); - std::vector<std::string> unserialize (std::string v); + static std::vector<std::string> unserialize (std::string v); /** * Tells if IAX2 support is enabled @@ -1059,7 +1044,7 @@ class ManagerImpl * Fills the local _config (Conf::ConfigTree) with the default contents. * Called in main.cpp, just before Manager::init(). */ - void initConfigFile (bool load_user_value=true, std::string alternate=""); + void initConfigFile (std::string alternate=""); /** * Tell if the setup was already loaded @@ -1142,14 +1127,9 @@ class ManagerImpl int app_is_running (std::string process); /** - * 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. + * Create config directory in home user and return configuration file path */ - int createSettingsPath (void); + std::string getConfigFile (void); /* * Initialize audiocodec with config setting @@ -1224,7 +1204,7 @@ class ManagerImpl /** * Multithread variable (non protected) */ - DBusManagerImpl * _dbus; + DBusManager _dbus; /** * Waiting Call Vectors @@ -1371,11 +1351,11 @@ class ManagerImpl bool hasCurrentCall(); /** - * Return the current DBusManagerImpl - * @return A pointer to the DBusManagerImpl instance + * Return the current DBusManager + * @return A pointer to the DBusManager instance */ - DBusManagerImpl * getDbusManager() { - return _dbus; + DBusManager * getDbusManager() { + return &_dbus; } /** @@ -1442,6 +1422,13 @@ class ManagerImpl // Assignment Operator ManagerImpl& operator= (const ManagerImpl& rh); + /** + * Send registration to all enabled accounts + * @return 0 on registration success + * 1 otherelse + */ + int initRegisterAccounts(); + NumberCleaner *_cleaner; /** diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 554e686aa52d1c12a69e52c2cf6f7e9d61fe569e..191728546e5c85d2b8770df5c62bd502af13c1d7 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -266,7 +266,7 @@ void SIPAccount::unserialize (Conf::MappingNode *map) map->getValue(mailboxKey, &_mailBox); map->getValue(codecsKey, &_codecStr); // Update codec list which one is used for SDP offer - setActiveCodecs (Manager::instance ().unserialize (_codecStr)); + setActiveCodecs (ManagerImpl::unserialize (_codecStr)); map->getValue(ringtonePathKey, &_ringtonePath); map->getValue(ringtoneEnabledKey, &_ringtoneEnabled); diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 963023daf76e4f18a13cf468ba67e23900e7ee8b..91a4d18db9736a0ecb36780cce34f4eb84a9a667 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -3223,8 +3223,7 @@ void invite_session_state_changed_cb (pjsip_inv_session *inv, pjsip_event *e) if (statusCode) { const pj_str_t * description = pjsip_get_status_text (statusCode); // test wether or not dbus manager is instantiated, if not no need to notify the client - if (Manager::instance().getDbusManager()) - DBusManager::instance().getCallManager()->sipCallStateChanged (call->getCallId(), std::string (description->ptr, description->slen), statusCode); + Manager::instance().getDbusManager()->getCallManager()->sipCallStateChanged (call->getCallId(), std::string (description->ptr, description->slen), statusCode); } } @@ -3449,9 +3448,9 @@ void sdp_media_update_cb (pjsip_inv_session *inv, pj_status_t status) call->getAudioRtp()->setRemoteCryptoInfo (sdesnego); } catch (...) {} - DBusManager::instance().getCallManager()->secureSdesOn (call->getCallId()); + Manager::instance().getDbusManager()->getCallManager()->secureSdesOn (call->getCallId()); } else { - DBusManager::instance().getCallManager()->secureSdesOff (call->getCallId()); + Manager::instance().getDbusManager()->getCallManager()->secureSdesOff (call->getCallId()); } } @@ -3651,7 +3650,7 @@ void registration_cb (struct pjsip_regc_cbparam *param) if (param->code && description) { std::string state(description->ptr, description->slen); - DBusManager::instance().getCallManager()->registrationStateChanged (account->getAccountID(), state, param->code); + Manager::instance().getDbusManager()->getCallManager()->registrationStateChanged (account->getAccountID(), state, param->code); std::pair<int, std::string> details (param->code, state); // TODO: there id a race condition for this ressource when closing the application account->setRegistrationStateDetailed (details); diff --git a/daemon/test/main.cpp b/daemon/test/main.cpp index 3a7af6754b06002720721196e66b5931e15f83ba..af8fbcd136e1654931719c0a1ee1a7a3f7406d0e 100644 --- a/daemon/test/main.cpp +++ b/daemon/test/main.cpp @@ -91,7 +91,7 @@ int main (int argc, char* argv[]) printf ("\n\n=== SFLphone initialization ===\n\n"); system("cp " CONFIG_SAMPLE " " CONFIG_SAMPLE ".bak"); - Manager::instance().initConfigFile (true, CONFIG_SAMPLE); + Manager::instance().initConfigFile (CONFIG_SAMPLE); Manager::instance().init(); // Get the top level suite from the registry