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");
133 int FTAPP::FT_Creator::init (CORBA::ORB_ptr orb
)
136 this->orb_
= CORBA::ORB::_duplicate (orb
);
138 // if a factory IOR was specified on command line
139 if ( this->registry_ior_
!= 0)
141 CORBA::Object_var registry_obj
142 = this->orb_
->string_to_object (this->registry_ior_
);
143 PortableGroup::FactoryRegistry_var registry
144 = PortableGroup::FactoryRegistry::_narrow(registry_obj
.in ());
145 if (! CORBA::is_nil (registry
.in ()))
147 result
= this->creator_
.set_factory_registry(registry
.in());
153 result
= this->creator_
.init (orb
);
157 if (result
== 0 && this->ns_register_
)
159 CORBA::Object_var naming_obj
=
160 this->orb_
->resolve_initial_references ("NameService");
162 if (CORBA::is_nil(naming_obj
.in ()))
164 ACE_ERROR_RETURN ((LM_ERROR
,
165 "%T %n (%P|%t) Unable to find the Naming Service\n"),
168 this->naming_context_
=
169 CosNaming::NamingContext::_narrow (naming_obj
.in ());
175 int FTAPP::FT_Creator::run (void)
178 size_t typeCount
= this->create_roles_
.size();
180 for ( nType
= 0; result
== 0 && nType
< typeCount
; ++nType
)
182 const char * role
= this->create_roles_
[nType
].c_str();
183 ACE_OS::fprintf (stdout
, "\nCreator: Creating group of %s\n", role
);
184 PortableGroup::ObjectGroup_var group
= this->creator_
.create_group (
188 if (this->write_iogr_
)
190 CORBA::String_var iogr
= this->orb_
->object_to_string (group
.in ());
192 char iogr_filename
[1000];
193 ACE_OS::snprintf (iogr_filename
, sizeof(iogr_filename
),
194 "%s%s_" ACE_SIZE_T_FORMAT_SPECIFIER_ASCII
".iogr",
195 this->prefix_
.c_str (),
198 FILE * iogr_file
= ACE_OS::fopen (iogr_filename
, "w");
201 char const * siogr
= static_cast<const char *> (iogr
.in ());
202 ACE_OS::fwrite (siogr
, 1, ACE_OS::strlen(siogr
), iogr_file
);
203 ACE_OS::fclose (iogr_file
);
207 ACE_OS::fprintf (stderr
, "Can't open iogr output file %s\n", iogr_filename
);
212 if(this->ns_register_
)
214 char iogr_name
[1000];
215 ACE_OS::snprintf (iogr_name
, sizeof(iogr_name
),
216 "%s_%s_" ACE_SIZE_T_FORMAT_SPECIFIER_ASCII
,
217 this->prefix_
.c_str (),
221 CosNaming::Name
this_name (1);
222 this_name
.length (1);
223 this_name
[0].id
= CORBA::string_dup (iogr_name
);
225 this->naming_context_
->rebind (this_name
, group
.in());
232 typeCount
= this->unregister_roles_
.size();
233 for ( nType
= 0; result
== 0 && nType
< typeCount
; ++nType
)
235 const char * role
= this->unregister_roles_
[nType
].c_str();
236 result
= this->creator_
.unregister_role (role
);
242 int FTAPP::FT_Creator::fini ()
244 return this->creator_
.fini();
248 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
253 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
254 FTAPP::FT_Creator app
;
255 result
= app
.parse_args(argc
, argv
);
258 result
= app
.init (orb
.in ());
269 catch (const CORBA::Exception
& ex
)
271 ex
._tao_print_exception ("FT_Creator::main\t\n");