Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
rnburn authored and Johannes Tax committed Jul 7, 2020
1 parent d76fd24 commit fda54ee
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 107 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ endif()

option(WITH_OTPROTOCOL
"Whether to include the OpenTelemetry Protocol in the SDK" OFF)
option(WITH_LIBEVENT
"Build SDK with libevent support" ON)
option(WITH_LIBEVENT "Build SDK with libevent support" ON)

set(WITH_PROTOBUF OFF)
if(WITH_OTPROTOCOL)
Expand Down
18 changes: 9 additions & 9 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ new_local_repository(

http_archive(
name = "bazel_skylib",
sha256 = "64ad2728ccdd2044216e4cec7815918b7bb3bb28c95b7e9d951f9d4eccb07625",
strip_prefix = "bazel-skylib-1.0.2",
urls = [
"https://github.com/bazelbuild/bazel-skylib/archive/1.0.2.zip",
],
sha256 = "64ad2728ccdd2044216e4cec7815918b7bb3bb28c95b7e9d951f9d4eccb07625",
strip_prefix = "bazel-skylib-1.0.2",
)

http_archive(
name = "rules_foreign_cc",
strip_prefix = "rules_foreign_cc-456425521973736ef346d93d3d6ba07d807047df",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/456425521973736ef346d93d3d6ba07d807047df.zip",
name = "rules_foreign_cc",
strip_prefix = "rules_foreign_cc-456425521973736ef346d93d3d6ba07d807047df",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/456425521973736ef346d93d3d6ba07d807047df.zip",
)

load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")
Expand All @@ -59,12 +59,12 @@ rules_foreign_cc_dependencies([

http_archive(
name = "com_github_libevent_libevent",
urls = [
"https://github.com/libevent/libevent/archive/release-2.1.8-stable.zip"
],
build_file = "//bazel:libevent.BUILD",
sha256 = "70158101eab7ed44fd9cc34e7f247b3cae91a8e4490745d9d6eb7edc184e4d96",
strip_prefix = "libevent-release-2.1.8-stable",
build_file = "//bazel:libevent.BUILD",
urls = [
"https://github.com/libevent/libevent/archive/release-2.1.8-stable.zip",
],
)

# GoogleTest framework.
Expand Down
4 changes: 2 additions & 2 deletions bazel/libevent.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")


filegroup(
name = "srcs",
srcs = glob(["**"]),
name = "srcs",
srcs = glob(["**"]),
)

cmake_external(
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules/FindLibevent.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# find LibEvent
# an event notification library (http://libevent.org/)
#
# Usage:
# Usage:
# LIBEVENT_INCLUDE_DIRS, where to find LibEvent headers
# LIBEVENT_LIBRARIES, LibEvent libraries
# Libevent_FOUND, If false, do not try to use libevent
Expand Down
5 changes: 3 additions & 2 deletions sdk/include/opentelemetry/sdk/common/file_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk {
namespace sdk
{
#ifdef _WIN32
using FileDescriptor = intptr_t;
#else
using FileDescriptor = int;
#endif
} // namespace sdk
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
15 changes: 9 additions & 6 deletions sdk/include/opentelemetry/sdk/event/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk {
namespace event {
namespace sdk
{
namespace event
{
/**
* Interface for managing asynchronous events.
*/
class Dispatcher {
public:
class Dispatcher
{
public:
virtual ~Dispatcher() = default;

/**
Expand Down Expand Up @@ -45,6 +48,6 @@ class Dispatcher {
*/
virtual void Run() noexcept = 0;
};
} // namespace event
} // namespace sdk
} // namespace event
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
20 changes: 11 additions & 9 deletions sdk/include/opentelemetry/sdk/event/file_event.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#pragma once

#include <chrono>
#include <system_error>
#include <cstdint>
#include <functional>
#include <system_error>

#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk {
namespace event {
namespace sdk
{
namespace event
{
/**
* Available events that can be monitored on a file descriptor.
*/
Expand All @@ -27,11 +29,11 @@ using FileReadyCallback = std::function<void(uint32_t)>;
*
* Note: Must be freed before the dipatcher is destructed
*/
class FileEvent {
public:
virtual ~FileEvent() = default;

class FileEvent
{
public:
virtual ~FileEvent() = default;
};
} // namespace event
} // namespace sdk
} // namespace event
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
51 changes: 27 additions & 24 deletions sdk/include/opentelemetry/sdk/event/timer.h
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
#pragma once

#include <chrono>
#include <system_error>
#include <functional>
#include <system_error>

#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk {
namespace event {
namespace sdk
{
namespace event
{
using TimerCallback = std::function<void()>;

/**
* Manages a timer event.
*
* Note: Must be freed before the dipatcher is destructed
*/
class Timer {
public:
virtual ~Timer() = default;
class Timer
{
public:
virtual ~Timer() = default;

/**
* Enable a pending timeout. If a timeout is already pending, it will be reset to the new
* timeout.
*/
virtual void EnableTimer(std::chrono::microseconds timeout) noexcept = 0;
/**
* Enable a pending timeout. If a timeout is already pending, it will be reset to the new
* timeout.
*/
virtual void EnableTimer(std::chrono::microseconds timeout) noexcept = 0;

template <class Rep, class Period>
void EnableTimer(std::chrono::duration<Rep, Period> timeout) noexcept
{
this->EnableTimer(std::chrono::duration_cast<std::chrono::microseconds>(timeout));
}
template <class Rep, class Period>
void EnableTimer(std::chrono::duration<Rep, Period> timeout) noexcept
{
this->EnableTimer(std::chrono::duration_cast<std::chrono::microseconds>(timeout));
}

/**
* Disable a pending timeout.
*
* If no timeout is active, it does nothing.
*/
virtual void DisableTimer() noexcept = 0;
/**
* Disable a pending timeout.
*
* If no timeout is active, it does nothing.
*/
virtual void DisableTimer() noexcept = 0;
};
} // namespace event
} // namespace sdk
} // namespace event
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
8 changes: 2 additions & 6 deletions sdk/src/event/libevent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
add_library(opentelemetry_event_libevent
dispatcher.cc
event.cc
event_base.cc
file_event.cc
timer.cc)
add_library(opentelemetry_event_libevent dispatcher.cc event.cc event_base.cc
file_event.cc timer.cc)
target_link_libraries(opentelemetry_event_libevent ${LIBEVENT_LIBRARIES})
17 changes: 10 additions & 7 deletions sdk/src/event/libevent/dispatcher.cc
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include "src/event/libevent/dispatcher.h"
#include "src/event/libevent/timer.h"
#include "src/event/libevent/file_event.h"
#include "src/event/libevent/timer.h"

#include "event2/event.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace event {
namespace libevent {
namespace event
{
namespace libevent
{
std::unique_ptr<event::FileEvent> Dispatcher::CreateFileEvent(FileDescriptor file_descriptor,
FileReadyCallback callback,
uint32_t events) noexcept
Expand All @@ -22,15 +24,16 @@ std::unique_ptr<event::Timer> Dispatcher::CreateTimer(TimerCallback callback) no
return std::unique_ptr<event::Timer>{new (std::nothrow) Timer{event_base_, callback}};
}

void Dispatcher::Exit() noexcept {
void Dispatcher::Exit() noexcept
{
event_base_.LoopBreak();
}


void Dispatcher::Run() noexcept {
void Dispatcher::Run() noexcept
{
event_base_.Dispatch();
}
} // namespace libevent
} // namespace libevent
} // namespace event
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
1 change: 1 addition & 0 deletions sdk/src/event/libevent/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Dispatcher final : public event::Dispatcher
void Exit() noexcept override;

void Run() noexcept override;

private:
EventBase event_base_;
};
Expand Down
27 changes: 14 additions & 13 deletions sdk/src/event/libevent/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@ namespace event
{
namespace libevent
{
class Event {
public:
using Callback = void (*)(FileDescriptor, short what, void *context);
class Event
{
public:
using Callback = void (*)(FileDescriptor, short what, void *context);

Event(EventBase &event_base,
FileDescriptor file_descriptor,
Callback callback,
short what,
void *context) noexcept;
Event(EventBase &event_base,
FileDescriptor file_descriptor,
Callback callback,
short what,
void *context) noexcept;

~Event() noexcept;
~Event() noexcept;

virtual void Add(std::chrono::microseconds timeout = std::chrono::microseconds{0}) noexcept;
virtual void Add(std::chrono::microseconds timeout = std::chrono::microseconds{0}) noexcept;

virtual void Delete() noexcept;
virtual void Delete() noexcept;

private:
::event* event_;
private:
::event *event_;
};
} // namespace libevent
} // namespace event
Expand Down
23 changes: 12 additions & 11 deletions sdk/src/event/libevent/file_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ namespace event
{
namespace libevent
{
class FileEvent final : public event::FileEvent {
public:
using Callback = std::function<void(uint32_t)>;
class FileEvent final : public event::FileEvent
{
public:
using Callback = std::function<void(uint32_t)>;

FileEvent(EventBase &event_base,
FileDescriptor file_descriptor,
uint32_t events,
Callback callback) noexcept;
FileEvent(EventBase &event_base,
FileDescriptor file_descriptor,
uint32_t events,
Callback callback) noexcept;

private:
Event event_;
Callback callback_;
private:
Event event_;
Callback callback_;

static void OnFileEvent(FileDescriptor file_descriptor, short what, void *context) noexcept;
static void OnFileEvent(FileDescriptor file_descriptor, short what, void *context) noexcept;
};
} // namespace libevent
} // namespace event
Expand Down
6 changes: 4 additions & 2 deletions sdk/src/event/libevent/timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ Timer::Timer(EventBase &event_base, Callback callback) noexcept
assert(callback_);
}

void Timer::EnableTimer(std::chrono::microseconds timeout) noexcept {
void Timer::EnableTimer(std::chrono::microseconds timeout) noexcept
{
event_.Add(timeout);
}

void Timer::DisableTimer() noexcept {
void Timer::DisableTimer() noexcept
{
event_.Delete();
}

Expand Down
Loading

0 comments on commit fda54ee

Please sign in to comment.