diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-13 10:56:55 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-14 09:16:50 +0000 |
commit | 6b228b92b44c473c773011cb043c10177b95bf66 (patch) | |
tree | 7759339e0877b2c052c7d5a4b086dc321eeab84c | |
parent | 0a53d3cc952885d03b7c643e1153370df5819891 (diff) |
Use SP typeddef to get the ensure coorrect shared_ptr in use.
6 files changed, 17 insertions, 14 deletions
diff --git a/filedistribution/src/apps/filedistributor/filedistributor.cpp b/filedistribution/src/apps/filedistributor/filedistributor.cpp index aadf5f8f4b0..7387d12245b 100644 --- a/filedistribution/src/apps/filedistributor/filedistributor.cpp +++ b/filedistribution/src/apps/filedistributor/filedistributor.cpp @@ -56,7 +56,7 @@ class FileDistributor : public config::IFetcherCallback<ZookeepersConfig>, const std::shared_ptr<FileDistributionModelImpl> _model; const std::shared_ptr<FileDistributorTrackerImpl> _tracker; const std::shared_ptr<FileDownloader> _downloader; - const std::shared_ptr<FileDownloaderManager> _manager; + const FileDownloaderManager::SP _manager; const FileDistributorRPC::SP _rpcHandler; const std::shared_ptr<StateServerImpl> _stateServer; @@ -96,7 +96,7 @@ class FileDistributor : public config::IFetcherCallback<ZookeepersConfig>, fileDistributorConfig.torrentport, boost::filesystem::path(fileDistributorConfig.filedbpath), exceptionRethrower))), - _manager(track(new FileDownloaderManager(_downloader, _model))), + _manager(track_boost(new FileDownloaderManager(_downloader, _model))), _rpcHandler(track_boost(new FileDistributorRPC(rpcConfig.connectionspec, _manager))), _stateServer(track(new StateServerImpl(fileDistributorConfig.stateport))), _downloaderEventLoopThread( ll::bind(&FileDownloader::runEventLoop, _downloader.get())), diff --git a/filedistribution/src/tests/rpc/testfileprovider.cpp b/filedistribution/src/tests/rpc/testfileprovider.cpp index 1291932c8a6..5c1dd0451ab 100644 --- a/filedistribution/src/tests/rpc/testfileprovider.cpp +++ b/filedistribution/src/tests/rpc/testfileprovider.cpp @@ -17,7 +17,7 @@ const std::string MockFileProvider::_queueForeverFileReference("queue-forever"); BOOST_AUTO_TEST_CASE(fileDistributionRPCTest) { const std::string spec("tcp/localhost:9111"); - std::shared_ptr<fd::MockFileProvider> provider(new fd::MockFileProvider()); + fd::FileProvider::SP provider(new fd::MockFileProvider()); fd::FileDistributorRPC::SP fileDistributorRPC(new fd::FileDistributorRPC(spec, provider)); fileDistributorRPC->start(); @@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE(fileDistributionRPCTest) { //must be run through valgrind BOOST_AUTO_TEST_CASE(require_that_queued_requests_does_not_leak_memory) { const std::string spec("tcp/localhost:9111"); - std::shared_ptr<MockFileProvider> provider(new MockFileProvider()); + fd::FileProvider::SP provider(new fd::MockFileProvider()); fd::FileDistributorRPC::SP fileDistributorRPC(new fd::FileDistributorRPC(spec, provider)); fileDistributorRPC->start(); @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(require_that_queued_requests_does_not_leak_memory) { request->GetParams()->AddString(MockFileProvider::_queueForeverFileReference.c_str()); target->InvokeVoid(request); - provider->_queueForeverBarrier.wait(); //the request has been enqueued. + static_cast<fd::MockFileProvider &>(*provider)._queueForeverBarrier.wait(); //the request has been enqueued. fileDistributorRPC.reset(); target->SubRef(); diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.h b/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.h index 18231698ef2..f6047f66b95 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.h +++ b/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.h @@ -42,6 +42,7 @@ class FileDownloaderManager : public FileProvider, void removePeerStatus(const std::string& fileReference); public: + using SP = boost::shared_ptr<FileDownloaderManager>; FileDownloaderManager(const FileDownloaderManager &) = delete; FileDownloaderManager & operator = (const FileDownloaderManager &) = delete; FileDownloaderManager(const std::shared_ptr<FileDownloader>&, diff --git a/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.cpp b/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.cpp index 1a3a6308523..e5941355c44 100644 --- a/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.cpp +++ b/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.cpp @@ -18,6 +18,8 @@ LOG_SETUP(".filedistributorrpc"); #include <vespa/filedistribution/model/filedbmodel.h> using filedistribution::FileDistributorRPC; +using filedistribution::FileProvider; + namespace ll = boost::lambda; namespace { @@ -68,14 +70,14 @@ class QueuedRequests { }; struct DownloadFailed { - filedistribution::FileProvider::FailedDownloadReason _reason; + FileProvider::FailedDownloadReason _reason; void operator()(FRT_RPCRequest& request) { LOG(info, "Download failed: '%d'", _reason); request.SetError(RPCErrorCodes::baseFileProviderErrorCode + _reason, "Download failed"); } - DownloadFailed(filedistribution::FileProvider::FailedDownloadReason reason) + DownloadFailed(FileProvider::FailedDownloadReason reason) :_reason(reason) {} }; @@ -122,7 +124,7 @@ public: } void downloadFailed(const std::string& fileReference, - filedistribution::FileProvider::FailedDownloadReason reason) { + FileProvider::FailedDownloadReason reason) { DownloadFailed handler(reason); returnAnswer(fileReference, handler); @@ -144,7 +146,7 @@ public: class FileDistributorRPC::Server : public FRT_Invokable { public: - std::shared_ptr<FileProvider> _fileProvider; + FileProvider::SP _fileProvider; std::unique_ptr<FRT_Supervisor> _supervisor; QueuedRequests _queuedRequests; @@ -157,7 +159,7 @@ class FileDistributorRPC::Server : public FRT_Invokable { Server(const Server &) = delete; Server & operator = (const Server &) = delete; - Server(int listen_port, const std::shared_ptr<FileProvider>& provider); + Server(int listen_port, const FileProvider::SP & provider); void start(const FileDistributorRPC::SP & parent); ~Server(); @@ -165,8 +167,7 @@ class FileDistributorRPC::Server : public FRT_Invokable { }; FileDistributorRPC:: -Server::Server(int listen_port, - const std::shared_ptr<filedistribution::FileProvider>& provider) +Server::Server(int listen_port, const FileProvider::SP & provider) :_fileProvider(provider), _supervisor(new FRT_Supervisor()) { @@ -248,7 +249,7 @@ FileDistributorRPC::Server::waitFor(FRT_RPCRequest* request) { } FileDistributorRPC::FileDistributorRPC(const std::string& connectionSpec, - const std::shared_ptr<filedistribution::FileProvider>& provider) + const FileProvider::SP & provider) :_server(new Server(get_port(connectionSpec), provider)) {} diff --git a/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.h b/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.h index c05991236aa..ee8f9ddef24 100644 --- a/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.h +++ b/filedistribution/src/vespa/filedistribution/rpc/filedistributorrpc.h @@ -15,7 +15,7 @@ public: using SP = boost::shared_ptr<FileDistributorRPC>; FileDistributorRPC(const FileDistributorRPC &) = delete; FileDistributorRPC & operator = (const FileDistributorRPC &) = delete; - FileDistributorRPC(const std::string& connectSpec, const std::shared_ptr<FileProvider>& provider); + FileDistributorRPC(const std::string& connectSpec, const FileProvider::SP & provider); void start(); diff --git a/filedistribution/src/vespa/filedistribution/rpc/fileprovider.h b/filedistribution/src/vespa/filedistribution/rpc/fileprovider.h index a95b50fc0f2..f8b3e1fcf1b 100644 --- a/filedistribution/src/vespa/filedistribution/rpc/fileprovider.h +++ b/filedistribution/src/vespa/filedistribution/rpc/fileprovider.h @@ -10,6 +10,7 @@ namespace filedistribution { class FileProvider { public: + using SP = boost::shared_ptr<FileProvider>; typedef boost::signals2::signal<void (const std::string& /* fileReference */, const boost::filesystem::path&)> DownloadCompletedSignal; |