~ fixed clang-tidy errors

This commit is contained in:
Julian Hinxlage 2019-11-12 14:07:02 +01:00
parent 843be8d47c
commit f5c461a05b
14 changed files with 102 additions and 85 deletions

View File

@ -1,7 +1,7 @@
#include "Color.h"
Color::Color(unsigned char red, unsigned char green, unsigned char blue)
Color::Color(unsigned char red, unsigned char green, unsigned char blue) noexcept
: red(red), green(green), blue(blue){
}

View File

@ -15,7 +15,7 @@ private:
unsigned char blue;
public:
Color(unsigned char red, unsigned char green, unsigned char blue);
Color(unsigned char red, unsigned char green, unsigned char blue) noexcept;
unsigned char getRed();
unsigned char getGreen();

View File

@ -1,20 +1,25 @@
#include "FontType.h"
FontType::FontType(std::string name, int height, int width) {
FontType::FontType(int id, std::string name, int height, int width) noexcept {
this->id = id;
this->name = std::move(name);
this->height = height;
this->width = width;
}
std::string FontType::getName() {
int FontType::getId() const{
return id;
}
std::string FontType::getName() const{
return name;
}
int FontType::getHeight() {
int FontType::getHeight() const{
return height;
}
int FontType::getWidth() {
int FontType::getWidth() const{
return width;
}

View File

@ -1,25 +1,27 @@
#include <utility>
#ifndef LIBRARY_FONT_H
#define LIBRARY_FONT_H
#include <string>
#include <utility>
class FontType {
private:
int id;
std::string name;
int height;
int width;
public:
FontType(std::string name, int height, int width);
std::string getName();
int getHeight();
int getWidth();
FontType(int id, std::string name, int height, int width) noexcept;
int getId() const;
std::string getName() const;
int getHeight() const;
int getWidth() const;
};
const static FontType font_1 = FontType("DummyFont", 10, 5);
const static FontType font_1 = FontType(1, "DummyFont", 10, 5);
#endif

View File

@ -1,9 +1,9 @@
#include "KeyCode.h"
KeyCode::KeyCode(int value) : value(value) {}
KeyCode::KeyCode(int16_t value) noexcept : value(value) {}
int KeyCode::getValue() {
int16_t KeyCode::getValue() {
return value;
}

View File

@ -1,12 +1,14 @@
#ifndef LIBRARY_KEYCODE_H
#define LIBRARY_KEYCODE_H
#include <sys/types.h>
class KeyCode {
private:
int value;
int16_t value;
public:
explicit KeyCode(int value);
int getValue();
explicit KeyCode(int16_t value) noexcept;
int16_t getValue();
};
const static KeyCode Backspace = KeyCode(8);

View File

@ -1,24 +1,24 @@
//
// Created by Cigerxwin Chaker on 05.11.19.
//
#include <iostream>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/sem.h>
#include <unistd.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "internal.h"
#include "SharedMemoryAccess.h" /* header is important for the shmID. name could be different. maybe not needed cause: (shmget(memory_access_key, NULL, 0)) */
#include "internal.h"
#define PERM 0666 /* Zugriffsrechte */
#define LOCK -1
#define UNLOCK 1
#define SEM_KEY 123458L
#define PERM 0666 /* access rights */
#define LOCK (-1)
#define UNLOCK (1)
#define SEM_KEY (123458L)
//int memoryAccessKey; /* var type is int. but could be another type. */ //TODO: look after type in sharedmemory group
int semId;
@ -39,14 +39,15 @@ int initSemaphore () {
return -1;
}
/* Semaphor mit 1 initialisieren */
if (semctl (semId, 0, SETVAL, (int) 1) == -1)
if (semctl(semId, 0, SETVAL, 1) == -1){
return -1;
}
}
return 1;
}
int semaphoreOperation(int op) {
semaphore.sem_op = (short)op;
semaphore.sem_op = static_cast<int16_t>(op);
semaphore.sem_flg = SEM_UNDO;
if (semop(semId, &semaphore, 1) == -1) {
perror(" semop ");
@ -56,13 +57,10 @@ int semaphoreOperation (int op) {
}
void writeSharedMemory(char *data, int size, int offset) {
int shmId = shmget(impl.sharedMemoryKey, NULL, 0); // dont init just get the ID if already existing.
if(shmId < 0 ) {
return;
/* we could return -1, not sure if it will be useful to continue after there is no shm allocated for any reason*/
} else {
int shmId = shmget(impl.sharedMemoryKey, 0, 0); // dont init just get the ID if already existing.
if (shmId >= 0) {
std::cout << "writing" << std::endl;
char *shm_pointer = (char *) shmat(shmId, NULL, 0);
auto *shm_pointer = reinterpret_cast<char *>(shmat(shmId, nullptr, 0));
semaphoreOperation(LOCK);
memcpy(shm_pointer + offset, data, size);
shmdt(shm_pointer); //close shm_pointer
@ -72,16 +70,13 @@ void writeSharedMemory(char *data, int size, int offset) {
}
void getSharedMemory(char *address, int size, int offset) {
int shmId = shmget(impl.sharedMemoryKey, NULL, 0);
if(shmId < 0) {
return;
} else {
char *shm_pointer = (char *) shmat(shmId, NULL, 0);
int shmId = shmget(impl.sharedMemoryKey, 0, 0);
if (shmId >= 0) {
auto *shm_pointer = reinterpret_cast<char *>(shmat(shmId, nullptr, 0));
semaphoreOperation(LOCK);
memcpy(address, shm_pointer + offset, size);
shmdt(shm_pointer); //close shm_pointer
semaphoreOperation(UNLOCK);
return;
}
}

View File

@ -37,6 +37,6 @@ void unlockSharedMemory();
* @param size of data
* @param offset where the data is written on the shared memory
*/
void writeSharedMemory(char *date, int size, int offset);
void writeSharedMemory(char *data, int size, int offset);
#endif //LIBRARY_SHAREDMEMORYACCESSS_H

View File

@ -2,8 +2,8 @@
#include "SharedMemoryAccess.h"
#include "vkvm.h"
#include <sys/shm.h>
#include <csignal>
#include <sys/shm.h>
Impl impl;
@ -16,11 +16,11 @@ void onSignal(int signalNumber, void(*callback)(int)) {
}
InterruptEntry *getInterrupTable(){
return (InterruptEntry*)(getSharedMemory() + sizeof(Registers) + impl.reservedSize);
return reinterpret_cast<InterruptEntry*>(getSharedMemory() + sizeof(Registers) + impl.reservedSize);
}
Registers *getRegisters(){
return (Registers*)getSharedMemory();
return reinterpret_cast<Registers*>(getSharedMemory());
}
char *getTextArea(){
@ -68,5 +68,11 @@ void setMousePosition(int x, int y) {
}
void buttonPressed(KeyCode keyCode) {
//TODO
lockSharedMemory();
auto reg = getRegisters();
if(reg->keyboardBuffer_index_write == sizeof(reg->keyboardBuffer)){
reg->keyboardBuffer_index_write = 0;
}
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode.getValue();
unlockSharedMemory();
}

View File

@ -32,9 +32,9 @@ struct Registers {
int textMode_font_height;
int mouse_pos_x;
int mouse_pos_y;
char keyboardBuffer[16];
int keyboardBuffer_index_w;
int keyboardBuffer_index_r;
short keyboardBuffer[16];
int keyboardBuffer_index_write;
int keyboardBuffer_index_read;
};
struct InterruptEntry {

View File

@ -8,7 +8,7 @@
#include <iostream>
//converts the level to a string of the level
const char *getLevelName(LogLevel level){
auto getLevelName(LogLevel level){
switch(level){
case LogLevel::DEBUG:
return "DEBUG";
@ -26,7 +26,7 @@ const char *getLevelName(LogLevel level){
}
//converts the level to a ansi color code
const char *getLevelColor(LogLevel level){
auto getLevelColor(LogLevel level){
switch(level){
case LogLevel::DEBUG:
return "0;37";
@ -72,7 +72,7 @@ void logTime(){
void log(const std::string &msg, LogLevel level) {
if(level >= logLevel) {
std::string levelName = getLevelName(level);
int maxLevelNameLength = 8;
const int maxLevelNameLength = 8;
//time
std::cout << "[";
@ -92,7 +92,8 @@ void log(const std::string &msg, LogLevel level) {
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++){
const int paddingSize = 22;
for(int i = 0; i < paddingSize;i++){
std::cout << " ";
}
}else{

View File

@ -1,14 +1,18 @@
#include "vkvm.h"
#include "internal.h"
#include "SharedMemoryAccess.h"
#include "internal.h"
#include "vkvm.h"
#include <unistd.h>
#include <csignal>
#include <unistd.h>
void initialize(int pid) {
impl.sharedMemoryPid = pid;
impl.sharedMemoryKey = 12345;
impl.sharedMemorySize = 8000;
const int sharedMemoryKey = 12345;
impl.sharedMemoryKey = sharedMemoryKey;
const int sharedMemorySize = 8000;
impl.sharedMemorySize = sharedMemorySize;
//set default values
setCharactersPerRow(60);
@ -23,7 +27,7 @@ void initialize(int pid) {
setTimerInterruptInterval(10);
}
bool registerEvent(EventType type, std::function<void()> handler) {
bool registerEvent(EventType type, const std::function<void()> &handler) {
int signum = SIGUSR1 + impl.eventTable.size();
auto ivt = getInterrupTable();
@ -55,10 +59,10 @@ bool setPixel(int x, int y, Color color) {
}
Color getPixel(int x, int y) {
//TODO: other than RGB colores
//TODO(julian): other than RGB colores
//only RGB colores for now
unsigned char *ptr = (unsigned char *)getPixelArea() + (y * getWidth() + x) * 3;
return Color(ptr[0], ptr[1], ptr[2]);
unsigned char *ptr = reinterpret_cast<unsigned char *>(getPixelArea()) + (y * getWidth() + x) * 3;
return {ptr[0], ptr[1], ptr[2]};
}
bool setText(std::string text) {
@ -82,11 +86,11 @@ std::string getText() {
}
LayoutVersion getLayoutVersion() {
return (LayoutVersion)getRegisters()->layout_version;
return static_cast<LayoutVersion>(getRegisters()->layout_version);
}
void reset() {
//TODO
//TODO(julian): reset
}
int getWidth() {
@ -168,14 +172,14 @@ int getCharactersPerColumn() {
}
FontType getFont() {
//TODO
//TODO(julian): get font properly
return font_1;
}
void setFont(FontType newValue) {
//TODO
void setFont(const FontType &newValue) {
//TODO(julian): setFont properly
lockSharedMemory();
getRegisters()->textMode_font = 0;
getRegisters()->textMode_font = newValue.getId();
unlockSharedMemory();
}
@ -184,6 +188,6 @@ std::pair<int, int> getMousePosition() {
}
KeyCode getLastPressedKey() {
//TODO
//TODO(julian): get key properly
return KeyCode(0);
}

View File

@ -1,14 +1,14 @@
#ifndef LIBRARY_VKVM_H
#define LIBRARY_VKVM_H
#include <string>
#include <functional>
#include "Color.h"
#include "EventType.h"
#include "GraphicMode.h"
#include "FontType.h"
#include "KeyCode.h"
#include "LayoutVersion.h"
#include <functional>
#include <string>
/**
* @since 0.1.0
@ -184,7 +184,7 @@ FontType getFont();
* set text mode font.
* @param newValue new text mode font.
*/
void setFont(FontType newValue);
void setFont(const FontType &newValue);
/**
* get current mouse position

View File

@ -2,7 +2,9 @@
#include "../src/vkvm.h"
TEST_CASE("add works") {
initialize(0);
setText("Hello World");
SECTION("equals") {
REQUIRE(getText() == "Hallo Welt");
REQUIRE(getText() == "Hello World");
}
}