47 std::cerr <<
"dispatch " <<
object->getNumId() << std::endl;
48 typedef std::set<YACS_ORB::Observer_ptr>::iterator jt;
49 std::pair<int,std::string> key(object->
getNumId(),event);
50 for(jt iter=_observers[key].begin();iter!=_observers[key].end();iter++)
52 (*iter)->notifyObserver((CORBA::Long)object->
getNumId(),
event.c_str());
56 void addObserver(YACS_ORB::Observer_ptr observer,
int numid,
const std::string& event)
58 _observers[std::pair<int,std::string>(numid,event)].insert(YACS_ORB::Observer::_duplicate(observer));
62 std::map< std::pair<int,std::string> , std::set<YACS_ORB::Observer_ptr> >
_observers;
65 class Yacs_i :
public POA_YACS_ORB::YACS_Gen,
66 public PortableServer::RefCountServantBase
71 YACS_ORB::Proc_ptr Load(
const char* xmlFile);
72 void Run(YACS_ORB::Proc_ptr
p);
73 void addObserver(YACS_ORB::Observer_ptr observer, CORBA::Long numid,
const char* event);
76 class Proc_i :
public POA_YACS_ORB::Proc,
77 public PortableServer::RefCountServantBase
83 CORBA::Long getState(CORBA::Long numid);
84 char * getXMLState(CORBA::Long numid);
85 void getIds(YACS_ORB::longArray_out numids,YACS_ORB::stringArray_out names);
93 _executor.RunW(_proc,0);
100 std::cerr <<
"Unknown node id " << numid << std::endl;
101 return (CORBA::Long)-1;
112 std::cerr <<
"Unknown node id " << numid << std::endl;
113 return "<state>unknown</state>";
116 std::stringstream msg;
119 msg <<
"<id>" << numid <<
"</id>";
120 return CORBA::string_dup(msg.str().c_str());
123 void Proc_i::getIds(YACS_ORB::longArray_out numids,YACS_ORB::stringArray_out names)
125 std::list<YACS::ENGINE::Node *> nodes=_proc->getAllRecursiveNodes();
126 int len=nodes.size();
132 for(list<YACS::ENGINE::Node *>::const_iterator iter=nodes.begin();iter!=nodes.end();iter++,i++)
134 (*names)[
i]=CORBA::string_dup((*iter)->getQualifiedName().c_str());
135 (*numids)[
i]=(*iter)->getNumId();
143 YACS_ORB::Proc_ptr pp = p->_this();
154 Proc_i *servant=
dynamic_cast<Proc_i *
> (PortableServer::POA::_the_root_poa()->reference_to_servant(p));
158 static CORBA::Boolean
bindObjectToName(CORBA::ORB_ptr, CORBA::Object_ptr,
const char*);
159 static ostream&
operator<<(ostream& os,
const CORBA::Exception& e);
161 int main(
int argc,
char** argv)
170 orb = CORBA::ORB_init(argc, argv);
173 CORBA::Object_var obj =
orb->resolve_initial_references(
"RootPOA");
174 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
176 PortableServer::POAManager_var poa_man = root_poa->the_POAManager();
183 obj = myyacs->_this();
184 CORBA::String_var sior(
orb->object_to_string(obj));
185 DEBTRACE(
"'" << (
char*)sior <<
"'");
186 myyacsref = YACS_ORB::YACS_Gen::_narrow(obj);
193 myyacs->_remove_ref();
197 catch(CORBA::SystemException&) {
198 DEBTRACE(
"Caught CORBA::SystemException.");
200 catch(CORBA::Exception& ex) {
201 DEBTRACE(
"Caught CORBA::Exception." << ex);
203 catch(omniORB::fatalException& fe) {
204 DEBTRACE(
"Caught omniORB::fatalException:");
210 DEBTRACE(
"Caught unknown exception." );
219 static CORBA::Boolean
222 CosNaming::NamingContext_var rootContext;
226 CORBA::Object_var obj;
227 obj = orb->resolve_initial_references(
"NameService");
230 rootContext = CosNaming::NamingContext::_narrow(obj);
231 if( CORBA::is_nil(rootContext) ) {
232 DEBTRACE(
"Failed to narrow the root naming context.");
236 catch(CORBA::ORB::InvalidName& ex) {
238 DEBTRACE(
"Service required is invalid [does not exist]." );
245 CosNaming::Name contextName;
246 contextName.length(1);
247 contextName[0].id = (
const char*)
"test";
248 contextName[0].kind = (
const char*)
"my_context";
253 CosNaming::NamingContext_var testContext;
256 testContext = rootContext->bind_new_context(contextName);
258 catch(CosNaming::NamingContext::AlreadyBound& ex) {
262 CORBA::Object_var obj;
263 obj = rootContext->resolve(contextName);
264 testContext = CosNaming::NamingContext::_narrow(obj);
265 if( CORBA::is_nil(testContext) ) {
266 DEBTRACE(
"Failed to narrow naming context.");
272 CosNaming::Name objectName;
273 objectName.length(1);
274 objectName[0].id = name;
275 objectName[0].kind = (
const char*)
"Object";
278 testContext->bind(objectName, objref);
280 catch(CosNaming::NamingContext::AlreadyBound& ex) {
281 testContext->rebind(objectName, objref);
284 catch(CORBA::COMM_FAILURE& ex) {
285 DEBTRACE(
"Caught system exception COMM_FAILURE -- unable to contact the "
286 <<
"naming service.");
289 catch(CORBA::SystemException&) {
290 DEBTRACE(
"Caught a CORBA::SystemException while using the naming service.");
297 static ostream&
operator<<(ostream& os,
const CORBA::Exception& e)
301 CORBA::TypeCode_var tc = tmp.type();
302 const char *
p = tc->name();