Skip to content

Commit

Permalink
Tasks: time_point typedef to limit explicit std::chrono::clock depend…
Browse files Browse the repository at this point in the history
…encies
  • Loading branch information
PBrunot committed Jul 19, 2024
1 parent eae9a8b commit 80cc6f4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
6 changes: 4 additions & 2 deletions include/Machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "FabUser.hpp"
#include "MachineConfig.hpp"
#include "Tasks.hpp"

#include <array>
#include <chrono>
#include <cstdint>
Expand Down Expand Up @@ -107,8 +109,8 @@ namespace fabomatic
bool active{false};
FabUser current_user{};

std::optional<std::chrono::steady_clock::time_point> usage_start_timestamp{std::nullopt}; // When did the machine start?
std::optional<std::chrono::steady_clock::time_point> logoff_timestamp{std::nullopt}; // When did the last user log off?
std::optional<Tasks::time_point> usage_start_timestamp{std::nullopt}; // When did the machine start?
std::optional<Tasks::time_point> logoff_timestamp{std::nullopt}; // When did the last user log off?
PowerState power_state{PowerState::PoweredOff};

/// @brief If true, machine needs maintenance
Expand Down
10 changes: 6 additions & 4 deletions include/Tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace fabomatic::Tasks
using milliseconds = std::chrono::milliseconds;
using namespace std::chrono_literals;

[[nodiscard]] inline auto arduinoNow() -> const std::chrono::steady_clock::time_point
typedef std::chrono::steady_clock::time_point time_point;

[[nodiscard]] inline auto arduinoNow() -> const time_point
{
return std::chrono::steady_clock::now();
}
Expand Down Expand Up @@ -93,7 +95,7 @@ namespace fabomatic::Tasks

/// @brief When shall the task be run again
/// @return time_point of the next run or time_point::max() if the task will not run.
[[nodiscard]] auto getNextRun() const -> const std::chrono::steady_clock::time_point;
[[nodiscard]] auto getNextRun() const -> const Tasks::time_point &;

[[nodiscard]] auto toString() const -> const std::string;

Expand All @@ -102,8 +104,8 @@ namespace fabomatic::Tasks
const std::string id;
milliseconds period;
milliseconds delay;
std::chrono::steady_clock::time_point last_run;
std::chrono::steady_clock::time_point next_run;
Tasks::time_point last_run;
Tasks::time_point next_run;
milliseconds average_tardiness;
milliseconds total_runtime;
std::function<void()> callback;
Expand Down
3 changes: 2 additions & 1 deletion include/mock/MockMrfc522.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "MFRC522DriverPinSimple.h"
#include "MFRC522DriverSPI.h"
#include "MFRC522v2.h"
#include "Tasks.hpp"

namespace fabomatic
{
Expand All @@ -19,7 +20,7 @@ namespace fabomatic
{
private:
std::optional<card::uid_t> uid{std::nullopt};
std::optional<std::chrono::steady_clock::time_point> stop_uid_simulate_time{std::nullopt};
std::optional<Tasks::time_point> stop_uid_simulate_time{std::nullopt};
std::optional<card::uid_t> getSimulatedUid() const;

public:
Expand Down
11 changes: 5 additions & 6 deletions src/Tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,12 @@ namespace fabomatic::Tasks
{
std::stringstream ss;
ss << "Task " << getId() << ", active=" << active
<< ",Period=" << period << ", Delay=" << delay
<< ",Period(ms)=" << period << ", Delay(ms)=" << delay
<< ",Last run=" << last_run.time_since_epoch()
<< ",Next_run=" << next_run.time_since_epoch()
<< ",Avg tardiness=" << average_tardiness
<< ",total_runtime " << total_runtime
<< ",run_counter=" << run_counter
<< ",clock=" << millis();
<< ",Avg tardiness (ms)=" << average_tardiness
<< ",total_runtime (ms)= " << total_runtime
<< ",run_counter=" << run_counter;
return ss.str();
}

Expand Down Expand Up @@ -256,7 +255,7 @@ namespace fabomatic::Tasks
return total_runtime;
}

auto Task::getNextRun() const -> const std::chrono::steady_clock::time_point
auto Task::getNextRun() const -> const Tasks::time_point &
{
return next_run;
}
Expand Down

0 comments on commit 80cc6f4

Please sign in to comment.