1 #include "Event_Comm_i.h"
2 #include "Notifier_Handler.h"
3 #include "Supplier_Input_Handler.h"
4 #include "tao/ORB_Core.h"
6 Supplier_Input_Handler::Supplier_Input_Handler ()
12 Supplier_Input_Handler::~Supplier_Input_Handler (void)
15 "closing down Supplier_Input_Handler::~Supplier_Input_Handler\n"));
19 Supplier_Input_Handler::close (void)
22 "closing down Supplier::Supplier_Input_Handler\n"));
24 // Make sure to cleanup the STDIN handler.
25 if (ACE_Event_Handler::remove_stdin_handler
27 TAO_ORB_Core_instance ()->reactor (),
28 TAO_ORB_Core_instance ()->thr_mgr ()) == -1)
31 "remove_stdin_handler"));
36 Supplier_Input_Handler::initialize (Notifier_Handler
*notifier
)
39 // Register our <Input_Handler> to handle STDIN events, which will
40 // trigger the <handle_input> method to process these events.
42 if (ACE_Event_Handler::register_stdin_handler
44 TAO_ORB_Core_instance ()->reactor (),
45 TAO_ORB_Core_instance ()->thr_mgr ()) == -1)
46 ACE_ERROR_RETURN ((LM_ERROR
,
48 "register_stdin_handler"),
55 // Frame input events and notify <Consumers>.
58 Supplier_Input_Handler::handle_input (ACE_HANDLE
)
62 // Read up to BUFSIZ worth of data from ACE_HANDLE h.
64 if (ACE_OS::fgets (buf
,
69 "shutting down Supplier_Input_Handler\n"));
74 size_t n
= ACE_OS::strlen (buf
);
76 // Null terminate the buffer, replacing the '\n' with '\0'.
77 if (buf
[n
- 1] == '\n')
82 "notifying for event %s\n",
88 if (ACE_OS::strncmp (buf
, "quit", 4) == 0)
89 // Tell the main event loop to shutdown.
90 this->notifier_
->shutdown ();
93 Event_Comm::Notifier
*notifier
= this->notifier_
->notifier ();
94 ACE_ASSERT (notifier
!= 0);
96 // Use the notifier to notify Consumers.
99 Event_Comm::Event event
;
101 // Pass the buf over in the tag field.
102 event
.tag_
= ACE_OS::strdup (buf
);
104 // This is where the "any" value goes or the object
105 // reference... event.value_ = ...
107 // Forward <Event> to all <Consumers>.
108 notifier
->push (event
);
110 catch (const CORBA::Exception
& ex
)
112 ex
._tao_print_exception ("Unexpected Error\n");