Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / FT_App / StubFaultConsumer.cpp
blob6410929038d5f0f081640137cd78c4428216dc39
1 // -*- C++ -*-
2 #include "StubFaultConsumer.h"
3 #include "ace/Get_Opt.h"
4 #include "orbsvcs/PortableGroup/PG_Properties_Encoder.h"
6 StubFaultConsumer::StubFaultConsumer ()
7 : quit_(0)
8 , notifications_(0)
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[])
35 int optionError = 0;
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(""));
41 int c;
42 while ((c = get_opts ()) != -1)
44 switch (c)
46 case 'r':
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_;
63 while (pos != 0)
65 this->iorReplicaFiles_.push_back(pos);
66 // find a comma delimiter, and
67 // chop the string there.
68 pos = ACE_OS::strchr (pos, ',');
69 if (pos != 0)
71 *pos = '\0';
72 pos += 1;
76 else
78 ACE_ERROR ((LM_ERROR,
79 "Command line option error: -r can't allocate buffer.\n"
80 ));
81 optionError = -1;
84 else
86 ACE_ERROR ((LM_ERROR,
87 "Command line option error: -r specified more than once.\n"
88 ));
89 optionError = -1;
91 break;
93 case 'd':
95 this->iorDetectorFile_ = get_opts.opt_arg ();
96 break;
98 case 'n':
100 this->nsName_ = get_opts.opt_arg ();
101 break;
103 case 'o':
105 this->iorOutputFile_ = get_opts.opt_arg ();
106 break;
109 default:
110 // fall thru
111 case '?':
113 break;
118 if(! optionError)
120 if (0 == this->replicaIorBuffer_)
122 ACE_ERROR ((LM_ERROR,
123 "-r option is required.\n"
125 optionError = -1;
127 if (0 == this->iorDetectorFile_)
129 ACE_ERROR ((LM_ERROR,
130 "-d option is required.\n"
132 optionError = -1;
136 if(optionError)
138 ACE_ERROR ((LM_ERROR,
139 "usage: %s"
140 " -r <replica.ior[,replica.ior]>"
141 " -d <detector.ior>"
142 " -o <this.ior>"
143 " -n <nameService name>"
144 "\n",
145 argv [0]
148 #endif /* NO_ARGS_FOR_NOW */
149 return optionError;
153 * Register this object.
155 int StubFaultConsumer::init (CORBA::ORB_ptr orb,
156 ::FT::FaultNotifier_var & notifier)
158 int result = 0;
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")),
171 -1);
173 // Get the POA object.
174 this->poa_ =
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")),
181 -1);
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 ()),
202 filter.in ());
204 return result;
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_);
221 return 0;
225 int StubFaultConsumer::idle(int & result)
227 ACE_UNUSED_ARG(result);
228 return this->quit_;
231 ////////////////
232 // CORBA methods
233 void StubFaultConsumer::push_structured_event(
234 const CosNotification::StructuredEvent &notification
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 )
261 // ok!
263 ACE_ERROR ((LM_ERROR,
264 "FaultConsumer: Property Name: %s=%s\n",
265 property_name,
266 value
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"
292 this->quit_ = 1;