Esempio n. 1
0
int
Writer::svc ()
{
    ACE_DEBUG((LM_DEBUG,
               ACE_TEXT("(%P|%t) Writer::svc() - ")
               ACE_TEXT("processing publication %d.\n"),
               this->index_
              ));

    int count = 0;
    Test::DataDataWriter_var dataWriter
        = Test::DataDataWriter::_narrow( this->writer_.in());
    while( this->done_ == false) {
        Test::Data sample;
        sample.pid = this->index_;
        sample.seq = ++count;

        dataWriter->write( sample, DDS::HANDLE_NIL);
        ++this->messages_;

        ACE_Time_Value interval( 0, 1000); // 1 mS == 1000 samples per second.

        if( this->verbose_ && BE_REALLY_VERBOSE) {
            ACE_DEBUG((LM_DEBUG,
                       ACE_TEXT("(%P|%t) Writer::svc() - ")
                       ACE_TEXT("publication %d wrote sample %d, ")
                       ACE_TEXT("waiting %d microseconds to send next one.\n"),
                       this->index_,
                       count,
                       interval.usec()
                      ));
        }

        // Wait before sending the next message.
        ACE_OS::sleep( interval);
    }

    ::DDS::Duration_t shutdownDelay = { 15, 0 }; // Wait for up to 15 seconds.
    ::DDS::ReturnCode_t result
        = this->writer_->wait_for_acknowledgments( shutdownDelay);
    if( result != ::DDS::RETCODE_OK) {
        ACE_DEBUG((LM_DEBUG,
                   ACE_TEXT("(%P|%t) ERROR: Writer::svc() - ")
                   ACE_TEXT("publication %d wait failed with code: %d while terminating.\n"),
                   this->index_,
                   result
                  ));
        ++this->status_;
    }

    if( this->verbose_) {
        ACE_DEBUG((LM_DEBUG,
                   ACE_TEXT("(%P|%t) Writer::svc() - ")
                   ACE_TEXT("publication %d honoring termination request, ")
                   ACE_TEXT("stopping thread.\n"),
                   this->index_
                  ));
    }
    return 0;
}
Esempio n. 2
0
int
Writer::svc ()
{
  ACE_DEBUG((LM_DEBUG,
    ACE_TEXT("(%P|%t) Writer::svc() - ")
    ACE_TEXT("processing publication %C.\n"),
    this->profile_.name().c_str()
  ));

  int count = 0;
  while( this->done_ == false) {
    Test::DataDataWriter_var dataWriter
      = Test::DataDataWriter::_narrow( this->writer_.in());
    Test::Data sample;
    sample.priority = this->profile_.priority();
    sample.seq      = ++count;
    sample.pid      = this->publicationId_;
    sample.buffer.length( this->profile_.messageSize());

    dataWriter->write( sample, DDS::HANDLE_NIL);
    ++this->messages_;

    // Determine the interval to next message here so it can be mentioned
    // in the diagnostic messsage.  Note that this results in an
    // End-to-Start delay which will give slightly different results from
    // the Start-to-Start delay assumed when generating the intervals.
    ACE_Time_Value interval( 0, this->profile_.interval());

    if( this->verbose_ && BE_REALLY_VERBOSE) {
      ACE_DEBUG((LM_DEBUG,
        ACE_TEXT("(%P|%t) Writer::svc() - ")
        ACE_TEXT("publication %C wrote sample %d at priority %d, ")
        ACE_TEXT("waiting %d microseconds to send next one.\n"),
        this->profile_.name().c_str(),
        count,
        this->profile_.priority(),
        interval.usec()
      ));
    }

    // Wait before sending the next message.
    ACE_OS::sleep( interval);
  }

  if( this->verbose_) {
    ACE_DEBUG((LM_DEBUG,
      ACE_TEXT("(%P|%t) Writer::svc() - ")
      ACE_TEXT("publication %C honoring termination request, ")
      ACE_TEXT("stopping thread.\n"),
      this->profile_.name().c_str()
    ));
  }
  return 0;
}
Esempio n. 3
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;
}