Diff
Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/servermanager.cpp (14677 => 14678)
--- freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/servermanager.cpp 2009-08-30 01:11:46 UTC (rev 14677)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/servermanager.cpp 2009-08-30 04:08:17 UTC (rev 14678)
@@ -29,15 +29,60 @@
delete m_ui;
}
-ESLconnection * ServerManager::getESLconnection()
+ESLconnection *ServerManager::getESLconnection(QString pluginName, QString name)
{
QTreeWidgetItem * item = m_ui->listServers->selectedItems().first();
- return new ESLconnection(item->data(0, ServerManager::Host).toByteArray(),
- item->data(0, ServerManager::Port).toByteArray(),
- item->data(0, ServerManager::Password).toByteArray(),
- item->data(0, ServerManager::Name).toByteArray());
+ if (name.isNull())
+ {
+ name = item->data(0, ServerManager::Name).toByteArray();
+ }
+
+ if(! _ESLpool.contains(name) )
+ {
+ _ESLpool.insert(name, new ESLconnection(item->data(0, ServerManager::Host).toByteArray(),
+ item->data(0, ServerManager::Port).toByteArray(),
+ item->data(0, ServerManager::Password).toByteArray(),
+ item->data(0, ServerManager::Name).toByteArray()));
+ if ( _ESLpoolCount.contains(name) )
+ qDebug() << "Something really bad happened here.";
+
+ QList<QString> pluginRefs;
+ pluginRefs.append(pluginName);
+ _ESLpoolCount.insert(name, pluginRefs);
+ }
+ else
+ {
+ if ( !_ESLpoolCount.contains(name) )
+ qDebug() << "Something really bad happened here.";
+
+ QList<QString> list = _ESLpoolCount.value(name);
+ list.append(pluginName);
+ }
+ return _ESLpool.value(name);
}
+void ServerManager::endESLconnection(QString pluginName, QString name)
+{
+ if ( _ESLpool.contains(name) )
+ {
+ QList<QString> pluginList = _ESLpoolCount.value(name);
+ for ( int i=0; i < pluginList.size(); i++)
+ {
+ if ( pluginList[i] == pluginName )
+ {
+ pluginList.removeAt(i);
+ break;
+ }
+ }
+
+ if ( _ESLpoolCount.value(name).count() == 0 )
+ {
+ delete _ESLpool.take(name);
+ _ESLpoolCount.remove(name);
+ }
+ }
+}
+
void ServerManager::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/servermanager.h (14677 => 14678)
--- freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/servermanager.h 2009-08-30 01:11:46 UTC (rev 14677)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/interfaces/servermanager.h 2009-08-30 04:08:17 UTC (rev 14678)
@@ -39,6 +39,9 @@
#define SERVERMANAGER_H
#include <QtGui/QDialog>
+#include <QSharedPointer>
+#include <QHash>
+#include <QList>
namespace Ui {
class ServerManager;
@@ -56,11 +59,20 @@
ServerManager(QWidget *parent = 0);
~ServerManager();
/*!
- \brief Gets a new ESLconnection object from the selected server entry
+ \brief Gets a new ESLconnection from pool
+ \param pluginName Name of the plugin that requests the connection
+ \param name Name of the connection to return. If NULL, new one from dialog is returned
\return The ESLconnection object
*/
- ESLconnection * getESLconnection();
+ ESLconnection *getESLconnection(QString pluginName, QString name = NULL);
+ /*!
+ \brief Tells ServerManager that we have finnished using a ESLconnection
+ \param pluginName Name of the plugin that ends the connection
+ \param name Name of the connection that the plugin is no longer using
+ */
+ void endESLconnection(QString pluginName, QString name);
+
protected:
/*!
\brief Used for changing translation on runtime
@@ -102,6 +114,11 @@
Name
};
+ /*! Holds all already initiated ESLconnections */
+ QHash <QString, ESLconnection *> _ESLpool;
+ /*! Holds ref cont for ESLconnections */
+ QHash <QString, QList<QString> > _ESLpoolCount;
+
/*!
\brief Read all servers and populate the interface
*/
Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.cpp (14677 => 14678)
--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.cpp 2009-08-30 01:11:46 UTC (rev 14677)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.cpp 2009-08-30 04:08:17 UTC (rev 14678)
@@ -134,16 +134,15 @@
{
if (serverManager->exec())
{
- ESLconnection *esl = serverManager->getESLconnection();
+ ESLconnection *esl = serverManager->getESLconnection(PLUGIN_NAME);
- if (hashESL.contains(esl->getName()))
+ if (esl)
{
for (int i = 0; i < consoleWindow->tabConsole->count(); i++)
{
if (consoleWindow->tabConsole->tabText(i) == esl->getName())
{
consoleWindow->tabConsole->setCurrentIndex(i);
- delete esl;
return;
}
}
@@ -152,7 +151,6 @@
ConsoleTabWidget *newTab = new ConsoleTabWidget(this, esl);
consoleWindow->tabConsole->addTab(newTab, esl->getName());
consoleWindow->tabConsole->setCurrentWidget(newTab);
- hashESL.insert(esl->getName(), esl);
QObject::connect(esl, SIGNAL(connected()),
this, SLOT(connectionStateChanged()));
QObject::connect(esl, SIGNAL(disconnected()),
@@ -423,14 +421,7 @@
void ConsolePlugin::tabClose(int index)
{
QWidget *tab = consoleWindow->tabConsole->widget(index);
- ESLconnection *esl = hashESL.value(consoleWindow->tabConsole->tabText(index), NULL);
- if (esl)
- {
- hashESL.remove(consoleWindow->tabConsole->tabText(index));
- esl->disconnect();
- esl->wait();
- delete esl;
- }
+ serverManager->endESLconnection(PLUGIN_NAME, consoleWindow->tabConsole->tabText(index));
consoleWindow->tabConsole->removeTab(index);
delete tab;
if (consoleWindow->tabConsole->count() == 0)
@@ -442,7 +433,7 @@
void ConsolePlugin::tabChanged(int index)
{
- ESLconnection *esl = hashESL.value(consoleWindow->tabConsole->tabText(index), NULL);
+ ESLconnection *esl = serverManager->getESLconnection(PLUGIN_NAME, consoleWindow->tabConsole->tabText(index));
if (esl)
{
consoleWindow->action_Connect->setDisabled(esl->isConnected());
@@ -452,7 +443,7 @@
void ConsolePlugin::connect()
{
- ESLconnection *esl = hashESL.value(consoleWindow->tabConsole->tabText(consoleWindow->tabConsole->currentIndex()), NULL);
+ ESLconnection *esl = serverManager->getESLconnection(PLUGIN_NAME, consoleWindow->tabConsole->tabText(consoleWindow->tabConsole->currentIndex()));
if (esl)
{
esl->connect();
@@ -461,7 +452,7 @@
void ConsolePlugin::disconnect()
{
- ESLconnection *esl = hashESL.value(consoleWindow->tabConsole->tabText(consoleWindow->tabConsole->currentIndex()), NULL);
+ ESLconnection *esl = serverManager->getESLconnection(PLUGIN_NAME, consoleWindow->tabConsole->tabText(consoleWindow->tabConsole->currentIndex()));
if (esl)
{
esl->disconnect();
Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.h (14677 => 14678)
--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.h 2009-08-30 01:11:46 UTC (rev 14677)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.h 2009-08-30 04:08:17 UTC (rev 14678)
@@ -44,6 +44,8 @@
#include "interfaces.h"
#include "ui_centralWidget.h"
+#define PLUGIN_NAME "Console"
+
namespace Ui
{
class configPage;
@@ -103,7 +105,6 @@
Ui::consoleWindow *consoleWindow;
Ui::configPage *consoleConfigPage;
ServerManager *serverManager;
- QHash<QString, ESLconnection *> hashESL;
SettingsDialog *settingsDialog;
void setPalette(QLineEdit *control, QString key);
Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.cpp (14677 => 14678)
--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.cpp 2009-08-30 01:11:46 UTC (rev 14677)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoletabwidget.cpp 2009-08-30 04:08:17 UTC (rev 14678)
@@ -75,8 +75,6 @@
ConsoleTabWidget::~ConsoleTabWidget()
{
- esl->disconnect();
- esl->wait();
writeSettings();
delete m_ui;
}