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<Config_FeatureMessage> 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)) {
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<Config_FeatureMessage>& 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)
#include <Config_def.h>
#include <Config_XMLReader.h>
+#include <boost/shared_ptr.hpp>
#include <string>
#include <list>
void processNode(xmlNodePtr aNode);
bool processChildren(xmlNodePtr aNode);
- void fillFeature(xmlNodePtr theRoot, Config_FeatureMessage& outFeatureMessage);
+ void fillFeature(xmlNodePtr theRoot,
+ const boost::shared_ptr<Config_FeatureMessage>& outFeatureMessage);
bool isInternalFeature(xmlNodePtr theRoot);
private:
{
Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
Events_Loop* aEvLoop = Events_Loop::loop();
- Config_ValidatorMessage aMessage(aValidatoEvent, this);
+ boost::shared_ptr<Config_ValidatorMessage>
+ aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
std::string aValidatorId;
std::list<std::string> 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);
}
void Events_Error::send(char* theDescription, const void* theSender)
{
- Events_Error anError(theDescription, theSender);
- Events_Loop::loop()->send(anError);
+ boost::shared_ptr<Events_Message> aNewOne =
+ boost::shared_ptr<Events_Message>(new Events_Error(theDescription, theSender));
+ Events_Loop::loop()->send(aNewOne);
}
void Events_Error::send(std::string theDescription, const void* theSender)
#define Events_Listener_H_
#include <Events.h>
+#include <boost/shared_ptr.hpp>
+
class Events_Message;
/**\class 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<Events_Message>& theMessage) = 0;
};
#endif
MY_SENDERS[theSender]++;
if (toSend) {
- Events_LongOp anEvent(theSender);
- Events_Loop::loop()->send(anEvent);
+ boost::shared_ptr<Events_Message> aNewOne =
+ boost::shared_ptr<Events_Message>(new Events_LongOp(theSender));
+ Events_Loop::loop()->send(aNewOne);
}
}
MY_SENDERS[theSender] = aCount - 1;
}
if (MY_SENDERS.empty()) {
- Events_LongOp anEvent(theSender);
- Events_Loop::loop()->send(anEvent);
+ boost::shared_ptr<Events_Message> aNewOne =
+ boost::shared_ptr<Events_Message>(new Events_LongOp(theSender));
+ Events_Loop::loop()->send(aNewOne);
}
}
return Events_ID(aResult);
}
-void Events_Loop::send(Events_Message& theMessage, bool isGroup)
+void Events_Loop::send(const boost::shared_ptr<Events_Message>& theMessage, bool isGroup)
{
// if it is grouped message, just accumulate it
if (isGroup) {
- Events_MessageGroup* aGroup = dynamic_cast<Events_MessageGroup*>(&theMessage);
+ boost::shared_ptr<Events_MessageGroup> aGroup =
+ boost::dynamic_pointer_cast<Events_MessageGroup>(theMessage);
if (aGroup) {
- std::map<char*, Events_MessageGroup*>::iterator aMyGroup = myGroups.find(
+ std::map<char*, boost::shared_ptr<Events_Message> >::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<Events_MessageGroup> aNewOne =
+ boost::dynamic_pointer_cast<Events_MessageGroup>(aMyGroup->second);
+ aGroup->Join(aNewOne);
return;
}
}
// TO DO: make it in thread and with usage of semaphores
map<char*, map<void*, list<Events_Listener*> > >::iterator aFindID = myListeners.find(
- theMessage.eventID().eventText());
+ theMessage->eventID().eventText());
if (aFindID != myListeners.end()) {
map<void*, list<Events_Listener*> >::iterator aFindSender = aFindID->second.find(
- theMessage.sender());
+ theMessage->sender());
if (aFindSender != aFindID->second.end()) {
list<Events_Listener*>& aListeners = aFindSender->second;
for (list<Events_Listener*>::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<Events_Listener*>& aListeners = aFindSender->second;
for (list<Events_Listener*>::iterator aL = aListeners.begin(); aL != aListeners.end(); aL++)
- (*aL)->processEvent(&theMessage);
+ (*aL)->processEvent(theMessage);
}
}
}
{
if (!myFlushActive)
return;
- std::map<char*, Events_MessageGroup*>::iterator aMyGroup = myGroups.find(theID.eventText());
+ std::map<char*, boost::shared_ptr<Events_Message>>::iterator aMyGroup =
+ myGroups.find(theID.eventText());
if (aMyGroup != myGroups.end()) { // really sends
- Events_MessageGroup* aGroup = aMyGroup->second;
+ boost::shared_ptr<Events_Message> aGroup = aMyGroup->second;
myGroups.erase(aMyGroup);
- send(*aGroup, false);
- delete aGroup;
+ send(aGroup, false);
}
}
std::map<char*, std::map<void*, std::list<Events_Listener*> > > myListeners;
/// map from event ID to groupped messages (accumulated on flush)
- std::map<char*, Events_MessageGroup*> myGroups;
+ std::map<char*, boost::shared_ptr<Events_Message> > myGroups;
/// to process flushes or not
bool myFlushActive;
//! 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<Events_Message>& 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
#define Events_MessageGroup_H_
#include <Events_Message.h>
+#include <boost/shared_ptr.hpp>
/**\class Events_Message
* \ingroup EventsLoop
}
//! Creates a new empty group (to store it in the loop before flush)
- virtual Events_MessageGroup* newEmpty() = 0;
+ virtual boost::shared_ptr<Events_MessageGroup> 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<Events_MessageGroup>& theJoined) = 0;
};
#endif
void Model_EventCreator::sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
const bool isGroupped) const
{
- Model_ObjectUpdatedMessage aMsg(theObject, theEvent);
+ boost::shared_ptr<Model_ObjectUpdatedMessage> aMsg(
+ new Model_ObjectUpdatedMessage(theObject, theEvent));
Events_Loop::loop()->send(aMsg, isGroupped);
}
void Model_EventCreator::sendDeleted(const boost::shared_ptr<ModelAPI_Document>& theDoc,
const std::string& theGroup) const
{
- Model_ObjectDeletedMessage aMsg(theDoc, theGroup);
+ boost::shared_ptr<Model_ObjectDeletedMessage> aMsg(
+ new Model_ObjectDeletedMessage(theDoc, theGroup));
Events_Loop::loop()->send(aMsg, true);
}
return myObjects;
}
-Events_MessageGroup* Model_ObjectUpdatedMessage::newEmpty()
+boost::shared_ptr<Events_MessageGroup> Model_ObjectUpdatedMessage::newEmpty()
{
ObjectPtr anEmptyObject;
- return new Model_ObjectUpdatedMessage(anEmptyObject, eventID());
+ return boost::shared_ptr<Model_ObjectUpdatedMessage>(
+ new Model_ObjectUpdatedMessage(anEmptyObject, eventID()));
}
-void Model_ObjectUpdatedMessage::Join(Events_MessageGroup& theJoined)
+void Model_ObjectUpdatedMessage::Join(const boost::shared_ptr<Events_MessageGroup>& theJoined)
{
- Model_ObjectUpdatedMessage* aJoined = dynamic_cast<Model_ObjectUpdatedMessage*>(&theJoined);
+ boost::shared_ptr<Model_ObjectUpdatedMessage> aJoined =
+ boost::dynamic_pointer_cast<Model_ObjectUpdatedMessage>(theJoined);
std::set<ObjectPtr>::iterator aFIter = aJoined->myObjects.begin();
for (; aFIter != aJoined->myObjects.end(); aFIter++) {
myObjects.insert(*aFIter);
myGroups.insert(theGroup);
}
-Events_MessageGroup* Model_ObjectDeletedMessage::newEmpty()
+boost::shared_ptr<Events_MessageGroup> Model_ObjectDeletedMessage::newEmpty()
{
- return new Model_ObjectDeletedMessage(myDoc, "");
+ return boost::shared_ptr<Model_ObjectDeletedMessage>(new Model_ObjectDeletedMessage(myDoc, ""));
}
const Events_ID Model_ObjectDeletedMessage::messageId()
return MY_ID;
}
-void Model_ObjectDeletedMessage::Join(Events_MessageGroup& theJoined)
+void Model_ObjectDeletedMessage::Join(const boost::shared_ptr<Events_MessageGroup>& theJoined)
{
- Model_ObjectDeletedMessage* aJoined = dynamic_cast<Model_ObjectDeletedMessage*>(&theJoined);
+ boost::shared_ptr<Model_ObjectDeletedMessage> aJoined =
+ boost::dynamic_pointer_cast<Model_ObjectDeletedMessage>(theJoined);
std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
for (; aGIter != aJoined->myGroups.end(); aGIter++) {
myGroups.insert(*aGIter);
virtual std::set<ObjectPtr> objects() const;
//! Creates a new empty group (to store it in the loop before flush)
- virtual Events_MessageGroup* newEmpty();
+ virtual boost::shared_ptr<Events_MessageGroup> newEmpty();
//! Allows to join the given message with the current one
- virtual void Join(Events_MessageGroup& theJoined);
+ virtual void Join(const boost::shared_ptr<Events_MessageGroup>& theJoined);
};
/// Message that feature was deleted (used for Object Browser update)
return myGroups;
}
- virtual Events_MessageGroup* newEmpty();
+ virtual boost::shared_ptr<Events_MessageGroup> newEmpty();
virtual const Events_ID messageId();
- virtual void Join(Events_MessageGroup& theJoined);
+ virtual void Join(const boost::shared_ptr<Events_MessageGroup>& theJoined);
};
#endif
{
if (myCurrentDoc != theDoc) {
myCurrentDoc = theDoc;
- static Events_Message aMsg(Events_Loop::eventByName("CurrentDocumentChanged"));
+ static boost::shared_ptr<Events_Message> aMsg(new Events_Message(Events_Loop::eventByName("CurrentDocumentChanged")));
Events_Loop::loop()->send(aMsg);
}
}
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<Events_Message>& 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<const Config_FeatureMessage*>(theMessage);
+ const boost::shared_ptr<Config_FeatureMessage> aMsg =
+ boost::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
if (aMsg) {
// proccess the plugin info, load plugin
if (myPlugins.find(aMsg->id()) == myPlugins.end()) {
// plugins information was started to load, so, it will be loaded
myPluginsInfoLoaded = true;
} else if (theMessage->eventID() == kValidatorEvent) {
- const Config_ValidatorMessage* aMsg = dynamic_cast<const Config_ValidatorMessage*>(theMessage);
+ boost::shared_ptr<Config_ValidatorMessage> aMsg =
+ boost::dynamic_pointer_cast<Config_ValidatorMessage>(theMessage);
if (aMsg) {
if (aMsg->attributeId().empty()) { // feature validator
validators()->assignValidator(aMsg->validatorId(), aMsg->featureId(), aMsg->parameters());
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<Events_Message>& theMessage);
/// Copies the document to the new one wit hthe given id
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> copy(
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<Events_Message>& theMessage)
{
if (isExecuted)
return; // nothing to do: it is executed now
//Events_LongOp::start(this);
isExecuted = true;
- const ModelAPI_ObjectUpdatedMessage* aMsg =
- dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
+ boost::shared_ptr<ModelAPI_ObjectUpdatedMessage> aMsg =
+ boost::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
myInitial = aMsg->objects();
// collect all documents involved into the update
set<boost::shared_ptr<ModelAPI_Document> > aDocs;
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<Events_Message>& theMessage);
protected:
/// Recoursively checks and updates the feature if needed (calls the execute method)
virtual std::set<ObjectPtr> 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<Events_MessageGroup> 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<Events_MessageGroup>& theJoined) = 0;
};
/// Message that feature was deleted (used for Object Browser update)
/// Returns the group where the feature was deleted
virtual const std::set<std::string>& groups() const = 0;
- virtual Events_MessageGroup* newEmpty() = 0;
+ virtual boost::shared_ptr<Events_MessageGroup> newEmpty() = 0;
virtual const Events_ID messageId() = 0;
- virtual void Join(Events_MessageGroup& theJoined) = 0;
+ virtual void Join(const boost::shared_ptr<Events_MessageGroup>& theJoined) = 0;
};
/// Allows to create ModelAPI messages