supla-device
Loading...
Searching...
No Matches
security_logger.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_DEVICE_SECURITY_LOGGER_H_
5#define SRC_SUPLA_DEVICE_SECURITY_LOGGER_H_
6
7#include <stdint.h>
8#include <stddef.h>
9
10constexpr size_t SUPLA_SECURITY_LOG_ENTRY_SIZE = 64;
11constexpr size_t SUPLA_SECURITY_LOG_TEXT_SIZE =
12 (SUPLA_SECURITY_LOG_ENTRY_SIZE - sizeof(uint32_t) * 3);
13
14namespace Supla {
15class Mutex;
16
17#pragma pack(push, 1)
19 union {
20 uint8_t rawData[SUPLA_SECURITY_LOG_ENTRY_SIZE];
21 struct {
22 uint32_t index;
23 uint32_t timestamp;
24 union {
25 uint32_t source;
26 uint8_t sourceBytes[4];
27 };
28 char log[SUPLA_SECURITY_LOG_TEXT_SIZE];
29 };
30 };
31
32 void print() const;
33 bool isEmpty() const;
34};
35#pragma pack(pop)
36
37static_assert(sizeof(SecurityLogEntry) == SUPLA_SECURITY_LOG_ENTRY_SIZE);
38
39enum class SecurityLogSource : uint32_t {
40 NONE = 0x00000000,
41 LOCAL_DEVICE = 0x00000001,
42 REMOTE = 0x00000002,
43};
44
45
46namespace Device {
48 public:
50 virtual ~SecurityLogger();
51 void log(uint32_t source, const char *log);
52
53 virtual void init();
54 virtual bool isEnabled() const;
55 virtual void deleteAll();
56
57 // getLog locks the mutex on first call and releases it when all messages
58 // have been read, so make sure you call it in a loop until null is returned
59 virtual Supla::SecurityLogEntry *getLog();
60 virtual bool prepareGetLog();
61
62 virtual void storeLog(const SecurityLogEntry &entry);
63
64 static const char *getSourceName(uint32_t source);
65
66 protected:
67 uint32_t index = 0;
68 Supla::Mutex *mutex = nullptr;
69 static char buffer[SUPLA_SECURITY_LOG_ENTRY_SIZE];
70};
71}; // namespace Device
72}; // namespace Supla
73
74#endif // SRC_SUPLA_DEVICE_SECURITY_LOGGER_H_
Definition security_logger.h:47
Definition mutex.h:9
Definition security_logger.h:18