\r
class polling_filesystem_monitor : public filesystem_monitor\r
{\r
+ std::shared_ptr<boost::asio::io_service> scheduler_;\r
directory_monitor root_monitor_;\r
executor executor_;\r
- boost::asio::io_service& scheduler_;\r
boost::asio::deadline_timer timer_;\r
tbb::atomic<bool> running_;\r
int scan_interval_millis_;\r
filesystem_event events_of_interest_mask,\r
bool report_already_existing,\r
int scan_interval_millis,\r
- boost::asio::io_service& scheduler,\r
+ std::shared_ptr<boost::asio::io_service> scheduler,\r
const filesystem_monitor_handler& handler,\r
const initial_files_handler& initial_files_handler)\r
- : root_monitor_(\r
+ : scheduler_(std::move(scheduler))\r
+ , root_monitor_(\r
report_already_existing,\r
folder_to_watch,\r
events_of_interest_mask,\r
handler,\r
initial_files_handler)\r
, executor_(L"polling_filesystem_monitor")\r
- , scheduler_(scheduler)\r
- , timer_(scheduler)\r
+ , timer_(*scheduler_)\r
, scan_interval_millis_(scan_interval_millis)\r
{\r
running_ = true;\r
timer_.expires_from_now(\r
boost::posix_time::milliseconds(scan_interval_millis_));\r
timer_.async_wait([this](const boost::system::error_code& e)\r
+ {\r
+ begin_scan();\r
+ });\r
+ }\r
+\r
+ void begin_scan()\r
+ {\r
+ if (!running_)\r
+ return;\r
+\r
+ executor_.begin_invoke([this] ()\r
{\r
scan();\r
schedule_next();\r
\r
struct polling_filesystem_monitor_factory::implementation\r
{\r
- boost::asio::io_service& scheduler_;\r
+ std::shared_ptr<boost::asio::io_service> scheduler_;\r
int scan_interval_millis;\r
\r
implementation(\r
- boost::asio::io_service& scheduler, int scan_interval_millis)\r
- : scheduler_(scheduler), scan_interval_millis(scan_interval_millis)\r
+ std::shared_ptr<boost::asio::io_service> scheduler,\r
+ int scan_interval_millis)\r
+ : scheduler_(std::move(scheduler))\r
+ , scan_interval_millis(scan_interval_millis)\r
{\r
}\r
};\r
\r
polling_filesystem_monitor_factory::polling_filesystem_monitor_factory(\r
- boost::asio::io_service& scheduler,\r
+ std::shared_ptr<boost::asio::io_service> scheduler,\r
int scan_interval_millis)\r
- : impl_(new implementation(scheduler, scan_interval_millis))\r
+ : impl_(new implementation(std::move(scheduler), scan_interval_millis))\r
{\r
}\r
\r
* reaction time but causes more I/O.\r
*/\r
polling_filesystem_monitor_factory(\r
- boost::asio::io_service& scheduler,\r
+ std::shared_ptr<boost::asio::io_service> scheduler,\r
int scan_interval_millis = 5000);\r
virtual ~polling_filesystem_monitor_factory();\r
virtual filesystem_monitor::ptr create(\r
+++ /dev/null
-/*
-* Copyright 2013 Sveriges Television AB http://casparcg.com/
-*
-* This file is part of CasparCG (www.casparcg.com).
-*
-* CasparCG is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* CasparCG is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
-*
-* Author: Helge Norberg, helge.norberg@svt.se
-*/
-
-#include "../StdAfx.h"
-
-#include "io_service_manager.h"
-
-#include <memory>
-
-#include <boost/asio/io_service.hpp>
-#include <boost/thread/thread.hpp>
-
-#include <common/exception/win32_exception.h>
-
-namespace caspar { namespace protocol { namespace asio {
-
-struct io_service_manager::impl
-{
- boost::asio::io_service service_;
- // To keep the io_service::run() running although no pending async
- // operations are posted.
- std::unique_ptr<boost::asio::io_service::work> work_;
- boost::thread thread_;
-
- impl()
- : work_(new boost::asio::io_service::work(service_))
- , thread_([this] { run(); })
- {
- }
-
- void run()
- {
- win32_exception::ensure_handler_installed_for_thread("asio-thread");
-
- service_.run();
- }
-
- ~impl()
- {
- work_.reset();
- service_.stop();
- thread_.join();
- }
-};
-
-io_service_manager::io_service_manager()
- : impl_(new impl)
-{
-}
-
-io_service_manager::~io_service_manager()
-{
-}
-
-boost::asio::io_service& io_service_manager::service()
-{
- return impl_->service_;
-}
-
-}}}
+++ /dev/null
-/*
-* Copyright 2013 Sveriges Television AB http://casparcg.com/
-*
-* This file is part of CasparCG (www.casparcg.com).
-*
-* CasparCG is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* CasparCG is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
-*
-* Author: Helge Norberg, helge.norberg@svt.se
-*/
-
-#pragma once
-
-#include <memory>
-
-#include <boost/noncopyable.hpp>
-
-namespace boost { namespace asio {
- class io_service;
-}}
-
-namespace caspar { namespace protocol { namespace asio {
-
-class io_service_manager : boost::noncopyable
-{
-public:
- io_service_manager();
- ~io_service_manager();
- boost::asio::io_service& service();
-private:
- struct impl;
- std::unique_ptr<impl> impl_;
-};
-
-}}}
struct client::impl : public std::enable_shared_from_this<client::impl>, core::monitor::sink
{
+ std::shared_ptr<boost::asio::io_service> service_;
udp::socket socket_;
tbb::spin_mutex endpoints_mutex_;
std::map<udp::endpoint, int> reference_counts_by_endpoint_;
boost::thread thread_;
public:
- impl(boost::asio::io_service& service)
- : socket_(service, udp::v4())
+ impl(std::shared_ptr<boost::asio::io_service> service)
+ : service_(std::move(service))
+ , socket_(*service_, udp::v4())
, thread_(boost::bind(&impl::run, this))
{
}
}
};
-client::client(boost::asio::io_service& service)
- : impl_(new impl(service))
+client::client(std::shared_ptr<boost::asio::io_service> service)
+ : impl_(new impl(std::move(service)))
{
}
// Constructors
- client(boost::asio::io_service& service);
+ client(std::shared_ptr<boost::asio::io_service> service);
client(client&&);
<ClInclude Include="amcp\AMCPCommandQueue.h" />\r
<ClInclude Include="amcp\AMCPCommandsImpl.h" />\r
<ClInclude Include="amcp\AMCPProtocolStrategy.h" />\r
- <ClInclude Include="asio\io_service_manager.h" />\r
<ClInclude Include="cii\CIICommand.h" />\r
<ClInclude Include="cii\CIICommandsImpl.h" />\r
<ClInclude Include="cii\CIIProtocolStrategy.h" />\r
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
</ClCompile>\r
- <ClCompile Include="asio\io_service_manager.cpp">\r
- <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
- <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
- <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
- <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
- </ClCompile>\r
<ClCompile Include="cii\CIICommandsImpl.cpp">\r
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
<Filter Include="source\osc\oscpack">\r
<UniqueIdentifier>{6d9a82d4-6805-4de0-b400-6212fac06109}</UniqueIdentifier>\r
</Filter>\r
- <Filter Include="source\asio">\r
- <UniqueIdentifier>{9c3a5197-d725-475d-ad5c-6b120e08022f}</UniqueIdentifier>\r
- </Filter>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="amcp\AMCPCommand.h">\r
<ClInclude Include="osc\oscpack\OscOutboundPacketStream.h">\r
<Filter>source\osc\oscpack</Filter>\r
</ClInclude>\r
- <ClInclude Include="asio\io_service_manager.h">\r
- <Filter>source\asio</Filter>\r
- </ClInclude>\r
<ClInclude Include="osc\client.h">\r
<Filter>source\osc</Filter>\r
</ClInclude>\r
<ClCompile Include="osc\oscpack\OscOutboundPacketStream.cpp">\r
<Filter>source\osc\oscpack</Filter>\r
</ClCompile>\r
- <ClCompile Include="asio\io_service_manager.cpp">\r
- <Filter>source\asio</Filter>\r
- </ClCompile>\r
<ClCompile Include="osc\client.cpp">\r
<Filter>source\osc</Filter>\r
</ClCompile>\r
#include <protocol/util/AsyncEventServer.h>\r
#include <protocol/util/stateful_protocol_strategy_wrapper.h>\r
#include <protocol/osc/client.h>\r
-#include <protocol/asio/io_service_manager.h>\r
\r
#include <boost/algorithm/string.hpp>\r
#include <boost/lexical_cast.hpp>\r
#include <boost/foreach.hpp>\r
#include <boost/property_tree/ptree.hpp>\r
#include <boost/property_tree/xml_parser.hpp>\r
+#include <boost/asio.hpp>\r
\r
namespace caspar {\r
\r
using namespace core;\r
using namespace protocol;\r
\r
+std::shared_ptr<boost::asio::io_service> create_running_io_service()\r
+{\r
+ auto service = std::make_shared<boost::asio::io_service>();\r
+ // To keep the io_service::run() running although no pending async\r
+ // operations are posted.\r
+ auto work = std::make_shared<boost::asio::io_service::work>(*service);\r
+ auto thread = std::make_shared<boost::thread>([service]\r
+ {\r
+ win32_exception::ensure_handler_installed_for_thread("asio-thread");\r
+\r
+ service->run();\r
+ });\r
+\r
+ return std::shared_ptr<boost::asio::io_service>(\r
+ service.get(),\r
+ [service, work, thread] (void*) mutable\r
+ {\r
+ work.reset();\r
+ service->stop();\r
+ thread->join();\r
+ });\r
+}\r
+\r
struct server::implementation : boost::noncopyable\r
{\r
- protocol::asio::io_service_manager io_service_manager_;\r
+ std::shared_ptr<boost::asio::io_service> io_service_;\r
safe_ptr<core::monitor::subject> monitor_subject_;\r
boost::promise<bool>& shutdown_server_now_;\r
safe_ptr<ogl_device> ogl_;\r
std::shared_ptr<thumbnail_generator> thumbnail_generator_;\r
\r
implementation(boost::promise<bool>& shutdown_server_now)\r
- : shutdown_server_now_(shutdown_server_now)\r
+ : io_service_(create_running_io_service())\r
+ , shutdown_server_now_(shutdown_server_now)\r
, ogl_(ogl_device::create())\r
- , osc_client_(io_service_manager_.service())\r
+ , osc_client_(io_service_)\r
{\r
setup_audio(env::properties());\r
\r
}\r
\r
~implementation()\r
- { \r
+ {\r
thumbnail_generator_.reset();\r
primary_amcp_server_.reset();\r
async_servers_.clear();\r
auto scan_interval_millis = pt.get(L"configuration.thumbnails.scan-interval-millis", 5000);\r
\r
polling_filesystem_monitor_factory monitor_factory(\r
- io_service_manager_.service(),\r
- scan_interval_millis);\r
+ io_service_, scan_interval_millis);\r
thumbnail_generator_.reset(new thumbnail_generator(\r
monitor_factory, \r
env::media_folder(),\r