diff options
author | bala <balanatarajan@users.noreply.github.com> | 1999-03-31 06:28:58 +0000 |
---|---|---|
committer | bala <balanatarajan@users.noreply.github.com> | 1999-03-31 06:28:58 +0000 |
commit | 3d39ed8a9c474c47d36578f9759272335094e14b (patch) | |
tree | 3ba8a991ab929ab6b259c35a0bf31722a92fbe5b /TAO/examples/POA/Default_Servant/client.cpp | |
parent | 4860a1d01712496c41986a78372e0181e4a41339 (diff) | |
download | ATCD-3d39ed8a9c474c47d36578f9759272335094e14b.tar.gz |
Made some cosmetic changes..
Diffstat (limited to 'TAO/examples/POA/Default_Servant/client.cpp')
-rw-r--r-- | TAO/examples/POA/Default_Servant/client.cpp | 166 |
1 files changed, 74 insertions, 92 deletions
diff --git a/TAO/examples/POA/Default_Servant/client.cpp b/TAO/examples/POA/Default_Servant/client.cpp index 9131e4e6dd4..8d09ec6d5ae 100644 --- a/TAO/examples/POA/Default_Servant/client.cpp +++ b/TAO/examples/POA/Default_Servant/client.cpp @@ -71,105 +71,87 @@ parse_args (int argc, char **argv) int main (int argc, char **argv) { - CORBA::Environment env; - char* ior=0; - // Initialize the ORB - CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, 0, env); - if (env.exception () != 0) - { - env.print_exception ("CORBA::ORB_init"); - return -1; - } - - // Parse the command-line arguments to get the IOR - parse_args (argc, argv); - - // parse args should catch this, but just in case... - if (iorfile == 0) - return 0; - - // Read the file, and get the IOR - ACE_HANDLE input_file = ACE_OS::open (iorfile, 0); - if (input_file == ACE_INVALID_HANDLE) - ACE_ERROR_RETURN ((LM_DEBUG, - "Cannot open input file for reading IOR: %s\n", - iorfile), - -1); - ACE_Read_Buffer ior_buffer (input_file); - char *data = ior_buffer.read (); - if (data == 0) - ACE_ERROR_RETURN ((LM_ERROR, - "Unable to read ior\n"), - -1); - ior = ACE_OS::strdup (data); - ior_buffer.alloc ()-> free (data); - ACE_OS::close (input_file); + ACE_DECLARE_NEW_CORBA_ENV; - CORBA::Object_var object = orb->string_to_object (ior, env); - if (env.exception () != 0) + ACE_TRY { - env.print_exception ("CORBA::ORB::string_to_object"); - return -1; - } + + char* ior=0; - // Narrow the object reference to a File::System - File::System_var file_system = File::System::_narrow (object.in (), env); - if (env.exception () != 0) - { - env.print_exception ("File::System::_narrow"); - return -1; - } - - // Creat the file filename i.e "test" - File::Descriptor_var fd = file_system->open (filename, O_CREAT | O_RDWR, env); - if (env.exception () != 0) - { - env.print_exception ("File::System::open"); - return -1; - } - - int message_length = ACE_OS::strlen (message) + 1; - CORBA::Octet *buffer = File::Descriptor::DataBuffer::allocbuf (message_length); - ACE_OS::strcpy ((char *) buffer, message); - File::Descriptor::DataBuffer data_sent (message_length, message_length, buffer, 1); - - // write the message to the file - fd->write (data_sent, env); - if (env.exception () != 0) - { - env.print_exception ("File::Descriptor::write"); - return -1; - } - - //seek to the beginning of the file - fd->lseek (0, SEEK_SET, env); - if (env.exception () != 0) - { - env.print_exception ("File::Descriptor::lseek"); - return -1; - } - - // Read back the written message - File::Descriptor::DataBuffer_var data_received = fd->read (message_length, env); - if (env.exception () != 0) - { - env.print_exception ("File::Descriptor::read"); - return -1; + // Initialize the ORB + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, 0, ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Parse the command-line arguments to get the IOR + parse_args (argc, argv); + + // parse args should catch this, but just in case... + if (iorfile == 0) + return 0; + + // Read the file, and get the IOR + ACE_HANDLE input_file = ACE_OS::open (iorfile, 0); + if (input_file == ACE_INVALID_HANDLE) + ACE_ERROR_RETURN ((LM_DEBUG, + "Cannot open input file for reading IOR: %s\n", + iorfile), + -1); + ACE_Read_Buffer ior_buffer (input_file); + char *data = ior_buffer.read (); + if (data == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to read ior\n"), + -1); + ior = ACE_OS::strdup (data); + ior_buffer.alloc ()-> free (data); + ACE_OS::close (input_file); + + CORBA::Object_var object = orb->string_to_object (ior, ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Narrow the object reference to a File::System + File::System_var file_system = File::System::_narrow (object.in (), + ACE_TRY_ENV); + // Creat the file filename i.e "test" + File::Descriptor_var fd = file_system->open (filename, + O_CREAT | O_RDWR, + ACE_TRY_ENV); + ACE_TRY_CHECK; + + int message_length = ACE_OS::strlen (message) + 1; + CORBA::Octet *buffer = File::Descriptor::DataBuffer::allocbuf (message_length); + ACE_OS::strcpy ((char *) buffer, message); + File::Descriptor::DataBuffer data_sent (message_length, message_length, buffer, 1); + + // write the message to the file + fd->write (data_sent, ACE_TRY_ENV); + ACE_TRY_CHECK; + + //seek to the beginning of the file + fd->lseek (0, SEEK_SET, ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Read back the written message + File::Descriptor::DataBuffer_var data_received = fd->read (message_length, + ACE_TRY_ENV); + ACE_TRY_CHECK; + + char *result = (char *) &data_received[0]; + + // print the read message + ACE_DEBUG((LM_DEBUG,"%s\n", + result)); + + // close the file + fd->destroy (ACE_TRY_ENV); + ACE_TRY_CHECK; } - - char *result = (char *) &data_received[0]; - - // print the read message - ACE_DEBUG((LM_DEBUG,"%s\n", - result)); - - // close the file - fd->destroy (env); - if (env.exception () != 0) + ACE_CATCHANY { - env.print_exception ("File::Descriptor::destroy"); return -1; } + ACE_ENDTRY; + ACE_CHECK_RETURN (-1); return 0; } |