Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / Event_Comm / Notifier_Server.cpp
blobece19d92bfa7e3e579f876fcf43908b9ee0222bf
1 #include "Notifier_Server.h"
2 #include "Event_CommC.h"
3 #include "tao/debug.h"
4 #include "tao/ORB_Core.h"
6 // Constructor.
7 Notifier_Server::Notifier_Server (void)
11 // Destructor.
13 Notifier_Server::~Notifier_Server (void)
17 int
18 Notifier_Server::close (void)
20 try
22 // disconnect all the consumers.
23 this->servant_.disconnect ("notifier shutdown.");
25 // Name the object.
26 CosNaming::Name notifier_obj_name (1);
27 notifier_obj_name.length (1);
28 notifier_obj_name[0].id =
29 CORBA::string_dup (NOTIFIER_BIND_NAME);
31 this->naming_server_->unbind (notifier_obj_name);
33 // Instruct the ORB to shutdown.
34 this->orb_manager_.orb ()->shutdown ();
36 catch (const CORBA::Exception&)
38 return -1;
41 return 0;
44 // The naming service is initialized and the naming context as well as
45 // the object name is bound to the naming server.
47 int
48 Notifier_Server::init_naming_service (void)
50 try
52 CORBA::ORB_var orb = this->orb_manager_.orb ();
54 TAO_debug_level = 1;
56 if (this->naming_server_.init (orb.in ()) == -1)
57 ACE_ERROR_RETURN ((LM_ERROR,
58 "Failed to initialize TAO_Naming_Server\n"),
59 -1);
61 // Register the object implementation with the POA.
62 Event_Comm::Notifier_var notifier_obj =
63 this->servant_._this ();
65 // Name the object.
66 CosNaming::Name notifier_obj_name (1);
67 notifier_obj_name.length (1);
68 notifier_obj_name[0].id =
69 CORBA::string_dup (NOTIFIER_BIND_NAME);
71 // Now, attach the object name to the context.
72 this->naming_server_->bind (notifier_obj_name,
73 notifier_obj.in ());
75 catch (const CORBA::Exception& ex)
77 ex._tao_print_exception ("Notifier_Server::init_naming_service\n");
78 return -1;
81 return 0;
85 // Initialize the server.
86 int
87 Notifier_Server::init (int argc,
88 ACE_TCHAR *argv[])
90 // Call the init of <TAO_ORB_Manager> to initialize the ORB and
91 // create the child poa under the root POA.
93 if (this->orb_manager_.init_child_poa (argc,
94 argv,
95 "child_poa") == -1)
97 ACE_ERROR_RETURN ((LM_ERROR,
98 "%p\n",
99 "init_child_poa"),
100 -1);
102 this->orb_manager_.activate_poa_manager ();
104 // Activate the servant in the POA.
105 CORBA::String_var str =
106 this->orb_manager_.activate_under_child_poa (NOTIFIER_BIND_NAME,
107 &this->servant_);
109 return this->init_naming_service ();
113 Notifier_Server::run (void)
115 ACE_DEBUG ((LM_DEBUG,
116 "Running the notifier server...\n"));
118 // Run the main event loop for the ORB.
119 this->orb_manager_.run ();
121 return 0;
124 ACE_Reactor *
125 Notifier_Server::reactor (void)
127 return TAO_ORB_Core_instance ()->reactor ();