summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-14 19:33:05 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-14 19:33:05 (GMT)
commitd2625df30861a4caa984031a6990d19dfebc3367 (patch)
tree9f6b36168d2a417f0e4ef393b099428c2024223e /Swiften
parentee3a46975986865fe5064f9d87a27277fc6c235a (diff)
downloadswift-contrib-d2625df30861a4caa984031a6990d19dfebc3367.zip
swift-contrib-d2625df30861a4caa984031a6990d19dfebc3367.tar.bz2
Make all Connection instances shared_ptrs.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Client/Session.cpp2
-rw-r--r--Swiften/Client/Session.h2
-rw-r--r--Swiften/Client/UnitTest/SessionTest.cpp8
-rw-r--r--Swiften/Network/BoostConnectionFactory.cpp5
-rw-r--r--Swiften/Network/BoostConnectionFactory.h7
-rw-r--r--Swiften/Network/ConnectionFactory.h9
-rw-r--r--Swiften/QA/NetworkTest/BoostConnectionTest.cpp5
-rw-r--r--Swiften/Server/ServerFromClientSession.cpp2
-rw-r--r--Swiften/StreamStack/ConnectionLayer.h14
9 files changed, 24 insertions, 30 deletions
diff --git a/Swiften/Client/Session.cpp b/Swiften/Client/Session.cpp
index 1ae97d6..087880f 100644
--- a/Swiften/Client/Session.cpp
+++ b/Swiften/Client/Session.cpp
@@ -31,7 +31,6 @@ Session::Session(const JID& jid, ConnectionFactory* connectionFactory, TLSLayerF
payloadSerializers_(payloadSerializers),
state_(Initial),
error_(NoError),
- connection_(0),
xmppLayer_(0),
tlsLayer_(0),
connectionLayer_(0),
@@ -46,7 +45,6 @@ Session::~Session() {
delete connectionLayer_;
delete tlsLayer_;
delete xmppLayer_;
- delete connection_;
}
void Session::start() {
diff --git a/Swiften/Client/Session.h b/Swiften/Client/Session.h
index 516cb5a..72b57bd 100644
--- a/Swiften/Client/Session.h
+++ b/Swiften/Client/Session.h
@@ -112,7 +112,7 @@ namespace Swift {
PayloadSerializerCollection* payloadSerializers_;
State state_;
SessionError error_;
- Connection* connection_;
+ boost::shared_ptr<Connection> connection_;
XMPPLayer* xmppLayer_;
TLSLayer* tlsLayer_;
ConnectionLayer* connectionLayer_;
diff --git a/Swiften/Client/UnitTest/SessionTest.cpp b/Swiften/Client/UnitTest/SessionTest.cpp
index da05a06..f7f1db0 100644
--- a/Swiften/Client/UnitTest/SessionTest.cpp
+++ b/Swiften/Client/UnitTest/SessionTest.cpp
@@ -428,7 +428,7 @@ class SessionTest : public CppUnit::TestFixture {
private:
struct MockConnection;
- MockConnection* getMockServer() const {
+ boost::shared_ptr<MockConnection> getMockServer() const {
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connectionFactory_->connections_.size()));
return connectionFactory_->connections_[0];
}
@@ -689,15 +689,15 @@ class SessionTest : public CppUnit::TestFixture {
struct MockConnectionFactory : public ConnectionFactory {
MockConnectionFactory() : fail_(false) {}
- MockConnection* createConnection() {
- MockConnection* result = new MockConnection(fail_);
+ boost::shared_ptr<Connection> createConnection() {
+ boost::shared_ptr<MockConnection> result(new MockConnection(fail_));
connections_.push_back(result);
return result;
}
void setCreateFailingConnections() {
fail_ = true;
}
- std::vector<MockConnection*> connections_;
+ std::vector<boost::shared_ptr<MockConnection> > connections_;
bool fail_;
};
diff --git a/Swiften/Network/BoostConnectionFactory.cpp b/Swiften/Network/BoostConnectionFactory.cpp
index a1bef15..3f62730 100644
--- a/Swiften/Network/BoostConnectionFactory.cpp
+++ b/Swiften/Network/BoostConnectionFactory.cpp
@@ -1,12 +1,13 @@
#include "Swiften/Network/BoostConnectionFactory.h"
+#include "Swiften/Network/BoostConnection.h"
namespace Swift {
BoostConnectionFactory::BoostConnectionFactory(boost::asio::io_service* ioService) : ioService(ioService) {
}
-BoostConnection* BoostConnectionFactory::createConnection() {
- return new BoostConnection(ioService);
+boost::shared_ptr<Connection> BoostConnectionFactory::createConnection() {
+ return boost::shared_ptr<Connection>(new BoostConnection(ioService));
}
}
diff --git a/Swiften/Network/BoostConnectionFactory.h b/Swiften/Network/BoostConnectionFactory.h
index d15770d..5695c6c 100644
--- a/Swiften/Network/BoostConnectionFactory.h
+++ b/Swiften/Network/BoostConnectionFactory.h
@@ -1,5 +1,4 @@
-#ifndef SWIFTEN_BoostConnectionFactory_H
-#define SWIFTEN_BoostConnectionFactory_H
+#pragma once
#include <boost/asio.hpp>
@@ -13,11 +12,9 @@ namespace Swift {
public:
BoostConnectionFactory(boost::asio::io_service*);
- virtual BoostConnection* createConnection();
+ virtual boost::shared_ptr<Connection> createConnection();
private:
boost::asio::io_service* ioService;
};
}
-
-#endif
diff --git a/Swiften/Network/ConnectionFactory.h b/Swiften/Network/ConnectionFactory.h
index ef4eec9..e78f6ab 100644
--- a/Swiften/Network/ConnectionFactory.h
+++ b/Swiften/Network/ConnectionFactory.h
@@ -1,5 +1,6 @@
-#ifndef SWIFTEN_ConnectionFactory_H
-#define SWIFTEN_ConnectionFactory_H
+#pragma once
+
+#include <boost/shared_ptr.hpp>
namespace Swift {
class Connection;
@@ -8,8 +9,6 @@ namespace Swift {
public:
virtual ~ConnectionFactory();
- virtual Connection* createConnection() = 0;
+ virtual boost::shared_ptr<Connection> createConnection() = 0;
};
}
-
-#endif
diff --git a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
index 6090a97..d29739e 100644
--- a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
+++ b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
@@ -1,5 +1,6 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <boost/shared_ptr.hpp>
#include "Swiften/Base/String.h"
#include "Swiften/Base/sleep.h"
@@ -31,14 +32,14 @@ class BoostConnectionTest : public CppUnit::TestFixture {
void testDestructor() {
{
std::string domain("el-tramo.be");
- std::auto_ptr<BoostConnection> testling(new BoostConnection(&boostIOServiceThread_->getIOService()));
+ boost::shared_ptr<BoostConnection> testling(new BoostConnection(&boostIOServiceThread_->getIOService()));
testling->connect(domain);
}
}
void testDestructor_PendingEvents() {
{
- std::auto_ptr<BoostConnection> testling(new BoostConnection(&boostIOServiceThread_->getIOService()));
+ boost::shared_ptr<BoostConnection> testling(new BoostConnection(&boostIOServiceThread_->getIOService()));
testling->connect("el-tramo.be");
while (!eventLoop_->hasEvents()) {
Swift::sleep(10);
diff --git a/Swiften/Server/ServerFromClientSession.cpp b/Swiften/Server/ServerFromClientSession.cpp
index 612e667..6d4aba1 100644
--- a/Swiften/Server/ServerFromClientSession.cpp
+++ b/Swiften/Server/ServerFromClientSession.cpp
@@ -42,7 +42,7 @@ ServerFromClientSession::ServerFromClientSession(
boost::bind(boost::ref(onDataRead), _1));
xmppLayer_->onWriteData.connect(
boost::bind(boost::ref(onDataWritten), _1));
- connectionLayer_ = new ConnectionLayer(connection_.get());
+ connectionLayer_ = new ConnectionLayer(connection_);
streamStack_ = new StreamStack(xmppLayer_, connectionLayer_);
}
diff --git a/Swiften/StreamStack/ConnectionLayer.h b/Swiften/StreamStack/ConnectionLayer.h
index 99873a0..7688f78 100644
--- a/Swiften/StreamStack/ConnectionLayer.h
+++ b/Swiften/StreamStack/ConnectionLayer.h
@@ -1,7 +1,7 @@
-#ifndef SWIFTEN_CONNECTIONLAYER_H
-#define SWIFTEN_CONNECTIONLAYER_H
+#pragma once
#include <boost/signal.hpp>
+#include <boost/shared_ptr.hpp>
#include "Swiften/StreamStack/LowLayer.h"
#include "Swiften/Network/Connection.h"
@@ -9,17 +9,15 @@
namespace Swift {
class ConnectionLayer : public LowLayer {
public:
- ConnectionLayer(Connection* connection) : connection_(connection) {
- connection_->onDataRead.connect(onDataRead);
+ ConnectionLayer(boost::shared_ptr<Connection> connection) : connection(connection) {
+ connection->onDataRead.connect(onDataRead);
}
void writeData(const ByteArray& data) {
- connection_->write(data);
+ connection->write(data);
}
private:
- Connection* connection_;
+ boost::shared_ptr<Connection> connection;
};
}
-
-#endif