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 
29 {
30 }
31 
33  Size & size,
34  const Size offset)
35 {
36  // Bounds checking
37  if (offset >= 2)
38  {
39  size = 0;
40  return FileSystem::Success;
41  }
42  else
43  {
44  // Retrieve the current log level
45  const Log::Level level = Log::instance()->getMinimumLogLevel();
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 
56  return FileSystem::Success;
57  }
58 }
59 
61  Size & size,
62  const Size offset)
63 {
64  // Bounds checking
65  if (offset > 1)
66  {
67  size = 0;
68  return FileSystem::Success;
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 
84  return FileSystem::Success;
85  }
86 }
LogLevelFile::write
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Write bytes to the file.
Definition: LogLevelFile.cpp:60
Log::setMinimumLogLevel
void setMinimumLogLevel(Level level)
Set the minimum logging level.
Definition: Log.cpp:38
LogLevelFile::~LogLevelFile
virtual ~LogLevelFile()
Destructor.
Definition: LogLevelFile.cpp:28
String
Abstraction of strings.
Definition: String.h:41
LogLevelFile.h
LogLevelFile::LogLevelFile
LogLevelFile(const u32 inode)
Default constructor.
Definition: LogLevelFile.cpp:22
String::set
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
FileSystem::Success
@ Success
Definition: FileSystem.h:54
File
Represents a file present on a FileSystem.
Definition: File.h:39
Log.h
File::m_access
FileSystem::FileModes m_access
Access permissions.
Definition: File.h:145
FileSystem::OwnerRW
@ OwnerRW
Definition: FileSystem.h:90
IOBuffer
Abstract Input/Output buffer.
Definition: IOBuffer.h:37
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
WeakSingleton< Log >::instance
static Log * instance()
Retrieve the instance.
Definition: Singleton.h:86
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
Log::getMinimumLogLevel
Level getMinimumLogLevel()
Get the minimum logging level.
Definition: Log.cpp:33
String.h
IOBuffer::read
FileSystem::Result read(void *buffer, const Size size, const Size offset=ZERO)
Read bytes from the I/O buffer.
Definition: IOBuffer.cpp:156
IOBuffer::write
FileSystem::Result write(const void *buffer, const Size size, const Size offset=ZERO)
Write bytes to the I/O buffer.
Definition: IOBuffer.cpp:180
LogLevelFile::read
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read bytes from the file.
Definition: LogLevelFile.cpp:32
String::toLong
long toLong(const Number::Base base=Number::Dec) const
Convert the String to a signed long integer.
Definition: String.cpp:456
Log::Level
Level
Logging level values.
Definition: Log.h:106