From: mpv Date: Mon, 15 Sep 2014 08:17:35 +0000 (+0400) Subject: Move Events messages to boost pointers: partially done X-Git-Tag: V_0.4.4~57 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f796a1cc0ab2c9d545e1a642f1e207ece3316b82;p=modules%2Fshaper.git Move Events messages to boost pointers: partially done --- diff --git a/src/Config/Config_FeatureReader.cpp b/src/Config/Config_FeatureReader.cpp index 69d7176e4..19f4499e8 100644 --- a/src/Config/Config_FeatureReader.cpp +++ b/src/Config/Config_FeatureReader.cpp @@ -47,11 +47,12 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode) Events_ID aMenuItemEvent = Events_Loop::eventByName(myEventGenerated); if (isNode(theNode, NODE_FEATURE, NULL)) { Events_Loop* aEvLoop = Events_Loop::loop(); - Config_FeatureMessage aMessage(aMenuItemEvent, this); + boost::shared_ptr aMessage( + new Config_FeatureMessage(aMenuItemEvent, this)); fillFeature(theNode, aMessage); myFeatures.push_back(getProperty(theNode, _ID)); //If a feature has xml definition for it's widget: - aMessage.setUseInput(hasChild(theNode)); + aMessage->setUseInput(hasChild(theNode)); aEvLoop->send(aMessage); //The m_last* variables always defined before fillFeature() call. XML is a tree. } else if (isNode(theNode, NODE_GROUP, NULL)) { @@ -68,24 +69,25 @@ bool Config_FeatureReader::processChildren(xmlNodePtr theNode) return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NODE_FEATURE, NULL); } -void Config_FeatureReader::fillFeature(xmlNodePtr theNode, Config_FeatureMessage& outFeatureMessage) +void Config_FeatureReader::fillFeature(xmlNodePtr theNode, + const boost::shared_ptr& outFeatureMessage) { - outFeatureMessage.setId(getProperty(theNode, _ID)); - outFeatureMessage.setPluginLibrary(myLibraryName); - outFeatureMessage.setNestedFeatures(getProperty(theNode, FEATURE_NESTED)); + outFeatureMessage->setId(getProperty(theNode, _ID)); + outFeatureMessage->setPluginLibrary(myLibraryName); + outFeatureMessage->setNestedFeatures(getProperty(theNode, FEATURE_NESTED)); bool isInternal = isInternalFeature(theNode); - outFeatureMessage.setInternal(isInternal); + outFeatureMessage->setInternal(isInternal); if (isInternal) { //Internal feature has no visual representation. return; } - outFeatureMessage.setText(getProperty(theNode, FEATURE_TEXT)); - outFeatureMessage.setTooltip(getProperty(theNode, FEATURE_TOOLTIP)); - outFeatureMessage.setIcon(getProperty(theNode, FEATURE_ICON)); - outFeatureMessage.setKeysequence(getProperty(theNode, FEATURE_KEYSEQUENCE)); - outFeatureMessage.setGroupId(myLastGroup); - outFeatureMessage.setWorkbenchId(myLastWorkbench); + outFeatureMessage->setText(getProperty(theNode, FEATURE_TEXT)); + outFeatureMessage->setTooltip(getProperty(theNode, FEATURE_TOOLTIP)); + outFeatureMessage->setIcon(getProperty(theNode, FEATURE_ICON)); + outFeatureMessage->setKeysequence(getProperty(theNode, FEATURE_KEYSEQUENCE)); + outFeatureMessage->setGroupId(myLastGroup); + outFeatureMessage->setWorkbenchId(myLastWorkbench); } bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode) diff --git a/src/Config/Config_FeatureReader.h b/src/Config/Config_FeatureReader.h index f7547785c..c9535c34b 100644 --- a/src/Config/Config_FeatureReader.h +++ b/src/Config/Config_FeatureReader.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -29,7 +30,8 @@ class Config_FeatureReader : public Config_XMLReader void processNode(xmlNodePtr aNode); bool processChildren(xmlNodePtr aNode); - void fillFeature(xmlNodePtr theRoot, Config_FeatureMessage& outFeatureMessage); + void fillFeature(xmlNodePtr theRoot, + const boost::shared_ptr& outFeatureMessage); bool isInternalFeature(xmlNodePtr theRoot); private: diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index 26da54b51..3b206f3ce 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -155,18 +155,19 @@ void Config_XMLReader::processValidator(xmlNodePtr theNode) { Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED); Events_Loop* aEvLoop = Events_Loop::loop(); - Config_ValidatorMessage aMessage(aValidatoEvent, this); + boost::shared_ptr + aMessage(new Config_ValidatorMessage(aValidatoEvent, this)); std::string aValidatorId; std::list aValidatorParameters; getValidatorInfo(theNode, aValidatorId, aValidatorParameters); - aMessage.setValidatorId(aValidatorId); - aMessage.setValidatorParameters(aValidatorParameters); + aMessage->setValidatorId(aValidatorId); + aMessage->setValidatorParameters(aValidatorParameters); xmlNodePtr aFeatureOrWdgNode = theNode->parent; if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) { - aMessage.setFeatureId(getProperty(aFeatureOrWdgNode, _ID)); + aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID)); } else { - aMessage.setAttributeId(getProperty(aFeatureOrWdgNode, _ID)); - aMessage.setFeatureId(myCurrentFeature); + aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID)); + aMessage->setFeatureId(myCurrentFeature); } aEvLoop->send(aMessage); } diff --git a/src/Events/Events_Error.cpp b/src/Events/Events_Error.cpp index 7fe307b6a..3ac990edb 100644 --- a/src/Events/Events_Error.cpp +++ b/src/Events/Events_Error.cpp @@ -31,8 +31,9 @@ char* Events_Error::description() const void Events_Error::send(char* theDescription, const void* theSender) { - Events_Error anError(theDescription, theSender); - Events_Loop::loop()->send(anError); + boost::shared_ptr aNewOne = + boost::shared_ptr(new Events_Error(theDescription, theSender)); + Events_Loop::loop()->send(aNewOne); } void Events_Error::send(std::string theDescription, const void* theSender) diff --git a/src/Events/Events_Listener.h b/src/Events/Events_Listener.h index ac7714f02..f59bbd2f9 100644 --- a/src/Events/Events_Listener.h +++ b/src/Events/Events_Listener.h @@ -6,6 +6,8 @@ #define Events_Listener_H_ #include +#include + class Events_Message; /**\class Events_Listener @@ -20,7 +22,7 @@ class EVENTS_EXPORT Events_Listener public: //! This method is called by loop when the event is started to process. - virtual void processEvent(const Events_Message* theMessage) = 0; + virtual void processEvent(const boost::shared_ptr& theMessage) = 0; }; #endif diff --git a/src/Events/Events_LongOp.cpp b/src/Events/Events_LongOp.cpp index b4718608a..75b7a0dfd 100644 --- a/src/Events/Events_LongOp.cpp +++ b/src/Events/Events_LongOp.cpp @@ -33,8 +33,9 @@ void Events_LongOp::start(void* theSender) MY_SENDERS[theSender]++; if (toSend) { - Events_LongOp anEvent(theSender); - Events_Loop::loop()->send(anEvent); + boost::shared_ptr aNewOne = + boost::shared_ptr(new Events_LongOp(theSender)); + Events_Loop::loop()->send(aNewOne); } } @@ -48,8 +49,9 @@ void Events_LongOp::end(void* theSender) MY_SENDERS[theSender] = aCount - 1; } if (MY_SENDERS.empty()) { - Events_LongOp anEvent(theSender); - Events_Loop::loop()->send(anEvent); + boost::shared_ptr aNewOne = + boost::shared_ptr(new Events_LongOp(theSender)); + Events_Loop::loop()->send(aNewOne); } } diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index 1fb0ed178..04d94b088 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -37,19 +37,22 @@ Events_ID Events_Loop::eventByName(const char* theName) return Events_ID(aResult); } -void Events_Loop::send(Events_Message& theMessage, bool isGroup) +void Events_Loop::send(const boost::shared_ptr& theMessage, bool isGroup) { // if it is grouped message, just accumulate it if (isGroup) { - Events_MessageGroup* aGroup = dynamic_cast(&theMessage); + boost::shared_ptr aGroup = + boost::dynamic_pointer_cast(theMessage); if (aGroup) { - std::map::iterator aMyGroup = myGroups.find( + std::map >::iterator aMyGroup = myGroups.find( aGroup->eventID().eventText()); if (aMyGroup == myGroups.end()) { // create a new group of messages for accumulation myGroups[aGroup->eventID().eventText()] = aGroup->newEmpty(); aMyGroup = myGroups.find(aGroup->eventID().eventText()); } - aMyGroup->second->Join(*aGroup); + boost::shared_ptr aNewOne = + boost::dynamic_pointer_cast(aMyGroup->second); + aGroup->Join(aNewOne); return; } } @@ -57,21 +60,21 @@ void Events_Loop::send(Events_Message& theMessage, bool isGroup) // TO DO: make it in thread and with usage of semaphores map > >::iterator aFindID = myListeners.find( - theMessage.eventID().eventText()); + theMessage->eventID().eventText()); if (aFindID != myListeners.end()) { map >::iterator aFindSender = aFindID->second.find( - theMessage.sender()); + theMessage->sender()); if (aFindSender != aFindID->second.end()) { list& aListeners = aFindSender->second; for (list::iterator aL = aListeners.begin(); aL != aListeners.end(); aL++) - (*aL)->processEvent(&theMessage); + (*aL)->processEvent(theMessage); } - if (theMessage.sender()) { // also call for NULL senders registered + if (theMessage->sender()) { // also call for NULL senders registered aFindSender = aFindID->second.find(NULL); if (aFindSender != aFindID->second.end()) { list& aListeners = aFindSender->second; for (list::iterator aL = aListeners.begin(); aL != aListeners.end(); aL++) - (*aL)->processEvent(&theMessage); + (*aL)->processEvent(theMessage); } } } @@ -105,12 +108,12 @@ void Events_Loop::flush(const Events_ID& theID) { if (!myFlushActive) return; - std::map::iterator aMyGroup = myGroups.find(theID.eventText()); + std::map>::iterator aMyGroup = + myGroups.find(theID.eventText()); if (aMyGroup != myGroups.end()) { // really sends - Events_MessageGroup* aGroup = aMyGroup->second; + boost::shared_ptr aGroup = aMyGroup->second; myGroups.erase(aMyGroup); - send(*aGroup, false); - delete aGroup; + send(aGroup, false); } } diff --git a/src/Events/Events_Loop.h b/src/Events/Events_Loop.h index cd78497ed..3a02e16a6 100644 --- a/src/Events/Events_Loop.h +++ b/src/Events/Events_Loop.h @@ -29,7 +29,7 @@ class Events_Loop std::map > > myListeners; /// map from event ID to groupped messages (accumulated on flush) - std::map myGroups; + std::map > myGroups; /// to process flushes or not bool myFlushActive; @@ -46,7 +46,7 @@ class Events_Loop //! Allows to send an event //! \param isGroup is true for grouping messages if possible - EVENTS_EXPORT void send(Events_Message& theMessage, bool isGroup = true); + EVENTS_EXPORT void send(const boost::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 diff --git a/src/Events/Events_MessageGroup.h b/src/Events/Events_MessageGroup.h index 232c8d1b6..46c765cce 100644 --- a/src/Events/Events_MessageGroup.h +++ b/src/Events/Events_MessageGroup.h @@ -6,6 +6,7 @@ #define Events_MessageGroup_H_ #include +#include /**\class Events_Message * \ingroup EventsLoop @@ -30,9 +31,9 @@ class EVENTS_EXPORT Events_MessageGroup : public Events_Message } //! Creates a new empty group (to store it in the loop before flush) - virtual Events_MessageGroup* newEmpty() = 0; + virtual boost::shared_ptr newEmpty() = 0; //! Allows to join the given message with the current one - virtual void Join(Events_MessageGroup& theJoined) = 0; + virtual void Join(const boost::shared_ptr& theJoined) = 0; }; #endif diff --git a/src/Model/Model_Events.cpp b/src/Model/Model_Events.cpp index ae785563c..0d421704b 100644 --- a/src/Model/Model_Events.cpp +++ b/src/Model/Model_Events.cpp @@ -12,14 +12,16 @@ Model_EventCreator MY_CREATOR; void Model_EventCreator::sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent, const bool isGroupped) const { - Model_ObjectUpdatedMessage aMsg(theObject, theEvent); + boost::shared_ptr aMsg( + new Model_ObjectUpdatedMessage(theObject, theEvent)); Events_Loop::loop()->send(aMsg, isGroupped); } void Model_EventCreator::sendDeleted(const boost::shared_ptr& theDoc, const std::string& theGroup) const { - Model_ObjectDeletedMessage aMsg(theDoc, theGroup); + boost::shared_ptr aMsg( + new Model_ObjectDeletedMessage(theDoc, theGroup)); Events_Loop::loop()->send(aMsg, true); } @@ -42,15 +44,17 @@ std::set Model_ObjectUpdatedMessage::objects() const return myObjects; } -Events_MessageGroup* Model_ObjectUpdatedMessage::newEmpty() +boost::shared_ptr Model_ObjectUpdatedMessage::newEmpty() { ObjectPtr anEmptyObject; - return new Model_ObjectUpdatedMessage(anEmptyObject, eventID()); + return boost::shared_ptr( + new Model_ObjectUpdatedMessage(anEmptyObject, eventID())); } -void Model_ObjectUpdatedMessage::Join(Events_MessageGroup& theJoined) +void Model_ObjectUpdatedMessage::Join(const boost::shared_ptr& theJoined) { - Model_ObjectUpdatedMessage* aJoined = dynamic_cast(&theJoined); + boost::shared_ptr aJoined = + boost::dynamic_pointer_cast(theJoined); std::set::iterator aFIter = aJoined->myObjects.begin(); for (; aFIter != aJoined->myObjects.end(); aFIter++) { myObjects.insert(*aFIter); @@ -67,9 +71,9 @@ Model_ObjectDeletedMessage::Model_ObjectDeletedMessage( myGroups.insert(theGroup); } -Events_MessageGroup* Model_ObjectDeletedMessage::newEmpty() +boost::shared_ptr Model_ObjectDeletedMessage::newEmpty() { - return new Model_ObjectDeletedMessage(myDoc, ""); + return boost::shared_ptr(new Model_ObjectDeletedMessage(myDoc, "")); } const Events_ID Model_ObjectDeletedMessage::messageId() @@ -78,9 +82,10 @@ const Events_ID Model_ObjectDeletedMessage::messageId() return MY_ID; } -void Model_ObjectDeletedMessage::Join(Events_MessageGroup& theJoined) +void Model_ObjectDeletedMessage::Join(const boost::shared_ptr& theJoined) { - Model_ObjectDeletedMessage* aJoined = dynamic_cast(&theJoined); + boost::shared_ptr aJoined = + boost::dynamic_pointer_cast(theJoined); std::set::iterator aGIter = aJoined->myGroups.begin(); for (; aGIter != aJoined->myGroups.end(); aGIter++) { myGroups.insert(*aGIter); diff --git a/src/Model/Model_Events.h b/src/Model/Model_Events.h index c9b59c3c6..74d38a7fd 100644 --- a/src/Model/Model_Events.h +++ b/src/Model/Model_Events.h @@ -39,10 +39,10 @@ class Model_ObjectUpdatedMessage : public ModelAPI_ObjectUpdatedMessage virtual std::set objects() const; //! Creates a new empty group (to store it in the loop before flush) - virtual Events_MessageGroup* newEmpty(); + virtual boost::shared_ptr newEmpty(); //! Allows to join the given message with the current one - virtual void Join(Events_MessageGroup& theJoined); + virtual void Join(const boost::shared_ptr& theJoined); }; /// Message that feature was deleted (used for Object Browser update) @@ -69,11 +69,11 @@ class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage return myGroups; } - virtual Events_MessageGroup* newEmpty(); + virtual boost::shared_ptr newEmpty(); virtual const Events_ID messageId(); - virtual void Join(Events_MessageGroup& theJoined); + virtual void Join(const boost::shared_ptr& theJoined); }; #endif diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 3bc3dee03..d0879860c 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -135,7 +135,7 @@ void Model_Session::setActiveDocument(boost::shared_ptr theDo { if (myCurrentDoc != theDoc) { myCurrentDoc = theDoc; - static Events_Message aMsg(Events_Loop::eventByName("CurrentDocumentChanged")); + static boost::shared_ptr aMsg(new Events_Message(Events_Loop::eventByName("CurrentDocumentChanged"))); Events_Loop::loop()->send(aMsg); } } @@ -176,12 +176,13 @@ Model_Session::Model_Session() aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VALIDATOR_LOADED)); } -void Model_Session::processEvent(const Events_Message* theMessage) +void Model_Session::processEvent(const boost::shared_ptr& theMessage) { static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent"); static const Events_ID kValidatorEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED); if (theMessage->eventID() == kFeatureEvent) { - const Config_FeatureMessage* aMsg = dynamic_cast(theMessage); + const boost::shared_ptr aMsg = + boost::dynamic_pointer_cast(theMessage); if (aMsg) { // proccess the plugin info, load plugin if (myPlugins.find(aMsg->id()) == myPlugins.end()) { @@ -191,7 +192,8 @@ void Model_Session::processEvent(const Events_Message* theMessage) // plugins information was started to load, so, it will be loaded myPluginsInfoLoaded = true; } else if (theMessage->eventID() == kValidatorEvent) { - const Config_ValidatorMessage* aMsg = dynamic_cast(theMessage); + boost::shared_ptr aMsg = + boost::dynamic_pointer_cast(theMessage); if (aMsg) { if (aMsg->attributeId().empty()) { // feature validator validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->parameters()); diff --git a/src/Model/Model_Session.h b/src/Model/Model_Session.h index 5ee656025..845d93f7e 100644 --- a/src/Model/Model_Session.h +++ b/src/Model/Model_Session.h @@ -81,7 +81,7 @@ class Model_Session : public ModelAPI_Session, public Events_Listener MODEL_EXPORT virtual void registerPlugin(ModelAPI_Plugin* thePlugin); /// Processes the configuration file reading - MODEL_EXPORT virtual void processEvent(const Events_Message* theMessage); + MODEL_EXPORT virtual void processEvent(const boost::shared_ptr& theMessage); /// Copies the document to the new one wit hthe given id MODEL_EXPORT virtual boost::shared_ptr copy( diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 380d12b3f..848f38b80 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -27,14 +27,14 @@ Model_Update::Model_Update() Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); } -void Model_Update::processEvent(const Events_Message* theMessage) +void Model_Update::processEvent(const boost::shared_ptr& theMessage) { if (isExecuted) return; // nothing to do: it is executed now //Events_LongOp::start(this); isExecuted = true; - const ModelAPI_ObjectUpdatedMessage* aMsg = - dynamic_cast(theMessage); + boost::shared_ptr aMsg = + boost::dynamic_pointer_cast(theMessage); myInitial = aMsg->objects(); // collect all documents involved into the update set > aDocs; diff --git a/src/Model/Model_Update.h b/src/Model/Model_Update.h index ee3efc79c..5cfa02527 100644 --- a/src/Model/Model_Update.h +++ b/src/Model/Model_Update.h @@ -31,7 +31,7 @@ class Model_Update : public Events_Listener Model_Update(); /// Processes the feature argument update: executes the results - MODEL_EXPORT virtual void processEvent(const Events_Message* theMessage); + MODEL_EXPORT virtual void processEvent(const boost::shared_ptr& theMessage); protected: /// Recoursively checks and updates the feature if needed (calls the execute method) diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index c35573168..b2b9add75 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -44,10 +44,10 @@ class ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup virtual std::set objects() const = 0; //! Creates a new empty group (to store it in the loop before flush) - virtual Events_MessageGroup* newEmpty() = 0; + virtual boost::shared_ptr newEmpty() = 0; //! Allows to join the given message with the current one - virtual void Join(Events_MessageGroup& theJoined) = 0; + virtual void Join(const boost::shared_ptr& theJoined) = 0; }; /// Message that feature was deleted (used for Object Browser update) @@ -66,11 +66,11 @@ class ModelAPI_ObjectDeletedMessage : public Events_MessageGroup /// Returns the group where the feature was deleted virtual const std::set& groups() const = 0; - virtual Events_MessageGroup* newEmpty() = 0; + virtual boost::shared_ptr newEmpty() = 0; virtual const Events_ID messageId() = 0; - virtual void Join(Events_MessageGroup& theJoined) = 0; + virtual void Join(const boost::shared_ptr& theJoined) = 0; }; /// Allows to create ModelAPI messages