Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / examples / Log / RTEvent / RTEvent_Supplier.cpp
blob8800ef9a19e479006ee0d24ef3b6d4747b1f4ef8
1 #include "RTEvent_Supplier.h"
2 #include "orbsvcs/RtecEventChannelAdminC.h"
3 #include "orbsvcs/Event_Service_Constants.h"
4 #include "ace/OS_main.h"
5 #include "ace/OS_NS_unistd.h"
7 #define NAMING_SERVICE_NAME "NameService"
8 #define EVENT_TLS_LOG_FACTORY_NAME "RTEventLogFactory"
9 #define LOG_EVENT_COUNT 29
10 #define QUERY_1 "id > 0"
11 #define QUERY_2 "id >= 0"
12 #define QUERY_LANG "TCL"
14 int
15 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
17 Supplier supplier;
19 return supplier.run (argc, argv);
22 // ****************************************************************
24 Supplier::Supplier ()
28 int
29 Supplier::run (int argc, ACE_TCHAR* argv[])
31 try
33 // ORB initialization boiler plate...
34 CORBA::ORB_var orb =
35 CORBA::ORB_init (argc, argv);
39 if (argc <= 1)
41 ACE_ERROR ((LM_ERROR,
42 "Usage: Supplier <event_channel_ior>\n"));
43 return 1;
47 // Do *NOT* make a copy because we don't want the ORB to outlive
48 // the run() method.
49 // this->orb_ = orb.in ();
51 CORBA::Object_var object =
52 orb->resolve_initial_references ("RootPOA");
53 PortableServer::POA_var poa =
54 PortableServer::POA::_narrow (object.in ());
55 PortableServer::POAManager_var poa_manager =
56 poa->the_POAManager ();
57 poa_manager->activate ();
59 // Obtain the event channel, we could use a naming service, a
60 // command line argument or resolve_initial_references(), but
61 // this is simpler...
62 /* object =
63 orb->string_to_object (argv[1]);
65 RtecEventChannelAdmin::EventChannel_var event_channel =
66 RtecEventChannelAdmin::EventChannel::_narrow (object.in ());
69 CORBA::Object_var naming_obj =
70 orb->resolve_initial_references (NAMING_SERVICE_NAME);
72 // Need to check return value for errors.
73 if (CORBA::is_nil (naming_obj.in ()))
74 throw CORBA::UNKNOWN ();
76 this->naming_context_ =
77 CosNaming::NamingContext::_narrow (naming_obj.in ());
80 CosNaming::Name name (1);
81 name.length (1);
82 name[0].id = CORBA::string_dup (EVENT_TLS_LOG_FACTORY_NAME);
84 CORBA::Object_var obj =
85 this->naming_context_->resolve (name);
87 this->event_log_factory_ =
88 RTEventLogAdmin::EventLogFactory::_narrow (obj.in ());
90 ACE_ASSERT (!CORBA::is_nil (this->event_log_factory_.in ()));
95 // create a log..
97 ACE_DEBUG ((LM_DEBUG,
98 "\nCalling EventLogFactory::create...\n"));
100 DsLogAdmin::LogFullActionType logfullaction = DsLogAdmin::halt;
101 DsLogAdmin::CapacityAlarmThresholdList threshold = 0;
102 CORBA::ULongLong max_size = 0; // 0 means "infinite"
104 DsLogAdmin::LogId logid = 0;
106 RTEventLogAdmin::EventLog_var event_log =
107 // DsLogAdmin::Log_var event_log =
108 this->event_log_factory_->create (logfullaction,
109 max_size,
110 threshold,
111 logid);
114 ACE_DEBUG ((LM_DEBUG,
115 "Create returned logid = %d\n",logid));
117 // The canonical protocol to connect to the EC
118 RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
119 event_log->for_suppliers ();
121 this->consumer_ =
122 supplier_admin->obtain_push_consumer ();
124 RtecEventComm::PushSupplier_var supplier =
125 this->_this ();
128 // Simple publication, but usually the helper classes in
129 // $TAO_ROOT/orbsvcs/Event_Utils.h are a better way to do this.
130 RtecEventChannelAdmin::SupplierQOS qos;
131 qos.publications.length (1);
132 RtecEventComm::EventHeader& h0 =
133 qos.publications[0].event.header;
134 h0.type = ACE_ES_EVENT_UNDEFINED; // first free event type
135 h0.source = 1; // first free event source
137 this->consumer_->connect_push_supplier (supplier.in (), qos);
140 // Create some fake log events.
141 // Push the events...
142 ACE_Time_Value sleep_time (0, 10000); // 10 milliseconds
144 RtecEventComm::EventSet event (1);
145 event.length (1);
146 event[0].header.type = ACE_ES_EVENT_UNDEFINED;
147 event[0].header.source = 1;
148 event[0].header.ttl = 1;
150 for (int i = 0; i != LOG_EVENT_COUNT; ++i)
152 this->consumer_->push (event);
153 ACE_OS::sleep (sleep_time);
156 ACE_DEBUG ((LM_DEBUG,
157 "Writing %d records...\n", LOG_EVENT_COUNT));
159 ACE_DEBUG ((LM_DEBUG,
160 "Calling EventLog::get_n_records...\n"));
161 CORBA::ULongLong retval = event_log->get_n_records ();
163 ACE_DEBUG ((LM_DEBUG, "Number of records in Log = %d\n", retval));
165 ACE_DEBUG ((LM_DEBUG,
166 "Calling EventLog::get_current_size...\n"));
167 retval = event_log->get_current_size ();
169 ACE_DEBUG ((LM_DEBUG, "Size of data in Log = %d\n", retval));
171 ACE_DEBUG ((LM_DEBUG, "Querying the Log: %s\n", QUERY_1));
172 DsLogAdmin::Iterator_var iter_out;
173 DsLogAdmin::RecordList_var rec_list =
174 event_log->query (QUERY_LANG, QUERY_1, iter_out);
176 CORBA::ULong j = 0;
177 for (; j < rec_list->length();++j)
178 ACE_DEBUG ((LM_DEBUG,
179 "id = %Q, time= %Q\n",
180 rec_list[j].id, rec_list[j].time));
182 ACE_DEBUG ((LM_DEBUG,
183 "Deleting records...\n"));
185 retval = event_log->delete_records (QUERY_LANG, QUERY_2);
187 ACE_DEBUG ((LM_DEBUG,
188 "Calling EventLog::get_n_records...\n"));
189 retval = event_log->get_n_records ();
191 ACE_DEBUG ((LM_DEBUG, "Number of records in Log after delete = %d\n",
192 retval));
194 ACE_DEBUG ((LM_DEBUG, "Geting the current_size again...\n"));
195 retval = event_log->get_current_size ();
197 ACE_DEBUG ((LM_DEBUG, "Size of data in Log = %d\n", retval));
199 // Disconnect from the EC
200 this->consumer_->disconnect_push_consumer ();
202 // Destroy the EC....
203 //event_channel->destroy ();
204 event_log->destroy ();
206 // Deactivate this object...
207 PortableServer::ObjectId_var id =
208 poa->servant_to_id (this);
209 poa->deactivate_object (id.in ());
211 // Destroy the POA
212 poa->destroy (1, 0);
214 catch (const CORBA::Exception& ex)
216 ex._tao_print_exception ("Supplier::run");
217 return 1;
219 return 0;
222 void
223 Supplier::disconnect_push_supplier ()