More tests update
[ACE_TAO.git] / TAO / tests / MT_NoUpcall_Connect / server.cpp
blobf691ae823f230393d67afd086a85dadbb6a64a27
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 (void)
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;
31 int
32 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
34 int result = 0;
36 try
38 ACE_DEBUG((LM_INFO,"(%P|%t) SERVER START\n"));
40 orb_ = CORBA::ORB_init (argc, argv);
42 CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
43 PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in());
44 PortableServer::POAManager_var mgr = poa->the_POAManager ();
45 mgr->activate ();
47 ACE_DEBUG((LM_INFO,"(%P|%t) ORB initialized\n"));
49 Test_Idl_SharedIntf_i* intf_i = new Test_Idl_SharedIntf_i(orb_.in());
51 PortableServer::ServantBase_var base_var = intf_i;
52 PortableServer::ObjectId_var intfId_var =
53 poa->activate_object(base_var.in());
55 obj = poa->id_to_reference(intfId_var.in());
56 Test_Idl::SharedIntf_var intf_var = Test_Idl::SharedIntf::_narrow(obj.in());
57 CORBA::String_var intfString_var = orb_->object_to_string(intf_var.in());
59 // Output the IOR to the <ior_output_file>
60 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
61 if (output_file == 0)
62 ACE_ERROR_RETURN ((LM_ERROR,
63 "Cannot open output file for writing IOR: %s\n",
64 ior_output_file),
65 1);
66 ACE_OS::fprintf (output_file, "%s", intfString_var.in ());
67 ACE_OS::fclose (output_file);
69 intf_i->set_upper (upper_ior);
71 // Running ORB in separate thread
72 Worker worker;
73 if (worker.activate () != 0)
74 ACE_ERROR_RETURN ((LM_ERROR,
75 "(%P|%t) %p\n", "Cannot activate server thread(s)"),
76 -1);
78 worker.thr_mgr()->wait ();
79 orb_->destroy();
81 catch (const CORBA::Exception& ex)
83 ex._tao_print_exception ("Error: Exception caught:");
86 ACE_OS::unlink (ior_output_file);
87 return result;