From 035e60363495fd324979d01d6c86019d0464ef51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mesquita?= Date: Sat, 23 Jan 2010 16:15:59 +0000 Subject: [PATCH] Properly reload gateway after it has been edited. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16478 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- fscomm/fshost.cpp | 35 ++++++++++++++++++++++++++++ fscomm/fshost.h | 5 ++++ fscomm/preferences/accountdialog.cpp | 18 +++++--------- fscomm/preferences/prefaccounts.cpp | 1 - 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/fscomm/fshost.cpp b/fscomm/fshost.cpp index 63b8e04c58..d4a780c5cf 100644 --- a/fscomm/fshost.cpp +++ b/fscomm/fshost.cpp @@ -385,6 +385,7 @@ void FSHost::generalEventHandler(switch_event_t *event) } else if (strcmp(event->subclass_name, "sofia::gateway_del") == 0) { + qDebug() << "We are deleted..."; QSharedPointer acc = _accounts.take(switch_event_get_header_nil(event, "Gateway")); if (!acc.isNull()) emit delAccount(acc); @@ -400,6 +401,40 @@ void FSHost::generalEventHandler(switch_event_t *event) } } +void FSHost::accountReloadCmd(QSharedPointer acc) +{ + QString res; + QString arg = QString("profile softphone killgw %1").arg(acc.data()->getName()); + + connect(this, SIGNAL(delAccount(QSharedPointer)), this, SLOT(accountReloadSlot(QSharedPointer))); + + if (g_FSHost.sendCmd("sofia", arg.toAscii().data() , &res) != SWITCH_STATUS_SUCCESS) + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not killgw %s from profile softphone.\n", + acc.data()->getName().toAscii().data()); + } + _reloading_Accounts.append(acc.data()->getName()); + + qDebug() << "We are reloading..."; +} + +void FSHost::accountReloadSlot(QSharedPointer acc) +{ + if (_reloading_Accounts.contains(acc.data()->getName())) + { + _reloading_Accounts.takeAt(_reloading_Accounts.indexOf(acc.data()->getName(), 0)); + QString res; + if (g_FSHost.sendCmd("sofia", "profile softphone rescan", &res) != SWITCH_STATUS_SUCCESS) + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not rescan the softphone profile.\n"); + return; + } + if (_reloading_Accounts.isEmpty()) + disconnect(this, SLOT(accountReloadSlot(QSharedPointer))); + qDebug() << "We are rescanning..."; + } +} + switch_status_t FSHost::sendCmd(const char *cmd, const char *args, QString *res) { switch_status_t status = SWITCH_STATUS_FALSE; diff --git a/fscomm/fshost.h b/fscomm/fshost.h index 74e215197b..dc543947cf 100644 --- a/fscomm/fshost.h +++ b/fscomm/fshost.h @@ -47,6 +47,7 @@ public: QSharedPointer getCurrentActiveCall(); QList > getAccounts() { return _accounts.values(); } QSharedPointer getAccountByUUID(QString uuid); + void accountReloadCmd(QSharedPointer acc); protected: void run(void); @@ -63,6 +64,9 @@ signals: void newAccount(QSharedPointer); void delAccount(QSharedPointer); +private slots: + void accountReloadSlot(QSharedPointer); + private: switch_status_t processBlegEvent(switch_event_t *, QString); switch_status_t processAlegEvent(switch_event_t *, QString); @@ -71,6 +75,7 @@ private: QHash > _active_calls; QHash > _accounts; QHash _bleg_uuids; + QList _reloading_Accounts; }; extern FSHost g_FSHost; diff --git a/fscomm/preferences/accountdialog.cpp b/fscomm/preferences/accountdialog.cpp index 44cfb08143..1d0783881a 100644 --- a/fscomm/preferences/accountdialog.cpp +++ b/fscomm/preferences/accountdialog.cpp @@ -108,21 +108,15 @@ void AccountDialog::readConfig() void AccountDialog::writeConfig() { + QSharedPointer acc = g_FSHost.getAccountByUUID(_accId); + if (!acc.isNull()) + { + g_FSHost.accountReloadCmd(acc); + } + _settings->beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways"); _settings->beginGroup(_accId); - - if (!g_FSHost.getAccountByUUID(_accId).isNull()) - { - QString res; - QString arg = QString("profile softphone killgw %1").arg(g_FSHost.getAccountByUUID(_accId).data()->getName()); - - if (g_FSHost.sendCmd("sofia", arg.toAscii().data() , &res) != SWITCH_STATUS_SUCCESS) - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not killgw %s from profile softphone.\n", - g_FSHost.getAccountByUUID(_accId).data()->getName().toAscii().data()); - } - } _settings->beginGroup("gateway/attrs"); _settings->setValue("name", ui->sofiaGwNameEdit->text()); diff --git a/fscomm/preferences/prefaccounts.cpp b/fscomm/preferences/prefaccounts.cpp index c551a11f6b..7374715a62 100644 --- a/fscomm/preferences/prefaccounts.cpp +++ b/fscomm/preferences/prefaccounts.cpp @@ -149,7 +149,6 @@ void PrefAccounts::readConfig(bool reload) if (reload) { QString res; - _settings->sync(); if (g_FSHost.sendCmd("sofia", "profile softphone rescan", &res) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not rescan the softphone profile.\n");