1

merged cleanup

This commit is contained in:
2022-07-24 21:12:31 +02:00
parent 5ff3d72bfd
commit 6481bae5f6
92 changed files with 663 additions and 755 deletions

View File

@ -37,7 +37,7 @@ void MainMenu::run() {
char input = '\0';
unsigned int running_demo = 0;
while (running) {
input = this->listener.waitForKeyEvent();
input = listener.waitForKeyEvent();
if ((input >= '0' && input <= '9') || input == '!') {
switch (input) {

View File

@ -1,5 +1,5 @@
#ifndef __MainMenu_Inlucde_H_
#define __MainMenu_Inlucde_H_
#ifndef MainMenu_Inlucde_H_
#define MainMenu_Inlucde_H_
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
@ -7,17 +7,17 @@
class MainMenu : public Thread {
private:
MainMenu(const MainMenu& copy) = delete;
KeyEventListener listener;
public:
MainMenu() : Thread("MainMenu"), listener(this->tid) {
kevman.subscribe(this->listener);
MainMenu(const MainMenu& copy) = delete;
MainMenu() : Thread("MainMenu"), listener(tid) {
kevman.subscribe(listener);
}
~MainMenu() override {
kevman.unsubscribe(this->listener);
kevman.unsubscribe(listener);
}
void run() override;

View File

@ -1,6 +1,6 @@
/* GIMP RGB C-Source image dump (hhulogo.c) */
static constexpr const struct {
static constexpr struct {
unsigned int width;
unsigned int height;
unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */

View File

@ -3,7 +3,6 @@
void ArrayDemo::run() {
bse::array<int, 10> arr1 {};
bse::array<int, 10> arr2 {};
bse::array<Thread*, 10> arr3 {};
kout.lock();
kout.clear();

View File

@ -1,14 +1,13 @@
#ifndef __ArrayDemo_include__
#define __ArrayDemo_include__
#ifndef ArrayDemo_include__
#define ArrayDemo_include__
#include "kernel/Globals.h"
#include "user/lib/Array.h"
class ArrayDemo : public Thread {
private:
public:
ArrayDemo(const ArrayDemo& copy) = delete;
public:
ArrayDemo() : Thread("ArrayDemo") {}
void run() override;

View File

@ -1,14 +1,13 @@
#ifndef __BlueScreenDemo_include__
#define __BlueScreenDemo_include__
#ifndef BlueScreenDemo_include__
#define BlueScreenDemo_include__
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
class BlueScreenDemo : public Thread {
private:
public:
BlueScreenDemo(const BlueScreenDemo& copy) = delete;
public:
BlueScreenDemo() : Thread("BlueScreenDemo") {}
void run() override;

View File

@ -7,8 +7,8 @@
* *
* Autor: Michael Schoettner, HHU, 25.9.2016 *
*****************************************************************************/
#ifndef __HeapDemo_include__
#define __HeapDemo_include__
#ifndef HeapDemo_include__
#define HeapDemo_include__
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
@ -21,10 +21,9 @@ public:
};
class HeapDemo : public Thread {
private:
public:
HeapDemo(const HeapDemo& copy) = delete;
public:
HeapDemo() : Thread("HeapDemo") {}
void run() override;

View File

@ -8,8 +8,8 @@
* Autor: Michael Schoettner, HHU, 26.10.2018 *
*****************************************************************************/
#ifndef __KeyboardDemo_include__
#define __KeyboardDemo_include__
#ifndef KeyboardDemo_include__
#define KeyboardDemo_include__
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
@ -17,13 +17,13 @@
class KeyboardDemo : public Thread {
private:
KeyboardDemo(const KeyboardDemo& copy) = delete;
KeyEventListener listener;
public:
KeyboardDemo() : Thread("KeyboardDemo"), listener(this->tid) {
kevman.subscribe(this->listener);
KeyboardDemo(const KeyboardDemo& copy) = delete;
KeyboardDemo() : Thread("KeyboardDemo"), listener(tid) {
kevman.subscribe(listener);
}
// Base class destructor will be called automatically
@ -35,7 +35,7 @@ public:
// thread set it (so use nice_kill)
kout.unlock();
}
kevman.unsubscribe(this->listener);
kevman.unsubscribe(listener);
}
void run() override;

View File

@ -6,7 +6,7 @@ void PCSPKdemo::run() {
kout << "Playing..." << endl;
kout.unlock();
(pcspk.*this->melody)(); // This syntax is confusing as hell
(pcspk.*melody)(); // This syntax is confusing as hell
kout.lock();
kout << "Finished" << endl;

View File

@ -1,20 +1,20 @@
#ifndef __PCSPKdemo_INCLUDE_H_
#define __PCSPKdemo_INCLUDE_H_
#ifndef PCSPKdemo_INCLUDE_H_
#define PCSPKdemo_INCLUDE_H_
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
class PCSPKdemo : public Thread {
private:
PCSPKdemo(const PCSPKdemo& copy) = delete;
void (PCSPK::*melody)(void); // Allow to pass a melody to play when initializing the demo
void (PCSPK::*melody)(); // Allow to pass a melody to play when initializing the demo
public:
PCSPKdemo(void (PCSPK::*melody)(void)) : Thread("PCSPKdemo"), melody(melody) {}
PCSPKdemo(const PCSPKdemo& copy) = delete;
explicit PCSPKdemo(void (PCSPK::*melody)()) : Thread("PCSPKdemo"), melody(melody) {}
~PCSPKdemo() override {
pcspk.off();
PCSPK::off();
}
void run() override;

View File

@ -8,8 +8,8 @@ void PreemptiveLoopThread::run() {
kout.lock();
// Saving + restoring kout position doesn't help much as preemption still occurs
kout.setpos(55, this->id);
kout << fillw(3) << this->id << fillw(0) << ": " << dec << cnt++ << endl;
CGA_Stream::setpos(55, id);
kout << fillw(3) << id << fillw(0) << ": " << dec << cnt++ << endl;
kout.unlock();
}
@ -24,7 +24,7 @@ void PreemptiveThreadDemo::run() {
kout << "Preemptive Thread Demo:" << endl;
kout << "Readying LoopThreads" << endl;
for (unsigned int i = 0; i < this->number_of_threads; ++i) {
for (unsigned int i = 0; i < number_of_threads; ++i) {
scheduler.ready<PreemptiveLoopThread>(i);
}

View File

@ -1,5 +1,5 @@
#ifndef __preemptive_thread_include__
#define __preemptive_thread_include__
#ifndef preemptive_thread_include__
#define preemptive_thread_include__
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
@ -8,9 +8,10 @@
class PreemptiveLoopThread : public Thread {
private:
int id;
PreemptiveLoopThread(const PreemptiveLoopThread& copy) = delete; // Verhindere Kopieren
public:
PreemptiveLoopThread(const PreemptiveLoopThread& copy) = delete; // Verhindere Kopieren
// Gibt der Loop einen Stack und eine Id.
PreemptiveLoopThread(int i) : Thread("LoopThread"), id(i) {}
@ -20,11 +21,11 @@ public:
class PreemptiveThreadDemo : public Thread {
private:
PreemptiveThreadDemo(const PreemptiveThreadDemo& copy) = delete; // Verhindere Kopieren
unsigned int number_of_threads;
public:
PreemptiveThreadDemo(const PreemptiveThreadDemo& copy) = delete; // Verhindere Kopieren
PreemptiveThreadDemo(unsigned int n) : Thread("PreemptiveThreadDemo"), number_of_threads(n) {}
// Thread-Startmethode

View File

@ -21,10 +21,10 @@ void SmartPointerDemo::run() {
bse::unique_ptr<int> ptr1 = bse::make_unique<int>(1);
bse::unique_ptr<int> ptr2;
log.info() << "*ptr1 == " << *ptr1 << ", (bool)ptr2 == " << (bool)ptr2 << endl;
log.info() << "*ptr1 == " << *ptr1 << ", (bool)ptr2 == " << static_cast<bool>(ptr2) << endl;
log.info() << "Moving ptr1 => ptr2 (no allocations should happen)..." << endl;
ptr2 = std::move(ptr1);
log.info() << "(bool)ptr1 == " << (bool)ptr1 << ", *ptr2 == " << *ptr2 << endl;
log.info() << "(bool)ptr1 == " << static_cast<bool>(ptr1) << ", *ptr2 == " << *ptr2 << endl;
log.info() << "Leaving scope..." << endl;
}

View File

@ -1,13 +1,12 @@
#ifndef __SmartPointerDemo_include__
#define __SmartPointerDemo_include__
#ifndef SmartPointerDemo_include__
#define SmartPointerDemo_include__
#include "kernel/Globals.h"
class SmartPointerDemo : public Thread {
private:
public:
SmartPointerDemo(const SmartPointerDemo& copy) = delete;
public:
SmartPointerDemo() : Thread("SmartPointerDemo") {}
void run() override;

View File

@ -40,14 +40,14 @@ void StringDemo::run() {
log.info() << "Reassign str2" << endl;
str2 = "Hello";
bse::array<char, 5> arr;
bse::array<char, 5> arr{};
arr[0] = 'H';
arr[1] = 'e';
arr[2] = 'l';
arr[3] = 'l';
arr[4] = 'o';
kout << "bse::array<char, 5> to bse::string: " << arr << ", size: " << ((bse::string)arr).size() << endl;
kout << "(bse::string)arr (" << arr << ") == str2 (" << str2 << "): " << static_cast<int>((bse::string)arr == str2) << endl;
kout << "bse::array<char, 5> to bse::string: " << static_cast<bse::string>(arr) << ", size: " << (bse::string(arr)).size() << endl;
kout << "(bse::string)arr (" << static_cast<bse::string>(arr) << ") == str2 (" << str2 << "): " << static_cast<int>(bse::string(arr) == str2) << endl;
kout.unlock();
scheduler.exit();

View File

@ -1,13 +1,12 @@
#ifndef __StringDemo_include__
#define __StringDemo_include__
#ifndef StringDemo_include__
#define StringDemo_include__
#include "kernel/Globals.h"
class StringDemo : public Thread {
private:
public:
StringDemo(const StringDemo& copy) = delete;
public:
StringDemo() : Thread("StringDemo") {}
void run() override;

View File

@ -8,17 +8,16 @@
* Autor: Michael Schoettner, HHU, 26.10.2018 *
*****************************************************************************/
#ifndef __TextDemo_include__
#define __TextDemo_include__
#ifndef TextDemo_include__
#define TextDemo_include__
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
class TextDemo : public Thread {
private:
public:
TextDemo(const TextDemo& copy) = delete;
public:
TextDemo() : Thread("TextDemo") {}
void run() override;

View File

@ -59,7 +59,7 @@ void VBEdemo::drawBitmap() {
unsigned int sprite_width = hhu.width;
unsigned int sprite_height = hhu.height;
unsigned int sprite_bpp = hhu.bytes_per_pixel;
unsigned char* sprite_pixel = (unsigned char*)hhu.pixel_data;
const unsigned char* sprite_pixel = reinterpret_cast<const unsigned char*>(hhu.pixel_data);
/* Hier muss Code eingefuegt werden */

View File

@ -7,27 +7,27 @@
* *
* Autor: Michael Schoettner, HHU, 26.12.2016 *
*****************************************************************************/
#ifndef __VBEdemo_include__
#define __VBEdemo_include__
#ifndef VBEdemo_include__
#define VBEdemo_include__
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
class VBEdemo : public Thread {
private:
VBEdemo(const VBEdemo& copy) = delete; // Verhindere Kopieren
// Hilfsfunktionen fuer drawColors()
int linInterPol1D(int x, int xr, int l, int r);
int linInterPol2D(int x, int y, int lt, int rt, int lb, int rb);
static int linInterPol1D(int x, int xr, int l, int r);
static int linInterPol2D(int x, int y, int lt, int rt, int lb, int rb);
public:
VBEdemo(const VBEdemo& copy) = delete; // Verhindere Kopieren
// Gib dem Anwendungsthread einen Stack.
VBEdemo() : Thread("VBEdemo") {}
~VBEdemo() override {
vesa.initTextMode();
allocator.free(reinterpret_cast<void*>(vesa.hfb)); // Memory is allocated after every start and never deleted, so add that
VESA::initTextMode();
}
// Thread-Startmethode
@ -37,10 +37,10 @@ public:
void drawColors();
// Bitmap aus GIMP ausgeben
void drawBitmap();
static void drawBitmap();
// Fonts ausgeben
void drawFonts();
static void drawFonts();
};
#endif

View File

@ -18,7 +18,7 @@ void VectorDemo::run() {
log.info() << "Initial list size: " << dec << list.size() << endl;
log.info() << "Adding elements in order" << endl;
for (unsigned int i = 0; i < 5; ++i) {
for (int i = 0; i < 5; ++i) {
list.push_back(i);
}
print(log.info(), list);
@ -32,7 +32,7 @@ void VectorDemo::run() {
// ============================================================
log.info() << "Adding elements in order with realloc" << endl;
for (unsigned int i = 0; i < 10; ++i) {
for (int i = 0; i < 10; ++i) {
log.info() << "Add " << dec << i << endl;
list.push_back(i);
}
@ -46,7 +46,7 @@ void VectorDemo::run() {
// ============================================================
for (unsigned int i = 0; i < 5; ++i) {
for (int i = 0; i < 5; ++i) {
list.push_back(i);
}
print(log.info(), list);

View File

@ -1,15 +1,14 @@
#ifndef __VectorDemo_include__
#define __VectorDemo_include__
#ifndef VectorDemo_include__
#define VectorDemo_include__
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
#include "user/lib/Vector.h"
class VectorDemo : public Thread {
private:
public:
VectorDemo(const VectorDemo& copy) = delete;
public:
VectorDemo() : Thread("VectorDemo") {}
void run() override;

View File

@ -1,6 +1,8 @@
#include "user/devices/SerialOut.h"
int SerialOut::init() const {
const IOport SerialOut::com1(0x3f8);
SerialOut::SerialOut() {
// NOTE: I could add different ports for every register but this was easier as it's that way on OSDev
com1.outb(1, 0x00); // Disable all interrupts
com1.outb(3, 0x80); // Enable DLAB (set baud rate divisor)
@ -13,14 +15,11 @@ int SerialOut::init() const {
com1.outb(0xAE); // Test serial chip (send byte 0xAE and check if serial returns same byte)
// Check if serial is faulty (i.e: not same byte as sent)
if (com1.inb() != 0xAE) {
return 1;
if (com1.inb() == 0xAE) {
// If serial is not faulty set it in normal operation mode
// (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
com1.outb(4, 0x0F);
}
// If serial is not faulty set it in normal operation mode
// (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
com1.outb(4, 0x0F);
return 0;
}
int SerialOut::serial_received() {
@ -44,11 +43,11 @@ void SerialOut::write(const char a) {
void SerialOut::write(const char* a) {
const char* current = a;
do {
this->write(*current);
write(*current);
current = current + 1;
} while (*current != '\0');
}
void SerialOut::write(const bse::string& a) {
write((const char*)a);
write(static_cast<const char*>(a));
}

View File

@ -1,5 +1,5 @@
#ifndef __SerialOut_Include_H_
#define __SerialOut_Include_H_
#ifndef SerialOut_Include_H_
#define SerialOut_Include_H_
#include "kernel/IOport.h"
#include "user/lib/String.h"
@ -8,24 +8,19 @@
class SerialOut {
private:
const IOport com1;
static const IOport com1;
SerialOut(const SerialOut& copy) = delete;
int serial_received();
int is_transmit_empty();
static int serial_received();
static int is_transmit_empty();
public:
SerialOut() : com1(0x3f8) {
this->init();
}
SerialOut(const SerialOut& copy) = delete;
SerialOut();
int init() const;
char read();
void write(char a);
void write(const char* a);
void write(const bse::string& a);
static char read();
static void write(char a);
static void write(const char* a);
static void write(const bse::string& a);
};
#endif

View File

@ -2,11 +2,11 @@
#include "kernel/Globals.h"
void KeyEventListener::trigger(char c) {
this->lastChar = c;
lastChar = c;
}
char KeyEventListener::waitForKeyEvent() const {
Logger::instance() << DEBUG << "KEvLis:: Thread with id: " << tid << " waiting for key event" << endl;
scheduler.block();
return this->lastChar; // This is only executed after thread is woken up by manager
return lastChar; // This is only executed after thread is woken up by manager
}

View File

@ -1,17 +1,18 @@
#ifndef __KeyEventListener_Include_H_
#define __KeyEventListener_Include_H_
#ifndef KeyEventListener_Include_H_
#define KeyEventListener_Include_H_
#include "kernel/threads/Thread.h"
class KeyEventListener {
private:
KeyEventListener(const KeyEventListener& copy) = delete;
char lastChar = '\0';
public:
friend class KeyEventManager;
unsigned int tid; // Thread which contains this listener, so the listener can block the thread
public:
KeyEventListener(const KeyEventListener& copy) = delete;
KeyEventListener(unsigned int tid) : tid(tid) {}
char waitForKeyEvent() const; // Blocks the thread until woken up by manager

View File

@ -3,14 +3,14 @@
void KeyEventManager::subscribe(KeyEventListener& sub) {
log.debug() << "Subscribe, Thread ID: " << dec << sub.tid << endl;
this->listeners.push_back(&sub);
listeners.push_back(&sub);
}
void KeyEventManager::unsubscribe(KeyEventListener& unsub) {
log.debug() << "Unsubscribe, Thread ID: " << dec << unsub.tid << endl;
for (bse::vector<KeyEventListener*>::iterator it = listeners.begin(); it != listeners.end(); ++it) {
if ((*it)->tid == unsub.tid) {
this->listeners.erase(it);
listeners.erase(it);
return;
}
}
@ -18,7 +18,7 @@ void KeyEventManager::unsubscribe(KeyEventListener& unsub) {
void KeyEventManager::broadcast(char c) {
log.trace() << "Beginning Broadcast" << endl;
for (KeyEventListener* listener : this->listeners) {
for (KeyEventListener* listener : listeners) {
log.trace() << "Broadcasting " << c << " to Thread ID: " << dec << listener->tid << endl;
listener->trigger(c);
scheduler.deblock(listener->tid);

View File

@ -1,5 +1,5 @@
#ifndef __KeyEventManager_Include_H_
#define __KeyEventManager_Include_H_
#ifndef KeyEventManager_Include_H_
#define KeyEventManager_Include_H_
#include "user/event/KeyEventListener.h"
#include "user/lib/Logger.h"
@ -10,13 +10,13 @@
class KeyEventManager {
private:
KeyEventManager(const KeyEventManager& copy) = delete;
NamedLogger log;
bse::vector<KeyEventListener*> listeners;
public:
KeyEventManager(const KeyEventManager& copy) = delete;
KeyEventManager() : log("KEvMan"), listeners(true) {}
void init() {

View File

@ -1,5 +1,5 @@
#ifndef __ARRAY_INCLUDE_H
#define __ARRAY_INCLUDE_H
#ifndef ARRAY_INCLUDE_H
#define ARRAY_INCLUDE_H
#include "user/lib/Iterator.h"
#include <utility>
@ -15,22 +15,30 @@ namespace bse {
T buf[N];
public:
array() {}; // If i write default something like bse::array<int, 10> arr; is not initialized...
array() = default;; // If i write default something like bse::array<int, 10> arr; is not initialized...
array(std::initializer_list<T> list) {
typename std::initializer_list<T>::iterator it = list.begin();
for (unsigned int i = 0; i < N; ++i) {
buf[i] = *it;
++it;
}
}
iterator begin() { return iterator(&buf[0]); }
iterator begin() const { return iterator(&buf[0]); }
iterator end() { return iterator(&buf[N]); }
iterator end() const { return iterator(&buf[N]); }
T& operator[](std::size_t i) { return this->buf[i]; }
constexpr const T& operator[](std::size_t i) const { return this->buf[i]; }
T& operator[](std::size_t i) { return buf[i]; }
constexpr const T& operator[](std::size_t i) const { return buf[i]; }
T* operator&() { return &buf[0]; } // Not standard, I don't know yet if this will turn out to be a bad idea
const T* operator&() const { return &buf[0]; }
T* data() { return &buf[0]; } // Not standard, I don't know yet if this will turn out to be a bad idea
const T* data() const { return &buf[0]; }
void swap(array<T, N>& other) {
for (std::size_t i = 0; i < N; ++i) {
std::swap(this->buf[i], other[i]);
std::swap(buf[i], other[i]);
}
}
@ -39,7 +47,7 @@ namespace bse {
template<std::size_t n>
void swap_n(array<T, n>& other) {
for (std::size_t i = 0; i < n; ++i) {
std::swap(this->buf[i], other[i]);
std::swap(buf[i], other[i]);
}
}

View File

@ -1,5 +1,5 @@
#ifndef __Iterator_Include_H_
#define __Iterator_Include_H_
#ifndef Iterator_Include_H_
#define Iterator_Include_H_
namespace bse {
@ -9,45 +9,41 @@ namespace bse {
private:
T* ptr = nullptr;
public:
ContinuousIterator() = delete;
public:
ContinuousIterator(T* ptr) : ptr(ptr) {}
T* get() const {
return ptr;
}
ContinuousIterator& operator++() {
++this->ptr;
++ptr;
return *this;
}
ContinuousIterator& operator--() {
--this->ptr;
--ptr;
return *this;
}
ContinuousIterator operator+(unsigned int add) {
return ContinuousIterator(this->ptr + add);
return ContinuousIterator(ptr + add);
}
ContinuousIterator operator-(unsigned int sub) {
return ContinuousIterator(this->ptr - sub);
return ContinuousIterator(ptr - sub);
}
// Convenience
T* operator->() { return this->ptr; }
const T* operator->() const { return this->ptr; }
T& operator*() { return *this->ptr; }
const T& operator*() const { return *this->ptr; }
T* operator->() { return ptr; }
const T* operator->() const { return ptr; }
T& operator*() { return *ptr; }
const T& operator*() const { return *ptr; }
bool operator<(const ContinuousIterator& other) const { return this->ptr < other.ptr; }
bool operator<=(const ContinuousIterator& other) const { return this->ptr <= other.ptr; }
bool operator>(const ContinuousIterator& other) const { return this->ptr > other.ptr; }
bool operator>=(const ContinuousIterator& other) const { return this->ptr >= other.ptr; }
bool operator==(const ContinuousIterator& other) const { return this->ptr == other.ptr; }
bool operator!=(const ContinuousIterator& other) const { return this->ptr != other.ptr; }
bool operator<(const ContinuousIterator& other) const { return ptr < other.ptr; }
bool operator<=(const ContinuousIterator& other) const { return ptr <= other.ptr; }
bool operator>(const ContinuousIterator& other) const { return ptr > other.ptr; }
bool operator>=(const ContinuousIterator& other) const { return ptr >= other.ptr; }
bool operator==(const ContinuousIterator& other) const { return ptr == other.ptr; }
bool operator!=(const ContinuousIterator& other) const { return ptr != other.ptr; }
template<typename t>
friend unsigned int distance(const ContinuousIterator<t>& first, const ContinuousIterator<t>& last);

View File

@ -19,61 +19,61 @@ void Logger::log(const char* message, CGA::color col) const {
if (Logger::kout_enabled) {
CGA::color old_col = kout.color_fg;
kout << fgc(col)
<< Logger::level_to_string(this->current_message_level) << "::"
<< Logger::level_to_string(current_message_level) << "::"
<< message << fgc(old_col);
kout.flush(); // Don't add newline, Logger already does that
}
if (Logger::serial_enabled) {
switch (col) {
case CGA::WHITE:
serial.write(ansi_white);
SerialOut::write(ansi_white);
break;
case CGA::LIGHT_MAGENTA:
serial.write(ansi_magenta);
SerialOut::write(ansi_magenta);
break;
case CGA::LIGHT_RED:
serial.write(ansi_red);
SerialOut::write(ansi_red);
break;
case CGA::LIGHT_BLUE:
serial.write(ansi_blue);
SerialOut::write(ansi_blue);
break;
default:
serial.write(ansi_default);
SerialOut::write(ansi_default);
}
serial.write(Logger::level_to_string(this->current_message_level));
serial.write(":: ");
serial.write(message);
serial.write('\r');
SerialOut::write(Logger::level_to_string(current_message_level));
SerialOut::write(":: ");
SerialOut::write(message);
SerialOut::write('\r');
// serial.write("\r\n");
}
}
void Logger::flush() {
this->buffer[this->pos] = '\0';
buffer[pos] = '\0';
switch (this->current_message_level) {
switch (current_message_level) {
case Logger::TRACE:
this->trace(&buffer);
trace(buffer.data());
break;
case Logger::DEBUG:
this->debug(&buffer);
debug(buffer.data());
break;
case Logger::ERROR:
this->error(&buffer);
error(buffer.data());
break;
case Logger::INFO:
this->info(&buffer);
info(buffer.data());
break;
}
this->current_message_level = Logger::INFO;
this->pos = 0;
current_message_level = Logger::INFO;
pos = 0;
Logger::unlock();
}
void Logger::trace(const char* message) const {
if (Logger::level <= Logger::TRACE) {
this->log(message, CGA::WHITE);
log(message, CGA::WHITE);
}
}
void Logger::trace(const bse::string& message) const {
@ -82,7 +82,7 @@ void Logger::trace(const bse::string& message) const {
void Logger::debug(const char* message) const {
if (Logger::level <= Logger::DEBUG) {
this->log(message, CGA::LIGHT_MAGENTA);
log(message, CGA::LIGHT_MAGENTA);
}
}
void Logger::debug(const bse::string& message) const {
@ -91,7 +91,7 @@ void Logger::debug(const bse::string& message) const {
void Logger::error(const char* message) const {
if (Logger::level <= Logger::ERROR) {
this->log(message, CGA::LIGHT_RED);
log(message, CGA::LIGHT_RED);
}
}
void Logger::error(const bse::string& message) const {
@ -100,7 +100,7 @@ void Logger::error(const bse::string& message) const {
void Logger::info(const char* message) const {
if (Logger::level <= Logger::INFO) {
this->log(message, CGA::LIGHT_BLUE);
log(message, CGA::LIGHT_BLUE);
}
}
void Logger::info(const bse::string& message) const {

View File

@ -1,5 +1,5 @@
#ifndef __Logger_Include_H_
#define __Logger_Include_H_
#ifndef Logger_Include_H_
#define Logger_Include_H_
#include "devices/CGA.h"
#include "lib/OutStream.h"
@ -15,8 +15,6 @@ public:
private:
Logger() = default;
Logger(const Logger& copy) = delete;
void operator=(const Logger& copy) = delete;
static bool kout_enabled;
static bool serial_enabled;
@ -24,6 +22,7 @@ private:
void log(const char* message, CGA::color col) const;
friend class NamedLogger; // Allow NamedLogger to lock/unlock
SpinLock sem; // Semaphore would be a cyclic include
static void lock() { Logger::instance().sem.acquire(); }
static void unlock() { Logger::instance().sem.release(); }
@ -31,6 +30,11 @@ private:
// static void unlock() {}
public:
// ~Logger() override = default;
Logger(const Logger& copy) = delete;
void operator=(const Logger& copy) = delete;
enum LogLevel {
TRACE,
DEBUG,
@ -51,13 +55,13 @@ public:
void info(const char* message) const;
void info(const bse::string& message) const;
// TODO: Make level change accessible over menu
static void set_level(LogLevel level) {
Logger::level = level;
// TODO: Make lvl change accessible over menu
static void set_level(LogLevel lvl) {
Logger::level = lvl;
}
static char* level_to_string(LogLevel level) {
switch (level) {
static char* level_to_string(LogLevel lvl) {
switch (lvl) {
case Logger::TRACE:
return "TRACE";
case Logger::DEBUG:
@ -94,7 +98,7 @@ private:
const char* name;
public:
NamedLogger(const char* name) : name(name) {}
explicit NamedLogger(const char* name) : name(name) {}
Logger& trace() {
Logger::lock();

View File

@ -1,12 +1,19 @@
#ifndef __MATH_INCLUDE_H_
#define __MATH_INCLUDE_H_
#ifndef MATH_INCLUDE_H_
#define MATH_INCLUDE_H_
namespace bse {
// I didn't add any numeric constraints, will do with c++20
template<typename T>
T& min(const T& a, const T& b) { return a < b ? a : b; }
template<typename T>
T& max(const T& a, const T& b) { return a > b ? a : b; }
template<typename T>
std::make_unsigned<T> abs(const T& a) { return a < 0 ? -a : a; }
} // namespace bse
#endif

View File

@ -1,8 +1,10 @@
#ifndef __MYSTDLIB_INCLUDE_H_
#define __MYSTDLIB_INCLUDE_H_
#ifndef MYSTDLIB_INCLUDE_H_
#define MYSTDLIB_INCLUDE_H_
namespace bse {
// add using byte or sth to replace char
template<typename T>
void memcpy(T* destination, const T* source, const unsigned int count = 1) {
for (unsigned int i = 0; i < count; ++i) {
@ -14,7 +16,7 @@ namespace bse {
template<typename T>
void zero(T* destination) {
memset((char*)destination, '\0', sizeof(T));
memset(reinterpret_cast<char*>(destination), '\0', sizeof(T));
}
// void strcpy(char* destination, char* source);

View File

@ -1,5 +1,5 @@
#ifndef __String_Include_H_
#define __String_Include_H_
#ifndef String_Include_H_
#define String_Include_H_
#include "user/lib/Array.h"
#include "user/lib/Iterator.h"
@ -24,8 +24,9 @@ namespace bse {
strncpy(buf, len + 1, str);
}
// Convert char array to string
template<unsigned int N>
string(const array<char, N>& arr) : len(N), buf(new char[len + 1]) {
explicit string(const array<char, N>& arr) : len(N), buf(new char[len + 1]) {
for (unsigned int i = 0; i < N; ++i) {
buf[i] = arr[i];
}

View File

@ -1,5 +1,5 @@
#ifndef __VECTOR_INCLUDE_H_
#define __VECTOR_INCLUDE_H_
#ifndef VECTOR_INCLUDE_H_
#define VECTOR_INCLUDE_H_
// NOTE: I decided to implement this because I wanted some sort of dynamic array (for example for the keyeventmanager).
// Also I wanted to template the Queue (for the scheduler) but with this I can just replace the Queue and use the
@ -101,16 +101,14 @@ namespace bse {
}
public:
vector(bool lazy = false) {
explicit vector(bool lazy = false) {
if (!lazy) { // I added this as a work around, the scheduler can't initialize the queues right
// away because when the scheduler is started the allocator is not ready.
init();
}
};
vector(const vector& copy) {
buf_cap = copy.buf_cap;
buf_pos = copy.buf_pos;
vector(const vector& copy) : buf_pos(copy.buf_pos), buf_cap(copy.buf_cap) {
buf = new T[buf_cap];
for (unsigned int i = 0; i < buf_pos; ++i) {
buf[i] = copy[i]; // Does a copy since copy is marked const reference
@ -131,9 +129,7 @@ namespace bse {
return *this;
}
vector(vector&& move) noexcept {
buf_cap = move.buf_cap;
buf_pos = move.buf_pos;
vector(vector&& move) noexcept : buf_pos(move.buf_pos), buf_cap(move.buf_cap) {
buf = move.buf;
move.buf_cap = 0;

View File

@ -1,5 +1,5 @@
#ifndef __UniquePointer_Include_H_
#define __UniquePointer_Include_H_
#ifndef UniquePointer_Include_H_
#define UniquePointer_Include_H_
#include <utility>
@ -34,11 +34,11 @@ namespace bse {
ptr = nullptr;
}
public:
// Forbid copying
unique_ptr(const unique_ptr& copy) = delete;
unique_ptr& operator=(const unique_ptr& copy) = delete;
public:
// Construction
unique_ptr() = default; // Allow declaration without explicit definition
@ -74,9 +74,9 @@ namespace bse {
// Resetting: Replaces managed object, deleting the old one
void reset() { del(); }
void reset(T_* ptr) {
void reset(T_* pt) {
del();
this->ptr = ptr;
ptr = pt;
}
// Release: Releases ownership without deletion
@ -92,7 +92,7 @@ namespace bse {
return ptr;
}
// Nice to have operators
// Pointer operators
T_* operator->() { return ptr; }
const T_* operator->() const { return ptr; }
T_& operator*() { return *ptr; }
@ -103,7 +103,7 @@ namespace bse {
bool operator==(const unique_ptr& other) const { return ptr == other.ptr; }
// These are only for array unique_ptr but I didn't want to define a full template specialization just for this
// These are only for array unique_ptr but I didn't enforce that
T_& operator[](std::size_t i) { return ptr[i]; }
const T_& operator[](std::size_t i) const { return ptr[i]; }
};