Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_1383_Regression / SimpleServer.cpp
blob6508fddf239c8987adc4112f4a50667cf3e823b5
1 #include "tao/corba.h"
2 #include "tao/IORTable/IORTable.h"
3 #include "simple_i.h"
5 void advertise(CORBA::ORB_ptr orb, CORBA::Object_ptr obj)
7 // advertise our object in the IORTable so that it can be
8 // accessed by a client using the "cobaloc" syntax
9 CORBA::String_var str = orb->object_to_string(obj);
10 CORBA::Object_var tmp = orb->resolve_initial_references("IORTable");
11 IORTable::Table_var iorTable = IORTable::Table::_narrow(tmp.in ());
12 if (CORBA::is_nil(iorTable.in ()))
14 ACE_ERROR ((LM_ERROR, "could not get the IORTable, will not register\n"));
16 else
18 iorTable->rebind("Simple", str.in());
19 ACE_DEBUG ((LM_DEBUG, "regisered\n"));
21 // we could also advertise the object reference to a naming and/or
22 // trading service
25 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
27 try
29 // Initialize the orb.
30 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
32 // Get the "RootPOA"
33 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
34 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in ());
36 // activate its managers so it can handle incoming requests
37 poa->the_POAManager()->activate();
39 // Create a CORBA object that can be called by a client. Note that
40 // this does not create the CORBA object. It creates the object
41 // that does the real work behind the CORBA object.
42 Simple_i * simple = new Simple_i(orb.in ());
44 // This call creates the CORBA object and returns a reference to
45 // it. It uses the "RootPOA" for dispatching its calls. There are
46 // a number of ways this can be done different. Refer to "Advanced
47 // CORBA Programming with C++" chapter 11 for more information.
48 PortableServer::ObjectId_var id =
49 poa->activate_object (simple);
51 CORBA::Object_var object_act = poa->id_to_reference (id.in ());
53 Simple_var simpleRef = Simple::_narrow (object_act.in ());
55 advertise(orb.in(), simpleRef.in());
57 // give the ORB control for only 30 seconds
58 ACE_DEBUG ((LM_DEBUG, "run orb\n"));
59 for (int i = 0; i < 1000; ++i) {
60 ACE_Time_Value runTime(3);
61 orb->run(runTime);
62 for (int i = 0; i < 10000000; ++i) {}
65 ACE_DEBUG ((LM_DEBUG, "done running\n"));
67 poa->destroy (1, 1);
69 orb->destroy ();
71 catch (const CORBA::Exception& ex)
73 ex._tao_print_exception ("Exception caught:");
74 return 1;
77 return 0;