2 //=============================================================================
4 * @file Factory_Finder.cpp
6 * A Factory Finder for the Quoter example. This example conforms
7 * to the CosLifeCycle Factory Finder notion.
9 * @author Michael Kircher (mk1@cs.wustl.edu)
11 //=============================================================================
14 #include "Factory_Finder.h"
16 Quoter_Factory_Finder_Server::Quoter_Factory_Finder_Server ()
22 Quoter_Factory_Finder_Server::~Quoter_Factory_Finder_Server ()
26 // Unbind the Quoter Factory Finder.
27 CosNaming::Name
factory_Finder_Name (2);
28 factory_Finder_Name
.length (2);
29 factory_Finder_Name
[0].id
= CORBA::string_dup ("IDL_Quoter");
30 factory_Finder_Name
[1].id
= CORBA::string_dup ("Quoter_Factory_Finder");
31 if (!CORBA::is_nil (this->quoterNamingContext_var_
.in ()))
32 this->quoterNamingContext_var_
->unbind (factory_Finder_Name
);
34 catch (const CORBA::Exception
& ex
)
36 ACE_ERROR ((LM_ERROR
, "Could not unbind the Factor Finder from the Name Service\n"));
37 ex
._tao_print_exception ("~Quoter_Factor_Finder_Server");
42 Quoter_Factory_Finder_Server::init (int argc
,
45 const char *exception_message
= "Null Message";
49 exception_message
= "While ORB_Manager::init";
50 int initvalue
= this->orb_manager_
.init (argc
,
54 ACE_ERROR_RETURN ((LM_ERROR
,
59 // Activate the POA manager
60 exception_message
= "While activating the POA manager";
61 int result
= this->orb_manager_
.activate_poa_manager ();
64 ACE_ERROR_RETURN ((LM_ERROR
, "%p\n", "activate_poa_manager"), -1);
66 // Copy them, because parse_args expects them there.
73 ACE_NEW_RETURN (this->quoter_Factory_Finder_i_ptr_
,
74 Quoter_Factory_Finder_i(this->debug_level_
),
77 // Activate the object.
78 exception_message
= "Failure while activating the Quoter Factory Finder Impl";
79 CORBA::String_var str
=
80 this->orb_manager_
.activate (this->quoter_Factory_Finder_i_ptr_
);
83 if (this->debug_level_
>= 2)
84 ACE_DEBUG ((LM_DEBUG
, "Factory Finder: IOR is: <%C>\n", str
.in ()));
86 // Register the Quoter Factory Finder with the Naming Service
87 if (this->debug_level_
>= 2)
88 ACE_DEBUG ((LM_DEBUG
,"Factory Finder: Trying to get a reference to the Naming Service.\n"));
90 // Get the Naming Service object reference.
91 exception_message
= "While resolving the Name Service";
92 CORBA::Object_var namingObj_var
=
93 orb_manager_
.orb()->resolve_initial_references ("NameService");
95 if (CORBA::is_nil (namingObj_var
.in ()))
97 " (%P|%t) Unable get the Naming Service.\n"));
99 // Narrow the object reference to a Naming Context.
100 exception_message
= "While narrowing the Naming Context";
101 CosNaming::NamingContext_var namingContext_var
=
102 CosNaming::NamingContext::_narrow (namingObj_var
.in ());
104 // Get the IDL_Quoter naming context.
105 CosNaming::Name
quoterContextName (1); // max = 1
106 quoterContextName
.length (1);
107 quoterContextName
[0].id
= CORBA::string_dup ("IDL_Quoter");
109 exception_message
= "While resolving the Quoter Naming Context";
110 CORBA::Object_var quoterNamingObj_var
=
111 namingContext_var
->resolve (quoterContextName
);
113 exception_message
= "While narrowing the Quoter Naming Context";
114 quoterNamingContext_var_
=
115 CosNaming::NamingContext::_narrow (quoterNamingObj_var
.in ());
117 if (this->debug_level_
>= 2)
118 ACE_DEBUG ((LM_DEBUG
,
119 "Factory Finder: Have a proper reference to the Quoter Naming Context.\n"));
121 // Bind the QuoterFactory Finder to the IDL_Quoter naming
123 CosNaming::Name
quoter_Factory_Finder_Name_ (1);
124 quoter_Factory_Finder_Name_
.length (1);
125 quoter_Factory_Finder_Name_
[0].id
= CORBA::string_dup ("Quoter_Factory_Finder");
127 exception_message
= "Factory_Factory::_this";
128 CORBA::Object_var ff_obj
= this->quoter_Factory_Finder_i_ptr_
->_this();
130 exception_message
= "While binding the Factory Finder";
131 quoterNamingContext_var_
->bind (quoter_Factory_Finder_Name_
,
134 if (this->debug_level_
>= 2)
135 ACE_DEBUG ((LM_DEBUG
,
136 "Factory_Finder: Bound the Quoter Factory Finder to the Quoter Naming Context.\n"));
138 catch (const CORBA::Exception
& ex
)
140 ACE_ERROR ((LM_ERROR
, "Quoter_Factor_Finder_Server::init - %C\n", exception_message
));
141 ex
._tao_print_exception ("SYS_EX");
149 Quoter_Factory_Finder_Server::run ()
151 if (this->debug_level_
>= 1)
152 ACE_DEBUG ((LM_DEBUG
,
153 "\nQuoter Example: Quoter_Factory_Finder_Server is running\n"));
155 orb_manager_
.orb()->run ();
161 // Function get_options.
164 Quoter_Factory_Finder_Server::parse_args ()
166 ACE_Get_Opt
get_opt (this->argc_
, this->argv_
, ACE_TEXT("?d:"));
170 while ((opt
= get_opt ()) != EOF
)
173 case 'd': // debug flag.
174 this->debug_level_
= ACE_OS::atoi (get_opt
.opt_arg ());
178 ACE_ERROR ((LM_ERROR
,
179 "%s: unknown arg, -%c\n",
180 this->argv_
[0], char(opt
)));
183 ACE_DEBUG ((LM_DEBUG
,
185 " [-d] <debug level> - Set the debug level\n"
186 " [-?] - Prints this message\n"
189 ACE_OS::exit (exit_code
);
198 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
200 Quoter_Factory_Finder_Server quoter_Factory_Finder_Server
;
204 int result
= quoter_Factory_Finder_Server
.init (argc
, argv
);
210 quoter_Factory_Finder_Server
.run ();
213 catch (const CORBA::SystemException
& sysex
)
215 sysex
._tao_print_exception ("System Exception");
218 catch (const CORBA::UserException
& userex
)
220 userex
._tao_print_exception ("User Exception");