Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / tests / NestedUpcall / Simple / server.cpp
blobd5ef9e815ba0f80826cf866a65114097616c8f0b
1 #include "server_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Task.h"
5 static int quiet = 0;
6 // The test is quiet...
8 static const ACE_TCHAR *ior_file = ACE_TEXT ("test.ior");
9 // File of file to which the ior is written
11 static int number_of_threads = 1;
12 // Number of server threads.
14 class Server_Task : public ACE_Task_Base
16 public:
17 Server_Task (CORBA::ORB_ptr orb);
18 int svc ();
20 private:
21 CORBA::ORB_var orb_;
24 Server_Task::Server_Task (CORBA::ORB_ptr orb)
25 : orb_ (CORBA::ORB::_duplicate (orb))
29 int
30 Server_Task::svc ()
32 try
34 this->orb_->run ();
36 catch (const CORBA::Exception&)
38 return -1;
40 return 0;
43 static int
44 write_ior_to_file (const char *ior)
46 FILE *output_file = ACE_OS::fopen (ior_file, "w");
48 if (output_file == 0)
49 ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output files for writing IOR: %s\n",
50 ior_file),
51 -1);
53 int result = 0;
55 result = ACE_OS::fprintf (output_file,
56 "%s",
57 ior);
58 if (result < 0 ||
59 static_cast<size_t> (result) != ACE_OS::strlen (ior))
60 ACE_ERROR_RETURN ((LM_ERROR,
61 "ACE_OS::fprintf failed while writing %C to %s\n",
62 ior,
63 ior_file),
64 -1);
66 ACE_OS::fclose (output_file);
68 return 0;
71 static int
72 parse_args (int argc,
73 ACE_TCHAR **argv)
75 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("q:f:t:"));
76 int c;
78 while ((c = get_opts ()) != -1)
79 switch (c)
81 case 'q':
82 quiet = 1;
83 break;
85 case 't':
86 number_of_threads = ACE_OS::atoi (get_opts.opt_arg ());
87 break;
89 case 'f':
90 ior_file = get_opts.opt_arg ();
91 break;
93 case '?':
94 default:
95 ACE_ERROR_RETURN ((LM_ERROR,
96 "usage: %s"
97 " [-t number of threads]"
98 " [-f ior file]"
99 " [-q (quite)]"
100 "\n",
101 argv[0]),
102 -1);
105 return 0;
109 ACE_TMAIN (int argc, ACE_TCHAR **argv)
113 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
115 int result = parse_args (argc, argv);
116 if (result != 0)
117 return result;
119 CORBA::Object_var object = orb->resolve_initial_references ("RootPOA");
121 PortableServer::POA_var root_poa =
122 PortableServer::POA::_narrow (object.in ());
124 PortableServer::POAManager_var poa_manager =
125 root_poa->the_POAManager ();
127 poa_manager->activate ();
129 server_i server_servant (quiet,
130 orb.in ());
132 PortableServer::ObjectId_var id =
133 root_poa->activate_object (&server_servant);
135 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
137 server_var server_object = server::_narrow (object_act.in ());
139 CORBA::String_var ior = orb->object_to_string (server_object.in ());
141 result = write_ior_to_file (ior.in ());
142 if (result != 0)
143 return result;
145 Server_Task server_tasks (orb.in ());
147 result = server_tasks.activate (THR_BOUND,
148 number_of_threads);
150 if (result != 0)
151 return result;
153 result = ACE_Thread_Manager::instance ()->wait ();
155 if (result != 0)
156 return result;
158 root_poa->destroy (true, true);
160 catch (const CORBA::Exception& ex)
162 ex._tao_print_exception ("server::main");
163 return -1;
166 return 0;