Salome HOME
257b9830e40c5788b160ea112a136c8eddf7caa2
[modules/yacs.git] / src / runtime / SALOMEDispatcher.cxx
1 // Copyright (C) 2006-2023  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "SALOMEDispatcher.hxx"
21 #include "Node.hxx"
22
23 #include <iostream>
24
25 //#define _DEVDEBUG_
26 #include "YacsTrace.hxx"
27
28 using namespace std;
29 using namespace YACS::BASES;
30 using namespace YACS::ENGINE;
31
32 map< pair<int,string> , set<YACS_ORB::Observer_ptr> > SALOMEDispatcher::_observers;
33 SALOMEDispatcher* SALOMEDispatcher::_disp = 0;
34
35 SALOMEDispatcher::SALOMEDispatcher()
36 {
37 }
38
39 SALOMEDispatcher::~SALOMEDispatcher()
40 {
41 }
42
43 void SALOMEDispatcher::setSALOMEDispatcher()
44 {
45   DEBTRACE("SALOMEDispatcher::setSALOMEDispatcher");
46   _disp=new SALOMEDispatcher();
47   YACS::ENGINE::Dispatcher::setDispatcher(_disp);
48 }
49
50 SALOMEDispatcher* SALOMEDispatcher::getSALOMEDispatcher()
51 {
52   return _disp;
53 }
54
55 void SALOMEDispatcher::dispatch(Node* object, const std::string& event)
56 {
57   DEBTRACE("SALOMEDispatcher::dispatch " << event << " " << object->getNumId());
58   CORBA::Long numId = object->getNumId();
59   typedef set<YACS_ORB::Observer_ptr>::iterator jt;
60   std::pair<int,std::string> key(numId, event);
61   for(jt iter = _observers[key].begin(); iter!=_observers[key].end(); iter++)
62     {
63       if (! CORBA::is_nil(*iter))
64         {
65           DEBTRACE("numId, event " << numId << " " << event );
66           (*iter)->notifyObserver(numId, event.c_str());
67         }
68       else
69         DEBTRACE("************************** dispatch on a CORBA::nil *******************************");
70     }
71 }
72
73 void SALOMEDispatcher::addObserver(YACS_ORB::Observer_ptr observer,
74                                    int numid,
75                                    std::string event)
76 {
77   _observers[std::pair<int,std::string>(numid,event)].insert(YACS_ORB::Observer::_duplicate(observer));
78 }