void Events_Loop::send(const boost::shared_ptr<Events_Message>& theMessage, bool isGroup)
{
+ if (myImmediateListeners.find(theMessage->eventID().eventText()) != myImmediateListeners.end()) {
+ myImmediateListeners[theMessage->eventID().eventText()]->processEvent(theMessage);
+ }
// if it is grouped message, just accumulate it
if (isGroup) {
boost::shared_ptr<Events_MessageGroup> aGroup =
}
}
- // TO DO: make it in thread and with usage of semaphores
+ // TODO: make it in thread and with usage of semaphores
map<char*, map<void*, list<Events_Listener*> > >::iterator aFindID = myListeners.find(
theMessage->eventID().eventText());
}
void Events_Loop::registerListener(Events_Listener* theListener, const Events_ID theID,
- void* theSender)
+ void* theSender, bool theImmediate)
{
+ if (theImmediate) { // just register as an immediate
+ myImmediateListeners[theID.eventText()] = theListener;
+ return;
+ }
map<char*, map<void*, list<Events_Listener*> > >::iterator aFindID = myListeners.find(
theID.eventText());
if (aFindID == myListeners.end()) { // create container associated with ID
/// map from event ID to sender pointer to listeners that must be called for this
std::map<char*, std::map<void*, std::list<Events_Listener*> > > myListeners;
+ /// map from event ID to listeners which must process message without waiting for flush
+ std::map<char*, Events_Listener*> myImmediateListeners;
+
/// map from event ID to groupped messages (accumulated on flush)
std::map<char*, boost::shared_ptr<Events_Message> > myGroups;
//! 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);
+ void* theSender = 0, bool theImmediate = false);
//! Initializes sending of a group-message by the given ID
EVENTS_EXPORT void flush(const Events_ID& theID);
void Model_Document::finishOperation()
{
- // just to be sure that everybody knows that changes were performed
+ // finish for all subs first: to avoid nested finishing and "isOperation" calls problems inside
+ std::set<std::string>::iterator aSubIter = mySubs.begin();
+ for (; aSubIter != mySubs.end(); aSubIter++)
+ subDoc(*aSubIter)->finishOperation();
+ // just to be sure that everybody knows that changes were performed
if (!myDoc->HasOpenCommand() && myNestedNum != -1)
boost::static_pointer_cast<Model_Session>(Model_Session::get())
->setCheckTransactions(false); // for nested transaction commit
myTransactionsAfterSave++;
}
- // finish for all subs
- std::set<std::string>::iterator aSubIter = mySubs.begin();
- for (; aSubIter != mySubs.end(); aSubIter++)
- subDoc(*aSubIter)->finishOperation();
}
void Model_Document::abortOperation()
Events_Loop* aLoop = Events_Loop::loop();
static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
aLoop->registerListener(this, kFeatureEvent);
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED), 0, true);
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED), 0, true);
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED), 0, true);
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VALIDATOR_LOADED));
}
bool XGUI_OperationMgr::validateOperation(ModuleBase_Operation* theOperation)
{
- if(!theOperation)
+ if (!theOperation)
return false;
//Get operation feature to validate
FeaturePtr aFeature = theOperation->feature();