Example #1
0
std::string GetStringDefault(const char* name, const std::string &def)
{
    ACE_TString val;
    return GetValueHelper(name, val) ? val.c_str() : def;
};
Example #2
0
  bool
  XML_Saver::open(const ACE_TString & base_name, size_t backup_count)
  {
    this->base_name_ = base_name;
    this->backup_count_ = backup_count;
    if (base_name ==  ACE_TEXT("cout"))
    {
      this->output_ = stdout;
      this->close_out_ = false;
    }
    else if (base_name ==  ACE_TEXT("cerr"))
    {
      this->output_ = stderr;
      this->close_out_ = false;
    }
    else
    {
      ACE_TString file_name = base_name;
      file_name += ACE_TEXT(".new");

      this->output_ = ACE_OS::fopen (file_name.c_str(), ACE_TEXT("wb"));
      if (this->output_) {
        this->close_out_ = true;
      } else {
        ORBSVCS_ERROR ((LM_ERROR,
          ACE_TEXT ("(%P|%t) XML_Saver unable to open %s\n"),
            base_name.c_str()));
      }
    }
    if (this->output_ != 0)
    {
      FILE * const out = this->output_;

      ACE_OS::fprintf (out, "<?xml version=\"1.0\"?>\n");

      try
      {
        bool changed = true;
        NVPList attrs;

        ACE_Time_Value const now = ACE_High_Res_Timer::gettimeofday();

        ACE_UINT64 nowus = now.usec();
        static const ACE_UINT64 USECSPERSEC = 1000 * 1000;
        ACE_UINT64 const tmpus = now.sec();
        nowus += tmpus * USECSPERSEC;

        ACE_TCHAR nowusstr[128];
        ACE_OS::sprintf(nowusstr, ACE_UINT64_FORMAT_SPECIFIER, nowus);

        attrs.push_back(NVP("version", "1.0"));
        if (this->timestamp_)
        {
          attrs.push_back(NVP("timestamp", ACE_TEXT_ALWAYS_CHAR(nowusstr)));
        }
        this->begin_object(0, "notification_service", attrs, changed);
      }
      catch (const CORBA::Exception& ex)
      {
        ex._tao_print_exception (
          ACE_TEXT (
            "(%P|%t) XML_Saver Unknown exception\n"));
        if (this->close_out_ && this->output_ != 0)
          {
            (void) ACE_OS::fclose (this->output_);
          }

        this->output_ = 0;
      }
    }
    return this->output_ != 0;
  }
Example #3
0
float GetFloatDefault(const char* name, float def)
{
    ACE_TString val;
    return GetValueHelper(name, val) ? (float)atof(val.c_str()) : def;
};
Example #4
0
int
ACE_DLL_Handle::open (const ACE_TCHAR *dll_name,
                      int open_mode,
                      ACE_SHLIB_HANDLE handle,
                      ERROR_STACK *errors)
{
  ACE_TRACE ("ACE_DLL_Handle::open");
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));

  if (this->dll_name_)
    {
      // Once dll_name_ has been set, it can't be changed..
      if (ACE_OS::strcmp (this->dll_name_, dll_name) != 0)
        {
          if (ACE::debug ())
            ACELIB_ERROR ((LM_ERROR,
                        ACE_TEXT ("ACE (%P|%t) DLL_Handle::open: error, ")
                        ACE_TEXT ("tried to reopen %s with name %s\n"),
                        this->dll_name_,
                        dll_name));

          return -1;
        }
    }
  else
    this->dll_name_ = ACE::strnew (dll_name);

  if (!this->open_called_)
    this->open_called_ = 1;

  // If it hasn't been loaded yet, go ahead and do that now.
  if (this->handle_ == ACE_SHLIB_INVALID_HANDLE)
    {
      if (handle)
        this->handle_ = handle;
      else
        {
          /*
          ** Get the set of names to try loading. We need to do this to
          ** properly support the ability for a user to specify a simple,
          ** unadorned name (for example, "ACE") that will work across
          ** platforms. We apply platform specifics to get a name that will
          ** work (e.g. libACE, ACEd.dll, ACE.dll, etc.) We rely on the
          ** underlying dlopen() implementation to "Do The Right Thing" in
          ** terms of using relative paths, LD_LIBRARY_PATH, system security
          ** rules, etc. except when ACE_MUST_HELP_DLOPEN_SEARCH_PATH is set.
          ** If it is set, then ACE::ldfind() scans the configured path
          ** looking for a match on the name and prefix/suffix applications.
          ** NOTE: having ACE scan for a file and then pass a fully-qualified
          ** pathname to dlopen() is a potential security hole; therefore,
          ** do not use ACE_MUST_HELP_DLOPEN_SEARCH_PATH unless necessary
          ** and only after considering the risks.
          */
          ACE_Array<ACE_TString> dll_names;
          dll_names.max_size (10);    // Decent guess to avoid realloc later

#if defined (ACE_MUST_HELP_DLOPEN_SEARCH_PATH)
          // Find out where the library is
          ACE_TCHAR dll_pathname[MAXPATHLEN + 1];

          // Transform the pathname into the appropriate dynamic link library
          // by searching the ACE_LD_SEARCH_PATH.
          ACE::ldfind (dll_name,
                       dll_pathname,
                       (sizeof dll_pathname / sizeof (ACE_TCHAR)));
          ACE_TString dll_str (dll_pathname);
          dll_names.size (1);
          dll_names.set (dll_str, 0);
#else
          this->get_dll_names (dll_name, dll_names);
#endif

          ACE_Array_Iterator<ACE_TString> name_iter (dll_names);
          ACE_TString *name = 0;
          while (name_iter.next (name))
            {
              // The ACE_SHLIB_HANDLE object is obtained.
              this->handle_ = ACE_OS::dlopen (name->c_str (),
                                              open_mode);

              if (ACE::debug ())
                {
                  ACE_TString err;
                  ACELIB_DEBUG ((LM_DEBUG,
                              ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                              ACE_TEXT ("(\"%s\", 0x%x) -> %s: %s\n"),
                              name->c_str (),
                              open_mode,
                              ((this->handle_ != ACE_SHLIB_INVALID_HANDLE)
                               ? ACE_TEXT ("succeeded")
                               : ACE_TEXT ("failed")),
                              this->error (err).c_str()));
                }

              if (this->handle_ != ACE_SHLIB_INVALID_HANDLE)   // Good one?
                break;

              // If errno is ENOENT we just skip over this one,
              // anything else - like an undefined symbol, for
              // instance must be flagged here or the next error will
              // mask it.
              // @TODO: If we've found our DLL _and_ it's
              // broken, should we continue at all?
              if ((errno != 0) && (errno != ENOENT) && (errors || ACE::debug ()))
                {
                  ACE_TString errtmp;
                  if (errors)
                    {
                      errors->push (this->error (errtmp));
                    }

                  if (ACE::debug ())
                    {
                      if (!errors)
                        this->error (errtmp);
                      ACELIB_ERROR ((LM_ERROR,
                                  ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                                  ACE_TEXT ("(\'%s\') failed, errno=")
                                  ACE_TEXT ("%d: <%s>\n"),
                                  name->c_str (),
                                  ACE_ERRNO_GET,
                                  errtmp.c_str ()));
                    }
                }

#if defined (AIX)
              // AIX often puts the shared library file (most often named
              // shr.o) inside an archive library. If this is an archive
              // library name, then try appending [shr.o] and retry.
              if (ACE_TString::npos != name->strstr (ACE_TEXT (".a")))
                {
                  ACE_TCHAR aix_pathname[MAXPATHLEN + 1];
                  ACE_OS::strncpy (aix_pathname,
                                   name->c_str (),
                                   name->length ());
                  aix_pathname[name->length ()] = '\0';
                  ACE_OS::strcat (aix_pathname, ACE_TEXT ("(shr.o)"));
                  open_mode |= RTLD_MEMBER;

                  if (ACE::debug ())
                    {
                      ACE_TString err;
                      ACELIB_DEBUG ((LM_DEBUG,
                                  ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                                  ACE_TEXT ("(\"%s\", 0x%x) -> %s: %s\n"),
                                  aix_pathname,
                                  open_mode,
                                  (this->handle_ != ACE_SHLIB_INVALID_HANDLE
                                                ? ACE_TEXT ("succeeded")
                                                : ACE_TEXT ("failed")),
                                  this->error(err).c_str()));
                    }

                  this->handle_ = ACE_OS::dlopen (aix_pathname, open_mode);
                  if (this->handle_ != ACE_SHLIB_INVALID_HANDLE)
                    break;

                  // If errno is ENOENT we just skip over this one, anything
                  // else - like an undefined symbol, for instance
                  // must be flagged here or the next error will mask it.
                  //
                  // @TODO: If we've found our DLL _and_ it's broken,
                  // should we continue at all?
                  if ((errno != 0) && (errno != ENOENT) && (errors || ACE::debug ()))
                    {
                      ACE_TString errtmp;
                      if (errors)
                        {
                          errors->push (this->error (errtmp));
                        }

                      if (ACE::debug ())
                        {
                          if (!errors)
                            this->error (errtmp);
                          ACELIB_ERROR ((LM_ERROR,
                                      ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                                      ACE_TEXT ("(\'%s\') failed, errno=")
                                      ACE_TEXT ("%d: <%s>\n"),
                                      name->c_str (),
                                      ACE_ERRNO_GET,
                                      errtmp.c_str ()));
                        }
                    }

                }
#endif /* AIX */

              name_iter.advance ();
            }

          if (this->handle_ == ACE_SHLIB_INVALID_HANDLE)
            {
              if (errors || ACE::debug ())
                {
                  ACE_TString errtmp;
                  if (errors)
                    {
                      errors->push (this->error (errtmp));
                    }

                  if (ACE::debug ())
                    {
                      if (!errors)
                        this->error (errtmp);
                      ACELIB_ERROR ((LM_ERROR,
                                  ACE_TEXT ("ACE (%P|%t) DLL_Handle::open (\"%s\"): ")
                                  ACE_TEXT ("Invalid handle error: %s\n"),
                                  this->dll_name_,
                                  errtmp.c_str ()));
                    }
                }

              return -1;
            }
        }
    }

  ++this->refcount_;

  if (ACE::debug ())
    ACELIB_DEBUG ((LM_DEBUG,
                ACE_TEXT ("ACE (%P|%t) DLL_Handle::open - %s (%d), refcount=%d\n"),
                this->dll_name_,
                this->handle_,
                this->refcount_));
  return 0;
}
int
ACE_Ini_ImpExp::export_section (const ACE_Configuration_Section_Key& section,
                                const ACE_TString& path,
                                FILE* out)
{
    // don't export the root
    if (path.length ())
    {
        // Write out the section header
        ACE_TString header = ACE_TEXT ("[");
        header += path;
        header += ACE_TEXT ("]\n");
        if (ACE_OS::fputs (header.fast_rep (), out) < 0)
            return -1;
        // Write out each value
        int index = 0;
        ACE_TString name;
        ACE_Configuration::VALUETYPE type;
        ACE_TString line;
        ACE_TCHAR int_value[32];
        ACE_TCHAR bin_value[3];
        void* binary_data;
        size_t binary_length;
        ACE_TString string_value;
        while (!config_.enumerate_values (section, index, name, type))
        {
            line = name + ACE_TEXT ("=");
            switch (type)
            {
            case ACE_Configuration::INTEGER:
            {
                u_int value;
                if (config_.get_integer_value (section, name.fast_rep (), value))
                    return -2;
                ACE_OS::sprintf (int_value, ACE_TEXT ("%08x"), value);
                line += int_value;
                break;
            }
            case ACE_Configuration::STRING:
            {
                if (config_.get_string_value (section,
                                              name.fast_rep (),
                                              string_value))
                    return -2;
                line += string_value;
                break;
            }
#ifdef _WIN32
            case ACE_Configuration::INVALID:
                break;  // JDO added break.  Otherwise INVALID is processed
                // like BINARY. If that's correct, please remove the
                // break and these comments
#endif
            case ACE_Configuration::BINARY:
            {
                // not supported yet - maybe use BASE64 codeing?
                if (config_.get_binary_value (section,
                                              name.fast_rep (),
                                              binary_data,
                                              binary_length))
                    return -2;
                line += ACE_TEXT ("\"");
                unsigned char* ptr = (unsigned char*)binary_data;
                while (binary_length)
                {
                    if (ptr != binary_data)
                    {
                        line += ACE_TEXT (",");
                    }
                    ACE_OS::sprintf (bin_value, ACE_TEXT ("%02x"), *ptr);
                    line += bin_value;
                    --binary_length;
                    ++ptr;
                }
                line += ACE_TEXT ("\"");
                delete [] (char *) binary_data;
                break;
            }
            default:
                return -3;
            }// end switch on type

            line += ACE_TEXT ("\n");
            if (ACE_OS::fputs (line.fast_rep (), out) < 0)
                return -4;
            ++index;
        }// end while enumerating values
    }
    // Export all sub sections
    int index = 0;
    ACE_TString name;
    ACE_Configuration_Section_Key sub_key;
    ACE_TString sub_section;
    while (!config_.enumerate_sections (section, index, name))
    {
        ACE_TString sub_section (path);
        if (path.length ())
            sub_section += ACE_TEXT ("\\");
        sub_section += name;
        if (config_.open_section (section, name.fast_rep (), 0, sub_key))
            return -5;
        if (export_section (sub_key, sub_section.fast_rep (), out))
            return -6;
        ++index;
    }
    return 0;
}
Example #6
0
static void
writer (void)
{
  ACE_RW_Process_Mutex mutex (mutex_name.c_str ());

  // Make sure the constructor succeeded
  if (ACE_LOG_MSG->op_status () != 0)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Writer, mutex %s %p\n"),
                  mutex_name.c_str (),
                  ACE_TEXT ("ctor")));
      return;
    }

  ACE_SOCK_Dgram sock;
  ACE_INET_Addr parent;
  parent.set (reporting_port, ACE_LOCALHOST, 1, AF_INET);
  ACE_TCHAR me_str[80];
  parent.addr_to_string (me_str, 80);
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Sending reports to %s\n"), me_str));
  if (sock.open (ACE_Addr::sap_any, PF_INET) == -1)
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("UDP open")));

  Range_Report report;
  report.child_ = 0;   // We're the writer
  ACE_Time_Value start (ACE_Time_Value::zero), stop (ACE_Time_Value::zero);

  // Grab the lock
  if (-1 == mutex.acquire_write ())
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Writer first %p\n"),
                ACE_TEXT ("acquire_write")));
  else
    {
      start = ACE_OS::gettimeofday ();
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer acquired first time\n")));
    }

  // Now sleep, making the readers wait for the lock. Then release the lock,
  // sleep, and reacquire the lock.
  ACE_OS::sleep (2);
  stop = ACE_OS::gettimeofday ();
  if (-1 == mutex.release ())
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Writer %p\n"),
                ACE_TEXT ("first release")));
  else
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Writer released first time\n")));

  report.range_.set (start, stop);
  ssize_t bytes = sock.send (&report, sizeof (report), parent);
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer sent %b byte report\n"), bytes));

  ACE_OS::sleep (1);   // Ensure we don't immediately grab the lock back

  start = stop = ACE_Time_Value::zero;

  if (-1 == mutex.acquire_write ())
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Writer second %p\n"),
                ACE_TEXT ("acquire_write")));
  else
    {
      start = ACE_OS::gettimeofday ();
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer acquired second time\n")));
    }

  ACE_OS::sleep (2);
  stop = ACE_OS::gettimeofday ();
  if (-1 == mutex.release ())
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Writer %p\n"),
                ACE_TEXT ("second release")));
  else
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Writer released second time\n")));
  report.range_.set (start, stop);
  bytes = sock.send (&report, sizeof (report), parent);
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Writer sent %b byte report\n"), bytes));
  sock.close ();
  return;
}
// Print an context with <name> and <parent>
static void
print_context (ACE_Registry::Naming_Context &parent,
               const ACE_TString &name,
               u_long indentation)
{
  // Set indentation
  indent (indentation);
  cout << name << endl;

  ACE_Registry::Naming_Context child_context;
  // Find child context
  int result = parent.resolve_context (name,
                                       child_context,
                                       KEY_READ);
  if (result != 0)
    ACE_ERROR ((LM_ERROR, "%s %s\n", "ACE_Registry::Naming_Context::resolve_context failed for:", name.c_str ()));
  else
    {
      // Print contents of the child
      result = ::print_naming_context (child_context,
                                       indentation + INDENTATION_LEVEL);
      if (result != 0)
        ACE_ERROR ((LM_ERROR, "%p\n", "print_naming_context failed"));
    }
}
Example #8
0
int
SimpleDataWriter::run(SimplePublisher* publisher)
{
  DBG_ENTRY("SimpleDataWriter","run");

  VDBG((LM_DEBUG, "(%P|%t) DBG:   "
             "Build the DataSampleElementList to contain one element - "
             "our 'Hello World' string.\n"));

  // We just send one message.

  // This is what goes in the "Data Block".
  ACE_TString data = "Hello World!";

  // Now we can create the DataSampleHeader struct and set its fields.
  TAO::DCPS::DataSampleHeader header;

  // The +1 makes the null terminator ('/0') get placed into the block.
  header.message_length_ = data.length() + 1;
  header.message_id_ = 1;
  header.sequence_ = 0;
  // TMB - Compiler no longer likes the next line...  source_timestamp_ is gone.
  //header.source_timestamp_ = ACE_OS::gettimeofday().msec();
  header.publication_id_ = this->pub_id_;

  // The DataSampleHeader is what goes in the "Header Block".
  ACE_Message_Block* header_block = new ACE_Message_Block
                                                (header.max_marshaled_size());
  header_block << header;

  // The +1 makes the null terminator ('/0') get placed into the block.
  ACE_Message_Block* data_block = new ACE_Message_Block(data.length() + 1);
  data_block->copy(data.c_str());

  // Chain the "Data Block" to the "Header Block"
  header_block->cont(data_block);

  // Create the DataSampleListElement now.
  TAO::DCPS::DataSampleListElementAllocator allocator(3);
  TAO::DCPS::TransportSendElementAllocator trans_allocator(3, sizeof (TAO::DCPS::TransportSendElement));
  TAO::DCPS::DataSampleListElement* element;

  ACE_NEW_MALLOC_RETURN(element,
           static_cast<TAO::DCPS::DataSampleListElement*> (allocator.malloc(sizeof (TAO::DCPS::DataSampleListElement))),
           TAO::DCPS::DataSampleListElement(this->pub_id_, this, 0, &trans_allocator),
           1);

  // The Sample Element will hold on to the chain of blocks (header + data).
  element->sample_ = header_block;

  // Set up the DataSampleList
  TAO::DCPS::DataSampleList samples;

  samples.head_ = element;
  samples.tail_ = element;
  samples.size_ = 1;

  VDBG((LM_DEBUG, "(%P|%t) DBG:   "
             "Ask the publisher to send the DataSampleList (samples).\n"));

  publisher->send_samples(samples);

  VDBG((LM_DEBUG, "(%P|%t) DBG:   "
             "The Publisher has finished sending the samples.\n"));

  return 0;
}
Example #9
0
CORBA::ExtValueDef::ExtFullValueDescription *
TAO_ExtValueDef_i::describe_ext_value_i (
  )
{
  CORBA::ExtValueDef::ExtFullValueDescription *fv_desc = 0;
  ACE_NEW_RETURN (fv_desc,
                  CORBA::ExtValueDef::ExtFullValueDescription,
                  0);
  CORBA::ExtValueDef::ExtFullValueDescription_var retval = fv_desc;

  ACE_TString holder;
  this->repo_->config ()->get_string_value (this->section_key_,
                                            "name",
                                            holder);
  fv_desc->name = holder.fast_rep ();
  this->repo_->config ()->get_string_value  (this->section_key_,
                                             "id",
                                             holder);
  fv_desc->id = holder.fast_rep ();

  CORBA::ULong val = 0;

  this->repo_->config ()->get_integer_value (this->section_key_,
                                             "is_abstract",
                                             val);
  fv_desc->is_abstract = static_cast<CORBA::Boolean> (val);
  this->repo_->config ()->get_integer_value (this->section_key_,
                                             "is_custom",
                                             val);
  fv_desc->is_custom = static_cast<CORBA::Boolean> (val);
  this->repo_->config ()->get_string_value (this->section_key_,
                                            "container_id",
                                            holder);
  fv_desc->defined_in = holder.fast_rep ();
  this->repo_->config ()->get_string_value (this->section_key_,
                                            "version",
                                            holder);
  fv_desc->version = holder.fast_rep ();

  // Operations.

  fv_desc->operations.length (0);

  ACE_Configuration_Section_Key ops_key;
  int status =
    this->repo_->config ()->open_section (this->section_key_,
                                          "ops",
                                          0,
                                          ops_key);
  CORBA::ULong count = 0;
  CORBA::ULong param_count = 0;
  char *stringified = 0;
  CORBA::ULong i = 0;
  CORBA::ULong j = 0;
  TAO_IDLType_i *idl_type = 0;
  CORBA::Object_var obj;
  ACE_Configuration_Section_Key params_key, excepts_key, except_def_key;

  if (status == 0)
    {
      this->repo_->config ()->get_integer_value (ops_key,
                                                 "count",
                                                 count);
      fv_desc->operations.length (count);
      ACE_Configuration_Section_Key op_key, result_key, contexts_key;

      for (i = 0; i < count; ++i)
        {
          stringified = TAO_IFR_Service_Utils::int_to_string (i);
          this->repo_->config ()->open_section (ops_key,
                                                stringified,
                                                0,
                                                op_key);
          this->repo_->config ()->get_string_value (op_key,
                                                    "name",
                                                    holder);
          fv_desc->operations[i].name = holder.fast_rep ();
          this->repo_->config ()->get_string_value (op_key,
                                                    "id",
                                                    holder);
          fv_desc->operations[i].id = holder.fast_rep ();
          this->repo_->config ()->get_string_value (this->section_key_,
                                                    "id",
                                                    holder);
          fv_desc->operations[i].defined_in = holder.fast_rep ();
          this->repo_->config ()->get_string_value (op_key,
                                                    "result",
                                                    holder);
          idl_type =
            TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                    this->repo_);
          fv_desc->operations[i].result =
            idl_type->type_i ();

          this->repo_->config ()->get_integer_value (op_key,
                                                     "mode",
                                                     val);
          fv_desc->operations[i].mode = static_cast<CORBA::OperationMode> (val);
          CORBA::TCKind kind =
            fv_desc->operations[i].result->kind ();

          if (fv_desc->operations[i].mode == CORBA::OP_ONEWAY
              && kind != CORBA::tk_void)
            {
              throw CORBA::BAD_PARAM (
                CORBA::OMGVMCID | 31,
                CORBA::COMPLETED_NO);
            }

          // Operation contexts.

          TAO_IFR_Strseq_Utils<CORBA::ContextIdSeq>::fill_string_seq (
              "contexts",
              this->repo_->config (),
              op_key,
              fv_desc->operations[i].contexts
            );

          // Operation parameters.

          fv_desc->operations[i].parameters.length (0);
          status =
            this->repo_->config ()->open_section (op_key,
                                                  "params",
                                                  0,
                                                  params_key);
          if (status == 0)
            {
              ACE_Configuration_Section_Key param_key;
              this->repo_->config ()->get_integer_value (params_key,
                                                        "count",
                                                        param_count);
              fv_desc->operations[i].parameters.length (param_count);

              for (j = 0; j < param_count; ++j)
                {
                  stringified = TAO_IFR_Service_Utils::int_to_string (j);
                  this->repo_->config ()->open_section (params_key,
                                                        stringified,
                                                        0,
                                                        param_key);
                  this->repo_->config ()->get_string_value (param_key,
                                                            "name",
                                                            holder);
                  fv_desc->operations[i].parameters[j].name =
                    holder.fast_rep ();
                  this->repo_->config ()->get_string_value (param_key,
                                                            "type_path",
                                                            holder);
                  idl_type =
                    TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                            this->repo_);
                  fv_desc->operations[i].parameters[j].type =
                    idl_type->type_i ();

                  obj =
                    TAO_IFR_Service_Utils::path_to_ir_object (
                                               holder,
                                               this->repo_
                                             );

                  fv_desc->operations[i].parameters[j].type_def =
                    CORBA::IDLType::_narrow (obj.in ());

                  this->repo_->config ()->get_integer_value (param_key,
                                                             "mode",
                                                             val);
                  fv_desc->operations[i].parameters[j].mode =
                    static_cast<CORBA::ParameterMode> (val);
                }
            }

          // Operation exceptions.

          status =
            this->repo_->config ()->open_section (op_key,
                                                  "excepts",
                                                  0,
                                                  excepts_key);
          fv_desc->operations[i].exceptions.length (0);

          if (status == 0)
            {
              CORBA::ULong excep_count = 0;
              this->repo_->config ()->get_integer_value (excepts_key,
                                                         "count",
                                                         excep_count);
              fv_desc->operations[i].exceptions.length (excep_count);
              ACE_Configuration_Section_Key except_def_key;

              for (j = 0; j < excep_count; ++j)
                {
                  stringified = TAO_IFR_Service_Utils::int_to_string (j);
                  this->repo_->config ()->get_string_value (excepts_key,
                                                            stringified,
                                                            holder);

                  this->repo_->config ()->expand_path (
                                              this->repo_->root_key (),
                                              holder,
                                              except_def_key,
                                              0
                                            );
                  this->repo_->config ()->get_string_value (except_def_key,
                                                            "name",
                                                            holder);
                  fv_desc->operations[i].exceptions[j].name =
                    holder.fast_rep ();
                  this->repo_->config ()->get_string_value (except_def_key,
                                                            "id",
                                                            holder);
                  fv_desc->operations[i].exceptions[j].id =
                    holder.fast_rep ();
                  this->repo_->config ()->get_string_value (except_def_key,
                                                            "container_id",
                                                            holder);
                  fv_desc->operations[i].exceptions[j].defined_in =
                    holder.fast_rep ();
                  this->repo_->config ()->get_string_value (except_def_key,
                                                            "version",
                                                            holder);
                  fv_desc->operations[i].exceptions[j].version =
                    holder.fast_rep ();

                  TAO_ExceptionDef_i impl (this->repo_);
                  impl.section_key (except_def_key);
                  fv_desc->operations[i].exceptions[j].type =
                    impl.type_i ();
                }
            }
        }
    }

  // Attributes..

  fv_desc->attributes.length (0);

  ACE_Configuration_Section_Key attrs_key;
  status =
    this->repo_->config ()->open_section (this->section_key_,
                                          "attrs",
                                          0,
                                          attrs_key);
  if (status == 0)
    {
      this->repo_->config ()->get_integer_value (attrs_key,
                                                 "count",
                                                 count);
      fv_desc->attributes.length (count);
      ACE_Configuration_Section_Key attr_key, attr_def_key;

      for (i = 0; i < count; ++i)
        {
          stringified = TAO_IFR_Service_Utils::int_to_string (i);
          this->repo_->config ()->open_section (attrs_key,
                                                stringified,
                                                0,
                                                attr_key);
          this->repo_->config ()->get_string_value (attr_key,
                                                    "name",
                                                    holder);
          fv_desc->attributes[i].name = holder.fast_rep ();
          this->repo_->config ()->get_string_value (attr_key,
                                                    "id",
                                                    holder);
          fv_desc->attributes[i].id = holder.fast_rep ();
          this->repo_->config ()->get_string_value (attr_key,
                                                    "version",
                                                    holder);
          fv_desc->attributes[i].version = holder.fast_rep ();
          this->repo_->config ()->get_integer_value (attr_key,
                                                     "mode",
                                                     val);
          fv_desc->attributes[i].mode =
            static_cast<CORBA::AttributeMode> (val);
          this->repo_->config ()->get_string_value (attr_key,
                                                    "type_path",
                                                    holder);

          // Use the type path for 'defined_in' and 'type'.

          idl_type =
            TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                    this->repo_);
          fv_desc->attributes[i].type =
            idl_type->type_i ();

          this->repo_->config ()->expand_path (this->repo_->root_key (),
                                               holder,
                                               attr_def_key,
                                               0);
          this->repo_->config ()->get_string_value (attr_def_key,
                                                    "container_id",
                                                    holder);
          fv_desc->attributes[i].defined_in = holder.fast_rep ();


          this->fill_exceptions (fv_desc->attributes[i].get_exceptions,
                                 attr_key,
                                 "get_excepts");


          this->fill_exceptions (fv_desc->attributes[i].put_exceptions,
                                 attr_key,
                                 "put_excepts");
        }
    }

  // Members..

  fv_desc->members.length (0);

  ACE_Configuration_Section_Key members_key;
  status =
    this->repo_->config ()->open_section (this->section_key_,
                                          "members",
                                          0,
                                          members_key);
  if (status == 0)
    {
      this->repo_->config ()->get_integer_value (members_key,
                                                 "count",
                                                 count);
      fv_desc->members.length (count);
      ACE_Configuration_Section_Key member_key, member_def_key;

      for (i = 0; i < count; ++i)
        {
          stringified = TAO_IFR_Service_Utils::int_to_string (i);
          this->repo_->config ()->open_section (members_key,
                                                stringified,
                                                0,
                                                member_key);
          this->repo_->config ()->get_string_value (member_key,
                                                    "name",
                                                    holder);
          fv_desc->members[i].name = holder.fast_rep ();
          this->repo_->config ()->get_string_value (member_key,
                                                    "id",
                                                    holder);
          fv_desc->members[i].id = holder.fast_rep ();
          this->repo_->config ()->get_string_value (member_key,
                                                    "container_id",
                                                    holder);
          fv_desc->members[i].defined_in = holder.fast_rep ();
          this->repo_->config ()->get_string_value (member_key,
                                                    "version",
                                                    holder);
          fv_desc->members[i].version = holder.fast_rep ();

          this->repo_->config ()->get_integer_value (member_key,
                                                     "access",
                                                     val);
          fv_desc->members[i].access =
            static_cast<CORBA::Visibility> (val);

          // Use type path for 'type' and 'type_def',

          this->repo_->config ()->get_string_value (member_key,
                                                    "type_path",
                                                    holder);
          idl_type =
            TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                    this->repo_);
          fv_desc->members[i].type =
            idl_type->type_i ();

          obj =
            TAO_IFR_Service_Utils::path_to_ir_object (holder,
                                                      this->repo_);

          fv_desc->members[i].type_def =
            CORBA::IDLType::_narrow (obj.in ());
        }
    }

  // Initializers

  fv_desc->initializers.length (0);

  ACE_Configuration_Section_Key initializers_key;
  status =
    this->repo_->config ()->open_section (this->section_key_,
                                          "initializers",
                                          0,
                                          initializers_key);

  if (status == 0)
    {
      this->repo_->config ()->get_integer_value (initializers_key,
                                                 "count",
                                                 count);
      fv_desc->initializers.length (count);
      ACE_Configuration_Section_Key initializer_key,
                                    params_key,
                                    arg_key,
                                    excepts_key;

      for (i = 0; i < count; ++i)
        {
          stringified = TAO_IFR_Service_Utils::int_to_string (i);
          this->repo_->config ()->open_section (initializers_key,
                                                stringified,
                                                0,
                                                initializer_key);
          this->repo_->config ()->get_string_value (initializer_key,
                                                    "name",
                                                    holder);
          fv_desc->initializers[i].name = holder.fast_rep ();

          fv_desc->initializers[i].members.length (0);

          status =
            this->repo_->config ()->open_section (initializer_key,
                                                  "params",
                                                  0,
                                                  params_key);

          if (status == 0)
            {
              this->repo_->config ()->get_integer_value (params_key,
                                                         "count",
                                                         param_count);
              fv_desc->initializers[i].members.length (param_count);

              for (j = 0; j < param_count; ++j)
                {
                  stringified = TAO_IFR_Service_Utils::int_to_string (j);
                  this->repo_->config ()->open_section (params_key,
                                                        stringified,
                                                        0,
                                                        arg_key);
                  this->repo_->config ()->get_string_value (arg_key,
                                                            "arg_name",
                                                            holder);
                  fv_desc->initializers[i].members[j].name =
                    holder.fast_rep ();
                  this->repo_->config ()->get_string_value (arg_key,
                                                            "arg_path",
                                                            holder);
                  TAO_IDLType_i *impl =
                    TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                             this->repo_);
                  fv_desc->initializers[i].members[j].type =
                    impl->type_i ();

                  obj =
                    TAO_IFR_Service_Utils::path_to_ir_object (
                                               holder,
                                               this->repo_
                                             );

                  fv_desc->initializers[i].members[j].type_def =
                    CORBA::IDLType::_narrow (obj.in ());
                }
            }

          this->fill_exceptions (fv_desc->initializers[i].exceptions,
                                 initializer_key,
                                 "excepts");
        }
    }

  TAO_IFR_Strseq_Utils<CORBA::RepositoryIdSeq>::fill_string_seq (
      "supported",
      this->repo_->config (),
      this->section_key_,
      fv_desc->supported_interfaces
    );

  TAO_IFR_Strseq_Utils<CORBA::RepositoryIdSeq>::fill_string_seq (
      "abstract_bases",
      this->repo_->config (),
      this->section_key_,
      fv_desc->abstract_base_values
    );

  this->repo_->config ()->get_integer_value (this->section_key_,
                                             "is_truncatable",
                                             val);
  fv_desc->is_truncatable = static_cast<CORBA::Boolean> (val);
  status =
    this->repo_->config ()->get_string_value (this->section_key_,
                                              "base_value",
                                              holder);

  if (status == 0)
    {
      ACE_Configuration_Section_Key base_key;
      this->repo_->config ()->expand_path (this->repo_->root_key (),
                                           holder,
                                           base_key,
                                           0);
      this->repo_->config ()->get_string_value (base_key,
                                                "id",
                                                holder);
    }

  // If status isn't 0, then holder will be empty anyway.
  fv_desc->base_value = holder.fast_rep ();
  fv_desc->type = this->type_i ();

  return retval._retn ();
}
CORBA::InterfaceAttrExtension::ExtFullInterfaceDescription *
TAO_InterfaceAttrExtension_i::describe_ext_interface_i (
)
{
    CORBA::InterfaceAttrExtension::ExtFullInterfaceDescription *fifd = 0;
    ACE_NEW_RETURN (fifd,
                    CORBA::InterfaceAttrExtension::ExtFullInterfaceDescription,
                    0);

    CORBA::InterfaceAttrExtension::ExtFullInterfaceDescription_var retval =
        fifd;

    ACE_TString holder;

    this->repo_->config ()->get_string_value (this->section_key_,
            "name",
            holder);
    fifd->name = holder.fast_rep ();
    this->repo_->config ()->get_string_value (this->section_key_,
            "id",
            holder);
    fifd->id = holder.fast_rep ();

    this->repo_->config ()->get_string_value (this->section_key_,
            "container_id",
            holder);

    fifd->defined_in = holder.fast_rep ();
    this->repo_->config ()->get_string_value (this->section_key_,
            "version",
            holder);
    fifd->version = holder.fast_rep ();

    CORBA::ULong i = 0;
    CORBA::ULong j = 0;
    ACE_Unbounded_Queue<ACE_Configuration_Section_Key> key_queue;

    // Store our section key for later restoration after we have
    // traversed entries for inherited interfaces.
    ACE_Configuration_Section_Key key_holder = this->section_key_;

    // Operations
    TAO_InterfaceDef_i iface (this->repo_);
    iface.section_key (this->section_key_);
    iface.inherited_operations (key_queue);

    // Restore our original section key.
    //   I am not sure this is needed but it will not hurt.
    this->section_key (key_holder);

    ACE_Configuration_Section_Key ops_key, op_key;
    int status =
        this->repo_->config ()->open_section (this->section_key_,
                "ops",
                0,
                ops_key);

    CORBA::ULong count = 0;

    if (status == 0)
    {
        this->repo_->config ()->get_integer_value (ops_key,
                "count",
                count);

        for (j = 0; j < count; ++j)
        {
            char *stringified = TAO_IFR_Service_Utils::int_to_string (j);
            status =
                this->repo_->config ()->open_section (ops_key,
                        stringified,
                        0,
                        op_key);

            if (status == 0)
            {
                key_queue.enqueue_tail (op_key);
            }
        }
    }

    CORBA::ULong size = static_cast<CORBA::ULong> (key_queue.size ());
    fifd->operations.length (size);

    for (i = 0; i < size; ++i)
    {
        ACE_Configuration_Section_Key key;
        key_queue.dequeue_head (key);

        TAO_OperationDef_i op (this->repo_);
        op.section_key (key);

        op.make_description (fifd->operations[i]);
    }

    // Restore our original section key.
    //   It may have been overwritten by a superclass key as part of the
    //   make_description() call.
    this->section_key (key_holder);

    // Attributes.
    iface.inherited_attributes (key_queue);

    // Restore our original section key.
    //   I am not sure this is needed but it will not hurt.
    this->section_key (key_holder);

    ACE_Configuration_Section_Key attrs_key;
    status =
        this->repo_->config ()->open_section (this->section_key_,
                "attrs",
                0,
                attrs_key);

    count = 0;

    if (status == 0)
    {
        this->repo_->config ()->get_integer_value (attrs_key,
                "count",
                count);

        for (j = 0; j < count; ++j)
        {
            ACE_Configuration_Section_Key attr_key;
            char *stringified = TAO_IFR_Service_Utils::int_to_string (j);
            status =
                this->repo_->config ()->open_section (attrs_key,
                        stringified,
                        0,
                        attr_key);

            if (status == 0)
            {
                key_queue.enqueue_tail (attr_key);
            }
        }
    }

    size = static_cast<CORBA::ULong> (key_queue.size ());
    fifd->attributes.length (size);

    for (i = 0; i < size; ++i)
    {
        ACE_Configuration_Section_Key key;
        key_queue.dequeue_head (key);

        TAO_ExtAttributeDef_i attr (this->repo_);
        attr.section_key (key);

        attr.fill_description (fifd->attributes[i]);
    }

    // Restore our original section key.
    //   It may have been overwritten by a superclass key as part of the
    //   fill_description() call.
    this->section_key (key_holder);

    CORBA::InterfaceDefSeq_var bases =
        iface.base_interfaces_i ();

    CORBA::ULong length = bases->length ();
    CORBA::RepositoryIdSeq repo_ids (length);
    repo_ids.length (length);

    PortableServer::ObjectId_var oid;
    char *base_path = 0;
    ACE_Configuration_Section_Key base_key;

    for (i = 0; i < length; ++i)
    {
        base_path = TAO_IFR_Service_Utils::reference_to_path (bases[i]);

        this->repo_->config ()->expand_path (this->repo_->root_key (),
                                             base_path,
                                             base_key,
                                             0);
        this->repo_->config ()->get_string_value (base_key,
                "id",
                holder);
        repo_ids[i] = holder.fast_rep ();
    }

    fifd->base_interfaces = repo_ids;

    fifd->type = iface.type_i ();

    return retval._retn ();
}
Example #11
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  CORBA::ORB_var orb;
  test_var server;
  RTScheduling::Scheduler_var safe_scheduler;

  try
    {
      try
        {

          orb = CORBA::ORB_init (argc, argv);

          if (parse_args (argc, argv) == -1)
            return (-1);

          CORBA::Object_var manager_obj = orb->resolve_initial_references ("RTSchedulerManager");

          TAO_RTScheduler_Manager_var manager = TAO_RTScheduler_Manager::_narrow (manager_obj.in ());

          TAO_Scheduler* scheduler = 0;
          ACE_NEW_RETURN (scheduler,
                          TAO_Scheduler (orb.in ()),
                          -1);
          safe_scheduler = scheduler;

          manager->rtscheduler (scheduler);


          CORBA::Object_var object =
            orb->string_to_object (ior.c_str ());

          server = test::_narrow (object.in ());

          if (CORBA::is_nil (server.in ()))
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                "ERROR: Object reference <%s> is nil\n",
                                ior.c_str ()),
                                1);
            }

          CORBA::Object_var current_obj = orb->resolve_initial_references ("RTScheduler_Current");

          RTScheduling::Current_var current = RTScheduling::Current::_narrow (current_obj.in ());

          const char * name = 0;
          CORBA::Policy_ptr sched_param = 0;
          CORBA::Policy_ptr implicit_sched_param = 0;

          current->begin_scheduling_segment (name,
                                            sched_param,
                                            implicit_sched_param);

          ACE_DEBUG ((LM_DEBUG,
                      "Making a one-way request\n"));
          server->one_way (ACE_TEXT_ALWAYS_CHAR(ior.c_str ()));

          ACE_DEBUG ((LM_DEBUG,
                      "Making a two-way request\n"));
          server->two_way (ACE_TEXT_ALWAYS_CHAR(ior.c_str ()));

          current->end_scheduling_segment (name);

        }
      catch (const CORBA::THREAD_CANCELLED& )
        {
          ACE_DEBUG ((LM_DEBUG,
            "Distributable Thread Cancelled - Expected Exception\n"));
          server->shutdown ();
        }
      catch (const CORBA::Exception& ex)
        {
          ex._tao_print_exception ("Caught exception:");

          return 0;
        }

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught unexpected exception:");

      return 1;
    }

  return 0;
}
Example #12
0
int
ACE_DLL_Handle::open (const ACE_TCHAR *dll_name,
                      int open_mode,
                      ACE_SHLIB_HANDLE handle)
{
  ACE_TRACE ("ACE_DLL_Handle::open");
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));

  //ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("dll_name: %s; open_mode: %d \n"),
  //            dll_name,
  //            open_mode));

  if (this->dll_name_)
    {
      // Once dll_name_ has been set, it can't be changed..
      if (ACE_OS::strcmp (this->dll_name_, dll_name) != 0)
        {
          if (ACE::debug ())
            ACE_ERROR ((LM_ERROR,
                        ACE_LIB_TEXT ("ACE_DLL_Handle::open: error, ")
                        ACE_LIB_TEXT ("tried to reopen %s with name %s\n"),
                        this->dll_name_,
                        dll_name));

          return -1;
        }
    }
  else
    this->dll_name_ = ACE::strnew (dll_name);

  if (!this->open_called_)
    this->open_called_ = 1;

  // If it hasn't been loaded yet, go ahead and do that now.
  if (this->handle_ == ACE_SHLIB_INVALID_HANDLE)
    {
      if (handle)
        this->handle_ = handle;
      else
        {
          if (ACE::debug ())
            ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("ACE_DLL_Handle::open: calling dlopen on ")
                        ACE_LIB_TEXT ("\"%s\"\n"), dll_name));

          /*
          ** Get the set of names to try loading. We need to do this to
          ** properly support the ability for a user to specify a simple,
          ** unadorned name (for example, "ACE") that will work across
          ** platforms. We apply platform specifics to get a name that will
          ** work (e.g. libACE, ACEd.dll, ACE.dll, etc.) We rely on the
          ** underlying dlopen() implementation to "Do The Right Thing" in
          ** terms of using relative paths, LD_LIBRARY_PATH, system security
          ** rules, etc. except when ACE_MUST_HELP_DLOPEN_SEARCH_PATH is set.
          ** If it is set, then ACE::ldfind() scans the configured path
          ** looking for a match on the name and prefix/suffix applications.
          ** NOTE: having ACE scan for a file and then pass a fully-qualified
          ** pathname to dlopen() is a potential security hole; therefore,
          ** do not use ACE_MUST_HELP_DLOPEN_SEARCH_PATH unless necessary
          ** and only after considering the risks.
          */
          ACE_Array<ACE_TString> dll_names;
          dll_names.max_size (10);    // Decent guess to avoid realloc later

#if defined (ACE_MUST_HELP_DLOPEN_SEARCH_PATH)
          // Find out where the library is
          ACE_TCHAR dll_pathname[MAXPATHLEN + 1];

          // Transform the pathname into the appropriate dynamic link library
          // by searching the ACE_LD_SEARCH_PATH.
          ACE::ldfind (dll_name,
                       dll_pathname,
                       (sizeof dll_pathname / sizeof (ACE_TCHAR)));
          ACE_TString dll_str (dll_pathname);
          dll_names.size (1);
          dll_names.set (dll_str, 0);
#else
          this->get_dll_names (dll_name, dll_names);
#endif

          ACE_Array_Iterator<ACE_TString> name_iter (dll_names);
          ACE_TString *name = 0;
          while (name_iter.next (name))
            {
              if (ACE::debug ())
                ACE_DEBUG ((LM_DEBUG,
                            ACE_LIB_TEXT ("ACE_DLL_Handle::open: Trying to open DLL %s with %s name\n"),
                            this->dll_name_,
                            name->c_str ()));

              // The ACE_SHLIB_HANDLE object is obtained.
              this->handle_ = ACE_OS::dlopen (name->c_str (),
                                              open_mode);
              if (this->handle_ != ACE_SHLIB_INVALID_HANDLE)   // Good one
                break;

#if defined (AIX)
              // AIX often puts the shared library file (most often named
              // shr.o) inside an archive library. If this is an archive
              // library name, then try appending [shr.o] and retry.
              if (ACE_TString::npos != name->strstr (ACE_LIB_TEXT (".a")))
                {
                  ACE_TCHAR aix_pathname[MAXPATHLEN + 1];
                  ACE_OS::strncpy (aix_pathname,
                                   name->c_str (),
                                   name->length ());
                  aix_pathname[name->length ()] = '\0';
                  ACE_OS::strcat (aix_pathname, ACE_LIB_TEXT ("(shr.o)"));
                  open_mode |= RTLD_MEMBER;
                  this->handle_ = ACE_OS::dlopen (aix_pathname, open_mode);
                  if (this->handle_ != ACE_SHLIB_INVALID_HANDLE)
                    break;
                }
#endif /* AIX */
              name_iter.advance ();
            }

          if (this->handle_ == ACE_SHLIB_INVALID_HANDLE)
            {
              if (ACE::debug ())
                ACE_ERROR ((LM_ERROR,
                            ACE_LIB_TEXT ("ACE_DLL_Handle::open: Invalid handle when opening DLL %s: %s\n"),
                            this->dll_name_,
                            this->error ()->c_str ()));

              return -1;
            }
        }
    }
  if (ACE::debug ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_LIB_TEXT ("ACE_DLL_Handle::open: loading %s (%d)\n"),
                this->dll_name_,
                this->handle_));

  ++this->refcount_;
  return 0;
}
Example #13
0
void
ACE_DLL_Handle::get_dll_names (const ACE_TCHAR *dll_name,
                               ACE_Array<ACE_TString> &try_names)
{
  // Build the array of DLL names to try on this platform by applying the
  // proper prefixes and/or suffixes to the specified dll_name.
  ACE_TString base (dll_name);
  ACE_TString base_dir, base_file, base_suffix;

  // 1. Separate the dll_name into the dir part and the file part. We
  // only decorate the file part to determine the names to try loading.
  int pos = base.rfind (ACE_DIRECTORY_SEPARATOR_CHAR);
  if (pos != ACE_TString::npos)
    {
      base_dir = base.substr (0, static_cast<ssize_t>(pos) + 1);
      base_file = base.substr (static_cast<size_t>(pos) + 1);
    }
  else
    base_file = base;

  // 2. Locate the file suffix, if there is one. Move the '.' and the
  // suffix to base_suffix.
  if ((pos = base_file.rfind (ACE_LIB_TEXT ('.'))) != ACE_TString::npos)
    {
      base_suffix = base_file.substr (static_cast<size_t>(pos));
      base_file = base_file.substr (0, static_cast<ssize_t>(pos));
    }

  // 3. Build the combinations to try for this platform.
  // Try these combinations:
  //   - name as originally given
  //   - name with decorator and platform's suffix appended (if not supplied)
  //   - name with platform's suffix appended (if not supplied)
  //   - name with platform's dll prefix (if it has one) and suffix
  //   - name with platform's dll prefix, decorator, and suffix.
  // So we need room for 5 entries in try_names.
  try_names.size (0);
  if ((try_names.max_size () - try_names.size ()) < 5)
    try_names.max_size (try_names.max_size () + 5);
#if defined (ACE_WIN32) && defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
  ACE_TString decorator (ACE_LD_DECORATOR_STR);
#endif
  ACE_TString suffix (ACE_DLL_SUFFIX);
  ACE_TString prefix (ACE_DLL_PREFIX);

  for (size_t i = 0; i < 5 && try_names.size () < try_names.max_size (); ++i)
    {
      ACE_TString try_this;
      size_t j = try_names.size ();
      switch (i)
        {
        case 0:
          try_this = dll_name;
          break;

        case 1:        // Name + decorator + suffix
        case 2:        // Name + suffix
        case 3:        // Prefix + name + decorator + suffix
        case 4:        // Prefix + name + suffix
          if (
              base_suffix.length () > 0
#if !(defined(ACE_WIN32) && defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK))
              || (i == 2 || i == 4)    // No decorator desired; skip
#endif
              )
            break;
          try_this = base_dir;
          if (i > 2)
            try_this += prefix;
          try_this += base_file;
          if (base_suffix.length () > 0)
            try_this += base_suffix;
          else
            {
#if defined (ACE_WIN32) && defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
              try_this += decorator;
#endif
              try_this += suffix;
            }
          break;
        }

      if (try_this.length ())
        {
          try_names.size (j + 1);
          try_names.set (try_this, j);
        }
    }
  return;
}
Example #14
0
void Directory::scan_dir(const ACE_TString& relative, DDS_Dirent& dir,
                         unsigned int overflow_index)
{
  ACE_TString path = physical_dirname_ + relative;
  add_slash(path);

  while (DDS_DIRENT* ent = dir.read()) {
    if (ent->d_name[0] == ACE_TEXT('.') && (!ent->d_name[1] ||
        (ent->d_name[1] == ACE_TEXT('.') && !ent->d_name[2]))) {
      continue; // skip '.' and '..'
    }

    ACE_TString file = path + ent->d_name;

    if (is_dir(file.c_str())) {
      ACE_TString phys(relative);
      add_slash(phys);
      phys += ent->d_name;

      if (ACE_OS::strncmp(ent->d_name, ACE_TEXT("_overflow."), 10) == 0) {
        unsigned int n = ACE_OS::atoi(ent->d_name + 10);
        DDS_Dirent overflow(file.c_str());
        scan_dir(ent->d_name, overflow, n);

      } else if (ACE_OS::strlen(ent->d_name) <= FSS_MAX_FILE_NAME_ENCODED) {
        dirs_[b32h_decode(ent->d_name)] = phys;
        ++overflow_[overflow_index];

      } else {
        CwdGuard cg(file);
        std::ifstream fn("_fullname");
        std::string fullname;

        if (!std::getline(fn, fullname)) {
          throw std::runtime_error("Can't read .../_fullname");
        }

        ACE_TString full_t(ACE_TEXT_CHAR_TO_TCHAR(fullname.c_str()));
        dirs_[full_t] = phys;
        ++overflow_[overflow_index];

        String_Index_t idx = phys.rfind(ACE_TEXT('.'));

        if (idx == ACE_TString::npos) {
          throw std::runtime_error("Badly formatted long dir name");
        }

        ACE_TString prefix(phys.c_str(), idx);
        unsigned int serial = ACE_OS::atoi(&phys[idx + 1]);
        unsigned int& counter = long_names_[prefix];

        if (serial >= counter) counter = serial + 1;
      }

    } else { // regular file
      if (ent->d_name[0] != ACE_TEXT('_')) {
        files_[b32h_decode(ent->d_name)] = ent->d_name;
        ++overflow_[overflow_index];
      }
    }
  }
}
Example #15
0
int GetIntDefault(const char* name, int def)
{
    ACE_TString val;
    return GetValueHelper(name, val) ? atoi(val.c_str()) : def;
};
Example #16
0
CORBA::ExtInitializerSeq *
TAO_ExtValueDef_i::ext_initializers_i (
  )
{
  CORBA::ExtInitializerSeq *iseq = 0;
  ACE_NEW_RETURN (iseq,
                  CORBA::ExtInitializerSeq,
                  0);
  CORBA::ExtInitializerSeq_var retval = iseq;

  ACE_Configuration_Section_Key initializers_key;
  int status =
    this->repo_->config ()->open_section (this->section_key_,
                                          "initializers",
                                          0,
                                          initializers_key);

  if (status != 0)
    {
      iseq->length (0);
      return retval._retn ();
    }

  CORBA::ULong count = 0;
  this->repo_->config ()->get_integer_value (initializers_key,
                                             "count",
                                             count);
  iseq->length (count);
  char *stringified = 0;
  ACE_Configuration_Section_Key initializer_key, params_key, arg_key;
  ACE_TString holder;
  CORBA::ULong arg_count = 0;

  for (CORBA::ULong i = 0; i < count; ++i)
    {
      stringified = TAO_IFR_Service_Utils::int_to_string (i);
      this->repo_->config ()->open_section (initializers_key,
                                            stringified,
                                            0,
                                            initializer_key);
      this->repo_->config ()->get_string_value (initializer_key,
                                                "name",
                                                holder);
      retval[i].name = holder.fast_rep ();
      status =
        this->repo_->config ()->open_section (initializer_key,
                                              "params",
                                              0,
                                              params_key);

      if (status != 0)
        {
          retval[i].members.length (0);
          continue;
        }

      this->repo_->config ()->get_integer_value (params_key,
                                                 "count",
                                                 arg_count);
      retval[i].members.length (arg_count);
      CORBA::Object_var obj;

      for (CORBA::ULong j = 0; j < arg_count; ++j)
        {
          stringified = TAO_IFR_Service_Utils::int_to_string (j);
          this->repo_->config ()->open_section (params_key,
                                                stringified,
                                                0,
                                                arg_key);
          this->repo_->config ()->get_string_value (arg_key,
                                                    "arg_name",
                                                    holder);
          retval[i].members[j].name = holder.fast_rep ();
          this->repo_->config ()->get_string_value (arg_key,
                                                    "arg_path",
                                                    holder);
          TAO_IDLType_i *impl =
            TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                    this->repo_);
          retval[i].members[j].type =
            impl->type_i ();

          obj =
            TAO_IFR_Service_Utils::path_to_ir_object (holder,
                                                      this->repo_);

          retval[i].members[j].type_def =
            CORBA::IDLType::_narrow (obj.in ());
        }

      this->fill_exceptions (retval[i].exceptions,
                             initializer_key,
                             "excepts");
    }

  return retval._retn ();
}
Example #17
0
/*
 * The set of readers and the writer will operate in a staggered sequence
 * of acquiring and releasing the lock. The sequence is designed to exercise
 * waiting behavior of both readers and writer, as well as allowing multiple
 * readers in, without getting tripped up by any differences in ordering
 * on different platforms which may favor writers, or vice-versa.
 * In this timeline, time on seconds is on the left, time holding the lock
 * is solid, time waiting is dots, acquire/release point is a dash, and
 * time without the lock is blank.
 *
 *   TIME        WRITER    READER1    READER2    READER3
 *     0            |
 *                  |
 *     1            |         .
 *                  |         .
 *     2            -         -          -
 *                            |          |
 *     3                      |          |          -
 *                            |          |          |
 *     4                      -          |          |
 *                                       |          |
 *     5                                 -          |
 *                                                  |
 *     6            -                               -
 *                  |
 *     7            |         .          .          .
 *                  |         .          .          .
 *     8            -         -          -          -
 *                            |          |          |
 *     9                      |          |          |
 *
 * A file is used to test the sequencing. When the writer first gets the
 * lock, it will ensure the file is not present. At the end of its time
 * holding the lock the first time, it will write a "writer 1" string to
 * the file. When it gets the lock the second time, it will write a
 * different string to the file, and just before releasing the second time
 * write a "writer 2" string to the file. The readers all check to be sure
 * that the file is present and says "writer 1" at the start and end of
 * their periods of holding the reader lock and, similarly, check for
 * "writer 2" the second time they hold the lock.
 */
static void
reader (int num)
{
  // Let the writer get there first.
  ACE_OS::sleep (1);

  ACE_SOCK_Dgram sock;
  ACE_INET_Addr parent;
  parent.set (reporting_port, ACE_LOCALHOST, 1, AF_INET);
  ACE_TCHAR me_str[80];
  parent.addr_to_string (me_str, 80);
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Sending reports to %s\n"), me_str));

  if (sock.open (ACE_Addr::sap_any, PF_INET) == -1)
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("UDP open")));

  Range_Report report;
  report.child_ = num;
  ACE_Time_Value start (ACE_Time_Value::zero), stop (ACE_Time_Value::zero);

  ACE_RW_Process_Mutex mutex (mutex_name.c_str ());

  // Make sure the constructor succeeded
  if (ACE_LOG_MSG->op_status () != 0)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Reader %d, mutex %s %p\n"),
                  num,
                  mutex_name.c_str (),
                  ACE_TEXT ("ctor")));
      return;
    }

  ACE_OS::sleep (num);
  // Grab the lock
  if (-1 == mutex.acquire_read ())
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Reader %d %p\n"),
                num,
                ACE_TEXT ("first acquire_read")));
  else
    {
      start = ACE_OS::gettimeofday ();
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("Reader %d acquired first time\n"),
                  num));
    }

  // Wait a bit, then release and report the range held.
  ACE_OS::sleep (num);

  // Release the lock then wait; in the interim, the writer should change
  // the file.
  stop = ACE_OS::gettimeofday ();
  if (-1 == mutex.release ())
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Reader %d %p\n"),
                num,
                ACE_TEXT ("first release")));
  else
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Reader %d released first time\n"), num));
  report.range_.set (start, stop);
  ssize_t bytes = sock.send (&report, sizeof (report), parent);
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Reader %d sent %b byte report\n"),
              num,
              bytes));

  ACE_OS::sleep (4 - num);
  start = stop = ACE_Time_Value::zero;
  if (-1 == mutex.acquire_read ())
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Reader %d %p\n"),
                num,
                ACE_TEXT ("second acquire_read")));
  else
    {
      start = ACE_OS::gettimeofday ();
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("Reader %d acquired second time\n"),
                  num));
    }

  // Done; small delay, release, report, and return.
  ACE_OS::sleep (1);
  stop = ACE_OS::gettimeofday ();
  if (-1 == mutex.release ())
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Reader %d %p\n"),
                num,
                ACE_TEXT ("second release")));
  else
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Reader %d released second time; done\n"),
                num));
  report.range_.set (start, stop);
  bytes = sock.send (&report, sizeof (report), parent);
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Reader %d sent %b byte report\n"),
              num,
              bytes));
  sock.close ();
  return;
}
Example #18
0
void
TAO_Port_Desc_Seq_Utils<T_desc_seq>::port_descriptions (
    T_desc_seq &desc_seq,
    ACE_Configuration *config,
    ACE_Configuration_Section_Key &key,
    const char *sub_section
  )
{
  ACE_Configuration_Section_Key sub_key;
  int status = config->open_section (key,
                                     sub_section,
                                     0,
                                     sub_key);

  if (status != 0)
    {
      desc_seq.length (0);
      return;
    }

  CORBA::ULong count = 0;
  config->get_integer_value (sub_key,
                             "count",
                             count);
  desc_seq.length (count);
  ACE_Configuration_Section_Key desc_key;
  char *stringified = 0;
  ACE_TString holder;

  for (CORBA::ULong i = 0; i < count; ++i)
    {
      stringified = TAO_IFR_Service_Utils::int_to_string (i);
      config->open_section (sub_key,
                            stringified,
                            0,
                            desc_key);

      config->get_string_value (desc_key,
                                "name",
                                holder);
      desc_seq[i].name = holder.c_str ();

      config->get_string_value (desc_key,
                                "id",
                                holder);
      desc_seq[i].id = holder.c_str ();

      /// Seems to me that this field should refer to the component
      /// where the port is defined - NOT where the base type is defined.
      config->get_string_value (key,
                                "id",
                                holder);
      desc_seq[i].defined_in = holder.c_str ();

      config->get_string_value (desc_key,
                                "version",
                                holder);
      desc_seq[i].version = holder.c_str ();

      config->get_string_value (desc_key,
                                "base_type",
                                holder);
      TAO_Port_Desc_Seq_Utils<T_desc_seq>::port_base_type (desc_seq,
                                                           holder,
                                                           i);

      TAO_Port_Desc_Seq_Utils<T_desc_seq>::get_is_multiple (desc_seq,
                                                            config,
                                                            desc_key,
                                                            i);
    }
}
Example #19
0
int
run_main (int argc, ACE_TCHAR *argv[])
{
  parse_args (argc, argv);

  // Child process code.
  if (child_nr >= 0)
    {
      ACE_TCHAR lognm[MAXPATHLEN];
      int mypid (ACE_OS::getpid ());
      ACE_OS::sprintf(lognm,
                      ACE_TEXT ("RW_Process_Mutex_Test-child-%d"),
                      (int)mypid);
      ACE_START_TEST (lognm);
      if (child_nr == 0)
        writer ();
      else
        reader (child_nr);
      ACE_END_LOG;
    }
  else
    {
      ACE_START_TEST (ACE_TEXT ("RW_Process_Mutex_Test"));
      // Although it should be safe for each process to construct and
      // destruct the rw lock, this can disturb other process still
      // using the lock. This is not really correct, and should be
      // looked at, but it gets things moving.
      // Also see Process_Mutex_Test.cpp for similar issue.
      ACE_RW_Process_Mutex mutex (mutex_name.c_str ());
      // Make sure the constructor succeeded
      if (ACE_LOG_MSG->op_status () != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Parent, mutex %s %p\n"),
                      mutex_name.c_str (),
                      ACE_TEXT ("ctor")));
        }
#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
      static const ACE_TCHAR* format = ACE_TEXT ("%ls -c %d -p %u -n %ls");
#else
      static const ACE_TCHAR* format = ACE_TEXT ("%s -c %d -p %u -n %s");
#endif /* !ACE_WIN32 && ACE_USES_WCHAR */

      // The parent process reads time ranges sent from the children via
      // UDP. Grab an unused UDP port to tell the children to send to.
      ACE_INET_Addr me;
      ACE_SOCK_Dgram sock;
      if (sock.open (ACE_Addr::sap_any, PF_INET) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Socket %p\n"),
                           ACE_TEXT ("open")),
                          -1);
      sock.get_local_addr (me);
      ACE_TCHAR me_str[80];
      me.addr_to_string (me_str, 80);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Receiving on %s\n"), me_str));

      // Spawn 1 writer and 3 reader processes that will contend for the
      // lock.
      Child writer;
      Child readers[Nr_Processes - 1];
      int i;

      for (i = 0; i < Nr_Processes; i++)
        {
          Child *child = (i == 0 ? &writer : &readers[i-1]);
          ACE_Process_Options options;
          options.command_line (format,
                                argc > 0 ? argv[0] : ACE_TEXT ("RW_Process_Mutex_Test"),
                                i,
                                (unsigned int)me.get_port_number (),
                                mutex_name.c_str ());
          if (child->spawn (options) == -1)
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 ACE_TEXT ("spawn of child %d %p\n"),
                                 i,
                                 ACE_TEXT ("failed")),
                                -1);
            }
          else
            {
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("Child process %d has pid = %d.\n"),
                          i,
                          (int)(child->getpid ())));
            }
        }

      // Keep reading time ranges reported from the children until all the
      // children have exited. Alternate between checking for a range and
      // checking for exits.
      int processes = Nr_Processes;
      Child *children[Nr_Processes];
      for (i = 0; i < Nr_Processes; i++)
        children[i] = (i == 0 ? &writer : &readers[i-1]);

      Range_Report report;
      ACE_Time_Value poll (0);
      ACE_INET_Addr from;
      ssize_t bytes;
      while (processes > 0)
        {
          ACE_Time_Value limit (10);
          bytes = sock.recv (&report, sizeof (report), from, 0, &limit);
          if (bytes > 0)
            {
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("Report from child %d; %b bytes\n"),
                          report.child_, bytes));
              if (report.child_ == 0)
                writer.add_range (report.range_);
              else
                {
                  if (report.child_ >= 1 && report.child_ < Nr_Processes)
                    readers[report.child_ - 1].add_range (report.range_);
                  else
                    ACE_ERROR ((LM_ERROR,
                                ACE_TEXT ("Report from out-of-range child #%d\n"),
                                report.child_));
                }
            }
          else
            {
              if (errno == ETIME)
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("UDP time out; check child exits\n")));
              else
                ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("UDP recv")));
            }

          for (i = 0; i < Nr_Processes; i++)
            {
              if (children[i] == 0)
                continue;
              ACE_exitcode child_status;
              // See if the child has exited.
              int wait_result = children[i]->wait (poll, &child_status);
              if (wait_result == -1)
                ACE_ERROR ((LM_ERROR, ACE_TEXT ("Wait for child %d, %p\n"),
                            i, ACE_TEXT ("error")));
              else if (wait_result != 0)
                {
                  if (child_status == 0)
                    ACE_DEBUG ((LM_DEBUG,
                                ACE_TEXT ("Child %d finished ok\n"),
                                (int)(children[i]->getpid ())));
                  else
                    ACE_ERROR ((LM_ERROR,
                                ACE_TEXT ("Child %d finished with status %d\n"),
                                (int)(children[i]->getpid ()), child_status));
                  children[i] = 0;
                  --processes;
                }
            }
        }

      sock.close ();

      if (0 != mutex.remove ())
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("mutex remove")));

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Comparing time ranges...\n")));
      // The writer should never overlap any readers
      bool writer_overlap = false;
      for (i = 0; i < Nr_Processes - 1; ++i)
        {
          if (writer.any_overlaps (readers[i]))
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("Writer overlaps reader %d\n"),
                          i+1));
              writer_overlap = true;
            }
        }
      if (!writer_overlap)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("Writer does not overlap with readers; Ok\n")));

      // And there should be some overlap between readers.
      bool reader_overlap = false;
      for (i = 0; i < Nr_Processes - 1; ++i)
        {
          // Just compare to those higher, else it compares the same ones,
          // only in reverse.
          for (int j = i + 1; j < Nr_Processes - 1; ++j)
            {
              if (readers[i].any_overlaps (readers[j]))
                {
                  ACE_DEBUG ((LM_DEBUG,
                              ACE_TEXT ("Reader %d overlaps reader %d; Ok\n"),
                              i + 1, j + 1));
                  reader_overlap = true;
                }
            }
        }
      if (!reader_overlap)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("No readers overlapped!\n")));

      ACE_END_TEST;
    }

  return 0;
}
Example #20
0
int32 Config::GetIntDefault(const char* name, int32 def)
{
    ACE_TString val;
    return GetValueHelper(mConf, name, val) ? atoi(val.c_str()) : def;
}
Example #21
0
void
ACE_DLL_Handle::get_dll_names (const ACE_TCHAR *dll_name,
                               ACE_Array<ACE_TString> &try_names)
{
  // Build the array of DLL names to try on this platform by applying the
  // proper prefixes and/or suffixes to the specified dll_name.
  ACE_TString base (dll_name);
  ACE_TString base_dir, base_file, base_suffix;

  // 1. Separate the dll_name into the dir part and the file part. We
  // only decorate the file part to determine the names to try loading.
  ACE_TString::size_type pos = base.rfind (ACE_DIRECTORY_SEPARATOR_CHAR);
  if (pos != ACE_TString::npos)
    {
      base_dir = base.substr (0, pos + 1);
      base_file = base.substr (pos + 1);
    }
  else
    base_file = base;

  // 2. Locate the file suffix, if there is one. Move the '.' and the
  // suffix to base_suffix.
  if ((pos = base_file.rfind (ACE_TEXT ('.'))) != ACE_TString::npos)
    {
      base_suffix = base_file.substr (pos);
      base_file = base_file.substr (0, pos);
    }

  // 3. Build the combinations to try for this platform.
  // Try these combinations:
  //   - name with platform's dll prefix (if it has one) and suffix
  //   - name with platform's dll prefix, decorator, and suffix.
  //   - name with decorator and platform's suffix appended (if not supplied)
  //   - name with platform's suffix appended (if not supplied)
  //   - name as originally given
  // We first try to find the file using the decorator so that when a
  // filename with and without decorator is used, we get the file with
  // the same decorator as the ACE dll has and then as last resort
  // the one without. For example with msvc, the debug build has a "d"
  // decorator, but the release build has none and we really want to get
  // the debug version of the library in a debug application instead
  // of the release one.
  // So we need room for 5 entries in try_names.
  try_names.size (0);
  if ((try_names.max_size () - try_names.size ()) < 5)
    try_names.max_size (try_names.max_size () + 5);
#if defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
  ACE_TString decorator (ACE_LD_DECORATOR_STR);
#endif
  ACE_TString suffix (ACE_DLL_SUFFIX);
  ACE_TString prefix (ACE_DLL_PREFIX);

  for (size_t i = 0; i < 5 && try_names.size () < try_names.max_size (); ++i)
    {
      ACE_TString try_this;
      size_t const j = try_names.size ();
      switch (i)
        {
        case 0:        // Prefix + name + decorator + suffix
        case 1:        // Prefix + name + suffix
        case 2:        // Name + decorator + suffix
        case 3:        // Name + suffix
          if (
              base_suffix.length () > 0
#if !(defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK))
              || (i == 1 || i == 3)    // No decorator desired; skip
#endif
              )
            break;
          try_this = base_dir;
          if (i < 2)
            try_this += prefix;
          try_this += base_file;
          if (base_suffix.length () > 0)
            try_this += base_suffix;
          else
            {
#if defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
              try_this += decorator;
#endif
              try_this += suffix;
            }
          break;
        case 4:
          try_this = dll_name;
          break;
        }

      if (try_this.length ())
        {
          try_names.size (j + 1);
          try_names.set (try_this, j);
        }
    }
  return;
}
Example #22
0
std::string Config::GetStringDefault(const char* name, const char* def)
{
    ACE_TString val;
    return GetValueHelper(mConf, name, val) ? val.c_str() : def;
}
Example #23
0
int
run_main (int argc, ACE_TCHAR *argv[])
{
  int retval = 0;
  MCT_Config config;
  retval = config.open (argc, argv);
  if (retval != 0)
    return 1;

  const ACE_TCHAR *temp = ACE_TEXT ("Multicast_Test_IPV6");
  ACE_TString test = temp;

  u_long role = config.role ();
  if (ACE_BIT_DISABLED (role, MCT_Config::PRODUCER)
      || ACE_BIT_DISABLED (role, MCT_Config::CONSUMER))
    {
      if (ACE_BIT_ENABLED (role, MCT_Config::PRODUCER))
        test += ACE_TEXT ("-PRODUCER");
      else
        test += ACE_TEXT ("-CONSUMER");
    }

  // Start test only if options are valid.
  ACE_START_TEST (test.c_str ());

#if defined (ACE_HAS_IPV6)

# if !defined (ACE_LACKS_UNIX_SIGNALS)
  // Register a signal handler to close down application gracefully.
  ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT);
# endif

  // Dump the configuration info to the log if caller passed debug option.
  if (config.debug ())
    config.dump ();

  ACE_Reactor *reactor = ACE_Reactor::instance ();

  MCT_Task *task = new MCT_Task (config, reactor);

  if (ACE_BIT_ENABLED (role, MCT_Config::CONSUMER))
    {
      ACE_DEBUG ((LM_INFO, ACE_TEXT ("Starting consumer...\n")));
      // Open makes it an active object.
      retval += task->open ();
    }

  // now produce the datagrams...
  if (ACE_BIT_ENABLED (role, MCT_Config::PRODUCER))
    retval += producer (config);

  if (ACE_BIT_ENABLED (role, MCT_Config::CONSUMER))
    {
      // and wait for everything to finish
      ACE_DEBUG ((LM_INFO,
                  ACE_TEXT ("start waiting for consumer to finish...\n")));
      // Wait for the threads to exit.
      // But, wait for a limited time since we could hang if the last udp
      // message isn't received.
      ACE_Time_Value max_wait ( config.wait ()/* seconds */);
      ACE_Time_Value wait_time (ACE_OS::gettimeofday () + max_wait);
      ACE_Time_Value *ptime = ACE_BIT_ENABLED (role, MCT_Config::PRODUCER)
                                ? &wait_time : 0;
      if (ACE_Thread_Manager::instance ()->wait (ptime) == -1)
        {
          if (errno == ETIME)
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("maximum wait time of %d msec exceeded\n"),
                        max_wait.msec ()));
          else
            ACE_OS::perror (ACE_TEXT ("wait"));

          ++error;
        }
    }

  delete task;
#endif /* ACE_HAS_IPV6 */
  ACE_END_TEST;
  return (retval == 0 && error == 0) ? 0 : 1;
}
Example #24
0
int KSGConfig::loadConfig(const std::string& file_name)
{
	ACE_Configuration_Heap config;
	if(config.open() == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	ACE_Ini_ImpExp config_importer(config);

	if(config_importer.import_config(file_name.c_str()) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}

	ACE_Configuration_Section_Key section;
	if(config.open_section(config.root_section(),ACE_TEXT(KSG_COMMON_SECT)
		,0,section) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	
	ACE_TString v;

	if(config.get_string_value(section,ACE_TEXT(KSG_MAJOR_VER),v) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	_majorVer = ACE_OS::atoi(v.c_str());
	if(config.get_string_value(section,KSG_MINOR_VER,v) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	_minorVer = ACE_OS::atoi(v.c_str());

	if(config.open_section(config.root_section(),ACE_TEXT(KSG_SERVER_SECT)
		,0,section) == -1 )
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);

	
	if(config.get_string_value(section,KSG_SVR_IP,v) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	_drtpSvrIP = v.c_str();
	if(config.get_string_value(section,KSG_SVR_PORT,v) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	_drtpSvrPort = ACE_OS::atoi(v.c_str());
	if(config.get_string_value(section,KSG_SVR_BRANCE_NO,v) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	_drtpNo = ACE_OS::atoi(v.c_str());
	if(config.get_string_value(section,KSG_SVR_MAINFUNC,v) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	_drtpMainFunc = ACE_OS::atoi(v.c_str());
	if(config.get_string_value(section,KSG_SVR_POOL_CONN,v) == -1)
		_drtpPoolMaxCnt = 5;
	else
		_drtpPoolMaxCnt = ACE_OS::atoi(v.c_str());
	if(_drtpPoolMaxCnt < 0)
		_drtpPoolMaxCnt = 5;
	if(_drtpPoolMaxCnt > 30)
		_drtpPoolMaxCnt = 30;

	if(config.open_section(config.root_section(),ACE_TEXT(KSG_GATEWAY_SECT)
		,0,section) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);

	if(config.get_string_value(section,KSG_GW_IP,v) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	_localIP = v.c_str();

	if(config.open_section(config.root_section(),ACE_TEXT(KSG_SCHEDULER_SECT)
		,0,section) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);

	_runTaskIds = "";
	if(config.get_string_value(section,KSG_SCHD_IDS,v) != -1)
	{
		_runTaskIds = v.c_str();
	}

	_listenerIds = "";
	if(config.get_string_value(section,KSG_LISTENER_IDS,v) != -1)
	{
		_listenerIds = v.c_str();
	}

	if(config.open_section(config.root_section(),ACE_TEXT(KSG_LOG_SECT)
		,0,section) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取日志配置失败")),-1);
	if(config.get_string_value(section,KSG_LOG_LEVEL,v)!=-1)
	{
		_logLevel = v.c_str();
	}
	if(config.get_string_value(section,KSG_LOG_APPENDER,v)!=-1)
	{
		_logOutput = v.c_str();
	}
	if(config.get_string_value(section,KSG_LOG_FILE,v)!=-1)
	{
		_logFilePath = v.c_str();
	}
	
	if(config.get_string_value(section,KSG_LOG_FILEMAX,v) != -1)
	{
		_log_max_file_size = ACE_OS::atoi(v.c_str());
		if(_log_max_file_size == 0)
			_log_max_file_size = 1024;
		_log_max_file_size *= 1024;
		if(_log_max_file_size <= 0)
			_log_max_file_size = 1024 * 1024;
	}
	if(config.get_string_value(section,KSG_LOG_MAX_COUNT,v) !=-1)
	{
		_log_max_backup = ACE_OS::atoi(v.c_str());
		if(_log_max_backup == 0)
			_log_max_backup = 1;
	}
	return 0;
}
Example #25
0
int init_tranport ()
{
  int status = 0;

  if (sub_using_udp)
    {
      reader_transport_impl
        = TheTransportFactory->create_transport_impl (SUB_TRAFFIC,
                                                      ACE_TEXT("udp"),
                                                      OpenDDS::DCPS::DONT_AUTO_CONFIG);

      OpenDDS::DCPS::TransportConfiguration_rch reader_config
        = TheTransportFactory->create_configuration (SUB_TRAFFIC, ACE_TEXT("udp"));

      OpenDDS::DCPS::UdpConfiguration* reader_udp_config
        = static_cast <OpenDDS::DCPS::UdpConfiguration*> (reader_config.in ());

      if (!reader_address_given)
        {
          ACE_ERROR((LM_ERROR,
                    ACE_TEXT("(%P|%t) init_transport: sub UDP")
                    ACE_TEXT(" Must specify an address for UDP.\n")));
          return 11;
        }


      ACE_INET_Addr reader_address (reader_address_str.c_str ());
      reader_udp_config->local_address_ = reader_address;

      if (reader_transport_impl->configure(reader_config.in()) != 0)
        {
          ACE_ERROR((LM_ERROR,
                    ACE_TEXT("(%P|%t) init_transport: sub UDP")
                    ACE_TEXT(" Failed to configure the transport.\n")));
          status = 1;
        }
    }
  else
    {
      reader_transport_impl
        = TheTransportFactory->create_transport_impl (SUB_TRAFFIC,
                                                      ACE_TEXT("SimpleTcp"),
                                                      OpenDDS::DCPS::DONT_AUTO_CONFIG);

      OpenDDS::DCPS::TransportConfiguration_rch reader_config
        = TheTransportFactory->create_configuration (SUB_TRAFFIC, ACE_TEXT("SimpleTcp"));

      OpenDDS::DCPS::SimpleTcpConfiguration* reader_tcp_config
        = static_cast <OpenDDS::DCPS::SimpleTcpConfiguration*> (reader_config.in ());

      if (reader_address_given)
        {
          ACE_INET_Addr reader_address (reader_address_str.c_str ());
          reader_tcp_config->local_address_ = reader_address;
          reader_tcp_config->local_address_str_ = reader_address_str;
        }
        // else use default address - OS assigned.

      if (reader_transport_impl->configure(reader_config.in()) != 0)
        {
          ACE_ERROR((LM_ERROR,
                    ACE_TEXT("(%P|%t) init_transport: sub TCP ")
                    ACE_TEXT(" Failed to configure the transport.\n")));
          status = 1;
        }
    }

  if (pub_using_udp)
    {
      writer_transport_impl
         = TheTransportFactory->create_transport_impl (PUB_TRAFFIC,
                                                       ACE_TEXT("udp"),
                                                       OpenDDS::DCPS::DONT_AUTO_CONFIG);

      OpenDDS::DCPS::TransportConfiguration_rch writer_config
        = TheTransportFactory->create_configuration (PUB_TRAFFIC, ACE_TEXT("udp"));

      OpenDDS::DCPS::UdpConfiguration* writer_udp_config
        = static_cast <OpenDDS::DCPS::UdpConfiguration*> (writer_config.in ());

      if (!writer_address_given)
        {
          ACE_ERROR((LM_ERROR,
                    ACE_TEXT("(%P|%t) init_transport: pub UDP")
                    ACE_TEXT(" Must specify an address for UDP.\n")));
          return 12;
        }

      ACE_INET_Addr writer_address (writer_address_str.c_str ());
      writer_udp_config->local_address_ = writer_address;

      if (writer_transport_impl->configure(writer_config.in()) != 0)
        {
          ACE_ERROR((LM_ERROR,
                    ACE_TEXT("(%P|%t) init_transport: sub UDP")
                    ACE_TEXT(" Failed to configure the transport.\n")));
          status = 1;
        }
    }
  else
    {
      writer_transport_impl
        = TheTransportFactory->create_transport_impl (PUB_TRAFFIC,
                                                      ACE_TEXT("SimpleTcp"),
                                                      OpenDDS::DCPS::DONT_AUTO_CONFIG);
      OpenDDS::DCPS::TransportConfiguration_rch writer_config
        = TheTransportFactory->create_configuration (PUB_TRAFFIC, ACE_TEXT("SimpleTcp"));

      OpenDDS::DCPS::SimpleTcpConfiguration* writer_tcp_config
        = static_cast <OpenDDS::DCPS::SimpleTcpConfiguration*> (writer_config.in ());

      if (writer_address_given)
        {
          ACE_INET_Addr writer_address (writer_address_str.c_str());
          writer_tcp_config->local_address_ = writer_address;
          writer_tcp_config->local_address_str_ = writer_address_str;
        }
        // else use default address - OS assigned.

      if (writer_transport_impl->configure(writer_config.in()) != 0)
        {
          ACE_ERROR((LM_ERROR,
                    ACE_TEXT("(%P|%t) init_transport: sub TCP")
                    ACE_TEXT(" Failed to configure the transport.\n")));
          status = 1;
        }
    }

  return status;
}
Example #26
0
    int ExtractProperties(const ACE_TString& input, mstrings_t& properties)
    {
        TTASSERT(input.find('\n') == input.rfind('\n'));

        bool bSyntaxError = false;
        if( input.length() == 0 )
            bSyntaxError = true;

        size_t offset = input.find(' ');//past command
        if(offset == ACE_TString::npos)
            return 0;

        while(offset < input.length() && !bSyntaxError)
        {
            //past any spaces
            offset = pastBlanks(offset, input);
            if(offset == input.length())
            {
                break;
            }

            size_t propBegin = offset;
            ACE_TString prop;
            ACE_TString value;
            while(offset < input.length()) //extract property name
            {
                if( input[offset] != ' ' && input[offset] != '=') offset ++;
                else break;
            }
            if(offset == input.length())
            {
                bSyntaxError = true; //no properties in ACE_TString
                break;
            }

            prop = input.substr(propBegin, offset-propBegin); //set propertyname
            TTASSERT(properties.find(prop) == properties.end());
            offset = pastBlanks(offset, input); //past spaces
            if(offset == input.length())
            {
                bSyntaxError = true;
                break;
            }
            if(input[offset] != '=')
            {
                bSyntaxError = true;
                break;
            }
            else offset ++; //past =

            offset = pastBlanks(offset, input); //past spaces
            if(offset == input.length())
            {
                bSyntaxError = true;
                break;
            }

            //determine whether it's a string or an integer
            if(input[offset] == '"') //a ACE_TString
            {
                bool found = false;
                size_t strBegin = ++offset; //past "
                while(!found && offset<input.length())
                {
                    /*
                    if(input[offset]==ACE_TEXT('\"') && input[offset-1] != ACE_TEXT('\\')) found = true;
                    offset++;
                    */
                    if(input[offset] == '\\')
                        offset += 2;
                    else if(input[offset] == '"')
                    {
                        found = true;
                        offset++;
                    }
                    else
                        offset++;
                }

                if(!found)
                {
                    bSyntaxError = true;
                    break;
                }

                value = input.substr(strBegin, offset-strBegin-1);
                offset ++; //past \"

                properties[prop] = RebuildString(value);
                //properties.SetAt(prop, RebuildString(value));
            }
            else if(input[offset] == '[') // an int list
            {
                bool found = false;
                size_t listBegin = ++offset; //past "
                while(!found && offset<input.length())
                {
                    if(input[offset] == ']') found = true;
                    offset++;
                }

                if(!found)
                {
                    bSyntaxError = true;
                    break;
                }

                value = input.substr(listBegin, offset-listBegin-1);
                offset ++; //past ]

                properties[prop] = RebuildString(value);
                //properties.SetAt(prop, RebuildString(value));
            }
            else //eat what's left until space
            {
                size_t intBegin = offset;
                while(offset<input.length() && 
                    input[offset] != ' ' && 
                    input[offset] != '\r' &&
                    input[offset] != '\n') offset ++; //past spaces
                value = input.substr(intBegin, offset-intBegin);

                properties[prop] = RebuildString(value);
                //properties.SetAt(prop, RebuildString(value));
            }
        }

        return bSyntaxError? -1 : (int)properties.size();
    }