Example #1
0
DCPS_IR_Topic::~DCPS_IR_Topic()
{
  // check for remaining publication references
  if (0 != publicationRefs_.size()) {
    DCPS_IR_Publication* pub = 0;
    DCPS_IR_Publication_Set::ITERATOR iter = publicationRefs_.begin();
    DCPS_IR_Publication_Set::ITERATOR end = publicationRefs_.end();

    OpenDDS::DCPS::RepoIdConverter topic_converter(id_);
    ACE_ERROR((LM_ERROR,
               ACE_TEXT("(%P|%t) ERROR: DCPS_IR_Topic::~DCPS_IR_Topic: ")
               ACE_TEXT("id %C has retained publications.\n"),
               std::string(topic_converter).c_str()));

    while (iter != end) {
      pub = *iter;
      ++iter;

      OpenDDS::DCPS::RepoIdConverter pub_converter(pub->get_id());
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("(%P|%t) ERROR: DCPS_IR_Topic::~DCPS_IR_Topic: ")
                 ACE_TEXT("topic %C retains publication id %C.\n"),
                 std::string(topic_converter).c_str(),
                 std::string(pub_converter).c_str()));
    }
  }

  if (0 != subscriptionRefs_.size()) {
    DCPS_IR_Subscription* sub = 0;
    DCPS_IR_Subscription_Set::ITERATOR iter = subscriptionRefs_.begin();
    DCPS_IR_Subscription_Set::ITERATOR end = subscriptionRefs_.end();

    OpenDDS::DCPS::RepoIdConverter topic_converter(id_);
    ACE_ERROR((LM_ERROR,
               ACE_TEXT("(%P|%t) ERROR: DCPS_IR_Topic::~DCPS_IR_Topic: ")
               ACE_TEXT("id %C has retained subscriptions.\n"),
               std::string(topic_converter).c_str()));

    while (iter != end) {
      sub = *iter;
      ++iter;

      OpenDDS::DCPS::RepoIdConverter sub_converter(sub->get_id());
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("(%P|%t) ERROR: DCPS_IR_Topic::~DCPS_IR_Topic: ")
                 ACE_TEXT("topic %C retains subscription id %C.\n"),
                 std::string(topic_converter).c_str(),
                 std::string(sub_converter).c_str()));
    }
  }
}
void
DCPS_IR_Publication::reevaluate_defunct_associations()
{
  DCPS_IR_Subscription_Set::iterator it(this->defunct_.begin());
  while (it != this->defunct_.end()) {
    DCPS_IR_Subscription* subscription = *it;
    ++it;

    if (reevaluate_association(subscription)) {
      this->defunct_.remove(subscription); // no longer defunct

    } else {
      OpenDDS::DCPS::RepoIdConverter pub_converter(id_);
      OpenDDS::DCPS::RepoIdConverter sub_converter(subscription->get_id());
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("(%P|%t) ERROR: DCPS_IR_Publication::reevaluate_defunct_associations: ")
                 ACE_TEXT("publication %C failed to reassociate subscription %C at %x.\n"),
                 std::string(pub_converter).c_str(),
                 std::string(sub_converter).c_str(),
                 subscription));
    }
  }
}
int DCPS_IR_Publication::remove_associations(CORBA::Boolean notify_lost)
{
  int status = 0;
  DCPS_IR_Subscription* sub = 0;
  size_t numAssociations = associations_.size();
  CORBA::Boolean dontSend = 0;
  CORBA::Boolean send = 1;

  if (0 < numAssociations) {
    DCPS_IR_Subscription_Set::ITERATOR iter = associations_.begin();
    DCPS_IR_Subscription_Set::ITERATOR end = associations_.end();

    while (iter != end) {
      sub = *iter;
      ++iter;
      sub->remove_associated_publication(this, send, notify_lost);
      remove_associated_subscription(sub, dontSend, notify_lost);
    }
  }
  this->defunct_.reset();

  return status;
}
void DCPS_IR_Publication::disassociate_subscription(OpenDDS::DCPS::RepoId id,
                                                    bool reassociate)
{
  DCPS_IR_Subscription* sub = 0;
  size_t numAssociations = associations_.size();
  CORBA::Boolean send = 1;
  CORBA::Boolean dontSend = 0;
  long count = 0;

  if (0 < numAssociations) {
    OpenDDS::DCPS::ReaderIdSeq idSeq(static_cast<CORBA::ULong>(numAssociations));
    idSeq.length(static_cast<CORBA::ULong>(numAssociations));

    DCPS_IR_Subscription_Set::ITERATOR iter = associations_.begin();
    DCPS_IR_Subscription_Set::ITERATOR end = associations_.end();

    while (iter != end) {
      sub = *iter;
      ++iter;

      if (OpenDDS::DCPS::DCPS_debug_level > 0) {
        OpenDDS::DCPS::RepoIdConverter pub_converter(id_);
        OpenDDS::DCPS::RepoIdConverter sub_converter(sub->get_id());
        OpenDDS::DCPS::RepoIdConverter pub_sub_converter(id);
        ACE_DEBUG((LM_DEBUG,
                   ACE_TEXT("(%P|%t) DCPS_IR_Publication::disassociate_subscription: ")
                   ACE_TEXT("publication %C testing if subscription %C == %C.\n"),
                   std::string(pub_converter).c_str(),
                   std::string(sub_converter).c_str(),
                   std::string(pub_sub_converter).c_str()));
      }

      if (id == sub->get_id()) {
        CORBA::Boolean dont_notify_lost = 0;
        sub->remove_associated_publication(this, send, dont_notify_lost);
        remove_associated_subscription(sub, dontSend, dont_notify_lost);

        idSeq[count] = sub->get_id();
        ++count;

        if (reassociate && this->defunct_.insert(sub) != 0) {
          OpenDDS::DCPS::RepoIdConverter pub_converter(id_);
          OpenDDS::DCPS::RepoIdConverter sub_converter(sub->get_id());
          ACE_ERROR((LM_ERROR,
                     ACE_TEXT("(%P|%t) ERROR: DCPS_IR_Publication::disassociate_subscription: ")
                     ACE_TEXT("publication %C failed to reassociate subscription %C at %x.\n"),
                     std::string(pub_converter).c_str(),
                     std::string(sub_converter).c_str(),
                     sub));
        }
      }
    }

    if (0 < count) {
      idSeq.length(count);

      if (participant_->is_alive() && this->participant_->isOwner()) {
        try {
          CORBA::Boolean dont_notify_lost = 0;
          writer_->remove_associations(idSeq, dont_notify_lost);

        } catch (const CORBA::Exception& ex) {
          if (OpenDDS::DCPS::DCPS_debug_level > 0) {
            ex._tao_print_exception(
              "(%P|%t) ERROR: Exception caught in DCPS_IR_Publication::remove_associations:");
          }

          participant_->mark_dead();
        }
      }
    }
  }
}