herald  2.0.0
context.h
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 
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  : 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  ~Context() = default;
34 
35 
37  platform = other.platform;
38  loggingSink = other.loggingSink;
39  bleStateManager = other.bleStateManager;
40  return *this;
41  }
42 
43  // \brief Returns a reference to this OS'/runtimes implementation of the LoggingSink
44  LoggingSinkT& getLoggingSink() {
45  return loggingSink;
46  }
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  const ble::BLESensorConfiguration& getSensorConfiguration() {
59  return config;
60  }
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;
75 };
76 
77 // \brief Default empty platform type for platforms that have no custom functionality
79  datatype::Date getNow() noexcept {
80  return datatype::Date();
81  }
82 };
83 
84 } // end namespace
85 
86 #endif
Definition: date.h:18
Acts as a non-global memory arena for arbitrary classes.
Definition: aggregates.h:15
Compile-time Context class, customisable via template traits. Provides generic access to OS system fe...
Definition: context.h:22
Definition: context.h:78
Defines BLE sensor configuration data, e.g. service and characteristic UUIDs.
Definition: ble_sensor_configuration.h:23