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

96 lines
2.4 KiB
C
Raw Normal View History

/*******************************************************************************
2011-08-05 12:25:00 +00:00
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
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 SORTIX_LOG_H
#define SORTIX_LOG_H
#include <stdio.h>
#include <string.h>
2011-08-05 12:25:00 +00:00
namespace Sortix
{
namespace Log
{
extern size_t (*deviceCallback)(void*, const char*, size_t);
extern size_t (*deviceWidth)(void*);
extern size_t (*deviceHeight)(void*);
extern bool (*deviceSync)(void*);
2011-08-05 12:25:00 +00:00
extern void* devicePointer;
void Init(size_t (*callback)(void*, const char*, size_t),
size_t (*widthfunc)(void*),
size_t (*heightfunc)(void*),
bool (*syncfunc)(void*),
void* user);
2011-08-05 12:25:00 +00:00
inline void Flush()
{
if ( deviceCallback ) { deviceCallback(devicePointer, NULL, 0); }
}
inline size_t Width()
{
return deviceWidth(devicePointer);
}
inline size_t Height()
{
return deviceHeight(devicePointer);
}
inline bool Sync()
{
return deviceSync(devicePointer);
}
2011-08-05 12:25:00 +00:00
inline size_t Print(const char* str)
{
if ( !deviceCallback ) { return 0; }
return deviceCallback(devicePointer, str, strlen(str));
}
inline size_t PrintData(const void* ptr, size_t size)
{
if ( !deviceCallback ) { return 0; }
return deviceCallback(devicePointer, (const char*) ptr, size);
2011-08-05 12:25:00 +00:00
}
inline size_t PrintF(const char* format, ...)
{
va_list list;
va_start(list, format);
size_t result = vprintf_callback(deviceCallback, devicePointer, format, list);
2011-08-05 12:25:00 +00:00
va_end(list);
return result;
}
inline size_t PrintFV(const char* format, va_list list)
{
return vprintf_callback(deviceCallback, devicePointer, format, list);
2011-08-05 12:25:00 +00:00
}
}
}
#endif