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 357 of file tao_imr_i.cpp.

References ACE_ERROR, LM_ERROR, and print_usage().

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

void TAO_IMR_Op_IOR::print_usage void   )  [protected]
 

Prints a message about the usage.

Definition at line 342 of file tao_imr_i.cpp.

References ACE_ERROR, and LM_ERROR.

Referenced by parse().

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

int TAO_IMR_Op_IOR::run void   )  [virtual]
 

Do the work.

Implements TAO_IMR_Op.

Definition at line 782 of file tao_imr_i.cpp.

References ACE_ANY_EXCEPTION, ACE_ASSERT, ACE_CATCHANY, ACE_CString, ACE_DEBUG, ACE_ENDTRY, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_ERROR_RETURN, ACE_PRINT_EXCEPTION, ACE_TEXT(), ACE_TRY_CHECK, ACE_TRY_NEW_ENV, ACE_OS::fclose(), ACE_OS::fopen(), ACE_OS::fprintf(), CORBA::is_nil(), LM_DEBUG, LM_ERROR, ACE_OS::strchr(), and ACE_OS::strstr().

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


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 Thu Nov 9 13:37:28 2006 for TAO_Implementation_Repository by doxygen 1.3.6