diff --git a/sdk/include/opentelemetry/sdk/event/dispatcher.h b/sdk/include/opentelemetry/sdk/event/dispatcher.h index c9c4fa6d30..5b98f708ea 100644 --- a/sdk/include/opentelemetry/sdk/event/dispatcher.h +++ b/sdk/include/opentelemetry/sdk/event/dispatcher.h @@ -20,17 +20,6 @@ class Dispatcher public: virtual ~Dispatcher() = default; - /** - * Create an event that triggers when a file descriptor becomes readable or writable. - * @param file_descriptor the file descriptor to monitor - * @param callback the callback to call when event triggers - * @param events the events to monitor - * @return a handle for the event - */ - virtual std::unique_ptr CreateFileEvent(FileDescriptor file_descriptor, - FileReadyCallback callback, - uint32_t events) noexcept = 0; - /** * Create a timer event. * @callback the callback to call when the event triggers diff --git a/sdk/include/opentelemetry/sdk/event/io_dispatcher.h b/sdk/include/opentelemetry/sdk/event/io_dispatcher.h new file mode 100644 index 0000000000..3ccb73c580 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/event/io_dispatcher.h @@ -0,0 +1,26 @@ +#pragma once + +#include "opentelemetry/sdk/event/dispatcher.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace event +{ +class IoDispatcher : public Dispatcher +{ +public: + /** + * Create an event that triggers when a file descriptor becomes readable or writable. + * @param file_descriptor the file descriptor to monitor + * @param callback the callback to call when event triggers + * @param events the events to monitor + * @return a handle for the event + */ + virtual std::unique_ptr CreateFileEvent(FileDescriptor file_descriptor, + FileReadyCallback callback, + uint32_t events) noexcept = 0; +}; +} // namespace event +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/event/libevent/dispatcher.cc b/sdk/src/event/libevent/io_dispatcher.cc similarity index 54% rename from sdk/src/event/libevent/dispatcher.cc rename to sdk/src/event/libevent/io_dispatcher.cc index 5c11c18fcd..1a3baa3db3 100644 --- a/sdk/src/event/libevent/dispatcher.cc +++ b/sdk/src/event/libevent/io_dispatcher.cc @@ -1,4 +1,4 @@ -#include "src/event/libevent/dispatcher.h" +#include "src/event/libevent/io_dispatcher.h" #include "src/event/libevent/file_event.h" #include "src/event/libevent/timer.h" @@ -11,25 +11,25 @@ namespace event { namespace libevent { -std::unique_ptr Dispatcher::CreateFileEvent(FileDescriptor file_descriptor, - FileReadyCallback callback, - uint32_t events) noexcept +std::unique_ptr IoDispatcher::CreateFileEvent(FileDescriptor file_descriptor, + FileReadyCallback callback, + uint32_t events) noexcept { return std::unique_ptr{ new (std::nothrow) FileEvent{event_base_, file_descriptor, events, callback}}; } -std::unique_ptr Dispatcher::CreateTimer(TimerCallback callback) noexcept +std::unique_ptr IoDispatcher::CreateTimer(TimerCallback callback) noexcept { return std::unique_ptr{new (std::nothrow) Timer{event_base_, callback}}; } -void Dispatcher::Exit() noexcept +void IoDispatcher::Exit() noexcept { event_base_.LoopBreak(); } -void Dispatcher::Run() noexcept +void IoDispatcher::Run() noexcept { event_base_.Dispatch(); } diff --git a/sdk/src/event/libevent/dispatcher.h b/sdk/src/event/libevent/io_dispatcher.h similarity index 87% rename from sdk/src/event/libevent/dispatcher.h rename to sdk/src/event/libevent/io_dispatcher.h index b246c0c934..c20f636150 100644 --- a/sdk/src/event/libevent/dispatcher.h +++ b/sdk/src/event/libevent/io_dispatcher.h @@ -1,6 +1,6 @@ #pragma once -#include "opentelemetry/sdk/event/dispatcher.h" +#include "opentelemetry/sdk/event/io_dispatcher.h" #include "opentelemetry/version.h" #include "src/event/libevent/event_base.h" @@ -12,7 +12,7 @@ namespace event { namespace libevent { -class Dispatcher final : public event::Dispatcher +class IoDispatcher final : public event::IoDispatcher { public: // Dispatcher diff --git a/sdk/test/event/libevent/BUILD b/sdk/test/event/libevent/BUILD index 124de5dddd..048cef122e 100644 --- a/sdk/test/event/libevent/BUILD +++ b/sdk/test/event/libevent/BUILD @@ -1,7 +1,7 @@ cc_test( - name = "dispatcher_test", + name = "io_dispatcher_test", srcs = [ - "dispatcher_test.cc", + "io_dispatcher_test.cc", ], linkstatic = 1, deps = [ diff --git a/sdk/test/event/libevent/CMakeLists.txt b/sdk/test/event/libevent/CMakeLists.txt index 01c7ed9706..7f7add8d03 100644 --- a/sdk/test/event/libevent/CMakeLists.txt +++ b/sdk/test/event/libevent/CMakeLists.txt @@ -1,4 +1,4 @@ -foreach(testname dispatcher_test) +foreach(testname io_dispatcher_test) add_executable(${testname} "${testname}.cc") target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_event_libevent) diff --git a/sdk/test/event/libevent/dispatcher_test.cc b/sdk/test/event/libevent/io_dispatcher_test.cc similarity index 82% rename from sdk/test/event/libevent/dispatcher_test.cc rename to sdk/test/event/libevent/io_dispatcher_test.cc index e96370354a..f7b88c6e82 100644 --- a/sdk/test/event/libevent/dispatcher_test.cc +++ b/sdk/test/event/libevent/io_dispatcher_test.cc @@ -1,14 +1,14 @@ -#include "src/event/libevent/dispatcher.h" +#include "src/event/libevent/io_dispatcher.h" #include #include using opentelemetry::sdk::event::Timer; -using opentelemetry::sdk::event::libevent::Dispatcher; +using opentelemetry::sdk::event::libevent::IoDispatcher; TEST(DispatcherTest, Timer) { - Dispatcher dispatcher; + IoDispatcher dispatcher; std::chrono::steady_clock::time_point t1, t2; auto timer = dispatcher.CreateTimer([&] { t2 = std::chrono::steady_clock::now(); }); timer->EnableTimer(std::chrono::milliseconds{100}); @@ -21,7 +21,7 @@ TEST(DispatcherTest, Timer) TEST(DispatcherTest, Exit) { - Dispatcher dispatcher; + IoDispatcher dispatcher; std::unique_ptr timer; auto f = [&] { timer->EnableTimer(std::chrono::milliseconds{1});