1 // Main program for a PushSupplier of Echo events.
3 #include "orbsvcs/CosEventCommC.h"
4 #include "orbsvcs/CosEventChannelAdminC.h"
5 #include "orbsvcs/CosNamingC.h"
6 #include "orbsvcs/CosEvent/CEC_EventChannel.h"
7 #include "orbsvcs/CosEvent/CEC_Default_Factory.h"
10 const int EVENT_DELAY_MS
= 10;
12 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
16 // Initialize the CEC Factory so we can customize the CEC
17 TAO_CEC_Default_Factory::init_svcs ();
19 // Initialize the ORB.
20 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
22 // Find the Naming Service.
23 CORBA::Object_var obj
= orb
->resolve_initial_references("NameService");
24 CosNaming::NamingContextExt_var root_context
= CosNaming::NamingContextExt::_narrow(obj
.in());
27 CORBA::Object_var poa_object
= orb
->resolve_initial_references("RootPOA");
28 if (CORBA::is_nil (poa_object
.in ()))
29 ACE_ERROR_RETURN ((LM_ERROR
,
30 " (%P|%t) Unable to initialize the POA.\n"),
32 PortableServer::POA_var root_poa
=
33 PortableServer::POA::_narrow (poa_object
.in ());
34 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
35 poa_manager
->activate ();
37 // Create and activate the event channel servant
38 CosEventChannelAdmin::EventChannel_var echoEC
;
40 TAO_CEC_EventChannel_Attributes
attr(root_poa
.in(), root_poa
.in());
41 TAO_CEC_EventChannel
* ec
= new TAO_CEC_EventChannel(attr
);
43 PortableServer::ObjectId_var oid
= root_poa
->activate_object(ec
);
44 CORBA::Object_var ec_obj
= root_poa
->id_to_reference(oid
.in());
45 echoEC
= CosEventChannelAdmin::EventChannel::_narrow(ec_obj
.in());
47 // Bind the EventChannel.
48 CosNaming::Name_var name
= root_context
->to_name("CosEventService");
49 root_context
->rebind(name
.in(), echoEC
.in());
51 // Get a SupplierAdmin object from the EventChannel.
52 CosEventChannelAdmin::SupplierAdmin_var supplierAdmin
=
53 echoEC
->for_suppliers();
55 // Get a ProxyPushConsumer from the SupplierAdmin.
56 CosEventChannelAdmin::ProxyPushConsumer_var consumer
=
57 supplierAdmin
->obtain_push_consumer();
59 // Connect to the ProxyPushConsumer as a PushSupplier
60 // (passing a nil PushSupplier object reference to it because
61 // we don't care to be notified about disconnects).
62 consumer
->connect_push_supplier(CosEventComm::PushSupplier::_nil());
64 // Create an event (just a string in this case).
65 const CORBA::String_var eventData
= CORBA::string_dup("Hello, world.");
68 // Insert the event data into an any.
72 // Now push the event to the consumer
75 ACE_Time_Value
tv(0, 1000 * EVENT_DELAY_MS
);
82 catch(const CORBA::Exception
& exc
)
84 std::cerr
<< "Caught unknown CORBA::Exception exception" << std::endl
<< exc
<< std::endl
;