supla-device
Loading...
Searching...
No Matches
src
supla
device
security_logger.h
1
/*
2
Copyright (C) AC SOFTWARE SP. Z O.O
3
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
*/
18
19
#ifndef SRC_SUPLA_DEVICE_SECURITY_LOGGER_H_
20
#define SRC_SUPLA_DEVICE_SECURITY_LOGGER_H_
21
22
#include <stdint.h>
23
#include <stddef.h>
24
25
constexpr
size_t
SUPLA_SECURITY_LOG_ENTRY_SIZE = 64;
26
constexpr
size_t
SUPLA_SECURITY_LOG_TEXT_SIZE =
27
(SUPLA_SECURITY_LOG_ENTRY_SIZE -
sizeof
(uint32_t) * 3);
28
29
namespace
Supla {
30
class
Mutex
;
31
32
#pragma pack(push, 1)
33
struct
SecurityLogEntry
{
34
union
{
35
uint8_t rawData[SUPLA_SECURITY_LOG_ENTRY_SIZE];
36
struct
{
37
uint32_t index;
38
uint32_t timestamp;
39
union
{
40
uint32_t source;
41
uint8_t sourceBytes[4];
42
};
43
char
log[SUPLA_SECURITY_LOG_TEXT_SIZE];
44
};
45
};
46
47
void
print()
const
;
48
};
49
#pragma pack(pop)
50
51
static_assert
(
sizeof
(
SecurityLogEntry
) == SUPLA_SECURITY_LOG_ENTRY_SIZE);
52
53
enum class
SecurityLogSource : uint32_t {
54
NONE = 0x00000000,
55
LOCAL_DEVICE = 0x00000001,
56
REMOTE = 0x00000002,
57
};
58
59
60
namespace
Device {
61
class
SecurityLogger {
62
public
:
63
SecurityLogger();
64
virtual
~SecurityLogger();
65
void
log(uint32_t source,
const
char
*log);
66
67
virtual
void
deleteAll();
68
69
// getLog locks the mutex on first call and releases it when all messages
70
// have been read, so make sure you call it in a loop until null is returned
71
virtual
char
*getLog();
72
virtual
bool
prepareGetLog();
73
74
virtual
void
storeLog(
const
SecurityLogEntry
&entry);
75
76
protected
:
77
uint32_t index = 0;
78
Supla::Mutex
*mutex =
nullptr
;
79
};
80
};
// namespace Device
81
};
// namespace Supla
82
83
#endif
// SRC_SUPLA_DEVICE_SECURITY_LOGGER_H_
Supla::Mutex
Definition
mutex.h:22
SecurityLogEntry
Definition
security_logger.h:33
Supla::SecurityLogEntry
Definition
security_logger.h:33
Generated by
1.13.2