Switched UIAbsEventCollector and UIRelEventCollector also to instant-send

This commit is contained in:
Ingo Ruhnke 2011-07-14 03:31:38 +02:00
parent bf4501edc7
commit fe705d2123
11 changed files with 38 additions and 55 deletions

View file

@ -29,18 +29,20 @@ UIAbsEventCollector::UIAbsEventCollector(UInput& uinput, uint32_t device_id, int
UIEventEmitterPtr
UIAbsEventCollector::create_emitter()
{
UIAbsEventEmitterPtr emitter(new UIAbsEventEmitter);
UIAbsEventEmitterPtr emitter(new UIAbsEventEmitter(*this));
m_emitters.push_back(emitter);
return m_emitters.back();
}
void
UIAbsEventCollector::send(int value)
{
m_uinput.send(get_device_id(), get_type(), get_code(), value);
}
void
UIAbsEventCollector::sync()
{
for(Emitters::iterator i = m_emitters.begin(); i != m_emitters.end(); ++i)
{
m_uinput.send(get_device_id(), get_type(), get_code(), (*i)->get_value());
}
}
/* EOF */

View file

@ -32,6 +32,7 @@ public:
UIAbsEventCollector(UInput& uinput, uint32_t device_id, int type, int code);
UIEventEmitterPtr create_emitter();
void send(int value);
void sync();
private:

View file

@ -18,7 +18,10 @@
#include "ui_abs_event_emitter.hpp"
UIAbsEventEmitter::UIAbsEventEmitter() :
#include "ui_abs_event_collector.hpp"
UIAbsEventEmitter::UIAbsEventEmitter(UIAbsEventCollector& collector) :
m_collector(collector),
m_value(0)
{
}
@ -26,13 +29,11 @@ UIAbsEventEmitter::UIAbsEventEmitter() :
void
UIAbsEventEmitter::send(int value)
{
m_value = value;
}
int
UIAbsEventEmitter::get_value() const
if (m_value != value)
{
return m_value;
m_value = value;
m_collector.send(m_value);
}
}
/* EOF */

View file

@ -21,16 +21,18 @@
#include "ui_event_emitter.hpp"
class UIAbsEventCollector;
class UIAbsEventEmitter : public UIEventEmitter
{
private:
UIAbsEventCollector& m_collector;
int m_value;
public:
UIAbsEventEmitter();
UIAbsEventEmitter(UIAbsEventCollector& collector);
void send(int value);
int get_value() const;
private:
UIAbsEventEmitter(const UIAbsEventEmitter&);

View file

@ -35,7 +35,6 @@ public:
virtual ~UIEventEmitter() {}
virtual void send(int value) = 0;
virtual int get_value() const = 0;
private:
UIEventEmitter(const UIEventEmitter&);

View file

@ -38,10 +38,4 @@ UIKeyEventEmitter::send(int value)
}
}
int
UIKeyEventEmitter::get_value() const
{
return m_value;
}
/* EOF */

View file

@ -33,7 +33,6 @@ public:
UIKeyEventEmitter(UIKeyEventCollector& collector);
void send(int value);
int get_value() const;
private:
UIKeyEventEmitter(const UIKeyEventEmitter&);

View file

@ -29,25 +29,20 @@ UIRelEventCollector::UIRelEventCollector(UInput& uinput, uint32_t device_id, int
UIEventEmitterPtr
UIRelEventCollector::create_emitter()
{
UIRelEventEmitterPtr emitter(new UIRelEventEmitter);
UIRelEventEmitterPtr emitter(new UIRelEventEmitter(*this));
m_emitters.push_back(emitter);
return m_emitters.back();
}
void
UIRelEventCollector::sync()
{
int value = 0;
for(Emitters::iterator i = m_emitters.begin(); i != m_emitters.end(); ++i)
{
value += (*i)->get_value();
(*i)->clear();
}
if (value != 0)
UIRelEventCollector::send(int value)
{
m_uinput.send(get_device_id(), get_type(), get_code(), value);
}
void
UIRelEventCollector::sync()
{
}
/* EOF */

View file

@ -32,6 +32,7 @@ public:
UIRelEventCollector(UInput& uinput, uint32_t device_id, int type, int code);
UIEventEmitterPtr create_emitter();
void send(int value);
void sync();
private:

View file

@ -18,27 +18,17 @@
#include "ui_rel_event_emitter.hpp"
UIRelEventEmitter::UIRelEventEmitter() :
m_value()
#include "ui_rel_event_collector.hpp"
UIRelEventEmitter::UIRelEventEmitter(UIRelEventCollector& collector) :
m_collector(collector)
{
}
void
UIRelEventEmitter::send(int value)
{
m_value = value;
}
int
UIRelEventEmitter::get_value() const
{
return m_value;
}
void
UIRelEventEmitter::clear()
{
m_value = 0;
m_collector.send(value);
}
/* EOF */

View file

@ -21,18 +21,17 @@
#include "ui_event_emitter.hpp"
class UIRelEventCollector;
class UIRelEventEmitter : public UIEventEmitter
{
private:
int m_value;
UIRelEventCollector& m_collector;
public:
UIRelEventEmitter();
UIRelEventEmitter(UIRelEventCollector& collector);
void send(int value);
int get_value() const;
void clear();
private:
UIRelEventEmitter(const UIRelEventEmitter&);