X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FEvents%2FEvents_Loop.h;h=a11426f1b99263f8581a0d4b5640c14db9167bd3;hb=db0e21ea2f1117dd9af3320009ba8b50dc2e828b;hp=893ecb1994de3a38eb47581ffd950b128ff32c0b;hpb=37bf139347283d16d59b08079d52be5f6f29a38c;p=modules%2Fshaper.git diff --git a/src/Events/Events_Loop.h b/src/Events/Events_Loop.h index 893ecb199..a11426f1b 100644 --- a/src/Events/Events_Loop.h +++ b/src/Events/Events_Loop.h @@ -1,17 +1,22 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: Events_Loop.hxx // Created: Thu Mar 13 2014 // Author: Mikhail PONIKAROV -#ifndef Events_Loop_HeaderFile -#define Events_Loop_HeaderFile +#ifndef Events_Loop_H_ +#define Events_Loop_H_ #include #include #include +#include #include -/**\class Events_Lopp +class Events_MessageGroup; + +/**\class Events_Loop * \ingroup EventsLoop * \brief Base class that manages the receiving and sending of all * not Qt-events in the application. @@ -21,13 +26,27 @@ * Performing of events is processed in separated thread, so, sender takes * control back immideately. */ -class Events_Loop { - std::map > > - myListeners; ///< map from event ID to sender pointer to listeners that must be called for this +class Events_Loop +{ + /// map from event ID to sender pointer to listeners that must be called for this + std::map > > myListeners; + + /// map from event ID to listeners which must process message without waiting for flush + std::map myImmediateListeners; + + /// map from event ID to groupped messages (accumulated on flush) + std::map > myGroups; + + ///< set of messages that are flushed right now, so they are not grouped + std::set myFlushed; + + /// to process flushes or not + bool myFlushActive; //! The empty constructor, will be called at startup of the application, only once - Events_Loop() {}; -public: + Events_Loop() : myFlushActive(true) {} + + public: ///! Returns the main object of the loop, one per application. EVENTS_EXPORT static Events_Loop* loop(); //! Returns the unique event by the given name. Call this method only on initialization of object @@ -35,12 +54,32 @@ public: EVENTS_EXPORT static Events_ID eventByName(const char* theName); //! Allows to send an event - EVENTS_EXPORT void send(Events_Message& theMessage); + //! \param theMessage the enevt message to send + //! \param isGroup is true for grouping messages if possible + EVENTS_EXPORT void send(const std::shared_ptr& theMessage, bool isGroup = true); //! Registers (or adds if such listener is already registered) a listener //! that will be called on the event and from the defined sender - EVENTS_EXPORT void registerListener(Events_Listener* theListener, const Events_ID theID, - void* theSender = 0); + EVENTS_EXPORT void registerListener(Events_Listener* theListener, const Events_ID theID, + void* theSender = 0, bool theImmediate = false); + + //! Initializes sending of a group-message by the given ID + EVENTS_EXPORT void flush(const Events_ID& theID); + + //! Allows to disable flushes: needed in synchronization of document mechanism + //! (to synchronize all and only then flush create, update, etc in correct order) + EVENTS_EXPORT void activateFlushes(const bool theActivate); + + //! Clears all collected messages + EVENTS_EXPORT void clear(const Events_ID& theID); + + //! Enables flush without grouping for the given message + EVENTS_EXPORT void autoFlush(const Events_ID& theID, const bool theAuto = true); + + //! Returns true if the evement is flushed right now + EVENTS_EXPORT bool isFlushed(const Events_ID& theID); + //! Sets the flag that the event is flished right now + EVENTS_EXPORT void setFlushed(const Events_ID& theID, const bool theValue); }; #endif