2 //=============================================================================
6 * This file is part of Fault Tolerant CORBA.
7 * Main wrapped around TAO_Object_Group_Creator
9 * @author Dale Wilson <wilson_d@ociweb.com>
11 //=============================================================================
13 #include "FT_Creator.h"
14 // FUZZ: disable check_for_streams_include
15 #include "ace/streams.h"
16 #include <orbsvcs/PortableGroup/PG_Properties_Encoder.h>
18 #include <ace/Get_Opt.h>
19 #include <ace/OS_NS_stdio.h>
21 FTAPP::FT_Creator::FT_Creator ()
23 , orb_ (CORBA::ORB::_nil ())
25 , replication_manager_ (::FT::ReplicationManager::_nil ())
26 , have_replication_manager_ (0)
35 FTAPP::FT_Creator::~FT_Creator ()
40 FTAPP::FT_Creator::parse_args (int argc
, ACE_TCHAR
*argv
[])
44 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("r:ignf:u:p:"));
47 while (result
== 0 && (c
= get_opts ()) != -1)
53 this->create_roles_
.push_back (ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ()));
58 this->unregister_roles_
.push_back (ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ()));
63 this->registry_ior_
= get_opts
.opt_arg ();
69 this->write_iogr_
= !this->write_iogr_
;
75 this->write_iors_
= ! this->write_iors_
;
81 this->ns_register_
= !this->ns_register_
;
87 this->prefix_
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg());
93 ACE_OS::fprintf (stderr
, "Creator: Unknown argument -%c\n", (char) c
);
107 if ( this->create_roles_
.size() == 0 && this->unregister_roles_
.size() == 0)
109 //FUZZ: disable check_for_lack_ACE_OS
110 ACE_OS::fprintf (stderr
, "Creator: neither create (-t) nor kill (-u) specified. Nothing to do.\n");
111 //FUZZ: enable check_for_lack_ACE_OS
119 void FTAPP::FT_Creator::usage(FILE* out
)const
121 ACE_OS::fprintf (out
, "usage\n"
122 " -r <role for objects to be created>\n"
123 " -f <factory registry ior file> (if not specified, ReplicationManager is used.)\n"
124 " -u <role to be unregistered (for testing factory registry)>\n"
125 " -i (toggle write ior for each object (default false))\n"
126 " -p <prefix for registration & file names>\n"
127 " -g (toggle write iogr to file (default false))\n"
128 " -n (toggle register iogr with name service (default true))\n");
132 int FTAPP::FT_Creator::init (CORBA::ORB_ptr orb
)
135 this->orb_
= CORBA::ORB::_duplicate (orb
);
137 // if a factory IOR was specified on command line
138 if ( this->registry_ior_
!= 0)
140 CORBA::Object_var registry_obj
141 = this->orb_
->string_to_object (this->registry_ior_
);
142 PortableGroup::FactoryRegistry_var registry
143 = PortableGroup::FactoryRegistry::_narrow(registry_obj
.in ());
144 if (! CORBA::is_nil (registry
.in ()))
146 result
= this->creator_
.set_factory_registry(registry
.in());
152 result
= this->creator_
.init (orb
);
156 if (result
== 0 && this->ns_register_
)
158 CORBA::Object_var naming_obj
=
159 this->orb_
->resolve_initial_references ("NameService");
161 if (CORBA::is_nil(naming_obj
.in ()))
163 ACE_ERROR_RETURN ((LM_ERROR
,
164 "%T %n (%P|%t) Unable to find the Naming Service\n"),
167 this->naming_context_
=
168 CosNaming::NamingContext::_narrow (naming_obj
.in ());
174 int FTAPP::FT_Creator::run ()
177 size_t typeCount
= this->create_roles_
.size();
179 for ( nType
= 0; result
== 0 && nType
< typeCount
; ++nType
)
181 const char * role
= this->create_roles_
[nType
].c_str();
182 ACE_OS::fprintf (stdout
, "\nCreator: Creating group of %s\n", role
);
183 PortableGroup::ObjectGroup_var group
= this->creator_
.create_group (
187 if (this->write_iogr_
)
189 CORBA::String_var iogr
= this->orb_
->object_to_string (group
.in ());
191 char iogr_filename
[1000];
192 ACE_OS::snprintf (iogr_filename
, sizeof(iogr_filename
),
193 "%s%s_" ACE_SIZE_T_FORMAT_SPECIFIER_ASCII
".iogr",
194 this->prefix_
.c_str (),
197 FILE * iogr_file
= ACE_OS::fopen (iogr_filename
, "w");
200 char const * siogr
= static_cast<const char *> (iogr
.in ());
201 ACE_OS::fwrite (siogr
, 1, ACE_OS::strlen(siogr
), iogr_file
);
202 ACE_OS::fclose (iogr_file
);
206 ACE_OS::fprintf (stderr
, "Can't open iogr output file %s\n", iogr_filename
);
211 if(this->ns_register_
)
213 char iogr_name
[1000];
214 ACE_OS::snprintf (iogr_name
, sizeof(iogr_name
),
215 "%s_%s_" ACE_SIZE_T_FORMAT_SPECIFIER_ASCII
,
216 this->prefix_
.c_str (),
220 CosNaming::Name
this_name (1);
221 this_name
.length (1);
222 this_name
[0].id
= CORBA::string_dup (iogr_name
);
224 this->naming_context_
->rebind (this_name
, group
.in());
230 typeCount
= this->unregister_roles_
.size();
231 for ( nType
= 0; result
== 0 && nType
< typeCount
; ++nType
)
233 const char * role
= this->unregister_roles_
[nType
].c_str();
234 result
= this->creator_
.unregister_role (role
);
240 int FTAPP::FT_Creator::fini ()
242 return this->creator_
.fini();
246 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
251 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
252 FTAPP::FT_Creator app
;
253 result
= app
.parse_args(argc
, argv
);
256 result
= app
.init (orb
.in ());
267 catch (const CORBA::Exception
& ex
)
269 ex
._tao_print_exception ("FT_Creator::main\t\n");