diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 213f90f..dda246f 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -13,12 +13,10 @@ add_subdirectory(classbrowser) add_subdirectory(problemreporter) add_subdirectory(execute) -macro_optional_find_package(Commoncpp) macro_optional_find_package(BoostLibraries) -if(COMMONCPP2_FOUND AND Boost_FOUND AND Boost_LIBS_FOUND) +if(Boost_FOUND AND Boost_LIBS_FOUND) macro_optional_add_subdirectory(teamwork) -endif(COMMONCPP2_FOUND AND Boost_FOUND AND Boost_LIBS_FOUND) -macro_log_feature( COMMONCPP2_FOUND "Common C++2" "Support for Teamwork plugin integration" "http://ftp.gnu.org/pub/gnu/commoncpp/" FALSE "1.5.9" "The commoncpp2 libraries are needed for the Teamwork plugin" ) +endif(Boost_FOUND AND Boost_LIBS_FOUND) macro_log_feature( Boost_LIBS_FOUND "Boost" "Support for Teamwork plugin integration" "http://www.boost.org/" FALSE "1.34.0" "The boost C++ libraries are needed for the Teamwork plugin" ) macro_optional_find_package(SvnCpp) diff --git a/plugins/teamwork/lib/network/CMakeLists.txt b/plugins/teamwork/lib/network/CMakeLists.txt index 7bf2939..7367018 100644 --- a/plugins/teamwork/lib/network/CMakeLists.txt +++ b/plugins/teamwork/lib/network/CMakeLists.txt @@ -5,7 +5,8 @@ PROJECT(network) include_directories( - ${COMMONCPP2_INCLUDE_DIRS} + ${QT_QTCORE_INCLUDE_DIR} + ${QT_QTNETWORK_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ) @@ -37,14 +38,20 @@ ADD_DEFINITIONS(-Wall -ftemplate-depth-50 -D_REENTRANT -fexceptions) ###### First Target ########## ADD_LIBRARY( network SHARED ${libfiles} ) -TARGET_LINK_LIBRARIES( network ${COMMONCPP2_LIBRARIES} ${Boost_LIBRARIES} pthread) +TARGET_LINK_LIBRARIES( network ${Boost_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY} pthread) INSTALL(TARGETS network DESTINATION ${LIB_INSTALL_DIR}) ###### Next Target ########## ADD_EXECUTABLE( kdevteamwork_server ${testfiles} ) -TARGET_LINK_LIBRARIES( kdevteamwork_server ${Boost_LIBRARIES} network ${COMMONCPP2_LIBRARIES} ${ZLIB_LIBRARIES} dl ) +TARGET_LINK_LIBRARIES( kdevteamwork_server + ${Boost_LIBRARIES} + ${QT_QTCORE_LIBRARY} + ${QT_QTNETWORK_LIBRARY} + ${ZLIB_LIBRARIES} + network + dl ) INSTALL(TARGETS kdevteamwork_server DESTINATION ${BIN_INSTALL_DIR}) diff --git a/plugins/teamwork/lib/network/basicserver.cpp b/plugins/teamwork/lib/network/basicserver.cpp index ba1f43a..ecc5061 100644 --- a/plugins/teamwork/lib/network/basicserver.cpp +++ b/plugins/teamwork/lib/network/basicserver.cpp @@ -31,13 +31,17 @@ typedef char StandardDataType; namespace Teamwork { -BasicTCPSocket::BasicTCPSocket( ost::InetAddress &ia, int port ) : ost::TCPSocket( ia, port ) {} - -bool BasicTCPSocket::onAccept( const ost::InetHostAddress &ia, ost::tpport_t port ) { - setCompletion( false ); - cout << "accepting from: " << ia.getHostname() << ":" << port << endl; +ServerThread::ServerThread( int socket, QObject* parent ) + : QThread( parent ), socketDescriptor(socket) { +} - return true; +void ServerThread::run() +{ + QTcpSocket socket; + if( !socket.setSocketDescriptor(socketDescriptor) ) { + emit error(socket.error()); + return; + } } /**The MessageType holds all information necessary to Identify a Message and build an Object from it. @@ -48,105 +52,97 @@ void BasicServer::buildSocket() { closeSocket(); failed_ = false; - try { - server_ = new BasicTCPSocket( addr, port_ ); - out() << "server is listening on " << addr << ":" << port_; - } catch ( ost::Socket * socket ) { + if( listen( QHostAddress( addr ), port ) ) { + out() << "server is listening on " << addr.toUtf8().data() << ":" << port; + } else { failed_ = true; - ost::tpport_t port; - int erro = socket->getErrorNumber(); - ost::InetAddress saddr = ( ost::InetAddress ) socket->getPeer( &port ); - err() << "socket error " << saddr.getHostname() << ":" << port << " = " << erro; - if ( erro == ost::Socket::errBindingFailed ) { + err() << "socket error " << addr.toUtf8().data() << ":" << port << " = " << errorString().toUtf8().data(); + if ( serverError() == QAbstractSocket::AddressInUseError ) { err() << "bind failed; port busy"; } else { err() << "client socket failed"; } - if ( server_ ) - delete server_; - server_ = 0; } } -void BasicServer::run() { - lockCountUp(); - out() << "server started"; - bool needMore = false; - while ( !exit_ ) { - lockCountDown(); ///leave room time other threads that try to lock this one - if ( server_ && server_->isPendingConnection( needMore ? 1 : SLEEPTIME ) ) { - lockCountUp(); - try { - ost::InetHostAddress next = server_->getRequest(); - if ( !allowIncoming_ ) { - out() << "refusing session for client " << next; - server_->reject(); - } else { - out() << "creating session for client " << next; - SessionPointer tcp = createSession( server_ ); - if ( tcp ) { - out() << "session created" ; - if ( !registerSession( tcp ) ) { - server_->reject(); - out() << "session rejected"; - } else { - tcp.unsafe() ->startSession(); - } - } else { - out() << "session was rejected"; - server_->reject(); - } - } - } catch ( ost::Socket * socket ) { - ost::tpport_t port; - int err = socket->getErrorNumber(); - ost::InetAddress saddr = ( ost::InetAddress ) socket->getPeer( &port ); - cerr << "socket error " << saddr.getHostname() << ":" << port << " = " << err << endl; - if ( err == ost::Socket::errBindingFailed ) - cerr << "bind failed; port busy" << endl; - else - cerr << "client socket failed" << endl; - } - } else { - sleep( 10 ); - lockCountUp(); - } - needMore = think(); - - if ( _Shared_count() == 1 && selfPointer_ ) { ///The server is only referenced by itself, so it may be deleted - out() << "server is closing because the external reference-count reached zero"; - exit_ = true; - } - } - closeSocket(); - - out() << "server exiting"; - stopRunning(); - exit(); -} +// void BasicServer::run() { +// lockCountUp(); +// out() << "server started"; +// bool needMore = false; +// while ( !exit_ ) { +// lockCountDown(); ///leave room time other threads that try to lock this one +// if ( server_ && server_->isPendingConnection( needMore ? 1 : SLEEPTIME ) ) { +// lockCountUp(); +// try { +// ost::InetHostAddress next = server_->getRequest(); +// if ( !allowIncoming_ ) { +// out() << "refusing session for client " << next; +// server_->reject(); +// } else { +// out() << "creating session for client " << next; +// SessionPointer tcp = createSession( server_ ); +// if ( tcp ) { +// out() << "session created" ; +// if ( !registerSession( tcp ) ) { +// server_->reject(); +// out() << "session rejected"; +// } else { +// tcp.unsafe() ->startSession(); +// } +// } else { +// out() << "session was rejected"; +// server_->reject(); +// } +// } +// } catch ( ost::Socket * socket ) { +// ost::tpport_t port; +// int err = socket->getErrorNumber(); +// ost::InetAddress saddr = ( ost::InetAddress ) socket->getPeer( &port ); +// cerr << "socket error " << saddr.getHostname() << ":" << port << " = " << err << endl; +// if ( err == ost::Socket::errBindingFailed ) +// cerr << "bind failed; port busy" << endl; +// else +// cerr << "client socket failed" << endl; +// } +// } else { +// sleep( 10 ); +// lockCountUp(); +// } +// needMore = think(); +// +// if ( _Shared_count() == 1 && selfPointer_ ) { ///The server is only referenced by itself, so it may be deleted +// out() << "server is closing because the external reference-count reached zero"; +// exit_ = true; +// } +// } +// closeSocket(); +// +// out() << "server exiting"; +// stopRunning(); +// exit(); +// } void BasicServer::allowIncoming( bool allow ) { if ( allow ) { out() << "incoming connections activated, opening socket"; - buildSocket(); +// buildSocket(); } else { out() << "incoming connections deactivated, closing socket"; - closeSocket(); +// closeSocket(); } allowIncoming_ = allow; } void BasicServer::closeSocket() { - if ( server_ ) - delete server_; - server_ = 0; + if ( isListening() ) + close(); } /**Should be overridden to create own types derived from BasicTCPSession, can return 0*/ -SessionPointer BasicServer::createSession( BasicTCPSocket* sock ) { - BasicTCPSession * s = new BasicTCPSession( *sock , new HandlerProxy( this ), messageTypes_, logger_, "incoming_" ); - return s; -} +// SessionPointer BasicServer::createSession( BasicTCPSocket* sock ) { +// BasicTCPSession * s = new BasicTCPSession( *sock , new HandlerProxy( this ), messageTypes_, logger_, "incoming_" ); +// return s; +// } bool BasicServer::handleMessage( MessagePointer msg ) throw() { messagesToHandle_ << msg; @@ -166,22 +162,22 @@ LoggerPrinter BasicServer::out( Logger::Level level ) { return l; } -void BasicServer::run(); +// void BasicServer::run(); -void BasicServer::initial() { - Thread::initial(); -} +// void BasicServer::initial() { +// Thread::initial(); +// } -bool BasicServer::think() { - //messagesToHandle_.clear(); - return false; -} +// bool BasicServer::think() { +// //messagesToHandle_.clear(); +// return false; +// } -void BasicServer::final( void ) { - stopRunning(); - lockCountDown(); - clearSelfPointer(); -} +// void BasicServer::final( void ) { +// stopRunning(); +// lockCountDown(); +// clearSelfPointer(); +// } bool BasicServer::registerSession( SessionPointer /*session*/ ) { return false; @@ -196,7 +192,7 @@ LoggerPointer& BasicServer::logger() { return logger_; } -BasicServer::BasicServer( const char* str, int port, MessageTypeSet& messageTypes, LoggerPointer logger, bool openServer ) : Thread( ), messageTypes_( messageTypes ), logger_( logger ), failed_( false ), exit_( false ), allowIncoming_( openServer ), server_( 0 ), port_( port ), selfPointer_( this ) { +BasicServer::BasicServer( const QString& str, quint16 p, MessageTypeSet& messageTypes, LoggerPointer logger, bool openServer, QObject* parent ) : QTcpServer( parent ), messageTypes_( messageTypes ), logger_( logger ), failed_( false ), exit_( false ), allowIncoming_( openServer ), port( p ), selfPointer_( this ) { addr = str; if( allowIncoming_ ) diff --git a/plugins/teamwork/lib/network/basicserver.h b/plugins/teamwork/lib/network/basicserver.h index 2e0dd38..aa70a40 100644 --- a/plugins/teamwork/lib/network/basicserver.h +++ b/plugins/teamwork/lib/network/basicserver.h @@ -21,18 +21,24 @@ #include "logger.h" #include "networkexport.h" -#include +#include +#include +#include namespace Teamwork { template struct HandlerProxy; -class NETWORK_EXPORT BasicTCPSocket : public ost::TCPSocket { - protected: - bool onAccept( const ost::InetHostAddress &ia, ost::tpport_t port ); +class NETWORK_EXPORT ServerThread : public QThread { + Q_OBJECT public: - BasicTCPSocket( ost::InetAddress &ia, int port ); + ServerThread( int socketDescriptor, QObject* parent = 0 ); + void run(); + Q_SIGNALS: + void error( QTcpSocket::SocketError ); + private: + int socketDescriptor; }; /**This class runs the server as the run()-method is called in the same ost::Thread. @@ -40,9 +46,10 @@ This class never deletes itself, it can be deleted from outside once isRunning() For each client that connects, it creates a session derived from BasicSession, which can also be created by a derived class. */ -class NETWORK_EXPORT BasicServer : protected ost::Thread, public WeakSafeShared { +class NETWORK_EXPORT BasicServer : protected QTcpServer { + Q_OBJECT public: - BasicServer( const char* str, int port, MessageTypeSet& messageTypes, LoggerPointer logger, bool openServer = true ); + BasicServer( const QString& str, quint16 p, MessageTypeSet& messageTypes, LoggerPointer logger, bool openServer = true, QObject* parent = 0 ); virtual ~BasicServer(); @@ -55,14 +62,6 @@ class NETWORK_EXPORT BasicServer : protected ost::Thread, public WeakSafeShared once isRunning() returns false, it can be deleted.*/ void stopRunning(); - ///Returns whether the ost::Thread is running - using ost::Thread::isRunning; - - ///Starts the ost::Thread, should be called after the ost::Thread was constructed - using ost::Thread::start; - - using ost::Thread::join; - ///This can be used to allow/disallow incoming connections. Already connected clients are not kicked on deactivation. void allowIncoming( bool allow ); @@ -74,18 +73,8 @@ class NETWORK_EXPORT BasicServer : protected ost::Thread, public WeakSafeShared virtual LoggerPrinter err(); virtual LoggerPrinter out( Logger::Level level = Logger::Info ); - - virtual void run(); - - /**This is called once at the beginning of the ost::Thread*/ - virtual void initial(); - - /**Gets called regularly from within the server-ost::Thread - should be overridden, can return whether it needs more cpu-time*/ - virtual bool think(); - - /**This is called once at end of the ost::Thread*/ - virtual void final( void ); + + virtual void incomingConnection( int socketDescriptor ); /**In this function, the derived class should take the ownership of the session. If it refuses the ownership, it can return false. once it has the ownership, it also has to care about proper @@ -100,20 +89,18 @@ class NETWORK_EXPORT BasicServer : protected ost::Thread, public WeakSafeShared MessageTypeSet& messageTypes_; private: friend class HandlerProxy; - ost::BroadcastAddress addr; LoggerPointer logger_; + QString addr; + quint16 port; bool failed_, exit_, allowIncoming_; - BasicTCPSocket* server_; - int port_; SafeList messagesToHandle_; SafeSharedPtr< BasicServer > selfPointer_; void buildSocket(); - void closeSocket(); - + /**can be overridden to create own types derived from BasicTCPSession, can return 0(reject connection). Not called for forwarded sessions.*/ - virtual SessionPointer createSession( BasicTCPSocket* sock ); +// virtual SessionPointer createSession( BasicTCPSocket* sock ); }; } diff --git a/plugins/teamwork/lib/network/server.cpp b/plugins/teamwork/lib/network/server.cpp deleted file mode 100644 index d63b06a..0000000 --- a/plugins/teamwork/lib/network/server.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/*************************************************************************** - Copyright 2006 David Nolden -***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -#include "server.h" -#include "sharedptr.h" -#include -#include -#include -#include -#include -#include -#include "interfaces.h" -#include -#include "messagetypeset.h" -#include "messageimpl.h" -#include "helpers.h" -#include "basicsession.h" - - -#define SLEEPTIME 50 - -using namespace std; - -typedef char StandardDataType; - - -namespace Teamwork { - -BasicTCPSocket::BasicTCPSocket( InetAddress &ia, int port ) : TCPSocket( ia, port ) {} -; - -bool BasicTCPSocket::onAccept( const InetHostAddress &ia, tpport_t port ) { - setCompletion( false ); - cout << "accepting from: " << ia.getHostname() << ":" << port << endl; - - return true; -} - -/**The MessageType holds all information necessary to Identify a Message and build an Object from it. - The IdList is an inheritance-chain. Messages whose list begins with IDs of other Messages must be specializations of those, and the parent-types should be able to handle those too. -*/ - -void BasicServer::buildSocket() { - closeSocket(); - failed_ = false; - - try { - server_ = new BasicTCPSocket( addr, port_ ); - out() << "server is listening on " << addr << ":" << port_; - } catch ( Socket * socket ) { - failed_ = true; - tpport_t port; - int erro = socket->getErrorNumber(); - InetAddress saddr = ( InetAddress ) socket->getPeer( &port ); - err() << "socket error " << saddr.getHostname() << ":" << port << " = " << erro; - if ( erro == Socket::errBindingFailed ) { - err() << "bind failed; port busy"; - } else { - err() << "client socket failed"; - } - if ( server_ ) - delete server_; - server_ = 0; - } -} - -void BasicServer::run() { - lockCountUp(); - out() << "server started"; - bool needMore = false; - while ( !exit_ ) { - lockCountDown(); ///leave room time other threads that try to lock this one - if ( server_ && server_->isPendingConnection( needMore ? 1 : SLEEPTIME ) ) { - lockCountUp(); - try { - InetHostAddress next = server_->getRequest(); - if ( !allowIncoming_ ) { - out() << "refusing session for client " << next; - server_->reject(); - } else { - out() << "creating session for client " << next; - SessionPointer tcp = createSession( server_ ); - if ( tcp ) { - out() << "session created" ; - if ( !registerSession( tcp ) ) { - server_->reject(); - out() << "session rejected"; - } else { - tcp.unsafe() ->startSession(); - } - } else { - out() << "session was rejected"; - server_->reject(); - } - } - } catch ( Socket * socket ) { - tpport_t port; - int err = socket->getErrorNumber(); - InetAddress saddr = ( InetAddress ) socket->getPeer( &port ); - cerr << "socket error " << saddr.getHostname() << ":" << port << " = " << err << endl; - if ( err == Socket::errBindingFailed ) - cerr << "bind failed; port busy" << endl; - else - cerr << "client socket failed" << endl; - } - } else { - sleep( 10 ); - lockCountUp(); - } - needMore = think(); - - if ( _Shared_count() == 1 && selfPointer_ ) { ///The server is only referenced by itself, so it may be deleted - out() << "server is closing because the external reference-count reached zero"; - exit_ = true; - } - } - closeSocket(); - - out() << "server exiting"; - stopRunning(); - exit(); -} - -void BasicServer::allowIncoming( bool allow ) { - if ( allow ) { - out() << "incoming connections activated, opening socket"; - buildSocket(); - } else { - out() << "incoming connections deactivated, closing socket"; - closeSocket(); - } - allowIncoming_ = allow; -} - - void closeSocket() { - if( server_ ) delete server_; - server_ = 0; - } - - /**Should be overridden to create own types derived from BasicTCPSession, can return 0*/ - virtual SessionPointer createSession( BasicTCPSocket* sock ) { - BasicTCPSession* s = new BasicTCPSession( *sock , new HandlerProxy( this ), messageTypes_, logger_, "incoming_" ); - return s; - } -} - -// kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on - diff --git a/plugins/teamwork/lib/network/server.h b/plugins/teamwork/lib/network/server.h deleted file mode 100644 index 12cf309..0000000 --- a/plugins/teamwork/lib/network/server.h +++ /dev/null @@ -1,171 +0,0 @@ -/*************************************************************************** - Copyright 2006 David Nolden -***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -#ifndef TEAMWORK_SERVER_H -#define TEAMWORK_SERVER_H - -#include "networkfwd.h" -#include "basicsession.h" -#include "helpers.h" -#include "messagetypeset.h" -#include "safesharedptr.h" -#include "weaksafesharedptr.h" -#include "handler.h" - -namespace Teamwork { - - class BasicTCPSocket : public TCPSocket - { - protected: - bool onAccept(const InetHostAddress &ia, tpport_t port); - - public: - BasicTCPSocket(InetAddress &ia, int port); - }; - - /**This class runs the server as the run()-method is called in the same thread. - This class never deletes itself, it can be deleted from outside once isRunning() returns false or the threads are joined, or it can be deleted through a SharedPtr/SafeSharedPtr. - For each client that connects, it creates a session derived from BasicSession, which can also be - created by a derived class. - */ - class BasicServer : protected Thread, public WeakSafeShared - { - friend class HandlerProxy; - BroadcastAddress addr; - LoggerPointer logger_; - bool failed_, exit_, allowIncoming_; - BasicTCPSocket* server_; - MessageTypeSet& messageTypes_; - int port_; - SafeList messagesToHandle_; - SafeSharedPtr< BasicServer > selfPointer_; - - void buildSocket(); - - void closeSocket() { - if( server_ ) delete server_; - server_ = 0; - } - - /**Should be overridden to create own types derived from BasicTCPSession, can return 0*/ - virtual SessionPointer createSession( BasicTCPSocket* sock ) { - BasicTCPSession* s = new BasicTCPSession( *sock , new HandlerProxy( this ), messageTypes_, logger_, "incoming_" ); - return s; - } - - protected: - - ///this one is called from within another thread, so it is more useful to override processMessage(...) in the teamwork-server than this one - virtual bool handleMessage( MessagePointer msg ) throw() { - messagesToHandle_ << msg; - return true; - } - - - virtual LoggerPrinter err() { - LoggerPrinter l( logger_, Logger::Error ); - l << "server: "; - return l; - } - - virtual LoggerPrinter out( Logger::Level level = Logger::Info ) { - LoggerPrinter l( logger_, level ); - l << "server: "; - return l; - } - - virtual void run(); - - /**This is called once at the beginning of the thread*/ - virtual void initial() { - Thread::initial(); - } - - /**Gets called regularly from within the server-thread - should be overridden, can return whether it needs more cpu-time*/ - virtual bool think() { - //messagesToHandle_.clear(); - return false; - } - - /**This is called once at end of the thread*/ - virtual void final(void) { - stopRunning(); - lockCountDown(); - clearSelfPointer(); - } - - /**In this function, the derived class should take the ownership of the session. If it refuses the ownership, it can return false. - once it has the ownership, it also has to care about proper - Must be ovverridden. */ - virtual bool registerSession( SessionPointer /*session*/ ) { - return false; - } - - ///After this is called, the object may well be deleted - void clearSelfPointer() { - SafeSharedPtr s = selfPointer_; - selfPointer_ = 0; - } - - LoggerPointer& logger() { - return logger_; - } - - - public: - BasicServer( const char* str, int port, MessageTypeSet& messageTypes, LoggerPointer logger ) : Thread( ), logger_(logger), failed_( false ), exit_( false ), allowIncoming_( true ), server_(0), messageTypes_(messageTypes), port_( port ), selfPointer_( this ) - { - addr = "255.255.255.255"; -// out() << "testing addr: " << addr.getHostname() << ":" << port; - addr = str; -// out() << "binding for: " << addr.getHostname() << ":" << port; - - buildSocket(); - } - - virtual ~BasicServer() { - closeSocket(); - } - - virtual bool isOk() { - return !exit_ && !failed_; - } - - ///returns the reference to a synchronized list of messages that are waiting for being processed. Processed messages should be removed from that list. - SafeList& messages() { - return messagesToHandle_; - } - - /**After this function was called, the thread is going to exit soon. - once isRunning() returns false, it can be deleted.*/ - void stopRunning() { - exit_ = true; - } - - ///Returns whether the thread is running - using Thread::isRunning; - - ///Starts the thread, should be called after the thread was constructed - using Thread::start; - - using Thread::join; - - ///This can be used to allow/disallow incoming connections. Already connected clients are not kicked on deactivation. - void allowIncoming( bool allow ); - }; -} - -#endif - -// kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on diff --git a/plugins/teamwork/lib/network/teamworkclient.cpp b/plugins/teamwork/lib/network/teamworkclient.cpp index 341ac89..cf66bf5 100644 --- a/plugins/teamwork/lib/network/teamworkclient.cpp +++ b/plugins/teamwork/lib/network/teamworkclient.cpp @@ -49,26 +49,26 @@ void Client::disconnectedFromServer( const ClientSessionDesc& /*session*/, const } -bool Client::think() { - for ( ClientSessionMap::iterator it = clientSessions_.begin(); it != clientSessions_.end(); ) { - if ( !( *it ).second.session.unsafe() ->isRunning() ) { - out() << "closing outgoing session because it stopped running"; - disconnectedFromServer( ( *it ).second, ( *it ).first ); - ClientSessionMap::iterator itb = it; - ++it; - clientSessions_.erase( itb ); - } else { - if ( needUserUpdate_ ) { - send( ( *it ).second.session.unsafe(), SystemMessage::GetUserList ); - } - ++it; - } - } - - needUserUpdate_ = false; - - return Server::think(); -} +// bool Client::think() { +// for ( ClientSessionMap::iterator it = clientSessions_.begin(); it != clientSessions_.end(); ) { +// if ( !( *it ).second.session.unsafe() ->isRunning() ) { +// out() << "closing outgoing session because it stopped running"; +// disconnectedFromServer( ( *it ).second, ( *it ).first ); +// ClientSessionMap::iterator itb = it; +// ++it; +// clientSessions_.erase( itb ); +// } else { +// if ( needUserUpdate_ ) { +// send( ( *it ).second.session.unsafe(), SystemMessage::GetUserList ); +// } +// ++it; +// } +// } +// +// needUserUpdate_ = false; +// +// return Server::think(); +// } void Client::connectToServer( const ServerInformation& server, const UserPointer& asUser ) { if ( isConnectedToServer( server ) ) @@ -261,9 +261,9 @@ void Client::gotUserList( const std::list& /*users*/ ) { } ///this could be used to create a custom session deriven from MultiSession -SessionPointer Client::createSession( BasicTCPSocket* sock ) { - return Server::createSession( sock ); -} +// SessionPointer Client::createSession( BasicTCPSocket* sock ) { +// return Server::createSession( sock ); +// } bool Client::registerSession( SessionPointer session ) { if ( ! Server::registerSession( session ) ) diff --git a/plugins/teamwork/lib/network/teamworkclient.h b/plugins/teamwork/lib/network/teamworkclient.h index e6e3cdf..3d53316 100644 --- a/plugins/teamwork/lib/network/teamworkclient.h +++ b/plugins/teamwork/lib/network/teamworkclient.h @@ -53,13 +53,13 @@ class NETWORK_EXPORT Client : public Server { bool needUserUpdate_; protected: - virtual bool think(); +// virtual bool think(); ///Is called whenever a connected server sends its list of connected users virtual void gotUserList( const std::list& /*users*/ ); ///this could be used to create a custom session deriven from MultiSession - virtual SessionPointer createSession( BasicTCPSocket* sock ); +// virtual SessionPointer createSession( BasicTCPSocket* sock ); virtual bool registerSession( SessionPointer session ); diff --git a/plugins/teamwork/lib/network/teamworkserver.cpp b/plugins/teamwork/lib/network/teamworkserver.cpp index 4e1d387..df230a6 100644 --- a/plugins/teamwork/lib/network/teamworkserver.cpp +++ b/plugins/teamwork/lib/network/teamworkserver.cpp @@ -68,10 +68,10 @@ Server::~Server() { } } -SessionPointer Server::createSession( BasicTCPSocket* sock ) { - return new MultiSession( *sock, new HandlerProxy( this ), globalMessageTypeSet(), logger() ); - ///check yet whether this is thread-safe, if not give some kind of safe pointers -} +// SessionPointer Server::createSession( BasicTCPSocket* sock ) { +// return new MultiSession( *sock, new HandlerProxy( this ), globalMessageTypeSet(), logger() ); +// ///check yet whether this is thread-safe, if not give some kind of safe pointers +// } bool Server::registerSession( SessionPointer session ) { MultiSessionPointer s = session.cast(); @@ -99,9 +99,9 @@ void Server::sendUserLists() { } } -void Server::initial( void ) { - return BasicServer::initial(); -} +// void Server::initial( void ) { +// return BasicServer::initial(); +// } UserPointer Server::findUser( const UserPointer& user ) { UserSet::iterator it = users_.find( user ); @@ -119,58 +119,58 @@ UserPointer Server::findUser( const UserIdentity& user ) { return 0; } -bool Server::think() { - ///identify dead sessions and free pointers to them so they are deleted by reference-counting - for ( SessionSet::iterator it = unknownSessions_.begin(); it != unknownSessions_.end(); ) { - if ( !( *it ).unsafe() ->isRunning() ) { - out() << "deleting unknown incoming session"; - SessionSet::iterator itb = it; - ++it; - unknownSessions_.erase( itb ); - } else - ++it; - } - - for ( SessionMap::iterator it = sessions_.begin(); it != sessions_.end(); ) { - if ( !( *it ).first.unsafe() ->isRunning() ) { - SessionMap::iterator itb = it; - ++it; - UserPointer::Locked l = ( *itb ).second; - if ( l ) { - l->setSession( 0 ); - } else { - err() << "could not lock user-data, reference to session can not be cleared"; - } - - closeSession( ( *itb ).first ); - /*userDisconnected( (*itb).second ); - sessions_.erase( itb );*/ - out() << "deleting incoming session"; - } else - ++it; - } - - while ( !messages().empty() ) { - MessagePointer::Locked l = ( MessagePointer ) messages().front(); - if ( l ) { - processMessage( l.data() ); - } else { - out() << "a message from the incoming queue could not be locked"; - } - messages().pop_front(); - } - - if ( userListDirty_ ) { - sendUserLists(); - userListDirty_ = false; - } - - return BasicServer::think(); -} - -void Server::final( void ) { - return BasicServer::final(); -} +// bool Server::think() { +// ///identify dead sessions and free pointers to them so they are deleted by reference-counting +// for ( SessionSet::iterator it = unknownSessions_.begin(); it != unknownSessions_.end(); ) { +// if ( !( *it ).unsafe() ->isRunning() ) { +// out() << "deleting unknown incoming session"; +// SessionSet::iterator itb = it; +// ++it; +// unknownSessions_.erase( itb ); +// } else +// ++it; +// } +// +// for ( SessionMap::iterator it = sessions_.begin(); it != sessions_.end(); ) { +// if ( !( *it ).first.unsafe() ->isRunning() ) { +// SessionMap::iterator itb = it; +// ++it; +// UserPointer::Locked l = ( *itb ).second; +// if ( l ) { +// l->setSession( 0 ); +// } else { +// err() << "could not lock user-data, reference to session can not be cleared"; +// } +// +// closeSession( ( *itb ).first ); +// /*userDisconnected( (*itb).second ); +// sessions_.erase( itb );*/ +// out() << "deleting incoming session"; +// } else +// ++it; +// } +// +// while ( !messages().empty() ) { +// MessagePointer::Locked l = ( MessagePointer ) messages().front(); +// if ( l ) { +// processMessage( l.data() ); +// } else { +// out() << "a message from the incoming queue could not be locked"; +// } +// messages().pop_front(); +// } +// +// if ( userListDirty_ ) { +// sendUserLists(); +// userListDirty_ = false; +// } +// +// return BasicServer::think(); +// } + +// void Server::final( void ) { +// return BasicServer::final(); +// } void Server::closeAllIncomingSessions() { int c = 0; diff --git a/plugins/teamwork/lib/network/teamworkserver.h b/plugins/teamwork/lib/network/teamworkserver.h index 69716ac..f442256 100644 --- a/plugins/teamwork/lib/network/teamworkserver.h +++ b/plugins/teamwork/lib/network/teamworkserver.h @@ -112,18 +112,18 @@ class NETWORK_EXPORT Server : public BasicServer, public MessageSendHelper { protected: - virtual SessionPointer createSession( BasicTCPSocket* sock ); +// virtual SessionPointer createSession( BasicTCPSocket* sock ); virtual bool registerSession( SessionPointer session ); ///Internally maps the given user to his session. Fails if the user already has a session virtual bool registerSessionUser( const UserPointer& user ); - virtual void initial( void ); +// virtual void initial( void ); - virtual bool think(); +// virtual bool think(); - virtual void final( void ); +// virtual void final( void ); virtual void processMessage( MessageInterface* msg );