1 #include "Notify_Consumer.h"
2 #include "orbsvcs/CosEventChannelAdminS.h"
3 #include "orbsvcs/CosNotifyChannelAdminS.h"
4 #include "ace/OS_main.h"
6 #define NAMING_SERVICE_NAME "NameService"
7 #define NOTIFY_TLS_LOG_FACTORY_NAME "NotifyLogFactory"
8 #define LOG_EVENT_COUNT 29
9 #define QUERY_1 "id > 0"
10 #define QUERY_2 "id >= 0"
11 #define QUERY_LANG "TCL"
12 #define SA_FILTER "threshold > 10"
13 #define TCL_GRAMMAR "TCL"
14 #define EVENTS_TO_SEND 30
17 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
21 return consumer
.run (argc
, argv
);
24 // ****************************************************************
26 Consumer::Consumer (void)
32 Consumer::run (int argc
, ACE_TCHAR
* argv
[])
36 // ORB initialization boiler plate...
38 CORBA::ORB_init (argc
, argv
);
40 // Do *NOT* make a copy because we don't want the ORB to outlive
41 // the Consumer object.
42 this->orb_
= orb
.in ();
44 CORBA::Object_var object
=
45 orb
->resolve_initial_references ("RootPOA");
46 PortableServer::POA_var poa
=
47 PortableServer::POA::_narrow (object
.in ());
48 PortableServer::POAManager_var poa_manager
=
49 poa
->the_POAManager ();
50 poa_manager
->activate ();
52 // Obtain the event channel
53 CORBA::Object_var naming_obj
=
54 this->orb_
->resolve_initial_references (NAMING_SERVICE_NAME
);
56 // Need to check return value for errors.
57 if (CORBA::is_nil (naming_obj
.in ()))
58 throw CORBA::UNKNOWN ();
60 this->naming_context_
=
61 CosNaming::NamingContext::_narrow (naming_obj
.in ());
64 CosNaming::Name
name (1);
66 name
[0].id
= CORBA::string_dup (NOTIFY_TLS_LOG_FACTORY_NAME
);
68 CORBA::Object_var obj
=
69 this->naming_context_
->resolve (name
);
71 this->notify_log_factory_
=
72 DsNotifyLogAdmin::NotifyLogFactory::_narrow (obj
.in ());
74 CosNotifyComm::PushConsumer_var objref
=
77 ACE_ASSERT (!CORBA::is_nil (objref
.in ()));
79 CosNotifyChannelAdmin::ProxySupplier_var proxysupplier
=
80 this->notify_log_factory_
->obtain_notification_push_supplier (CosNotifyChannelAdmin::ANY_EVENT
, proxy_supplier_id_
);
82 ACE_ASSERT (!CORBA::is_nil (proxysupplier
.in ()));
85 this->proxy_supplier_
=
86 CosNotifyChannelAdmin::ProxyPushSupplier::
87 _narrow (proxysupplier
.in ());
89 ACE_ASSERT (!CORBA::is_nil (proxy_supplier_
.in ()));
91 proxy_supplier_
->connect_any_push_consumer (objref
.in ());
95 // We don't do any cleanup, it is hard to do it after shutdown,
96 // and would complicate the example; plus it is almost
97 // impossible to do cleanup after ORB->run() because the POA is
98 // in the holding state. Applications should use
99 // work_pending()/perform_work() to do more interesting stuff.
100 // Check the supplier for the proper way to do cleanup.
102 catch (const CORBA::Exception
& ex
)
104 ex
._tao_print_exception ("Consumer::run");
111 Consumer::push (const CORBA::Any
&event
)
113 ACE_UNUSED_ARG (event
);
115 this->event_count_
++;
117 ACE_DEBUG ((LM_DEBUG
,
118 "Consumer (%P|%t): %d log generated events received\n",
119 this->event_count_
));
123 Consumer::disconnect_push_consumer
126 this->proxy_supplier_
->
127 disconnect_push_supplier();
131 Consumer::offer_change
132 (const CosNotification::EventTypeSeq
& /*added*/,
133 const CosNotification::EventTypeSeq
& /*removed*/)