Merge branch 'dev' of ssh://gitlab.repo.digitech.hs-emden-leer.de:2222/link/projekte/ws19/vkvm-new/library into dev
This commit is contained in:
commit
9faf65438a
|
@ -1,5 +1,27 @@
|
|||
#include "internal.h"
|
||||
#include <sys/shm.h>
|
||||
Impl impl;
|
||||
|
||||
Internal internal;
|
||||
void *getSharedMemory(){
|
||||
impl.sharedMemorySize = 8000;
|
||||
|
||||
auto id = shmget(impl.sharedMemoryKey, impl.sharedMemorySize, 0644 | IPC_CREAT);
|
||||
if(id == -1){
|
||||
//error
|
||||
impl.sharedMemorySize = 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void *data = shmat(id, nullptr, 0);
|
||||
if(data == (char*)(-1)){
|
||||
//error
|
||||
impl.sharedMemorySize = 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
int getSharedMemorySize(){
|
||||
return impl.sharedMemorySize;
|
||||
}
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
#include "LayoutVersion.h"
|
||||
#include "GraphicMode.h"
|
||||
#include "Color.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
/**
|
||||
* the Control Registers
|
||||
* @author Julian Hinxlage
|
||||
* @since 0.1.0
|
||||
*/
|
||||
struct Registers{
|
||||
struct Registers {
|
||||
int layout_version;
|
||||
int trigger_reset;
|
||||
int width_pixels;
|
||||
|
@ -34,7 +35,7 @@ struct Registers{
|
|||
int keyboardBuffer_index_r;
|
||||
};
|
||||
|
||||
struct InterruptEntry{
|
||||
struct InterruptEntry {
|
||||
int pid;
|
||||
int signum;
|
||||
};
|
||||
|
@ -42,10 +43,16 @@ struct InterruptEntry{
|
|||
/**
|
||||
* internal values for the library.
|
||||
*/
|
||||
struct Internal{
|
||||
struct Impl {
|
||||
int sharedMemoryPid;
|
||||
key_t sharedMemoryKey;
|
||||
int sharedMemorySize;
|
||||
};
|
||||
extern Internal internal;
|
||||
extern Impl impl;
|
||||
|
||||
void *getSharedMemory();
|
||||
|
||||
int getSharedMemorySize();
|
||||
|
||||
/**
|
||||
* set layout version.
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
|
||||
/**
|
||||
* @author Julian Hinxlage
|
||||
* @since 0.1.0
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
#include <iostream>
|
||||
|
||||
//converts the level to a string of the level
|
||||
const char *getLevelName(LogLevel level){
|
||||
switch(level){
|
||||
case LogLevel::DEBUG:
|
||||
return "DEBUG";
|
||||
case LogLevel::INFO:
|
||||
return "INFO";
|
||||
case LogLevel::WARNING:
|
||||
return "WARNING";
|
||||
case LogLevel::ERROR:
|
||||
return "ERROR";
|
||||
case LogLevel::CRITICAL:
|
||||
return "CRITICAL";
|
||||
default:
|
||||
return "NON";
|
||||
}
|
||||
}
|
||||
|
||||
//converts the level to a ansi color code
|
||||
const char *getLevelColor(LogLevel level){
|
||||
switch(level){
|
||||
case LogLevel::DEBUG:
|
||||
return "0;37";
|
||||
case LogLevel::INFO:
|
||||
return "0";
|
||||
case LogLevel::WARNING:
|
||||
return "1;33";
|
||||
case LogLevel::ERROR:
|
||||
return "1;31";
|
||||
case LogLevel::CRITICAL:
|
||||
return "1;35";
|
||||
default:
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
LogLevel logLevel = LogLevel::INFO;
|
||||
|
||||
//log the current time
|
||||
void logTime(){
|
||||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
struct tm *timeinfo;
|
||||
timeinfo = localtime(&rawtime);
|
||||
|
||||
if (timeinfo->tm_hour < 10) {
|
||||
std::cout << "0";
|
||||
}
|
||||
std::cout << timeinfo->tm_hour;
|
||||
std::cout << ":";
|
||||
if (timeinfo->tm_min < 10) {
|
||||
std::cout << "0";
|
||||
}
|
||||
std::cout << timeinfo->tm_min;
|
||||
std::cout << ":";
|
||||
if (timeinfo->tm_sec < 10) {
|
||||
std::cout << "0";
|
||||
}
|
||||
std::cout << timeinfo->tm_sec;
|
||||
}
|
||||
|
||||
//log the message
|
||||
void log(const std::string &msg, LogLevel level) {
|
||||
if(level >= logLevel) {
|
||||
std::string levelName = getLevelName(level);
|
||||
int maxLevelNameLength = 8;
|
||||
|
||||
//time
|
||||
std::cout << "[";
|
||||
logTime();
|
||||
std::cout << "] ";
|
||||
|
||||
//color and level name;lo
|
||||
std::cout << "[";
|
||||
std::cout << "\033[" << getLevelColor(level) << "m" << levelName << "\033[0m";
|
||||
std::cout << "] ";
|
||||
for (int i = levelName.size(); i < maxLevelNameLength; i++) {
|
||||
std::cout << " ";
|
||||
}
|
||||
|
||||
//message
|
||||
for(char c : msg){
|
||||
if(c == '\n'){
|
||||
//intend newlines so that they align with the start of the message
|
||||
std::cout << "\n";
|
||||
for(int i = 0; i < 22;i++){
|
||||
std::cout << " ";
|
||||
}
|
||||
}else{
|
||||
std::cout << c;
|
||||
}
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void setLogLevel(LogLevel level) {
|
||||
logLevel = level;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef LIBRARY_LOG_H
|
||||
#define LIBRARY_LOG_H
|
||||
|
||||
#include <string>
|
||||
|
||||
enum LogLevel{
|
||||
DEBUG = 1,
|
||||
INFO = 2,
|
||||
WARNING = 3,
|
||||
ERROR = 4,
|
||||
CRITICAL = 5,
|
||||
OFF = 6
|
||||
};
|
||||
|
||||
/**
|
||||
* log the messgae with logLevel and timestamp
|
||||
* @author Julian Hinxlage
|
||||
* @since 0.1.0
|
||||
*/
|
||||
void log(const std::string &msg, LogLevel level = LogLevel::INFO);
|
||||
|
||||
|
||||
/**
|
||||
* set the logLevel, the log function will use this to determine if the message is logged
|
||||
* @author Julian Hinxlage
|
||||
* @since 0.1.0
|
||||
*/
|
||||
void setLogLevel(LogLevel level);
|
||||
|
||||
#endif //LIBRARY_LOG_H
|
|
@ -2,5 +2,7 @@
|
|||
#include "internal.h"
|
||||
|
||||
void initialize(int pid) {
|
||||
internal.sharedMemoryPid = pid;
|
||||
impl.sharedMemoryPid = pid;
|
||||
impl.sharedMemoryKey = 892348;
|
||||
impl.sharedMemorySize = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue