1 #include "Event_Consumer.h"
2 #include "orbsvcs/CosEventChannelAdminS.h"
3 #include "ace/OS_main.h"
5 #define NAMING_SERVICE_NAME "NameService"
6 #define EVENT_TLS_LOG_FACTORY_NAME "EventLogFactory"
9 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
13 return consumer
.run (argc
, argv
);
16 // ****************************************************************
24 Consumer::run (int argc
, ACE_TCHAR
* argv
[])
28 // ORB initialization boiler plate...
30 CORBA::ORB_init (argc
, argv
);
32 // Do *NOT* make a copy because we don't want the ORB to outlive
33 // the Consumer object.
34 this->orb_
= orb
.in ();
36 CORBA::Object_var object
=
37 orb
->resolve_initial_references ("RootPOA");
38 PortableServer::POA_var poa
=
39 PortableServer::POA::_narrow (object
.in ());
40 PortableServer::POAManager_var poa_manager
=
41 poa
->the_POAManager ();
42 poa_manager
->activate ();
44 // Obtain the event channel
45 CORBA::Object_var naming_obj
=
46 this->orb_
->resolve_initial_references (NAMING_SERVICE_NAME
);
48 // Need to check return value for errors.
49 if (CORBA::is_nil (naming_obj
.in ()))
50 throw CORBA::UNKNOWN ();
52 this->naming_context_
=
53 CosNaming::NamingContext::_narrow (naming_obj
.in ());
55 CosNaming::Name
name (1);
57 name
[0].id
= CORBA::string_dup (EVENT_TLS_LOG_FACTORY_NAME
);
59 CORBA::Object_var obj
=
60 this->naming_context_
->resolve (name
);
62 this->event_log_factory_
=
63 DsEventLogAdmin::EventLogFactory::_narrow (obj
.in ());
66 this->event_log_factory_
->obtain_push_supplier ();
68 CosEventComm::PushConsumer_var consumer
=
71 this->supplier_
->connect_push_consumer (consumer
.in ());
75 // We don't do any cleanup, it is hard to do it after shutdown,
76 // and would complicate the example; plus it is almost
77 // impossible to do cleanup after ORB->run() because the POA is
78 // in the holding state. Applications should use
79 // work_pending()/perform_work() to do more interesting stuff.
80 // Check the supplier for the proper way to do cleanup.
82 catch (const CORBA::Exception
& ex
)
84 ex
._tao_print_exception ("Consumer::run");
91 Consumer::push (const CORBA::Any
&)
93 this->event_count_
++;
96 "Consumer (%P|%t): %d log generated events received\n",
101 Consumer::disconnect_push_consumer ()
103 // In this example we shutdown the ORB when we disconnect from the
104 // EC (or rather the EC disconnects from us), but this doesn't have
105 // to be the case....
106 this->orb_
->shutdown (false);