Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / Content_Server / SMI_Iterator / server.cpp
blobb85b1283d0d92ac0a68cbae090c8dd1a06543a54
1 // -*- C++ -*-
2 // Ossama Othman <ossama@uci.edu>
4 #include "orbsvcs/CosNamingC.h"
5 #include "Web_ServerS.h"
7 #include "Iterator_Factory_i.h"
9 int
10 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
12 try
14 // Initialize the ORB.
15 CORBA::ORB_var orb = CORBA::ORB_init (argc,
16 argv,
17 "Mighty ORB");
19 // Get the Root POA.
20 CORBA::Object_var obj =
21 orb->resolve_initial_references ("RootPOA");
23 PortableServer::POA_var poa =
24 PortableServer::POA::_narrow (obj.in ());
26 // Activate the POA manager.
27 PortableServer::POAManager_var mgr = poa->the_POAManager ();
28 mgr->activate ();
30 // Create the Iterator_Factory servant and object.
31 // It activates and deactivates the Content_Iterator object.
32 Iterator_Factory_i factory_servant;
33 Web_Server::Iterator_Factory_var factory =
34 factory_servant._this ();
36 // Get a reference to the Name Service.
37 obj = orb->resolve_initial_references ("NameService");
39 // Narrow to a Naming Context
40 CosNaming::NamingContext_var nc;
41 nc = CosNaming::NamingContext::_narrow (obj.in ());
43 // Create a name.
44 CosNaming::Name name;
45 name.length (1);
46 name[0].id = CORBA::string_dup ("Iterator_Factory");
47 name[0].kind = CORBA::string_dup ("");
49 nc->bind (name, factory.in ());
51 // Some debugging output.
52 CORBA::String_var IOR = orb->object_to_string (factory.in ());
53 ACE_DEBUG ((LM_DEBUG,
54 ACE_TEXT ("Bound <%s> to <%s> in Name Service.\n"),
55 name[0].id.in (),
56 IOR.in ()));
58 ACE_DEBUG ((LM_INFO,
59 ACE_TEXT ("Accepting requests.\n")));
61 // Accept requests.
62 orb->run ();
64 catch (const CORBA::Exception& ex)
66 ex._tao_print_exception (ACE_TEXT ("Caught unexpected exception:"));
68 return -1;
71 return 0;