Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / examples / Log / Event / Event_Supplier.cpp
blob7b09a500702b4f87f7bca8b571ffe01ad9614132
1 #include "Event_Supplier.h"
2 #include "orbsvcs/CosEventChannelAdminS.h"
3 #include "ace/OS_main.h"
5 #define NAMING_SERVICE_NAME "NameService"
6 #define EVENT_TLS_LOG_FACTORY_NAME "EventLogFactory"
7 #define LOG_EVENT_COUNT 9
8 #define QUERY_1 "id > 0"
9 #define QUERY_2 "id >= 0"
10 #define QUERY_LANG "TCL"
12 int
13 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
15 Supplier supplier;
17 return supplier.run (argc, argv);
20 // ****************************************************************
22 Supplier::Supplier ()
26 int
27 Supplier::run (int argc, ACE_TCHAR* argv[])
29 try
31 // ORB initialization boiler plate...
32 this->orb_ =
33 CORBA::ORB_init (argc, argv);
35 CORBA::Object_var object =
36 this->orb_->resolve_initial_references ("RootPOA");
37 PortableServer::POA_var poa =
38 PortableServer::POA::_narrow (object.in ());
39 PortableServer::POAManager_var poa_manager =
40 poa->the_POAManager ();
41 poa_manager->activate ();
44 CORBA::Object_var naming_obj =
45 this->orb_->resolve_initial_references (NAMING_SERVICE_NAME);
47 // Need to check return value for errors.
48 if (CORBA::is_nil (naming_obj.in ()))
49 throw CORBA::UNKNOWN ();
51 this->naming_context_ =
52 CosNaming::NamingContext::_narrow (naming_obj.in ());
55 CosNaming::Name name (1);
56 name.length (1);
57 name[0].id = CORBA::string_dup (EVENT_TLS_LOG_FACTORY_NAME);
59 CORBA::Object_var obj =
60 this->naming_context_->resolve (name);
62 this->event_log_factory_ =
63 DsEventLogAdmin::EventLogFactory::_narrow (obj.in ());
65 ACE_ASSERT (!CORBA::is_nil (this->event_log_factory_.in ()));
68 // create a log..
70 ACE_DEBUG ((LM_DEBUG,
71 "\nCalling EventLogFactory::create...\n"));
73 DsLogAdmin::LogFullActionType logfullaction = DsLogAdmin::halt;
74 DsLogAdmin::CapacityAlarmThresholdList threshold = 0;
75 CORBA::ULongLong max_size = 0; // 0 means "infinite"
77 DsLogAdmin::LogId logid = 0;
79 DsEventLogAdmin::EventLog_var event_log =
80 // DsLogAdmin::Log_var event_log =
81 this->event_log_factory_->create (logfullaction,
82 max_size,
83 threshold,
84 logid);
87 ACE_DEBUG ((LM_DEBUG,
88 "Create returned logid = %d\n",logid));
90 CosEventChannelAdmin::SupplierAdmin_var supplier_admin =
91 event_log->for_suppliers ();
93 this->consumer_ =
94 supplier_admin->obtain_push_consumer ();
96 CosEventComm::PushSupplier_var supplier =
97 this->_this ();
99 this->consumer_->connect_push_supplier (supplier.in ());
101 // Create some fake log events.
102 CORBA::Any event;
103 event <<= CORBA::ULong (10);
105 for (int d = 0; d < LOG_EVENT_COUNT; d++)
107 this->consumer_->push (event);
110 ACE_DEBUG ((LM_DEBUG,
111 "Writing %d records...\n", LOG_EVENT_COUNT));
113 ACE_DEBUG ((LM_DEBUG,
114 "Calling EventLog::get_n_records...\n"));
115 CORBA::ULongLong retval = event_log->get_n_records ();
117 ACE_DEBUG ((LM_DEBUG, "Number of records in Log = %d\n", retval));
119 ACE_DEBUG ((LM_DEBUG,
120 "Calling EventLog::get_current_size...\n"));
121 retval = event_log->get_current_size ();
123 ACE_DEBUG ((LM_DEBUG, "Size of data in Log = %d\n", retval));
125 ACE_DEBUG ((LM_DEBUG, "Querying the Log: %s\n", QUERY_1));
126 DsLogAdmin::Iterator_var iter_out;
127 DsLogAdmin::RecordList_var rec_list =
128 event_log->query (QUERY_LANG, QUERY_1, iter_out);
130 CORBA::ULong j = 0;
131 for (; j < rec_list->length();++j)
132 ACE_DEBUG ((LM_DEBUG,
133 "id = %Q, time= %Q\n",
134 rec_list[j].id, rec_list[j].time));
136 ACE_DEBUG ((LM_DEBUG,
137 "Deleting records...\n"));
139 retval = event_log->delete_records (QUERY_LANG, QUERY_2);
141 ACE_DEBUG ((LM_DEBUG,
142 "Calling EventLog::get_n_records...\n"));
143 retval = event_log->get_n_records ();
145 ACE_DEBUG ((LM_DEBUG, "Number of records in Log after delete = %d\n",
146 retval));
148 ACE_DEBUG ((LM_DEBUG, "Geting the current_size again...\n"));
149 retval = event_log->get_current_size ();
151 ACE_DEBUG ((LM_DEBUG, "Size of data in Log = %d\n", retval));
153 // Disconnect from the EC
154 this->consumer_->disconnect_push_consumer ();
156 // Destroy the EC....
157 //event_channel->destroy ();
158 event_log->destroy ();
160 // Deactivate this object...
161 PortableServer::ObjectId_var id =
162 poa->servant_to_id (this);
164 poa->deactivate_object (id.in ());
166 // Destroy the POA
167 poa->destroy (1, 0);
169 catch (const CORBA::Exception& ex)
171 ex._tao_print_exception ("Supplier::run");
172 return 1;
174 return 0;
177 void
178 Supplier::disconnect_push_supplier ()