Ejemplo n.º 1
0
CORBA::Boolean
CORBA::ValueBase::_tao_unmarshal_codebase_url_indirection (TAO_InputCDR &strm,
                                                           ACE_CString& codebase_url)
{
  CORBA::Long offset = 0;
  if (!strm.read_long (offset) ||  offset >= 0)
  {
    return false;
  }

  void* pos = strm.rd_ptr () + offset - sizeof (CORBA::Long);

  if (strm.get_codebase_url_map()->get()->find (pos, codebase_url) != 0)
    {
      throw CORBA::INTERNAL ();
    }
  else if (TAO_debug_level)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
        ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_unmarshal_codebase_url_indirection, found %x=%C\n"),
        pos, codebase_url.c_str ()));
    }

  return 1;
}
Ejemplo n.º 2
0
void
TAO_ConstantDef_i::value_i (const CORBA::Any &value)
{
  CORBA::TypeCode_var my_tc =
    this->type_i ();

  CORBA::TypeCode_var val_tc = value.type ();

  CORBA::Boolean const equal_tc =
    my_tc.in ()->equal (val_tc.in ());

  if (!equal_tc)
    {
      return;
    }

  ACE_Message_Block *mb = 0;
  TAO::Any_Impl *impl = value.impl ();

  if (impl->encoded ())
    {
      TAO::Unknown_IDL_Type *unk =
        dynamic_cast<TAO::Unknown_IDL_Type *> (impl);

      mb = unk->_tao_get_cdr ().steal_contents ();
    }
  else
    {
      TAO_OutputCDR out;
      impl->marshal_value (out);
      TAO_InputCDR in (out);
      mb = in.steal_contents ();
    }
  ACE_Auto_Ptr<ACE_Message_Block> safe (mb);

  CORBA::TCKind kind = val_tc->kind ();

  switch (kind)
  {
    // The data for these types will be aligned to an 8-byte
    // boundary, while the rd_ptr may not.
    case CORBA::tk_double:
    case CORBA::tk_ulonglong:
    case CORBA::tk_longlong:
    case CORBA::tk_longdouble:
      mb->rd_ptr (ACE_ptr_align_binary (mb->rd_ptr (),
                                        ACE_CDR::MAX_ALIGNMENT));
      break;
    default:
      break;
  }

  mb->crunch ();
  this->repo_->config ()->set_binary_value (this->section_key_,
                                            "value",
                                            mb->base (),
                                            mb->length ());
}
Ejemplo n.º 3
0
void
Test::AMI_ControllerHandler::worker_finished_reply_stub (
  TAO_InputCDR &_tao_in,
  ::Messaging::ReplyHandler_ptr _tao_reply_handler,
  ::CORBA::ULong reply_status)
{
  // Retrieve Reply Handler object.
  Test::AMI_ControllerHandler_var _tao_reply_handler_object =
    Test::AMI_ControllerHandler::_narrow (_tao_reply_handler);

  // Exception handling
  switch (reply_status)
  {
    case TAO_AMI_REPLY_OK:
    {
      // Demarshall all the arguments.
      // Invoke the call back method.
      _tao_reply_handler_object->worker_finished (

        );
      break;
    }
    case TAO_AMI_REPLY_USER_EXCEPTION:
    case TAO_AMI_REPLY_SYSTEM_EXCEPTION:
    {
      const ACE_Message_Block* cdr = _tao_in.start ();
      ::CORBA::OctetSeq _tao_marshaled_exception (
          static_cast <CORBA::ULong> (cdr->length ()),
          static_cast <CORBA::ULong> (cdr->length ()),
          reinterpret_cast <unsigned char*> (cdr->rd_ptr ()),
          0
        );
      ::Messaging::ExceptionHolder* exception_holder_ptr = 0;
      ACE_NEW (
          exception_holder_ptr,
          ::TAO::ExceptionHolder (
            (reply_status == TAO_AMI_REPLY_SYSTEM_EXCEPTION),
            _tao_in.byte_order (),
            _tao_marshaled_exception,
            0,
            0,
            _tao_in.char_translator (),
            _tao_in.wchar_translator ())
          );

      ::Messaging::ExceptionHolder_var exception_holder_var = exception_holder_ptr;
      _tao_reply_handler_object->worker_finished_excep (
          exception_holder_var
        );
      break;
    }
    case TAO_AMI_REPLY_NOT_OK:
      // @@ Michael: Not even the spec mentions this case.
      //             We have to think about this case.
      break;
  }
}
Ejemplo n.º 4
0
bool
Routing_Slip::unmarshal (TAO_Notify_EventChannelFactory &ecf, TAO_InputCDR & cdr)
{
  CORBA::ULong count = 0;
  cdr.read_ulong (count);
  for (size_t nreq = 0; nreq < count; ++nreq)
  {
    ACE_CDR::Octet code = 0;
    while (cdr.read_octet(code))
    {
      try
      {
        if (code == TAO_Notify_Method_Request_Dispatch::persistence_code)
        {
          Delivery_Request * prequest;
          ACE_NEW_THROW_EX (
            prequest,
            Delivery_Request(this_ptr_, this->delivery_requests_.size ()),
            CORBA::NO_MEMORY ());
          Delivery_Request_Ptr request(prequest);
          TAO_Notify_Method_Request_Dispatch_Queueable * method =
            TAO_Notify_Method_Request_Dispatch::unmarshal (
              request,
              ecf,
              cdr);
          if (method != 0)
          {
            this->delivery_requests_.push_back (request);
            this->delivery_methods_.push_back (method);
          }
        }
        else if (code == TAO_Notify_Method_Request_Lookup::persistence_code)
        {
          Delivery_Request_Ptr request(new Delivery_Request(this_ptr_, this->delivery_requests_.size ()));
          TAO_Notify_Method_Request_Lookup_Queueable * method =
              TAO_Notify_Method_Request_Lookup::unmarshal (
                request,
                ecf,
                cdr);
          if (method != 0)
          {
            this->delivery_requests_.push_back (request);
            this->delivery_methods_.push_back (method);
          }
        }
      }
      catch (const CORBA::Exception&)
      {
        // @@todo should we log this?
        // just ignore failures
      }
    }
  }
  return this->delivery_requests_.size () > 0;
}
Ejemplo n.º 5
0
void
TAO::Unknown_IDL_Type::_tao_decode (TAO_InputCDR & cdr)
{
  // @@ (JP) The following code depends on the fact that
  //         TAO_InputCDR does not contain chained message blocks,
  //         otherwise <begin> and <end> could be part of
  //         different buffers!

  // This will be the start of a new message block.
  char const * const begin = cdr.rd_ptr ();

  // Skip over the next argument.
  TAO::traverse_status const status =
    TAO_Marshal_Object::perform_skip (this->type_, &cdr);

  if (status != TAO::TRAVERSE_CONTINUE)
    {
      throw ::CORBA::MARSHAL ();
    }

  // This will be the end of the new message block.
  char const * const end = cdr.rd_ptr ();

  // The ACE_CDR::mb_align() call can shift the rd_ptr by up to
  // ACE_CDR::MAX_ALIGNMENT - 1 bytes. Similarly, the offset adjustment
  // can move the rd_ptr by up to the same amount. We accommodate
  // this by including 2 * ACE_CDR::MAX_ALIGNMENT bytes of additional
  // space in the message block.
  size_t const size = end - begin;

  ACE_Message_Block new_mb (size + 2 * ACE_CDR::MAX_ALIGNMENT);

  ACE_CDR::mb_align (&new_mb);
  ptrdiff_t offset = ptrdiff_t (begin) % ACE_CDR::MAX_ALIGNMENT;

  if (offset < 0)
    {
      offset += ACE_CDR::MAX_ALIGNMENT;
    }

  new_mb.rd_ptr (offset);
  new_mb.wr_ptr (offset + size);

  ACE_OS::memcpy (new_mb.rd_ptr (), begin, size);

  this->cdr_.reset (&new_mb, cdr.byte_order ());
  this->cdr_.char_translator (cdr.char_translator ());
  this->cdr_.wchar_translator (cdr.wchar_translator ());

  this->cdr_.set_repo_id_map (cdr.get_repo_id_map ());
  this->cdr_.set_codebase_url_map (cdr.get_codebase_url_map ());
  this->cdr_.set_value_map (cdr.get_value_map ());

  // Take over the GIOP version, the input cdr can have a different
  // version then our current GIOP version.
  ACE_CDR::Octet major_version;
  ACE_CDR::Octet minor_version;
  cdr.get_version (major_version, minor_version);
  this->cdr_.set_version (major_version, minor_version);
}
Ejemplo n.º 6
0
  /*static*/ CORBA::Boolean
  PG_Utils::get_tagged_component (
      PortableGroup::ObjectGroup *&ior,
      PortableGroup::TagGroupTaggedComponent &tg)
  {
    if (ior->_stubobj () == 0)
      return 0;

    TAO_MProfile &mprofile =
      ior->_stubobj ()->base_profiles ();

    // Looking for a tagged component with a TAG_FT_GROUP flag.
    IOP::TaggedComponent tc;
    tc.tag = IOP::TAG_FT_GROUP;

    CORBA::ULong count =
      mprofile.profile_count ();

    for (CORBA::ULong i = 0;
         i < count;
         i++)
      {

        // Get the Tagged Components
        const TAO_Tagged_Components &pfile_tagged =
          mprofile.get_profile (i)->tagged_components ();

        // Look for the primary
        if (pfile_tagged.get_component (tc) == 1)
          {
            TAO_InputCDR cdr (reinterpret_cast<const char*> (tc.component_data.get_buffer ()),
                            tc.component_data.length ());

            CORBA::Boolean byte_order;

            cdr >> ACE_InputCDR::to_boolean (byte_order);

            if (!cdr.good_bit ())
              return 0;

            cdr.reset_byte_order (static_cast<int> (byte_order));

            cdr >> tg;

            if (cdr.good_bit ())
              return 1;
          }
      }
Ejemplo n.º 7
0
CORBA::Boolean
CORBA::ValueBase::_tao_read_repository_id_list (TAO_InputCDR& strm,
                                                Repository_Id_List& ids)
{
  CORBA::Long num_ids = 0;

  if (!strm.read_long (num_ids))
    {
      return 0;
    }

  if (num_ids == TAO_OBV_GIOP_Flags::Indirection_tag)
    {
      // Multiple repo id is not indirected.
      return 0;
    }
  else
    {
      for (CORBA::Long i = 0; i < num_ids; ++i)
        {
          ACE_CString id;
          if (!_tao_read_repository_id (strm, id))
            {
              return 0;
            }
          ids.push_back (id);
        }
    }

  return 1;
}
Ejemplo n.º 8
0
void
CORBA::SystemException::_tao_decode (TAO_InputCDR &cdr)
{
  // The string is read by the caller, to determine the exact type of
  // the exception.  We just decode the fields...
  // cdr.read_string (this->id ());
  CORBA::ULong tmp;

  if (cdr.read_ulong (this->minor_)
      && cdr.read_ulong (tmp))
    {
      this->completed_ = CORBA::CompletionStatus (tmp);
      return;
    }

  throw ::CORBA::MARSHAL ();
}
Ejemplo n.º 9
0
bool
TAO_Operation_Details::demarshal_args (TAO_InputCDR &cdr)
{
  try {
    for (CORBA::ULong i = 0; i != this->num_args_; ++i)
      {
        if (!((*this->args_[i]).demarshal (cdr)))
          return false;
      }

    cdr.reset_vt_indirect_maps ();
  }
  catch (...) {
    cdr.reset_vt_indirect_maps ();
    throw;
  }
  return true;
}
Ejemplo n.º 10
0
void
TAO_AMH_DSI_Response_Handler::gateway_exception_reply (
    CORBA::ULong reply_status,
    TAO_InputCDR &encap)
{
  // for this to be effective, ACE & TAO must be built with
  // ACE_ENABLE_SWAP_ON_WRITE defined in ace/config.h
  this->_tao_out.reset_byte_order(encap.byte_order());
  // This reply path handles only user exceptions.
  switch (reply_status)
    {
    //case TAO_PLUGGABLE_MESSAGE_USER_EXCEPTION:
    case TAO_AMI_REPLY_USER_EXCEPTION:
      this->reply_status_ = GIOP::USER_EXCEPTION;
      break;
    case TAO_AMI_REPLY_SYSTEM_EXCEPTION:
      this->reply_status_ = GIOP::SYSTEM_EXCEPTION;
      break;

    // we don't handle location forward at this moment.
    // need to be addressed later.
    //
    //case TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD:
    //  this->exception_type_ = TAO_GIOP_LOCATION_FORWARD;
    //  break;
    }
  try
  {
    this->_tao_rh_init_reply ();

  // We know nothing about this exception, so we marshal it as a block
  // of bytes. The outgoing stream's byte order has already been matched
  // to the original source of the reply.
    this->_tao_out.write_octet_array_mb (encap.start());
  // This will prevent the marshaling of any parameters into this reply.
  //  this->sent_gateway_exception_ = 1;
    this->_tao_rh_send_reply ();
  }
  catch (const CORBA::Exception &)
  {
    // TODO:
  }

}
Ejemplo n.º 11
0
CORBA::Boolean
CORBA::ValueBase::_tao_unmarshal_value_indirection_pre (TAO_InputCDR &strm,
                                                        TAO_InputCDR &indirected_strm)
{
  CORBA::Long offset = 0;
  if (!strm.read_long (offset) ||  offset >= 0)
    {
      return false;
    }

  size_t const buffer_size = -(offset) + sizeof (CORBA::Long);
  // Cribbed from tc_demarshal_indirection in Typecode_CDR_Extraction.cpp
  indirected_strm = TAO_InputCDR (strm.rd_ptr () + offset - sizeof (CORBA::Long),
    buffer_size,
    strm.byte_order ());

  indirected_strm.set_repo_id_map (strm.get_repo_id_map ());
  indirected_strm.set_codebase_url_map (strm.get_codebase_url_map ());
  indirected_strm.set_value_map (strm.get_value_map ());
  return indirected_strm.good_bit ();
}
Ejemplo n.º 12
0
CORBA::Boolean
TAO_DynEnum_i::equal (DynamicAny::DynAny_ptr rhs)
{
  CORBA::TypeCode_var tc = rhs->type ();

  CORBA::Boolean equivalent = tc->equivalent (this->type_.in ());

  if (!equivalent)
    {
      return false;
    }

  CORBA::Any_var any = rhs->to_any ();

  TAO::Any_Impl *impl = any->impl ();
  CORBA::ULong value;

  if (impl->encoded ())
    {
      TAO::Unknown_IDL_Type * const unk =
        dynamic_cast<TAO::Unknown_IDL_Type *> (impl);

      if (!unk)
        throw CORBA::INTERNAL ();

      // We don't want unk's rd_ptr to move, in case we are shared by
      // another Any, so we use this to copy the state, not the buffer.
      TAO_InputCDR for_reading (unk->_tao_get_cdr ());
      for_reading.read_ulong (value);
    }
  else
    {
      TAO_OutputCDR out;
      impl->marshal_value (out);
      TAO_InputCDR in (out);
      in.read_ulong (value);
    }

  return value == this->value_;
}
Ejemplo n.º 13
0
bool
Lorica::EvaluatorBase::evaluate_exception(const char *,
					  PortableServer::POA_ptr,
					  const char *ex_type,
					  TAO_InputCDR &incoming,
					  TAO_OutputCDR &encap ) const
{
	const ACE_Message_Block *buffer = incoming.start();
	encap << ex_type;
	encap.write_octet_array_mb (buffer);
	return true;

}
Ejemplo n.º 14
0
CORBA::Boolean
TAO_ChunkInfo::skip_chunks (TAO_InputCDR &strm)
{
  if (!this->chunking_)
    {
      return 1;
    }

  // This function is called after reading data of the truncated parent and
  // skips the remaining chunks until the outmost endtag (-1).
  // The tag read here is suppoused to be an endtag.
  CORBA::Long tag;
  if (!strm.read_long(tag))
    {
      return 0;
    }

  // end of the whole valuetype.
  if (tag == -1)
    {
      return 1;
    }
  else if (tag < 0)
    {
      // continue skip the chunk.
      return this->skip_chunks (strm);
    }
  else if (tag < TAO_OBV_GIOP_Flags::Value_tag_base)
    {
      // Read the chunk size and move forward to skip the data.
      ACE_Message_Block* current =
        const_cast<ACE_Message_Block*>(strm.start ());
      current->rd_ptr (tag);
      return this->skip_chunks (strm);
    }
  else
    return 0;
}
Ejemplo n.º 15
0
void
TAO_DynEnum_i::init (const CORBA::Any &any)
{
  CORBA::TypeCode_var tc = any.type ();
  CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ());

  if (kind != CORBA::tk_enum)
    {
      throw DynamicAny::DynAnyFactory::InconsistentTypeCode ();
    }

  this->type_ = tc;

  TAO::Any_Impl *impl = any.impl ();

  if (impl->encoded ())
    {
      TAO::Unknown_IDL_Type * const unk =
        dynamic_cast<TAO::Unknown_IDL_Type *> (impl);

      if (!unk)
        throw CORBA::INTERNAL ();

      // We don't want unk's rd_ptr to move, in case we are shared by
      // another Any, so we use this to copy the state, not the buffer.
      TAO_InputCDR for_reading (unk->_tao_get_cdr ());
      for_reading.read_ulong (this->value_);
    }
  else
    {
      TAO_OutputCDR out;
      impl->marshal_value (out);
      TAO_InputCDR in (out);
      in.read_ulong (this->value_);
    }

  this->init_common ();
}
Ejemplo n.º 16
0
static int
test_read (TAO_InputCDR &cdr, int n)
{
  CORBA::Long xl;

  for (int i = 0; i < n; ++i)
    {
      if (cdr.read_long (xl) == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "read_long[%d] failed\n",
                           i),
                          1);
    }

  return 0;
}
Ejemplo n.º 17
0
void
CORBA::Request::handle_response (TAO_InputCDR &incoming,
                                 GIOP::ReplyStatusType reply_status)
{
  // If this request was created by a gateway, then result_
  // and/or args_ are shared by a CORBA::ServerRequest, whose
  // reply must be in the same byte order as the reply we are
  // handling here. So we set the member to be accessed later.
  this->byte_order_ = incoming.byte_order ();

  switch (reply_status)
  {
    case GIOP::NO_EXCEPTION:
      if (this->result_ != 0)
        {
          // We can be sure that the impl is a TAO::Unknown_IDL_Type.
          this->result_->value ()->impl ()->_tao_decode (incoming);
        }

      this->args_->_tao_incoming_cdr (incoming,
                                      CORBA::ARG_OUT | CORBA::ARG_INOUT,
                                      this->lazy_evaluation_);

      {
        ACE_GUARD (TAO_SYNCH_MUTEX,
                   ace_mon,
                   this->lock_);

        this->response_received_ = true;
      }

      break;
    case GIOP::USER_EXCEPTION:
    case GIOP::SYSTEM_EXCEPTION:
    case GIOP::LOCATION_FORWARD:
    case GIOP::LOCATION_FORWARD_PERM:
    default:
      // @@ (JP) Don't know what to do about any of these yet.
      TAOLIB_ERROR ((LM_ERROR,
                  ACE_TEXT ("(%P|%t) unhandled reply status\n")));
  }
}
Ejemplo n.º 18
0
CORBA::Boolean
CORBA::ValueBase::_tao_unmarshal_value_indirection (TAO_InputCDR &strm,
                                                    CORBA::ValueBase *&value)
{
  if (strm.get_value_map().is_nil ())
    throw CORBA::INTERNAL ();

  CORBA::Long offset = 0;
  if (!strm.read_long (offset) ||  offset >= 0)
  {
    return 0;
  }

  void* pos = strm.rd_ptr () + offset - sizeof (CORBA::Long);

  if (9 < TAO_debug_level)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
        ACE_TEXT ("TAO (%P|%t) ValueBase::_tao_unmarshal_value_indirection, pos %x\n"), pos));
      TAO_InputCDR::Value_Map* map = strm.get_value_map()->get ();
      for (TAO_InputCDR::Value_Map::ITERATOR it = map->begin (); it != map->end (); ++ it)
        {
          TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) ValueBase::_tao_unmarshal_value_indirection, %x=%x\n"), it->ext_id_, it->int_id_));
        }
    }
  void * v = 0;
  if (strm.get_value_map()->get()->find (pos, v) != 0)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
        ACE_TEXT ("TAO (%P|%t) - %N:%l ")
        ACE_TEXT ("ValueBase::_tao_unmarshal_value_indirection, ")
        ACE_TEXT ("did not find %x in map %x\n"),
        pos, (void *) strm.get_value_map()->get()));
      throw CORBA::INTERNAL ();
    }
  else if (TAO_debug_level)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
        ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_unmarshal_value_indirection, found %x=%x\n"),
        pos,v));
    }

  value = reinterpret_cast<CORBA::ValueBase *>(v);
  return true;
}
Ejemplo n.º 19
0
CORBA::Boolean
CORBA::ValueBase::_tao_unmarshal_pre (
  TAO_InputCDR &strm,
  CORBA::ValueBase *&valuetype,
  const char *const fallback_repo_id,
  CORBA::Boolean &is_null_object,
  CORBA::Boolean &is_indirected)
{
  // %! yet much to do ... look for +++ !

  // 1. Get the <value-tag> (else it may be <indirection-tag> or <null-ref>).
  //    Is object yet unmarshalled (<indirection-tag> is set) ? (->1a)
  //    Is <null-ref> given ? Set 0 and return ok.
  // 1a. Lookup the real address in memory, which should be aligned +++
  //     to CORBA::ValueBase. Its possible at this point that worse
  //     type mismatch gets by undetected, if the CDR stream fakes.
  //     So the type should be checked ... +++

  // 2. Now at this point it must be a <value-tag> (error else).
  //    if (chunking) check that any last chunk ends with matching
  //    size. If not raise marshal exception.
  //    Increase the nesting level of valuetypes.

  // 3. if (chunking) read and record the blocksize-tag.

  // 4. Unmarshal type information and lookup factory.
  //    If no type information is given in the CDR encoding, as told
  //    from the <value-tag>, then use the repository id parameter
  //    (it _must_ be right).

  CORBA::Boolean is_chunked = false;

  // Save the position of the start of the ValueType
  // to allow caching for later indirection.
  if (strm.align_read_ptr (ACE_CDR::LONG_SIZE))
    {
      return false;
    }
  void *const start_of_valuetype = strm.rd_ptr();

  Repository_Id_List ids;
  CORBA::Boolean result =
    CORBA::ValueBase::_tao_unmarshal_header (
      strm, fallback_repo_id, ids,
      is_null_object, is_indirected, is_chunked);

  if (!result || is_null_object)
    {
      valuetype = 0;
      return result;
    }
  if (is_indirected)
    {
      return _tao_unmarshal_value_indirection (strm, valuetype);
    }

  CORBA::ValueBase::_tao_unmarshal_find_factory (
    strm, start_of_valuetype, valuetype, ids, is_chunked);

  return true;
}
Ejemplo n.º 20
0
int ACE_TMAIN (int, ACE_TCHAR *[])
{
  int status = 0;

  for (CORBA::ULong i = 16; i != 64; ++i)
    {
      ACE_Message_Block mb (i + ACE_CDR::MAX_ALIGNMENT);
      ACE_CDR::mb_align (&mb);
      mb.wr_ptr (i);

      CORBA::Double dbl = i;

      TAO_OutputCDR cdr;
      cdr.write_ulong (i); // length
      cdr.write_octet_array_mb (&mb);
      cdr.write_double (dbl);
      cdr.write_double (dbl);

      TAO_InputCDR input (cdr);

      CORBA::ULong len;

      input.read_ulong (len);

      if (len != i)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "ERROR: mismatched lengths,"
                      " got %d, expected %d\n",
                      len, i));
        }

      ACE_Message_Block read_mb (len + ACE_CDR::MAX_ALIGNMENT);
      ACE_CDR::mb_align (&mb);
      mb.wr_ptr (len);
      input.read_char_array (mb.rd_ptr (), len);

      CORBA::Double read_dbl;
      if (input.read_double (read_dbl) == 0)
        ACE_DEBUG ((LM_DEBUG, "Failure reading double...\n"));

      if (!ACE::is_equal (read_dbl, dbl))
        {
          status = 1;
          ACE_DEBUG ((LM_DEBUG,
                      "ERROR: mismatched doubles,"
                      " got %f, expected %f\n",
                      read_dbl, dbl));
          for (const ACE_Message_Block *j = cdr.begin ();
               j != cdr.end ();
               j = j->cont ())
            {
              ACE_HEX_DUMP ((LM_DEBUG,
                             j->rd_ptr (),
                             j->length (),
                             ACE_TEXT("Output CDR stream")));
            }
          TAO_InputCDR debug (cdr);
          ACE_HEX_DUMP ((LM_DEBUG,
                         debug.rd_ptr (),
                         debug.length (),
                         ACE_TEXT("Input CDR stream")));
        }
    }

  return status;
}
Ejemplo n.º 21
0
void ReplicaController::
listener ()
{
  try
  {
    for (char buffer[1024];;)
    {
      size_t n = group_->recv (buffer, sizeof (buffer));

      ACE_HEX_DUMP ((LM_DEBUG, buffer, n));

      TAO_InputCDR cdr (buffer, n);

      CORBA::OctetSeq object_id;
      PortableInterceptor::AdapterName adapter_name;
      CORBA::String_var client_id;
      CORBA::Long retention_id;
      CORBA::OctetSeq reply;
      CORBA::Any state;

      cdr >> object_id;
      cdr >> adapter_name;
      cdr >> client_id.out ();
      cdr >> retention_id;
      cdr >> reply;
      cdr >> state;

      if (!cdr.good_bit ())
      {
        ACE_DEBUG ((LM_DEBUG, "CDR failed\n"));
        //@@ what to do?
      }

      ACE_DEBUG ((LM_DEBUG,
                  "Received log for %s with rid %i\n",
                  client_id.in (),
                  retention_id));


      RecordId rid (client_id.in (), retention_id);

      CORBA::OctetSeq_var tmp (new CORBA::OctetSeq (reply));
      log_.insert (rid, tmp);

      // Update state.
      CORBA::TypeCode_var tc = state.type ();

      if (tc->kind () != CORBA::tk_null)
      {
        PortableServer::POA_var poa = resolve_poa (adapter_name);

        PortableServer::ServantBase_var servant =
          poa->id_to_servant (object_id);

        Checkpointable* target =
          dynamic_cast<Checkpointable*> (servant.in ());

        if (target) target->set_state (state);
      }
    }
  }
  catch (ACE_TMCast::Group::Failed const&)
  {
    ACE_DEBUG ((LM_DEBUG,
                "Group failure. Perhaps, I am alone in the group.\n"));
  }
  catch (ACE_TMCast::Group::InsufficienSpace const&)
  {
    ACE_DEBUG ((LM_DEBUG, "Group::InsufficienSpace\n"));
  }

  orb_->shutdown (0);
}
Ejemplo n.º 22
0
  Invocation_Status
  DII_Invocation::handle_user_exception (TAO_InputCDR &cdr)
  {
    Reply_Guard mon (this, TAO_INVOKE_FAILURE);

    if (TAO_debug_level > 3)
      {
        TAOLIB_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t) - DII_Invocation::"
                    "handle_user_exception\n"));
      }

    // Match the exception interface repository id with the
    // exception in the exception list.
    // This is important to decode the exception.
    CORBA::String_var buf;

    TAO_InputCDR tmp_stream (cdr,
                             cdr.start ()->length (),
                             0);

    // Pull the exception ID out of the marshaling buffer.
    if (tmp_stream.read_string (buf.inout ()) == 0)
      {
        throw ::CORBA::MARSHAL (TAO::VMCID, CORBA::COMPLETED_YES);
      }

    for (CORBA::ULong i = 0;
         this->excp_list_ != 0 && i < this->excp_list_->count ();
         i++)
      {
          CORBA::TypeCode_var tc = this->excp_list_->item (i);

          const char *xid = tc->id ();

          if (ACE_OS::strcmp (buf.in (), xid) != 0)
            {
              continue;
            }

          CORBA::Any any;
          TAO::Unknown_IDL_Type *unk = 0;
          ACE_NEW_RETURN (unk,
                          TAO::Unknown_IDL_Type (
                              tc.in (),
                              cdr
                            ),
                          TAO_INVOKE_FAILURE);

          any.replace (unk);

          mon.set_status (TAO_INVOKE_USER_EXCEPTION);

          throw ::CORBA::UnknownUserException (any);
        }

    // If we couldn't find the right exception, report it as
    // CORBA::UNKNOWN.

    // But first, save the user exception in case we
    // are being used in a TAO gateway.
    this->host_->raw_user_exception (cdr);

    mon.set_status (TAO_INVOKE_USER_EXCEPTION);

    // @@ It would seem that if the remote exception is a
    //    UserException we can assume that the request was
    //    completed.
    throw ::CORBA::UNKNOWN (TAO::VMCID, CORBA::COMPLETED_YES);

  }
Ejemplo n.º 23
0
void
TAO_DynSequence_i::init (const CORBA::Any& any)
{
  CORBA::TypeCode_var tc = any.type ();

  CORBA::TCKind kind = TAO_DynAnyFactory::unalias (tc.in ());

  if (kind != CORBA::tk_sequence)
    {
      throw DynamicAny::DynAnyFactory::InconsistentTypeCode ();
    }

  this->type_ = tc;

  // Get the CDR stream of the Any, if there isn't one, make one.
  TAO::Any_Impl *impl = any.impl ();
  CORBA::ULong length;
  TAO_OutputCDR out;
  TAO_InputCDR cdr (static_cast<ACE_Message_Block *> (0));

  if (impl->encoded ())
    {
      TAO::Unknown_IDL_Type * const unk =
        dynamic_cast<TAO::Unknown_IDL_Type *> (impl);

      if (!unk)
        throw CORBA::INTERNAL ();

      cdr = unk->_tao_get_cdr ();
    }
  else
    {
      impl->marshal_value (out);
      TAO_InputCDR tmp_in (out);
      cdr = tmp_in;
    }

  // If the any is a sequence, first 4 bytes of cdr hold the
  // length.
  cdr.read_ulong (length);

  // Resize the array.
  this->da_members_.size (length);

  this->init_common ();

  // Get the type of the sequence elments.
  CORBA::TypeCode_var field_tc =
    this->get_element_type ();

  for (CORBA::ULong i = 0; i < length; ++i)
    {
      CORBA::Any field_any;
      TAO_InputCDR unk_in (cdr);
      TAO::Unknown_IDL_Type *field_unk = 0;
      ACE_NEW (field_unk,
               TAO::Unknown_IDL_Type (field_tc.in (), unk_in));
      field_any.replace (field_unk);

      // This recursive step will call the correct constructor
      // based on the type of field_any.
      this->da_members_[i] =
        TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
          field_any._tao_get_typecode (),
          field_any,
          this->allow_truncation_ );

      // Move to the next field in the CDR stream.
      (void) TAO_Marshal_Object::perform_skip (field_tc.in (), &cdr);
    }
}
Ejemplo n.º 24
0
void
TAO_DynSequence_i::from_any (const CORBA::Any & any)
{
  if (this->destroyed_)
    {
      throw ::CORBA::OBJECT_NOT_EXIST ();
    }

  CORBA::TypeCode_var tc = any.type ();
  CORBA::Boolean equivalent =
    this->type_.in ()->equivalent (tc.in ());

  if (equivalent)
    {
      // Get the CDR stream of the Any, if there isn't one, make one.
      TAO::Any_Impl *impl = any.impl ();
      TAO_OutputCDR out;
      TAO_InputCDR cdr (static_cast<ACE_Message_Block *> (0));

      if (impl->encoded ())
        {
          TAO::Unknown_IDL_Type * const unk =
            dynamic_cast<TAO::Unknown_IDL_Type *> (impl);

          if (!unk)
            throw CORBA::INTERNAL ();

          cdr = unk->_tao_get_cdr ();
        }
      else
        {
          impl->marshal_value (out);
          TAO_InputCDR tmp_in (out);
          cdr = tmp_in;
        }


      CORBA::ULong arg_length;

      // If the any is a sequence, first 4 bytes of cdr hold the
      // length.
      cdr.read_ulong (arg_length);

      // If the array grows, we must do it now.
      if (arg_length > this->component_count_)
        {
          this->da_members_.size (arg_length);
        }

      CORBA::TypeCode_var field_tc =
        this->get_element_type ();

      for (CORBA::ULong i = 0; i < arg_length; ++i)
        {
          CORBA::Any field_any;
          TAO_InputCDR unk_in (cdr);
          TAO::Unknown_IDL_Type *field_unk = 0;
          ACE_NEW (field_unk,
                   TAO::Unknown_IDL_Type (field_tc.in (),
                                          unk_in));
          field_any.replace (field_unk);

          if (i < this->component_count_)
            {
              this->da_members_[i]->destroy ();
            }

          this->da_members_[i] =
            TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
              field_any._tao_get_typecode (),
              field_any,
              this->allow_truncation_ );

          // Move to the next field in the CDR stream.
          (void) TAO_Marshal_Object::perform_skip (field_tc.in (), &cdr);
        }

      // Destroy any dangling members.
      for (CORBA::ULong j = arg_length; j < this->component_count_; ++j)
        {
          this->da_members_[j]->destroy ();
        }

      // If the array shrinks, we must wait until now to do it.
      if (arg_length < this->component_count_)
        {
          this->da_members_.size (arg_length);
        }

      // Now we can update component_count_.
      this->component_count_ = arg_length;

      this->current_position_ = arg_length ? 0 : -1;
    }
  else
    {
      throw DynamicAny::DynAny::TypeMismatch ();
    }
}
Ejemplo n.º 25
0
CORBA::Boolean
TAO_ChunkInfo::handle_chunking (TAO_InputCDR &strm)
{
  if (!this->chunking_)
    {
      return 1;
    }

  char* the_rd_ptr = strm.start()->rd_ptr ();

  //This case could happen if a handle_chunking() reads a chunk size
  //and then calls the handle_chunking() again without reading the chunk data.
  //The handle_chunking() called continuously without reading the chunk data
  //only happens at the beginning of _tao_unmarshal_state() in a valuetype
  //that has parents.
  if (the_rd_ptr < this->chunk_octets_end_pos_)
    {
      ++this->value_nesting_level_;
      return 1;
    }

  //Safty check if reading is out of range of current chunk.
  if (this->chunk_octets_end_pos_ != 0
      && the_rd_ptr > this->chunk_octets_end_pos_)
    {
      return 0;
    }

  // Read a long value that might be an endtag, the chunk size or the value tag
  // of the nested valuetype.
  CORBA::Long tag;

  if (!strm.read_long (tag))
    {
      return 0;
    }

  if (tag < 0)
    {
      // tag is an end tag
      if (-tag > this->value_nesting_level_)
        {
          TAOLIB_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("TAO (%P|%t) - %N:%l TAO_ChunkInfo::handle_chunking, received end tag ")
                             ACE_TEXT ("%d > value_nesting_level %d\n"),
                             -tag,
                             this->value_nesting_level_),
                            0);
        }

      this->value_nesting_level_ = - tag;
      --this->value_nesting_level_;

      this->chunk_octets_end_pos_ = 0;

      // Continue reading so that we can read the outmost endtag. This
      // would simplify the implementation in the derived valuetype.
      if (this->value_nesting_level_ > 0)
        {
          this->handle_chunking(strm);
        }
    }
  else if (tag < TAO_OBV_GIOP_Flags::Value_tag_base)
    {
      // Read the chunk size of another chunk.
      this->chunk_octets_end_pos_ = strm.rd_ptr () + tag;
      ++this->value_nesting_level_;
    }
  else // (tag >= 0x7fffff00)
    {
      // This should not happen since the valuetag of the nested
      // values are always unmarshalled in the
      // ValueBase::_tao_unmarshal_pre().
      return 0;
    }

  return 1;
}
Ejemplo n.º 26
0
CORBA::Boolean
CORBA::ValueBase::_tao_read_codebase_url (TAO_InputCDR& strm,
                                          ACE_CString& codebase_url)
{
  CORBA::ULong length = 0;

  size_t buffer_size = strm.length();

  if (!strm.read_ulong (length))
    {
      return 0;
    }

  VERIFY_MAP (TAO_InputCDR, codebase_url_map, Codebase_URL_Map);
  char * pos = strm.rd_ptr();

  // 'length' may not be the codebase url length - it could be the
  // FFFFFFF indirection marker instead. If it is an indirection marker, we
  // get the offset following the indirection marker, otherwise we can follow
  // the same logic using the offset to simply rewind to the start of length
  // and re-read the length as part of the string
  if (TAO_OBV_GIOP_Flags::is_indirection_tag (length))
    {
      return _tao_unmarshal_codebase_url_indirection (strm, codebase_url);
    }

  pos -= sizeof (CORBA::ULong);

  // Cribbed from tc_demarshal_indirection in Typecode_CDR_Extraction.cpp
  TAO_InputCDR url_stream (pos,
                          buffer_size,
                          strm.byte_order ());

  if (!url_stream.good_bit ())
    {
      return 0;
    }

  if (! url_stream.read_string (codebase_url))
    return 0;

  // It's possible the codebase url is read again from an indirection stream,
  // so make sure the codebase url is the same.
  ACE_CString mapped_url;
  if (strm.get_codebase_url_map ()->get()->find (pos, mapped_url) == 0)
  {
    if (TAO_debug_level)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
        ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_read_codebase_url, found %x=%C\n"),
        pos, mapped_url.c_str ()));
    }
    if (ACE_OS::strcmp (mapped_url.c_str (), codebase_url.c_str ()) != 0)
      throw CORBA::INTERNAL ();
  }
  else if (strm.get_codebase_url_map ()->get()->bind (pos, codebase_url) != 0)
  {
    throw CORBA::INTERNAL ();
  }
  else
  {
    if (TAO_debug_level)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
        ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_read_codebase_url, bound %x=%C\n"),
        pos, codebase_url.c_str ()));
    }
  }

  // Since the codebase url is always read from the indirection cdr we have to skip
  // the main CDR forward if we were in fact reading from the current
  // location and not rewinding back some offset.

  strm.skip_bytes (length);

  return 1;
}
Ejemplo n.º 27
0
CORBA::Boolean
CORBA::ValueBase::_tao_unmarshal_header (
  TAO_InputCDR &strm,
  const char *const fallback_repo_id,
  Repository_Id_List &ids,
  CORBA::Boolean &is_null_object,
  CORBA::Boolean &is_indirected,
  CORBA::Boolean &is_chunked)
{
  is_indirected = false;
  is_null_object = false;
  is_chunked = false;

  CORBA::Long valuetag;
  if (!strm.read_long (valuetag))
    {
      return false;
    }

  is_chunked = TAO_OBV_GIOP_Flags::is_chunked (valuetag);

  if (TAO_OBV_GIOP_Flags::is_null_ref (valuetag))
    {
      // null reference is unmarshalled.
      is_null_object = true;
      return true;
    }

  if (TAO_OBV_GIOP_Flags::is_indirection_tag (valuetag))
    {
      // value is redirected
      is_indirected = true;
      return true;
    }

  if (TAO_OBV_GIOP_Flags::has_codebase_url (valuetag))
    {
      // We don't do anything with this url, but it needs
      // to be read and ignored.
      ACE_CString codebase_url;
      if (!_tao_read_codebase_url (strm, codebase_url))
        {
          return false;
        }
    }

  // Obtain the repo_id(s) of the type we are reading

  if (TAO_OBV_GIOP_Flags::has_single_type_info (valuetag))
    {
      ACE_CString id;
      if (!_tao_read_repository_id(strm, id))
        {
          return false;
        }
      ids.push_back (id);
    }
  else if (TAO_OBV_GIOP_Flags::has_list_type_info (valuetag))
    {
      if (!_tao_read_repository_id_list(strm, ids))
        {
          return false;
        }
    }
  else if (TAO_OBV_GIOP_Flags::has_no_type_info (valuetag))
    {
      if (fallback_repo_id)
        {
          ids.push_back (fallback_repo_id);
        }
      else
        {
          TAOLIB_ERROR ((
            LM_ERROR,
            ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_unmarshal_pre, ")
            ACE_TEXT ("unknown repo_id\n") ));
          return false;
        }
    }
  else
    {
      if (TAO_debug_level)
        {
          TAOLIB_ERROR ((
            LM_ERROR,
            ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_unmarshal_pre, ")
            ACE_TEXT ("unknown value tag: %x\n"),
            valuetag  ));
        }

      return false;
    }

  return true;
}
Ejemplo n.º 28
0
CORBA::Boolean
CORBA::ValueBase::_tao_validate_box_type (TAO_InputCDR &strm,
                                          TAO_InputCDR &indirected_strm,
                                          const char * const repo_id_expected,
                                          CORBA::Boolean & null_object,
                                          CORBA::Boolean & is_indirected)
{
  CORBA::Long value_tag;
  null_object = false;
  is_indirected = false;

  if (!strm.read_long (value_tag))
    {
      return false;
    }

  if (TAO_OBV_GIOP_Flags::is_null_ref (value_tag))
    { // ok, null reference unmarshaled
      null_object = true;
      return true;
    }

  if (TAO_OBV_GIOP_Flags::is_indirection_tag (value_tag))
    {
      is_indirected = true;

      // box value is redirected.
      return _tao_unmarshal_value_indirection_pre (strm, indirected_strm);
    }

  if (!TAO_OBV_GIOP_Flags::is_value_tag (value_tag))
    {
      TAOLIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - %N:%l CORBA::ValueBase::_tao_validate_box_type, ")
                  ACE_TEXT ("not value_tag\n")));
      return false;
    }


  if (TAO_OBV_GIOP_Flags::has_codebase_url (value_tag))
    { // Demarshal the codebase url (but we won't be using it).

      ACE_CString codebase_url;
      if (! _tao_read_codebase_url (strm, codebase_url))
        {
          return false;
        }
    }

  if (TAO_OBV_GIOP_Flags::has_no_type_info (value_tag))
    {
      // No type information so assume it is the correct type.
      return true;
    }

  if (TAO_OBV_GIOP_Flags::has_single_type_info (value_tag))
    {
      // Demarshal the repository id and check if it is the expected one.
      ACE_CString id;
      if (! _tao_read_repository_id (strm, id))
        {
          return false;
        }

      if (!ACE_OS::strcmp (id.c_str(), repo_id_expected))
      {  // Repository ids matched as expected
        return true;
      }
    }

  if (TAO_OBV_GIOP_Flags::has_list_type_info (value_tag))
    {
      // Don't know how to handle a repository id list.  It does not
      // make sense for a value box anyway.
      return false;
    }

  return false;
}
Ejemplo n.º 29
0
void
CORBA::ValueBase::_tao_unmarshal_find_factory (
  TAO_InputCDR &strm,
  void *const start_of_valuetype,
  CORBA::ValueBase *&valuetype,
  Repository_Id_List &ids,
  CORBA::Boolean &is_chunked)
{
  valuetype = 0;

  TAO_ORB_Core *orb_core = strm.orb_core ();
  if (!orb_core)
    {
      orb_core = TAO_ORB_Core_instance ();
      if (TAO_debug_level)
        {
          TAOLIB_DEBUG ((
            LM_WARNING,
            ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_unmarshal_find_factory, ")
            ACE_TEXT ("WARNING: extracting valuetype using default ORB_Core\n") ));
        }
    }

  // Find the registered factory for this unmarshalling valuetype. If any
  // factory for the valuetype in its truncatable derivation hierarchy
  // is registered, the factory is used to create value for unmarshalling.
  // Value factories are reference counted. When we get a new value factory
  // from the ORB, its reference count is increased.

  CORBA::ValueFactory_var factory;
  CORBA::Boolean requires_truncation = false;
  const size_t num_ids = ids.size ();
  const char *id = (num_ids) ? ids[0].c_str () : "{Null}";
  for (size_t i = 0u; i < num_ids; ++i)
    {
      factory = orb_core->orb ()->lookup_value_factory (ids[i].c_str ());
      if (factory.in() != 0)
        {
          id = ids[i].c_str ();
          requires_truncation = (i != 0u);
          break;
        }
    }

  // Obtain the actual ValueType from the factory
  if (factory.in() == 0 || !(valuetype = factory->create_for_unmarshal ()))
    {
      if (TAO_debug_level)
        {
          TAOLIB_ERROR ((LM_ERROR,
            ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_unmarshal_find_factory, ")
            ACE_TEXT ("OBV factory is null, id=%C\n"),
            id));
        }

      throw ::CORBA::MARSHAL (CORBA::OMGVMCID | 1, CORBA::COMPLETED_MAYBE);
    }

  if (requires_truncation)
    {
      valuetype->truncation_hook ();
    }
  valuetype->chunking_ = is_chunked;

  // Cache the start of this ValueType for later possiable indirection
  VERIFY_MAP (TAO_InputCDR, value_map, Value_Map);
  if (strm.get_value_map ()->get()->bind (start_of_valuetype, valuetype) != 0)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
        ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_unmarshal_find_factory, ")
        ACE_TEXT ("Failed to bound value %x=%x, id=%C\n"),
        start_of_valuetype, valuetype, id ));
    }
  else if (TAO_debug_level)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
        ACE_TEXT ("TAO (%P|%t) - %N:%l ValueBase::_tao_unmarshal_find_factory, ")
        ACE_TEXT ("bound value %x=%x, id=%C\n"),
        start_of_valuetype, valuetype, id ));
    }
}