herald  2.0.0
contact_log.h
1 // Copyright 2020-2021 Herald Project Contributors
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #ifndef HERALD_CONTACT_LOG_H
6 #define HERALD_CONTACT_LOG_H
7 
8 #include "../sensor_delegate.h"
9 #include "payload_data_formatter.h"
10 #include "sensor_logger.h"
11 #include "../context.h"
12 
13 namespace herald::data {
14 
18 template <typename ContextT, typename PayloadDataFormatterT>
20 public:
21  ErrorStreamContactLogger(ContextT& context, PayloadDataFormatterT& formatter)
22  : ctx(context),
23  fmt(formatter)
24  HLOGGERINIT(ctx,"Sensor","contacts.log")
25  {
26  ;
27  }
28  ~ErrorStreamContactLogger() = default;
29 
30  // Sensor delegate overrides
31  void sensor(SensorType sensor, const TargetIdentifier& didDetect) {
32  HTDBG("didDetect");
33  }
34  // TODO Log all the other activity
35  // void sensor(SensorType sensor, const PayloadData& didRead, const TargetIdentifier& fromTarget) {}
36  // void sensor(SensorType sensor, const ImmediateSendData& didReceive, const TargetIdentifier& fromTarget) {}
37  // void sensor(SensorType sensor, const std::vector<PayloadData>& didShare, const TargetIdentifier& fromTarget){}
38  // void sensor(SensorType sensor, const Proximity& didMeasure, const TargetIdentifier& fromTarget) {}
39  // template <typename LocationT>
40  // void sensor(SensorType sensor, const Location<LocationT>& didVisit) {}
41  // void sensor(SensorType sensor, const Proximity& didMeasure, const TargetIdentifier& fromTarget, const PayloadData& withPayload) {}
42  // void sensor(SensorType sensor, const SensorState& didUpdateState) {}
43 
44 private:
45  std::string csv(std::string toEscape) const noexcept {
46  // C++23 only: if (toEscape.contains(",") || toEscape.contains("\"") || toEscape.contains("'") || toEscape.contains("’")) {
47  // Pre C++23:-
48  if (std::string::npos != toEscape.find(",") ||
49  std::string::npos != toEscape.find("\"") ||
50  std::string::npos != toEscape.find("'") ||
51  std::string::npos != toEscape.find("’")) {
52  return "\"" + toEscape + "\"";
53  }
54  return toEscape;
55  }
56 
57  std::string timestamp() const noexcept {
58  return Date().iso8601DateTime();
59  }
60 
61  ContextT& ctx;
62  PayloadDataFormatterT& fmt;
63 
64  HLOGGER(ContextT);
65 };
66 
67 }
68 
69 #endif
Definition: contact_log.h:19
Definition: date.h:18
Definition: target_identifier.h:17
SensorType
Sensor type as qualifier for target identifier.
Definition: sensor_type.h:14