2 //=============================================================================
4 * @file LifeCycle_Service.cpp
6 * The server for the LifeCycleService of the quoter example.
8 * @author Michael Kircher (mk1@cs.wustl.edu)
10 //=============================================================================
13 #include "orbsvcs/Log_Macros.h"
14 #include "LifeCycle_Service.h"
16 #include "ace/Argv_Type_Converter.h"
17 #include "ace/OS_main.h"
19 Life_Cycle_Service_Server::Life_Cycle_Service_Server ()
24 Life_Cycle_Service_Server::~Life_Cycle_Service_Server ()
28 // Unbind the Factory Finder.
29 CosNaming::Name
generic_Factory_Name (2);
30 generic_Factory_Name
.length (2);
31 generic_Factory_Name
[0].id
= CORBA::string_dup ("LifeCycle_Service");
32 this->namingContext_var_
->unbind (generic_Factory_Name
);
34 catch (const CORBA::Exception
& ex
)
36 ex
._tao_print_exception ("User Exception");
41 Life_Cycle_Service_Server::init (int argc
,
46 // Copy command line parameter.
47 ACE_Argv_Type_Converter
command(argc
, argv
);
49 retval
= this->orb_manager_
.init (command
.get_argc(),
50 command
.get_TCHAR_argv());
53 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
58 // Activate the POA manager
59 retval
= this->orb_manager_
.activate_poa_manager ();
62 ORBSVCS_ERROR_RETURN ((LM_ERROR
, "%p\n", "activate_poa_manager"), -1);
65 this->parse_args (command
.get_argc(), command
.get_TCHAR_argv());
67 ACE_NEW_RETURN (this->life_Cycle_Service_i_ptr_
,
68 Life_Cycle_Service_i(this->debug_level_
),
71 // Activate the object.
72 CORBA::String_var str
=
73 this->orb_manager_
.activate (this->life_Cycle_Service_i_ptr_
);
75 if (this->debug_level_
>= 2)
76 ORBSVCS_DEBUG ((LM_DEBUG
, "LifeCycle_Service: IOR is: <%C>\n", str
.in ()));
78 // Register the LifeCycle Service with the Naming Service.
81 if (this->debug_level_
>= 2)
82 ORBSVCS_DEBUG ((LM_DEBUG
,
83 ACE_TEXT("LifeCycle_Service: Trying to get a reference to the Naming Service.\n")));
85 // Get the Naming Service object reference.
86 CORBA::Object_var namingObj_var
=
87 orb_manager_
.orb()->resolve_initial_references ("NameService");
89 if (CORBA::is_nil (namingObj_var
.in ()))
90 ORBSVCS_ERROR ((LM_ERROR
,
91 " LifeCycle_Service: Unable get the Naming Service.\n"));
93 // Narrow the object reference to a Naming Context.
94 namingContext_var_
= CosNaming::NamingContext::_narrow (namingObj_var
.in ());
97 if (CORBA::is_nil (namingContext_var_
.in ()))
98 ORBSVCS_ERROR ((LM_ERROR
,
99 "LifeCycle_Service: Unable get the Naming Service.\n"));
101 if (this->debug_level_
>= 2)
102 ORBSVCS_DEBUG ((LM_DEBUG
,
103 ACE_TEXT("LifeCycle_Service: Have a proper reference to the Naming Service.\n")));
105 CosNaming::Name
life_Cycle_Service_Name (1);
106 life_Cycle_Service_Name
.length (1);
107 life_Cycle_Service_Name
[0].id
= CORBA::string_dup ("Life_Cycle_Service");
109 CORBA::Object_ptr tmp
= this->life_Cycle_Service_i_ptr_
->_this();
111 namingContext_var_
->bind (life_Cycle_Service_Name
,
114 if (this->debug_level_
>= 2)
115 ORBSVCS_DEBUG ((LM_DEBUG
,
116 ACE_TEXT("LifeCycle_Service: Bound the LifeCycle Service to the Naming Context.\n")));
118 catch (const CORBA::Exception
& ex
)
120 ex
._tao_print_exception (
121 "Life_Cycle_Service_Server::init");
129 Life_Cycle_Service_Server::run ()
131 if (this->debug_level_
>= 1)
132 ORBSVCS_DEBUG ((LM_DEBUG
,
133 ACE_TEXT("\nLifeCycle Service: Life_Cycle_Service_Server is running\n")));
135 orb_manager_
.orb()->run ();
141 // Function get_options.
144 Life_Cycle_Service_Server::parse_args (int argc
,
147 ACE_Get_Opt
get_opt (argc
, argv
, ACE_TEXT("?d:"));
151 while ((opt
= get_opt ()) != EOF
)
154 case 'd': // debug flag.
155 this->debug_level_
= ACE_OS::atoi (get_opt
.opt_arg ());
159 ORBSVCS_ERROR ((LM_ERROR
,
160 "%s: unknown arg, -%c\n",
161 argv
[0], char(opt
)));
164 ORBSVCS_DEBUG ((LM_DEBUG
,
165 ACE_TEXT("usage: %s")
166 ACE_TEXT(" [-d] <debug level> - Set the debug level\n")
167 ACE_TEXT(" [-?] - Prints this message\n")
170 ACE_OS::exit (exit_code
);
179 ACE_TMAIN (int argc
, ACE_TCHAR
* argv
[])
181 Life_Cycle_Service_Server life_Cycle_Service_Server
;
185 int check
= life_Cycle_Service_Server
.init (argc
,
192 life_Cycle_Service_Server
.run ();
195 catch (const CORBA::Exception
& ex
)
197 ex
._tao_print_exception ("LifeCycleService::main");