usb: getting string descriptors, minor improvements
[quarnos.git] / services / kernel_state.cpp
blob13f98fc659e2eae050372303c24f54e8f1ddb301
1 /* Quarn OS
3 * Kernel state controller
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 /* Implementation of kernel state controller which monitors all changes in the
24 * way that CPU executes code. Can be used mainly for schedulers and saving
25 * energy services.
28 #include "arch/low/e820.h"
29 #include "kernel_state.h"
30 #include "manes/error.h"
31 #include "manes/manec.h"
33 using namespace manes;
34 using namespace resources;
35 using namespace services;
37 kernel_state::kernel_state() : _state(starting), time(0) {}
39 void kernel_state::add_time_tick_call(delegate<void> call) {
40 assert("kernel_state: tick call null delegate", call.null());
42 time_tick_call.add(call);
45 void kernel_state::del_time_tick_call(delegate<void> call) {
46 for (int i = 0; i < time_tick_call.get_count(); i++)
47 if (time_tick_call[i] == call)
48 time_tick_call.remove(i);
51 void kernel_state::increase_time() {
52 time++;
54 for (int i = 0; i < time_tick_call.get_count(); i++)
55 time_tick_call[i]();
58 int kernel_state::get_time() const {
59 return time;
62 error *kernel_state::new_error(const char *x) {
63 return new error(x);
66 extern "C" void memcpy(char *a, char *b, int size) {
67 for (int i = 0; i < size; i++)
68 a[i] = b[i];
71 /* IDEA: allow to create "hooks" that will allow to call a "dynamically set"
72 * function when change from one specific type to another happens
74 bool kernel_state::set_state(state new_state) {
75 if (_state == halting) {
76 debug("kernel_state: fail at changing kernel status");
77 return false;
79 if (new_state == starting) {
80 debug("kernel_state: fail at changing kernel status");
81 return false;
84 _state = new_state;
85 return true;
88 kernel_state::state kernel_state::get_state() const {
89 return _state;
92 unsigned int kernel_state::get_memory_size() const {
93 return arch::get_memory_size();
96 void kernel_state::register_type() {
97 manec::get()->register_type<kernel_state>("kernel_state", "service");