Exemplo n.º 1
0
Server_Info_Ptr
Locator_Repository::get_active_server (const ACE_CString& name, int pid)
{
  sync_load ();
  ACE_CString key;
  Server_Info_Ptr si;
  if (name.length() == 0)
    {
      return si;
    }
  Server_Info::fqname_to_key (name.c_str(), key);
  servers ().find (key, si);
  if (si.null())
    {
      if (this->opts_.debug() > 5)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%P|%t) get_active_server could not find %C\n"),
                          name.c_str()));
        }
      si = find_by_poa (key);
      if (si.null())
        {
          if (name.find ("JACORB:") == ACE_CString::npos)
            {
              ACE_CString jo_key ("JACORB:");
              ACE_CString::size_type pos = name.find (':');
              if (pos == ACE_CString::npos)
                {
                  jo_key += name;
                }
              else
                {
                  jo_key += name.substring (0, pos);
                  jo_key += '/';
                  jo_key += name.substring (pos+1);
                }
              return this->get_active_server (jo_key, pid);
            }
          else
            {
              return si;
            }
        }
    }

  if (pid != 0 && si->pid != 0 && si->pid != pid)
    {
      if (this->opts_.debug() > 5)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%P|%t) get_active_server could not")
                          ACE_TEXT (" find %C, %d != %d\n"),
                          name.c_str(), pid, si->pid));
        }
      si.reset ();
    }
  return si;
}
Exemplo n.º 2
0
int
HTML_Body_Iterator::next (ACE_CString &url)
{
  size_t len = BUFSIZ;
  const char *buf;
  ACE_CString buffer;
  int href_index = 0;

  for (buf = this->url_.stream ().recv (len);
       buf > 0;
       buf = this->url_.stream ().recv (len))
    {

      buffer.set (buf, BUFSIZ, 1);

      href_index = ACE_Utils::truncate_cast<int> (buffer.find ("HREF"));

      if (href_index < 0)
        href_index = ACE_Utils::truncate_cast<int> (buffer.find ("href"));

      // Grep fpr " and grab the string until end-"
      if ( href_index > 0)
        {
          // Get back to buffer start location.
          this->url_.stream ().seek (-1 * static_cast<ACE_OFF_T> (len),
                                     SEEK_CUR);

          int start_index =
            ACE_Utils::truncate_cast<int> (
              buffer.find ('\"', href_index));

          if (start_index <= 0)
            break;

          start_index += href_index;

          int end_index =
            ACE_Utils::truncate_cast<int> (
              buffer.find ('\"', start_index + 1));

          if (end_index <= 0)
            break;

          end_index += start_index + 1;

          ssize_t url_len = end_index - (start_index + 1);

          ACE_CString temp = buffer.substring (start_index + 1,
                                               url_len);
          url.set (temp.c_str (), len, 1);

          this->url_.stream ().seek (end_index + 1);

          return url_len;
        }
    }
  return 0;

}
Exemplo n.º 3
0
//
// get_target_basename
//
const ACE_CString & BE_GlobalData::get_target_basename (void) const
{
  if (!this->target_basename_.empty ())
    return this->target_basename_;

  // Normalize the source file name.
  ACE_CString dup_src_file (this->source_file_);
  std::replace (dup_src_file.begin (), dup_src_file.end (), '\\', '/');

  // Extract the basename of the source file. This include removing
  // the path from the source file, and removing its extension.
  size_t pos = dup_src_file.rfind ('/');
  ACE_CString filename;
  BE_GlobalData::get_filename (dup_src_file, filename);

  pos = filename.rfind ('.');
  this->target_basename_ = pos == ACE_CString::npos ? filename : filename.substring (0, pos);
  this->target_basename_ += this->suffix_;

  return this->target_basename_;
}
bool
ImR_Locator_i::split_key (ACE_CString &full, ACE_CString &key, Server_Info_Ptr &si)
{
  key = full;
  if (this->get_info_for_name (full.c_str(), si))
    {
      return true;
    }

  ACE_CString::size_type pos = full.rfind ('/');
  while (pos != ACE_CString::npos)
    {
      ACE_CString server = full.substring (0, pos);
      if (this->get_info_for_name (server.c_str (), si))
        {
          return true;
        }
      pos = server.rfind ('/');
    }

  return false;
}
Exemplo n.º 5
0
int
TAO_ORB_Parameters::parse_and_add_endpoints (const ACE_CString &endpoints,
                                             TAO_EndpointSet &endpoint_set)
{
  // Parse the string into seperate endpoints, where `endpoints' is of
  // the form:
  //
  //    protocol1://V,v@addr1,...,addrN;protocol2://addr1,...,W.w@addrN;...
  //
  // A single endpoint, instead of several, can be added just as well.

  static char const endpoints_delimiter = ';';

  size_t const length = endpoints.length ();

  if (endpoints[0] == endpoints_delimiter ||
      endpoints[length - 1] == endpoints_delimiter)
    {
      return -1;
      // Failure: endpoints string has an empty endpoint at the
      // beginning or the end of the string
      // (e.g. ";uiop://foo;iiop://1.3@bar")
    }

  int status = 0;
  // Return code:  0 = success,  -1 = failure

  if (length > 0)
    {
      int endpoints_count = 1;

      for (size_t j = 0; j != length; ++j)
        {
          if (endpoints[j] == endpoints_delimiter)
            {
              ++endpoints_count;
            }
        }

      ssize_t begin = 0;
      ssize_t end = endpoints.find (endpoints_delimiter);

      for (int i = 0; i < endpoints_count; ++i)
        {
          if (end == 0)
            {
              // Handle case where two consecutive endpoints `;;'
              // delimiters are found within the endpoints set.
              //
              // Is it enough to just skip over it or should we return an
              // error?
              continue;
            }

          ACE_CString const endpt =
            endpoints.substring (begin, end - begin);
          // The substring call will work even if `end' is equal to
          // ACE_CString::npos since that will just extract the substring
          // from the offset `begin' to the end of the string.

          // Check for a valid URL style endpoint set
          ACE_CString::size_type const check_offset = endpt.find ("://");

          if (check_offset > 0 &&
              check_offset != endpt.npos)
            {
              endpoint_set.enqueue_tail (endpt);
              // Insert endpoint into list
            }
          else
            {
              status = -1;  // Error: invalid URL style endpoint set
            }

          begin = end + 1;
          end = endpoints.find (endpoints_delimiter, begin);
        }
    }
  else
    {
      status = -1;
      // Failure:  Empty string
    }

  return status;
}
Exemplo n.º 6
0
int
TAO_Connector::make_mprofile (const char *string, TAO_MProfile &mprofile)
{
  // This method utilizes the "Template Method" design pattern to
  // parse the given URL style IOR for the protocol being used
  // and create an mprofile from it.
  //
  // The methods that must be defined by all Connector sub-classes are:
  //      make_profile
  //      check_prefix

  // Check for a valid string
  if (!string || !*string)
    {
      throw ::CORBA::INV_OBJREF (
        CORBA::SystemException::_tao_minor_code (
          0,
          EINVAL),
        CORBA::COMPLETED_NO);
    }

  // Check for the proper prefix in the IOR.  If the proper prefix isn't
  // in the IOR then it is not an IOR we can use.
  if (this->check_prefix (string) != 0)
    {
      return 1;
      // Failure: not the correct IOR for this protocol.
      // DO NOT throw an exception here since the Connector_Registry
      // should be allowed the opportunity to continue looking for
      // an appropriate connector.
    }

  if (TAO_debug_level > 0)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - TAO_Connector::make_mprofile ")
                  ACE_TEXT ("<%C>\n"),
                  string));
    }

  ACE_CString ior;

  ior.set (string, ACE_OS::strlen (string), 1);

  // Find out where the protocol ends
  ACE_CString::size_type ior_index = ior.find ("://");

  if (ior_index == ACE_CString::npos)
    {
      throw ::CORBA::INV_OBJREF ();
      // No colon ':' in the IOR!
    }
  else
    {
      ior_index += 3;
      // Add the length of the colon and the two forward slashes `://'
      // to the IOR string index (i.e. 3)
    }

  // Find the object key
  const ACE_CString::size_type objkey_index =
    ior.find (this->object_key_delimiter (), ior_index);

  if (objkey_index == 0 || objkey_index == ACE_CString::npos)
    {
      throw ::CORBA::INV_OBJREF ();
      // Failure: No endpoints specified or no object key specified.
    }

  const char endpoint_delimiter = ',';
  // The delimiter used to separate individual addresses.

  // Count the number of endpoints in the IOR.  This will be the number
  // of entries in the MProfile.

  CORBA::ULong profile_count = 1;
  // Number of endpoints in the IOR  (initialized to 1).

  // Only check for endpoints after the protocol specification and
  // before the object key.
  for (ACE_CString::size_type i = ior_index; i < objkey_index; ++i)
    {
      if (ior[i] == endpoint_delimiter)
        ++profile_count;
    }

  // Tell the MProfile object how many Profiles it should hold.
  // MProfile::set(size) returns the number profiles it can hold.
  if (mprofile.set (profile_count) != static_cast<int> (profile_count))
    {
      throw ::CORBA::INV_OBJREF (
        CORBA::SystemException::_tao_minor_code (
          TAO_MPROFILE_CREATION_ERROR,
          0),
        CORBA::COMPLETED_NO);
      // Error while setting the MProfile size!
    }

  // The idea behind the following loop is to split the IOR into several
  // strings that can be parsed by each profile.
  // For example,
  //    `1.3@moo,shu,1.1@chicken/arf'
  // will be parsed into:
  //    `1.3@moo/arf'
  //    `shu/arf'
  //    `1.1@chicken/arf'

  ACE_CString::size_type begin = 0;
  ACE_CString::size_type end = ior_index - 1;
  // Initialize the end of the endpoint index

  for (CORBA::ULong j = 0; j < profile_count; ++j)
    {
      begin = end + 1;

      if (j < profile_count - 1)
        {
          end = ior.find (endpoint_delimiter, begin);
        }
      else
        {
          end = objkey_index;  // Handle last endpoint differently
        }

      if (end < ior.length () && end != ior.npos)
        {
          ACE_CString endpoint = ior.substring (begin, end - begin);

          // Add the object key to the string.
          endpoint += ior.substring (objkey_index);

          // The endpoint should now be of the form:
          //    `N.n@endpoint/object_key'
          // or
          //    `endpoint/object_key'

          TAO_Profile *profile =
            this->make_profile ();
          // Failure:  Problem during profile creation

          // Initialize a Profile using the individual endpoint
          // string.
          // @@ Not exception safe!  We need a TAO_Profile_var!
          profile->parse_string (endpoint.c_str ()
                                );

          // Give up ownership of the profile.
          if (mprofile.give_profile (profile) == -1)
            {
              profile->_decr_refcnt ();

              throw ::CORBA::INV_OBJREF (
                CORBA::SystemException::_tao_minor_code (
                  TAO_MPROFILE_CREATION_ERROR,
                  0),
                CORBA::COMPLETED_NO);
              // Failure presumably only occurs when MProfile is full!
              // This should never happen.
            }
        }
      else
        {
          throw ::CORBA::INV_OBJREF ();
          // Unable to separate endpoints
        }
    }

  return 0;  // Success
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
    int c, instance = -1;
    ACE_CString daemonRef;
    ACE_CString hostName;
    ACE_CString additional;
    for (;;) {
	int option_index = 0;
	c = getopt_long(argc, argv, "hi:d:H:a:",
			long_options, &option_index);
	if (c == -1)
	    break;
	switch (c) {
	case 'h':
	    usage(argv[0]);
	    return 0;
	case 'i':
	    instance = ACE_OS::atoi(optarg);
	    break;
	case 'd':
	    daemonRef = optarg;
	    break;
	case 'H':
	    hostName = optarg;
	    break;
	case 'a':
	    additional = optarg;
	    break;
	}
    }
    if (instance == -1) {
	ACE_OS::printf("Error: instance is a mandatory option try %s -h\n",
		       argv[0]);
	return -1;
    }

	#define DEFAULT_LOG_FILE_NAME "acs_local_log"
	ACE_CString daemonsLogFileName = getTempFileName(0, DEFAULT_LOG_FILE_NAME);

	// replace "ACS_INSTANCE.x" with "acsdaemonStartAcs_" + <timestamp>
	ACE_CString daemonsDir = "acsdaemonStartAcs_" + getStringifiedTimeStamp();

	ACE_CString instancePart("ACS_INSTANCE.");
	ACE_CString::size_type pos = daemonsLogFileName.find(instancePart);
	daemonsLogFileName =
			daemonsLogFileName.substring(0, pos) +
			daemonsDir +
			daemonsLogFileName.substring(pos + instancePart.length() + 1);	// +1 for skipping instance number

	ACE_OS::setenv("ACS_LOG_FILE", daemonsLogFileName.c_str(), 1);

	LoggingProxy *logger = new LoggingProxy(0, 0, 31);
    if (logger) {
	LoggingProxy::init(logger);
	LoggingProxy::ProcessName(argv[0]);
	LoggingProxy::ThreadName("main");
    } else
	ACS_SHORT_LOG((LM_INFO, "Failed to initialize logging."));

    StartCallback* sc = new StartCallback();

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

	// get a reference to the RootPOA
	CORBA::Object_var pobj = orb->resolve_initial_references("RootPOA");
	PortableServer::POA_var root_poa = PortableServer::POA::_narrow(pobj.in());
	PortableServer::POAManager_var poa_manager = root_poa->the_POAManager();
      
	// create policies
	CORBA::PolicyList policy_list;
	policy_list.length(5);
	policy_list[0] = root_poa->create_request_processing_policy(PortableServer::USE_DEFAULT_SERVANT);
	policy_list[1] = root_poa->create_id_uniqueness_policy(PortableServer::MULTIPLE_ID);
	policy_list[2] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); 
	policy_list[3] = root_poa->create_servant_retention_policy(PortableServer::NON_RETAIN); 
	policy_list[4] = root_poa->create_lifespan_policy(PortableServer::PERSISTENT);
      
	// create a ACSDaemon POA with policies 
	PortableServer::POA_var poa = root_poa->create_POA("DaemonCallback", poa_manager.in(), policy_list);

	// destroy policies
	for (CORBA::ULong i = 0; i < policy_list.length(); ++i)
	    {
	    CORBA::Policy_ptr policy = policy_list[i];
	    policy->destroy();
	    }

	// set as default servant
	poa->set_servant(sc);

	// create reference
	PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("DaemonCallback");
	pobj = poa->create_reference_with_id (oid.in(), sc->_interface_repository_id());
	CORBA::String_var m_ior = orb->object_to_string(pobj.in());

	// bind to IOR table
      	CORBA::Object_var table_object = orb->resolve_initial_references("IORTable");
	IORTable::Table_var adapter = IORTable::Table::_narrow(table_object.in());
      
	if (CORBA::is_nil(adapter.in()))
	    {
	    ACS_SHORT_LOG ((LM_ERROR, "Nil IORTable"));
	    return -1;
	    }
	else
	    {
	    adapter->bind("DaemonCallback", m_ior.in());
	    }

	// activate POA
	poa_manager->activate();

	ACS_SHORT_LOG((LM_INFO, "%s is waiting for incoming requests.", "DaemonCallback"));


	// construct default one
	if (daemonRef.length() == 0) {
	    if (hostName.length() == 0) {
		hostName = ACSPorts::getIP();
	    }
	    daemonRef = "corbaloc::";
	    daemonRef =
		daemonRef + hostName + ":" +
		ACSPorts::getServicesDaemonPort().c_str() +
		"/" + ::acsdaemon::servicesDaemonServiceName;
	    ACS_SHORT_LOG((LM_INFO,
			   "Using local ACS Services Daemon reference: '%s'",
			   daemonRef.c_str()));

	} else {
	    ACS_SHORT_LOG((LM_INFO,
			   "ACS Services Daemon reference obtained via command line: '%s'",
			   daemonRef.c_str()));
	}

	CORBA::Object_var obj = orb->string_to_object(daemonRef.c_str());
	if (CORBA::is_nil(obj.in())) {
	    ACS_SHORT_LOG((LM_INFO, "Failed to resolve reference '%s'.",
			   daemonRef.c_str()));
	    return -1;
	}

	acsdaemon::ServicesDaemon_var daemon =
	    acsdaemon::ServicesDaemon::_narrow(obj.in());
	if (CORBA::is_nil(daemon.in())) {
	    ACS_SHORT_LOG((LM_INFO, "Failed to narrow reference '%s'.",
			   daemonRef.c_str()));
	    return -1;
	}

	// @todo implement support for callback and wait for completion call
	acsdaemon::DaemonSequenceCallback_var dummyCallback = sc->_this();
	ACS_SHORT_LOG((LM_INFO, "Calling start_acs(%d, %s, dummyCallback).", instance,
		       additional.c_str()));
	daemon->start_acs(dummyCallback.in(), instance, additional.c_str());
	ACS_SHORT_LOG((LM_INFO, "ACS start message issued."));

	while(!sc->isComplete())
	{
	    if (orb->work_pending())
	        orb->perform_work();
	}
    }
    catch(ACSErrTypeCommon::BadParameterEx & ex) {
	ACSErrTypeCommon::BadParameterExImpl exImpl(ex);
	exImpl.log();
	return -1;
    }
    catch(CORBA::Exception & ex) {

	ACS_SHORT_LOG((LM_INFO, "Failed."));
	ex._tao_print_exception("Caught unexpected exception:");
	return -1;
    }

    return 0;
}