Пример #1
0
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  if (parse_args(argc, argv) != 0)
    return 1;

  try
    {
      ACE_Argv_Type_Converter converter(argc, argv);

      CORBA::ORB_var orb =
        CORBA::ORB_init(converter.get_argc(), converter.get_ASCII_argv(), "");

      CORBA::Object_var tmp =
          orb->string_to_object (ACE_TEXT_ALWAYS_CHAR(ior));
      OpenDDS::DCPS::DCPSInfo_var info =
          OpenDDS::DCPS::DCPSInfo::_narrow (tmp.in ());

      if (CORBA::is_nil(info.in()) )
        {
          ACE_ERROR_RETURN ((LM_DEBUG,
                             "Nil OpenDDS::DCPS::DCPSInfo reference <%s>\n",
                             ior),
                            1);
        }

      OPENDDS_STRING state = info->dump_to_string();

      std::cout << state.c_str() << std::endl;

      // clean up the orb
      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught in publisher.cpp:");
      return 1;
    }

  return 0;
}
Пример #2
0
int ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
  int status = 0;
  const char* exename = "repoctl";

  try {
    // Initialize an ORB.
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    // Grab our information from the command line.
    Options options(argc, argv);
    exename = ACE_OS::strdup( options.name().c_str());

    OpenDDS::DCPS::DCPSInfo_var ir;
    OpenDDS::Federator::Manager_var target;
    OpenDDS::Federator::Manager_var peer;

    if (options.command() == Options::KILL) {
      // Resolve the ir reference.
      std::string iorString("corbaloc:iiop:");
      iorString += options.target();
      iorString += "/";
      iorString += OpenDDS::Federator::REPOSITORY_IORTABLE_KEY;

      if (options.verbose()) {
        ACE_DEBUG((LM_INFO,
                   ACE_TEXT("(%P|%t) INFO: %C: ")
                   ACE_TEXT("attempting to resolve and connect to repository at: %C.\n"),
                   exename,
                   iorString.c_str()));
      }

      CORBA::Object_var obj = orb->string_to_object(iorString.c_str());

      ir = OpenDDS::DCPS::DCPSInfo::_narrow(obj.in());

      if (CORBA::is_nil(ir.in())) {
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("(%P|%t) ERROR: %C: could not narrow %C.\n"),
                   exename,
                   iorString.c_str()));
        return -4;
      }

    } else {
      // Resolve the target reference.
      std::string iorString("corbaloc:iiop:");
      iorString += options.target();
      iorString += "/";
      iorString += OpenDDS::Federator::FEDERATOR_IORTABLE_KEY;

      if (options.verbose()) {
        ACE_DEBUG((LM_INFO,
                   ACE_TEXT("(%P|%t) INFO: %C: ")
                   ACE_TEXT("attempting to resolve and connect to repository at: %C.\n"),
                   exename,
                   iorString.c_str()));
      }

      CORBA::Object_var obj = orb->string_to_object(iorString.c_str());

      target = OpenDDS::Federator::Manager::_narrow(obj.in());

      if (CORBA::is_nil(target.in())) {
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("(%P|%t) ERROR: %C: could not narrow %C.\n"),
                   exename,
                   iorString.c_str()));
        return -5;
      }

      // Join command needs the peer reference resolved as well.
      if (options.command() == Options::JOIN) {
        iorString  = "corbaloc:iiop:";
        iorString += options.peer();
        iorString += "/";
        iorString += OpenDDS::Federator::FEDERATOR_IORTABLE_KEY;

        if (options.verbose()) {
          ACE_DEBUG((LM_INFO,
                     ACE_TEXT("(%P|%t) INFO: %C: ")
                     ACE_TEXT("attempting to resolve and connect to repository at: %C.\n"),
                     exename,
                     iorString.c_str()));
        }

        obj = orb->string_to_object(iorString.c_str());

        peer = OpenDDS::Federator::Manager::_narrow(obj.in());

        if (CORBA::is_nil(peer.in())) {
          ACE_ERROR((LM_ERROR,
                     ACE_TEXT("(%P|%t) ERROR: %C: could not narrow %C.\n"),
                     exename,
                     iorString.c_str()));
          return -6;
        }
      }
    }

    switch (options.command()) {
    case Options::JOIN: {
      if (options.verbose()) {
        ACE_DEBUG((LM_INFO,
                   ACE_TEXT("(%P|%t) INFO: %C: federating.\n"), exename));
      }

      target->join_federation(peer.in(), options.federationDomain());
    }
    break;

    case Options::LEAVE: {
      if (options.verbose()) {
        ACE_DEBUG((LM_INFO,
                   ACE_TEXT("(%P|%t) INFO: %C: leaving and shutting down.\n"), exename));
      }

      target->leave_and_shutdown();
    }
    break;

    case Options::SHUTDOWN: {
      if (options.verbose()) {
        ACE_DEBUG((LM_INFO,
                   ACE_TEXT("(%P|%t) INFO: %C: shutting down.\n"), exename));
      }

      target->shutdown();
    }
    break;

    case Options::KILL: {
      if (options.verbose()) {
        ACE_DEBUG((LM_INFO,
                   ACE_TEXT("(%P|%t) INFO: %C: shutting down.\n"), exename));
      }

      ir->shutdown();
    }
    break;

    default:
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("(%P|%t) ERROR: %C: unknown command requested.\n "), exename));
      usage_and_exit(-7);
      break;
    }

  } catch (const CORBA::Exception& ex) {
    std::string message = "(%P|%t) ABORT: ";
    message += exename;
    message += " : CORBA problem detected.\n";
    ex._tao_print_exception(message.c_str());
    status = -1;

  } catch (const std::exception& ex) {
    ACE_ERROR((LM_ERROR,
               ACE_TEXT("(%P|%t) ABORT: %C: %C exception caught in main().\n"),
               ex.what(), exename));
    status = -2;

  } catch (...) {
    ACE_ERROR((LM_ERROR,
               ACE_TEXT("(%P|%t) ABORT: %C: unspecified exception caught in main() - panic.\n"),
               exename));
    status = -3;

  }

  return status;
}