StartLineProcessConnector::~StartLineProcessConnector() {
    DDSDomainParticipant *participant = RTIConnector::getParticipant();
    DDS_ReturnCode_t retcode;


    if (NULL != m_reader_cache) {
        if (DDS_RETCODE_OK != RTIConnector::getSubscriber()->delete_datareader(m_reader_cache)) {

            g_cSystemLogger.LogMessage("(%s:%s(:%d))::Unable to delete m_reader_cache \n", LOG_LOCATION);
        }
        m_reader_cache = NULL;
    }
    if (NULL != m_read_topic) {
        if (DDS_RETCODE_OK != participant->delete_topic(m_read_topic)) {

            g_cSystemLogger.LogMessage("(%s:%s(:%d))::Unable to delete m_read_topic \n", LOG_LOCATION);
        }
        m_read_topic = NULL;
    }

    // Un-register the type...
    if ((NULL != participant) && (NULL != m_type_name_cache)) {
        retcode = MONITORING::leaseProcessStartTypeSupport::unregister_type(participant, m_type_name_cache);
        if (retcode != DDS_RETCODE_OK) {

            g_cSystemLogger.LogMessage("(%s:%s(:%d))::Error ---> RTCConnector() unregister_type RTC error \n", LOG_LOCATION);
        }
        m_type_name_cache = NULL;
    }
    pt_rtc = 0;

    return;
}
Beispiel #2
0
	int dispose(){

	DDS_ReturnCode_t retCode;
    int status = 0;

    if (participant != NULL) {
        retCode = participant->delete_contained_entities();
        if (retCode != DDS_RETCODE_OK) {
            printf("delete_contained_entities error %d\n", retCode);
            status = -1;
        }

        retCode = DDSTheParticipantFactory->delete_participant(participant);
        if (retCode != DDS_RETCODE_OK) {
            printf("delete_participant error %d\n", retCode);
            status = -1;
        }
    }

    /* Release memory associated with participant factory */
    retCode = DDSDomainParticipantFactory::finalize_instance();
    if (retCode != DDS_RETCODE_OK) {
        printf("finalize_instance error %d\n", retCode);
        status = -1;
    }

	std::cout<<"\n All entities deleted successfully !";
    return status;

	}
  void
  Component_exec_i::check_domain_id (DDSPublisher * pub)
  {
#if (CIAO_DDS4CCM_NDDS == 1)
    DDSDomainParticipant * part = pub->get_participant ();
    if (part->get_domain_id () != DOMAIN_ID_IN_DP)
      {
        ACE_ERROR ((LM_ERROR, "Component_exec_i::check_domain_id - "
                              "ERROR: Domain ID not set properly: "
                              "expected <%u> - retrieved <%u>\n",
                              DOMAIN_ID_IN_DP,
                              part->get_domain_id ()));
      }
    else
      {
        ACE_DEBUG ((LM_DEBUG, "Component_exec_i::check_domain_id - "
                              "Domain ID set properly.\n"));
      }
#else
    ACE_UNUSED_ARG (pub);
#endif
  }
StartLineProcessConnector::StartLineProcessConnector(const char* rd_topic) {
    DDS_ReturnCode_t retcode_cache;
    DDSDomainParticipant *participant = RTIConnector::getParticipant();
    m_read_topic = NULL;
    pt_rtc = NULL;
    m_reader_cache = NULL;

    if (rd_topic == NULL) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->rd_topic is NULL \n", LOG_LOCATION);
        return;
    }
    if (participant == NULL) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->Participant is NULL \n", LOG_LOCATION);
        return;
    }

    /* Register the type before creating the topic for RTC */
    m_type_name_cache = MONITORING::leaseProcessStartTypeSupport::get_type_name();
    retcode_cache = MONITORING::leaseProcessStartTypeSupport::register_type(participant, m_type_name_cache);
    if (retcode_cache != DDS_RETCODE_OK) {
        g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->Register Type RTC ERROR \n", LOG_LOCATION);
        m_type_name_cache = NULL;
        return;
    }
    if (NULL == m_read_topic) {
        /* To customize the topic QoS, use the configuration file USER_QOS_PROFILES.xml */
        m_read_topic = participant->create_topic(rd_topic, m_type_name_cache, DDS_TOPIC_QOS_DEFAULT, NULL /* listener */
                , DDS_STATUS_MASK_NONE);
        if (m_read_topic == NULL) {
            g_cSystemLogger.LogMessage("(%s:%s:%d):: Error --->create topic success is NULL \n", LOG_LOCATION);
            return;
        }
    }
    g_cSystemLogger.LogMessage("(%s:%s:%d)::  --->create topic success \n", LOG_LOCATION);

}
Beispiel #5
0
	int initialise(){

		
		/* To customize the participant QoS, use 
       the configuration file USER_QOS_PROFILES.xml */    
    participant = DDSTheParticipantFactory->
            create_participant_from_config(
                                    "MyParticipantLibrary::SubscriptionParticipant");
    if (participant == NULL) {
        printf("create_participant_from_config error\n");
        return -1;
    }
	else
	{
		std::cout<<"\n Subscriber initialised successfully !"<<std::endl;
		subscriber=participant->lookup_subscriber_by_name("MySubscriber");
		if (subscriber == NULL) {
        printf("lookup_subscriber_by_name error\n");
        return -1;
		}
	}
	}
Beispiel #6
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
    DDS_ReturnCode_t    retcode;
    DDSTopic*           topic = 0;
    DDSDataWriter*      data_writer = 0;
    DDSPublisher*       publisher = 0;
    int                 main_result = 1; /* error by default */

//     NDDS_Config_LogVerbosity n_verbosity =
//       static_cast <NDDS_Config_LogVerbosity> (3);
//     NDDSConfigLogger::get_instance()->set_verbosity (n_verbosity);
    const ACE_TCHAR * env_domain_id = 0;
    if (argc > 1)
    {
        env_domain_id = argv[1];
    }
    if (!env_domain_id)
    {
        printf ("Environment variable DEFAULT_DOMAIN_ID not set "
                "=> setting it to 2\n");
        env_domain_id = "2";
    }
    else
        printf ("Domain ID set to %s\n", env_domain_id);

    const int domain_id = ACE_OS::atoi (env_domain_id);

    DDSDomainParticipant *participant = DDSDomainParticipantFactory::get_instance()->
                                        create_participant_with_profile (domain_id,    /* Domain ID */
                                                LIBRARY_NAME, /* QoS */
                                                PROFILE_NAME,
                                                0,            /* Listener */
                                                DDS_STATUS_MASK_NONE);
    if (!participant) {
        cerr << "SENDER: Error creating participant" << endl;
        goto clean_exit;
    }

    retcode = QueryConditionTestTypeSupport::register_type(
                  participant, QueryConditionTestTypeSupport::get_type_name ());

    if (retcode != DDS_RETCODE_OK) {
        cerr << "SENDER: Error registering type" << endl;
        goto clean_exit;
    }

    topic = participant->create_topic_with_profile (
                "QC",                   /* Topic name*/
                QueryConditionTestTypeSupport::get_type_name (), /* Type name */
                LIBRARY_NAME,       /* QoS */
                PROFILE_NAME,
                0,                  /* Listener  */
                DDS_STATUS_MASK_NONE);
    if (!topic) {
        cerr << "SENDER: Error creating topic" << endl;
        goto clean_exit;
    }

    publisher = participant->create_publisher_with_profile (LIBRARY_NAME,
                PROFILE_NAME,
                0,
                0);
    if (!publisher) {
        cerr << "SENDER: Error creating publisher" << endl;
        goto clean_exit;
    }

    data_writer = publisher->create_datawriter_with_profile (
                      topic,
                      LIBRARY_NAME, /* QoS */
                      PROFILE_NAME,
                      0,            /* Listener */
                      DDS_STATUS_MASK_NONE);
    if (!data_writer) {
        cerr << "SENDER: Error creating data writer" << endl;
        goto clean_exit;
    }

    write (data_writer);
    sleep_now (8);
    write (data_writer);
    sleep_now (8);
    write (data_writer);
    sleep_now (30);

    main_result = 0;
clean_exit:
    cout << "SENDER: Exiting ..." << endl;
    if (participant) {
        retcode = participant->delete_contained_entities();
        if (retcode != DDS_RETCODE_OK) {
            main_result = 1;
        }
        retcode = DDSDomainParticipantFactory::get_instance()->
                  delete_participant(participant);
        if (retcode != DDS_RETCODE_OK) {
            main_result = 1;
        }
    }
    DDSDomainParticipantFactory::finalize_instance ();
    return main_result;
}
Beispiel #7
0
rmw_node_t *
create_node(const char * implementation_identifier, const char * name, size_t domain_id)
{
  DDSDomainParticipantFactory * dpf_ = DDSDomainParticipantFactory::get_instance();
  if (!dpf_) {
    RMW_SET_ERROR_MSG("failed to get participant factory");
    return NULL;
  }

  // use loopback interface to enable cross vendor communication
  DDS_DomainParticipantQos participant_qos;
  DDS_ReturnCode_t status = dpf_->get_default_participant_qos(participant_qos);
  if (status != DDS_RETCODE_OK) {
    RMW_SET_ERROR_MSG("failed to get default participant qos");
    return NULL;
  }
  // forces local traffic to be sent over loopback,
  // even if a more efficient transport (such as shared memory) is installed
  // (in which case traffic will be sent over both transports)
  status = DDSPropertyQosPolicyHelper::add_property(
    participant_qos.property,
    "dds.transport.UDPv4.builtin.ignore_loopback_interface",
    "0",
    DDS_BOOLEAN_FALSE);
  if (status != DDS_RETCODE_OK) {
    RMW_SET_ERROR_MSG("failed to add qos property");
    return NULL;
  }
  status = DDSPropertyQosPolicyHelper::add_property(
    participant_qos.property,
    "dds.transport.use_510_compatible_locator_kinds",
    "1",
    DDS_BOOLEAN_FALSE);
  if (status != DDS_RETCODE_OK) {
    RMW_SET_ERROR_MSG("failed to add qos property");
    return NULL;
  }

  DDS_DomainId_t domain = static_cast<DDS_DomainId_t>(domain_id);

  DDSDomainParticipant * participant = dpf_->create_participant(
    domain, participant_qos, NULL,
    DDS_STATUS_MASK_NONE);
  if (!participant) {
    RMW_SET_ERROR_MSG("failed to create participant");
    return NULL;
  }

  rmw_node_t * node_handle = nullptr;
  ConnextNodeInfo * node_info = nullptr;
  rmw_guard_condition_t * graph_guard_condition = nullptr;
  CustomPublisherListener * publisher_listener = nullptr;
  CustomSubscriberListener * subscriber_listener = nullptr;
  void * buf = nullptr;

  DDSDataReader * data_reader = nullptr;
  DDSPublicationBuiltinTopicDataDataReader * builtin_publication_datareader = nullptr;
  DDSSubscriptionBuiltinTopicDataDataReader * builtin_subscription_datareader = nullptr;
  DDSSubscriber * builtin_subscriber = participant->get_builtin_subscriber();
  if (!builtin_subscriber) {
    RMW_SET_ERROR_MSG("builtin subscriber handle is null");
    goto fail;
  }

  // setup publisher listener
  data_reader = builtin_subscriber->lookup_datareader(DDS_PUBLICATION_TOPIC_NAME);
  builtin_publication_datareader =
    static_cast<DDSPublicationBuiltinTopicDataDataReader *>(data_reader);
  if (!builtin_publication_datareader) {
    RMW_SET_ERROR_MSG("builtin publication datareader handle is null");
    goto fail;
  }

  graph_guard_condition = create_guard_condition(implementation_identifier);
  if (!graph_guard_condition) {
    RMW_SET_ERROR_MSG("failed to create graph guard condition");
    goto fail;
  }

  buf = rmw_allocate(sizeof(CustomPublisherListener));
  if (!buf) {
    RMW_SET_ERROR_MSG("failed to allocate memory");
    goto fail;
  }
  RMW_TRY_PLACEMENT_NEW(
    publisher_listener, buf, goto fail, CustomPublisherListener,
    implementation_identifier, graph_guard_condition)
  buf = nullptr;
  builtin_publication_datareader->set_listener(publisher_listener, DDS_DATA_AVAILABLE_STATUS);

  data_reader = builtin_subscriber->lookup_datareader(DDS_SUBSCRIPTION_TOPIC_NAME);
  builtin_subscription_datareader =
    static_cast<DDSSubscriptionBuiltinTopicDataDataReader *>(data_reader);
  if (!builtin_subscription_datareader) {
    RMW_SET_ERROR_MSG("builtin subscription datareader handle is null");
    goto fail;
  }

  // setup subscriber listener
  buf = rmw_allocate(sizeof(CustomSubscriberListener));
  if (!buf) {
    RMW_SET_ERROR_MSG("failed to allocate memory");
    goto fail;
  }
  RMW_TRY_PLACEMENT_NEW(
    subscriber_listener, buf, goto fail, CustomSubscriberListener,
    implementation_identifier, graph_guard_condition)
  buf = nullptr;
  builtin_subscription_datareader->set_listener(subscriber_listener, DDS_DATA_AVAILABLE_STATUS);

  node_handle = rmw_node_allocate();
  if (!node_handle) {
    RMW_SET_ERROR_MSG("failed to allocate memory for node handle");
    goto fail;
  }
  node_handle->implementation_identifier = implementation_identifier;
  node_handle->data = participant;

  node_handle->name =
    reinterpret_cast<const char *>(rmw_allocate(sizeof(char) * strlen(name) + 1));
  if (!node_handle->name) {
    RMW_SET_ERROR_MSG("failed to allocate memory for node name");
    goto fail;
  }
  memcpy(const_cast<char *>(node_handle->name), name, strlen(name) + 1);

  buf = rmw_allocate(sizeof(ConnextNodeInfo));
  if (!buf) {
    RMW_SET_ERROR_MSG("failed to allocate memory");
    goto fail;
  }
  RMW_TRY_PLACEMENT_NEW(node_info, buf, goto fail, ConnextNodeInfo)
  buf = nullptr;
  node_info->participant = participant;
  node_info->publisher_listener = publisher_listener;
  node_info->subscriber_listener = subscriber_listener;
  node_info->graph_guard_condition = graph_guard_condition;

  node_handle->implementation_identifier = implementation_identifier;
  node_handle->data = node_info;
  return node_handle;
fail:
  status = dpf_->delete_participant(participant);
  if (status != DDS_RETCODE_OK) {
    std::stringstream ss;
    ss << "leaking participant while handling failure at " <<
      __FILE__ << ":" << __LINE__;
    (std::cerr << ss.str()).flush();
  }
  if (graph_guard_condition) {
    rmw_ret_t ret = destroy_guard_condition(implementation_identifier, graph_guard_condition);
    if (ret != RMW_RET_OK) {
      std::stringstream ss;
      ss << "failed to destroy guard condition while handling failure at " <<
        __FILE__ << ":" << __LINE__;
      (std::cerr << ss.str()).flush();
    }
  }
  if (publisher_listener) {
    RMW_TRY_DESTRUCTOR_FROM_WITHIN_FAILURE(
      publisher_listener->~CustomPublisherListener(), CustomPublisherListener)
    rmw_free(publisher_listener);
  }
  if (subscriber_listener) {
    RMW_TRY_DESTRUCTOR_FROM_WITHIN_FAILURE(
      subscriber_listener->~CustomSubscriberListener(), CustomSubscriberListener)
    rmw_free(subscriber_listener);
  }
  if (node_handle) {
    if (node_handle->name) {
      rmw_free(const_cast<char *>(node_handle->name));
    }
    rmw_free(node_handle);
  }
  if (node_info) {
    RMW_TRY_DESTRUCTOR_FROM_WITHIN_FAILURE(
      node_info->~ConnextNodeInfo(), ConnextNodeInfo)
    rmw_free(node_info);
  }
  if (buf) {
    rmw_free(buf);
  }
  return NULL;
}
Beispiel #8
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  DDSTopic*           topic = 0;
  DDSDataReader*      data_reader = 0;
  DDSSubscriber*      sub = 0;
  DDS_ReturnCode_t    retcode = DDS_RETCODE_OK;
  QueryConditionTestDataReader* typed_dr = 0;
  DDSQueryCondition*  qc = 0;
  DDSReadCondition*   rc = 0;
  int run = 0;

//     NDDS_Config_LogVerbosity n_verbosity =
//       static_cast <NDDS_Config_LogVerbosity> (3);
//     NDDSConfigLogger::get_instance()->set_verbosity (n_verbosity);

  const ACE_TCHAR * env_domain_id = 0;
  if (argc > 1)
    {
      env_domain_id = argv[1];
    }
  if (!env_domain_id)
    {
      printf ("Environment variable DEFAULT_DOMAIN_ID not set "
              "=> setting it to 2\n");
      env_domain_id = "2";
    }
  else
    printf ("Domain ID set to %s\n", env_domain_id);

  const int domain_id = ACE_OS::atoi (env_domain_id);

  DDSDomainParticipant *participant = DDSDomainParticipantFactory::get_instance()->
      create_participant_with_profile (domain_id,    /* Domain ID */
                                       LIBRARY_NAME, /* QoS */
                                       PROFILE_NAME,
                                       0,            /* Listener */
                                       DDS_STATUS_MASK_NONE);
  if (!participant) {
    cerr << "RECEIVER: Error creating participant" << endl;
    return 1;
  }

  retcode = QueryConditionTestTypeSupport::register_type(
    participant, QueryConditionTestTypeSupport::get_type_name ());

  if (retcode != DDS_RETCODE_OK) {
    cerr << "RECEIVER: Error registering type" << endl;
    return clean_up (participant);
  }

  topic = participant->create_topic_with_profile (
                                    "QC",                   /* Topic name*/
                                    QueryConditionTestTypeSupport::get_type_name (), /* Type name */
                                    LIBRARY_NAME,       /* QoS */
                                    PROFILE_NAME,
                                    0,                  /* Listener  */
                                    DDS_STATUS_MASK_NONE);
  if (!topic) {
    cerr << "RECEIVER: Error creating topic" << endl;
    return clean_up (participant);
  }

  sub = participant->create_subscriber_with_profile (LIBRARY_NAME,
                                                     PROFILE_NAME,
                                                     0,
                                                     0);
  if (!sub) {
    cerr << "RECEIVER: Error creating subscriber" << endl;
    return clean_up (participant);
  }

  data_reader = sub->create_datareader_with_profile (
                                               topic,
                                               LIBRARY_NAME, /* QoS */
                                               PROFILE_NAME,
                                               0,            /* Listener */
                                               DDS_STATUS_MASK_NONE);
  if (!data_reader) {
    cerr << "RECEIVER: Error creating data reader" << endl;
    return clean_up (participant);
  }

  typed_dr = QueryConditionTestDataReader::narrow (data_reader);

  if (!typed_dr) {
    cerr << "RECEIVER: Unable to cast to a type specific data reader" << endl;
    return clean_up (participant);
  }

  const char* PARAMS_RUN_1[] = {"1", "3"};
  DDS_StringSeq parameters_run_1;
  parameters_run_1.from_array (PARAMS_RUN_1, 2);

  qc = typed_dr->create_querycondition (
                                DDS_NOT_READ_SAMPLE_STATE,
                                DDS_NEW_VIEW_STATE | DDS_NOT_NEW_VIEW_STATE,
                                DDS_ALIVE_INSTANCE_STATE | DDS_NOT_ALIVE_INSTANCE_STATE,
                                "iteration > %0 AND iteration < %1",
                                parameters_run_1);
  if (!qc) {
    cerr << "RECEIVER: Error creating query condition" << endl;
    return clean_up (participant);
  }
  else
    cout << "RECEIVER: query condition created : iteration > 1 AND iteration < 3" << endl;

  ws_->attach_condition (qc);

  cout << "RECEIVER: Expecting two samples (key_1 and key_2) with iteration 2." <<endl;

  read (data_reader, qc, rc, ++run);

  //Second run: change the parameters
  if (qc)
    {
      const char* PARAMS_RUN_2[] = {"4", "6"};
      DDS_StringSeq parameters_run_2;
      parameters_run_2.from_array (PARAMS_RUN_2, 2);
      if (qc->set_query_parameters (parameters_run_2) != DDS_RETCODE_OK)
        {
          cerr << "RECEIVER: Unable the set the new query parameters!!!" << endl;
          return clean_up (participant);
        }
    }
  cout << "RECEIVER: query condition changed : iteration > 4 AND iteration < 6" << endl;

  cout << "RECEIVER: Expecting two samples (key_1 and key_2) with iterations 5" <<endl;

  read (data_reader, qc, rc, ++run);
  // Third run: Detach querycondition and create read condition instead.
  // Remove the qc from the waitset and create a readcondition and start receiving
  // samples
  if (ws_->detach_condition (qc) != DDS_RETCODE_OK)
    {
      cerr << "RECEIVER: Error detaching query condition" << endl;
      return clean_up (participant);
    }
  // Delete the query condition from the data reader
  typed_dr->delete_readcondition (qc);
  cout << "RECEIVER: query condition deleted" << endl;
  cout << "RECEIVER: create read condition : DDS_NOT_READ_SAMPLE_STATE,"
       << "DDS_NEW_VIEW_STATE | DDS_NOT_NEW_VIEW_STATE,"
       << "DDS_ALIVE_INSTANCE_STATE | DDS_NOT_ALIVE_INSTANCE_STATE" << endl;

  sleep_now(10);

  rc = typed_dr->create_readcondition (
                            DDS_NOT_READ_SAMPLE_STATE,
                            DDS_NEW_VIEW_STATE | DDS_NOT_NEW_VIEW_STATE,
                            DDS_ALIVE_INSTANCE_STATE | DDS_NOT_ALIVE_INSTANCE_STATE);
  if (!rc) {
    cerr << "RECEIVER: Error creating read condition" << endl;
    return clean_up (participant);
  }

  if (ws_->attach_condition (rc) != DDS_RETCODE_OK)
    {
      cerr << "RECEIVER: Error attaching read condition" << endl;
      return clean_up (participant);
    }

  cout << "RECEIVER: Expecting ALL UNREAD samples (key_1 and key_2) with iterations between 1 and 9, except 2 and 5" <<endl;

  read (data_reader, qc, rc, ++run);

  return clean_up (participant);
}
Beispiel #9
0
int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
{
  timer = RTIHighResolutionClock_new();
  DDS_ReturnCode_t retcode;
  ::DDS::DataReader * data_reader = 0;
  ::DDS::DataReader * dum_data_reader = 0;

  HelloListener listener;
  DummyListener dum_listener;
  const char * type_name = 0;
  int main_result = 1; /* error by default */

  ::DDS::Topic * receive_topic = 0;
  ::DDS::Topic * send_topic = 0;
  ::DDS::DataWriter * data_writer = 0;
  ::DDS::DataWriter * dum_data_writer = 0;
  DummyPublisherListener * pub_listener = 0;
  ::DDS::Publisher * pub = 0;

  try
    {
      ACE_Env_Value<int> id (ACE_TEXT("DDS4CCM_DEFAULT_DOMAIN_ID"), domain_id_);
      domain_id_ = id;

      if (parse_args (argc, argv) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Error arguments.\n")));
          return 1;
        }

      /* Create the domain participant */
      DDSDomainParticipant * participant =
                              DDSDomainParticipantFactory::get_instance()->
                              create_participant_with_profile(
                                  domain_id_,
                                  lib_name_,
                                  prof_name_,
                                  0,
                                  DDS_STATUS_MASK_NONE);
      if (!participant)
        {
          ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("Sender : Unable to create domain participant.\n")));
          goto clean_exit;
        }

      /* Register type before creating topic */
      type_name = LatencyTestTypeSupport::get_type_name();
      retcode = LatencyTestTypeSupport::register_type (participant,
                                                      type_name);
      if (retcode != DDS_RETCODE_OK)
        {
          goto clean_exit;
        }

      send_topic = participant->create_topic_with_profile (
                                                            "send",
                                                            type_name,
                                                            lib_name_,
                                                            prof_name_,
                                                            0,
                                                            DDS_STATUS_MASK_NONE);
      if (!send_topic)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create topic.\n")));
          goto clean_exit;
        }

      receive_topic = participant->create_topic_with_profile (
                                                            "receive",
                                                            type_name,
                                                            lib_name_,
                                                            prof_name_,
                                                            0,
                                                            DDS_STATUS_MASK_NONE);
      if (!receive_topic)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create topic.\n")));
          goto clean_exit;
        }

      pub_listener = new DummyPublisherListener ();
      pub = participant->create_publisher_with_profile (
                                                lib_name_,
                                                prof_name_,
                                                0,
                                                DDS_STATUS_MASK_NONE);

      if (!pub)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create publisher.\n")));
          goto clean_exit;
        }

      /* Create the data writer using the publisher */
      data_writer = pub->create_datawriter_with_profile(
                                                send_topic,
                                                lib_name_,
                                                prof_name_,
                                                pub_listener,
                                                DDS_OFFERED_DEADLINE_MISSED_STATUS |
                                                DDS_OFFERED_INCOMPATIBLE_QOS_STATUS |
                                                DDS_RELIABLE_WRITER_CACHE_CHANGED_STATUS |
                                                DDS_RELIABLE_READER_ACTIVITY_CHANGED_STATUS |
                                                DDS_LIVELINESS_LOST_STATUS |
                                                DDS_PUBLICATION_MATCHED_STATUS);
      if (!data_writer)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create data writer.\n")));
          goto clean_exit;
        }

      /* Create a data reader, which will not be used, but is there for
      *  compatibility with DDS4CCM latency test, where there is always a
      *  reader and a writer per connector.
      */
      if (both_read_write_)
        {
          dum_data_reader = participant->create_datareader_with_profile(
                                                  send_topic,
                                                  lib_name_,
                                                  prof_name_,
                                                  &dum_listener,
                                                  DDS_DATA_AVAILABLE_STATUS);

          if (!dum_data_reader )
            {
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create dummy data reader.\n")));
              goto clean_exit;
            }
        }

      data_reader = participant->create_datareader_with_profile(
                                                  receive_topic,
                                                  lib_name_,
                                                  prof_name_,
                                                  &listener,
                                                  DDS_DATA_AVAILABLE_STATUS);
      if (!data_reader)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create data reader.\n")));
          goto clean_exit;
        }

      /* Create a data writer, which will not be used, but is there for
      *   compatibility with DDS4CCM latency test, where there is always a
      *  reader and a writer per connector
      */
      if (both_read_write_)
        {
          dum_data_writer = participant->create_datawriter_with_profile(
                                    receive_topic,
                                      lib_name_,
                                      prof_name_,
                                      0,
                                      DDS_STATUS_MASK_NONE);
          if (!dum_data_writer)
            {
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create dummy data writer.\n")));
              goto clean_exit;
            }
        }

      /* Create data sample for writing */
      instance_ = LatencyTestTypeSupport::create_data ();
      if (instance_ == 0)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to create data sample.\n")));
          goto clean_exit;
        }

      init_values();

      test_data_writer_ = LatencyTestDataWriter::narrow (data_writer);
      if (!test_data_writer_)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("LatencyTestDataWriter_narrow failed.\n")));
          goto clean_exit;
        }

      // Sleep a couple seconds to allow discovery to happen
      ACE_OS::sleep (5);

      // handle writing of messages
      start();

      /* --- Clean Up --- */
      ACE_OS::sleep (5);
      main_result = 0;

  clean_exit:
      const char * read_write_str = 0;
      if (both_read_write_)
        {
          read_write_str = "Used a extra dummy reader and writer per topic.";
        }
      else
        {
          read_write_str = "Used a reader for one topic and a writer for other topic.";
        }

      if((nr_of_runs_ -1) != datalen_idx_)
        {
          ACE_DEBUG ((LM_DEBUG, "SUMMARY SENDER : %u of %u runs completed.\n"
                              " Number of messages sent of last run (%u): %u\n"
                              "%C\n\n",
                              datalen_idx_,
                              nr_of_runs_,
                              datalen_idx_ + 1,
                              number_of_msg_,
                              read_write_str));
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG, "TEST successful, number of runs (%u) of "
                                "%u messages.\n"
                                "%C\n\n",
                                nr_of_runs_,
                                number_of_msg_,
                                read_write_str));
        }
      ACE_DEBUG ((LM_DEBUG, "\tNumber of unexpected events : %u\n",
                    unexpected_count_));
      if (participant)
        {
          retcode = participant->delete_contained_entities ();
          if (retcode != DDS_RETCODE_OK)
            {
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Deletion failed.\n")));
              main_result = 1;
            }
          retcode = DDSDomainParticipantFactory::get_instance()->
                          delete_participant (participant);
          if (retcode != DDS_RETCODE_OK)
            {
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Deletion failed.\n")));
              main_result = 1;
            }
        }
    }
  catch (const ::CORBA::Exception &ex)
    {
      ex._tao_print_exception("ERROR : Unexpected CORBA exception caught :");
      main_result = 1;
    }

  delete [] datalen_range_;
  delete [] duration_times_;
  delete pub_listener;

  return main_result;
}
Beispiel #10
0
	void MyPublisher::publish(unsigned short *image, const std::string& qosProfileName, 
		uint32_t domainId, const std::string& topic)
	{
		DDSDomainParticipant *participant = DDSDomainParticipantFactory::get_instance()->
			create_participant_with_profile(
											domainId,
											"DataExchangeProfile",
											qosProfileName.c_str(),
											NULL,
											DDS_STATUS_MASK_NONE);

		if(participant == NULL) {
			std::cout << "Error while creating participant" << std::endl;
		}

		DataExchangeTypeSupport::register_type(participant, DataExchangeTypeSupport::get_type_name());

		DDSTopic *ddstopic = participant->create_topic(
			topic.c_str(),
			DataExchangeTypeSupport::get_type_name(),
			DDS_TOPIC_QOS_DEFAULT,
			NULL,           /* listener */
			DDS_STATUS_MASK_NONE);

		if(ddstopic == NULL) {
			std::cout << "Publisher: Error while creating topic: " << topic << std::endl;
			std::cout << "With typename: " << DataExchangeTypeSupport::get_type_name() << std::endl;
		}

		DDSPublisher *publisher = participant->create_publisher(
			DDS_PUBLISHER_QOS_DEFAULT,
			NULL,           /* listener */
			DDS_STATUS_MASK_NONE);

		if(publisher == NULL) {
			std::cout << "Error while creating publisher" << std::endl;
		}

		DDSDataWriter *dataWriter = publisher->create_datawriter(
			ddstopic,
			DDS_DATAWRITER_QOS_DEFAULT,
			NULL,           /* listener */
			DDS_STATUS_MASK_NONE);

		if(dataWriter == NULL) {
			std::cout << "Error while creating dataWriter" << std::endl;
		}

		DataExchangeDataWriter *dataExchangeWriter    = NULL;
		dataExchangeWriter = DataExchangeDataWriter::narrow(dataWriter);

		DDS_Duration_t disc_period = {1,0};
		NDDSUtility::sleep(disc_period);

		DataExchange *instance                 = NULL;

		instance = DataExchangeTypeSupport::create_data_ex(DDS_BOOLEAN_FALSE);
		int rows = 1024;
		int cols = 1024;
		DDS_UnsignedShortSeq_ensure_length(&instance->pixels, rows*cols, MAX_PIXELS_SEQUENCE_LENGTH);

		for (int i = 0; i < rows*cols; ++i) {
			instance->pixels[i] = i;
		}

		std::cout << "Sending dataaa...";
		instance->rows = rows;
		instance->cols = cols;
		dataExchangeWriter->write(*instance, DDS_HANDLE_NIL);
		std::cout << " DONE!" << std::endl;
	}