Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald\include\herald\context.h
Line
Count
Source (jump to first uncovered line)
1
//  Copyright 2020-2021 Herald Project Contributors
2
//  SPDX-License-Identifier: Apache-2.0
3
//
4
5
#ifndef HERALD_CONTEXT_H
6
#define HERALD_CONTEXT_H
7
8
#include "ble/ble_sensor_configuration.h" // TODO abstract this away in to platform class
9
#include "datatype/date.h"
10
11
namespace herald {
12
13
/// \brief Compile-time Context class, customisable via template traits. Provides generic access to OS system features.
14
/// 
15
/// Covers all cross-cutting concerns methods and helpers to prevent tight coupling between components
16
/// Currently hard-coded to include Bluetooth relevant radio, but this should be abstracted in future to
17
/// compile out if Bluetooth support is not needed
18
template <typename PlatformT,
19
          typename LoggingSinkT,
20
          typename BluetoothStateManagerT
21
         >
22
struct Context {
23
  using logging_sink_type = LoggingSinkT;
24
25
  Context(PlatformT& platform,LoggingSinkT& sink,BluetoothStateManagerT& bsm) noexcept
26
21
    : platform(platform), loggingSink(sink), bleStateManager(bsm), config() {}
27
  Context(const Context& other) noexcept
28
    : platform(other.platform), loggingSink(other.loggingSink), bleStateManager(other.bleStateManager), config(other.config)
29
  {}
30
  // Context(Context&& other)
31
  //   : loggingSink(std::move(other.loggingSink)), bleStateManager(std::move(other.bleStateManager))
32
  // {}
33
21
  ~Context() = default;
34
35
  
36
0
  Context<PlatformT,LoggingSinkT,BluetoothStateManagerT>& operator=(Context& other) noexcept {
37
0
    platform = other.platform;
38
0
    loggingSink = other.loggingSink;
39
0
    bleStateManager = other.bleStateManager;
40
0
    return *this;
41
0
  }
42
  
43
  // \brief Returns a reference to this OS'/runtimes implementation of the LoggingSink
44
40
  LoggingSinkT& getLoggingSink() {
45
40
    return loggingSink;
46
40
  }
47
48
  // \brief Returns a reference to this OS'/runtimes implemetation of the Bluetooth State Manager
49
  BluetoothStateManagerT& getBluetoothStateManager() {
50
    return bleStateManager;
51
  }
52
53
  // \brief Returns platform-specific implementation. E.g. Zephyr specific calls
54
  PlatformT& getPlatform() {
55
    return platform;
56
  }
57
58
59
  const ble::BLESensorConfiguration& getSensorConfiguration() {
59
59
    return config;
60
59
  }
61
62
  void setSensorConfiguration(ble::BLESensorConfiguration newConfig) {
63
    config = newConfig;
64
  }
65
66
  datatype::Date getNow() noexcept {
67
    return platform.getNow();
68
  }
69
70
private:
71
  PlatformT& platform;
72
  LoggingSinkT& loggingSink;
73
  BluetoothStateManagerT& bleStateManager;
74
  ble::BLESensorConfiguration config;
75
};
76
77
// \brief Default empty platform type for platforms that have no custom functionality
78
struct DefaultPlatformType {
79
0
  datatype::Date getNow() noexcept {
80
0
    return datatype::Date();
81
0
  }
82
}; 
83
84
} // end namespace
85
86
#endif