2 #include "StubFaultNotifier.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "orbsvcs/PortableGroup/PG_Properties_Encoder.h"
6 // FUZZ: disable check_for_streams_include
7 #include "ace/streams.h"
9 StubFaultNotifier::StubFaultNotifier ()
17 StubFaultNotifier::~StubFaultNotifier ()
22 ::PortableServer::POA_ptr
StubFaultNotifier::_default_POA ()
24 return ::PortableServer::POA::_duplicate(this->poa_
.in ());
27 PortableServer::ObjectId
StubFaultNotifier::objectId()const
29 return this->object_id_
.in();
32 int StubFaultNotifier::parse_args (int argc
, ACE_TCHAR
* argv
[])
35 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:r:d:n:"));
37 while ((c
= get_opts ()) != -1)
43 this->iorReplicaFiles_
.push_back( ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ()));
48 this->detector_ior_
= get_opts
.opt_arg ();
53 this->ns_name_
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
58 this->ior_output_file_
= get_opts
.opt_arg ();
73 if (iorReplicaFiles_
.size() == 0)
76 "-r option is required.\n"
80 if (0 == this->detector_ior_
)
83 "-d option is required.\n"
93 " -r <replica.ior [-r <replica2.ior]...>"
96 " -n <nameService name>"
107 int StubFaultNotifier::fini ()
109 if(this->ns_name_
.length () != 0)
111 CORBA::Object_var naming_obj
=
112 this->orb_
->resolve_initial_references ("NameService");
114 if (CORBA::is_nil(naming_obj
.in ())){
115 ACE_ERROR_RETURN ((LM_ERROR
,
116 "%T %n (%P|%t) Unable to find the Naming Service\n"),
120 CosNaming::NamingContext_var naming_context
=
121 CosNaming::NamingContext::_narrow (naming_obj
.in ());
123 CosNaming::Name
this_name (1);
124 this_name
.length (1);
125 this_name
[0].id
= CORBA::string_dup (this->ns_name_
.c_str ());
127 naming_context
->unbind (this_name
);
134 * Publish this objects IOR.
136 int StubFaultNotifier::init (CORBA::ORB_ptr orb
)
139 this->orb_
= CORBA::ORB::_duplicate (orb
);
141 // Use the ROOT POA for now
142 CORBA::Object_var poa_object
=
143 this->orb_
->resolve_initial_references (TAO_OBJID_ROOTPOA
);
145 if (CORBA::is_nil (poa_object
.in ()))
146 ACE_ERROR_RETURN ((LM_ERROR
,
147 ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
150 // Get the POA object.
152 PortableServer::POA::_narrow (poa_object
.in ());
155 if (CORBA::is_nil(this->poa_
.in ()))
157 ACE_ERROR_RETURN ((LM_ERROR
,
158 ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")),
162 PortableServer::POAManager_var poa_manager
=
163 this->poa_
->the_POAManager ();
165 poa_manager
->activate ();
167 // Register with the POA.
169 this->object_id_
= this->poa_
->activate_object (this);
171 // find my identity as a corba object
172 CORBA::Object_var this_obj
=
173 this->poa_
->id_to_reference (object_id_
.in ());
175 //////////////////////////////////////////
176 // resolve references to detector factory
178 CORBA::Object_var obj
= this->orb_
->string_to_object(detector_ior_
);
179 this->factory_
= ::FT::FaultDetectorFactory::_narrow(obj
.in ());
180 if (CORBA::is_nil(this->factory_
.in ()))
182 ACE_OS::fprintf (stderr
, "Can't resolve Detector Factory IOR %s\n",
183 ACE_TEXT_ALWAYS_CHAR (this->detector_ior_
));
188 ////////////////////////////////////
189 // resolve references to replicas
190 size_t replicaCount
= this->iorReplicaFiles_
.size();
191 for(size_t nRep
= 0; result
== 0 && nRep
< replicaCount
; ++nRep
)
193 const char * iorName
= this->iorReplicaFiles_
[nRep
];
194 CORBA::Object_var obj
= this->orb_
->string_to_object(iorName
);
195 FT::PullMonitorable_var replica
= FT::PullMonitorable::_narrow(obj
.in ());
196 if (CORBA::is_nil(replica
.in ()))
198 ACE_OS::fprintf (stderr
, "Can't resolve Replica IOR %s\n", iorName
);
203 this->replicas_
.push_back(replica
);
205 CORBA::String_var type_id
= CORBA::string_dup("FaultDetector");
207 TAO_PG::Properties_Encoder encoder
;
209 PortableGroup::Value value
;
211 // FaultDetectorFactory gets picky about FaultNotifier's object type.
213 ::FT::FaultNotifier_var notifier
= ::FT::FaultNotifier::_narrow(this_obj
.in ());
214 value
<<= notifier
.in ();
215 encoder
.add(::FT::FT_NOTIFIER
, value
);
218 value
<<= replica
.in ();
219 encoder
.add(::FT::FT_MONITORABLE
, value
);
221 FT::FTDomainId domain_id
= 0;
223 encoder
.add(::FT::FT_DOMAIN_ID
, value
);
225 PortableGroup::Location object_location
;
226 object_location
.length(1);
227 object_location
[0].id
= CORBA::string_dup("Test location");
228 value
<<= object_location
;
229 encoder
.add(::FT::FT_LOCATION
, value
);
231 PortableGroup::TypeId object_type
= 0;
232 value
<<= object_type
;
233 encoder
.add(::FT::FT_TYPE_ID
, value
);
235 PortableGroup::ObjectGroupId group_id
= 0;
237 encoder
.add(::FT::FT_GROUP_ID
, value
);
239 // allocate and populate the criteria
240 PortableGroup::Criteria_var criteria
;
241 ACE_NEW_NORETURN (criteria
,
242 PortableGroup::Criteria
);
243 if (criteria
.ptr() == 0)
246 "Error cannot allocate criteria.\n"
252 encoder
.encode(criteria
);
253 PortableGroup::GenericFactory::FactoryCreationId_var factory_creation_id
;
255 this->factory_
->create_object (
258 factory_creation_id
);
263 if (this->ior_output_file_
!= 0)
265 this->identity_
= ACE_TEXT("file:");
266 this->identity_
+= this->ior_output_file_
;
267 result
= write_ior_file();
271 // if no IOR file specified,
272 // then always try to register with name service
273 this->ns_name_
= "FT_FaultNotifier";
276 if(this->ns_name_
.length () != 0)
278 this->identity_
= ACE_TEXT("name:");
279 this->identity_
+= ACE_TEXT_CHAR_TO_TCHAR(this->ns_name_
.c_str ());
281 CORBA::Object_var naming_obj
=
282 this->orb_
->resolve_initial_references ("NameService");
284 if (CORBA::is_nil(naming_obj
.in ())){
285 ACE_ERROR_RETURN ((LM_ERROR
,
286 "%T %n (%P|%t) Unable to find the Naming Service\n"),
290 CosNaming::NamingContext_var naming_context
=
291 CosNaming::NamingContext::_narrow (naming_obj
.in ());
293 CosNaming::Name
this_name (1);
294 this_name
.length (1);
295 this_name
[0].id
= CORBA::string_dup (this->ns_name_
.c_str ());
297 naming_context
->rebind (this_name
, this_obj
.in());
303 int StubFaultNotifier::write_ior_file()
306 FILE* out
= ACE_OS::fopen (this->ior_output_file_
, "w");
309 ACE_OS::fprintf (out
, "%s", this->ior_
.in ());
310 ACE_OS::fclose (out
);
317 * Return a string to identify this object for logging/console message purposes.
319 const ACE_TCHAR
* StubFaultNotifier::identity () const
321 return this->identity_
.c_str();
325 * Clean house for process shut down.
327 void StubFaultNotifier::shutdown_i ()
329 this->orb_
->shutdown (false);
332 void StubFaultNotifier::push_structured_fault (
333 const CosNotification::StructuredEvent
& event
336 ACE_ERROR ((LM_ERROR
,
337 "FaultNotifier: Received Fault notification:\n"
338 "FaultNotifier: Header EventType domain: %s\n"
339 "FaultNotifier: Header EventType type: %s\n"
340 "FaultNotifier: Header EventName: %s\n",
341 static_cast<const char *> (event
.header
.fixed_header
.event_type
.domain_name
),
342 static_cast<const char *> (event
.header
.fixed_header
.event_type
.type_name
),
343 static_cast<const char *> (event
.header
.fixed_header
.event_name
)
345 const CosNotification::FilterableEventBody
& filterable
= event
.filterable_data
;
347 size_t propertyCount
= filterable
.length ();
348 for (size_t nProp
= 0; nProp
< propertyCount
; ++nProp
)
350 const CosNotification::Property
& property
= filterable
[nProp
];
351 ACE_ERROR ((LM_ERROR
,
352 "FaultNotifier: Property Name: %s\n",
353 static_cast<const char *> (property
.name
)
355 //@@ we could stand to decode more--just for completeness
360 void StubFaultNotifier::push_sequence_fault (
361 const CosNotification::EventBatch
& events
364 ACE_UNUSED_ARG (events
);
365 throw CORBA::NO_IMPLEMENT();
368 ::CosNotifyFilter::Filter_ptr
StubFaultNotifier::create_subscription_filter (
369 const char * constraint_grammar
372 ACE_UNUSED_ARG (constraint_grammar
);
373 throw CORBA::NO_IMPLEMENT();
378 FT::FaultNotifier::ConsumerId
StubFaultNotifier::connect_structured_fault_consumer (
379 CosNotifyComm::StructuredPushConsumer_ptr push_consumer
,
380 CosNotifyFilter::Filter_ptr filter
383 ACE_UNUSED_ARG(push_consumer
);
384 ACE_UNUSED_ARG(filter
);
386 throw CORBA::NO_IMPLEMENT();
391 FT::FaultNotifier::ConsumerId
StubFaultNotifier::connect_sequence_fault_consumer (
392 CosNotifyComm::SequencePushConsumer_ptr push_consumer
,
393 CosNotifyFilter::Filter_ptr filter
396 ACE_UNUSED_ARG(push_consumer
);
397 ACE_UNUSED_ARG(filter
);
399 throw CORBA::NO_IMPLEMENT();
403 void StubFaultNotifier::disconnect_consumer (
404 FT::FaultNotifier::ConsumerId connection
407 ACE_UNUSED_ARG(connection
);
409 throw CORBA::NO_IMPLEMENT();
412 CORBA::Boolean
StubFaultNotifier::is_alive ()
417 int StubFaultNotifier::idle(int & result
)
419 ACE_UNUSED_ARG(result
);
423 if(!CORBA::is_nil(this->factory_
.in ()))
425 int ok
= this->factory_
->is_alive();
432 catch (const CORBA::Exception
&)