Beispiel #1
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;

	}
Beispiel #2
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 #3
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;
}