Cleanup Solaris support
[ACE_TAO.git] / TAO / performance-tests / Callback / server.cpp
blobd7a2a43ec3bbdbedec3ffa96500825791f6c5b8a
1 #include "Server_i.h"
3 #include "tao/Messaging/Messaging.h"
4 #include "tao/Strategies/advanced_resource.h"
5 #include "tao/AnyTypeCode/Any.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/Sched_Params.h"
8 #include "ace/OS_NS_errno.h"
10 const ACE_TCHAR *ior_file_name = ACE_TEXT("test.ior");
12 /// Parse the arguments.
13 static int parse_args (int argc, ACE_TCHAR *argv[]);
15 int
16 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
18 int priority =
19 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
20 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
21 priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO, priority);
22 // Enable FIFO scheduling
23 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
24 priority,
25 ACE_SCOPE_PROCESS)) != 0)
27 if (ACE_OS::last_error () == EPERM)
29 ACE_DEBUG ((LM_DEBUG,
30 "server (%P|%t): user is not superuser, "
31 "test runs in time-shared class\n"));
33 else
34 ACE_ERROR ((LM_ERROR,
35 "server (%P|%t): sched_params failed\n"));
38 try
40 CORBA::ORB_var orb =
41 CORBA::ORB_init (argc, argv);
43 CORBA::Object_var manager_object =
44 orb->resolve_initial_references ("ORBPolicyManager");
46 CORBA::PolicyManager_var policy_manager =
47 CORBA::PolicyManager::_narrow (manager_object.in ());
49 CORBA::Any sync_scope;
50 sync_scope <<= Messaging::SYNC_WITH_TARGET;
52 CORBA::PolicyList policy_list (1);
53 policy_list.length (1);
54 policy_list[0] =
55 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
56 sync_scope);
57 policy_manager->set_policy_overrides (policy_list,
58 CORBA::SET_OVERRIDE);
60 CORBA::Object_var poa_object =
61 orb->resolve_initial_references("RootPOA");
63 if (CORBA::is_nil (poa_object.in ()))
64 ACE_ERROR_RETURN ((LM_ERROR,
65 " (%P|%t) Unable to initialize the POA.\n"),
66 1);
68 PortableServer::POA_var root_poa =
69 PortableServer::POA::_narrow (poa_object.in ());
71 PortableServer::POAManager_var poa_manager =
72 root_poa->the_POAManager ();
74 poa_manager->activate ();
76 if (parse_args (argc, argv) != 0)
77 return 1;
79 Server_i server_i;
81 Test::Server_var server = server_i._this ();
83 CORBA::String_var str =
84 orb->object_to_string (server.in ());
86 if (ior_file_name != 0)
88 FILE *output_file = ACE_OS::fopen (ior_file_name, "w");
89 if (output_file == 0)
90 ACE_ERROR_RETURN ((LM_ERROR,
91 "Cannot open output file for writing IOR: %s",
92 ior_file_name),
93 1);
94 ACE_OS::fprintf (output_file, "%s", str.in ());
95 ACE_OS::fclose (output_file);
98 while (!server_i.done ())
100 ACE_Time_Value tv (1, 0);
101 orb->run (tv);
104 PortableServer::ObjectId_var id =
105 root_poa->servant_to_id (&server_i);
106 root_poa->deactivate_object (id.in ());
108 orb->destroy ();
110 catch (const CORBA::Exception& ex)
112 ex._tao_print_exception (argv[0]);
114 return 0;
117 // ****************************************************************
120 parse_args (int argc, ACE_TCHAR *argv[])
122 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
123 int c;
125 while ((c = get_opts ()) != -1)
126 switch (c)
128 case 'o':
129 ior_file_name = get_opts.opt_arg ();
130 break;
132 case '?':
133 default:
134 ACE_ERROR_RETURN ((LM_ERROR,
135 "usage: %s "
136 "-o <ior_file_name>"
137 "\n",
138 argv [0]),
139 -1);
141 // Indicates successful parsing of the command line
142 return 0;