예제 #1
0
파일: ECM_Data.cpp 프로젝트: CCJY/ATCD
CORBA::Boolean
operator<< (TAO_OutputCDR& cdr, ECM_Data& x)
{
  // We are a little careless about error checking in this routine,
  // because one the CDR gets the error bit on it is never disabled.
  CORBA::ULong count = x.inventory.current_size ();
  if (cdr << x.description.in ()
      && cdr << count )
    {
      for (ECM_Data::Inventory::ITERATOR i = x.inventory.begin ();
           i != x.inventory.end () && cdr.good_bit ();
           ++i)
        {
          const ECM_Data::Inventory::ENTRY& v = *i;
          cdr << v.ext_id_;
          cdr << v.int_id_;
        }
    }
  return cdr.good_bit ();
}
예제 #2
0
파일: Principal.cpp 프로젝트: asdlei00/ACE
CORBA::Boolean
operator<< (TAO_OutputCDR & cdr, CORBA::Principal * x)
{
  if (x != 0)
    {
      CORBA::ULong length  = x->id.length ();
      cdr.write_long (length);
      cdr.write_octet_array (x->id.get_buffer (), length);
    }
  else
    {
      cdr.write_ulong (0);
    }

  return (CORBA::Boolean) cdr.good_bit ();
}
예제 #3
0
int
ECMS_Driver::supplier_task (Test_Supplier *supplier,
                            void* /* cookie */)
{
  try
    {
      ACE_Time_Value tv (0, this->event_period_);

      CORBA::ULong n = this->event_size_;

      ECM_IDLData::Info info;
      info.mobile_name = CORBA::string_dup ("test");
      info.mobile_speed = 1;
      info.trajectory.length (n);

      ECM_Data other;
      other.description = CORBA::string_dup ("some data");

      for (CORBA::ULong j = 0; j < n; ++j)
        {
          info.trajectory[j].x = j;
          info.trajectory[j].y = j * j;
          other.inventory.bind (j, j + 1);
        }

      ACE_DEBUG ((LM_DEBUG,
                  "The inventory contains (%d) elements\n",
                  other.inventory.current_size ()));

      // We have to make it big enough so we get a contiguous block,
      // otherwise the octet sequence will not work correctly.
      // NOTE: we could pre-allocate enough memory in the CDR stream
      // but we want to show that chaining works!
      TAO_OutputCDR cdr;

      CORBA::Boolean byte_order = TAO_ENCAP_BYTE_ORDER;
      cdr << CORBA::Any::from_boolean (byte_order);

      // The typecode name standard, the encode method is not (in
      // general the CDR interface is not specified).
      if (!(cdr << info))
        throw CORBA::MARSHAL ();

      // Here we marshall a non-IDL type.
      cdr << other;

      if (!cdr.good_bit ())
        ACE_ERROR ((LM_ERROR, "Problem marshalling C++ data\n"));

      const ACE_Message_Block* mb = cdr.begin ();
      // NOTE: total_length () return the length of the complete
      // chain.
      CORBA::ULong mblen = cdr.total_length ();

      for (CORBA::Long i = 0; i < this->event_count_; ++i)
        {
          RtecEventComm::EventSet event (1);
          event.length (1);
          event[0].header.source = supplier->supplier_id ();
          event[0].header.ttl = 1;

          ACE_hrtime_t t = ACE_OS::gethrtime ();
          ORBSVCS_Time::hrtime_to_TimeT (event[0].header.creation_time, t);

          if (i == static_cast<CORBA::Long> (this->event_count_) - 1)
            event[0].header.type = ACE_ES_EVENT_SHUTDOWN;
          else if (i % 2 == 0)
            event[0].header.type = this->event_a_;
          else
            event[0].header.type = this->event_b_;

          // We use replace to minimize the copies, this should result
          // in just one memory allocation;
#if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
          event[0].data.payload.replace (mblen, mb);
#else
          // If the replace method is not available, we will need
          // to do the copy manually.  First, set the octet sequence length.
          event[0].data.payload.length (mblen);

          // Now copy over each byte.
          char* base = mb->data_block ()->base ();
          for(CORBA::ULong i = 0; i < mblen; i++)
            {
              event[0].data.payload[i] = base[i];
            }
#endif /* TAO_NO_COPY_OCTET_SEQUENCES == 1 */

          supplier->consumer_proxy ()->push(event);

          // ACE_DEBUG ((LM_DEBUG, "(%t) supplier push event\n"));

          ACE_OS::sleep (tv);
        }
    }
  catch (const CORBA::SystemException& sys_ex)
    {
      sys_ex._tao_print_exception ("SYS_EX");
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("NON SYS EX");
    }
  return 0;
}
예제 #4
0
파일: Stub.cpp 프로젝트: OspreyHub/ATCD
CORBA::Boolean
TAO_Stub::marshal (TAO_OutputCDR &cdr)
{
  // do as many outside of locked else-branch as posssible

  // STRING, a type ID hint
  if ((cdr << this->type_id.in()) == 0)
    return 0;

  if ( ! this->forward_profiles_perm_)
    {
      const TAO_MProfile& mprofile = this->base_profiles_;

      CORBA::ULong const profile_count = mprofile.profile_count ();
      if ((cdr << profile_count) == 0)
        return 0;

    // @@ The MProfile should be locked during this iteration, is there
    // anyway to achieve that?
    for (CORBA::ULong i = 0; i < profile_count; ++i)
      {
        const TAO_Profile* p = mprofile.get_profile (i);
        if (p->encode (cdr) == 0)
          return 0;
      }
    }
  else
    {
      ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                                guard,
                                this->profile_lock_,
                                0));
  if (TAO_debug_level > 5)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - Stub::marshal, acquired ")
                  ACE_TEXT ("profile lock this = 0x%x\n"),
                  this));
    }


      ACE_ASSERT(this->forward_profiles_ !=0);

      // paranoid - in case of FT the basic_profiles_ would do, too,
      // but might be dated
      const TAO_MProfile& mprofile =
          this->forward_profiles_perm_
        ? *(this->forward_profiles_perm_)
        : this->base_profiles_;

      CORBA::ULong const profile_count = mprofile.profile_count ();
      if ((cdr << profile_count) == 0)
           return 0;

      // @@ The MProfile should be locked during this iteration, is there
      // anyway to achieve that?
      for (CORBA::ULong i = 0; i < profile_count; ++i)
        {
          const TAO_Profile* p = mprofile.get_profile (i);
          if (p->encode (cdr) == 0)
            return 0;
        }

      // release ACE_Lock
    }

  return (CORBA::Boolean) cdr.good_bit ();
}
예제 #5
0
CORBA::Boolean
operator<< (TAO_OutputCDR &strm, const CORBA::AbstractBase_ptr abs)
{
  CORBA::Boolean discriminator = true;

  // We marshal a null abstract interface ptr as a discriminator
  // plus null object reference (see CORBA::Object::marshal()
  // and operator << for CORBA::Object).
  if (CORBA::is_nil (abs))
    {
      // Marshal discriminator, then empty type hint.
      strm << ACE_OutputCDR::from_boolean (discriminator);
      return strm << CORBA::Object::_nil ();
    }

  if (abs->_is_objref ())
    {
      if (strm << ACE_OutputCDR::from_boolean (discriminator))
        {
          TAO_Stub *stubobj = abs->_stubobj ();

          if (stubobj == 0)
            {
              return false;
            }

          // STRING, a type ID hint
          if ((strm << stubobj->type_id.in ()) == 0)
            {
              return false;
            }

          const TAO_MProfile& mprofile = stubobj->base_profiles ();

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

          if ((strm << profile_count) == 0)
            {
              return false;
            }

          // @@ The MProfile should be locked during this iteration, is there
          // anyway to achieve that?
          for (CORBA::ULong i = 0; i < profile_count; ++i)
            {
              const TAO_Profile *p = mprofile.get_profile (i);

              if (p->encode (strm) == 0)
                {
                  return false;
                }
            }

          return (CORBA::Boolean) strm.good_bit ();
        }
    }
  else
    {
      discriminator = false;

      if (strm << ACE_OutputCDR::from_boolean (discriminator))
        {
          CORBA::ULong value_tag = TAO_OBV_GIOP_Flags::Value_tag_base
                                   | TAO_OBV_GIOP_Flags::Type_info_single;

          if ((strm.write_ulong (value_tag)) == 0)
            {
              return false;
            }

          if ((strm << abs->_tao_obv_repository_id ()) == 0)
            {
              return false;
            }

          return abs->_tao_marshal_v (strm);
        }
    }

  return false;
}