usb: getting string descriptors, minor improvements
[quarnos.git] / manes / error.cpp
bloba56e0088865a171cedab95b1f986b0054535d2b5
1 /* Quarn OS
3 * Error messages implementation
5 * Copyright (C) 2008-2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "libs/colors.h"
24 #include "arch/low/hlt.h"
25 #include "error.h"
26 #include "libs/string.h"
27 #include "resources/keybscr.h"
28 #include "resources/x86_keybscr.h"
30 using namespace manes;
32 p<resources::stream> error::msg_output = p<resources::stream>::invalid;
34 error::error(const string &msg) : base_err(0), er_message(msg) {
35 if (!msg_output.valid())
36 msg_output = new resources::keybscr::arch_keybscr;
39 error::error(p<error> er) : base_err(er) {
40 if (!msg_output.valid())
41 msg_output = new resources::keybscr::arch_keybscr;
44 error::error(p<error> er, const string &msg) : base_err(er), er_message(msg) {
45 if (!msg_output.valid())
46 msg_output = new resources::keybscr::arch_keybscr;
49 void error::critical() {
50 er_print("Critical Quarn OS error has occurred!\n", color::red);
51 for (p<error> er = this; er.valid(); er = er->base_err)
52 er_print(er->er_message, color::red);
53 er_print("\nSystem is halted.", color::red);
55 halt_forever();
58 void error::assertion() {
59 #if DEBUG_MODE == CONF_YES
60 er_print("Assertion failed!\n", color::yellow);
61 for (p<error> er = this; er.valid(); er = er->base_err)
62 er_print(er->er_message, color::yellow);
63 er_print("\nPress any key to continue...", color::yellow);
64 wait_key();
65 #endif
68 #if DEBUG_MODE == CONF_YES
69 extern unsigned int last_call0;
70 extern unsigned int last_call1;
71 #endif
73 void error::debug() {
74 #if DEBUG_MODE == CONF_YES
75 er_print("(", color::darkgray);
76 for (p<error> er = this; er.valid(); er = er->base_err)
77 er_print(er->er_message, color::darkgray);
78 er_print(((string)" [last call: 0x" /*+ string(last_call0,true) + ", 0x" + string(last_call1,true) +*/ + "]"),color::darkgray);
79 er_print(")", color::darkgray);
80 wait_key();
81 #endif
84 void error::er_print(const string &_message, color::color color) {
85 if (msg_output.is<color_output>())
86 msg_output.cast<color_output>()->set_forecolor(color);
87 msg_output->write(_message.to_mem());
88 if (msg_output.is<color_output>())
89 msg_output.cast<color_output>()->default_color();