=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / RTCORBA / Explicit_Binding / server.cpp
blob86ba3654e6e9c74c403ad506460e450156ac391c
1 #include "testS.h"
2 #include "ace/Get_Opt.h"
4 #include "tao/Strategies/advanced_resource.h"
5 #include "tao/RTCORBA/RTCORBA.h"
6 #include "tao/RTPortableServer/RTPortableServer.h"
8 class Test_i : public POA_Test
10 // = TITLE
11 // An implementation for the Test interface in test.idl
13 public:
14 Test_i (CORBA::ORB_ptr orb);
15 // ctor
17 // = The Test methods.
18 void test_method ();
20 //FUZZ: disable check_for_lack_ACE_OS
21 void shutdown ();
22 //FUZZ: enable check_for_lack_ACE_OS
24 private:
25 CORBA::ORB_var orb_;
26 // The ORB
29 Test_i::Test_i (CORBA::ORB_ptr orb)
30 : orb_ (CORBA::ORB::_duplicate (orb))
34 void
35 Test_i::test_method (/* */)
37 ACE_DEBUG ((LM_DEBUG,
38 "Server: test_method invoked.\n"));
41 void
42 Test_i::shutdown ()
44 this->orb_->shutdown (false);
47 //*************************************************************************
49 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
51 // Parse command-line arguments.
52 int
53 parse_args (int argc, ACE_TCHAR *argv[])
55 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
56 int c;
58 while ((c = get_opts ()) != -1)
59 switch (c)
61 case 'o':
62 ior_output_file = get_opts.opt_arg ();
63 break;
65 case '?':
66 default:
67 ACE_ERROR_RETURN ((LM_ERROR,
68 "usage: %s "
69 "-o <iorfile>"
70 "\n",
71 argv [0]),
72 -1);
75 return 0;
78 int
79 check_for_nil (CORBA::Object_ptr obj, const char *msg)
81 if (CORBA::is_nil (obj))
82 ACE_ERROR_RETURN ((LM_ERROR,
83 "ERROR: Object reference <%C> is nil\n",
84 msg),
85 -1);
86 else
87 return 0;
90 int
91 create_object (PortableServer::POA_ptr poa,
92 CORBA::ORB_ptr orb,
93 Test_i *server_impl,
94 const ACE_TCHAR *filename)
96 // Register with poa.
97 PortableServer::ObjectId_var id =
98 poa->activate_object (server_impl);
101 CORBA::Object_var server =
102 poa->id_to_reference (id.in ());
104 // Print out the IOR.
105 CORBA::String_var ior =
106 orb->object_to_string (server.in ());
108 ACE_DEBUG ((LM_DEBUG, "<%C>\n\n", ior.in ()));
110 // Print ior to the file.
111 if (filename != 0)
113 FILE *output_file= ACE_OS::fopen (filename, "w");
114 if (output_file == 0)
115 ACE_ERROR_RETURN ((LM_ERROR,
116 "Cannot open output file for writing IOR: %s",
117 filename),
118 -1);
119 ACE_OS::fprintf (output_file, "%s", ior.in ());
120 ACE_OS::fclose (output_file);
123 return 0;
127 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
131 // ORB.
132 CORBA::ORB_var orb =
133 CORBA::ORB_init (argc, argv);
135 // Parse arguments.
136 if (parse_args (argc, argv) != 0)
137 return -1;
139 // RootPOA.
140 CORBA::Object_var object =
141 orb->resolve_initial_references("RootPOA");
142 PortableServer::POA_var root_poa =
143 PortableServer::POA::_narrow (object.in ());
144 if (check_for_nil (root_poa.in (), "RootPOA") == -1)
145 return -1;
147 // POAManager.
148 PortableServer::POAManager_var poa_manager =
149 root_poa->the_POAManager ();
151 // Servant.
152 Test_i server_impl (orb.in ());
154 // Create Object.
155 int result;
156 result = create_object (root_poa.in (),
157 orb.in (),
158 &server_impl,
159 ior_output_file);
160 if (result == -1)
161 return -1;
163 // Run ORB Event loop.
164 poa_manager->activate ();
166 orb->run ();
168 ACE_DEBUG ((LM_DEBUG, "Server ORB event loop finished\n"));
170 catch (const CORBA::Exception& ex)
172 ex._tao_print_exception (
173 "Unexpected exception caught in Explicit_Binding test server:");
174 return -1;
177 return 0;