Example #1
0
DDS::DataWriter_var
OpenDDS::Model::Entities::writer(
  const OPENDDS_STRING& name,
  const OPENDDS_STRING& transportConfig)
{
  StringToDataWriterMap::const_iterator which
    = this->writerByString_.find( name);
  if( which != this->writerByString_.end()) {
    return DDS::DataWriter::_duplicate( which->second);
  }

  // See if there is a configuration profile for it.
  Config::WriterProfileMap::const_iterator where
    = this->config_.writerProfileMap().find( name);
  if( where == this->config_.writerProfileMap().end()) {
    ACE_ERROR((LM_ERROR,
      ACE_TEXT("(%P|%t) ERROR: Entities::writer() - ")
      ACE_TEXT("unable to find profile to configure ")
      ACE_TEXT("writer: [%C].\n"),
      name.c_str()
    ));
    return 0;
  }
  WriterProfile* profile = where->second;

  // Find the containing Publisher.
  DDS::Publisher_var publisher = this->publisher(profile->publisher,
                                                 transportConfig);
  if( !publisher) {
    ACE_ERROR((LM_ERROR,
      ACE_TEXT("(%P|%t) ERROR: Entities::writer() - ")
      ACE_TEXT("unable to find publisher: [%C] for writer [%C].\n"),
      profile->publisher.c_str(), name.c_str()
    ));
    return 0;
  }

  // We need the *name* of the participant in order to look up the Topic.
  // This should be Ok since we will only be configuring Writers that have
  // been successfully defined in a configuration file, implying that there
  // exists a defined [publisher] profile.
  Config::PublisherProfileMap::const_iterator location
    = this->config_.publisherProfileMap().find( profile->publisher);
  if( location == this->config_.publisherProfileMap().end()) {
    ACE_ERROR((LM_ERROR,
      ACE_TEXT("(%P|%t) ERROR: Entities::writer() - ")
      ACE_TEXT("unable to find profile to configure ")
      ACE_TEXT("publisher: [%C] for writer [%C].\n"),
      profile->publisher.c_str(), name.c_str()
    ));
    return 0;
  }
  PublisherProfile* publisherProfile = location->second;

  // Find the Topic.
  DDS::Topic_var topic
    = this->topic( profile->topic,
                   publisherProfile->participant,
                   transportConfig);
  if( !topic) {
    ACE_ERROR((LM_ERROR,
      ACE_TEXT("(%P|%t) ERROR: Entities::writer() - ")
      ACE_TEXT("unable to find topic: [%C] for writer [%C] in participant [%C].\n"),
      profile->topic.c_str(), name.c_str(),
      publisherProfile->participant.c_str()
    ));
    return 0;
  }

  DDS::DataWriterQos writerQos;
  DDS::TopicQos      topicQos;
  topic->get_qos( topicQos);
  publisher->get_default_datawriter_qos( writerQos);
  publisher->copy_from_topic_qos( writerQos, topicQos);
  profile->copyToWriterQos( writerQos);

  if( OpenDDS::DCPS::DCPS_debug_level>1) {
    ACE_DEBUG((LM_DEBUG,
      ACE_TEXT("(%P|%t) Entities::writer() - ")
      ACE_TEXT("Creating writer [%C] in publisher [%C] in participant [%C] ")
      ACE_TEXT("with topic [%C].\n"),
      name.c_str(),
      profile->publisher.c_str(),
      publisherProfile->participant.c_str(),
      profile->topic.c_str()
    ));
  }
  this->writerByString_[ name]
    = this->delegate_.createWriter(
        publisher,
        topic,
        writerQos,
        OpenDDS::DCPS::DEFAULT_STATUS_MASK,
        transportConfig
      );

  return this->writerByString_[ name];
}