Program Listing for File Timer.h

Return to documentation for file (axr.sdk/utils/Timer.h)

// Copyright (C) AcceleratXR, Inc. All rights reserved.
//
// Author: Jean-Philippe Steinmetz <info@acceleratxr.com>
#pragma once

#include <cpprest/asyncrt_utils.h>
#include <functional>

// Forward declare spdlog dependencies so we don't have to include the header.
// Including the header causes lots of problems as it includes Windows.h and this causes issues for implementing
// apps like Unreal Engine.


namespace axr
{
namespace sdk
{

namespace logging
{
    class BaseLogger;
}

namespace utils
{

class Timer
{
public:
    Timer(pplx::cancellation_token cts, std::shared_ptr<logging::BaseLogger> logger);

    ~Timer() {}

    void Clear();

    pplx::task<void> SetInterval(std::function<void()> func, uint64_t interval);

    pplx::task<void> SetTimeout(std::function<void()> func, uint64_t timeout);

private:
    pplx::cancellation_token m_cts;
    std::shared_ptr<logging::BaseLogger> m_logger;
    uint32_t m_timeout;
    bool m_stopping;
};

} // namespace utils
} // namespace sdk
} // namespace axr