2012-07-24 16:43:34 +00:00
|
|
|
/*******************************************************************************
|
2011-08-05 12:25:00 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
2011-08-05 12:25:00 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
This file is part of Sortix.
|
2011-08-05 12:25:00 +00:00
|
|
|
|
2013-07-10 13:26:01 +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
|
|
|
|
2013-07-10 13:26:01 +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
|
|
|
|
2013-07-10 13:26:01 +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
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
sortix/kernel/log.h
|
|
|
|
A system for logging various messages to the kernel log.
|
2011-08-05 12:25:00 +00:00
|
|
|
|
2012-07-24 16:43:34 +00:00
|
|
|
*******************************************************************************/
|
2011-08-05 12:25:00 +00:00
|
|
|
|
|
|
|
#ifndef SORTIX_LOG_H
|
|
|
|
#define SORTIX_LOG_H
|
|
|
|
|
2012-09-22 19:09:33 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2011-08-05 12:25:00 +00:00
|
|
|
|
|
|
|
namespace Sortix
|
|
|
|
{
|
|
|
|
namespace Log
|
|
|
|
{
|
2012-09-22 19:09:33 +00:00
|
|
|
extern size_t (*deviceCallback)(void*, const char*, size_t);
|
2012-07-24 16:43:34 +00:00
|
|
|
extern size_t (*deviceWidth)(void*);
|
|
|
|
extern size_t (*deviceHeight)(void*);
|
2012-12-23 20:00:17 +00:00
|
|
|
extern bool (*deviceSync)(void*);
|
2011-08-05 12:25:00 +00:00
|
|
|
extern void* devicePointer;
|
|
|
|
|
2012-09-22 19:09:33 +00:00
|
|
|
void Init(size_t (*callback)(void*, const char*, size_t),
|
2012-07-24 16:43:34 +00:00
|
|
|
size_t (*widthfunc)(void*),
|
|
|
|
size_t (*heightfunc)(void*),
|
2012-12-23 20:00:17 +00:00
|
|
|
bool (*syncfunc)(void*),
|
2012-07-24 16:43:34 +00:00
|
|
|
void* user);
|
2012-03-21 23:52:29 +00:00
|
|
|
|
2011-08-05 12:25:00 +00:00
|
|
|
inline void Flush()
|
|
|
|
{
|
|
|
|
if ( deviceCallback ) { deviceCallback(devicePointer, NULL, 0); }
|
|
|
|
}
|
|
|
|
|
2012-07-24 16:43:34 +00:00
|
|
|
inline size_t Width()
|
|
|
|
{
|
|
|
|
return deviceWidth(devicePointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t Height()
|
|
|
|
{
|
|
|
|
return deviceHeight(devicePointer);
|
|
|
|
}
|
|
|
|
|
2012-12-23 20:00:17 +00:00
|
|
|
inline bool Sync()
|
|
|
|
{
|
|
|
|
return deviceSync(devicePointer);
|
|
|
|
}
|
|
|
|
|
2011-08-05 12:25:00 +00:00
|
|
|
inline size_t Print(const char* str)
|
|
|
|
{
|
2012-01-22 01:12:52 +00:00
|
|
|
if ( !deviceCallback ) { return 0; }
|
2012-09-22 19:09:33 +00:00
|
|
|
return deviceCallback(devicePointer, str, strlen(str));
|
2012-01-22 01:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t PrintData(const void* ptr, size_t size)
|
|
|
|
{
|
|
|
|
if ( !deviceCallback ) { return 0; }
|
2012-03-21 23:52:29 +00:00
|
|
|
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);
|
2012-09-22 19:09:33 +00:00
|
|
|
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)
|
|
|
|
{
|
2012-09-22 19:09:33 +00:00
|
|
|
return vprintf_callback(deviceCallback, devicePointer, format, list);
|
2011-08-05 12:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|