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"
15 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
19 return supplier
.run (argc
, argv
);
22 // ****************************************************************
29 Supplier::run (int argc
, ACE_TCHAR
* argv
[])
33 // ORB initialization boiler plate...
35 CORBA::ORB_init (argc
, argv
);
42 "Usage: Supplier <event_channel_ior>\n"));
47 // Do *NOT* make a copy because we don't want the ORB to outlive
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
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);
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 ()));
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
,
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 ();
122 supplier_admin
->obtain_push_consumer ();
124 RtecEventComm::PushSupplier_var supplier
=
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);
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
);
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",
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 ());
214 catch (const CORBA::Exception
& ex
)
216 ex
._tao_print_exception ("Supplier::run");
223 Supplier::disconnect_push_supplier ()