sortix-mirror/kernel/include/sortix/kernel/log.h

111 lines
2.9 KiB
C
Raw Normal View History

/*******************************************************************************
2011-08-05 12:25:00 +00:00
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
2011-08-05 12:25:00 +00:00
This file is part of Sortix.
2011-08-05 12:25:00 +00:00
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
2011-08-05 12:25:00 +00:00
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
2011-08-05 12:25:00 +00:00
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
2011-08-05 12:25:00 +00:00
sortix/kernel/log.h
A system for logging various messages to the kernel log.
2011-08-05 12:25:00 +00:00
*******************************************************************************/
2011-08-05 12:25:00 +00:00
#ifndef INCLUDE_SORTIX_KERNEL_LOG_H
#define INCLUDE_SORTIX_KERNEL_LOG_H
2011-08-05 12:25:00 +00:00
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
2011-08-05 12:25:00 +00:00
namespace Sortix {
namespace Log {
extern size_t (*device_callback)(void*, const char*, size_t);
extern size_t (*device_width)(void*);
extern size_t (*device_height)(void*);
2013-12-20 20:55:05 +00:00
extern void (*device_get_cursor)(void*, size_t*, size_t*);
extern bool (*device_sync)(void*);
extern void* device_pointer;
2013-11-11 21:21:56 +00:00
extern bool (*emergency_device_is_impaired)(void*);
extern bool (*emergency_device_recoup)(void*);
extern void (*emergency_device_reset)(void*);
extern size_t (*emergency_device_callback)(void*, const char*, size_t);
extern size_t (*emergency_device_width)(void*);
extern size_t (*emergency_device_height)(void*);
2013-12-20 20:55:05 +00:00
extern void (*emergency_device_get_cursor)(void*, size_t*, size_t*);
2013-11-11 21:21:56 +00:00
extern bool (*emergency_device_sync)(void*);
extern void* emergency_device_pointer;
inline void Flush()
2011-08-05 12:25:00 +00:00
{
if ( !device_callback )
return;
device_callback(device_pointer, NULL, 0);
2011-08-05 12:25:00 +00:00
}
inline size_t Width()
{
return device_width(device_pointer);
}
inline size_t Height()
{
return device_height(device_pointer);
}
2013-12-20 20:55:05 +00:00
inline void GetCursor(size_t* col, size_t* row)
{
return device_get_cursor(device_pointer, col, row);
}
inline bool Sync()
{
return device_sync(device_pointer);
}
inline size_t Print(const char* str)
{
if ( !device_callback )
return 0;
return device_callback(device_pointer, str, strlen(str));
}
inline size_t PrintData(const void* ptr, size_t size)
{
if ( !device_callback )
return 0;
return device_callback(device_pointer, (const char*) ptr, size);
}
inline size_t PrintF(const char* format, ...)
{
va_list list;
va_start(list, format);
size_t result = vprintf_callback(device_callback, device_pointer, format, list);
va_end(list);
return result;
}
inline size_t PrintFV(const char* format, va_list list)
{
return vprintf_callback(device_callback, device_pointer, format, list);
}
} // namespace Log
} // namespace Sortix
2011-08-05 12:25:00 +00:00
#endif