Exemple #1
0
DDS::DataWriter_var
Factory::writer(const DDS::Publisher_var& pub, const DDS::Topic_var& topic, const DDS::DataWriterListener_var& dwl) const
{
  // Create the data writer
  DDS::DataWriterQos dw_qos;
  pub->get_default_datawriter_qos(dw_qos);

  dw_qos.durability.kind = opts_.durability_kind;
  dw_qos.liveliness.kind = opts_.liveliness_kind;
  dw_qos.liveliness.lease_duration = opts_.LEASE_DURATION;
  dw_qos.reliability.kind = opts_.reliability_kind;

  DDS::DataWriter_var dw = pub->create_datawriter(topic,
                                                  dw_qos,
                                                  dwl.in(),
                                                  OpenDDS::DCPS::DEFAULT_STATUS_MASK);

  // Initialize the transport configuration for the appropriate entity
  if (opts_.configuration_str != "none" && opts_.entity_str == "rw")
    {
      OpenDDS::DCPS::TransportRegistry::instance()->bind_config(opts_.configuration_str,
                                                                dw.in());

      if (!opts_.entity_autoenable)
        {
          TEST_ASSERT(DDS::RETCODE_OK == dw->enable());
        }

    }

  return dw;
}
Exemple #2
0
bool
assert_publication_matched(const Options& opts, const DDS::DataWriterListener_var& dwl)
{

  // Assert if pub/sub made a match ...
  DataWriterListenerImpl* dwl_servant =
          dynamic_cast<DataWriterListenerImpl*> (dwl.in());

  // check to see if the publisher worked
  if (opts.compatible != dwl_servant->publication_matched() && opts.reliability_kind == DDS::RELIABLE_RELIABILITY_QOS)
    {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("(%P|%t) Expected publication_matched to be %C, but it was %C [")
                        ACE_TEXT(" durability_kind=%C, liveliness_kind=%C, liveliness_duration=%C, ")
                        ACE_TEXT("reliability_kind=%C]\n"),
                        (opts.compatible) ? "true" : "false",
                        (dwl_servant->publication_matched()) ? "true" : "false",
                        opts.durability_kind_str.c_str(),
                        opts.liveliness_kind_str.c_str(),
                        opts.LEASE_DURATION_STR.c_str(),
                        opts.reliability_kind_str.c_str()),
                       false);
    }

  return true;
}
Exemple #3
0
int
Writer_Base::svc()
{
  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) %C svc() begins. %C\n"), name_, get_id()));

  try {
    DDS::InstanceHandleSeq handles;
    while (true) {
      writer_->get_matched_subscriptions(handles);
      if (handles.length() > 0)
        break;
      else
        ACE_OS::sleep(ACE_Time_Value(0, 200000));
    }

    pre_loop();

    for (int i = 0; i < num_messages; ++i) {
      if (!liveliness_lost_test || i == 0 || i == num_messages - 1) {
        in_loop(i);
        if (i == 0) {
          // Since an arbitrary amount of time was spent in the get_matched_subscriptions
          // loop above, any number of liveliness lost callbacks may have already occurred.
          // These are not the callbacks that the test is counting (liveliness_lost_test).
          DDS::DataWriterListener_var dwl = writer_->get_listener();
          DataWriterListenerImpl* listener = dynamic_cast<DataWriterListenerImpl*>(dwl.in());
          listener->reset_liveliness_lost_callbacks();
        }
      }

      ACE_OS::sleep(assert_liveliness_period);
    }

    while (true) {
      writer_->get_matched_subscriptions(handles);
      if (handles.length() == 0)
        break;
      else
        ACE_OS::sleep(1);
    }

  } catch (const CORBA::Exception& e) {
    cerr << "Exception caught in svc:" << endl << e << endl;
  }

  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Writer_Base::svc finished %C.\n"), name_));

  return 0;
}
void
OpenDDS::DCPS::OfferedDeadlineWatchdog::execute(OpenDDS::DCPS::PublicationInstance_rch instance, bool timer_called)
{
  if (instance->deadline_timer_id_ != -1) {
    bool missed = false;

    if (instance->cur_sample_tv_  == ACE_Time_Value::zero) { // not write any sample.
      missed = true;

    } else if (timer_called) { // handle_timeout is called
      ACE_Time_Value diff = ACE_OS::gettimeofday() - instance->cur_sample_tv_;
      missed = diff >= this->interval_;

    } else if (instance->last_sample_tv_ != ACE_Time_Value::zero) { // upon writing sample.
      ACE_Time_Value diff = instance->cur_sample_tv_ - instance->last_sample_tv_;
      missed = diff > this->interval_;
    }

    if (missed) {
      ACE_GUARD(ACE_Recursive_Thread_Mutex, monitor, this->status_lock_);

      if (timer_called) {
        ++this->status_.total_count;
        this->status_.total_count_change =
          this->status_.total_count - this->last_total_count_;
        this->status_.last_instance_handle = instance->instance_handle_;

        this->writer_impl_->set_status_changed_flag(
          DDS::OFFERED_DEADLINE_MISSED_STATUS, true);

        DDS::DataWriterListener_var listener =
          this->writer_impl_->listener_for(
            DDS::OFFERED_DEADLINE_MISSED_STATUS);

        if (! CORBA::is_nil(listener.in())) {
          // Copy before releasing the lock.
          DDS::OfferedDeadlineMissedStatus const status = this->status_;

          // Release the lock during the upcall.
          ACE_GUARD(reverse_lock_type, reverse_monitor, this->reverse_status_lock_);

          // @todo Will this operation ever throw?  If so we may want to
          //       catch all exceptions, and act accordingly.
          listener->on_offered_deadline_missed(this->writer_.in(),
                                              status);
        }

        this->writer_impl_->notify_status_condition();
      }
    }

    // This next part is without status_lock_ held to avoid reactor deadlock.
    if (!timer_called) {
      this->cancel_timer(instance);
      this->schedule_timer(instance);
    }

  } else {
    // not an error - timer is scheduled asynchronously so we can get here
    // via WriteDataContainer::enqueue() before schedule_timer() is done
  }
}
Exemple #5
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]){
  try
    {
      DDS::DomainParticipantFactory_var dpf =
        TheParticipantFactoryWithArgs(argc, argv);
      DDS::DomainParticipant_var participant =
        dpf->create_participant(11,
                                PARTICIPANT_QOS_DEFAULT,
                                DDS::DomainParticipantListener::_nil(),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (participant.in ())) {
        cerr << "create_participant failed." << endl;
        return 1;
      }

      MessageTypeSupportImpl* servant = new MessageTypeSupportImpl();

      if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) {
        cerr << "register_type failed." << endl;
        exit(1);
      }

      CORBA::String_var type_name = servant->get_type_name ();

      DDS::TopicQos topic_qos;
      participant->get_default_topic_qos(topic_qos);
      DDS::Topic_var topic =
        participant->create_topic ("Movie Discussion List",
                                   type_name.in (),
                                   topic_qos,
                                   DDS::TopicListener::_nil(),
                                   ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (topic.in ())) {
        cerr << "create_topic failed." << endl;
        exit(1);
      }

      DDS::Publisher_var pub =
        participant->create_publisher(PUBLISHER_QOS_DEFAULT,
        DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (pub.in ())) {
        cerr << "create_publisher failed." << endl;
        exit(1);
      }

      // ----------------------------------------------

      // Create the listener.
      DDS::DataWriterListener_var listener (new DataWriterListenerImpl);
      if (CORBA::is_nil (listener.in ()))
      {
        cerr << "ERROR: listener is nil." << endl;
        exit(1);
      }


      DDS::DataWriterQos dw_qos; // Good QoS.
      pub->get_default_datawriter_qos (dw_qos);

      assert (DEADLINE_PERIOD.sec > 1); // Requirement for the test.

      // First data writer will have a listener to test listener
      // callback on deadline expiration.
      DDS::DataWriter_var dw =
        pub->create_datawriter (topic.in (),
                                dw_qos,
                                listener.in (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      if (CORBA::is_nil (dw.in ()))
      {
        cerr << "ERROR: create_datawriter failed." << endl;
        exit(1);
      }

      dw_qos.deadline.period.sec     = DEADLINE_PERIOD.sec;
      dw_qos.deadline.period.nanosec = DEADLINE_PERIOD.nanosec;

      // Set qos with deadline. The watch dog starts now.
      if (dw->set_qos (dw_qos) != ::DDS::RETCODE_OK)
      {
        cerr << "ERROR: set deadline qos failed." << endl;
        exit(1);
      }

      {
        // Two threads use same datawriter to write different instances.
        std::auto_ptr<Writer> writer1 (new Writer (dw.in (), 99, SLEEP_DURATION));
        std::auto_ptr<Writer> writer2 (new Writer (dw.in (), 100, SLEEP_DURATION));

        writer1->start ();
        writer2->start ();
        // ----------------------------------------------

        // Wait for fully associate with DataReaders.
        if (writer1->wait_for_start () == false || writer2->wait_for_start () == false)
        {
          cerr << "ERROR: took too long to associate. " << endl;
          exit (1);
        }

        ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: sleep for %d milliseconds\n"),
                              SLEEP_DURATION.msec ()));

        // Wait for a set of deadline periods to expire.
        ACE_OS::sleep (SLEEP_DURATION);

        ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: now verify missed ")
                            ACE_TEXT ("deadline status \n")));

        ::DDS::InstanceHandle_t handle1 = writer1->get_instance_handle ();
        ::DDS::InstanceHandle_t handle2 = writer2->get_instance_handle ();

        DDS::OfferedDeadlineMissedStatus deadline_status;
        if (dw->get_offered_deadline_missed_status(deadline_status) != ::DDS::RETCODE_OK)
        {
           cerr << "ERROR: Failed to get offered deadline missed status" << endl;
           exit (1);
        }

        ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: got missed")
                              ACE_TEXT ("deadline status \n")));

        if (deadline_status.total_count != NUM_EXPIRATIONS * NUM_WRITE_THREADS)
        {
          cerr << "ERROR: Unexpected number of missed offered "
            << "deadlines (" << deadline_status.total_count
            << " instead of " << NUM_EXPIRATIONS * NUM_WRITE_THREADS << ") "
            << endl;

          exit (1);
        }

        if (deadline_status.total_count_change != NUM_EXPIRATIONS * NUM_WRITE_THREADS)
        {
          cerr << "ERROR: Incorrect missed offered "
            << "deadline count change ("
            << deadline_status.total_count_change
            << ") instead of " << NUM_EXPIRATIONS * NUM_WRITE_THREADS
            << endl;

          exit (1);
        }

        if (deadline_status.last_instance_handle != handle1
          && deadline_status.last_instance_handle != handle2)
        {
          cerr << "ERROR: Unexpected last instance handle "
            << deadline_status.last_instance_handle << " instead of "
            << handle1 << " or "
            << handle2 << endl;
          exit (1);
        }

        writer1->wait ();
        writer2->wait ();

        ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: sleep for %d milliseconds\n"),
                              SLEEP_DURATION.msec()));

        // Wait for another set of deadline periods to expire.
        ACE_OS::sleep (SLEEP_DURATION);

        ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: now verify missed ")
                            ACE_TEXT ("deadline status \n")));

        if (dw->get_offered_deadline_missed_status(deadline_status) != ::DDS::RETCODE_OK)
        {
           cerr << "ERROR: Failed to get offered deadline missed status" << endl;
           exit (1);
        }

        ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: got missed")
                              ACE_TEXT ("deadline status \n")));

        if (deadline_status.total_count != (NUM_EXPIRATIONS + 2) * NUM_WRITE_THREADS)
        {
          cerr << "ERROR: Unexpected number of missed offered "
            << "deadlines (" << deadline_status.total_count
            << " instead of " << (NUM_EXPIRATIONS + 2) * NUM_WRITE_THREADS << ") "
            << endl;

          exit (1);
        }

        if (deadline_status.total_count_change != NUM_WRITE_THREADS * 2)
        {
          cerr << "ERROR: Incorrect missed offered "
            << "deadline count change ("
            << deadline_status.total_count_change
            << ") instead of " << NUM_WRITE_THREADS * 2
            << endl;

          exit (1);
        }

        if (deadline_status.last_instance_handle != handle1
          && deadline_status.last_instance_handle != handle2)
        {
          cerr << "ERROR: Unexpected last instance handle "
            << deadline_status.last_instance_handle << " instead of "
            << handle1 << " or "
            << handle2 << endl;
          exit (1);
        }


        // Wait for datareader finish.
        while (1)
        {
          ::DDS::InstanceHandleSeq handles;
          dw->get_matched_subscriptions (handles);
          if (handles.length () == 0)
            break;
          else
            ACE_OS::sleep(1);
        }
      }

      participant->delete_contained_entities();
      dpf->delete_participant(participant.in ());
      TheServiceParticipant->shutdown ();
  }
  catch (CORBA::Exception& e)
  {
    cerr << "PUB: Exception caught in main.cpp:" << endl
         << e << endl;
    exit(1);
  }

  return 0;
}
Exemple #6
0
int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf =
        TheParticipantFactoryWithArgs(argc, argv);
      DDS::DomainParticipant_var participant =
        dpf->create_participant(411,
                                PARTICIPANT_QOS_DEFAULT,
                                DDS::DomainParticipantListener::_nil(),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (participant.in ())) {
        cerr << "create_participant failed." << endl;
        return 1;
      }

      Test::DataTypeSupportImpl* servant = new Test::DataTypeSupportImpl();

      if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) {
        cerr << "register_type failed." << endl;
        exit(1);
      }

      CORBA::String_var type_name = servant->get_type_name ();

      DDS::TopicQos topic_qos;
      participant->get_default_topic_qos (topic_qos);

      DDS::Topic_var topic =
        participant->create_topic ("Data",
                                   type_name.in (),
                                   topic_qos,
                                   DDS::TopicListener::_nil(),
                                   ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (topic.in ()))
      {
        cerr << "create_topic failed." << endl;
        exit(1);
      }

      size_t const num_partitions =
        sizeof (Test::Offered::PartitionConfigs)
        / sizeof (Test::Offered::PartitionConfigs[0]);

      Test::PartitionConfig const * const begin =
        Test::Offered::PartitionConfigs;
      Test::PartitionConfig const * const end =
        begin + num_partitions;

      // Keep the writers around long enough for the publications and
      // subscriptions to match.
      typedef std::vector<DDS::DataWriter_var> writers_type;
      writers_type writers (num_partitions);

      for (Test::PartitionConfig const * i = begin; i != end; ++i)
      {
        DDS::PublisherQos pub_qos;
        participant->get_default_publisher_qos (pub_qos);

        // Specify partitions we're offering.
        CORBA::ULong n = 0;
        DDS::StringSeq & names = pub_qos.partition.name;
        for (char const * const * s = (*i).partitions;
             s != 0 && *s != 0;
             ++s, ++n)
        {
          CORBA::ULong const new_len = names.length () + 1;
          names.length (new_len);
          names[n] = *s;
        }

        DDS::Publisher_var pub =
          participant->create_publisher (pub_qos,
                                         DDS::PublisherListener::_nil (),
                                         ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
        if (CORBA::is_nil (pub.in ()))
        {
          cerr << "create_publisher failed." << endl;
          exit(1);
        }

        DDS::DataWriterListener_var listener (
          new Test::DataWriterListener ((*i).expected_matches));

        // Create the datawriter
        DDS::DataWriterQos dw_qos;
        pub->get_default_datawriter_qos (dw_qos);

        DDS::DataWriter_var dw =
          pub->create_datawriter(topic.in (),
                                 dw_qos,
                                 listener.in (),
                                 ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
        if (CORBA::is_nil (dw.in ()))
        {
          cerr << "create_datawriter failed." << endl;
          exit(1);
        }

        writers.push_back (dw);

        Test::DataDataWriter_var writer
          = Test::DataDataWriter::_narrow (dw.in());
        if (CORBA::is_nil (writer.in ()))
        {
          cerr << "Data Writer could not be narrowed"<< endl;
          exit(1);
        }

        Test::Data the_data;
        the_data.key = 2;
        the_data.the_data = CORBA::string_dup ("Data Wuz Here!");

        ::DDS::InstanceHandle_t const handle =
            writer->register_instance(the_data);

        ACE_DEBUG((LM_DEBUG,
                   ACE_TEXT("(%P|%t) %T PUB starting to write.\n")));

        ::DDS::ReturnCode_t const ret = writer->write (the_data, handle);;
        if (ret != ::DDS::RETCODE_OK)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: PUB ")
                      ACE_TEXT ("write() returned %d.\n"),
                      ret));
        }
      }

//       // Wait for DataReaders to finish.
//       writers_type::const_iterator zend (writers.end ());
//       for (writers_type::const_iterator z (writers.begin ()); z != zend; ++z)
//       {
//         ::DDS::InstanceHandleSeq handles;
//         while (1)
//         {
//           (*z)->get_matched_subscriptions (handles);
//           if (handles.length () == 0)
//             break;
//           else
//             ACE_OS::sleep (1);
//         }
//       }
      ACE_OS::sleep (20);
      {
        // Force contents of writers vector to be destroyed now.
        writers_type tmp;
        tmp.swap (writers);
      }

      participant->delete_contained_entities();
      dpf->delete_participant(participant.in ());
      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "PUB: Exception caught in main.cpp:" << endl
           << e << endl;
      exit(1);
    }

  return 0;
}
Exemple #7
0
int main (int argc, char *argv[]) {
  try {
    DDS::DomainParticipantFactory_var dpf =
      TheParticipantFactoryWithArgs(argc, argv);

    if( parse_args(argc, argv) != 0)
      return 1;

    DDS::DomainParticipant_var participant =
      dpf->create_participant(411,
                              PARTICIPANT_QOS_DEFAULT,
                              DDS::DomainParticipantListener::_nil());
    if (CORBA::is_nil (participant.in ())) {
      cerr << "create_participant failed." << endl;
      return 1;
    }

    Messenger::MessageTypeSupportImpl* servant = new Messenger::MessageTypeSupportImpl();
    OpenDDS::DCPS::LocalObject_var safe_servant = servant;

    if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) {
      cerr << "register_type failed." << endl;
      exit(1);
    }

    CORBA::String_var type_name = servant->get_type_name ();

    DDS::TopicQos topic_qos;
    participant->get_default_topic_qos(topic_qos);
    DDS::Topic_var topic =
      participant->create_topic ("Movie Discussion List",
                                 type_name.in (),
                                 topic_qos,
                                 DDS::TopicListener::_nil());
    if (CORBA::is_nil (topic.in ())) {
      cerr << "create_topic failed." << endl;
      exit(1);
    }

    // Initialize the transport
    OpenDDS::DCPS::TransportImpl_rch tcp_impl =
        TheTransportFactory->create_transport_impl (TCP_IMPL_ID,
                                                    "SimpleTcp",
                                                    OpenDDS::DCPS::DONT_AUTO_CONFIG);

    OpenDDS::DCPS::TransportConfiguration_rch writer_config
      = TheTransportFactory->create_configuration (TCP_IMPL_ID, "SimpleTcp");

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

    writer_tcp_config->local_address_ = ACE_INET_Addr (local_address.c_str());
    writer_tcp_config->local_address_str_ = local_address;
    // This is needed for bp_timeout test.
    writer_tcp_config->max_output_pause_period_ = 2000;

    // This is needed to get the connection deletion callback.
    writer_tcp_config->datalink_release_delay_ = 0;

    if (tcp_impl->configure(writer_config.in()) != 0)
    {
      cerr << "Failed to configure the transport." << endl;
      exit(1);
    }

    DDS::Publisher_var pub =
      participant->create_publisher(PUBLISHER_QOS_DEFAULT,
                                    DDS::PublisherListener::_nil());
    if (CORBA::is_nil (pub.in ())) {
      cerr << "create_publisher failed." << endl;
      exit(1);
    }

    // Attach the publisher to the transport.
    OpenDDS::DCPS::PublisherImpl* pub_impl =
      dynamic_cast<OpenDDS::DCPS::PublisherImpl*> (pub.in ());
    if (0 == pub_impl) {
      cerr << "Failed to obtain publisher servant" << endl;
      exit(1);
    }

    OpenDDS::DCPS::AttachStatus status = pub_impl->attach_transport(tcp_impl.in());
    if (status != OpenDDS::DCPS::ATTACH_OK) {
      std::string status_str;
      switch (status) {
        case OpenDDS::DCPS::ATTACH_BAD_TRANSPORT:
          status_str = "ATTACH_BAD_TRANSPORT";
          break;
        case OpenDDS::DCPS::ATTACH_ERROR:
          status_str = "ATTACH_ERROR";
          break;
        case OpenDDS::DCPS::ATTACH_INCOMPATIBLE_QOS:
          status_str = "ATTACH_INCOMPATIBLE_QOS";
          break;
        default:
          status_str = "Unknown Status";
          break;
      }
      cerr << "Failed to attach to the transport. Status == "
           << status_str.c_str() << endl;
      exit(1);
    }

    // activate the listener
    DDS::DataWriterListener_var listener (new DataWriterListenerImpl);
    if (CORBA::is_nil (listener.in ())) {
      cerr << "listener is nil." << endl;
      exit(1);
    }

    // Create the datawriter
    DDS::DataWriterQos dw_qos;
    pub->get_default_datawriter_qos (dw_qos);
    // Make it KEEP_ALL history so we can verify the received
    // data without dropping.
    dw_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS;
    dw_qos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS;
    dw_qos.resource_limits.max_samples_per_instance = num_writes;

    DDS::DataWriter_var dw =
      pub->create_datawriter(topic.in (),
                             dw_qos,
                             listener.in ());
    if (CORBA::is_nil (dw.in ())) {
      cerr << "create_datawriter failed." << endl;
      exit(1);
    }
    Writer* writer = new Writer(dw.in());

    // Indicate that the publisher is ready
    FILE* writers_ready = ACE_OS::fopen (pub_ready_filename, "w");
    if (writers_ready == 0) {
      cerr << "ERROR Unable to create publisher ready file" << endl;
      exit(1);
    }
    ACE_OS::fclose(writers_ready);

    // Wait for the subscriber to be ready.
    FILE* readers_ready = 0;
    do {
      ACE_Time_Value small(0,250000);
      ACE_OS::sleep (small);
      readers_ready = ACE_OS::fopen (sub_ready_filename, "r");
    } while (0 == readers_ready);
    ACE_OS::fclose(readers_ready);

    // ensure the associations are fully established before writing.
    ACE_OS::sleep(3);
    writer->start ();
    while ( !writer->is_finished()) {
      ACE_Time_Value small(0,250000);
      ACE_OS::sleep (small);
    }

    // Indicate that the publisher is done
    FILE* writers_completed = ACE_OS::fopen (pub_finished_filename, "w");
    if (writers_completed == 0) {
      cerr << "ERROR Unable to i publisher completed file" << endl;
    } else {
      ACE_OS::fprintf (writers_completed, "%d\n",
                       writer->get_timeout_writes());
    }
    ACE_OS::fclose (writers_completed);

    // Wait for the subscriber to finish.
    FILE* readers_completed = 0;
    do {
      ACE_Time_Value small(0,250000);
      ACE_OS::sleep (small);
      readers_completed = ACE_OS::fopen (sub_finished_filename, "r");
    } while (0 == readers_completed);
    ACE_OS::fclose(readers_completed);

    writer->end ();
    delete writer;

    // Sleep a while before shutdown to avoid the problem of repository
    // crashes when it handles both remove_association from subscriber
    // and publisher at the same time.
    // Cleanup
    //ACE_OS::sleep (2);

    participant->delete_contained_entities();
    dpf->delete_participant(participant.in ());
    TheTransportFactory->release();
    TheServiceParticipant->shutdown ();
  } catch (CORBA::Exception& e) {
    cerr << "Exception caught in main.cpp:" << endl
         << e << endl;
    exit(1);
  }

  if (actual_lost_pub_notification != expected_lost_pub_notification)
  {
    ACE_ERROR ((LM_ERROR, "(%P|%t)ERROR: on_publication_lost called %d times "
      "and expected %d times\n", actual_lost_pub_notification,
      expected_lost_pub_notification));
    return 1;
  }

  if (num_deleted_connections != expected_deleted_connections)
  {
    ACE_ERROR ((LM_ERROR, "(%P|%t)ERROR: on_connection_deleted called %d times "
      "and expected %d times\n", num_deleted_connections,
      expected_deleted_connections));
    return 1;
  }

  return 0;
}
Exemple #8
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf =
        TheParticipantFactoryWithArgs (argc, argv);
      DDS::DomainParticipant_var participant =
        dpf->create_participant (411,
                                 PARTICIPANT_QOS_DEFAULT,
                                 DDS::DomainParticipantListener::_nil(),
                                 ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (participant.in ()))
      {
        cerr << "create_participant failed." << endl;
        return 1;
      }

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

      if (delete_data)
      {
        using OpenDDS::FileSystemStorage::Directory;
        Directory::create (ACE_TEXT_ALWAYS_CHAR (dir))->remove ();
        dpf->delete_participant (participant);
        TheServiceParticipant->shutdown ();
        return 0;
      }

      MessageTypeSupport_var servant = new MessageTypeSupportImpl ();

      if (DDS::RETCODE_OK != servant->register_type(participant.in (), ""))
      {
        cerr << "register_type failed." << endl;
        exit (1);
      }

      CORBA::String_var type_name = servant->get_type_name ();

      DDS::TopicQos topic_qos;
      participant->get_default_topic_qos (topic_qos);
      DDS::Topic_var topic =
        participant->create_topic ("Movie Discussion List",
                                   type_name.in (),
                                   topic_qos,
                                   DDS::TopicListener::_nil(),
                                   ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (topic.in ()))
      {
        cerr << "create_topic failed." << endl;
        exit (1);
      }

      DDS::Publisher_var pub =
        participant->create_publisher (PUBLISHER_QOS_DEFAULT,
                                       DDS::PublisherListener::_nil(),
                                       ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (pub.in ()))
      {
        cerr << "create_publisher failed." << endl;
        exit (1);
      }

      // Configure DataWriter QoS policies.
      DDS::DataWriterQos dw_qos;
      pub->get_default_datawriter_qos (dw_qos);
      dw_qos.durability.kind = DDS::PERSISTENT_DURABILITY_QOS;
      dw_qos.durability_service.history_kind = ::DDS::KEEP_ALL_HISTORY_QOS;
      dw_qos.reliability.kind  = ::DDS::RELIABLE_RELIABILITY_QOS;
      dw_qos.resource_limits.max_samples_per_instance = 1000;
      dw_qos.history.kind  = ::DDS::KEEP_ALL_HISTORY_QOS;

      // -------------------------------------------------------

      {
        DataWriterListenerImpl* listener = new DataWriterListenerImpl;
        DDS::DataWriterListener_var dwl = listener;

        // Create a DataWriter.

        // Upon exiting this scope, all unsent data should be
        // transferred to OpenDDS's data durability cache since the
        // run_test.pl script should not have started the subscriber
        // until it detects the "Done writing" log text.
        DDS::DataWriter_var dw =
          pub->create_datawriter (topic.in (),
                                  dw_qos,
                                  dwl.in (),
                                  ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
        if (CORBA::is_nil (dw.in ()))
        {
          cerr << "create_datawriter failed." << endl;
          exit (1);
        }

        // Only write samples if configured to do so.  The expectation
        // is to otherwise retrieve the data from the PERSISTENT data
        // durability cache.
        if (do_write)
        {
          // Write samples.
          std::auto_ptr<Writer> writer (new Writer (dw.in ()));

          if (!writer->start () || !writer->end ())
          {
            // Error logging performed in above method call.
            exit (1);
          }

          // Explicitly destroy the DataWriter.
          if (pub->delete_datawriter (dw.in ())
              == ::DDS::RETCODE_PRECONDITION_NOT_MET)
          {
            cerr << "Unable to delete DataWriter" << endl;
            exit (1);
          }
        }
        else
        {
          int const max_attempts = 50;
          int attempts;
          for (attempts = 1;
               attempts != max_attempts
                 && listener->publication_matched_.value () == false;
               ++attempts)
          {
            ACE_OS::sleep (5);
          }

          if (attempts == max_attempts)
          {
            cerr << "ERROR: subscriptions failed to match." << endl;
            exit (1);
          }

          // Wait for DataReader to finish.
          ::DDS::InstanceHandleSeq handles;
          for (attempts = 1; attempts != max_attempts; ++attempts)
          {
            dw->get_matched_subscriptions (handles);
            if (handles.length () == 0)
              break;
            else
              ACE_OS::sleep(1);
          }

          // The data durability cache should no longer contain samples
          // for this domain/topic/type.
        }
      }

      // -------------------------------------------------------

      {
        // Write samples that will not be sent.  Exercise
        // service_cleanup_delay.  We can either do this through the
        // durability member or durability_service member in either of
        // TopicQos or DataWriterQos.  This test arbitrarily uses the
        // DataWriterQos::durability_service member.

        // Cleanup data after this number of seconds.
        CORBA::Long const delay_seconds = 5;

        ::DDS::Duration_t & cleanup_delay =
          dw_qos.durability_service.service_cleanup_delay;
        cleanup_delay.sec     = delay_seconds;
        cleanup_delay.nanosec = 0;

        // Create a dummy topic which will have no subscriptions.
        DDS::Topic_var dummy_topic =
          participant->create_topic ("Dummy Topic",
                                     type_name.in (),
                                     topic_qos,
                                     DDS::TopicListener::_nil(),
                                     ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

        DDS::DataWriter_var dummy_dw =
          pub->create_datawriter (dummy_topic.in (),
                                  dw_qos,
                                  ::DDS::DataWriterListener::_nil (),
                                  ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
        if (CORBA::is_nil (dummy_dw.in ()))
        {
          cerr << "create_datawriter for dummy topic failed." << endl;
          exit (1);
        }

        // Write samples using multiple threads.
        std::auto_ptr<Writer> writer (new Writer (dummy_dw.in ()));

        // Explicitly destroy the DataWriter.
        if (pub->delete_datawriter (dummy_dw.in ())
            == ::DDS::RETCODE_PRECONDITION_NOT_MET)
        {
          cerr << "Unable to delete DataWriter" << endl;
          exit (1);
        }

        // Allow durability cleanup to occur
        ACE_OS::sleep (delay_seconds + 3);
      }

      participant->delete_contained_entities();
      dpf->delete_participant(participant.in ());
      TheServiceParticipant->shutdown ();
  } catch (CORBA::Exception& e) {
     cerr << "PUB: Exception caught in main.cpp:" << endl
          << e << endl;
      exit (1);
    }
  catch (const std::runtime_error& err) {
    ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: main() - %s\n"),
                      err.what()), -1);
  }

  return 0;
}