2 #include "StubFaultConsumer.h"
3 #include "ace/Get_Opt.h"
4 #include "orbsvcs/PortableGroup/PG_Properties_Encoder.h"
6 StubFaultConsumer::StubFaultConsumer ()
13 StubFaultConsumer::~StubFaultConsumer ()
17 ::PortableServer::POA_ptr
StubFaultConsumer::_default_POA ()
19 return ::PortableServer::POA::_duplicate(this->poa_
.in ());
22 PortableServer::ObjectId
StubFaultConsumer::objectId()const
24 return this->object_id_
.in();
27 size_t StubFaultConsumer::notifications () const
29 return this->notifications_
;
33 int StubFaultConsumer::parse_args (int argc
, ACE_TCHAR
* argv
[])
36 #ifndef NO_ARGS_FOR_NOW
37 ACE_UNUSED_ARG (argc
);
38 ACE_UNUSED_ARG (argv
);
39 #else // NO_ARGS_FOR_NOW
40 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT(""));
42 while ((c
= get_opts ()) != -1)
48 if (this->replicaIorBuffer_
== 0)
50 const char * repNames
= get_opts
.opt_arg ();
51 size_t repNameLen
= ACE_OS::strlen(repNames
);
53 // make a working copy of the string
54 ACE_NEW_NORETURN(this->replicaIorBuffer_
,
55 char[repNameLen
+ 1]);
56 if ( this->replicaIorBuffer_
!= 0)
58 ACE_OS::memcpy(this->replicaIorBuffer_
, repNames
, repNameLen
+1);
60 // tokenize the string on ','
61 // into iorReplicaFiles_
62 char * pos
= this->replicaIorBuffer_
;
65 this->iorReplicaFiles_
.push_back(pos
);
66 // find a comma delimiter, and
67 // chop the string there.
68 pos
= ACE_OS::strchr (pos
, ',');
79 "Command line option error: -r can't allocate buffer.\n"
87 "Command line option error: -r specified more than once.\n"
95 this->iorDetectorFile_
= get_opts
.opt_arg ();
100 this->nsName_
= get_opts
.opt_arg ();
105 this->iorOutputFile_
= get_opts
.opt_arg ();
120 if (0 == this->replicaIorBuffer_
)
122 ACE_ERROR ((LM_ERROR
,
123 "-r option is required.\n"
127 if (0 == this->iorDetectorFile_
)
129 ACE_ERROR ((LM_ERROR
,
130 "-d option is required.\n"
138 ACE_ERROR ((LM_ERROR
,
140 " -r <replica.ior[,replica.ior]>"
143 " -n <nameService name>"
148 #endif /* NO_ARGS_FOR_NOW */
153 * Register this object.
155 int StubFaultConsumer::init (CORBA::ORB_ptr orb
,
156 ::FT::FaultNotifier_var
& notifier
)
159 this->orb_
= CORBA::ORB::_duplicate (orb
);
160 this->notifier_
= notifier
;
161 this->identity_
= "StubFaultConsumer";
164 // Use the ROOT POA for now
165 CORBA::Object_var poa_object
=
166 this->orb_
->resolve_initial_references (TAO_OBJID_ROOTPOA
);
168 if (CORBA::is_nil (poa_object
.in ()))
169 ACE_ERROR_RETURN ((LM_ERROR
,
170 ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
173 // Get the POA object.
175 PortableServer::POA::_narrow (poa_object
.in ());
177 if (CORBA::is_nil(this->poa_
.in ()))
179 ACE_ERROR_RETURN ((LM_ERROR
,
180 ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")),
184 PortableServer::POAManager_var poa_manager
=
185 this->poa_
->the_POAManager ();
187 poa_manager
->activate ();
189 // Register with the POA.
191 this->object_id_
= this->poa_
->activate_object (this);
193 // find my identity as an object
195 CORBA::Object_var this_obj
=
196 this->poa_
->id_to_reference (object_id_
.in ());
198 CosNotifyFilter::Filter_var filter
= CosNotifyFilter::Filter::_nil();
200 this->consumer_id_
= notifier
->connect_structured_fault_consumer(
201 CosNotifyComm::StructuredPushConsumer::_narrow(this_obj
.in ()),
208 * Return a string to identify this object for logging/console message purposes.
210 const char * StubFaultConsumer::identity () const
212 return this->identity_
.c_str();
216 * Clean house for process shut down.
218 int StubFaultConsumer::fini ()
220 this->notifier_
->disconnect_consumer(this->consumer_id_
);
225 int StubFaultConsumer::idle(int & result
)
227 ACE_UNUSED_ARG(result
);
233 void StubFaultConsumer::push_structured_event(
234 const CosNotification::StructuredEvent
¬ification
237 ////////////////////////////////////////
238 // keep track of how many we've received
239 this->notifications_
+= 1;
240 ACE_ERROR ((LM_ERROR
,
241 "FaultConsumer: Received Fault notification(%d):\n"
242 "FaultConsumer: Header EventType domain: %s\n"
243 "FaultConsumer: Header EventType type: %s\n"
244 "FaultConsumer: Header EventName: %s\n",
245 static_cast<unsigned int> (this->notifications_
),
246 static_cast<const char *> (notification
.header
.fixed_header
.event_type
.domain_name
),
247 static_cast<const char *> (notification
.header
.fixed_header
.event_type
.type_name
),
248 static_cast<const char *> (notification
.header
.fixed_header
.event_name
)
250 const CosNotification::FilterableEventBody
& filterable
= notification
.filterable_data
;
252 size_t propertyCount
= filterable
.length ();
253 for (size_t nProp
= 0; nProp
< propertyCount
; ++nProp
)
255 const CosNotification::Property
& property
= filterable
[nProp
];
257 const char * property_name
= static_cast<const char *> (property
.name
);
258 const char * value
= "<unknown>";
259 if (property
.value
>>= value
)
263 ACE_ERROR ((LM_ERROR
,
264 "FaultConsumer: Property Name: %s=%s\n",
270 // int todo_finish_decode;
275 void StubFaultConsumer::offer_change (
276 const CosNotification::EventTypeSeq
& added
,
277 const CosNotification::EventTypeSeq
& removed
280 ACE_UNUSED_ARG (added
);
281 ACE_UNUSED_ARG (removed
);
282 ACE_ERROR ((LM_ERROR
,
283 "StubFaultConsumer: offer_change call ignored.\n"
287 void StubFaultConsumer::disconnect_structured_push_consumer()
289 ACE_ERROR ((LM_ERROR
,
290 "StubFaultConsumer:disconnect_structured_push_consumer interpreted as quit request.\n"