mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
better handling of TCPSessionIO::connected
This commit is contained in:
@ -19,9 +19,9 @@ PhoneLineManagerImpl::PhoneLineManagerImpl()
|
||||
}
|
||||
|
||||
void
|
||||
PhoneLineManagerImpl::connect()
|
||||
PhoneLineManagerImpl::start()
|
||||
{
|
||||
//mSession.getEvents();
|
||||
mSession.getEvents();
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,7 +46,7 @@ signals:
|
||||
void selected(unsigned int);
|
||||
|
||||
public slots:
|
||||
void connect();
|
||||
void start();
|
||||
|
||||
void sendKey(Qt::Key c);
|
||||
|
||||
|
56
src/gui/official/SessionFactory.hpp
Normal file
56
src/gui/official/SessionFactory.hpp
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 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.
|
||||
*/
|
||||
|
||||
#ifndef __FACTORY_HPP__
|
||||
#define __FACTORY_HPP__
|
||||
|
||||
template< T >
|
||||
struct Creator
|
||||
{
|
||||
virtual T *create();
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class Factory
|
||||
{
|
||||
public:
|
||||
Factory();
|
||||
~Factory();
|
||||
|
||||
/**
|
||||
* This function will set the creator. The
|
||||
* Factory owns the creator instance.
|
||||
*/
|
||||
void setCreator(Creator< T > *creator);
|
||||
|
||||
/**
|
||||
* It ask the creator to create a SessionIO.
|
||||
* If there's no creator set, it will throw
|
||||
* a std::logic_error.
|
||||
*/
|
||||
T *create();
|
||||
|
||||
private:
|
||||
Creator< T > *mCreator;
|
||||
}
|
||||
|
||||
#include "Factory.inl"
|
||||
|
||||
#endif
|
@ -31,7 +31,7 @@
|
||||
class SessionIO : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
virtual ~SessionIO(){}
|
||||
|
||||
|
31
src/gui/official/SessionIOFactory.hpp
Normal file
31
src/gui/official/SessionIOFactory.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 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.
|
||||
*/
|
||||
|
||||
#ifndef __SESSIONIOFACTORY_HPP__
|
||||
#define __SESSIONIOFACTORY_HPP__
|
||||
|
||||
#include "utilspp/Singleton.hpp"
|
||||
#include "Factory.hpp"
|
||||
#include "SessionIO.hpp"
|
||||
|
||||
typedef utilspp::SingletonHolder< Factory< SessionIO > > SessionIOFactory;
|
||||
|
||||
#endif
|
||||
|
@ -33,6 +33,8 @@ TCPSessionIO::TCPSessionIO(const QString &hostname, quint16 port)
|
||||
this, SLOT(receive()));
|
||||
QObject::connect(mSocket, SIGNAL(connected()),
|
||||
this, SLOT(sendWaitingRequests()));
|
||||
QObject::connect(mSocket, SIGNAL(connected()),
|
||||
this, SIGNAL(connected()));
|
||||
QObject::connect(mSocket, SIGNAL(disconnected()),
|
||||
this, SLOT(askReconnect()));
|
||||
QObject::connect(mSocket, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||
@ -92,10 +94,6 @@ TCPSessionIO::sendWaitingRequests()
|
||||
stream << *mStack.begin();
|
||||
mStack.pop_front();
|
||||
}
|
||||
|
||||
if(mSocket->state() == QAbstractSocket::ConnectedState) {
|
||||
emit connected();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
87
src/gui/official/TCPSessionIO.hpp
Normal file
87
src/gui/official/TCPSessionIO.hpp
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 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.
|
||||
*/
|
||||
|
||||
#ifndef __TCPSESSIONIO_HPP__
|
||||
#define __TCPSESSIONIO_HPP__
|
||||
|
||||
#include <QMutex>
|
||||
#include <QString>
|
||||
#include <QTcpSocket>
|
||||
#include <QTextStream>
|
||||
#include <list>
|
||||
|
||||
#include "SessionIO.hpp"
|
||||
|
||||
|
||||
class TCPSessionIO : public SessionIO
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TCPSessionIO(const QString &hostname,
|
||||
quint16 port);
|
||||
|
||||
virtual ~TCPSessionIO();
|
||||
|
||||
signals:
|
||||
void connected();
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* This function send the request that we were
|
||||
* unable to send.
|
||||
*/
|
||||
void sendWaitingRequests();
|
||||
|
||||
/**
|
||||
* Those function are the actual function
|
||||
* that write to the socket.
|
||||
*/
|
||||
virtual void send(const QString &request);
|
||||
virtual void send(const std::string &request);
|
||||
|
||||
/**
|
||||
*/
|
||||
void askReconnect();
|
||||
|
||||
/**
|
||||
* This function is called when we have
|
||||
* incomming data on the socket.
|
||||
*/
|
||||
virtual void receive();
|
||||
|
||||
/**
|
||||
* Those function are the actual function
|
||||
* that read from the socket.
|
||||
*/
|
||||
virtual void receive(QString &answer);
|
||||
virtual void receive(std::string &answer);
|
||||
virtual void connect();
|
||||
|
||||
private:
|
||||
QTcpSocket *mSocket;
|
||||
QString mHostname;
|
||||
quint16 mPort;
|
||||
|
||||
QMutex mStackMutex;
|
||||
std::list< QString > mStack;
|
||||
};
|
||||
|
||||
#endif
|
@ -11,8 +11,8 @@ TCPSessionIO *
|
||||
TCPSessionIOCreator::create()
|
||||
{
|
||||
TCPSessionIO *t = new TCPSessionIO(mHostname, mPort);
|
||||
//QObject::connect(t, SIGNAL(connected()),
|
||||
// &PhoneLineManager::instance(), SLOT(connect()));
|
||||
QObject::connect(t, SIGNAL(connected()),
|
||||
&PhoneLineManager::instance(), SLOT(start()));
|
||||
t->connect();
|
||||
return t;
|
||||
}
|
||||
|
Reference in New Issue
Block a user