Commit 3c039662 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

* #6630 : don't make DBusManager a singleton

Instead it is part of Manager which is already itself a singleton
When the client requests termination of the daemon, the DBusManager instance
is not destructed, so we avoid using already freed memory

make Manager::(un)serialize static functions, they don't depend on the instance state
No need to check for the NULLity of _dbus anymore

Remove a useless argument to initConfigFile
parent 80cc4a92
......@@ -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);
}
......@@ -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;
......
......@@ -41,7 +41,6 @@ using std::ptrdiff_t;
#include <map>
class SIPCall;
class DBusManagerImpl;
namespace sfl
{
......
......@@ -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)
......
......@@ -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();
}
......@@ -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
/*
* 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
......@@ -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;
}
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -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);