replaced plain pointers with smart pointers in various interfaces

This commit is contained in:
Guenter Obiltschnig 2009-03-24 10:40:58 +00:00
parent 37e6fa383a
commit a790bba33c
16 changed files with 60 additions and 70 deletions

View File

@ -1,7 +1,7 @@
//
// HTTPRequestHandlerFactory.h
//
// $Id: //poco/svn/Net/include/Poco/Net/HTTPRequestHandlerFactory.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/HTTPRequestHandlerFactory.h#4 $
//
// Library: Net
// Package: HTTPServer
@ -41,6 +41,7 @@
#include "Poco/Net/Net.h"
#include "Poco/SharedPtr.h"
namespace Poco {
@ -58,6 +59,8 @@ class Net_API HTTPRequestHandlerFactory
/// method.
{
public:
typedef Poco::SharedPtr<HTTPRequestHandlerFactory> Ptr;
HTTPRequestHandlerFactory();
/// Creates the HTTPRequestHandlerFactory.

View File

@ -1,7 +1,7 @@
//
// HTTPServer.h
//
// $Id: //poco/svn/Net/include/Poco/Net/HTTPServer.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/HTTPServer.h#3 $
//
// Library: Net
// Package: HTTPServer
@ -42,16 +42,14 @@
#include "Poco/Net/Net.h"
#include "Poco/Net/TCPServer.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerParams.h"
namespace Poco {
namespace Net {
class HTTPRequestHandlerFactory;
class HTTPServerParams;
class Net_API HTTPServer: public TCPServer
/// A subclass of TCPServer that implements a
/// full-featured multithreaded HTTP server.
@ -75,7 +73,7 @@ class Net_API HTTPServer: public TCPServer
/// information about the HTTP protocol.
{
public:
HTTPServer(HTTPRequestHandlerFactory* pFactory, const ServerSocket& socket, HTTPServerParams* pParams);
HTTPServer(HTTPRequestHandlerFactory::Ptr pFactory, const ServerSocket& socket, HTTPServerParams::Ptr pParams);
/// Creates the HTTPServer, using the given ServerSocket.
///
/// The server takes ownership of the HTTPRequstHandlerFactory
@ -85,7 +83,7 @@ public:
///
/// News threads are taken from the default thread pool.
HTTPServer(HTTPRequestHandlerFactory* pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, HTTPServerParams* pParams);
HTTPServer(HTTPRequestHandlerFactory::Ptr pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, HTTPServerParams::Ptr pParams);
/// Creates the HTTPServer, using the given ServerSocket.
///
/// The server takes ownership of the HTTPRequstHandlerFactory

View File

@ -1,7 +1,7 @@
//
// HTTPServerConnection.h
//
// $Id: //poco/svn/Net/include/Poco/Net/HTTPServerConnection.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/HTTPServerConnection.h#4 $
//
// Library: Net
// Package: HTTPServer
@ -43,14 +43,14 @@
#include "Poco/Net/Net.h"
#include "Poco/Net/TCPServerConnection.h"
#include "Poco/Net/HTTPResponse.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerParams.h"
namespace Poco {
namespace Net {
class HTTPServerParams;
class HTTPRequestHandlerFactory;
class HTTPServerSession;
@ -59,7 +59,7 @@ class Net_API HTTPServerConnection: public TCPServerConnection
/// connections.
{
public:
HTTPServerConnection(const StreamSocket& socket, HTTPServerParams* pParams, HTTPRequestHandlerFactory* pFactory);
HTTPServerConnection(const StreamSocket& socket, HTTPServerParams::Ptr pParams, HTTPRequestHandlerFactory::Ptr pFactory);
/// Creates the HTTPServerConnection.
virtual ~HTTPServerConnection();
@ -72,8 +72,8 @@ protected:
void sendErrorResponse(HTTPServerSession& session, HTTPResponse::HTTPStatus status);
private:
HTTPServerParams* _pParams;
HTTPRequestHandlerFactory* _pFactory;
HTTPServerParams::Ptr _pParams;
HTTPRequestHandlerFactory::Ptr _pFactory;
};

View File

@ -1,7 +1,7 @@
//
// HTTPServerConnectionFactory.h
//
// $Id: //poco/svn/Net/include/Poco/Net/HTTPServerConnectionFactory.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/HTTPServerConnectionFactory.h#3 $
//
// Library: Net
// Package: HTTPServer
@ -42,22 +42,20 @@
#include "Poco/Net/Net.h"
#include "Poco/Net/TCPServerConnectionFactory.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerParams.h"
namespace Poco {
namespace Net {
class HTTPServerParams;
class HTTPRequestHandlerFactory;
class Net_API HTTPServerConnectionFactory: public TCPServerConnectionFactory
/// This implementation of a TCPServerConnectionFactory
/// is used by HTTPServer to create HTTPServerConnection objects.
{
public:
HTTPServerConnectionFactory(HTTPServerParams* pParams, HTTPRequestHandlerFactory* pFactory);
HTTPServerConnectionFactory(HTTPServerParams::Ptr pParams, HTTPRequestHandlerFactory::Ptr pFactory);
/// Creates the HTTPServerConnectionFactory.
~HTTPServerConnectionFactory();
@ -68,8 +66,8 @@ public:
/// using the given StreamSocket.
private:
HTTPServerParams* _pParams;
HTTPRequestHandlerFactory* _pFactory;
HTTPServerParams::Ptr _pParams;
HTTPRequestHandlerFactory::Ptr _pFactory;
};

View File

@ -1,7 +1,7 @@
//
// HTTPServerParams.h
//
// $Id: //poco/svn/Net/include/Poco/Net/HTTPServerParams.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/HTTPServerParams.h#3 $
//
// Library: Net
// Package: HTTPServer
@ -55,6 +55,8 @@ class Net_API HTTPServerParams: public TCPServerParams
/// Subclasses may add new parameters to the class.
{
public:
typedef Poco::AutoPtr<HTTPServerParams> Ptr;
HTTPServerParams();
/// Creates the HTTPServerParams.
///

View File

@ -1,7 +1,7 @@
//
// NetworkInterface.h
//
// $Id: //poco/1.3/Net/include/Poco/Net/NetworkInterface.h#7 $
// $Id: //poco/Main/Net/include/Poco/Net/NetworkInterface.h#5 $
//
// Library: Net
// Package: Sockets

View File

@ -1,7 +1,7 @@
//
// TCPServer.h
//
// $Id: //poco/svn/Net/include/Poco/Net/TCPServer.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/TCPServer.h#4 $
//
// Library: Net
// Package: TCPServer
@ -42,6 +42,8 @@
#include "Poco/Net/Net.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Net/TCPServerConnectionFactory.h"
#include "Poco/Net/TCPServerParams.h"
#include "Poco/Runnable.h"
#include "Poco/Thread.h"
#include "Poco/ThreadPool.h"
@ -51,9 +53,7 @@ namespace Poco {
namespace Net {
class TCPServerParams;
class TCPServerDispatcher;
class TCPServerConnectionFactory;
class Net_API TCPServer: public Poco::Runnable
@ -98,7 +98,7 @@ class Net_API TCPServer: public Poco::Runnable
/// Already served connections, however, will continue being served.
{
public:
TCPServer(TCPServerConnectionFactory* pFactory, const ServerSocket& socket, TCPServerParams* pParams = 0);
TCPServer(TCPServerConnectionFactory::Ptr pFactory, const ServerSocket& socket, TCPServerParams::Ptr pParams = 0);
/// Creates the TCPServer, using the given ServerSocket.
///
/// The server takes ownership of the TCPServerConnectionFactory
@ -110,7 +110,7 @@ public:
///
/// News threads are taken from the default thread pool.
TCPServer(TCPServerConnectionFactory* pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, TCPServerParams* pParams = 0);
TCPServer(TCPServerConnectionFactory::Ptr pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, TCPServerParams::Ptr pParams = 0);
/// Creates the TCPServer, using the given ServerSocket.
///
/// The server takes ownership of the TCPServerConnectionFactory

View File

@ -1,7 +1,7 @@
//
// TCPServerConnectionFactory.h
//
// $Id: //poco/svn/Net/include/Poco/Net/TCPServerConnectionFactory.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/TCPServerConnectionFactory.h#3 $
//
// Library: Net
// Package: TCPServer
@ -42,6 +42,7 @@
#include "Poco/Net/Net.h"
#include "Poco/Net/TCPServerConnection.h"
#include "Poco/SharedPtr.h"
namespace Poco {
@ -64,6 +65,8 @@ class Net_API TCPServerConnectionFactory
/// of TCPServerConnection.
{
public:
typedef Poco::SharedPtr<TCPServerConnectionFactory> Ptr;
virtual ~TCPServerConnectionFactory();
/// Destroys the TCPServerConnectionFactory.

View File

@ -1,7 +1,7 @@
//
// TCPServerDispatcher.h
//
// $Id: //poco/svn/Net/include/Poco/Net/TCPServerDispatcher.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/TCPServerDispatcher.h#3 $
//
// Library: Net
// Package: TCPServer
@ -42,6 +42,8 @@
#include "Poco/Net/Net.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/TCPServerConnectionFactory.h"
#include "Poco/Net/TCPServerParams.h"
#include "Poco/Runnable.h"
#include "Poco/NotificationQueue.h"
#include "Poco/ThreadPool.h"
@ -52,16 +54,12 @@ namespace Poco {
namespace Net {
class TCPServerParams;
class TCPServerConnectionFactory;
class Net_API TCPServerDispatcher: public Poco::Runnable
/// A helper class for TCPServer that dispatches
/// connections to server connection threads.
{
public:
TCPServerDispatcher(TCPServerConnectionFactory* pFactory, Poco::ThreadPool& threadPool, TCPServerParams* pParams);
TCPServerDispatcher(TCPServerConnectionFactory::Ptr pFactory, Poco::ThreadPool& threadPool, TCPServerParams::Ptr pParams);
/// Creates the TCPServerDispatcher.
///
/// The dispatcher takes ownership of the TCPServerParams object.
@ -122,17 +120,17 @@ private:
TCPServerDispatcher& operator = (const TCPServerDispatcher&);
int _rc;
TCPServerParams* _pParams;
TCPServerParams::Ptr _pParams;
int _currentThreads;
int _totalConnections;
int _currentConnections;
int _maxConcurrentConnections;
int _refusedConnections;
bool _stopped;
Poco::NotificationQueue _queue;
TCPServerConnectionFactory* _pConnectionFactory;
Poco::ThreadPool& _threadPool;
mutable Poco::FastMutex _mutex;
Poco::NotificationQueue _queue;
TCPServerConnectionFactory::Ptr _pConnectionFactory;
Poco::ThreadPool& _threadPool;
mutable Poco::FastMutex _mutex;
};

View File

@ -1,7 +1,7 @@
//
// TCPServerParams.h
//
// $Id: //poco/svn/Net/include/Poco/Net/TCPServerParams.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/TCPServerParams.h#4 $
//
// Library: Net
// Package: TCPServer
@ -44,6 +44,7 @@
#include "Poco/RefCountedObject.h"
#include "Poco/Timespan.h"
#include "Poco/Thread.h"
#include "Poco/AutoPtr.h"
namespace Poco {
@ -57,6 +58,8 @@ class Net_API TCPServerParams: public Poco::RefCountedObject
/// Subclasses may add new parameters to the class.
{
public:
typedef Poco::AutoPtr<TCPServerParams> Ptr;
TCPServerParams();
/// Creates the TCPServerParams.
///

View File

@ -1,7 +1,7 @@
//
// HTTPServer.cpp
//
// $Id: //poco/svn/Net/src/HTTPServer.cpp#2 $
// $Id: //poco/Main/Net/src/HTTPServer.cpp#7 $
//
// Library: Net
// Package: HTTPServer
@ -35,7 +35,6 @@
#include "Poco/Net/HTTPServer.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/HTTPServerConnectionFactory.h"
@ -43,13 +42,13 @@ namespace Poco {
namespace Net {
HTTPServer::HTTPServer(HTTPRequestHandlerFactory* pFactory, const ServerSocket& socket, HTTPServerParams* pParams):
HTTPServer::HTTPServer(HTTPRequestHandlerFactory::Ptr pFactory, const ServerSocket& socket, HTTPServerParams::Ptr pParams):
TCPServer(new HTTPServerConnectionFactory(pParams, pFactory), socket, pParams)
{
}
HTTPServer::HTTPServer(HTTPRequestHandlerFactory* pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, HTTPServerParams* pParams):
HTTPServer::HTTPServer(HTTPRequestHandlerFactory::Ptr pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, HTTPServerParams::Ptr pParams):
TCPServer(new HTTPServerConnectionFactory(pParams, pFactory), threadPool, socket, pParams)
{
}

View File

@ -1,7 +1,7 @@
//
// HTTPServerConnection.cpp
//
// $Id: //poco/Main/Net/src/HTTPServerConnection.cpp#11 $
// $Id: //poco/Main/Net/src/HTTPServerConnection.cpp#12 $
//
// Library: Net
// Package: HTTPServer
@ -40,7 +40,6 @@
#include "Poco/Net/HTTPServerResponseImpl.h"
#include "Poco/Net/HTTPRequestHandler.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/NetException.h"
#include "Poco/NumberFormatter.h"
#include "Poco/Timestamp.h"
@ -51,21 +50,17 @@ namespace Poco {
namespace Net {
HTTPServerConnection::HTTPServerConnection(const StreamSocket& socket, HTTPServerParams* pParams, HTTPRequestHandlerFactory* pFactory):
HTTPServerConnection::HTTPServerConnection(const StreamSocket& socket, HTTPServerParams::Ptr pParams, HTTPRequestHandlerFactory::Ptr pFactory):
TCPServerConnection(socket),
_pParams(pParams),
_pFactory(pFactory)
{
poco_check_ptr (pFactory);
poco_check_ptr (pParams);
_pParams->duplicate();
}
HTTPServerConnection::~HTTPServerConnection()
{
_pParams->release();
}

View File

@ -1,7 +1,7 @@
//
// HTTPServerConnectionFactory.cpp
//
// $Id: //poco/svn/Net/src/HTTPServerConnectionFactory.cpp#2 $
// $Id: //poco/Main/Net/src/HTTPServerConnectionFactory.cpp#7 $
//
// Library: Net
// Package: HTTPServer
@ -36,7 +36,6 @@
#include "Poco/Net/HTTPServerConnectionFactory.h"
#include "Poco/Net/HTTPServerConnection.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
@ -44,21 +43,16 @@ namespace Poco {
namespace Net {
HTTPServerConnectionFactory::HTTPServerConnectionFactory(HTTPServerParams* pParams, HTTPRequestHandlerFactory* pFactory):
HTTPServerConnectionFactory::HTTPServerConnectionFactory(HTTPServerParams::Ptr pParams, HTTPRequestHandlerFactory::Ptr pFactory):
_pParams(pParams),
_pFactory(pFactory)
{
poco_check_ptr (pParams);
poco_check_ptr (pFactory);
_pParams->duplicate();
}
HTTPServerConnectionFactory::~HTTPServerConnectionFactory()
{
_pParams->release();
delete _pFactory;
}

View File

@ -1,7 +1,7 @@
//
// NetworkInterface.cpp
//
// $Id: //poco/1.3/Net/src/NetworkInterface.cpp#9 $
// $Id: //poco/Main/Net/src/NetworkInterface.cpp#23 $
//
// Library: Net
// Package: Sockets

View File

@ -1,7 +1,7 @@
//
// TCPServer.cpp
//
// $Id: //poco/svn/Net/src/TCPServer.cpp#3 $
// $Id: //poco/Main/Net/src/TCPServer.cpp#12 $
//
// Library: Net
// Package: TCPServer
@ -50,7 +50,7 @@ namespace Poco {
namespace Net {
TCPServer::TCPServer(TCPServerConnectionFactory* pFactory, const ServerSocket& socket, TCPServerParams* pParams):
TCPServer::TCPServer(TCPServerConnectionFactory::Ptr pFactory, const ServerSocket& socket, TCPServerParams::Ptr pParams):
_socket(socket),
_pDispatcher(new TCPServerDispatcher(pFactory, Poco::ThreadPool::defaultPool(), pParams)),
_thread(threadName(socket)),
@ -59,7 +59,7 @@ TCPServer::TCPServer(TCPServerConnectionFactory* pFactory, const ServerSocket& s
}
TCPServer::TCPServer(TCPServerConnectionFactory* pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, TCPServerParams* pParams):
TCPServer::TCPServer(TCPServerConnectionFactory::Ptr pFactory, Poco::ThreadPool& threadPool, const ServerSocket& socket, TCPServerParams::Ptr pParams):
_socket(socket),
_pDispatcher(new TCPServerDispatcher(pFactory, threadPool, pParams)),
_thread(threadName(socket)),

View File

@ -1,7 +1,7 @@
//
// TCPServerDispatcher.cpp
//
// $Id: //poco/svn/Net/src/TCPServerDispatcher.cpp#2 $
// $Id: //poco/Main/Net/src/TCPServerDispatcher.cpp#10 $
//
// Library: Net
// Package: TCPServer
@ -36,7 +36,6 @@
#include "Poco/Net/TCPServerDispatcher.h"
#include "Poco/Net/TCPServerConnectionFactory.h"
#include "Poco/Net/TCPServerParams.h"
#include "Poco/Notification.h"
#include "Poco/AutoPtr.h"
#include <memory>
@ -73,7 +72,7 @@ private:
};
TCPServerDispatcher::TCPServerDispatcher(TCPServerConnectionFactory* pFactory, Poco::ThreadPool& threadPool, TCPServerParams* pParams):
TCPServerDispatcher::TCPServerDispatcher(TCPServerConnectionFactory::Ptr pFactory, Poco::ThreadPool& threadPool, TCPServerParams::Ptr pParams):
_rc(1),
_pParams(pParams),
_currentThreads(0),
@ -97,8 +96,6 @@ TCPServerDispatcher::TCPServerDispatcher(TCPServerConnectionFactory* pFactory, P
TCPServerDispatcher::~TCPServerDispatcher()
{
_pParams->release();
delete _pConnectionFactory;
}