From fc3c50063f659584b2145addab8236a479a031b7 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 18 May 2009 19:53:51 +0200 Subject: Von sigc++ auf boost-signals migriert --- src/Net/ClientConnection.cpp | 4 ++-- src/Net/Connection.cpp | 18 +++++++++--------- src/Net/Connection.h | 18 +++++++++--------- src/Net/FdManager.cpp | 11 ++++------- src/Net/FdManager.h | 6 +++--- src/Net/Listener.cpp | 14 ++++++-------- src/Net/Listener.h | 8 ++++---- src/Net/Makefile.in | 4 ++-- src/Net/ServerConnection.cpp | 2 +- src/Net/ServerConnection.h | 2 +- src/Net/ThreadManager.cpp | 6 ++---- src/Net/ThreadManager.h | 6 +++--- 12 files changed, 46 insertions(+), 53 deletions(-) (limited to 'src/Net') diff --git a/src/Net/ClientConnection.cpp b/src/Net/ClientConnection.cpp index 688dbc7..087d95f 100644 --- a/src/Net/ClientConnection.cpp +++ b/src/Net/ClientConnection.cpp @@ -54,7 +54,7 @@ void ClientConnection::connectionHeader() { ConnectionHeader header = {'M', 'A', 'D', daemon ? 'D' : 'C', 0, 1, 1, 1}; rawSend((uint8_t*)&header, sizeof(header)); - rawReceive(sizeof(ConnectionHeader), sigc::mem_fun(this, &ClientConnection::connectionHeaderReceiveHandler)); + rawReceive(sizeof(ConnectionHeader), boost::bind(&ClientConnection::connectionHeaderReceiveHandler, this, _1, _2)); } void ClientConnection::connect(const IPAddress &address, bool daemon0) throw(Exception) { @@ -104,7 +104,7 @@ void ClientConnection::connect(const IPAddress &address, bool daemon0) throw(Exc gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred); gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t)sock); - FdManager::get()->registerFd(sock, sigc::mem_fun(this, &ClientConnection::sendReceive)); + FdManager::get()->registerFd(sock, boost::bind(&ClientConnection::sendReceive, this, _1)); state = CONNECT; diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp index cf675c9..4e5029f 100644 --- a/src/Net/Connection.cpp +++ b/src/Net/Connection.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include namespace Mad { namespace Net { @@ -125,12 +125,12 @@ void Connection::enterReceiveLoop() { return; if(_isConnecting()) - ThreadManager::get()->pushWork(sigc::mem_fun(connectedSignal, &sigc::signal::emit)); + ThreadManager::get()->pushWork(boost::bind((void (boost::signal0::*)())&boost::signal0::operator(), &connectedSignal)); state = PACKET_HEADER; lock.unlock(); - rawReceive(sizeof(Packet::Data), sigc::mem_fun(this, &Connection::packetHeaderReceiveHandler)); + rawReceive(sizeof(Packet::Data), boost::bind(&Connection::packetHeaderReceiveHandler, this, _1, _2)); } void Connection::packetHeaderReceiveHandler(const void *data, unsigned long length) { @@ -146,13 +146,13 @@ void Connection::packetHeaderReceiveHandler(const void *data, unsigned long leng header = *(const Packet::Data*)data; if(header.length == 0) { - ThreadManager::get()->pushWork(sigc::bind(sigc::mem_fun(receiveSignal, &sigc::signal::emit), Packet(ntohs(header.requestId)))); + ThreadManager::get()->pushWork(boost::bind((void (boost::signal1::*)(const Packet&))&boost::signal1::operator(), &receiveSignal, Packet(ntohs(header.requestId)))); enterReceiveLoop(); } else { state = PACKET_DATA; - rawReceive(ntohs(header.length), sigc::mem_fun(this, &Connection::packetDataReceiveHandler)); + rawReceive(ntohs(header.length), boost::bind(&Connection::packetDataReceiveHandler, this, _1, _2)); } } @@ -166,7 +166,7 @@ void Connection::packetDataReceiveHandler(const void *data, unsigned long length return; } - ThreadManager::get()->pushWork(sigc::bind(sigc::mem_fun(receiveSignal, &sigc::signal::emit), Packet(ntohs(header.requestId), data, length))); + ThreadManager::get()->pushWork(boost::bind((void (boost::signal1::*)(const Packet&))&boost::signal1::operator(), &receiveSignal, Packet(ntohs(header.requestId), data, length))); enterReceiveLoop(); } @@ -213,7 +213,7 @@ void Connection::doReceive() { } bool Connection::rawReceive(unsigned long length, - const sigc::slot ¬ify) + const boost::function2 ¬ify) { if(!isConnected()) return false; @@ -271,7 +271,7 @@ bool Connection::rawSend(const uint8_t *data, unsigned long length) { if(!isConnected()) return false; - Transmission trans = {length, 0, new uint8_t[length], sigc::slot()}; + Transmission trans = {length, 0, new uint8_t[length], boost::function2()}; std::memcpy(trans.data, data, length); sendLock.lock(); @@ -350,7 +350,7 @@ void Connection::doDisconnect() { gnutls_deinit(session); - ThreadManager::get()->pushWork(sigc::mem_fun(disconnectedSignal, &sigc::signal::emit)); + ThreadManager::get()->pushWork(boost::bind((void (boost::signal0::*)())&boost::signal0::operator(), &disconnectedSignal)); state = DISCONNECTED; } diff --git a/src/Net/Connection.h b/src/Net/Connection.h index 1a3e72b..a0b95ea 100644 --- a/src/Net/Connection.h +++ b/src/Net/Connection.h @@ -27,9 +27,9 @@ #include #include #include -#include #include +#include #include #include @@ -61,7 +61,7 @@ class Connection { uint8_t *data; - sigc::slot notify; + boost::function2 notify; }; boost::mutex receiveLock; @@ -72,9 +72,9 @@ class Connection { Packet::Data header; - sigc::signal receiveSignal; - sigc::signal connectedSignal; - sigc::signal disconnectedSignal; + boost::signal1 receiveSignal; + boost::signal0 connectedSignal; + boost::signal0 disconnectedSignal; void doHandshake(); @@ -129,7 +129,7 @@ class Connection { virtual void connectionHeader() = 0; - bool rawReceive(unsigned long length, const sigc::slot ¬ify); + bool rawReceive(unsigned long length, const boost::function2 ¬ify); bool rawSend(const uint8_t *data, unsigned long length); void enterReceiveLoop(); @@ -190,9 +190,9 @@ class Connection { bool send(const Packet &packet); - sigc::signal signalReceive() const {return receiveSignal;} - sigc::signal signalConnected() const {return connectedSignal;} - sigc::signal signalDisconnected() const {return disconnectedSignal;} + boost::signal1& signalReceive() {return receiveSignal;} + boost::signal0& signalConnected() {return connectedSignal;} + boost::signal0& signalDisconnected() {return disconnectedSignal;} }; } diff --git a/src/Net/FdManager.cpp b/src/Net/FdManager.cpp index c7abe73..d8faef4 100644 --- a/src/Net/FdManager.cpp +++ b/src/Net/FdManager.cpp @@ -24,9 +24,6 @@ #include #include -#include -#include - namespace Mad { namespace Net { @@ -43,7 +40,7 @@ FdManager::FdManager() : running(false) { flags = fcntl(interruptPipe[1], F_GETFL, 0); fcntl(interruptPipe[1], F_SETFL, flags | O_NONBLOCK); - registerFd(interruptPipe[0], sigc::hide(sigc::mem_fun(this, &FdManager::readInterrupt)), POLLIN); + registerFd(interruptPipe[0], boost::bind(&FdManager::readInterrupt, this), POLLIN); } FdManager::~FdManager() { @@ -54,7 +51,7 @@ FdManager::~FdManager() { } -bool FdManager::registerFd(int fd, const sigc::slot &handler, short events) { +bool FdManager::registerFd(int fd, const boost::function1 &handler, short events) { struct pollfd pollfd = {fd, events, 0}; boost::lock(handlerLock, eventLock); @@ -149,11 +146,11 @@ void FdManager::ioThread() { if(poll(fdarray, count, -1) > 0) { handlerLock.lock_shared(); - std::queue > calls; + std::queue > calls; for(size_t n = 0; n < count; ++n) { if(fdarray[n].revents) - calls.push(sigc::bind(handlers[fdarray[n].fd], fdarray[n].revents)); + calls.push(boost::bind(handlers[fdarray[n].fd], fdarray[n].revents)); } handlerLock.unlock_shared(); diff --git a/src/Net/FdManager.h b/src/Net/FdManager.h index 406110d..1cb95bc 100644 --- a/src/Net/FdManager.h +++ b/src/Net/FdManager.h @@ -22,8 +22,8 @@ #include #include -#include +#include #include namespace Mad { @@ -41,7 +41,7 @@ class FdManager { bool running; std::map pollfds; - std::map > handlers; + std::map > handlers; int interruptPipe[2]; @@ -64,7 +64,7 @@ class FdManager { static FdManager *get() {return &fdManager;} - bool registerFd(int fd, const sigc::slot &handler, short events = 0); + bool registerFd(int fd, const boost::function1 &handler, short events = 0); bool unregisterFd(int fd); bool setFdEvents(int fd, short events); diff --git a/src/Net/Listener.cpp b/src/Net/Listener.cpp index 5bcc353..11cbaf5 100644 --- a/src/Net/Listener.cpp +++ b/src/Net/Listener.cpp @@ -27,8 +27,6 @@ #include #include -#include - namespace Mad { namespace Net { @@ -40,8 +38,8 @@ void Listener::acceptHandler(int) { while((sd = accept(sock, (struct sockaddr*)&sa, &addrlen)) >= 0) { ServerConnection *con = new ServerConnection(sd, IPAddress(sa), dh_params, x905CertFile, x905KeyFile); - sigc::connection con1 = con->signalConnected().connect(sigc::bind(sigc::mem_fun(this, &Listener::connectHandler), con)); - sigc::connection con2 = con->signalDisconnected().connect(sigc::bind(sigc::mem_fun(this, &Listener::disconnectHandler), con)); + boost::signals::connection con1 = con->signalConnected().connect(boost::bind(&Listener::connectHandler, this, con)); + boost::signals::connection con2 = con->signalDisconnected().connect(boost::bind(&Listener::disconnectHandler, this, con)); connections.insert(std::make_pair(con, std::make_pair(con1, con2))); @@ -51,7 +49,7 @@ void Listener::acceptHandler(int) { void Listener::connectHandler(ServerConnection *con) { - std::map >::iterator it = connections.find(con); + std::map >::iterator it = connections.find(con); if(it == connections.end()) return; @@ -65,7 +63,7 @@ void Listener::connectHandler(ServerConnection *con) { } void Listener::disconnectHandler(ServerConnection *con) { - std::map >::iterator it = connections.find(con); + std::map >::iterator it = connections.find(con); if(it == connections.end()) return; @@ -112,11 +110,11 @@ Listener::Listener(const std::string &x905CertFile0, const std::string &x905KeyF throw Exception("listen()", Exception::INTERNAL_ERRNO, errno); } - FdManager::get()->registerFd(sock, sigc::mem_fun(this, &Listener::acceptHandler), POLLIN); + FdManager::get()->registerFd(sock, boost::bind(&Listener::acceptHandler, this, _1), POLLIN); } Listener::~Listener() { - for(std::map >::iterator con = connections.begin(); con != connections.end(); ++con) { + for(std::map >::iterator con = connections.begin(); con != connections.end(); ++con) { con->first->disconnect(); delete con->first; } diff --git a/src/Net/Listener.h b/src/Net/Listener.h index 3805403..26dffab 100644 --- a/src/Net/Listener.h +++ b/src/Net/Listener.h @@ -26,7 +26,7 @@ #include #include -#include +#include namespace Mad { namespace Net { @@ -42,9 +42,9 @@ class Listener { gnutls_dh_params_t dh_params; - std::map > connections; + std::map > connections; - sigc::signal signal; + boost::signal1 signal; void acceptHandler(int); @@ -59,7 +59,7 @@ class Listener { Listener(const std::string &x905CertFile0, const std::string &x905KeyFile0, const IPAddress &address0 = IPAddress()) throw(Exception); virtual ~Listener(); - sigc::signal signalNewConnection() const {return signal;} + boost::signal1& signalNewConnection() {return signal;} }; } diff --git a/src/Net/Makefile.in b/src/Net/Makefile.in index c51039d..36b924e 100644 --- a/src/Net/Makefile.in +++ b/src/Net/Makefile.in @@ -39,6 +39,7 @@ DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/argz.m4 \ $(top_srcdir)/m4/ax_boost_base.m4 \ + $(top_srcdir)/m4/ax_boost_signals.m4 \ $(top_srcdir)/m4/ax_boost_thread.m4 \ $(top_srcdir)/m4/ax_lib_mysql.m4 $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltdl.m4 $(top_srcdir)/m4/ltoptions.m4 \ @@ -88,6 +89,7 @@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BOOST_CPPFLAGS = @BOOST_CPPFLAGS@ BOOST_LDFLAGS = @BOOST_LDFLAGS@ +BOOST_SIGNALS_LIB = @BOOST_SIGNALS_LIB@ BOOST_THREAD_LIB = @BOOST_THREAD_LIB@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ @@ -219,8 +221,6 @@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ -sigc_CFLAGS = @sigc_CFLAGS@ -sigc_LIBS = @sigc_LIBS@ srcdir = @srcdir@ sys_symbol_underscore = @sys_symbol_underscore@ sysconfdir = @sysconfdir@ diff --git a/src/Net/ServerConnection.cpp b/src/Net/ServerConnection.cpp index c415cb3..1f01ce5 100644 --- a/src/Net/ServerConnection.cpp +++ b/src/Net/ServerConnection.cpp @@ -77,7 +77,7 @@ ServerConnection::ServerConnection(int sock0, const IPAddress &address, gnutls_d gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, x509_cred); gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t)sock); - FdManager::get()->registerFd(sock, sigc::mem_fun(this, &ServerConnection::sendReceive)); + FdManager::get()->registerFd(sock, boost::bind(&ServerConnection::sendReceive, this, _1)); state = CONNECT; diff --git a/src/Net/ServerConnection.h b/src/Net/ServerConnection.h index 0870143..d52cd7c 100644 --- a/src/Net/ServerConnection.h +++ b/src/Net/ServerConnection.h @@ -44,7 +44,7 @@ class ServerConnection : public Connection { ServerConnection(int sock0, const IPAddress &address, gnutls_dh_params_t dh_params, const std::string &x905certFile, const std::string &x905keyFile); virtual void connectionHeader() { - rawReceive(sizeof(ConnectionHeader), sigc::mem_fun(this, &ServerConnection::connectionHeaderReceiveHandler)); + rawReceive(sizeof(ConnectionHeader), boost::bind(&ServerConnection::connectionHeaderReceiveHandler, this, _1, _2)); } public: diff --git a/src/Net/ThreadManager.cpp b/src/Net/ThreadManager.cpp index b1f4d4b..71a754e 100644 --- a/src/Net/ThreadManager.cpp +++ b/src/Net/ThreadManager.cpp @@ -24,8 +24,6 @@ #include #include -#include -#include namespace Mad { namespace Net { @@ -50,7 +48,7 @@ void ThreadManager::workerFunc() { return; } - sigc::slot nextWork = work.front(); + boost::function0 nextWork = work.front(); work.pop(); lock2.unlock(); @@ -85,7 +83,7 @@ void ThreadManager::detach() { threadLock.unlock(); } -void ThreadManager::pushWork(const sigc::slot &newWork) { +void ThreadManager::pushWork(const boost::function0 &newWork) { workLock.lock(); work.push(newWork); workLock.unlock(); diff --git a/src/Net/ThreadManager.h b/src/Net/ThreadManager.h index 9394329..fd903af 100644 --- a/src/Net/ThreadManager.h +++ b/src/Net/ThreadManager.h @@ -26,8 +26,8 @@ #include #include -#include +#include #include #include #include @@ -48,7 +48,7 @@ class ThreadManager : public Common::Initializable { boost::mutex workLock; boost::condition_variable workCond; - std::queue > work; + std::queue > work; static ThreadManager threadManager; @@ -81,7 +81,7 @@ class ThreadManager : public Common::Initializable { void detach(); - void pushWork(const sigc::slot &newWork); + void pushWork(const boost::function0 &newWork); static ThreadManager* get() { return &threadManager; -- cgit v1.2.3