FreeNOS
LogLevelFile.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (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, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <Log.h>
19#include <String.h>
20#include "LogLevelFile.h"
21
23 : File(inode)
24{
26}
27
31
33 Size & size,
34 const Size offset)
35{
36 // Bounds checking
37 if (offset >= 2)
38 {
39 size = 0;
41 }
42 else
43 {
44 // Retrieve the current log level
46
47 // Format it as a string
48 String tmp;
49 tmp.set(level);
50 tmp << "\n";
51
52 // Write to the output buffer
53 size = 2;
54 buffer.write(*tmp, 2);
55
57 }
58}
59
61 Size & size,
62 const Size offset)
63{
64 // Bounds checking
65 if (offset > 1)
66 {
67 size = 0;
69 }
70 else
71 {
72 char tmp[2];
73
74 // Read input
75 buffer.read(tmp, 1);
76 tmp[1] = 0;
77
78 // Convert from text to integer
79 const Log::Level level = (const Log::Level) String(tmp).toLong();
80
81 // Apply new loglevel
83
85 }
86}
Represents a file present on a FileSystem.
Definition File.h:40
FileSystem::FileModes m_access
Access permissions.
Definition File.h:145
Abstract Input/Output buffer.
Definition IOBuffer.h:38
FileSystem::Result read(void *buffer, const Size size, const Size offset=ZERO)
Read bytes from the I/O buffer.
Definition IOBuffer.cpp:156
FileSystem::Result write(const void *buffer, const Size size, const Size offset=ZERO)
Write bytes to the I/O buffer.
Definition IOBuffer.cpp:180
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read bytes from the file.
LogLevelFile(const u32 inode)
Default constructor.
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Write bytes to the file.
virtual ~LogLevelFile()
Destructor.
Level getMinimumLogLevel()
Get the minimum logging level.
Definition Log.cpp:33
void setMinimumLogLevel(Level level)
Set the minimum logging level.
Definition Log.cpp:38
Level
Logging level values.
Definition Log.h:107
Abstraction of strings.
Definition String.h:42
long toLong(const Number::Base base=Number::Dec) const
Convert the String to a signed long integer.
Definition String.cpp:456
Size set(const long number, const Number::Base base=Number::Dec, char *string=ZERO)
Set text-representation of a signed number.
Definition String.cpp:533
static Log * instance()
Retrieve the instance.
Definition Singleton.h:86
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
Result
Result code for filesystem Actions.
Definition FileSystem.h:53