本文整理汇总了C++中EventQueue类的典型用法代码示例。如果您正苦于以下问题:C++ EventQueue类的具体用法?C++ EventQueue怎么用?C++ EventQueue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processQueue
void InputService::processQueue(EventQueue& queue)
{
// Send events which are piled on queue so far
size_t numEvents = queue.size(); // TODO: Do we have to limit by numEvents?
while (!queue.empty())
{
EventEntry& e = queue.front();
EventId id = e.eventID;
Ref<InputEvent> evt = e.event;
queue.pop_front();
if (evt && evt->isConsumed())
continue;
EventChannel* channel = e.channel;
if (channel)
{
// If channel specified on post : Send to that channel
channel->send(id, evt);
continue;
}
// When channel not specified: broadcast upward from source channel
if (evt == NULL)
continue; // Can't handle event with no channel specified.
// 1. Broadcast to source channel
Ref<InputSource> source = evt->getSource();
if (source && source->hasChannel())
{
source->channel()->send(id, evt);
if (evt->isConsumed() || !evt->isUplinking())
continue;
}
// 2. Broadcast to device channel
Weak<InputDevice> device = evt->getDevice();
if (device && device->hasChannel())
{
device->channel()->send(id, evt);
if (evt->isConsumed() || !evt->isUplinking())
continue;
}
// 3. Broadcast to user channel
Ref<InputUser> user = evt->getUser();
if (user && user->hasChannel())
{
user->channel()->send(id, evt);
if (evt->isConsumed() || !evt->isUplinking())
continue;
}
// TODO: 4. Broadcast to service channel?
}
}
示例2: TEST
TEST(A1UnitTestDemos, Interaction) {
StopWatch* watch = new StopWatch(XApplication::GetInstance()->GetEventQueue(), Rectangle(0, 0, 200, 75));
EXPECT_FALSE(watch == NULL);
// Create a synthetic mouse event to test whether watch responds to it
// or not. Note that this assumes that clicking in the location
// specified amounts to pressing the start/stop button. Your actual
// interaction will likely be different, making this test useless.
// However, this should provide a template for how to do unit tests
// for interaction.
EXPECT_FALSE(watch->GetParentWindow() == NULL);
MouseEvent* e = new MouseEvent(watch->GetParentWindow(), MouseEvent::mouseUp, Point(10, 10));
EventQueue* queue = XApplication::GetInstance()->GetEventQueue();
EXPECT_FALSE(queue == NULL);
EXPECT_FALSE(watch->IsRunning());
queue->AddEventToQueue(e);
unsigned int max_num_tries_to_flush_queue = 10;
while (max_num_tries_to_flush_queue-- > 0
&& queue->GetNumEventsInQueue() > 0
&& !watch->IsRunning())
{
queue->ProcessNextEvent();
}
EXPECT_TRUE(watch->IsRunning());
queue->ClearEventQueue();
delete watch;
// We do not need to delete the mouse event that we created, because
// it will be deleted automatically by the EventQueue.
}
示例3: authorize
bool authorize(const Service& authService,
Identity *providerIdentity,
ProviderSession *session,
const CorrelationId& cid)
{
{
MutexGuard guard(&g_lock);
g_authorizationStatus[cid] = WAITING;
}
EventQueue tokenEventQueue;
session->generateToken(CorrelationId(), &tokenEventQueue);
std::string token;
Event event = tokenEventQueue.nextEvent();
if (event.eventType() == Event::TOKEN_STATUS ||
event.eventType() == Event::REQUEST_STATUS) {
MessageIterator iter(event);
while (iter.next()) {
Message msg = iter.message();
{
MutexGuard guard(&g_lock);
msg.print(std::cout);
}
if (msg.messageType() == TOKEN_SUCCESS) {
token = msg.getElementAsString(TOKEN);
}
else if (msg.messageType() == TOKEN_FAILURE) {
break;
}
}
}
if (token.length() == 0) {
MutexGuard guard(&g_lock);
std::cout << "Failed to get token" << std::endl;
return false;
}
Request authRequest = authService.createAuthorizationRequest();
authRequest.set(TOKEN, token.c_str());
session->sendAuthorizationRequest(
authRequest,
providerIdentity,
cid);
time_t startTime = time(0);
const int WAIT_TIME_SECONDS = 10;
while (true) {
{
MutexGuard guard(&g_lock);
if (WAITING != g_authorizationStatus[cid]) {
return AUTHORIZED == g_authorizationStatus[cid];
}
}
time_t endTime = time(0);
if (endTime - startTime > WAIT_TIME_SECONDS) {
return false;
}
SLEEP(1);
}
}
示例4: testThread
void testThread(int n, ServiceLocator* aDifferentThreadsLocator) {
ServiceLocator* loc = ServiceLocator::getDefaultLocator();
ServiceLocator* loc2 = ServiceLocator::getDefaultLocator();
Timer* timer1 = loc->locateTimerService();
Timer* timer2 = loc2->locateTimerService();
MessageService* mes1 = loc->locateMessageService();
MessageService* mes2 = loc2->locateMessageService();
assert(mes1 == mes2);
mes1->publish("someMessage", StringMap());
MessageService* mes3 = aDifferentThreadsLocator->locateMessageService();
mes3->publish("aMessage", StringMap());
EventQueue* eq = loc->locateEventService();
eq->pushTimerEvent(loc->locateTimerService()->getTimeStamp());
assert(loc == loc2);
assert(loc != aDifferentThreadsLocator);
assert(loc != NULL);
assert(aDifferentThreadsLocator != NULL);
assert(timer1 == timer2);
assert(mes1 != NULL);
assert(mes3 != NULL);
assert(mes1 != mes3);
}
示例5: ProbeEvent
void
SimpleNbmtr::start(int sk)
{
EventQueue * q = EventQueue::Instance();
q->add_event(new ProbeEvent(time(NULL) + probe_interval, this, sk));
q->add_event(new SaveEvent(time(NULL) + save_interval, this));
}
示例6: main
int main()
{
Link link("L1", 10000000, 0.01, 64000);
Node node1("H1");
Node node2("H2");
NetworkManager* nm = NetworkManager::getInstance();
nm->registerLink(link);
nm->registerNode(node1);
nm->registerNode(node2);
nm->connectLink("L1", "H1", "H2");
Flow flow("F1", "H1", "H2", 20000000, TCP_RENO_t, 1);
nm->registerFlow(flow);
EventQueue* eq = EventQueue::getInstance();
eq->run();
Logger * logger = Logger::getInstance();
delete logger;
return EXIT_SUCCESS;
}
示例7: while
void GlobalEventQueue::Cycle( ncycle_t steps )
{
EventQueue *nextEventQueue;
ncycle_t iterationSteps = 0;
while( iterationSteps < steps )
{
ncycle_t nextEvent = GetNextEvent( &nextEventQueue );
ncycle_t globalQueueSteps = 0;
if( nextEvent > currentCycle )
{
globalQueueSteps = nextEvent - currentCycle;
}
/* Next event occurs after the current number of steps. */
if( globalQueueSteps > (steps - iterationSteps))
{
currentCycle += steps - iterationSteps;
Sync( );
break;
}
ncycle_t localQueueSteps = nextEventQueue->GetNextEvent( ) - nextEventQueue->GetCurrentCycle( );
nextEventQueue->Loop( localQueueSteps );
currentCycle += globalQueueSteps;
iterationSteps += globalQueueSteps;
Sync( );
}
}
示例8: DCHECK
void IDBDatabase::closeConnection() {
DCHECK(m_closePending);
DCHECK(m_transactions.isEmpty());
if (m_backend) {
m_backend->close();
m_backend.reset();
}
if (m_databaseCallbacks)
m_databaseCallbacks->detachWebCallbacks();
if (m_contextStopped || !getExecutionContext())
return;
EventQueue* eventQueue = getExecutionContext()->getEventQueue();
// Remove any pending versionchange events scheduled to fire on this
// connection. They would have been scheduled by the backend when another
// connection attempted an upgrade, but the frontend connection is being
// closed before they could fire.
for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) {
bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get());
DCHECK(removed);
}
}
示例9: ASSERT
void IDBRequest::abort()
{
ASSERT(!m_requestAborted);
if (m_contextStopped || !scriptExecutionContext())
return;
ASSERT(m_readyState == PENDING || m_readyState == DONE);
if (m_readyState == DONE)
return;
// Enqueued events may be the only reference to this object.
RefPtr<IDBRequest> self(this);
EventQueue* eventQueue = scriptExecutionContext()->eventQueue();
for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) {
bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get());
ASSERT_UNUSED(removed, removed);
}
m_enqueuedEvents.clear();
m_errorCode = 0;
m_error.clear();
m_errorMessage = String();
m_result.clear();
onError(IDBDatabaseError::create(IDBDatabaseException::IDB_ABORT_ERR, "The transaction was aborted, so the request cannot be fulfilled."));
m_requestAborted = true;
}
示例10: SystemActivities_GetNextPendingEvent
eVrApiEventStatus SystemActivities_GetNextPendingEvent( EventQueue * queue, char * buffer, unsigned int const bufferSize )
{
if ( buffer == NULL || bufferSize == 0 )
{
return VRAPI_EVENT_ERROR_INVALID_BUFFER;
}
if ( bufferSize < 2 )
{
buffer[0] = '\0';
return VRAPI_EVENT_ERROR_INVALID_BUFFER;
}
if ( queue == NULL )
{
return VRAPI_EVENT_ERROR_INTERNAL;
}
EventQueue * q = reinterpret_cast< EventQueue* >( queue );
EventData const * eventData;
if ( !q->Dequeue( eventData ) )
{
return VRAPI_EVENT_NOT_PENDING;
}
OVR_strncpy( buffer, bufferSize, static_cast< char const * >( eventData->GetData() ), eventData->GetSize() );
bool overflowed = eventData->GetSize() >= bufferSize;
delete eventData;
return overflowed ? VRAPI_EVENT_BUFFER_OVERFLOW : VRAPI_EVENT_PENDING;
}
示例11: interrupt
// interrupt handler. this just adds a quit event to the queue.
static
void
interrupt(Arch::ESignal, void* data)
{
EventQueue* events = static_cast<EventQueue*>(data);
events->addEvent(Event(Event::kQuit));
}
示例12: ASSERT
void IDBDatabase::enqueueEvent(PassRefPtr<Event> event)
{
ASSERT(scriptExecutionContext()->isDocument());
EventQueue* eventQueue = static_cast<Document*>(scriptExecutionContext())->eventQueue();
event->setTarget(this);
eventQueue->enqueueEvent(event.get());
m_enqueuedEvents.append(event);
}
示例13: ASSERT
void IDBDatabase::enqueueEvent(PassRefPtr<Event> event)
{
ASSERT(!m_contextStopped);
ASSERT(scriptExecutionContext());
EventQueue* eventQueue = scriptExecutionContext()->eventQueue();
event->setTarget(this);
eventQueue->enqueueEvent(event.get());
m_enqueuedEvents.append(event);
}
示例14: main
int
main(int argc, char **argv)
{
dbgopen(stderr);
if (argc != 3)
{
cerr << "usage: " << argv[0] << " maxcount readernum" << endl;
return(2);
}
int arg=0;
int imax = ::atoi(argv[++arg]);
MustBeTrue(imax > 0);
int nreaders = ::atoi(argv[++arg]);
MustBeTrue(nreaders > 0);
EventQueue<int> eq;
std::list<UseCntPtr<Reader> > readers;
std::list<UseCntPtr<SimpleThread> > threads;
for (int ireader=1; ireader<=nreaders; ++ireader)
{
UseCntPtr<Reader> reader(new Reader(ireader, eq));
readers.push_back(reader);
UseCntPtr<SimpleThread> st(new SimpleThread(reader));
MustBeTrue(st->isOk());
MustBeTrue(st->run() == 0);
MustBeTrue(st->isOk());
threads.push_back(st);
}
SimpleThread st(new Writer(0, imax, eq));
MustBeTrue(st.isOk());
MustBeTrue(st.run() == 0);
MustBeTrue(st.isOk());
void *retval;
st.join(retval);
eq.done();
std::list<UseCntPtr<SimpleThread> >::iterator iter = threads.begin();
std::list<UseCntPtr<SimpleThread> >::iterator iterend = threads.end();
for ( ; iter != iterend; ++iter)
{
(*iter)->join(retval);
}
return(0);
}
示例15: ASSERT_WITH_MESSAGE
void IDBTransaction::enqueueEvent(PassRefPtrWillBeRawPtr<Event> event)
{
ASSERT_WITH_MESSAGE(m_state != Finished, "A finished transaction tried to enqueue an event of type %s.", event->type().utf8().data());
if (m_contextStopped || !executionContext())
return;
EventQueue* eventQueue = executionContext()->eventQueue();
event->setTarget(this);
eventQueue->enqueueEvent(event);
}