Skip to content

Commit

Permalink
Setup dispatcher interface
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 65f6639 commit 73d9d9d
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 0 deletions.
21 changes: 21 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ new_local_repository(
path = "third_party/opentelemetry-proto",
)

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

load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")

rules_foreign_cc_dependencies([
])

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

# GoogleTest framework.
# Only needed for tests, not to build the OpenTelemetry library.
http_archive(
Expand Down
23 changes: 23 additions & 0 deletions bazel/libevent.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external")


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

cmake_external(
name = "libevent",
cache_entries = {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_POSITION_INDEPENDENT_CODE" : "on",
"BUILD_SHARED_LIBS": "off",
"BUILD_STATIC_LIBS": "on",
"EVENT__DISABLE_OPENSSL": "on",
"EVENT__DISABLE_REGRESS": "on",
"EVENT__DISABLE_TESTS": "on",
},
lib_source = ":srcs",
static_libraries = ["libevent.a"],
visibility = ["//visibility:public"],
)
17 changes: 17 additions & 0 deletions sdk/include/opentelemetry/sdk/common/file_descriptor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <cstdint>

#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk {
namespace common {
#ifdef _WIN32
using FileDescriptor = intptr_t;
#else
using FileDescriptor = int;
#endif
} // namespace common
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
29 changes: 29 additions & 0 deletions sdk/include/opentelemetry/sdk/event/dispatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <memory>

#include "opentelemetry/sdk/common/file_descriptor.h"
#include "opentelemetry/sdk/event/file_event.h"
#include "opentelemetry/sdk/event/timer.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk {
namespace event {
class Dispatcher {
public:
virtual ~Dispatcher() = default;

virtual std::unique_ptr<FileEvent> CreateFileEvent(FileDescriptor file_descriptor,
FileReadyCallback callback,
uint32_t events) noexcept = 0;

virtual std::unique_ptr<Timer> CreateTimer(TimerCallback callback) noexcept = 0;

virtual void Exit() noexcept = 0;

virtual void Run() noexcept = 0;
};
} // namespace event
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
29 changes: 29 additions & 0 deletions sdk/include/opentelemetry/sdk/event/file_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

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

#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk {
namespace event {
struct FileReadyType {
static const uint32_t kRead = 1;
static const uint32_t kWrite = 2;
static const uint32_t kClosed = 3;
static const uint32_t kTimeout = 4;
};

using FileReadyCallback = std::function<void(uint32_t)>;

class FileEvent {
public:
virtual ~FileEvent() = default;

};
} // namespace event
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
23 changes: 23 additions & 0 deletions sdk/include/opentelemetry/sdk/event/timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

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

#include "opentelemetry/version.h"

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

class Timer {
public:
virtual ~Timer() = default;

virtual void EnableTimer(std::chrono::microseconds timeout,
std::error_code &error_code) noexcept = 0;
};
} // namespace event
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

0 comments on commit 73d9d9d

Please sign in to comment.