TAO_IMR_Op_IOR Class Reference

IOR Operation. More...

#include <tao_imr_i.h>

Inheritance diagram for TAO_IMR_Op_IOR:

Inheritance graph
[legend]
Collaboration diagram for TAO_IMR_Op_IOR:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual int parse (int argc, ACE_TCHAR **argv)
 Parse arguments.

virtual int run (void)
 Do the work.


Protected Member Functions

void print_usage (void)
 Prints a message about the usage.


Protected Attributes

ACE_CString server_name_
 POA server name.

ACE_CString filename_
 Filename to output to.


Detailed Description

IOR Operation.

IOR is used to create a simple IOR for a server that uses the IMR and the Interoperable Naming Service.

Definition at line 166 of file tao_imr_i.h.


Member Function Documentation

int TAO_IMR_Op_IOR::parse int  argc,
ACE_TCHAR **  argv
[virtual]
 

Parse arguments.

Implements TAO_IMR_Op.

Definition at line 352 of file tao_imr_i.cpp.

References ACE_ERROR, LM_ERROR, and print_usage().

00353 {
00354   // Check for enough arguments (we need at least one for the server name)
00355   if (argc < 2)
00356     {
00357       this->print_usage ();
00358       return -1;
00359     }
00360 
00361   // Skip both the program name and the "ior" command
00362   ACE_Get_Opt get_opts (argc, argv, "hf:");
00363 
00364   this->server_name_ = argv[1];
00365   if (this->server_name_.length() == 0 || this->server_name_[0] == '-')
00366     {
00367       ACE_ERROR((LM_ERROR, "ERROR : name is required.\n"));
00368       this->print_usage ();
00369       return -1;
00370     }
00371 
00372   int c;
00373 
00374   while ((c = get_opts ()) != -1)
00375     {
00376       switch (c)
00377       {
00378       case 'f':  // File name
00379         this->filename_ = get_opts.opt_arg ();
00380         break;
00381       case 'h':  // display help
00382         this->print_usage ();
00383         return -1;
00384       default:
00385         ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00386         this->print_usage ();
00387         return -1;
00388       }
00389     }
00390   return 0;
00391 }

void TAO_IMR_Op_IOR::print_usage void   )  [protected]
 

Prints a message about the usage.

Definition at line 337 of file tao_imr_i.cpp.

References ACE_ERROR, and LM_ERROR.

Referenced by parse().

00338 {
00339   ACE_ERROR ((LM_ERROR, "Creates an IOR for a server that is registered with the IMR and uses\n"
00340     "the InterOperable Naming Service.  Please see the documentation for\n"
00341     "more information on which server configurations work with this command.\n"
00342     "\n"
00343     "Usage: tao_imr [options] ior <object_key> [command-arguments]\n"
00344     "  where [options] are ORB options\n"
00345     "  where <object_key> matches the simple key bound in the server IORTable.\n"
00346     "  where [command-arguments] can be\n"
00347     "    -f filename   filename to output the IOR to\n"
00348     "    -h            Displays this\n"));
00349 }

int TAO_IMR_Op_IOR::run void   )  [virtual]
 

Do the work.

Implements TAO_IMR_Op.

Definition at line 770 of file tao_imr_i.cpp.

References ACE_ASSERT, ACE_CString, ACE_DEBUG, ACE_ERROR_RETURN, ACE_TEXT(), ACE_OS::fclose(), ACE_OS::fopen(), ACE_OS::fprintf(), CORBA::is_nil(), LM_DEBUG, LM_ERROR, ACE_OS::strchr(), and ACE_OS::strstr().

00771 {
00772   ACE_ASSERT (! CORBA::is_nil(imr_));
00773 
00774   // Create a corbaloc string
00775   // Todo : Most of this logic duplicates that in the POA.cpp
00776   try
00777     {
00778       if (CORBA::is_nil (this->imr_)
00779         || !this->imr_->_stubobj ()
00780         || !this->imr_->_stubobj ()->profile_in_use ())
00781       {
00782         ACE_ERROR_RETURN ((
00783           LM_ERROR,
00784           ACE_TEXT ("Invalid ImR IOR.\n")
00785           ), -1);
00786       }
00787 
00788       CORBA::String_var imr_str =
00789         this->imr_->_stubobj ()->
00790         profile_in_use ()->to_string ();
00791 
00792       // Search for "corbaloc:" alone, without the protocol.  This code
00793       // should be protocol neutral.
00794       const char corbaloc[] = "corbaloc:";
00795       char *pos = ACE_OS::strstr (imr_str.inout (), corbaloc);
00796 
00797       if (pos == 0)
00798       {
00799         ACE_ERROR_RETURN ((LM_ERROR, "Could not parse IMR IOR.\n"), -1);
00800       }
00801       else
00802       {
00803         pos = ACE_OS::strchr (pos + sizeof (corbaloc), ':');
00804         pos = ACE_OS::strchr (pos + 1,
00805           this->imr_->_stubobj ()->profile_in_use ()->object_key_delimiter ());
00806 
00807         if (pos)
00808         {
00809           *(pos + 1) = 0;  // Crop the string
00810         }
00811         else
00812         {
00813           ACE_ERROR_RETURN ((LM_ERROR, "Could not parse IMR IOR.\n"), -1);
00814         }
00815       }
00816       ACE_CString ior (imr_str.in ());
00817 
00818       // Add the key
00819       ior += this->server_name_;
00820 
00821       ACE_DEBUG ((LM_DEBUG, "%s\n", ior.c_str ()));
00822 
00823       if (this->filename_.length () > 0)
00824       {
00825         FILE *file = ACE_OS::fopen (this->filename_.c_str (), "w");
00826 
00827         if (file == 0)
00828         {
00829           ACE_ERROR_RETURN ((LM_ERROR,
00830             "Error: Unable to open %s for writing: %p\n",
00831             this->filename_.c_str ()),
00832             -1);
00833         }
00834 
00835         ACE_OS::fprintf (file, "%s", ior.c_str ());
00836         ACE_OS::fclose (file);
00837       }
00838     }
00839   catch (const CORBA::Exception& ex)
00840     {
00841       ex._tao_print_exception ("IOR");
00842       return TAO_IMR_Op::UNKNOWN;
00843     }
00844 
00845   return TAO_IMR_Op::NORMAL;
00846 }


Member Data Documentation

ACE_CString TAO_IMR_Op_IOR::filename_ [protected]
 

Filename to output to.

Definition at line 180 of file tao_imr_i.h.

ACE_CString TAO_IMR_Op_IOR::server_name_ [protected]
 

POA server name.

Definition at line 177 of file tao_imr_i.h.


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 15:56:05 2008 for TAO_Implementation_Repository by doxygen 1.3.6