1 // Copyright (C) 2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // Author : Anthony Geay (EDF R&D)
23 // This is an example of plugin implementation you can write to intercept events sent by YACS engine during execution
24 // 1 - Build your shared library with 2 symboles defined : DefineCustomObservers and CleanUpObservers (warning respect the API !).
25 // 2 - At run time set YACS_DRIVER_PLUGIN_PATH in your environement to the shared library
27 #include "Dispatcher.hxx"
28 #include "ForEachLoop.hxx"
33 class PluginObserver : public YACS::ENGINE::Observer
36 PluginObserver(YACS::ENGINE::ForEachLoop *fe):_fe(fe) { }
38 void notifyObserver(YACS::ENGINE::Node* object,const std::string& event);
39 void notifyObserver2(YACS::ENGINE::Node* object,const std::string& event, void *something);
41 YACS::ENGINE::ForEachLoop *_fe;
44 void PluginObserver::notifyObserver(YACS::ENGINE::Node* object,const std::string& event)
46 std::cerr << "------------" << event << std::endl;
49 void PluginObserver::notifyObserver2(YACS::ENGINE::Node* object,const std::string& event, void *something)
51 std::ostringstream oss;
52 if(event=="progress_ok")
54 int itemOk(*reinterpret_cast<int *>(something));
55 oss << event << " " << itemOk;
56 std::cerr << oss.str() << std::endl;
60 class PluginObserverKeeper
63 ~PluginObserverKeeper() { clean(); }
64 void clean() { for(std::vector<YACS::ENGINE::Observer *>::iterator it=_observers.begin();it!=_observers.end();it++) delete *it; _observers.clear(); }
65 void registerObserver(YACS::ENGINE::Observer *newObs) { _observers.push_back(newObs); }
67 std::vector<YACS::ENGINE::Observer *> _observers;
70 PluginObserverKeeper pok;
72 #include "ForEachLoop.hxx"
76 void DefineCustomObservers(YACS::ENGINE::Dispatcher *disp, YACS::ENGINE::ComposedNode *rootNode, YACS::ENGINE::Executor *executor)
78 YACS::ENGINE::Node *n(rootNode->getChildByName("ForEachLoop_pyobj1"));
79 YACS::ENGINE::ForEachLoop *nc(dynamic_cast<YACS::ENGINE::ForEachLoop *>(n));
81 throw YACS::Exception("Expect to have a ForEach node called ForEachLoop_pyobj1 !");
82 PluginObserver *myCustomObsever(new PluginObserver(nc));
83 pok.registerObserver(myCustomObsever);
84 disp->addObserver(myCustomObsever,nc,"progress_ok");
87 void CleanUpObservers()