Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / NotifyService / QoSProperties / MessengerConsumer.cpp
bloba7ef3d0a9568c267545988825670ce75bf3af12a
1 #include "orbsvcs/CosNotifyChannelAdminC.h"
2 #include "orbsvcs/CosNotifyCommC.h"
3 #include "orbsvcs/CosNamingC.h"
5 #include "StructuredEventConsumer_i.h"
6 #include <iostream>
8 int
9 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
11 try
13 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
15 CORBA::Object_var naming_obj =
16 orb->resolve_initial_references ("NameService");
18 CosNaming::NamingContext_var naming_context =
19 CosNaming::NamingContext::_narrow(naming_obj.in());
21 CosNaming::Name name;
22 name.length (1);
23 name[0].id = CORBA::string_dup("MyEventChannel");
24 CORBA::Object_var ecObj = naming_context->resolve(name);
26 CosNotifyChannelAdmin::EventChannel_var ec =
27 CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in());
29 CosNotifyChannelAdmin::AdminID adminid;
30 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
31 CosNotifyChannelAdmin::AND_OP;
33 CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin =
34 ec->new_for_consumers(ifgop, adminid);
36 CORBA::Object_var poa_object =
37 orb->resolve_initial_references("RootPOA");
39 PortableServer::POA_var poa =
40 PortableServer::POA::_narrow (poa_object.in());
42 PortableServer::Servant_var<StructuredEventConsumer_i> servant =
43 new StructuredEventConsumer_i(orb.in());
45 PortableServer::ObjectId_var objectId = poa->activate_object (servant.in());
47 CORBA::Object_var consumer_obj = poa->id_to_reference (objectId.in ());
49 CosNotifyComm::StructuredPushConsumer_var consumer =
50 CosNotifyComm::StructuredPushConsumer::_narrow (consumer_obj.in ());
52 CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id;
54 CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier =
55 consumer_admin->obtain_notification_push_supplier(
56 CosNotifyChannelAdmin::STRUCTURED_EVENT,
57 consumeradmin_proxy_id);
59 CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy;
60 supplier_proxy =
61 CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(proxy_supplier.in());
63 CosNotification::QoSProperties properties (1);
65 properties.length (1);
66 properties[0].name = CORBA::string_dup (CosNotification::OrderPolicy);
67 properties[0].value <<= CosNotification::FifoOrder;
69 supplier_proxy->set_qos (properties);
70 supplier_proxy->connect_structured_push_consumer(consumer.in());
72 CosNotification::EventTypeSeq added (1);
73 CosNotification::EventTypeSeq removed (1);
74 added.length (1);
75 removed.length (1);
77 added[0].domain_name = CORBA::string_dup ("OCI_TAO");
78 added[0].type_name = CORBA::string_dup ("examples");
80 removed[0].domain_name = CORBA::string_dup ("*");
81 removed[0].type_name = CORBA::string_dup ("*");
83 supplier_proxy->subscription_change(added, removed);
85 PortableServer::POAManager_var poa_manager = poa->the_POAManager();
87 poa_manager->activate();
89 orb->run();
91 catch(const CORBA::Exception& ex)
93 std::cerr << "Caught exception: " << ex << std::endl;
94 return 1;
97 return 0;