本文整理汇总了C++中EventListener类的典型用法代码示例。如果您正苦于以下问题:C++ EventListener类的具体用法?C++ EventListener怎么用?C++ EventListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dispatchEvent
bool EventDispatcher::dispatchEvent( Event& event )
{
event.setSender( this );
EventDispatcher::EventListeners::iterator iter = listeners_.begin();
EventDispatcher::EventListeners::iterator endIter = listeners_.end();
EventListener* el;
// std::cout << "event dispatched: " << event.getType() << std::endl;
while (iter != endIter)
{
el = (*iter);
// std::cout << "listener of " << el->getType() << std::endl;
// std::cout << "comparsion result: " << (el->getType().compare(event.getType()) == 1) << std::endl;
if (el->getType().compare(event.getType()) == 0)
{
if (!el->exec(event))
{
return false;
}
}
++iter;
}
return true;
}
示例2: assert
void EventManager::writeCallback(int fd, short ev, void* arg)
{
assert(ev == EV_WRITE && instance()->writes.count(fd));
EventListener* eh = static_cast<EventListener*>(arg);
eh->onWrite(fd);
}
示例3: CPPUNIT_ASSERT
void EventListenerFixture::Should_Return_Correct_EventHandler_Function( )
{
EventListener< Mock_EventSubject >* fullEventListener = static_cast< EventListener< Mock_EventSubject >* >( _eventListener );
CPPUNIT_ASSERT( &Mock_EventSubject::EventHandler == fullEventListener->GetHandlerFunctor( ) );
CPPUNIT_ASSERT( &Mock_EventSubject::FalseEventHandler != fullEventListener->GetHandlerFunctor( ) );
}
示例4: lock
void KEventObject::FireEvent(const char* event, const ValueList& args)
{
// Make a copy of the listeners map here, because firing the event might
// take a while and we don't want to block other threads that just need
// too add event listeners.
EventListenerList listenersCopy;
{
Poco::FastMutex::ScopedLock lock(this->listenersMutex);
listenersCopy = listeners;
}
KObjectRef thisObject(this, true);
EventListenerList::iterator li = listenersCopy.begin();
while (li != listenersCopy.end())
{
EventListener* listener = *li++;
if (listener->Handles(event))
{
try
{
if (!listener->Dispatch(thisObject, args, true))
{
// Stop event dispatch if callback tells us
break;
}
}
catch (ValueException& e)
{
this->ReportDispatchError(e.ToString());
break;
}
}
}
}
示例5: perror
static void *serial_thread_handler(void *arg)
{
Connector *thiz = (Connector *)arg;
EventListener listener = thiz->open_listener;
PrivInfo *priv = (PrivInfo *)thiz->priv;
if ((priv->fd = open(priv->serial_port, O_RDWR | O_NOCTTY)) == -1)
{
if (listener.cb_func != NULL)
{
listener.cb_func(strerror(errno), listener.ctx);
}
perror("open serial fail");
}
serial_set_raw_mode(priv->fd);
serial_set_speed(priv->fd, priv->baud_rate);
serial_set_parity(priv->fd, DATA_BITS, PARITY_TYPE, STOP_BITS);
priv->status = 1;
if (listener.cb_func != NULL)
{
listener.cb_func(NULL, listener.ctx);
}
pthread_exit(NULL);
}
示例6: notify
void Event::notify(){
for (std::set<EventListener*>::iterator it=listeners.begin(); it!=listeners.end();){
EventListener* e = *it;
it++; // Increment before calling handler in case the handler removes this listener,
// which would invalidate the iterator.
e->handler();
}
}
示例7:
EventReciever::~EventReciever()
{
// unplug any EventListeners that points to this object
for(EventListener* l = _listeners.first(); _listeners.canMove(); l = _listeners.next()){
if (l != 0)
l->_unplug();
}
}
示例8:
void EventListener::Function::operator()(EventListener const& eventListener)
{
if (eventListener.getType() == this->_type)
{
eventListener.execute(this->_widget, this->_event);
++this->_executed;
}
}
示例9: notifyObservers
void InputManager::notifyObservers(QuadrantID q, EventType e)
{
// iterate through and call onEvent for each listener
std::list<EventListener *>::iterator it;
for (it = observers.begin(); it != observers.end(); ++it) {
EventListener *observer = (*it);
observer->onEvent(q, e);
}
}
示例10: getEventListeners
EventListener* EventTarget::getAttributeEventListener(const AtomicString& eventType)
{
const EventListenerVector& entry = getEventListeners(eventType);
for (size_t i = 0; i < entry.size(); ++i) {
EventListener* listener = entry[i].listener.get();
if (listener->isAttribute() && listener->belongsToTheCurrentWorld())
return listener;
}
return 0;
}
示例11: onended
void AudioScheduledSourceNode::notifyEnded()
{
EventListener* listener = onended();
if (!listener)
return;
RefPtr<Event> event = Event::create(eventNames().endedEvent, FALSE, FALSE);
event->setTarget(this);
listener->handleEvent(context()->scriptExecutionContext(), event.get());
}
示例12: getEventListeners
EventListener* EventTarget::getAttributeEventListener(const AtomicString& eventType)
{
const EventListenerVector& entry = getEventListeners(eventType);
for (const auto& eventListener : entry) {
EventListener* listener = eventListener.listener.get();
if (listener->isAttribute() && listener->belongsToTheCurrentWorld())
return listener;
}
return 0;
}
示例13: lock
void EventHandler::_broadcast(AmigoEvent &e)
{
std::lock_guard<std::mutex> lock(_mutex);
std::vector<EventListener*>::iterator it;
for(it=_listeners.begin(); it!=_listeners.end(); it++)
{
EventListener *l = *it;
l->onEvent(e);
}
}
示例14: removeListener
// removes any listeners that points to the same reciever and reciever callback method
// the Listener object created here doesn't have to be the same object that was added to addListener
// deleteObj is used if the EventListener whas created with new
void EventSender::removeListener(EventListener &listener, bool deleteObj /*= false*/) {
listener._sender = this;
int32_t idx = _listeners.indexOf(&listener);
if (idx > -1){
EventListener* l = _listeners[idx];
l->_unplug();
if (deleteObj)
delete l;
}
}
示例15: main
int main()
{
//Test case 1 : Shouldn't throw
{
try
{
EventListener listener;
EventConsumer consumer(listener);
listener.on_connect().set_function([](Connection&){});
consumer.on_disconnect().set_function([](Connection&){});
consumer.on_server_disconnect().set_function([](TCPServer&){});
consumer.on_event().set_function([](Connection&, const Event&){});
consumer.bind("hellomsg").set_function([](Connection&, const Event&){});
listener.run();
listener.join();
}
catch(Exception& e)
{
ASSERT(false, "Test case 1 failed: \n" << e.what());
}
}
#define TEST_THROW(n, slot, lambda) \
{ \
try \
{ \
EventListener listener; \
EventConsumer consumer1(listener); \
EventConsumer consumer2(listener); \
\
consumer1.slot.set_function(lambda); \
consumer2.slot.set_function(lambda); \
\
listener.run(); \
listener.join(); \
\
ASSERT(false, "Test case " n " failed: " \
"collision not detected."); \
} \
catch(Exception& e) \
{} \
}
//Test cases 3-6 : Should throw
TEST_THROW("3", on_disconnect(), [](Connection&){});
TEST_THROW("4", on_server_disconnect(), [](TCPServer&){});
TEST_THROW("5", on_event(), [](Connection&, const Event&){});
TEST_THROW("6", bind("hellomsg"), [](Connection&, const Event&){});
return EXIT_SUCCESS;
}