Version: 9.16.0
SALOMEDispatcher.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 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
28using namespace std;
29using namespace YACS::BASES;
30using namespace YACS::ENGINE;
31
32map< pair<int,string> , set<YACS_ORB::Observer_ptr> > SALOMEDispatcher::_observers;
33SALOMEDispatcher* SALOMEDispatcher::_disp = 0;
34
35SALOMEDispatcher::SALOMEDispatcher()
36{
37}
38
40{
41}
42
44{
45 DEBTRACE("SALOMEDispatcher::setSALOMEDispatcher");
48}
49
51{
52 return _disp;
53}
54
55void 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
73void 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}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
static void setDispatcher(Dispatcher *dispatcher)
Definition: Dispatcher.cxx:64
Base class for all nodes.
Definition: Node.hxx:70
static SALOMEDispatcher * _disp
void addObserver(YACS_ORB::Observer_ptr observer, int numid, std::string event)
void dispatch(Node *object, const std::string &event)
static SALOMEDispatcher * getSALOMEDispatcher()
static std::map< std::pair< int, std::string >, std::set< YACS_ORB::Observer_ptr > > _observers