Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / MT_NoUpcall_Connect / server.cpp
blob240e2b737363b60bbc276d6dfe1f9dcfe8e108b5
1 #include "SharedIntf_i.h"
3 #include "ace/Task.h"
4 #include "ace/SString.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.h"
8 const ACE_TCHAR *ior_output_file = ACE_TEXT ("server.ior");
9 const char *upper_ior = "corbaloc::127.10.100.4:34999/bogus";
10 CORBA::ORB_var orb_;
13 class Worker : public ACE_Task_Base
15 public:
16 int svc ()
18 ACE_DEBUG((LM_INFO,"(%P|%t) Running ORB in a separate thread\n"));
19 try
21 orb_->run ();
23 catch (const CORBA::Exception&)
26 return 0;
30 int
31 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
33 int result = 0;
35 try
37 ACE_DEBUG((LM_INFO,"(%P|%t) SERVER START\n"));
39 orb_ = CORBA::ORB_init (argc, argv);
41 CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
42 PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in());
43 PortableServer::POAManager_var mgr = poa->the_POAManager ();
44 mgr->activate ();
46 ACE_DEBUG((LM_INFO,"(%P|%t) ORB initialized\n"));
48 Test_Idl_SharedIntf_i* intf_i = new Test_Idl_SharedIntf_i(orb_.in());
50 PortableServer::ServantBase_var base_var = intf_i;
51 PortableServer::ObjectId_var intfId_var =
52 poa->activate_object(base_var.in());
54 obj = poa->id_to_reference(intfId_var.in());
55 Test_Idl::SharedIntf_var intf_var = Test_Idl::SharedIntf::_narrow(obj.in());
56 CORBA::String_var intfString_var = orb_->object_to_string(intf_var.in());
58 // Output the IOR to the <ior_output_file>
59 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
60 if (output_file == 0)
61 ACE_ERROR_RETURN ((LM_ERROR,
62 "Cannot open output file for writing IOR: %s\n",
63 ior_output_file),
64 1);
65 ACE_OS::fprintf (output_file, "%s", intfString_var.in ());
66 ACE_OS::fclose (output_file);
68 intf_i->set_upper (upper_ior);
70 // Running ORB in separate thread
71 Worker worker;
72 if (worker.activate () != 0)
73 ACE_ERROR_RETURN ((LM_ERROR,
74 "(%P|%t) %p\n", "Cannot activate server thread(s)"),
75 -1);
77 worker.thr_mgr()->wait ();
78 orb_->destroy();
80 catch (const CORBA::Exception& ex)
82 ex._tao_print_exception ("Error: Exception caught:");
85 ACE_OS::unlink (ior_output_file);
86 return result;