summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp2
-rw-r--r--Swiften/Examples/SendMessage/SendMessage.cpp2
-rw-r--r--Swiften/Network/BoostConnection.h9
-rw-r--r--Swiften/Network/BoostConnectionFactory.cpp2
-rw-r--r--Swiften/Network/BoostConnectionServer.cpp2
-rw-r--r--Swiften/Network/BoostConnectionServer.h9
-rw-r--r--Swiften/Network/BoostTimer.h8
-rw-r--r--Swiften/Network/BoostTimerFactory.cpp2
-rw-r--r--Swiften/Network/Timer.h2
-rw-r--r--Swiften/Network/TimerFactory.h6
-rw-r--r--Swiften/QA/ClientTest/ClientTest.cpp2
-rw-r--r--Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp12
-rw-r--r--Swiften/QA/NetworkTest/BoostConnectionTest.cpp6
-rw-r--r--Swiften/QA/ReconnectTest/ReconnectTest.cpp2
14 files changed, 44 insertions, 22 deletions
diff --git a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
index 5669be9..049802f 100644
--- a/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
+++ b/Swiften/Examples/ConnectivityTest/ConnectivityTest.cpp
@@ -84,7 +84,7 @@ int main(int argc, char* argv[]) {
}
{
- boost::shared_ptr<BoostTimer> timer(new BoostTimer(timeout, &MainBoostIOServiceThread::getInstance().getIOService()));
+ BoostTimer::ref timer(BoostTimer::create(timeout, &MainBoostIOServiceThread::getInstance().getIOService()));
timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
timer->start();
diff --git a/Swiften/Examples/SendMessage/SendMessage.cpp b/Swiften/Examples/SendMessage/SendMessage.cpp
index efc12f6..2ba5f3b 100644
--- a/Swiften/Examples/SendMessage/SendMessage.cpp
+++ b/Swiften/Examples/SendMessage/SendMessage.cpp
@@ -72,7 +72,7 @@ int main(int argc, char* argv[]) {
}
{
- boost::shared_ptr<BoostTimer> timer(new BoostTimer(30000, &MainBoostIOServiceThread::getInstance().getIOService()));
+ BoostTimer::ref timer(BoostTimer::create(30000, &MainBoostIOServiceThread::getInstance().getIOService()));
timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
timer->start();
diff --git a/Swiften/Network/BoostConnection.h b/Swiften/Network/BoostConnection.h
index abe7eeb..8d3d444 100644
--- a/Swiften/Network/BoostConnection.h
+++ b/Swiften/Network/BoostConnection.h
@@ -22,9 +22,14 @@ namespace boost {
namespace Swift {
class BoostConnection : public Connection, public EventOwner, public boost::enable_shared_from_this<BoostConnection> {
public:
- BoostConnection(boost::asio::io_service* ioService);
+ typedef boost::shared_ptr<BoostConnection> ref;
+
~BoostConnection();
+ static ref create(boost::asio::io_service* ioService) {
+ return ref(new BoostConnection(ioService));
+ }
+
virtual void listen();
virtual void connect(const HostAddressPort& address);
virtual void disconnect();
@@ -35,6 +40,8 @@ namespace Swift {
}
private:
+ BoostConnection(boost::asio::io_service* ioService);
+
void handleConnectFinished(const boost::system::error_code& error);
void handleSocketRead(const boost::system::error_code& error, size_t bytesTransferred);
void handleDataWritten(const boost::system::error_code& error);
diff --git a/Swiften/Network/BoostConnectionFactory.cpp b/Swiften/Network/BoostConnectionFactory.cpp
index f84a26e..7ba9f48 100644
--- a/Swiften/Network/BoostConnectionFactory.cpp
+++ b/Swiften/Network/BoostConnectionFactory.cpp
@@ -13,7 +13,7 @@ BoostConnectionFactory::BoostConnectionFactory(boost::asio::io_service* ioServic
}
boost::shared_ptr<Connection> BoostConnectionFactory::createConnection() {
- return boost::shared_ptr<Connection>(new BoostConnection(ioService));
+ return BoostConnection::create(ioService);
}
}
diff --git a/Swiften/Network/BoostConnectionServer.cpp b/Swiften/Network/BoostConnectionServer.cpp
index 51c1203..febe6c9 100644
--- a/Swiften/Network/BoostConnectionServer.cpp
+++ b/Swiften/Network/BoostConnectionServer.cpp
@@ -50,7 +50,7 @@ void BoostConnectionServer::stop(boost::optional<Error> e) {
}
void BoostConnectionServer::acceptNextConnection() {
- boost::shared_ptr<BoostConnection> newConnection(new BoostConnection(&acceptor_->io_service()));
+ BoostConnection::ref newConnection(BoostConnection::create(&acceptor_->io_service()));
acceptor_->async_accept(newConnection->getSocket(),
boost::bind(&BoostConnectionServer::handleAccept, shared_from_this(), newConnection, boost::asio::placeholders::error));
}
diff --git a/Swiften/Network/BoostConnectionServer.h b/Swiften/Network/BoostConnectionServer.h
index 311be4b..3a3c096 100644
--- a/Swiften/Network/BoostConnectionServer.h
+++ b/Swiften/Network/BoostConnectionServer.h
@@ -18,18 +18,25 @@
namespace Swift {
class BoostConnectionServer : public ConnectionServer, public EventOwner, public boost::enable_shared_from_this<BoostConnectionServer> {
public:
+ typedef boost::shared_ptr<BoostConnectionServer> ref;
+
enum Error {
Conflict,
UnknownError
};
- BoostConnectionServer(int port, boost::asio::io_service* ioService);
+ static ref create(int port, boost::asio::io_service* ioService) {
+ return ref(new BoostConnectionServer(port, ioService));
+ }
+
void start();
void stop();
boost::signal<void (boost::optional<Error>)> onStopped;
private:
+ BoostConnectionServer(int port, boost::asio::io_service* ioService);
+
void stop(boost::optional<Error> e);
void acceptNextConnection();
void handleAccept(boost::shared_ptr<BoostConnection> newConnection, const boost::system::error_code& error);
diff --git a/Swiften/Network/BoostTimer.h b/Swiften/Network/BoostTimer.h
index 85db864..f48cb36 100644
--- a/Swiften/Network/BoostTimer.h
+++ b/Swiften/Network/BoostTimer.h
@@ -16,12 +16,18 @@
namespace Swift {
class BoostTimer : public Timer, public EventOwner, public boost::enable_shared_from_this<BoostTimer> {
public:
- BoostTimer(int milliseconds, boost::asio::io_service* service);
+ typedef boost::shared_ptr<BoostTimer> ref;
+
+ static ref create(int milliseconds, boost::asio::io_service* service) {
+ return ref(new BoostTimer(milliseconds, service));
+ }
virtual void start();
virtual void stop();
private:
+ BoostTimer(int milliseconds, boost::asio::io_service* service);
+
void handleTimerTick(const boost::system::error_code& error);
private:
diff --git a/Swiften/Network/BoostTimerFactory.cpp b/Swiften/Network/BoostTimerFactory.cpp
index 7eec197..b22525c 100644
--- a/Swiften/Network/BoostTimerFactory.cpp
+++ b/Swiften/Network/BoostTimerFactory.cpp
@@ -13,7 +13,7 @@ BoostTimerFactory::BoostTimerFactory(boost::asio::io_service* ioService) : ioSer
}
boost::shared_ptr<Timer> BoostTimerFactory::createTimer(int milliseconds) {
- return boost::shared_ptr<Timer>(new BoostTimer(milliseconds, ioService));
+ return BoostTimer::create(milliseconds, ioService);
}
}
diff --git a/Swiften/Network/Timer.h b/Swiften/Network/Timer.h
index 873837d..278a8fb 100644
--- a/Swiften/Network/Timer.h
+++ b/Swiften/Network/Timer.h
@@ -11,6 +11,8 @@
namespace Swift {
class Timer {
public:
+ typedef boost::shared_ptr<Timer> ref;
+
virtual ~Timer();
virtual void start() = 0;
diff --git a/Swiften/Network/TimerFactory.h b/Swiften/Network/TimerFactory.h
index 558426c..44c87b6 100644
--- a/Swiften/Network/TimerFactory.h
+++ b/Swiften/Network/TimerFactory.h
@@ -8,13 +8,13 @@
#include <boost/shared_ptr.hpp>
-namespace Swift {
- class Timer;
+#include "Swiften/Network/Timer.h"
+namespace Swift {
class TimerFactory {
public:
virtual ~TimerFactory();
- virtual boost::shared_ptr<Timer> createTimer(int milliseconds) = 0;
+ virtual Timer::ref createTimer(int milliseconds) = 0;
};
}
diff --git a/Swiften/QA/ClientTest/ClientTest.cpp b/Swiften/QA/ClientTest/ClientTest.cpp
index cd95e70..872d6f2 100644
--- a/Swiften/QA/ClientTest/ClientTest.cpp
+++ b/Swiften/QA/ClientTest/ClientTest.cpp
@@ -61,7 +61,7 @@ int main(int, char**) {
client->connect();
{
- boost::shared_ptr<BoostTimer> timer(new BoostTimer(30000, &MainBoostIOServiceThread::getInstance().getIOService()));
+ boost::shared_ptr<BoostTimer> timer(BoostTimer::create(30000, &MainBoostIOServiceThread::getInstance().getIOService()));
timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
timer->start();
diff --git a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp
index cf3535a..543e085 100644
--- a/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp
+++ b/Swiften/QA/NetworkTest/BoostConnectionServerTest.cpp
@@ -39,15 +39,15 @@ class BoostConnectionServerTest : public CppUnit::TestFixture {
}
void testConstructor_TwoServersOnSamePort() {
- boost::shared_ptr<BoostConnectionServer> testling(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
- boost::shared_ptr<BoostConnectionServer> testling2(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
+ BoostConnectionServer::ref testling(BoostConnectionServer::create(9999, &boostIOServiceThread_->getIOService()));
+ BoostConnectionServer::ref testling2(BoostConnectionServer::create(9999, &boostIOServiceThread_->getIOService()));
}
void testStart_Conflict() {
- boost::shared_ptr<BoostConnectionServer> testling(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
+ BoostConnectionServer::ref testling(BoostConnectionServer::create(9999, &boostIOServiceThread_->getIOService()));
testling->start();
- boost::shared_ptr<BoostConnectionServer> testling2(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
+ BoostConnectionServer::ref testling2(BoostConnectionServer::create(9999, &boostIOServiceThread_->getIOService()));
testling2->onStopped.connect(
boost::bind(&BoostConnectionServerTest::handleStopped, this, _1));
@@ -55,12 +55,12 @@ class BoostConnectionServerTest : public CppUnit::TestFixture {
}
void testStop() {
- boost::shared_ptr<BoostConnectionServer> testling(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
+ BoostConnectionServer::ref testling(BoostConnectionServer::create(9999, &boostIOServiceThread_->getIOService()));
testling->start();
testling->stop();
- boost::shared_ptr<BoostConnectionServer> testling2(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
+ BoostConnectionServer::ref testling2(BoostConnectionServer::create(9999, &boostIOServiceThread_->getIOService()));
testling2->start();
testling2->stop();
diff --git a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
index 28c8608..913f7c0 100644
--- a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
+++ b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp
@@ -43,14 +43,14 @@ class BoostConnectionTest : public CppUnit::TestFixture {
void testDestructor() {
{
- boost::shared_ptr<BoostConnection> testling(new BoostConnection(&boostIOServiceThread_->getIOService()));
+ BoostConnection::ref testling(BoostConnection::create(&boostIOServiceThread_->getIOService()));
testling->connect(HostAddressPort(HostAddress(address, 4), 5222));
}
}
void testDestructor_PendingEvents() {
{
- boost::shared_ptr<BoostConnection> testling(new BoostConnection(&boostIOServiceThread_->getIOService()));
+ BoostConnection::ref testling(BoostConnection::create(&boostIOServiceThread_->getIOService()));
testling->connect(HostAddressPort(HostAddress(address, 4), 5222));
while (!eventLoop_->hasEvents()) {
Swift::sleep(10);
@@ -60,7 +60,7 @@ class BoostConnectionTest : public CppUnit::TestFixture {
}
void testWrite() {
- boost::shared_ptr<BoostConnection> testling(new BoostConnection(&boostIOServiceThread_->getIOService()));
+ BoostConnection::ref testling(BoostConnection::create(&boostIOServiceThread_->getIOService()));
testling->onConnectFinished.connect(boost::bind(&BoostConnectionTest::doWrite, this, testling.get()));
testling->onDataRead.connect(boost::bind(&BoostConnectionTest::handleDataRead, this, _1));
testling->onDisconnected.connect(boost::bind(&BoostConnectionTest::handleDisconnected, this));
diff --git a/Swiften/QA/ReconnectTest/ReconnectTest.cpp b/Swiften/QA/ReconnectTest/ReconnectTest.cpp
index f630dd8..24be849 100644
--- a/Swiften/QA/ReconnectTest/ReconnectTest.cpp
+++ b/Swiften/QA/ReconnectTest/ReconnectTest.cpp
@@ -43,7 +43,7 @@ void handleTick(boost::shared_ptr<BoostTimer> timer) {
int delay = 500;
// int delay = 0;
- boost::shared_ptr<BoostTimer> newTimer(new BoostTimer(delay, &MainBoostIOServiceThread::getInstance().getIOService()));
+ boost::shared_ptr<BoostTimer> newTimer(BoostTimer::create(delay, &MainBoostIOServiceThread::getInstance().getIOService()));
newTimer->onTick.connect(boost::bind(&handleTick, timer));
newTimer->start();
}