merged cleanup
This commit is contained in:
@ -2,11 +2,11 @@
|
||||
#include "kernel/Globals.h"
|
||||
|
||||
void KeyEventListener::trigger(char c) {
|
||||
this->lastChar = c;
|
||||
lastChar = c;
|
||||
}
|
||||
|
||||
char KeyEventListener::waitForKeyEvent() const {
|
||||
Logger::instance() << DEBUG << "KEvLis:: Thread with id: " << tid << " waiting for key event" << endl;
|
||||
scheduler.block();
|
||||
return this->lastChar; // This is only executed after thread is woken up by manager
|
||||
return lastChar; // This is only executed after thread is woken up by manager
|
||||
}
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
#ifndef __KeyEventListener_Include_H_
|
||||
#define __KeyEventListener_Include_H_
|
||||
#ifndef KeyEventListener_Include_H_
|
||||
#define KeyEventListener_Include_H_
|
||||
|
||||
#include "kernel/threads/Thread.h"
|
||||
|
||||
class KeyEventListener {
|
||||
private:
|
||||
KeyEventListener(const KeyEventListener& copy) = delete;
|
||||
|
||||
char lastChar = '\0';
|
||||
|
||||
public:
|
||||
friend class KeyEventManager;
|
||||
unsigned int tid; // Thread which contains this listener, so the listener can block the thread
|
||||
|
||||
public:
|
||||
KeyEventListener(const KeyEventListener& copy) = delete;
|
||||
|
||||
KeyEventListener(unsigned int tid) : tid(tid) {}
|
||||
|
||||
char waitForKeyEvent() const; // Blocks the thread until woken up by manager
|
||||
|
||||
@ -3,14 +3,14 @@
|
||||
|
||||
void KeyEventManager::subscribe(KeyEventListener& sub) {
|
||||
log.debug() << "Subscribe, Thread ID: " << dec << sub.tid << endl;
|
||||
this->listeners.push_back(&sub);
|
||||
listeners.push_back(&sub);
|
||||
}
|
||||
|
||||
void KeyEventManager::unsubscribe(KeyEventListener& unsub) {
|
||||
log.debug() << "Unsubscribe, Thread ID: " << dec << unsub.tid << endl;
|
||||
for (bse::vector<KeyEventListener*>::iterator it = listeners.begin(); it != listeners.end(); ++it) {
|
||||
if ((*it)->tid == unsub.tid) {
|
||||
this->listeners.erase(it);
|
||||
listeners.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,7 @@ void KeyEventManager::unsubscribe(KeyEventListener& unsub) {
|
||||
|
||||
void KeyEventManager::broadcast(char c) {
|
||||
log.trace() << "Beginning Broadcast" << endl;
|
||||
for (KeyEventListener* listener : this->listeners) {
|
||||
for (KeyEventListener* listener : listeners) {
|
||||
log.trace() << "Broadcasting " << c << " to Thread ID: " << dec << listener->tid << endl;
|
||||
listener->trigger(c);
|
||||
scheduler.deblock(listener->tid);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef __KeyEventManager_Include_H_
|
||||
#define __KeyEventManager_Include_H_
|
||||
#ifndef KeyEventManager_Include_H_
|
||||
#define KeyEventManager_Include_H_
|
||||
|
||||
#include "user/event/KeyEventListener.h"
|
||||
#include "user/lib/Logger.h"
|
||||
@ -10,13 +10,13 @@
|
||||
|
||||
class KeyEventManager {
|
||||
private:
|
||||
KeyEventManager(const KeyEventManager& copy) = delete;
|
||||
|
||||
NamedLogger log;
|
||||
|
||||
bse::vector<KeyEventListener*> listeners;
|
||||
|
||||
public:
|
||||
KeyEventManager(const KeyEventManager& copy) = delete;
|
||||
|
||||
KeyEventManager() : log("KEvMan"), listeners(true) {}
|
||||
|
||||
void init() {
|
||||
|
||||
Reference in New Issue
Block a user