~ fixed registerEvent
This commit is contained in:
parent
a1f9f62f51
commit
7bb6846b33
@ -1,9 +1,9 @@
|
||||
|
||||
#include "KeyCode.h"
|
||||
|
||||
KeyCode::KeyCode(int16_t value) noexcept : value(value) {}
|
||||
KeyCode::KeyCode(int value) noexcept : value(value) {}
|
||||
|
||||
int16_t KeyCode::getValue() {
|
||||
int KeyCode::getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,10 @@
|
||||
|
||||
class KeyCode {
|
||||
private:
|
||||
int16_t value;
|
||||
int value;
|
||||
public:
|
||||
explicit KeyCode(int16_t value) noexcept;
|
||||
int16_t getValue();
|
||||
explicit KeyCode(int value) noexcept;
|
||||
int getValue();
|
||||
};
|
||||
|
||||
const static KeyCode Backspace = KeyCode(8);
|
||||
|
@ -69,35 +69,31 @@ void writeSharedMemory(char *data, int size, int offset) {
|
||||
}
|
||||
}
|
||||
|
||||
void getSharedMemory(char *address, int size, int offset) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
char *getSharedMemory() {
|
||||
/*
|
||||
int shmId = shmget(impl.sharedMemoryKey, NULL, 0);
|
||||
if(shmId < 0) {
|
||||
return nullptr;
|
||||
// we could return -1, not sure if it will be useful to continue after there is no shm allocated for any reason
|
||||
} else {
|
||||
return (char *) shmat(shmId, NULL, 0);
|
||||
}
|
||||
*/
|
||||
constexpr bool useLocal = false;
|
||||
|
||||
if(useLocal){
|
||||
//using a local buffer for shared memory testing
|
||||
if (localSharedMemory.empty()) {
|
||||
initSemaphore();
|
||||
localSharedMemory.resize(impl.sharedMemorySize * 1024);
|
||||
}
|
||||
|
||||
return &localSharedMemory[0];
|
||||
}else {
|
||||
int shmId = shmget(impl.sharedMemoryKey, NULL, 0);
|
||||
if(shmId < 0) {
|
||||
// we could return -1, not sure if it will be useful to continue after there is no shm allocated for any reason
|
||||
return nullptr;
|
||||
} else {
|
||||
return (char *) shmat(shmId, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void getSharedMemory(char *address, int size, int offset) {
|
||||
lockSharedMemory();
|
||||
memcpy(address, getSharedMemory() + offset, size);
|
||||
unlockSharedMemory();
|
||||
}
|
||||
|
||||
int getSharedMemorySize() {
|
||||
|
@ -46,7 +46,7 @@ Color getPixel(int x, int y);
|
||||
* @param handler function to call.
|
||||
* @return true if handler could be registered, false if it failed.
|
||||
*/
|
||||
bool registerEvent(EventType type, std::function<void()> handler);
|
||||
bool registerEvent(EventType type, const std::function<void()> &handler);
|
||||
|
||||
/**
|
||||
* set displayed text in Text mode
|
||||
|
Loading…
Reference in New Issue
Block a user