Example #1
0
//	Return TRUE if the contact never received any message (which means the contact may need an invitation)
//	Return FALSE if there is at least one message received (which means both parties have communicated successfully)
BOOL
TContact::Contact_FIsInvitationRecommended()
	{
	if ((m_uFlagsContact & FC_kfContactNeedsInvitation) == 0)
		return FALSE;
	if (m_paVaultEvents != NULL)
		{
		// Search the entire Chat Log to find any message received.  Of course this is not the most optimal code, however the Chat Log should be rather short if there has been no communication between the two parties.
		IEvent ** ppEventStop;
		IEvent ** ppEvent = m_paVaultEvents->m_arraypaEvents.PrgpGetEventsStop(OUT &ppEventStop);
		while (ppEvent != ppEventStop)
			{
			IEvent * pEvent = *--ppEventStop;
			AssertValidEvent(pEvent);
			EEventClass eEventClass = pEvent->EGetEventClass();
			if ((eEventClass == eEventClass_eMessageTextSent && pEvent->Event_FHasCompleted()) ||	// If the message was sent successfully (with a confirmation receipt), then there is no need to send an invitation because the remote contact has the JID of the account
				(eEventClass & eEventClass_kfReceivedByRemoteClient))								// Anything received by the remote client means there has been a communication between the two contacts, and therefore there is no need to send an invitaiton
				{
				m_uFlagsContact &= ~FC_kfContactNeedsInvitation;	// Remove the invitation flag
				return FALSE;
				}
			} // while
		} // if
	return TRUE;
	}
void CEventManager::ProcessEvents()
{
	while(!m_cEventList.empty())
	{
		IEvent* pEvent = *m_cEventList.begin();

		// Remove from the list now to avoid problems with sorting new events
		m_cEventList.erase(m_cEventList.begin());

		// Make range of listeners for the current event
		pair<EventIter, EventIter> range;
		range = m_cListeners.equal_range(pEvent->GetEventID());


		for(EventIter cMapIter = range.first; cMapIter != range.second; 
			cMapIter++)
		{
			// Call the callback function of each listener listening for this
			// event
			//if(cMapIter->second->m_pcListener->GetIsActive())
			{
				cMapIter->second->m_pfCallback(pEvent, 
					cMapIter->second->m_pcListener);
			}
		}

		// clean up the event's memory
		MMDELEVENT(pEvent);

		// Unregister any events
		UnregisterEvents();
	}
}	
Example #3
0
	void enableEvent(const std::string& eventName) {
		IEvent* event = findEvent(eventName);

		if (event != NULL) {
			event->setEnabled(true);
		}
	}
Example #4
0
int		Ncurses::run(IEvent &eventManager)
{
    int	pb;

    Update();
    timeout(_timeout);
    while ((pb = getch()) != 'q' || pb != KEY_ESC)
    {
        switch (pb)
        {
        case KEY_LEFT :
        {
            eventManager.KeyLeft();
            break;
        }
        case KEY_RIGHT :
        {
            eventManager.KeyRight();
            break;
        }
        case KEY_ESC :
        {
            eventManager.KeyEschap();
            break;
        }
        }
        eventManager.ChooseEvent();
    }
    return (1);
}
Example #5
0
void
WChatLog::SL_HyperlinkMouseHovering(const QUrl & url)
	{
	CStr strTip;
	QString sUrl = url.toString();
	CStr strUrl = sUrl;		// Convert the URL to UTF-8
	PSZUC pszUrl = strUrl;
	if (FIsSchemeCambrian(pszUrl))
		{
		const CHS chCambrianAction = ChGetCambrianActionFromUrl(pszUrl);
		if (chCambrianAction == d_chCambrianAction_None)
			{
			TIMESTAMP tsEventID;
			PSZUC pszAction = Timestamp_PchDecodeFromBase64Url(OUT &tsEventID, pszUrl + 2);
			Assert(pszAction[0] == d_chSchemeCambrianActionSeparator);
			IEvent * pEvent = m_pContactOrGroup->Vault_PFindEventByID(tsEventID);
			if (pEvent != NULL)
				pEvent->HyperlinkGetTooltipText(pszAction + 1, IOUT &strTip);
			else
				MessageLog_AppendTextFormatSev(eSeverityErrorWarning, "WChatLog::SL_HyperlinkMouseHovering() - Unable to find matching tsEventID $t from hyperlink $s\n", tsEventID, pszUrl);
			} // if
		sUrl = strTip.ToQString();
		}
	QToolTip::showText(QCursor::pos(), sUrl, this);
	} // SL_HyperlinkMouseHovering()
Boolean DetailsTreeHandler :: dispatchHandlerEvent ( IEvent& evt)
{
  if(evt.eventId() == WM_PRESPARAMCHANGED)
  {
     if(evt.parameter1() == PP_FONTNAMESIZE ||
        evt.parameter1() == PP_FONTHANDLE)
        return fontChanged(evt);
  }
  return Inherited::dispatchHandlerEvent(evt);
}
Example #7
0
	/* Checks the passed xmlNode for a recognized item (ToolButton, ToggleToolButton, Separator)
	 * Returns the widget or NULL if nothing useful is found
	 */
	GtkWidget* ToolbarCreator::createToolItem(xml::Node& node, GtkToolbar* toolbar) {
		const std::string nodeName = node.getName();
		GtkWidget* toolItem;

		if (nodeName == "separator") {
			toolItem = GTK_WIDGET(gtk_separator_tool_item_new());
		}
		else if (nodeName == "toolbutton" || nodeName == "toggletoolbutton") {
			// Found a button, load the values that are shared by both types
			const std::string name 		= node.getAttributeValue("name");
			const std::string icon 		= node.getAttributeValue("icon");
			const std::string tooltip 	= _(node.getAttributeValue("tooltip").c_str());
			const std::string action 	= node.getAttributeValue("action");

			if (nodeName == "toolbutton") {
				// Create a new GtkToolButton and assign the right callback
				toolItem = GTK_WIDGET(gtk_tool_button_new(NULL, name.c_str()));

			}
			else {
				// Create a new GtkToggleToolButton and assign the right callback
				toolItem = GTK_WIDGET(gtk_toggle_tool_button_new());

			}

			IEvent* event = GlobalEventManager().findEvent(action);
			if (event != NULL) {
				event->connectWidget(GTK_WIDGET(toolItem));

				// Tell the event to update the state of this button
				event->updateWidgets();
			} else {
				globalErrorStream() << "ToolbarCreator: Failed to lookup command " << action << "\n";
			}

			// Set the tooltip, if not empty
			if (!tooltip.empty()) {
				gtk_tooltips_set_tip(_tooltips, GTK_WIDGET(toolItem), tooltip.c_str(), "");
				//gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolItem), _tooltips, tooltip.c_str(), "");
			}

			// Load and assign the icon, if specified
			if (icon != "") {
				GtkWidget* image = gtk_image_new_from_pixbuf(gtkutil::getLocalPixbufWithMask(icon));
				gtk_widget_show(image);
				gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(toolItem), image);
			}
		}
		else {
			return NULL;
		}

		gtk_widget_show(toolItem);
		return toolItem;
	}
 virtual Boolean
   dispatchHandlerEvent ( IEvent &event )
   {
     Boolean stopProcessing = false;
     if (event.eventId() == 0x000F  &&   // WM_SETFOCUS
         event.parameter2().number1())   //   gaining focus
     {
        stopProcessing = true;
     }
     return stopProcessing;
   }
Example #9
0
void DummyDevDA::executeOutputLoop() {
    this->outputLoopRunning = true;
    while (outputLoopRunning) {
        this->outputEventQueue.waitForData();
        IEvent * event = this->outputEventQueue.pop();
        if (event) {
            cout << "DummyDevDA: " << event->getEventTypeID() << " " << event << endl;
            //delete event;
        }
    }
}
Example #10
0
 void EventManager::DoEvent(typeEventID theEventID,void* theContext)
 {
   std::map<const typeEventID, IEvent*>::const_iterator anIter =
     mList.find(theEventID);
   if (anIter != mList.end())
   {
     // Get the event to execute
     IEvent* anEvent = anIter->second;
     // Now call DoEvent for this event with theContext provided
     anEvent->DoEvent(theContext);
   }
 }
Example #11
0
int SyncReactor::epollDispatch()
{
    int ret = 0;
    int num = epoll_wait(_epfd, _epev, _maxEvents, 3000); 
    Log::DEBUG("wait done %d", num);

    for(int i  = 0; i < num; i++)
    {
        IEvent *ev = static_cast<IEvent *>(_epev[i].data.ptr);
        
        int events = 0;
        if((_epev[i].events & EPOLLHUP) ||
            _epev[i].events & EPOLLERR)
        {
            Log::WARN("EPOLLHUP | EPOLLERR event happen in %d", _epev[i].data.fd);
            events = events | IEvent::CLOSESOCK;
        }

        if(_epev[i].events & EPOLLIN)
            events |= IEvent::IOREADABLE;
        if(_epev[i].events & EPOLLOUT)
            events |= IEvent::IOWRITEABLE;
        if(ev->result() & IEvent::ACCEPT) 
            events |= IEvent::ACCEPT;

        ev->setResult(events);
        if(events & IEvent::CLOSESOCK)
        {
            delete ev;
            continue;
        }
        if(events & IEvent::ACCEPT)
        {
            extEvent(ev);
            continue;
        }
        
        ret = epoll_ctl(_epfd, EPOLL_CTL_DEL, ev->handle(), NULL);
        if(ret < 0)
        {
            Log::WARN("del event fd from epoll error, %d : %s", ev->handle(), strerror(errno));
        }

        if(_extReactor != NULL)
            _extReactor->post(ev);
        else
            extEvent(ev);
    }
    return num;
}
Example #12
0
void MyMain::main (IEvent & event)               // Do in this effective main function whatever you want!
{

  IString s;                                     // Two values we want the user to input.
  double d;

  switch (event.parameter1())                    // Use this to define the different parts of your program
     {
     case cmdStartUp:                            // This part will be run when the program first comes up.

        cout = text.stream();                    // Assign the KrTextOutput object's stream to cout
        cout.setf (ios::unitbuf);                // Unfortunately, the above line does not copy this property

        s = "Old value of the string";           // Since the user will be offered to use the old values,
        d = 42;                                  //   those should be set to a sensible value.

        wcin << "Please enter a string here:" >> s;
                                                 // Ask for a string with this text explaining what to do...
        wcin << "...and a number here:" >> d     // ...and for a number.
             << display;                         // The display manipulator will display all the
                                                 //   queries we've made (in one dialog window)

        if (wcin.ok())                           // The result of the last dialog
           cout << "You pressed OK.\n";
        else
           cout << "You aborted the dialog.\n";

        cout << "  s = " << s << "\n  d = " << d;

        break;                                   // Our effective main program ends here.
     };
};
Boolean DetailsTreeHandler :: fontChanged(IEvent& evt)
{
  IFUNCTRACE_DEVELOP();
  IContainerControl* thisContainer = (IContainerControl*)evt.window();
  IContainerControl* otherContainer;

  if(thisContainer==treeCnr) {
    otherContainer = &(treeCnr->detailsContainer());
  }
  else {
    otherContainer = treeCnr;
  }


  // We need to keep track of the top level entry to this    
  // function so that we avoid a ping-pong affect that could 
  // occur between the two containers on font a change. This 
  // works since the font change notification is WinSent.    
  Boolean fNested = treeCnr->fontChangeStarted();
  treeCnr->setFontChangeStarted(true);


  if(!fNested) {
       IFont newFont(thisContainer);
       otherContainer->setFont(newFont);
       treeCnr->setFontChangeStarted(false);
  }
  return false;
}
void MyMain::main (IEvent & event)               // Do in this effective main function whatever you want!
{

  switch (event.parameter1())                    // Use this to define the different parts of your program
     {
     case cmdStartUp:                            // This part will be run when the program first comes up.

        cout = text.stream();                    // Assign the KrTextOutput object's stream to cout
        cout.setf (ios::unitbuf);                // Unfortunately, the above line does not copy this property

        static KrBitfield bf;                    // Let the user click several options on/off independently
        int bf1 = bf.add ("Space");              // The int variables are used to identify the item later.
        int bf2 = bf.add ("Lots of Money");      // You may also define them a priori, but this is easier.
                                                 // All options are off by default, but his can be changed.

        static KrChoice ch;                      // Let the user choose exactly one of several choices.
        int ch1 = ch.add ("Betazoid");
        int ch2 = ch.add ("Klingon");
        ch.set (ch1);                            // One choice should be set as the default.

        wcin << "'Enterprise' has something to do with..." >> bf;
        wcin << "Deanna Troi is..." >> ch
             >> display;                         // The display manipulator will work with both
                                                 //   the >> and the << operator.

        cout << "Your choices:\n";
        cout << " 'Enterprise' has " << (bf.isChecked(bf1)?"something":"nothing") << " to do with Space\n";
        cout << " 'Enterprise' has " << (bf.isChecked(bf2)?"something":"nothing")
             << " to do with Lots of Money\n";
        cout << " Deanna Troi is " << (ch.get()==ch1?"Betazoid":"Klingon") << "\n";

        break;                                   // Our effective main program ends here.
     };
};
Example #15
0
  void EventManager::DoEvents(void* theContext)
  {
    std::map<const typeEventID, IEvent*>::const_iterator anIter =
      mList.begin();
    while(anIter != mList.end())
    {
      // Get the event to execute
      IEvent* anEvent = anIter->second;

      // Iterate to the next event
      anIter++;

      // Now call DoEvent for this event with theContext provided
      anEvent->DoEvent(theContext);
    }
  }
  Boolean dispatchHandlerEvent( IEvent& event )
  {
    if (event.eventId() == WM_CLOSE) {
      IMessageBox msgbox (event.controlWindow());

      IMessageBox::Response result = msgbox.show ("Do you want to close?",
          (IMessageBox::okCancelButton |
           IMessageBox::defButton1 |
           IMessageBox::applicationModal)
        );
      if (result == IMessageBox::ok) {
        return false;
      }
      return true;
    }
    return false;
  }
/**************************************************************************
* Class AHelpHandler :: keysHelpId - Handle the keys help request event   *
**************************************************************************/
bool
  AHelpHandler :: keysHelpId(IEvent& evt)
{
  evt.setResult(1000);                  //1000=keys help ID in
                                        //  ahellow5.ipf file

  return (true);                        //Event is always processed
} /* end AHelpHandler :: keysHelpId(...) */
Example #18
0
int EventLoop::ProcessEvents(int timeout) {
  int i, nt, n;

  n = CollectFileEvents(timeout);
  now_.SetNow();
  nt = DoTimeout();

  for(i = 0; i < n; i++) {
    IEvent *e = (IEvent *)evs_[i].data.ptr;
    uint32_t events = 0;
    if (evs_[i].events & EPOLLIN) events |= IOEvent::READ;
    if (evs_[i].events & EPOLLOUT) events |= IOEvent::WRITE;
    if (evs_[i].events & (EPOLLHUP | EPOLLERR)) events |= IOEvent::ERROR;
    e->OnEvents(events);
  }

  return nt + n;
}
Example #19
0
void TUIClientApp::processEvents() {
    while (this->inEventQueue.size()) {
        IEvent * event = this->inEventQueue.pop();
        if (event) {
            if (event->getEventTypeID() == HostEvent::EventTypeID()) {
                HostEvent * ipEventMsg = static_cast<HostEvent *>(event);
                IEvent * event2 = ipEventMsg->getPayload();
                if (event2->getEventTypeID() >= EPEventMsgTypeIDOffset) {
                    this->stubContainer.handleEvent(static_cast<IEventMsg<EPAddress> *>(event2));
                } else if (event2->getEventTypeID() == AttachedObjectsMsg::EventTypeID()) {
                    this->handleAttachedObjectsMsg(static_cast<AttachedObjectsMsg *>(event2));
                } else if (event2->getEventTypeID() == MulticastGroupInvitationMsg::EventTypeID()) {
                    this->handleMulticastGroupInvitationMsg(static_cast<MulticastGroupInvitationMsg *>(event2));
                }
            }
            delete event;
        }
    }
}
Example #20
0
void TweenSystem::actorRemovedCallback(const IEvent& event)
{
    if(event.getEventType() != ActorDestroyedEvent::m_type) {
        warn("TweenSystem expected ActorDestroyedEvent, but received something else.");
        return;
    }
    const ActorDestroyedEvent* e = dynamic_cast<const ActorDestroyedEvent*>(&event);
    for(auto i : tween_map[e->getId()])
        tweens.erase(i);
    tween_map.erase(e->getId());
}
Boolean
  ChildHelpHandler :: dispatchHandlerEvent ( IEvent& event )
{
  unsigned long activeWindow = true;
  switch ( event.eventId() )
  {
     case WM_ACTIVATE:
        // Frame is gaining or losing activation.
        activeWindow = event.parameter1().number1();
        // Fall into the WM_HELP case.
     case WM_HELP:
        // In case help is initialized only after this
        // frame window is activated.
        this->setActiveWindow( event, activeWindow );
        break;
     default:
        break;
  }
  return false;
}
Example #22
0
IBase::Boolean                                                              //V6
  ATimeHandler :: dispatchHandlerEvent(IEvent& event)                       //V6
{                                                                           //V6
  Boolean eventProcessed(false);        //Assume event will not be proccessed V6
/*--------------------------- Test the Event -----------------------------|   V6
| This event must be a timer event and parameter 1 must contain the       |   V6
|   ID of the timer that was started by this handler.                     |   V6
|------------------------------------------------------------------------*/ //V6
  if ((event.eventId() == WM_TIMER) && (event.parameter1() == timerId))     //V6
  {                                                                         //V6
/*------------------------- Process Timer Event --------------------------|   V6
| Process the timer event by calling the virtual function tick, which     |   V6
|   should be overridden by an inheriting class.  The returned boolean    |   V6
|   value determines whether the event was actually processed by tick.    |   V6
|   The default ATimeHandler::tick function does not process the event.   |   V6
|------------------------------------------------------------------------*/ //V6
    eventProcessed = tick(event);                                           //V6
  }                                                                         //V6
  return (eventProcessed);                                                  //V6
} /* end ATimeHandler :: dispatchHandlerEvent(...) */                       //V6
Boolean QFMotionPlayer::destroy(IEvent &event)
{
  if (event.dispatchingWindow() == window_p)
  {
#ifdef TRACE
  stampTime();
  *debugOutput << "Plugin window destroyed!:" << '\t' << &qf << endl;
#endif
  }

  return false;
}
Example #24
0
bool SceneState::handleEvent(const IEvent &event)
{
	if(event.getName() == CursorMovedEvent::name)
	{
		slotCursorMoved(static_cast<const CursorMovedEvent&>(event).coordinates);
	}
	else if(event.getName() == CursorLeftClickedEvent::name)
	{
		slotCursorLeftClicked(static_cast<const CursorLeftClickedEvent&>(event).coordinates);
	}
	else if(event.getName() == CursorRightClickedEvent::name)
	{
		slotCursorRightClicked(static_cast<const CursorRightClickedEvent&>(event).coordinates);
	}
	else if(event.getName() == KeyPressedEvent::name)
	{
		if(static_cast<const KeyPressedEvent&>(event).key == KeyboardKey::Esc)
			_backToMainMenuDialog->setVisible(true);
	}
	return false;
}
Example #25
0
int main(){

    // Preparing a factory
    string xmlSpecs("gamesInfo.xml");
    FactoryGame fac(xmlSpecs);

    // Build Escenarios
    string idScen("game.scenes.scene.sce001");
    cout<<"Building Scenario "<<idScen<<" "<<endl;	  
    pScene scene1=fac.buildScenarioById(idScen);

    string idScen2("game.scenes.scene.sce002");
    cout<<"Building Scenario "<<idScen2<<" "<<endl;	  
    pScene scene2=fac.buildScenarioById(idScen2);

    scene1->set_salida(scene2,s_norte,false);
    scene2->set_salida(scene1,s_sur,true);

    cout<<"Salidas disponibles desde scene1:"<<scene1->salidasDisponibles()<<endl;
	  
    // Build Event	  
    string cardinal=s_norte;
    string postMessage="Evento activado OK.";
    IEvent *event = new EventOpenConnection(scene1,
                                            cardinal,
                                            postMessage);
    
    cout<<"Activar evento sobre scene1:"<<event->activate()<<endl;
    cout<<"Salidas disponibles desde scene1:"<<scene1->salidasDisponibles()<<endl;;

    //
    cout<<"-- Usando objeto EventsQueue como wrapper de cola de evento"<<endl;
    EventsQueue eventsQueue;
    eventsQueue.push(event);
    eventsQueue.fire();	  
    return 0;
}
Example #26
0
void
WChatLog::SL_HyperlinkClicked(const QUrl & url)
	{
	QString sUrl = url.toString();
	CStr strUrl = sUrl;		// Convert the URL to UTF-8
	PSZUC pszUrl = strUrl;
	if (FIsSchemeCambrian(pszUrl))
		{
		const CHS chCambrianAction = ChGetCambrianActionFromUrl(pszUrl);
		if (chCambrianAction == d_chCambrianAction_None)
			{
			TIMESTAMP tsEventID;
			PSZUC pszAction = Timestamp_PchDecodeFromBase64Url(OUT &tsEventID, pszUrl + 2);
			Assert(pszAction[0] == d_chSchemeCambrianActionSeparator);
			IEvent * pEvent = m_pContactOrGroup->Vault_PFindEventByID(tsEventID);
			if (pEvent != NULL)
				{
				OCursorSelectBlock oCursor(pEvent, this);
				pEvent->HyperlinkClicked(pszAction + 1, INOUT &oCursor);
				return;
				}
			MessageLog_AppendTextFormatSev(eSeverityErrorWarning, "WChatLog::SL_HyperlinkClicked() - Unable to find matching tsEventID $t from hyperlink $s\n", tsEventID, pszUrl);
			}
		else
			{
			if (chCambrianAction == d_chCambrianAction_DisplayAllHistory)
				{
				CWaitCursor wait;
				m_fDisplayAllMessages = TRUE;
				ChatLog_EventsRepopulate();
				}
			} // if...else
		return;
		} // if
	if (url.scheme() != QLatin1String("file") && !url.isRelative())
		QDesktopServices::openUrl(url);
	} // SL_HyperlinkClicked()
Example #27
0
void TUIServerApp::executeInputLoop() {
    this->inputLoopRunning = true;
    while (inputLoopRunning) {
        this->inEventQueue.waitForData();
        IEvent * event = this->inEventQueue.pop();
        if (event) {
            //cout << event->getEventTypeID() << " " << event << endl;

            if (event->getEventTypeID() == HostEvent::EventTypeID()) {
               HostEvent * ipEventMsg = static_cast<HostEvent *>(event);
               IEvent * event2 = ipEventMsg->getPayload();
               //cout << event2->getEventTypeID() << " " << event2 << endl;

               if (event2->getAddressTypeID() == EPAddress::AddressTypeID()) {
                   this->tuiRouter.push(event2->getDuplicate());
                   /*
                   IEventMsg<EPAddress> * eventMsg = static_cast<IEventMsg<EPAddress> *>(event2);
                   map<int, IEventSink *>::iterator iter = this->eventSinkMap.find(eventMsg->getAddress().getEntityID());

                   if (iter != this->eventSinkMap.end()) {
                       //cout << "delivering: " << event2 << endl;
                       (*iter).second->push(event2->getDuplicate());

                   } else {
                       cout << "event nicht zustellber, entityID = " << eventMsg->getAddress().getEntityID() << endl;
                       delete event;
                   }
                   */
               } else if (event2->getEventTypeID() == SystemCmdMsg::EventTypeID()) {
                   this->handleSystemCmdMsg(ipEventMsg);
               }
           }
           delete event;
        }
    }
}
Example #28
0
void MyMain::main (IEvent & event)               // Do in this effective main function whatever you want!
{                                                //   However, please note that this function - unlike the
                                                 //   usual main() - will be left before the program exits.
                                                 //   Make sure to define all variables as static or use
                                                 //   new / delete for objects which must survive the exit
                                                 //   of the function.

  switch (event.parameter1())                    // Use this to define the different parts of your program
     {
     case cmdStartUp:                            // This part will be run when the program first comes up.
                                                 //   You may define more commands (e.g. as menu entries or
                                                 //   as subprocedures to be called from here) and add them
                                                 //   to this switch instruction.

        cout = text.stream();                    // Assign the KrTextOutput object's stream to cout
        cout.setf (ios::unitbuf);                // Unfortunately, the above line does not copy this property

        cout << "Hello, World!";

        break;                                   // Our effective main program ends here.
     };
};
Example #29
0
	void CGUIManager::OnEvent(IEvent & Event)
	{
		ImGuiIO& io = ImGui::GetIO();

		if (InstanceOf<SKeyboardEvent>(Event))
		{
			SKeyboardEvent KeyboardEvent = As<SKeyboardEvent>(Event);
			io.KeysDown[(int) KeyboardEvent.Key] = KeyboardEvent.Pressed;
			io.KeyCtrl = Window->IsKeyDown(EKey::LeftControl) || Window->IsKeyDown(EKey::RightControl);
			io.KeyShift = Window->IsKeyDown(EKey::LeftShift) || Window->IsKeyDown(EKey::RightShift);
			io.KeyAlt = Window->IsKeyDown(EKey::LeftAlt) || Window->IsKeyDown(EKey::RightAlt);
		}
		else if (InstanceOf<SMouseEvent>(Event))
		{
			SMouseEvent MouseEvent = As<SMouseEvent>(Event);
			switch (MouseEvent.Type)
			{
			case SMouseEvent::EType::Click:
				if (ImGui::IsMouseHoveringAnyWindow())
				{
					Event.Block();
				}
				MousePressed[(int) MouseEvent.Button] = MouseEvent.Pressed;
				break;
			case SMouseEvent::EType::Move:
				break;
			case SMouseEvent::EType::Scroll:
				MouseWheel += MouseEvent.Movement.Y;
				break;
			}
		}
		else if (InstanceOf<SCharacterEvent>(Event))
		{
			SCharacterEvent CharacterEvent = As<SCharacterEvent>(Event);
			if (CharacterEvent.C > 0)
				io.AddInputCharacter(CharacterEvent.C);
		}
	}
Example #30
0
IEventSPtr OMXComponent::WaitForGeneric(const list<IEventSPtr> &lstEvents, unsigned int uTimeoutMs)
{
	IEventSPtr pRes;
	uint32_t u32Sec;
	uint32_t u32NanoSec;

	m_pClock->GetCurrent(&u32Sec, &u32NanoSec);

	add_milliseconds(&u32Sec, &u32NanoSec, uTimeoutMs);

	bool bMatch = false;
	bool bFailure = false;

	// go until we either fail or succeed
	while ((!bFailure) && (!bMatch))
	{
		// go through all things we _can_ match with ...
		for (list<IEventSPtr>::const_iterator lsi = lstEvents.begin(); lsi != lstEvents.end(); lsi++)
		{
			// determine what type of event this is
			IEvent *pEvent = lsi->get();
			OMXEventData *pOMX = pEvent->ToEvent();
			EmptyBufferDoneData *pEmpty = pEvent->ToEmpty();
			FillBufferDoneData *pFill = pEvent->ToFill();

			Lock();

			if (pEmpty != NULL)
			{
				for (list<EmptyBufferDoneData>::iterator li = m_lstEmpty.begin(); li != m_lstEmpty.end(); li++)
				{
					if (li->pBuffer == pEmpty->pBuffer)
					{
						bMatch = true;
						m_lstEmpty.erase(li);
						pRes = *lsi;
						break;
					}
				}
			}

			// if we are waiting for an OMXEvent
			else if (pOMX != NULL)
			{
				for (list<OMXEventData>::iterator li = m_lstEvents.begin(); li != m_lstEvents.end(); li++)
				{
					// if we found the match
					if ((li->eEvent == pOMX->eEvent) && (pOMX->nData1 == li->nData1) && (pOMX->nData2 == li->nData2))
					{
						bMatch = true;
						m_lstEvents.erase(li);	// remove this item from the list because the caller knows about it now
						pRes = *lsi;
						break;	// must break here to about segfault since we just called erase()
					}
				}
			}
			else if (pFill != NULL)
			{
				for (list<FillBufferDoneData>::iterator li = m_lstFill.begin(); li != m_lstFill.end(); li++)
				{
					if (li->pBuffer == pFill->pBuffer)
					{
						bMatch = true;
						m_lstFill.erase(li);
						pRes = *lsi;
						break;
					}
				}
			}
			// else this should never happen
			else
			{
				assert(false);
			}

			Unlock();

			// if we found a match, we're done
			if (bMatch)
			{
				break;
			}
		}	// end for

		// if we didn't get a match we need to wait for success or a timeout
		if (!bMatch)
		{
			Lock();

			// If we got an error or timed out, then we're done
			// (this implicitly unlocks the mutex during the waiting period, then relocks it upon returning!)
			if (!m_pLocker->WaitForEvent(u32Sec, u32NanoSec))
			{
				bFailure = true;
			}

			Unlock();
		}

	} // end while we haven't succeeded or failed

	if (bFailure)
	{
		throw runtime_error("Waiting timed out");
	}

	return pRes;
}