Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / TAO / examples / ior_corbaloc / server.cpp
blobdb50409477afd7a6723a400eabd6b1ece66a4c31
1 // server.cpp
3 #include "status_i.h"
4 #include "tao/PortableServer/PortableServer.h"
5 #include "orbsvcs/CosNamingC.h"
7 int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
9 try
11 // First initialize the ORB, that will remove some arguments...
12 CORBA::ORB_var orb =
13 CORBA::ORB_init (argc, argv);
15 if (argc < 2)
17 ACE_DEBUG ((LM_DEBUG, "\nUsage:\n %s [NAME to insert in Naming Service]\n", argv[0]));
18 return -1;
20 // Get a reference to the RootPOA
21 CORBA::Object_var poa_object =
22 orb->resolve_initial_references ("RootPOA");
24 // narrow down to the correct reference
25 PortableServer::POA_var poa =
26 PortableServer::POA::_narrow (poa_object.in ());
28 // Set a POA Manager
29 PortableServer::POAManager_var poa_manager =
30 poa->the_POAManager ();
32 // Activate the POA Manager
33 poa_manager->activate ();
35 // Create the servant
36 corbaloc_Status_i status_i;
37 status_i.set_name (ACE_TEXT_ALWAYS_CHAR (argv[1]));
38 // Activate it to obtain the reference
39 PortableServer::ObjectId_var id =
40 poa->activate_object (&status_i);
42 CORBA::Object_var object = poa->id_to_reference (id.in ());
44 corbaloc::Status_var status =
45 corbaloc::Status::_narrow (object.in ());
47 // Get a reference to Naming Context
48 CORBA::Object_var naming_context_object =
49 orb->resolve_initial_references ("NameService");
51 // Narrow down the reference
52 CosNaming::NamingContext_var naming_context =
53 CosNaming::NamingContext::_narrow (naming_context_object.in ());
55 // Bind Iterator_Factory to the Naming Context
56 CosNaming::Name name (1);
57 name.length (1);
58 name[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (argv[1]));
60 naming_context->rebind (name, status.in ());
62 // Run the orb
63 orb->run ();
65 // Destroy the POA, waiting until the destruction terminates
66 poa->destroy (true, true);
67 orb->destroy ();
69 catch (const CORBA::SystemException& ex){
70 ex._tao_print_exception ("CORBA exception raised! ");
72 catch (const CORBA::Exception& ex){
73 ex._tao_print_exception ("Exception caught in server");
76 return 0;