X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FEvents%2FEvents_Loop.h;h=65f5491a6d7bdb6710e4dfa9af5efc4855b39683;hb=9270adddc12db9661c676544537b0e8eb78c1624;hp=d19dd4d4a39cee1fa832018961e49ea5b8702309;hpb=10afa56c18322075c75ff2616ac23853bd0c87ca;p=modules%2Fshaper.git diff --git a/src/Events/Events_Loop.h b/src/Events/Events_Loop.h index d19dd4d4a..65f5491a6 100644 --- a/src/Events/Events_Loop.h +++ b/src/Events/Events_Loop.h @@ -1,19 +1,35 @@ -// File: Events_Loop.hxx -// Created: Thu Mar 13 2014 -// Author: Mikhail PONIKAROV +// Copyright (C) 2014-2022 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// -#ifndef Events_Loop_HeaderFile -#define Events_Loop_HeaderFile +#ifndef Events_Loop_H_ +#define Events_Loop_H_ #include #include #include +#include #include class Events_MessageGroup; -/**\class Events_Lopp +/**\class Events_Loop * \ingroup EventsLoop * \brief Base class that manages the receiving and sending of all * not Qt-events in the application. @@ -23,17 +39,27 @@ class Events_MessageGroup; * Performing of events is processed in separated thread, so, sender takes * control back immideately. */ -class Events_Loop { +class Events_Loop +{ /// map from event ID to sender pointer to listeners that must be called for this - std::map > > - myListeners; + std::map > > myListeners; - /// map from event ID to groupped messages (accumulated on flush) - std::map myGroups; + /// 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 for 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 @@ -41,16 +67,52 @@ public: EVENTS_EXPORT static Events_ID eventByName(const char* theName); //! Allows to send an event + //! \param theMessage the enevt message to send //! \param isGroup is true for grouping messages if possible - EVENTS_EXPORT void send(Events_Message& theMessage, bool isGroup = true); + EVENTS_EXPORT void send(const std::shared_ptr& theMessage, bool isGroup = true); - //! Registers (or adds if such listener is already registered) a listener + //! 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); + //! \param theListener the object that will listen (process) the event + //! \param theID listen for messages with this ID + //! \param theSender listen only for this sender (NULL - listen everybody) + //! \param theImmediate for listeners who can not wait (no groupping mechanism is used for it) + EVENTS_EXPORT void registerListener(Events_Listener* theListener, const Events_ID theID, + void* theSender = 0, bool theImmediate = false); + + //! Remove the listener from internal maps if it was registered there + //! \param theListener a listener + EVENTS_EXPORT void removeListener(Events_Listener* theListener); //! Initializes sending of a group-message by the given ID EVENTS_EXPORT void flush(const Events_ID& theID); + + //! Removes messages with the given ID: they are not needed anymore (UPDATE on close) + EVENTS_EXPORT void eraseMessages(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) + //! \param theActivate a state about flushe is active. If false, the flush is disabled + //! \return the previous active flush state + EVENTS_EXPORT bool activateFlushes(const bool theActivate); + + //! Clears all collected messages + EVENTS_EXPORT void clear(const Events_ID& theID); + + //! 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); + + //! Returns true if a loop accumulated events to be flashed + EVENTS_EXPORT bool hasGrouppedEvent(const Events_ID& theID); + +private: + //! Calls "processEvent" for the given listeners. + //! If theFlushedNow for grouped listeners is stores message in listeners. + void sendProcessEvent(const std::shared_ptr& theMessage, + std::list& theListeners, const bool theFlushedNow); + }; #endif