summaryrefslogtreecommitdiff
path: root/TAO/examples/Simple/chat/Client_i.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/examples/Simple/chat/Client_i.cpp')
-rw-r--r--TAO/examples/Simple/chat/Client_i.cpp118
1 files changed, 63 insertions, 55 deletions
diff --git a/TAO/examples/Simple/chat/Client_i.cpp b/TAO/examples/Simple/chat/Client_i.cpp
index 0702293f830..863a4dc66c4 100644
--- a/TAO/examples/Simple/chat/Client_i.cpp
+++ b/TAO/examples/Simple/chat/Client_i.cpp
@@ -26,26 +26,21 @@
#include "ace/OS_NS_unistd.h"
Client_i::Client_i ()
- : ior_file_name_ (ACE_TEXT("chat.ior")),
- nickname_ ("noname")
+ : ior_ ("")
+ , ior_file_name_ (ACE_TEXT ("chat.ior"))
+ , nickname_ ("noname")
{
-}
-
-Client_i::~Client_i (void)
-{
- // Make sure to cleanup the STDIN handler.
- if (ACE_Event_Handler::remove_stdin_handler
- (TAO_ORB_Core_instance ()->reactor (),
- TAO_ORB_Core_instance ()->thr_mgr ()) == -1)
- ACE_ERROR ((LM_ERROR,
- "%p\n",
- "remove_stdin_handler"));
+ Receiver_i *tmp = 0;
+ ACE_NEW_THROW_EX (tmp,
+ Receiver_i (),
+ CORBA::NO_MEMORY ());
+ this->receiver_i_ = tmp;
}
int
Client_i::parse_args (int argc, ACE_TCHAR *argv[])
{
- ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("n:f:"));
+ ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("n:f:"));
int c;
while ((c = get_opts ()) != -1)
@@ -62,17 +57,17 @@ Client_i::parse_args (int argc, ACE_TCHAR *argv[])
default: // display help for use of the serve
case '?': // display help for use of the server.
ACE_ERROR_RETURN ((LM_ERROR,
- "usage: %s"
- " [-n <your_nick_name>]"
- " [-f <ior_input_file>]"
- "\n",
+ ACE_TEXT ("usage: %s")
+ ACE_TEXT (" [-n <your_nick_name>]")
+ ACE_TEXT (" [-f <ior_input_file>]")
+ ACE_TEXT ("\n"),
argv [0]),
-1);
}
ACE_DEBUG ((LM_DEBUG,
- "\nusing nickname = %s, filename = %s\n",
- this->nickname_,
+ ACE_TEXT ("\nusing nickname = %C, filename = %s\n"),
+ this->nickname_.c_str (),
this->ior_file_name_));
return 0;
}
@@ -80,10 +75,6 @@ Client_i::parse_args (int argc, ACE_TCHAR *argv[])
int
Client_i::init (int argc, ACE_TCHAR *argv[])
{
- // Check if the command line arguments are ok.
- if (this->parse_args (argc, argv) == -1)
- return -1;
-
try
{
// Retrieve the ORB.
@@ -93,26 +84,36 @@ Client_i::init (int argc, ACE_TCHAR *argv[])
CORBA::ORB_var orb = this->orb_manager_.orb ();
+ // Check if the command line arguments are ok.
+ if (this->parse_args (argc, argv) == -1)
+ return -1;
+
// set the orb in the receiver_i_ object.
- this->receiver_i_.orb (orb.in ());
+ this->receiver_i_->orb (orb.in ());
// read the ior from file
if (this->read_ior (this->ior_file_name_) != 0)
ACE_ERROR_RETURN ((LM_ERROR,
- "could not read the ior from the file: <%s>\n",
+ ACE_TEXT ("could not read the ior from the file: <%s>\n"),
this->ior_file_name_),
-1);
CORBA::Object_var server_object =
- orb->string_to_object (this->ior_);
+ orb->string_to_object (this->ior_.c_str ());
if (CORBA::is_nil (server_object.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
- "invalid ior <%s>\n",
- this->ior_),
+ ACE_TEXT ("invalid ior <%C>\n"),
+ this->ior_.c_str ()),
-1);
this->server_ = Broadcaster::_narrow (server_object.in ());
+ if (CORBA::is_nil (this->server_.in ()))
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("Nil Server\n")),
+ -1);
+ }
}
catch (const CORBA::Exception& ex)
{
@@ -120,17 +121,6 @@ Client_i::init (int argc, ACE_TCHAR *argv[])
return -1;
}
- // Register our <Input_Handler> to handle STDIN events, which will
- // trigger the <handle_input> method to process these events.
-
- if (ACE_Event_Handler::register_stdin_handler
- (this,
- TAO_ORB_Core_instance ()->reactor (),
- TAO_ORB_Core_instance ()->thr_mgr ()) == -1)
- ACE_ERROR_RETURN ((LM_ERROR,
- "%p\n",
- "register_stdin_handler"),
- -1);
return 0;
}
@@ -138,8 +128,8 @@ int
Client_i::run (void)
{
ACE_DEBUG ((LM_DEBUG,
- "\n============= Simple Chat =================\n"
- "========== type 'quit' to exit ===========\n"));
+ ACE_TEXT ("\n============= Simple Chat =================\n")
+ ACE_TEXT ("========== type 'quit' to exit ===========\n")));
try
{
@@ -148,11 +138,22 @@ Client_i::run (void)
poa_manager->activate ();
this->receiver_var_ =
- this->receiver_i_._this ();
+ this->receiver_i_->_this ();
// Register ourselves with the server.
server_->add (this->receiver_var_.in (),
- this->nickname_);
+ this->nickname_.c_str ());
+
+ // Register our <Input_Handler> to handle STDIN events, which will
+ // trigger the <handle_input> method to process these events.
+ if (ACE_Event_Handler::register_stdin_handler
+ (this,
+ TAO_ORB_Core_instance ()->reactor (),
+ TAO_ORB_Core_instance ()->thr_mgr ()) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("%p\n"),
+ ACE_TEXT ("register_stdin_handler")),
+ -1);
// Run the ORB.
this->orb_manager_.run ();
@@ -182,10 +183,17 @@ Client_i::handle_input (ACE_HANDLE)
ACE_OS::strlen (QUIT_STRING)) == 0)
{
// Remove ourselves from the server.
- this->server_->remove (this->receiver_var_.in ());
- this->receiver_i_.shutdown ();
-
- return 0;
+ try
+ {
+ this->server_->remove (this->receiver_var_.in ());
+ }
+ catch (const CORBA::Exception &)
+ {
+ // we don't care about problems
+ }
+ this->receiver_i_->shutdown ();
+
+ return -1;
}
// Call the server function <say> to pass the string typed by
@@ -210,9 +218,9 @@ Client_i::read_ior (const ACE_TCHAR *filename)
if (f_handle == ACE_INVALID_HANDLE)
ACE_ERROR_RETURN ((LM_ERROR,
- "Unable to open %s for writing: %p\n",
+ ACE_TEXT ("Unable to open %s for writing (%p)\n"),
filename,
- "invalid handle"),
+ ACE_TEXT ("open")),
-1);
ACE_Read_Buffer ior_buffer (f_handle);
@@ -220,18 +228,18 @@ Client_i::read_ior (const ACE_TCHAR *filename)
if (data == 0)
ACE_ERROR_RETURN ((LM_ERROR,
- "Unable to read ior: %p\n"),
+ ACE_TEXT ("Unable to read ior (%p)\n"),
+ ACE_TEXT ("read")),
-1);
- this->ior_ = ACE_OS::strdup (data);
+ this->ior_ = data;
ior_buffer.alloc ()->free (data);
ACE_OS::close (f_handle);
- if (this->ior_ == 0)
+ if (this->ior_.length () == 0)
ACE_ERROR_RETURN ((LM_ERROR,
- "failed to read ior from file\n",
- ""),
+ ACE_TEXT ("failed to read ior from file\n")),
-1);
return 0;
}