Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / EventServices / OMG_Basic / EchoEventSupplierMain.cpp
blob2ac224abd8007e421ce02f4e87cef05a7551b84d
1 // Main program for a PushSupplier of Echo events.
3 #include "orbsvcs/CosEventCommC.h"
4 #include "orbsvcs/CosEventChannelAdminC.h"
5 #include "orbsvcs/CosNamingC.h"
7 #include <iostream>
9 const int EVENT_DELAY_MS = 10;
11 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
13 try
15 // Initialize the ORB.
16 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
18 // Find the Naming Service.
19 CORBA::Object_var obj = orb->resolve_initial_references("NameService");
20 CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in());
22 // Find the EventChannel.
23 obj = root_context->resolve_str("CosEventService");
25 // Downcast the object reference to an EventChannel reference.
26 CosEventChannelAdmin::EventChannel_var echoEC =
27 CosEventChannelAdmin::EventChannel::_narrow(obj.in());
28 if (CORBA::is_nil(echoEC.in())) {
29 std::cerr << "Could not resolve EchoEventChannel." << std::endl;
30 return 1;
33 // Get a SupplierAdmin object from the EventChannel.
34 CosEventChannelAdmin::SupplierAdmin_var supplierAdmin =
35 echoEC->for_suppliers();
37 // Get a ProxyPushConsumer from the SupplierAdmin.
38 CosEventChannelAdmin::ProxyPushConsumer_var consumer =
39 supplierAdmin->obtain_push_consumer();
41 // Connect to the ProxyPushConsumer as a PushSupplier
42 // (passing a nil PushSupplier object reference to it because
43 // we don't care to be notified about disconnects).
44 consumer->connect_push_supplier(CosEventComm::PushSupplier::_nil());
46 // Create an event (just a string in this case).
47 const CORBA::String_var eventData = CORBA::string_dup("Hello, world.");
49 // Send one event per second. (approx)
50 while (1) {
51 // Insert the event data into an any.
52 CORBA::Any any;
53 any <<= eventData;
55 // Now push the event to the consumer
56 consumer->push(any);
58 ACE_Time_Value event_delay(0, 1000 * EVENT_DELAY_MS);
59 orb->run(event_delay);
62 return 0;
64 catch(const CORBA::Exception& ex)
66 std::cerr << "Supplier Caught CORBA::Exception. " << ex << std::endl;
69 return 1;