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
bool
isEmpty()
const
;
49
};
50
#pragma pack(pop)
51
52
static_assert
(
sizeof
(
SecurityLogEntry
) == SUPLA_SECURITY_LOG_ENTRY_SIZE);
53
54
enum class
SecurityLogSource : uint32_t {
55
NONE = 0x00000000,
56
LOCAL_DEVICE = 0x00000001,
57
REMOTE = 0x00000002,
58
};
59
60
61
namespace
Device {
62
class
SecurityLogger {
63
public
:
64
SecurityLogger();
65
virtual
~SecurityLogger();
66
void
log(uint32_t source,
const
char
*log);
67
68
virtual
void
init();
69
virtual
bool
isEnabled()
const
;
70
virtual
void
deleteAll();
71
72
// getLog locks the mutex on first call and releases it when all messages
73
// have been read, so make sure you call it in a loop until null is returned
74
virtual
Supla::SecurityLogEntry
*getLog();
75
virtual
bool
prepareGetLog();
76
77
virtual
void
storeLog(
const
SecurityLogEntry
&entry);
78
79
static
const
char
*getSourceName(uint32_t source);
80
81
protected
:
82
uint32_t index = 0;
83
Supla::Mutex
*mutex =
nullptr
;
84
static
char
buffer[SUPLA_SECURITY_LOG_ENTRY_SIZE];
85
};
86
};
// namespace Device
87
};
// namespace Supla
88
89
#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