2 //=============================================================================
4 * @file Concurrency_Service.cpp
6 * This class implements a Concurrency_Service object.
8 * @author Torben Worm <tworm@cs.wustl.edu>
10 //=============================================================================
13 #include "orbsvcs/Log_Macros.h"
14 #include "Concurrency_Service.h"
16 #include "orbsvcs/Daemon_Utilities.h"
18 #include "ace/Argv_Type_Converter.h"
19 #include "tao/debug.h"
20 #include "ace/OS_main.h"
21 #include "ace/OS_NS_stdio.h"
22 #include "ace/OS_NS_unistd.h"
24 // Default Constructor.
26 Concurrency_Service::Concurrency_Service ()
27 : use_naming_service_ (1),
31 ORBSVCS_DEBUG ((LM_DEBUG
,
32 ACE_TEXT("Concurrency_Service::Concurrency_Service ()\n")));
35 // Constructor taking command-line arguments.
37 Concurrency_Service::Concurrency_Service (int argc
,
40 ORBSVCS_DEBUG ((LM_DEBUG
,
41 ACE_TEXT("Concurrency_Service::Concurrency_Service (...)\n")));
42 this->init (argc
, argv
);
46 Concurrency_Service::parse_args (int argc
, ACE_TCHAR
** argv
)
48 ORBSVCS_DEBUG ((LM_DEBUG
,
49 ACE_TEXT("Concurrency_Service::parse_args\n")));
51 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("do:p:s"));
54 while ((c
= get_opts ()) != -1)
57 case 'd': // debug flag
60 case 'o': // output the IOR to a file
61 this->ior_file_name_
= get_opts
.opt_arg();
64 this->pid_file_name_
= get_opts
.opt_arg();
67 this->use_naming_service_
= 0;
70 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
73 ACE_TEXT(" [-o] <ior_output_file>")
78 // Indicates successful persing of command line.
82 // Initialize the state of the Concurrency_Service object.
85 Concurrency_Service::init (int argc
,
88 ORBSVCS_DEBUG ((LM_DEBUG
,
89 "Concurrency_Service::init\n"));
91 // Check if -ORBDaemon is specified and if so, daemonize at this moment,
92 // -ORBDaemon in the ORB core is faulty, see bugzilla 3335
93 TAO_Daemon_Utility::check_for_daemon (argc
, argv
);
95 // Copy command line parameter.
96 ACE_Argv_Type_Converter
command_line(argc
, argv
);
98 if (this->orb_manager_
.init_child_poa (command_line
.get_argc(),
99 command_line
.get_TCHAR_argv(),
101 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
103 ACE_TEXT("init_child_poa")),
106 if (this->parse_args (command_line
.get_argc(), command_line
.get_TCHAR_argv())!=0)
107 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
108 ACE_TEXT("Could not parse command line\n")),
110 CORBA::String_var str
=
111 this->orb_manager_
.activate (this->my_concurrency_server_
.GetLockSetFactory ());
112 ORBSVCS_DEBUG ((LM_DEBUG
,
113 "The IOR is: <%C>\n",
116 if (this->ior_file_name_
!= 0)
118 FILE* iorf
= ACE_OS::fopen (ior_file_name_
, ACE_TEXT("w"));
121 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
122 "Cannot open output file for writing IOR: %s",
127 ACE_OS::fprintf (iorf
, "%s\n", str
.in ());
128 ACE_OS::fclose (iorf
);
131 if (this->pid_file_name_
!= 0)
133 FILE* pidf
= ACE_OS::fopen (pid_file_name_
, ACE_TEXT("w"));
136 ACE_OS::fprintf (pidf
,
138 static_cast<long> (ACE_OS::getpid ()));
139 ACE_OS::fclose (pidf
);
143 if (this->use_naming_service_
)
144 return this->init_naming_service ();
150 Concurrency_Service::init_naming_service ()
152 ORBSVCS_DEBUG ((LM_DEBUG
, "Concurrency_Service::init_naming_service (...)\n"));
154 PortableServer::POA_var child_poa
;
156 orb
= this->orb_manager_
.orb ();
158 int result
= this->naming_client_
.init (orb
.in ());
163 this->my_concurrency_server_
.GetLockSetFactory ()->_this ();
165 CosNaming::Name
concurrency_context_name (1);
166 concurrency_context_name
.length (1);
167 concurrency_context_name
[0].id
= CORBA::string_dup ("CosConcurrency");
169 this->concurrency_context_
=
170 this->naming_client_
->bind_new_context (concurrency_context_name
);
172 CosNaming::Name
lockset_name (1);
173 lockset_name
.length (1);
174 lockset_name
[0].id
= CORBA::string_dup ("LockSetFactory");
175 this->concurrency_context_
->bind (lockset_name
,
176 lockset_factory_
.in ());
180 // Run the ORB event loop.
183 Concurrency_Service::run ()
185 ORBSVCS_DEBUG ((LM_DEBUG
,
186 "Concurrency_Service::run (...)\n"));
188 int retval
= this->orb_manager_
.run ();
190 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
191 "Concurrency_Service::run"),
198 Concurrency_Service::~Concurrency_Service ()
200 ORBSVCS_DEBUG ((LM_DEBUG
,
201 "Concurrency_Service::~Concurrency_Service ()\n"));
205 ACE_TMAIN (int argc
, ACE_TCHAR
** argv
)
207 Concurrency_Service concurrency_service
;
209 ORBSVCS_DEBUG ((LM_DEBUG
,
210 "\n \t Concurrency Service:SERVER \n\n"));
214 int r
= concurrency_service
.init (argc
, argv
);
219 concurrency_service
.run ();
222 catch (const CORBA::SystemException
& sysex
)
224 sysex
._tao_print_exception ("System Exception");
227 catch (const CORBA::UserException
& userex
)
229 userex
._tao_print_exception ("User Exception");