Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / Event_Comm / Notifier_Handler.cpp
blob8fcf3d4b7e8fdaf2685887bc9791c0743650148d
1 #include "Notifier_Handler.h"
2 #include "tao/ORB_Core.h"
4 Notifier_Handler::Notifier_Handler (void)
6 // No-Op.
9 // Destroy a Notifier target object.
11 Notifier_Handler::~Notifier_Handler (void)
13 // No-Op.
16 int
17 Notifier_Handler::close (void)
19 if (this->notifier_ != 0)
21 ACE_DEBUG ((LM_DEBUG,
22 "closing down Notifier_Handler\n"));
23 CORBA::release (this->notifier_);
24 this->notifier_ = 0;
27 // shutdown the ORB.
28 this->orb_->shutdown ();
29 return 0;
32 void
33 Notifier_Handler::shutdown (void)
35 ACE_ASSERT (this->shutdowncallback != 0);
37 this->shutdowncallback->close ();
40 int
41 Notifier_Handler::run (void)
43 ACE_DEBUG ((LM_DEBUG,
44 "Running the Supplier...\n"));
45 // Run the ORB.
46 this->orb_->run ();
47 return 0;
50 ACE_Reactor*
51 Notifier_Handler::reactor(void)
53 // @@ Please see if there's a way to get to the Reactor without
54 // using the TAO_ORB_Core_instance().
55 return TAO_ORB_Core_instance ()->reactor ();
58 Event_Comm::Notifier *
59 Notifier_Handler::notifier (void)
61 return this->notifier_;
64 void
65 Notifier_Handler::notifier (Event_Comm::Notifier *notifier)
67 if (this->notifier_ != notifier)
69 CORBA::release (this->notifier_);
70 this->notifier_ = notifier;
74 // Init function.
76 int
77 Notifier_Handler::init (int argc,
78 ACE_TCHAR *argv[],
79 ShutdownCallback* _shutdowncallback)
81 // set the callback
82 shutdowncallback = _shutdowncallback;
84 try
86 // Retrieve the ORB.
87 this->orb_ = CORBA::ORB_init (argc, argv);
89 CORBA::Object_var poa_object =
90 this->orb_->resolve_initial_references ("RootPOA");
92 PortableServer::POA_var poa =
93 PortableServer::POA::_narrow (poa_object.in ());
95 PortableServer::POAManager_var poa_manager =
96 poa->the_POAManager ();
98 poa_manager->activate ();
100 // Initialization of the naming service.
101 if (this->naming_client_.init (orb_.in ()) != 0)
102 ACE_ERROR_RETURN ((LM_ERROR,
103 "(%P|%t) Unable to initialize "
104 "the TAO_Naming_Client.\n"),
105 -1);
107 CosNaming::Name notifier_ref_name (1);
108 notifier_ref_name.length (1);
109 notifier_ref_name[0].id =
110 CORBA::string_dup (NOTIFIER_BIND_NAME);
112 CORBA::Object_var notifier_obj =
113 this->naming_client_->resolve (notifier_ref_name);
116 // The CORBA::Object_var object is downcast to Notifier_var
117 // using the <_narrow> method.
118 this->notifier_ =
119 Event_Comm::Notifier::_narrow (notifier_obj.in ());
121 catch (const CORBA::Exception& ex)
123 ex._tao_print_exception ("Notifier_Handler::init\n");
124 return -1;
127 return 0;