当前位置: 首页>>代码示例>>C++>>正文


C++ dds::DataWriter_var类代码示例

本文整理汇总了C++中dds::DataWriter_var的典型用法代码示例。如果您正苦于以下问题:C++ DataWriter_var类的具体用法?C++ DataWriter_var怎么用?C++ DataWriter_var使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DataWriter_var类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

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;
}
开发者ID:FlavioFalcao,项目名称:DDS-1,代码行数:32,代码来源:Factory.cpp

示例2: ACE_TMAIN

int ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
  try {
    OpenDDS::Model::Application application(argc, argv);
    MessengerSimpleTypesLib::DefaultMessengerSimpleTypesType model(application, argc, argv);

    using OpenDDS::Model::MessengerSimpleTypesLib::Elements;

    DDS::DataWriter_var writer = model.writer( Elements::DataWriters::writer);

    // START OF EXISTING MESSENGER EXAMPLE CODE

    data1::MessageDataWriter_var message_writer =
      data1::MessageDataWriter::_narrow(writer.in());

    if (CORBA::is_nil(message_writer.in())) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                          ACE_TEXT(" _narrow failed!\n")),
                         -1);
    }

    OpenDDS::Model::WriterSync ws(writer);
    {
      // Write samples
      data1::Message message;
      message.subject_id = 99;

      message.from       = CORBA::string_dup("Comic Book Guy");
      message.subject    = CORBA::string_dup("Review");
      message.text       = CORBA::string_dup("Worst. Movie. Ever.");
      message.count      = 0;

      for (int i = 0; i < 10; i++) {
        DDS::ReturnCode_t error = message_writer->write(message, DDS::HANDLE_NIL);
        ++message.count;

        if (error != DDS::RETCODE_OK) {
          ACE_ERROR((LM_ERROR,
                     ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                     ACE_TEXT(" write returned %d!\n"), error));
        }
      }
    }

    // END OF EXISTING MESSENGER EXAMPLE CODE
  } catch (const CORBA::Exception& e) {
    e._tao_print_exception("Exception caught in main():");
    return -1;

  } catch( const std::exception& ex) {
    ACE_ERROR_RETURN((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                      ACE_TEXT(" Exception caught: %C\n"),
                      ex.what()),
                     -1);
  }

  return 0;
}
开发者ID:CapXilinx,项目名称:OpenDDS,代码行数:60,代码来源:publisher.cpp

示例3:

 void
 connector_status_exec_i::on_unexpected_status (::DDS::Entity_ptr the_entity,
 ::DDS::StatusKind status_kind)
 {
   if (!CORBA::is_nil (the_entity) &&
       status_kind == DDS::PUBLICATION_MATCHED_STATUS)
     {
       ::DDS::PublicationMatchedStatus_var stat;
       DDS::DataWriter_var wr = ::DDS::DataWriter::_narrow (the_entity);
       if(::CORBA::is_nil (wr.in ()))
         {
           throw ::CORBA::INTERNAL ();
         }
       ::DDS::ReturnCode_t retval =
                         wr->get_publication_matched_status (stat.out ());
       if (retval == ::DDS::RETCODE_OK)
         {
           if (stat.in ().current_count >= this->number_of_subscribers_ &&
               !this->started_.value ())
             {
               ACE_DEBUG ((LM_DEBUG, "ConnectorStatusListener_exec_i::on_unexpected_status - "
                         "on_publication_matched status received. Starting application\n"));
               this->started_ = true;
               this->callback_.start ();
             }
         }
     }
 }
开发者ID:DOCGroup,项目名称:CIAO,代码行数:28,代码来源:Throughput_Sender_exec.cpp

示例4:

DDS::DataWriter_ptr
MonitorFactoryImpl::create_data_writer(DDS::DomainParticipant_ptr participant,
                                       DDS::Publisher_ptr publisher,
                                       const char* type_name,
                                       const char* topic_name,
                                       const DDS::DataWriterQos& dw_qos)
{
  DDS::Topic_var topic =
    participant->create_topic(topic_name,
                              type_name,
                              TOPIC_QOS_DEFAULT,
                              DDS::TopicListener::_nil(),
                              OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  if (CORBA::is_nil(topic)) {
    ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::create_data_writer(): Failed to create topic, name = %s\n", topic_name));
  }
  DDS::DataWriter_var writer =
    publisher->create_datawriter(topic.in(),
                                 dw_qos,
                                 DDS::DataWriterListener::_nil(),
                                 OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  if (CORBA::is_nil(writer)) {
    ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::create_data_writer(): Failed to create data writer\n"));
  }

  return writer._retn();
}
开发者ID:AndroidDev77,项目名称:OpenDDS,代码行数:27,代码来源:MonitorFactoryImpl.cpp

示例5: if

int
OpenDDS::Model::WriterSync::wait_unmatch(const DDS::DataWriter_var& writer,
                                         unsigned int num_readers)
{
  DDS::ReturnCode_t stat;
  DDS::StatusCondition_var condition = writer->get_statuscondition();
  condition->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS);
  DDS::WaitSet_var ws = new DDS::WaitSet;
  ws->attach_condition(condition);
  DDS::ConditionSeq conditions;
  DDS::PublicationMatchedStatus ms = { 0, 0, 0, 0, 0 };
  DDS::Duration_t timeout = { 1, 0 };
  do {
    if (DCPS_debug_level > 4) {
      ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: pub checking unmatched\n")));
    }
    stat = writer->get_publication_matched_status(ms);
    if (stat != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((
                  LM_ERROR,
                  ACE_TEXT("(%P|%t) ERROR: %N:%l: wait_unmatch() -")
                  ACE_TEXT(" get_publication_matched_status failed!\n")),
                 -1);
    } else if (ms.current_count == 0 && (unsigned int)ms.total_count >= num_readers) {
      if (DCPS_debug_level > 4) {
        ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: pub match count %d total count %d\n"),
                                       ms.current_count, ms.total_count));
      }
      break;  // unmatched
    }
    if (DCPS_debug_level > 4) {
      ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: pub match count %d total count %d\n"),
                                     ms.current_count, ms.total_count));
    }
    // wait for a change
    stat = ws->wait(conditions, timeout);
    if ((stat != DDS::RETCODE_OK) && (stat != DDS::RETCODE_TIMEOUT)) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("(%P|%t) ERROR: %N:%l: wait_unmatch() -")
                        ACE_TEXT(" wait failed!\n")),
                       -1);
    }
  } while (true);
  ws->detach_condition(condition);
  if (DCPS_debug_level > 4) {
    ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: pub unmatched\n")));
  }
  return 0;
}
开发者ID:oschwaldp-oci,项目名称:OpenDDS,代码行数:49,代码来源:Sync.cpp

示例6:

int
OpenDDS::Model::WriterSync::wait_ack(const DDS::DataWriter_var& writer)
{
  DDS::ReturnCode_t stat;
  DDS::Duration_t timeout = { 30, 0 };
  if (DCPS_debug_level > 4) {
    ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: waiting for acks\n")));
  }
  stat = writer->wait_for_acknowledgments(timeout);
  if ((stat != DDS::RETCODE_OK) && (stat != DDS::RETCODE_TIMEOUT)) {
    ACE_ERROR_RETURN((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: %N:%l: wait_ack() -")
                      ACE_TEXT(" wait_for_acknowledgments failed!\n")),
                     -1);
  }
  if (DCPS_debug_level > 4) {
    ACE_DEBUG((LM_NOTICE, ACE_TEXT("WriterSync: acks received\n")));
  }
  return 0;
}
开发者ID:oschwaldp-oci,项目名称:OpenDDS,代码行数:20,代码来源:Sync.cpp

示例7: main

int main(int argc, char** args){
  std::cout << "Welcome to userqos stress test" << std::endl;
  enum {PUBLISHER, SUBSCRIBER} mode;
  if(argc != 2 || !(*args[1] == 'p' || *args[1] == 's')){
      printf("Usage: %s (p|s)\n"
             " p - Publisher\n"
             " s - Subscriber\n",args[0]);
      exit(EXIT_FAILURE);
  } else if(*args[1] == 'p'){
      mode = PUBLISHER;
  } else if(*args[1] == 's'){
      mode = SUBSCRIBER;
  } else {
      printf("Should never reach this state.\n");
      exit(EXIT_FAILURE);
  }

  DDS::ReturnCode_t retval;
  DDS::InstanceHandle_t handle;
  
  DDS::DomainParticipantFactory_ptr dpf = DDS::DomainParticipantFactory::get_instance();
  assert( NULL != dpf);

  DDS::DomainParticipantQos participant_qos;
  retval = dpf->get_default_participant_qos(participant_qos);
  assert( DDS::RETCODE_OK == retval );
  DDS::DomainId_t domain = NULL;
  DDS::DomainParticipant_var participant = dpf->create_participant(domain,
                                                                   PARTICIPANT_QOS_DEFAULT,
                                                                   NULL,
                                                                   DDS::STATUS_MASK_NONE);
  assert( NULL != participant.in() );

  /**
    Magical key definitions. If you want the idlpp to generate TypeSupport you MUST,
    I repeat, MUST, add #pragma. Why would you ever NOT want the TypeSupport? Who knows.
    OpenSplice_PreProcessor_usermanual.pdf , Section: 1.5.1 KeyDefinitions
  **/
  // Memory leak: I cannot seem to free pid_ts. Delete is blocked nor can I find _release per the docs
  PID::PresenceTypeSupport_ptr pid_ts = new PID::PresenceTypeSupport();
  assert( NULL != pid_ts );
  retval = pid_ts->register_type(participant, pid_ts->get_type_name());
  assert ( DDS::RETCODE_OK == retval );

  DDS::TopicQos topic_qos;
  retval = participant->get_default_topic_qos(topic_qos);
  assert( DDS::RETCODE_OK == retval );

  DDS::Topic_var presence_topic = participant->create_topic("presence",
                                                            pid_ts->get_type_name(),
                                                            topic_qos,
                                                            NULL,
                                                            DDS::STATUS_MASK_NONE); 
  assert( NULL != presence_topic.in() );

  /**
     Publisher code
  **/
  if(mode == PUBLISHER){
      DDS::PublisherQos publisher_qos;
      retval = participant->get_default_publisher_qos(publisher_qos);
      assert( DDS::RETCODE_OK == retval );
      DDS::Publisher_var publisher = participant->create_publisher(publisher_qos,
                                                                   NULL,
                                                                   DDS::STATUS_MASK_NONE);
      assert( NULL != publisher.in() );

      /**
        PID Data Writer
      **/
      DDS::DataWriterQos dw_qos;
      retval = publisher->get_default_datawriter_qos(dw_qos);
      assert( DDS::RETCODE_OK == retval );
      const char* msg = "HI THERE COWBOY";
      dw_qos.user_data.value = DDS_DCPSUFLSeq<unsigned char, DDS::octSeq_uniq_>(msg);
      assert( strlen(msg) == dw_qos.user_data.value.length() );
      
      DDS::DataWriter_var writer = publisher->create_datawriter(presence_topic, dw_qos, NULL, DDS::STATUS_MASK_NONE); 
      assert( NULL != writer.in() );
      PID::PresenceDataWriter_var presence_writer = PID::PresenceDataWriter::_narrow(writer);
      assert( NULL != presence_writer.in() );

      PID::Presence temp_presence;
      temp_presence.pid = 100;
      temp_presence.hostname = "my_machine";
      //handle = presence_writer->register_instance(temp_presence);
      //assert( DDS::HANDLE_NIL != handle );
      handle = DDS::HANDLE_NIL;

      // std::cout << "LOOPING" << std::endl;
      // while(shutdown_flag == 0){
        retval = presence_writer->write(temp_presence,handle);
        assert( DDS::RETCODE_OK == retval );
      //  usleep(50);
      //}
  }
  /**
    Subscriber
  **/
  else if(mode == SUBSCRIBER){
//.........这里部分代码省略.........
开发者ID:xrl,项目名称:osplstress,代码行数:101,代码来源:userqos.cpp

示例8: ACE_TMAIN

int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize DomainParticipantFactory
    DDS::DomainParticipantFactory_var dpf =
      TheParticipantFactoryWithArgs(argc, argv);

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

    TheServiceParticipant->monitor_factory_->initialize();

    // Create DomainParticipant
    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())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_participant failed!\n")),
                       -1);
    }

    // Register TypeSupport (Messenger::Message)
    Messenger::MessageTypeSupport_var mts =
      new Messenger::MessageTypeSupportImpl();

    if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: register_type failed!\n")),
                       -1);
    }

    // Create Topic
    DDS::Topic_var topic =
      participant->create_topic("Movie Discussion List",
                                mts->get_type_name(),
                                TOPIC_QOS_DEFAULT,
                                DDS::TopicListener::_nil(),
                                OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(topic.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_topic failed!\n")),
                       -1);
    }

    // Create Publisher
    DDS::Publisher_var pub =
      participant->create_publisher(PUBLISHER_QOS_DEFAULT,
                                    DDS::PublisherListener::_nil(),
                                    OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(pub.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_publisher failed!\n")),
                       -1);
    }

    // Create DataWriter
    DDS::DataWriter_var dw =
      pub->create_datawriter(topic.in(),
                             DATAWRITER_QOS_DEFAULT,
                             DDS::DataWriterListener::_nil(),
                             OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(dw.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_datawriter failed!\n")),
                       -1);
    }

    // Start writing threads
    Writer* writer = new Writer(dw.in());
    writer->start();

    while (!writer->is_finished()) {
      ACE_Time_Value small_time(0, 250000);
      ACE_OS::sleep(small_time);
    }

    writer->end();
    delete writer;

    // Clean-up!
    participant->delete_contained_entities();
    dpf->delete_participant(participant.in());

    TheServiceParticipant->shutdown();

  } catch (const CORBA::Exception& e) {
    e._tao_print_exception("Exception caught in main():");
//.........这里部分代码省略.........
开发者ID:AndroidDev77,项目名称:OpenDDS,代码行数:101,代码来源:publisher.cpp

示例9: ACE_TMAIN

int ACE_TMAIN (int argc, ACE_TCHAR *argv[]){
  try
    {
      DDS::DomainParticipantFactory_var dpf =
        TheParticipantFactoryWithArgs(argc, argv);

      DDS::DomainParticipant_var participant =
        dpf->create_participant(311,
                                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::PublisherQos pub_qos;
      participant->get_default_publisher_qos (pub_qos);

      pub_qos.partition.name.length (1);
      pub_qos.partition.name[0] = PARTITION_A;

      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);
      }

      // ----------------------------------------------
      // Create DataWriter which is belongs to PARTITION_A
      DDS::DataWriter_var dw =
        pub->create_datawriter (topic.in (),
                                DATAWRITER_QOS_DEFAULT,
                                DDS::DataWriterListener::_nil (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      int const max_attempts = 15;
      int attempts = 1;

      // ----------------------------------------------
      // Wait for first DataReader that belongs to PARTITION_A too,
      // then write samples.

      // cache handle for first reader.
      ::DDS::InstanceHandle_t handle = -1;
      {
        std::auto_ptr<Writer> writer (new Writer (dw.in ()));

        cout << "Pub waiting for match on A partition." << std::endl;
        if (OpenDDS::Model::WriterSync::wait_match(dw)) {
          cerr << "Error waiting for match on A partition" << std::endl;
          return 1;
        }
        while (attempts != max_attempts)
        {

          ::DDS::InstanceHandleSeq handles;
          dw->get_matched_subscriptions(handles);
          cout << "Pub matched " << handles.length() << " A subs." << std::endl;
          if (handles.length() == 1)
          {
            handle = handles[0];
            break;
          }
          else
            ACE_OS::sleep(1);
          ++attempts;
        }

        if (attempts == max_attempts)
        {
          cerr << "ERROR: failed to wait for first DataReader." << endl;
          exit (1);
        }

        writer->start ();
//.........这里部分代码省略.........
开发者ID:FlavioFalcao,项目名称:DDS-1,代码行数:101,代码来源:publisher.cpp

示例10: ACE_TMAIN

int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int status = 0;

  try {
    // Initialize DomainParticipantFactory
    DDS::DomainParticipantFactory_var dpf =
      TheParticipantFactoryWithArgs(argc, argv);

    bool reliable = true;
    int num_msgs = 10;
    int my_pid = ACE_OS::getpid();

    parse_args(argc, argv, reliable, num_msgs, my_pid);

    // Create DomainParticipant
    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())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_participant failed!\n")),
                       -1);
    }

    // Register TypeSupport (Messenger::Message)
    Messenger::MessageTypeSupport_var mts =
      new Messenger::MessageTypeSupportImpl();

    if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: register_type failed!\n")),
                       -1);
    }

    // Create Topic
    CORBA::String_var type_name = mts->get_type_name();
    DDS::Topic_var topic =
      participant->create_topic("Movie Discussion List",
                                type_name.in(),
                                TOPIC_QOS_DEFAULT,
                                DDS::TopicListener::_nil(),
                                OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(topic.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_topic failed!\n")),
                       -1);
    }

    // Create Publisher
    DDS::Publisher_var pub =
      participant->create_publisher(PUBLISHER_QOS_DEFAULT,
                                    DDS::PublisherListener::_nil(),
                                    OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(pub.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_publisher failed!\n")),
                       -1);
    }

    DDS::DataWriterQos qos;
    pub->get_default_datawriter_qos(qos);
    qos.liveliness.kind = DDS::AUTOMATIC_LIVELINESS_QOS;
    qos.liveliness.lease_duration.sec = 5;
    qos.liveliness.lease_duration.nanosec = 0;
    qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;
    qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_QOS;

    // Create DataWriter
    DDS::DataWriter_var dw =
      pub->create_datawriter(topic.in(),
                             qos,
                             DDS::DataWriterListener::_nil(),
                             OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(dw.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_datawriter failed!\n")),
                       -1);
    }

    DDS::DataWriter_var dw2 =
      pub->create_datawriter(topic.in(),
                             qos,
                             DDS::DataWriterListener::_nil(),
                             OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(dw2.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
//.........这里部分代码省略.........
开发者ID:shaominghaoo,项目名称:OpenDDS,代码行数:101,代码来源:publisher.cpp

示例11: ACE_TMAIN

int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  DDS::DomainParticipantFactory_var dpf;
  DDS::DomainParticipant_var participant;

  try {

    std::cout << "Starting publisher" << std::endl;
    {
      // Initialize DomainParticipantFactory
      dpf = TheParticipantFactoryWithArgs(argc, argv);

      std::cout << "Starting publisher with " << argc << " args" << std::endl;
      int error;
      if ((error = parse_args(argc, argv)) != 0) {
        return error;
      }

      // Create DomainParticipant
      participant = dpf->create_participant(4,
                                PARTICIPANT_QOS_DEFAULT,
                                DDS::DomainParticipantListener::_nil(),
                                OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      if (CORBA::is_nil(participant.in())) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("%N:%l: main()")
                          ACE_TEXT(" ERROR: create_participant failed!\n")),
                         -1);
      }

      // Register TypeSupport (Messenger::Message)
      Messenger::MessageTypeSupport_var mts =
        new Messenger::MessageTypeSupportImpl();

      if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("%N:%l: main()")
                          ACE_TEXT(" ERROR: register_type failed!\n")),
                         -1);
      }

      // Create Topic
      CORBA::String_var type_name = mts->get_type_name();
      DDS::Topic_var topic =
        participant->create_topic("Movie Discussion List",
                                  type_name.in(),
                                  TOPIC_QOS_DEFAULT,
                                  DDS::TopicListener::_nil(),
                                  OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      if (CORBA::is_nil(topic.in())) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("%N:%l: main()")
                          ACE_TEXT(" ERROR: create_topic failed!\n")),
                         -1);
      }

      // Create Publisher
      DDS::Publisher_var pub =
        participant->create_publisher(PUBLISHER_QOS_DEFAULT,
                                      DDS::PublisherListener::_nil(),
                                      OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      if (CORBA::is_nil(pub.in())) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("%N:%l: main()")
                          ACE_TEXT(" ERROR: create_publisher failed!\n")),
                         -1);
      }

      DDS::DataWriterQos qos;
      pub->get_default_datawriter_qos(qos);
      if (dw_reliable()) {
        std::cout << "Reliable DataWriter" << std::endl;
        qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;
        qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
      }

      // Create DataWriter
      DDS::DataWriter_var dw =
        pub->create_datawriter(topic.in(),
                               qos,
                               DDS::DataWriterListener::_nil(),
                               OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      if (CORBA::is_nil(dw.in())) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("%N:%l: main()")
                          ACE_TEXT(" ERROR: create_datawriter failed!\n")),
                         -1);
      }

      // Start writing threads
      std::cout << "Creating Writer" << std::endl;
      Writer* writer = new Writer(dw.in());
      std::cout << "Starting Writer" << std::endl;
      writer->start();

      while (!writer->is_finished()) {
//.........这里部分代码省略.........
开发者ID:bbidulock,项目名称:DDS,代码行数:101,代码来源:publisher.cpp

示例12: ACE_TMAIN

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) == -1) {
        return -1;
      }

      {
        // At this point we are connected to the Info Repo.
        // Trigger the driver
        std::ofstream ior_stream (driver_trigger.c_str());
        if (!ior_stream) {
          std::cerr << "Unable to open internal trigger file: "
                    << driver_trigger << std::endl;
          return -1;
        }
        ior_stream << "junk";
      }

      int max_wait_time = 30; //seconds
      int count = 0;
      while (true)
      {
        if (count > max_wait_time) {
          std::cerr << "Timed out waiting for external file: "
                    << publisher_trigger << std::endl;
          return -1;
        }

        // check for file
        ACE_stat my_stat;
        if (ACE_OS::stat (publisher_trigger.c_str(), &my_stat) == 0) {
          // found the trigger file.
          break;
        }

        ACE_OS::sleep (1);
      }

      MessageTypeSupportImpl* servant = new 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(),
                                   ::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 datawriter
      DDS::DataWriterQos dw_qos;
      pub->get_default_datawriter_qos (dw_qos);
      DDS::DataWriter_var dw =
        pub->create_datawriter(topic.in (),
                               dw_qos,
                               DDS::DataWriterListener::_nil(),
                               ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dw.in ())) {
        cerr << "create_datawriter failed." << endl;
        exit(1);
      }
      Writer* writer = new Writer(dw.in());

      writer->start ();
      while ( !writer->is_finished()) {
        ACE_Time_Value small_time(0,250000);
//.........这里部分代码省略.........
开发者ID:stonejiang208,项目名称:OpenDDS,代码行数:101,代码来源:publisher.cpp

示例13: BadSyncException

void
Publisher::run()
{
  DDS::Duration_t   timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC};
  DDS::ConditionSeq conditions;
  DDS::PublicationMatchedStatus matches = { 0, 0, 0, 0, 0};
  const int readers_per_publication = 2;
  unsigned int cummulative_count = 0;
  do {
    if( this->options_.verbose()) {
      ACE_DEBUG((LM_DEBUG,
        ACE_TEXT("(%P|%t) Publisher::run() - ")
        ACE_TEXT("%d of %d subscriptions attached, waiting for more.\n"),
        cummulative_count,
        this->publications_.size()*readers_per_publication
      ));
    }
    if( DDS::RETCODE_OK != this->waiter_->wait( conditions, timeout)) {
      ACE_ERROR((LM_ERROR,
        ACE_TEXT("(%P|%t) ERROR: Publisher::run() - ")
        ACE_TEXT("failed to synchronize at start of test.\n")
      ));
      throw BadSyncException();
    }
    for( unsigned long index = 0; index < conditions.length(); ++index) {
      DDS::StatusCondition_var condition
        = DDS::StatusCondition::_narrow( conditions[ index].in());

      DDS::Entity_var writer_entity = condition->get_entity();
      DDS::DataWriter_var writer = DDS::DataWriter::_narrow( writer_entity);
      if( !CORBA::is_nil( writer.in())) {
        DDS::StatusMask changes = writer->get_status_changes();
        if( changes & DDS::PUBLICATION_MATCHED_STATUS) {
          if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK)
          {
            ACE_ERROR ((LM_ERROR,
              "ERROR: failed to get publication matched status\n"));
            ACE_OS::exit (1);
          }
          cummulative_count += matches.current_count_change;
        }
      }
    }

  // We know that there are 2 subscriptions matched with each publication.
  } while( cummulative_count < (readers_per_publication*this->publications_.size()));

  // Kluge to bias the race between BuiltinTopic samples and application
  // samples towards the BuiltinTopics during association establishment.
  // ACE_OS::sleep( 2);

  if( this->options_.verbose()) {
    ACE_DEBUG((LM_DEBUG,
      ACE_TEXT("(%P|%t) Publisher::run() - ")
      ACE_TEXT("starting to publish samples with %d matched subscriptions.\n"),
      cummulative_count
    ));
  }

  for( unsigned int index = 0; index < this->publications_.size(); ++index) {
    this->publications_[ index]->start();
  }

  // Allow some traffic to occur before making any wait() calls.
  ACE_OS::sleep( 2);

  ::DDS::Duration_t delay = { 5, 0 }; // Wait for up to 5 seconds.
  if (this->options_.publisher())
  {
    DDS::ReturnCode_t error =
      this->publisher_->wait_for_acknowledgments(delay);
    if (error != DDS::RETCODE_OK)
    {
      ACE_DEBUG((LM_DEBUG,
        ACE_TEXT("(%P|%t) ERROR: Publisher::run() - ")
        ACE_TEXT("publisher wait failed with code: %d.\n"),
        error));
      ++this->status_;
    }
  }
  else
  {
    for( unsigned int index = 0; index < this->publications_.size(); ++index) {
      // First wait on this writer.
      ::DDS::ReturnCode_t result
        = this->publications_[ index]->wait_for_acks( delay);
      if( result != ::DDS::RETCODE_OK) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) ERROR: Publisher::run() - ")
          ACE_TEXT("publication %d wait failed with code: %d.\n"),
          index,
          result
        ));
        ++this->status_;
      }
    }
  }

  // Signal the writers to terminate.
  for( unsigned int index = 0; index < this->publications_.size(); ++index) {
//.........这里部分代码省略.........
开发者ID:tornadoxutao,项目名称:OpenDDS,代码行数:101,代码来源:Publisher.cpp

示例14: main

int main (int argc, char *argv[]) {
  try {
    DDS::DomainParticipantFactory_var dpf =
      TheParticipantFactoryWithArgs(argc, argv);
    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;
    }

    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());
    if (CORBA::is_nil (topic.in ())) {
      cerr << "create_topic failed." << endl;
      exit(1);
    }

    OpenDDS::DCPS::TransportImpl_rch tcp_impl =
      TheTransportFactory->create_transport_impl (TCP_IMPL_ID, 
                                                  ::OpenDDS::DCPS::AUTO_CONFIG);

    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);
    }

    // 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,
                             DDS::DataWriterListener::_nil());
    if (CORBA::is_nil (dw.in ())) {
      cerr << "create_datawriter failed." << endl;
      exit(1);
    }
    Writer* writer = new Writer(dw.in());

    writer->start ();
    while ( !writer->is_finished()) {
      ACE_Time_Value small(0,250000);
      ACE_OS::sleep (small);
    }

    // Cleanup
    writer->end ();
    delete writer;
    participant->delete_contained_entities();
    dpf->delete_participant(participant.in ());
//.........这里部分代码省略.........
开发者ID:svn2github,项目名称:OpenDDS,代码行数:101,代码来源:publisher.cpp

示例15: ACE_TMAIN

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);
//.........这里部分代码省略.........
开发者ID:Fantasticer,项目名称:OpenDDS,代码行数:101,代码来源:Publisher.cpp


注:本文中的dds::DataWriter_var类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。