Skip to content

Commit

Permalink
Work on async_timer
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 d14c11f commit 0cef1d8
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 0 deletions.
26 changes: 26 additions & 0 deletions sdk/src/event/async_timer/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(default_visibility = ["//visibility:public"])

cc_library(
name = "dispatcher",
srcs = glob(["**/*.cc"]),
hdrs = glob(["**/*.h"]),
include_prefix = "src/event/async_timer",
deps = [
"//sdk:headers",
],
)

23 changes: 23 additions & 0 deletions sdk/src/event/async_timer/dispatcher.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "src/event/async_timer/dispatcher.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace event
{
namespace async_timer
{
std::unique_ptr<event::Timer> Dispatcher::CreateTimer(TimerCallback callback) noexcept
{
(void)callback;
return nullptr;
}

void Dispatcher::Exit() noexcept {}

void Dispatcher::Run() noexcept {}
} // namespace async_timer
} // namespace event
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

34 changes: 34 additions & 0 deletions sdk/src/event/async_timer/dispatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <map>

#include "opentelemetry/sdk/event/dispatcher.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace event
{
namespace async_timer
{
class Dispatcher final : public event::Dispatcher
{
public:
using EventIterator =
std::map<std::chrono::steady_clock::time_point, TimerCallback>::const_iterator;

// event::Dispatcher
std::unique_ptr<event::Timer> CreateTimer(TimerCallback callback) noexcept override;

void Exit() noexcept override;

void Run() noexcept override;

private:
std::map<std::chrono::steady_clock::time_point, TimerCallback> events_;
};
} // namespace async_timer
} // namespace event
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
21 changes: 21 additions & 0 deletions sdk/src/event/async_timer/timer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "src/event/async_timer/timer.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace event
{
namespace async_timer
{
Timer::Timer(Dispatcher::EventIterator iterator) noexcept : iterator_{iterator} {}

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

void Timer::DisableTimer() noexcept {}
} // namespace async_timer
} // namespace event
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
27 changes: 27 additions & 0 deletions sdk/src/event/async_timer/timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "opentelemetry/sdk/event/timer.h"
#include "opentelemetry/version.h"

#include "src/event/async_timer/dispatcher.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace event
{
namespace async_timer {
class Timer final : event::Timer {
public:
explicit Timer(Dispatcher::EventIterator iterator) noexcept;

void EnableTimer(std::chrono::microseconds timeout) noexcept override;

void DisableTimer() noexcept override;
private:
Dispatcher::EventIterator iterator_;
};
} // namespace async_timer
} // namespace event
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
1 change: 1 addition & 0 deletions sdk/src/event/libevent/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Timer final : public event::Timer

Timer(EventBase &event_base, Callback callback) noexcept;

// event::Timer
void EnableTimer(std::chrono::microseconds timeout) noexcept override;

void DisableTimer() noexcept override;
Expand Down

0 comments on commit 0cef1d8

Please sign in to comment.