Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Bug_3543_Regression / server.cpp
blob951b1781947c64bc552548f69e7495c5225cee39
1 #include "masterS.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/ORB.h"
5 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'k':
17 ior = get_opts.opt_arg ();
18 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-k <iorfile>"
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 class ServerImpl : public POA_MasterClient::Server
35 public:
36 ServerImpl (CORBA::ORB_ptr orb) : orb_ (CORBA::ORB::_duplicate (orb))
40 virtual void ping()
44 virtual void shutdown ()
46 this->orb_->shutdown (false);
48 private:
49 CORBA::ORB_var orb_;
52 int
53 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
55 try
57 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
58 if (parse_args (argc, argv) != 0)
59 return 1;
61 CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA");
62 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(poa_object.in());
63 PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
65 ServerImpl *hello_impl = 0;
66 ACE_NEW_RETURN (hello_impl,
67 ServerImpl (orb.in ()),
68 1);
69 PortableServer::ServantBase_var owner_transfer(hello_impl);
71 PortableServer::ObjectId_var id =
72 root_poa->activate_object (hello_impl);
74 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
76 MasterClient::Server_var vserver = MasterClient::Server::_narrow (object.in ());
78 CORBA::Object_var tmp = orb->string_to_object(ior);
80 MasterClient::Master_var vmaster = MasterClient::Master::_narrow(tmp.in ());
82 poa_manager->activate ();
84 vmaster->registerServer(vserver.in());
86 orb->run();
88 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
90 root_poa->destroy (true, true);
92 orb->destroy ();
94 catch (const CORBA::Exception& ex)
96 ex._tao_print_exception ("Exception caught:");
97 return 1;
100 return 0;