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