/* Delete all entities */
static int subscriber_shutdown(
    DDS_DomainParticipant *participant)
{
    DDS_ReturnCode_t retcode;
    int status = 0;

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

        retcode = DDS_DomainParticipantFactory_delete_participant(
            DDS_TheParticipantFactory, participant);
        if (retcode != DDS_RETCODE_OK) {
            printf("delete_participant error %d\n", retcode);
            status = -1;
        }
    }

    /* RTI Connext provides the finalize_instance() method on
       domain participant factory for users who want to release memory used
       by the participant factory. Uncomment the following block of code for
       clean destruction of the singleton. */
/*
    retcode = DDS_DomainParticipantFactory_finalize_instance();
    if (retcode != DDS_RETCODE_OK) {
        printf("finalize_instance error %d\n", retcode);
        status = -1;
    }
*/

    return status;
}
Exemplo n.º 2
0
/* 
	Deletes the domain participant and the rest of the entities that
	it contains.
*/
void delete_node(void)
{
	error = DDS_DomainParticipant_delete_contained_entities (part);
	if (verbose)
		printf ("delete_node() DDS Entities deleted (error = %u).\r\n", error);

	delete_types();	
	if (verbose)
		printf ("delete_node() types deleted.\r\n");	

	error = DDS_DomainParticipantFactory_delete_participant (part);
	if (verbose)
		printf ("delete_node() DDS Participant deleted (error = %u).\r\n", error);
}
Exemplo n.º 3
0
int
dds_domainparticipant_delete(
    dds_entity_t pp)
{
    int result;

    result = DDS_DomainParticipant_delete_contained_entities(pp);
    if (result == DDS_RETCODE_OK) {
        DDS_DomainParticipantFactory factory = DDS_DomainParticipantFactory_get_instance();
        result = DDS_DomainParticipantFactory_delete_participant(factory, pp);
    }

    return DDS_ERRNO(result, DDS_MOD_KERNEL, DDS_ERR_Mx);
}
/* Delete all entities */
static int publisher_shutdown(DDS_DomainParticipant *participant,
                              struct DDS_PublisherQos *publisher_qos,
                              struct DDS_DataWriterQos *datawriter_qos) {

    DDS_ReturnCode_t retcode;
    int status = 0;

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

        retcode = DDS_DomainParticipantFactory_delete_participant(
                      DDS_TheParticipantFactory, participant);
        if (retcode != DDS_RETCODE_OK) {
            printf("delete_participant error %d\n", retcode);
            status = -1;
        }
    }

    retcode = DDS_PublisherQos_finalize(publisher_qos);
    if (retcode != DDS_RETCODE_OK) {
        printf("PublisherQos_finalize error %d\n", retcode);
        status = -1;
    }

    retcode = DDS_DataWriterQos_finalize(datawriter_qos);
    if (retcode != DDS_RETCODE_OK) {
        printf("DataWriterQos_finalize error %d\n", retcode);
        status = -1;
    }

    /* RTI Connext provides finalize_instance() method on
       domain participant factory for people who want to release memory used
       by the participant factory. Uncomment the following block of code for
       clean destruction of the singleton. */
    /*
        retcode = DDS_DomainParticipantFactory_finalize_instance();
        if (retcode != DDS_RETCODE_OK) {
            printf("finalize_instance error %d\n", retcode);
            status = -1;
        }
    */

    return status;
}
/* Delete all entities */
static int publisher_shutdown(
    DDS_DomainParticipant *participant)
{
    DDS_ReturnCode_t retcode;
    int status = 0;

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

        retcode = DDS_DomainParticipantFactory_delete_participant(
            DDS_TheParticipantFactory, participant);
        if (retcode != DDS_RETCODE_OK) {
            printf("delete_participant error %d\n", retcode);
            status = -1;
        }
    }

    /* RTI Data Distribution Service provides finalize_instance() method on
       domain participant factory and finalize() method on type support for
       people who want to release memory used by the participant factory and
       type support singletons. Uncomment the following block of code for
       clean destruction of the singletons. */
/*
    numbersTypeSupport_finalize();

    retcode = DDS_DomainParticipantFactory_finalize_instance();
    if (retcode != DDS_RETCODE_OK) {
        printf("finalize_instance error %d\n", retcode);
        status = -1;
    }
*/

    return status;
}
Exemplo n.º 6
0
void deleteContainedEntities()
{
    // Recursively delete all entities in the DomainParticipant.
    g_status = DDS_DomainParticipant_delete_contained_entities(g_domainParticipant);
    checkStatus(g_status, "DDS_DomainParticipant_delete_contained_entities");
}
Exemplo n.º 7
0
int main_subscriber (int argc, const char **argv)
{
	DDS_DataWriterQos 	wr_qos;
	DDS_DataReaderQos	rd_qos;
	DDS_ReturnCode_t	error;

	sprintf (user_name, ".pid.%u", getpid ());
	DDS_entity_name ("Technicolor Chatroom");

#ifdef DDS_SECURITY
	if (cert_path || key_path || engine_id)
		enable_security ();
#endif
	part = DDS_DomainParticipantFactory_create_participant (domain_id, NULL, NULL, 0);
	if (!part) {
		printf ("Can't create participant!\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS Domain Participant created.\r\n");

	ts = Vector3_type_new ();
	if (!ts) {
		printf ("Can't create vector3 message type!\r\n");
		exit (1);
	}
	error = DDS_DynamicTypeSupport_register_type (ts, part, "simple_msgs::dds_::Vector3_");
	if (error) {
		printf ("Can't register vector3 message type.\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS Topic type ('%s') registered.\r\n", "simple_msgs::dds_::Vector3_");

	topic = DDS_DomainParticipant_create_topic (part, "imu", "simple_msgs::dds_::Vector3_", NULL, NULL, 0);
	if (!topic) {
		printf ("Can't register vector3 message type.\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS Vector3 Topic created.\r\n");

	td = DDS_DomainParticipant_lookup_topicdescription (part, "imu");
	if (!td) {
		printf ("Can't get topicdescription.\r\n");
		exit (1);
	}
	pub = DDS_DomainParticipant_create_publisher (part, NULL, NULL, 0);
	if (!pub) {
		printf ("DDS_DomainParticipant_create_publisher () failed!\r\n");
		exit (1);
	}
	DDS_Publisher_get_default_datawriter_qos (pub, &wr_qos);
#ifdef TRANSIENT_LOCAL
	wr_qos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
#endif
#ifdef RELIABLE
	wr_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
#endif
#ifdef KEEP_ALL
	wr_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS;
	wr_qos.history.depth = DDS_LENGTH_UNLIMITED;
	wr_qos.resource_limits.max_samples_per_instance = HISTORY;
	wr_qos.resource_limits.max_instances = HISTORY * 10;
	wr_qos.resource_limits.max_samples = HISTORY * 4;
#else
	wr_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS;
	wr_qos.history.depth = HISTORY;
#endif
	/* Create a Data Writer. */
	dw = DDS_Publisher_create_datawriter (pub, topic, &wr_qos, NULL, 0);
	if (!dw) {
		printf ("Unable to create vector3 message writer.\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS Vector3 message writer created.\r\n");

	sub = DDS_DomainParticipant_create_subscriber (part, NULL, NULL, 0); 
	if (!sub) {
		printf ("DDS_DomainParticipant_create_subscriber () returned an error!\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS Subscriber created.\r\n");

	DDS_Subscriber_get_default_datareader_qos (sub, &rd_qos);
#ifdef TRANSIENT_LOCAL
	rd_qos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
#endif
#ifdef RELIABLE
	rd_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
#endif
#ifdef KEEP_ALL
	rd_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS;
	rd_qos.history.depth = DDS_LENGTH_UNLIMITED;
	rd_qos.resource_limits.max_samples_per_instance = HISTORY;
	rd_qos.resource_limits.max_instances = HISTORY * 10;
	rd_qos.resource_limits.max_samples = HISTORY * 4;
#else
	rd_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS;
	rd_qos.history.depth = HISTORY;
#endif
	dr = DDS_Subscriber_create_datareader (sub, td, &rd_qos,
#ifndef WAITSETS
			 &msg_listener, DDS_DATA_AVAILABLE_STATUS);
#else
			 NULL, 0);
#endif
	if (!dr) {
		printf ("DDS_DomainParticipant_create_datareader () returned an error!\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS Vector message reader created.\r\n");

#ifdef WAITSETS
	start_imu_reader (dr);
#endif

	// publisher thread
	//thread_create (rt2, dds_send_imu, dr);	

	// DDS Debug shell thread
	do_dds_shell (dw);

#ifdef WAITSETS
	stop_imu_reader (dr);
#endif
	DDS_Publisher_delete_datawriter (pub, dw);
	usleep (200000);
	error = DDS_DomainParticipant_delete_contained_entities (part);
	if (verbose)
		printf ("DDS Entities deleted (error = %u).\r\n", error);

	Vector3_type_free (ts);
	if (verbose)
		printf ("Vector3 Type deleted.\r\n");

	error = DDS_DomainParticipantFactory_delete_participant (part);
	if (verbose)
		printf ("DDS Participant deleted (error = %u).\r\n", error);

#ifdef DDS_SECURITY
	if (cert_path || key_path || engine_id)
		cleanup_security ();
#endif
	return (0);
}
Exemplo n.º 8
0
int main (int argc, char ** argv)
#endif
{
    /* Generic DDS entities */
    DDS_DomainParticipant           participant;
    DDS_Topic                       chatMessageTopic;
    DDS_Topic                       nameServiceTopic;
    DDS_Subscriber                  chatSubscriber;
    DDS_QueryCondition              singleUser;
    DDS_ReadCondition               newUser;
    DDS_StatusCondition             leftUser;
    DDS_GuardCondition              guard;
    DDS_WaitSet                     userLoadWS;
    DDS_LivelinessChangedStatus     livChangStatus;

    /* QosPolicy holders */
    DDS_TopicQos                    *setting_topic_qos;
    DDS_TopicQos                    *reliable_topic_qos;
    DDS_SubscriberQos               *sub_qos;
    DDS_DataReaderQos               *message_qos;

    /* DDS Identifiers */
    DDS_DomainId_t                  domain = NULL;
    DDS_ReturnCode_t                status;
    DDS_ConditionSeq                *guardList = NULL;
    DDS_Duration_t                  timeout = DDS_DURATION_INFINITE;

    /* Type-specific DDS entities */
    Chat_ChatMessageTypeSupport     chatMessageTS;
    Chat_NameServiceTypeSupport     nameServiceTS;
    Chat_NameServiceDataReader      nameServer;
    Chat_ChatMessageDataReader      loadAdmin;
    DDS_sequence_Chat_ChatMessage   msgList = { 0, 0, DDS_OBJECT_NIL, FALSE };
    DDS_sequence_Chat_NameService   nsList = { 0, 0, DDS_OBJECT_NIL, FALSE };
    DDS_SampleInfoSeq               infoSeq    = { 0, 0, DDS_OBJECT_NIL, FALSE };
    DDS_SampleInfoSeq               infoSeq2   = { 0, 0, DDS_OBJECT_NIL, FALSE };

    /* Others */
    DDS_StringSeq                   args;
    int                             closed = 0;
    DDS_unsigned_long               i, j;
    DDS_long                        prevCount = 0;
    char                            *partitionName;
    char                            *chatMessageTypeName = NULL;
    char                            *nameServiceTypeName = NULL;
    pthread_t                       tid;
    pthread_attr_t                  tattr;

    printf("Starting UserLoad example.\n");
    fflush(stdout);
    /* Create a DomainParticipant (using the 'TheParticipantFactory' convenience macro). */
    participant = DDS_DomainParticipantFactory_create_participant (
        DDS_TheParticipantFactory, 
        domain, 
        DDS_PARTICIPANT_QOS_DEFAULT, 
        NULL,
        DDS_STATUS_MASK_NONE);
    checkHandle(participant, "DDS_DomainParticipantFactory_create_participant");  

    /* Register the required datatype for ChatMessage. */
    chatMessageTS = Chat_ChatMessageTypeSupport__alloc();
    checkHandle(chatMessageTS, "Chat_ChatMessageTypeSupport__alloc");
    chatMessageTypeName = Chat_ChatMessageTypeSupport_get_type_name(chatMessageTS);
    status = Chat_ChatMessageTypeSupport_register_type(
        chatMessageTS, 
        participant, 
        chatMessageTypeName);
    checkStatus(status, "Chat_ChatMessageTypeSupport_register_type");
    
    /* Register the required datatype for NameService. */
    nameServiceTS = Chat_NameServiceTypeSupport__alloc();
    checkHandle(nameServiceTS, "Chat_NameServiceTypeSupport__alloc");
    nameServiceTypeName = Chat_NameServiceTypeSupport_get_type_name(nameServiceTS);
    status = Chat_NameServiceTypeSupport_register_type(
        nameServiceTS, 
        participant, 
        nameServiceTypeName);
    checkStatus(status, "Chat_NameServiceTypeSupport_register_type");

    /* Set the ReliabilityQosPolicy to RELIABLE. */
    reliable_topic_qos = DDS_TopicQos__alloc();
    checkHandle(reliable_topic_qos, "DDS_TopicQos__alloc");
    status = DDS_DomainParticipant_get_default_topic_qos(participant, reliable_topic_qos);
    checkStatus(status, "DDS_DomainParticipant_get_default_topic_qos");
    reliable_topic_qos->reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
    
    /* Make the tailored QoS the new default. */
    status = DDS_DomainParticipant_set_default_topic_qos(participant, reliable_topic_qos);
    checkStatus(status, "DDS_DomainParticipant_set_default_topic_qos");

    /* Use the changed policy when defining the ChatMessage topic */
    chatMessageTopic = DDS_DomainParticipant_create_topic( 
        participant, 
        "Chat_ChatMessage", 
        chatMessageTypeName, 
        reliable_topic_qos, 
        NULL,
        DDS_STATUS_MASK_NONE);
    checkHandle(chatMessageTopic, "DDS_DomainParticipant_create_topic (ChatMessage)");
    
    /* Set the DurabilityQosPolicy to TRANSIENT. */
    setting_topic_qos = DDS_TopicQos__alloc();
    checkHandle(setting_topic_qos, "DDS_TopicQos__alloc");
    status = DDS_DomainParticipant_get_default_topic_qos(participant, setting_topic_qos);
    checkStatus(status, "DDS_DomainParticipant_get_default_topic_qos");
    setting_topic_qos->durability.kind = DDS_TRANSIENT_DURABILITY_QOS;

    /* Create the NameService Topic. */
    nameServiceTopic = DDS_DomainParticipant_create_topic( 
        participant, 
        "Chat_NameService", 
        nameServiceTypeName, 
        setting_topic_qos, 
        NULL,
        DDS_STATUS_MASK_NONE);
    checkHandle(nameServiceTopic, "DDS_DomainParticipant_create_topic");

    /* Adapt the default SubscriberQos to read from the "ChatRoom" Partition. */
    partitionName = "ChatRoom";
    sub_qos = DDS_SubscriberQos__alloc();
    checkHandle(sub_qos, "DDS_SubscriberQos__alloc");
    status = DDS_DomainParticipant_get_default_subscriber_qos (participant, sub_qos);
    checkStatus(status, "DDS_DomainParticipant_get_default_subscriber_qos");
    sub_qos->partition.name._length = 1;
    sub_qos->partition.name._maximum = 1;
    sub_qos->partition.name._buffer = DDS_StringSeq_allocbuf (1);
    checkHandle(sub_qos->partition.name._buffer, "DDS_StringSeq_allocbuf");
    sub_qos->partition.name._buffer[0] = DDS_string_alloc (strlen(partitionName) + 1);
    checkHandle(sub_qos->partition.name._buffer[0], "DDS_string_alloc");
    strcpy (sub_qos->partition.name._buffer[0], partitionName);

    /* Create a Subscriber for the UserLoad application. */
    chatSubscriber = DDS_DomainParticipant_create_subscriber(participant, sub_qos, NULL, DDS_STATUS_MASK_NONE);
    checkHandle(chatSubscriber, "DDS_DomainParticipant_create_subscriber");
    
    /* Create a DataReader for the NameService Topic (using the appropriate QoS). */
    nameServer = DDS_Subscriber_create_datareader( 
        chatSubscriber, 
        nameServiceTopic, 
        DDS_DATAREADER_QOS_USE_TOPIC_QOS, 
        NULL,
        DDS_STATUS_MASK_NONE);
    checkHandle(nameServer, "DDS_Subscriber_create_datareader (NameService)");

    /* Adapt the DataReaderQos for the ChatMessageDataReader to keep track of all messages. */
    message_qos = DDS_DataReaderQos__alloc();
    checkHandle(message_qos, "DDS_DataReaderQos__alloc");
    status = DDS_Subscriber_get_default_datareader_qos(chatSubscriber, message_qos);
    checkStatus(status, "DDS_Subscriber_get_default_datareader_qos");
    status = DDS_Subscriber_copy_from_topic_qos(chatSubscriber, message_qos, reliable_topic_qos);
    checkStatus(status, "DDS_Subscriber_copy_from_topic_qos");
    message_qos->history.kind = DDS_KEEP_ALL_HISTORY_QOS;

    /* Create a DataReader for the ChatMessage Topic (using the appropriate QoS). */
    loadAdmin = DDS_Subscriber_create_datareader( 
        chatSubscriber, 
        chatMessageTopic, 
        message_qos, 
        NULL,
        DDS_STATUS_MASK_NONE);
    checkHandle(loadAdmin, "DDS_Subscriber_create_datareader (ChatMessage)");
    
    /* Initialize the Query Arguments. */
    args._length = 1;
    args._maximum = 1;
    args._buffer = DDS_StringSeq_allocbuf(1);
    checkHandle(args._buffer, "DDS_StringSeq_allocbuf");
    args._buffer[0] = DDS_string_alloc (12);  /* Enough for maximum size numbers. */
    checkHandle(args._buffer[0], "DDS_string_alloc");
    sprintf(args._buffer[0], "%d", 0);
    
    /* Create a QueryCondition that will contain all messages with userID=ownID */
    singleUser = DDS_DataReader_create_querycondition( 
        loadAdmin, 
        DDS_ANY_SAMPLE_STATE, 
        DDS_ANY_VIEW_STATE, 
        DDS_ANY_INSTANCE_STATE, 
        "userID=%0", 
        &args);
    checkHandle(singleUser, "DDS_DataReader_create_querycondition (singleUser Query)");
    
    /* Create a ReadCondition that will contain new users only */
    newUser = DDS_DataReader_create_readcondition( 
        nameServer, 
        DDS_NOT_READ_SAMPLE_STATE, 
        DDS_NEW_VIEW_STATE, 
        DDS_ALIVE_INSTANCE_STATE);
    checkHandle(newUser, "DDS_DataReader_create_readcondition (newUser)");

    /* Obtain a StatusCondition that triggers only when a Writer changes Liveliness */
    leftUser = DDS_DataReader_get_statuscondition(loadAdmin);
    checkHandle(leftUser, "DDS_DataReader_get_statuscondition");
    status = DDS_StatusCondition_set_enabled_statuses(leftUser, DDS_LIVELINESS_CHANGED_STATUS);
    checkStatus(status, "DDS_StatusCondition_set_enabled_statuses");

    /* Create a bare guard which will be used to close the room */
    escape = DDS_GuardCondition__alloc();
    checkHandle(escape, "DDS_GuardCondition__alloc");

    /* Create a waitset and add the ReadConditions */
    userLoadWS = DDS_WaitSet__alloc();
    checkHandle(userLoadWS, "DDS_WaitSet__alloc");
    status = DDS_WaitSet_attach_condition(userLoadWS, newUser);
    checkStatus(status, "DDS_WaitSet_attach_condition (newUser)");
    status = DDS_WaitSet_attach_condition(userLoadWS, leftUser);
    checkStatus(status, "DDS_WaitSet_attach_condition (leftUser)");
    status = DDS_WaitSet_attach_condition(userLoadWS, escape);
    checkStatus(status, "DDS_WaitSet_attach_condition (escape)");
    
    /* Initialize and pre-allocate the GuardList used to obtain the triggered Conditions. */
    guardList = DDS_ConditionSeq__alloc();
    checkHandle(guardList, "DDS_ConditionSeq__alloc");
    guardList->_maximum = 3;
    guardList->_length = 0;
    guardList->_buffer = DDS_ConditionSeq_allocbuf(3);
    checkHandle(guardList->_buffer, "DDS_ConditionSeq_allocbuf");
    
    /* Remove all known Users that are not currently active. */
    status = Chat_NameServiceDataReader_take(
        nameServer,
        &nsList, 
        &infoSeq, 
        DDS_LENGTH_UNLIMITED, 
        DDS_ANY_SAMPLE_STATE, 
        DDS_ANY_VIEW_STATE, 
        DDS_NOT_ALIVE_INSTANCE_STATE);
    checkStatus(status, "Chat_NameServiceDataReader_take");
    status = Chat_NameServiceDataReader_return_loan(nameServer, &nsList, &infoSeq);
    checkStatus(status, "Chat_NameServiceDataReader_return_loan");
    
    /* Start the sleeper thread. */
    pthread_attr_init(&tattr);
    pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
    pthread_create (&tid, &tattr, delayedEscape, NULL);
    pthread_attr_destroy(&tattr);

    while (!closed) {
        /* Wait until at least one of the Conditions in the waitset triggers. */
        status = DDS_WaitSet_wait(userLoadWS, guardList, &timeout);
        checkStatus(status, "DDS_WaitSet_wait");

        /* Walk over all guards to display information */
        for (i = 0; i < guardList->_length; i++) {
            guard = guardList->_buffer[i];
            if (guard == newUser) {
                /* The newUser ReadCondition contains data */
                status = Chat_NameServiceDataReader_read_w_condition( 
                    nameServer, 
                    &nsList, 
                    &infoSeq, 
                    DDS_LENGTH_UNLIMITED, 
                    newUser);
                checkStatus(status, "Chat_NameServiceDataReader_read_w_condition");
                
                for (j = 0; j < nsList._length; j++) {
                    printf ("New user: %s\n", nsList._buffer[j].name);
                }
                status = Chat_NameServiceDataReader_return_loan(nameServer, &nsList, &infoSeq);
                checkStatus(status, "Chat_NameServiceDataReader_return_loan");

            } else if (guard == leftUser) {
                /* Some liveliness has changed (either a DataWriter joined or a DataWriter left) */
                status = DDS_DataReader_get_liveliness_changed_status(loadAdmin, &livChangStatus);
                checkStatus(status, "DDS_DataReader_get_liveliness_changed_status");
                if (livChangStatus.alive_count < prevCount) {
                    /* A user has left the ChatRoom, since a DataWriter lost its liveliness */
                    /* Take the effected users so tey will not appear in the list later on. */
                    status = Chat_NameServiceDataReader_take( 
                        nameServer, 
                        &nsList, 
                        &infoSeq, 
                        DDS_LENGTH_UNLIMITED, 
                        DDS_ANY_SAMPLE_STATE, 
                        DDS_ANY_VIEW_STATE, 
                        DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE);
                    checkStatus(status, "Chat_NameServiceDataReader_take");
    
                    for (j = 0; j < nsList._length; j++) {
                        /* re-apply query arguments */
                        sprintf(args._buffer[0], "%d", nsList._buffer[j].userID);
                        status = DDS_QueryCondition_set_query_parameters(singleUser, &args);
                        checkStatus(status, "DDS_QueryCondition_set_query_parameters");
    
                        /* Read this users history */
                        status = Chat_ChatMessageDataReader_take_w_condition( 
                            loadAdmin, 
                            &msgList, 
                            &infoSeq2, 
                            DDS_LENGTH_UNLIMITED, 
                            singleUser);
                        checkStatus(status, "Chat_ChatMessageDataReader_take_w_condition");
                        
                        /* Display the user and his history */
                        printf (
                            "Departed user %s has sent %d messages\n", 
                            nsList._buffer[j].name,
                            msgList._length);
                        status = Chat_ChatMessageDataReader_return_loan(loadAdmin, &msgList, &infoSeq2);
                        checkStatus(status, "Chat_ChatMessageDataReader_return_loan");
                    }
                    status = Chat_NameServiceDataReader_return_loan(nameServer, &nsList, &infoSeq);
                    checkStatus(status, "Chat_NameServiceDataReader_return_loan");
                }
                prevCount = livChangStatus.alive_count;

            } else if (guard == escape) {
                printf ("UserLoad has terminated.\n");
                closed = 1;
            }
            else
            {
                assert(0);
            };
        } /* for */
    } /* while (!closed) */

    /* Remove all Conditions from the WaitSet. */
    status = DDS_WaitSet_detach_condition(userLoadWS, escape);
    checkStatus(status, "DDS_WaitSet_detach_condition (escape)");
    status = DDS_WaitSet_detach_condition(userLoadWS, leftUser);
    checkStatus(status, "DDS_WaitSet_detach_condition (leftUser)");
    status = DDS_WaitSet_detach_condition(userLoadWS, newUser);
    checkStatus(status, "DDS_WaitSet_detach_condition (newUser)");

    /* Free all resources */
    DDS_free(guardList);
    DDS_free(args._buffer);
    DDS_free(userLoadWS);
    DDS_free(escape);
    DDS_free(setting_topic_qos);
    DDS_free(reliable_topic_qos);
    DDS_free(nameServiceTypeName);
    DDS_free(chatMessageTypeName);
    DDS_free(nameServiceTS);
    DDS_free(chatMessageTS);    
    status = DDS_DomainParticipant_delete_contained_entities(participant);
    checkStatus(status, "DDS_DomainParticipant_delete_contained_entities");
    status = DDS_DomainParticipantFactory_delete_participant(
        DDS_TheParticipantFactory, 
        participant);
    checkStatus(status, "DDS_DomainParticipantFactory_delete_participant");
    
    return 0;
}
Exemplo n.º 9
0
int main (int argc, char *argv [])
{
	int domain_id = 128;
	DDS_ReturnCode_t error;

	do_switches (argc, argv);

#ifdef DDS_DEBUG
	DDS_Debug_start ();
#endif
	
	DDS_set_generate_callback (calculate_member_id);
		
	sem_init(&_sync, 0, 0);

	part = DDS_DomainParticipantFactory_create_participant (domain_id, NULL, NULL, 0);
	if (!part)
		fatal ("DDS_DomainParticipantFactory_create_participant () failed!");

	if (tsm_type == 0) {
		error = register_HelloWorldData_type (part);
		if (error) {
			DDS_DomainParticipantFactory_delete_participant (part);
			fatal ("DDS_DomainParticipant_register_type ('HelloWorldData') failed (%s)!", DDS_error (error));
		}

		sm = DDS_INCONSISTENT_TOPIC_STATUS;
		topic = DDS_DomainParticipant_create_topic (part, "HelloWorld", "HelloWorldData",
							    NULL, NULL, sm);
		if (!topic) {
			DDS_DomainParticipantFactory_delete_participant (part);
			fatal ("DDS_DomainParticipant_create_topic ('HelloWorld') failed!");
		}
		
		topic_desc = DDS_DomainParticipant_lookup_topicdescription (part, "HelloWorld");
		if (!topic_desc) {
			DDS_DomainParticipantFactory_delete_participant (part);
			fatal ("Unable to create topic description for 'HelloWorld'!");
		}
	} else {
		_tsm_types[0].flags |= TSMFLAG_KEY;
		error = register_TestType_type (part);
		if (error) {
			DDS_DomainParticipantFactory_delete_participant (part);
			fatal ("DDS_DomainParticipant_register_type ('HelloWorldData') failed (%s)!", DDS_error (error));
		}

		sm = DDS_INCONSISTENT_TOPIC_STATUS;
		topic = DDS_DomainParticipant_create_topic (part, _tsm_types->name, _tsm_types->name,
							    NULL, NULL, sm);
		if (!topic) {
			DDS_DomainParticipantFactory_delete_participant (part);
			fatal ("DDS_DomainParticipant_create_topic ('%s') failed!", _tsm_types->name);
		}
		
		topic_desc = DDS_DomainParticipant_lookup_topicdescription (part, _tsm_types->name);
		if (!topic_desc) {
			DDS_DomainParticipantFactory_delete_participant (part);
			fatal ("Unable to create topic description for '%s'!", _tsm_types->name);
		}
	}

	if (test == 3) {
		/* interop test */
		make_state_reader ();
		make_state_writer (key);
	} else {	
		if (reader)
			make_state_reader ();
		if (writer)
			make_state_writer (key);
	}
	
	if (reader)
		remove_state_reader ();
	if (writer)
		remove_state_writer ();

	if (test == 3) {
		remove_state_reader ();
		remove_state_writer ();
	}

	error = DDS_DomainParticipant_delete_topic (part, topic);
	if (error)
		fatal ("DDS_DomainParticipant_delete_topic () failed (%s)!", DDS_error (error));

	free_HelloWorldData_type (part);
	
	error = DDS_DomainParticipant_delete_contained_entities (part);
	if (error)
		fatal ("DDS_DomainParticipant_delete_contained_entities () failed (%s)!", DDS_error (error));

	error = DDS_DomainParticipantFactory_delete_participant (part);
	if (error)
		fatal ("DDS_DomainParticipantFactory_delete_participant () failed (%s)!", DDS_error (error));

	return (0);

}
Exemplo n.º 10
0
Arquivo: main.c Projeto: bq/qeo-core
int main (int argc, const char *argv [])
{
	DDS_DomainParticipant	part;
	unsigned		sw, sr, dw, dr, i;
	int			error;

	DDS_entity_name ("Technicolor Interop test");

	printf ("Test 1: dynamic type first, then static.\r\n");
	printf ("----------------------------------------\r\n");

	/* Create a domain participant. */
	part = DDS_DomainParticipantFactory_create_participant (
						domain_id, NULL, NULL, 0);
	if (!part)
		fatal ("DDS_DomainParticipantFactory_create_participant () failed!");

	printf ("DDS Domain Participant created.\r\n");

	/* Register the dynamic shape topic type. */
	register_dynamic_type (part);
	printf ("DDS dynamic Topic type registered.\r\n");

	/* Register the static topic type. */
	register_static_type (part);
	printf ("DDS static Topic type registered.\r\n");

	dw = dynamic_writer_create ("Square");
	dr = dynamic_reader_create ("Square");
	sw = static_writer_create ("Square");
	sr = static_reader_create ("Square");
	for (i = 0; i < 10; i++) {
		dynamic_writer_write (dw, "Red", i * 9 + 5, i * 11 + 5);
		static_writer_write (sw, "Yellow", i * 10, i * 12);
		usleep (100000);
	}
	dynamic_writer_delete (dw);
	dynamic_reader_delete (dr);
	static_writer_delete (sw);
	static_reader_delete (sr);

	unregister_dynamic_type ();
	unregister_static_type ();

	error = DDS_DomainParticipant_delete_contained_entities (part);
	if (error)
		fatal ("DDS_DomainParticipant_delete_contained_entities () failed (%s)!", DDS_error (error));

	printf ("DDS Entities deleted\r\n");

	error = DDS_DomainParticipantFactory_delete_participant (part);
	if (error)
		fatal ("DDS_DomainParticipantFactory_delete_participant () failed (%s)!", DDS_error (error));

	printf ("DDS Participant deleted\r\n\r\n");

	printf ("Test 2: static type first, then dynamic.\r\n");
	printf ("----------------------------------------\r\n");

	/* Create a domain participant. */
	part = DDS_DomainParticipantFactory_create_participant (
						domain_id, NULL, NULL, 0);
	if (!part)
		fatal ("DDS_DomainParticipantFactory_create_participant () failed!");

	printf ("DDS Domain Participant created.\r\n");

	/* Register the static topic type. */
	register_static_type (part);
	printf ("DDS static Topic type registered.\r\n");

	/* Register the dynamic shape topic type. */
	register_dynamic_type (part);
	printf ("DDS dynamic Topic type registered.\r\n");

	sw = static_writer_create ("Circle");
	sr = static_reader_create ("Circle");
	dw = dynamic_writer_create ("Circle");
	dr = dynamic_reader_create ("Circle");
	for (i = 0; i < 10; i++) {
		static_writer_write (sw, "Green", i * 11, i * 13);
		dynamic_writer_write (dw, "Magenta", i * 10 + 5, i * 12 + 5);
		usleep (100000);
	}
	static_writer_delete (sw);
	static_reader_delete (sr);
	dynamic_writer_delete (dw);
	dynamic_reader_delete (dr);
	unregister_static_type ();
	unregister_dynamic_type ();
	error = DDS_DomainParticipant_delete_contained_entities (part);
	if (error)
		fatal ("DDS_DomainParticipant_delete_contained_entities () failed (%s)!", DDS_error (error));

	printf ("DDS Entities deleted\r\n");

	error = DDS_DomainParticipantFactory_delete_participant (part);
	if (error)
		fatal ("DDS_DomainParticipantFactory_delete_participant () failed (%s)!", DDS_error (error));

	printf ("DDS Participant deleted\r\n\r\n");

	return (0);
}
Exemplo n.º 11
0
int dds_chat_main(int argc, char *argv[])
#endif
{
	DDS_DataWriterQos 	wr_qos;
	DDS_DataReaderQos	rd_qos;
	DDS_ReturnCode_t	error;	
	struct in_addr addr;

	/* Configure the network */
	/* Set up our host address */
	addr.s_addr = HTONL(CONFIG_EXAMPLES_UDP_IPADDR);
	netlib_sethostaddr("eth0", &addr);

	/* Set up the default router address */
	addr.s_addr = HTONL(CONFIG_EXAMPLES_UDP_DRIPADDR);
	netlib_setdraddr("eth0", &addr);

	/* Setup the subnet mask */
	addr.s_addr = HTONL(CONFIG_EXAMPLES_UDP_NETMASK);
	netlib_setnetmask("eth0", &addr);

  	/* Start the application */
  	printf("Network configured, starting DDS chat:\n");

	sprintf (user_name, ".pid.%u", getpid ());
	do_switches (argc, argv);
	if (verbose > 1)
		DDS_Log_stdio (1);

	DDS_entity_name ("ROS 2.0 embedded");

#ifdef DDS_SECURITY
	if (cert_path || key_path || engine_id)
		enable_security ();
#endif
	part = DDS_DomainParticipantFactory_create_participant (domain_id, NULL, NULL, 0);
	if (!part) {
		printf ("Can't create participant!\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS Domain Participant created.\r\n");

	ts = ChatMsg_type_new ();
	if (!ts) {
		printf ("Can't create chat message type!\r\n");
		exit (1);
	}
	error = DDS_DynamicTypeSupport_register_type (ts, part, "ChatMsg");
	if (error) {
		printf ("Can't register chat message type.\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS Topic type ('%s') registered.\r\n", "ChatMsg");

	topic = DDS_DomainParticipant_create_topic (part, "Chat", "ChatMsg", NULL, NULL, 0);
	if (!topic) {
		printf ("Can't register chat message type.\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS ChatMsg Topic created.\r\n");

	td = DDS_DomainParticipant_lookup_topicdescription (part, "Chat");
	if (!td) {
		printf ("Can't get topicdescription.\r\n");
		exit (1);
	}
	pub = DDS_DomainParticipant_create_publisher (part, NULL, NULL, 0);
	if (!pub) {
		printf ("DDS_DomainParticipant_create_publisher () failed!\r\n");
		exit (1);
	}
	DDS_Publisher_get_default_datawriter_qos (pub, &wr_qos);
#ifdef TRANSIENT_LOCAL
	wr_qos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
#endif
#ifdef RELIABLE
	wr_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
#endif
#ifdef KEEP_ALL
	wr_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS;
	wr_qos.history.depth = DDS_LENGTH_UNLIMITED;
	wr_qos.resource_limits.max_samples_per_instance = HISTORY;
	wr_qos.resource_limits.max_instances = HISTORY * 10;
	wr_qos.resource_limits.max_samples = HISTORY * 4;
#else
	wr_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS;
	wr_qos.history.depth = HISTORY;
#endif
	/* Create a Data Writer. */
	dw = DDS_Publisher_create_datawriter (pub, topic, &wr_qos, NULL, 0);
	if (!dw) {
		printf ("Unable to create chat message writer.\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS Chat message writer created.\r\n");

	sub = DDS_DomainParticipant_create_subscriber (part, NULL, NULL, 0); 
	if (!sub) {
		printf ("DDS_DomainParticipant_create_subscriber () returned an error!\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS Subscriber created.\r\n");

	DDS_Subscriber_get_default_datareader_qos (sub, &rd_qos);
#ifdef TRANSIENT_LOCAL
	rd_qos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
#endif
#ifdef RELIABLE
	rd_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
#endif
#ifdef KEEP_ALL
	rd_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS;
	rd_qos.history.depth = DDS_LENGTH_UNLIMITED;
	rd_qos.resource_limits.max_samples_per_instance = HISTORY;
	rd_qos.resource_limits.max_instances = HISTORY * 10;
	rd_qos.resource_limits.max_samples = HISTORY * 4;
#else
	rd_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS;
	rd_qos.history.depth = HISTORY;
#endif
	dr = DDS_Subscriber_create_datareader (sub, td, &rd_qos,
#ifndef WAITSETS
			 &msg_listener, DDS_DATA_AVAILABLE_STATUS);
#else
			 NULL, 0);
#endif
	if (!dr) {
		printf ("DDS_DomainParticipant_create_datareader () returned an error!\r\n");
		exit (1);
	}
	if (verbose)
		printf ("DDS Chat message reader created.\r\n");

#ifdef WAITSETS
	start_chat_reader (dr);
#endif
	do_chat (dw);

#ifdef WAITSETS
	stop_chat_reader (dr);
#endif
	DDS_Publisher_delete_datawriter (pub, dw);
	usleep (200000);
	error = DDS_DomainParticipant_delete_contained_entities (part);
	if (verbose)
		printf ("DDS Entities deleted (error = %u).\r\n", error);

	ChatMsg_type_free (ts);
	if (verbose)
		printf ("Chat Type deleted.\r\n");

	error = DDS_DomainParticipantFactory_delete_participant (part);
	if (verbose)
		printf ("DDS Participant deleted (error = %u).\r\n", error);

#ifdef DDS_SECURITY
	if (cert_path || key_path || engine_id)
		cleanup_security ();
#endif
	return (0);
}
Exemplo n.º 12
0
static void stub_fini(void)
{
    DDS_DomainParticipant_delete_contained_entities(_dp);
    DDS_DomainParticipantFactory_delete_participant(_dp);
}
Exemplo n.º 13
0
int main(int argc, char* argv[])
{
	int startTime = mstime();
	DDS_PoolConstraints reqs;
	DDS_DomainParticipant    domainParticipant;
	DDS_Publisher    publisher;
	DDS_Subscriber    subscriber;
	DDS_ReturnCode_t retCode;
	char *configTopicName[nofConfigTopics];
	DDS_Topic configTopic[nofConfigTopics];
	DDS_Topic stateTopic[nofStateTopics];
	DDS_Topic statisticTopic[nofStatisticTopics];
	DDS_DataWriterQos dataWriterQos;
	DDS_DataWriter    configDataWriter[nofConfigTopics];
	DDS_DataWriter    stateDataWriter[nofStateTopics];
	DDS_DataWriter    statisticDataWriter[nofStatisticTopics];
	DDS_DataReaderQos dataReaderQos;
	DDS_DataReader    configDataReader[nofConfigTopics];
	acceptance_high_end_Config config;
	acceptance_high_end_State state;
	acceptance_high_end_Statistic statistic;
	DDS_InstanceHandle_t configInstance[nofConfigTopics][nofConfigInstances];
	DDS_InstanceHandle_t stateInstance[nofStateTopics][nofStateInstances];
	DDS_InstanceHandle_t statisticInstance[nofStatisticTopics][nofStatisticInstances];
	int i = 0;
	int j = 0;

	int firstConfigTopic = (argc > 1) ? atoi(argv[1]) : 0;
	int firstStateTopic = (argc > 2) ? atoi(argv[2]) : 0;
	int firstStatisticTopic = (argc > 3) ? atoi(argv[3]) : 0;
	int stagedLoading = (argc > 4) ? atoi(argv[4]) : 0;
	printf("[0] Config topics start at %d...\r\n", firstConfigTopic);
	printf("[0] State topics start at %d...\r\n", firstStateTopic);
	printf("[0] Statistic topics start at %d...\r\n", firstStatisticTopic);
	printf("[0] Staged loading %s.\r\n", stagedLoading ? "on" : "off");

	if (stagedLoading) {
		char file_name[24];
		sprintf(file_name, "/tmp/acceptStageLoad%d", firstConfigTopic);
		struct stat buf;
		if (stat(file_name, &buf)) {
			printf ("[%d] Waiting for %s\r\n", mstime() - startTime, file_name);
			do {
				sleep(1);
			}
			while (stat(file_name, &buf));
			printf ("[%d] Got %s!\r\n", mstime() - startTime, file_name);
		}
	}

        DDS_program_name (&argc, argv);
	DDS_entity_name ("Technicolor Limits Component");
	DDS_get_default_pool_constraints(&reqs, ~0, 100);
#ifdef MINIMAL_POOLS
	configure_minimal_pool_constraints (&reqs);
#else
	configure_optimal_pool_constraints (&reqs);
#endif
	DDS_set_pool_constraints(&reqs);

#ifdef DDS_DEBUG
	DDS_Debug_start ();
#endif

	/* Create domain participant... */
	domainParticipant = DDS_DomainParticipantFactory_create_participant(0, NULL, NULL, 0);
	if (!domainParticipant) {
		fprintf(stderr, "Error creating domain participant.\r\n");
		return -1;
	}
	printf("[%d] Created domain participant.\r\n", mstime() - startTime);
	sleep(1);

	/* Create publisher... */
	publisher = DDS_DomainParticipant_create_publisher(domainParticipant, NULL, NULL, 0);
	if (!publisher) {
		fprintf(stderr, "Error creating publisher.\r\n");
		return -1;
	}
	printf("[%d] Created publisher.\r\n", mstime() - startTime);
	sleep(1);

	/* Create subscriber... */
	subscriber = DDS_DomainParticipant_create_subscriber(domainParticipant, NULL, NULL, 0);
	if (!subscriber) {
		fprintf(stderr, "Error creating subscriber.\r\n");
		return -1;
	}
	printf("[%d] Created subscriber.\r\n", mstime() - startTime);
	sleep(1);

	/* Register types... */
	retCode = acceptance_high_end_ConfigTypeSupport_register_type(domainParticipant, NULL);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode));
		return -1;
	}
	printf("[%d] Registered config type.\r\n", mstime() - startTime);
	retCode = acceptance_high_end_StateTypeSupport_register_type(domainParticipant, NULL);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode));
		return -1;
	}
	printf("[%d] Registered state type.\r\n", mstime() - startTime);
	retCode = acceptance_high_end_StatisticTypeSupport_register_type(domainParticipant, NULL);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode));
		return -1;
	}
	printf("[%d] Registered statistic type.\r\n", mstime() - startTime);
	sleep(1);

	/* Create topics... */
	for (i = 0; i < nofConfigTopics; i++) {
		char topicName[32];
		sprintf(topicName, "ConfigTopic%d", firstConfigTopic + i);
		configTopicName[i] = strdup (topicName);
		configTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_ConfigTypeSupport_get_type_name(), NULL, NULL, 0);
		if (!configTopic[i]) {
			fprintf(stderr, "Error creating topic.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d config topics.\r\n", mstime() - startTime, nofConfigTopics);
	for (i = 0; i < nofStateTopics; i++) {
		char topicName[32];
		sprintf(topicName, "StateTopic%d", firstStateTopic + i);
		stateTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_StateTypeSupport_get_type_name(), NULL, NULL, 0);
		if (!stateTopic[i]) {
			fprintf(stderr, "Error creating topic.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d state topics.\r\n", mstime() - startTime, nofStateTopics);
	for (i = 0; i < nofStatisticTopics; i++) {
		char topicName[32];
		sprintf(topicName, "StatisticTopic%d", firstStatisticTopic + i);
		statisticTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_StatisticTypeSupport_get_type_name(), NULL, NULL, 0);
		if (!statisticTopic[i]) {
			fprintf(stderr, "Error creating topic.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d statistic topics.\r\n", mstime() - startTime, nofStatisticTopics);
	sleep(1);

	/* Create data writers... */
	DDS_Publisher_get_default_datawriter_qos(publisher, &dataWriterQos);
	dataWriterQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
	dataWriterQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
	for (i = 0; i < nofConfigTopics; i++) {
		configDataWriter[i] = DDS_Publisher_create_datawriter(publisher, configTopic[i], &dataWriterQos, NULL, 0);

		if (!configDataWriter[i]) {
			fprintf(stderr, "Error creating data writer.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d config data writers.\r\n", mstime() - startTime, nofConfigTopics);
	DDS_Publisher_get_default_datawriter_qos(publisher, &dataWriterQos);
	dataWriterQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
	dataWriterQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
	for (i = 0; i < nofStateTopics; i++) {
		stateDataWriter[i] = DDS_Publisher_create_datawriter(publisher, stateTopic[i], &dataWriterQos, NULL, 0);
		if (!stateDataWriter[i]) {
			fprintf(stderr, "Error creating data writer.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d state data writers.\r\n", mstime() - startTime, nofStateTopics);
	DDS_Publisher_get_default_datawriter_qos(publisher, &dataWriterQos);
	for (i = 0; i < nofStatisticTopics; i++) {
		statisticDataWriter[i] = DDS_Publisher_create_datawriter(publisher, statisticTopic[i], &dataWriterQos, NULL, 0);
		if (!statisticDataWriter[i]) {
			fprintf(stderr, "Error creating data writer.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d statistic data writers.\r\n", mstime() - startTime, nofStatisticTopics);
	sleep(1);

	/* Create data readers... */
	DDS_Subscriber_get_default_datareader_qos(subscriber, &dataReaderQos);
	dataReaderQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
	dataReaderQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
	for (i = 0; i < nofConfigTopics; i++) {
		configDataReader[i] = DDS_Subscriber_create_datareader(subscriber, DDS_DomainParticipant_lookup_topicdescription(domainParticipant, configTopicName[i]), &dataReaderQos, NULL, 0);
		if (!configDataReader[i]) {
			fprintf(stderr, "Error creating data reader.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d config data readers.\r\n", mstime() - startTime, nofConfigTopics);
	sleep(1);

	/* Register instances... */
	for (i = 0; i < nofConfigTopics; i++) {
		for (j = 0; j < nofConfigInstances; j++) {
			config.key = j;
			configInstance[i][j] = DDS_DataWriter_register_instance(configDataWriter[i], &config);
			if (!configInstance[i][j]) {
				fprintf(stderr, "Error registering instance.\r\n");
				break;
			}
		}
	}
	printf("[%d] Registered %d config instances.\r\n", mstime() - startTime, nofConfigTopics * nofConfigInstances);
	for (i = 0; i < nofStateTopics; i++) {
		for (j = 0; j < nofStateInstances; j++) {
			state.key = j;
			stateInstance[i][j] = DDS_DataWriter_register_instance(stateDataWriter[i], &state);
			if (!stateInstance[i][j]) {
				fprintf(stderr, "Error registering instance.\r\n");
				break;
			}
		}
	}
	printf("[%d] Registered %d state instances.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances);
	for (i = 0; i < nofStatisticTopics; i++) {
		for (j = 0; j < nofStatisticInstances; j++) {
			statistic.key = j;
			statisticInstance[i][j] = DDS_DataWriter_register_instance(statisticDataWriter[i], &statistic);
			if (!statisticInstance[i][j]) {
				fprintf(stderr, "Error registering instance.\r\n");
				break;
			}
		}
	}
	printf("[%d] Registered %d statistic instances.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances);
	sleep(1);

	/* Publish samples... */
	for (i = 0; i < nofConfigTopics; i++) {
		for (j = 0; j < nofConfigInstances; j++) {
			config.key = j;
			retCode = DDS_DataWriter_write(configDataWriter[i], &config, configInstance[i][j]);
			if (retCode != DDS_RETCODE_OK) {
				fprintf(stderr, "Error publishing sample (%s).\r\n", DDS_error(retCode));
				break;
			}
		}
	}
	printf("[%d] Published %d config samples.\r\n", mstime() - startTime, nofConfigTopics * nofConfigInstances);
	for (i = 0; i < nofStateTopics; i++) {
		for (j = 0; j < nofStateInstances; j++) {
			state.key = j;
			retCode = DDS_DataWriter_write(stateDataWriter[i], &state, stateInstance[i][j]);
			if (retCode != DDS_RETCODE_OK) {
				fprintf(stderr, "Error publishing sample (%s).\r\n", DDS_error(retCode));
				break;
			}
		}
	}
	printf("[%d] Published %d state samples.\r\n", mstime() - startTime, nofStateTopics * nofStateInstances);
	for (i = 0; i < nofStatisticTopics; i++) {
		for (j = 0; j < nofStatisticInstances; j++) {
			statistic.key = j;
			retCode = DDS_DataWriter_write(statisticDataWriter[i], &statistic, statisticInstance[i][j]);
			if (retCode != DDS_RETCODE_OK) {
				fprintf(stderr, "Error publishing sample (%s).\r\n", DDS_error(retCode));
				break;
			}
		}
	}
	printf("[%d] Published %d statistic samples.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances);
	sleep(1);

	if (stagedLoading) {
		char file_name[24];
		sprintf(file_name, "/tmp/acceptStageLoad%d", firstConfigTopic + nofConfigTopics);
		FILE *f = fopen(file_name, "w");
		fclose(f);
	}

//	dbg_printf ("Zzzzzzz ... \r\n");
	sleep(TEST_TIME);
//	dbg_printf ("... o?\r\n");

	/* Delete contained entities... */
//	printf (" -- deleting contained entities.\r\n");
	retCode = DDS_DomainParticipant_delete_contained_entities(domainParticipant);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error deleting contained entities.\r\n");
		return -1;
	}

	for (i = 0; i < nofConfigTopics; i++)
		free (configTopicName[i]);

//	printf (" -- contained entities deleted!\r\n");
//	sleep(TEST_TIME);

	/* Delete domain participants... */
	retCode = DDS_DomainParticipantFactory_delete_participant(domainParticipant);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error deleting domain participant.\r\n");
		return -1;
	}

	printf ("[%d] comp completed successfully.\r\n", mstime() - startTime); 
	return 0;
}
Exemplo n.º 14
0
int main() {
    DDS_DomainParticipant * participant = NULL;
    DDS_Topic *             topic = NULL;
    DDS_DataWriter *        data_writer = NULL;
    DDS_StringDataWriter *  string_writer = NULL;
    DDS_ReturnCode_t        retcode;
    char                    sample[MAX_STRING_SIZE];
    int                     main_result = 1; /* error by default */
    
    /* --- Set Up --------------------------------------------------------- */

    /* Uncomment the following lines to increase the verbosity of the log
     * messages output by RTI Connext:
    NDDS_Config_Logger_set_verbosity(
                        NDDS_Config_Logger_get_instance(),
                        NDDS_CONFIG_LOG_VERBOSITY_STATUS_ALL );
    */

    /* Create the domain participant on domain ID 0 */
    participant = DDS_DomainParticipantFactory_create_participant(
                        DDS_TheParticipantFactory,
                        0,                              /* Domain ID */
                        &DDS_PARTICIPANT_QOS_DEFAULT,   /* QoS */
                        NULL,                           /* Listener */
                        DDS_STATUS_MASK_NONE);
    if (participant == NULL) {
        puts("Unable to create domain participant.");
        goto clean_exit;
    }

    /* Create the topic "Hello, World" for the String type */    
    topic = DDS_DomainParticipant_create_topic(
                        participant, 
                        "Hello, World",                        /* Topic name*/
                        DDS_StringTypeSupport_get_type_name(), /* Type name */
                        &DDS_TOPIC_QOS_DEFAULT,                /* Topic QoS */
                        NULL,                                  /* Listener  */
                        DDS_STATUS_MASK_NONE);
    if (topic == NULL) {
        puts("Unable to create topic.");
        goto clean_exit;
    }
    
    /* Create the data writer using the default publisher */
    data_writer = DDS_DomainParticipant_create_datawriter(
                                participant,
                                topic,
                                &DDS_DATAWRITER_QOS_DEFAULT,    /* QoS */
                                NULL,                           /* Listener */
                                DDS_STATUS_MASK_NONE);
    if (data_writer == NULL) {
        puts("Unable to create data writer.");
        goto clean_exit;
    }

    /* Perform a safe type-cast from a generic data writer into a
     * specific data writer for the type "DDS::String"
     */
    string_writer = DDS_StringDataWriter_narrow(data_writer);
    if (string_writer == NULL) {
        /* In this specific case, this will never fail */
        puts("DDS_StringDataWriter_narrow failed.");
        goto clean_exit;
    }

    /* --- Write Data ----------------------------------------------------- */

    puts("Ready to write data.");
    puts("When the subscriber is ready, you can start writing.");
    puts("Press CTRL+C to terminate or enter an empty line to do a clean shutdown.");
    puts("");
    /* RTI provides APIs for detecting when data readers and data writers
     * join the network. You can also configure data durability so that data
     * readers can receive data that were written before they started.
     * However, for the sake of keeping this example as simple as possible,
     * it asks you to wait for both sides to start before continuing.
     */

    for (;;) {
        printf("Please type a message> ");
        if (fgets(sample, MAX_STRING_SIZE-1, stdin) == NULL) {
            break;
        }
        /* Removes the newline from input string */
        sample[strlen(sample)-1] = '\0';
        retcode = DDS_StringDataWriter_write(
                            string_writer, 
                            sample,
                            &DDS_HANDLE_NIL);
        if (retcode != DDS_RETCODE_OK) {
            printf("Write failed: %d\n", retcode);
        }
        if (strlen(sample) == 0) {
            break;
        }
    }

    /* --- Clean Up ------------------------------------------------------- */

    main_result = 0;
clean_exit:
    puts("Exiting...");
    if (participant != NULL) {
        retcode = DDS_DomainParticipant_delete_contained_entities(
                        participant);
        if (retcode != DDS_RETCODE_OK) {
            puts("Deletion failed.");
            main_result = 1;
        }
        retcode = DDS_DomainParticipantFactory_delete_participant(
                        DDS_TheParticipantFactory,
                        participant);
        if (retcode != DDS_RETCODE_OK) {
            puts("Deletion failed.");
            main_result = 1;
        }
    }
    return main_result;
}
Exemplo n.º 15
0
int main(int argc, char* argv[])
{
	int startTime = mstime();
	DDS_PoolConstraints reqs;
	DDS_DomainParticipant    domainParticipant;
	DDS_Publisher    publisher;
	DDS_Subscriber    subscriber;
	DDS_ReturnCode_t retCode;
	char *configTopicName[nofConfigTopics];
	char *stateTopicName[nofStateTopics];
	char *statisticTopicName[nofStatisticTopics];
	DDS_Topic configTopic[nofConfigTopics];
	DDS_Topic stateTopic[nofStateTopics];
	DDS_Topic statisticTopic[nofStatisticTopics];
	DDS_DataWriterQos dataWriterQos;
	DDS_DataWriter    configDataWriter[nofConfigTopics];
	DDS_DataReaderQos dataReaderQos;
	DDS_DataReader    configDataReader[nofConfigTopics];
	DDS_DataReader    stateDataReader[nofStateTopics];
	DDS_DataReader    statisticDataReader[nofStatisticTopics];
#if 0
	acceptance_high_end_Config config;
	acceptance_high_end_State state;
	acceptance_high_end_Statistic statistic;
	DDS_InstanceHandle_t configInstance[nofConfigTopics][nofConfigInstances];
	DDS_InstanceHandle_t stateInstance[nofStateTopics][nofStateInstances];
	DDS_InstanceHandle_t statisticInstance[nofStatisticTopics][nofStatisticInstances];
#endif
	int i = 0;
	/*int j = 0;*/

	int firstConfigTopic = (argc > 1) ? atoi(argv[1]) : 0;
	int firstStateTopic = (argc > 2) ? atoi(argv[2]) : 0;
	int firstStatisticTopic = (argc > 3) ? atoi(argv[3]) : 0;
	int stagedLoading = (argc > 4) ? atoi(argv[4]) : 0;
	printf("[0] Config topics start at %d...\r\n", firstConfigTopic);
	printf("[0] State topics start at %d...\r\n", firstStateTopic);
	printf("[0] Statistic topics start at %d...\r\n", firstStatisticTopic);
	printf("[0] Staged loading %s.\r\n", stagedLoading ? "on" : "off");

        DDS_program_name (&argc, argv);
	DDS_entity_name ("Technicolor Limits Manager");
	DDS_get_default_pool_constraints(&reqs, ~0, 100);
#ifdef MINIMAL_POOLS
	configure_minimal_pool_constraints (&reqs);
#else
	configure_optimal_pool_constraints (&reqs);
#endif
	DDS_set_pool_constraints (&reqs);

#ifdef DDS_DEBUG
	DDS_Debug_start ();
#endif
#ifdef TRACE_DATA
	rtps_dtrace_set (DRTRC_TRACE_ALL);
#endif

	/* Create domain participant... */
	domainParticipant = DDS_DomainParticipantFactory_create_participant(0, NULL, NULL, 0);
	if (!domainParticipant) {
		fprintf(stderr, "Error creating domain participant.\r\n");
		return -1;
	}
	printf("[%d] Created domain participant.\r\n", mstime() - startTime);
	// sleep(1);

	/* Create publisher... */
	publisher = DDS_DomainParticipant_create_publisher(domainParticipant, NULL, NULL, 0);
	if (!publisher) {
		fprintf(stderr, "Error creating publisher.\r\n");
		return -1;
	}
	printf("[%d] Created publisher.\r\n", mstime() - startTime);
	// sleep(1);

	/* Create subscriber... */
	subscriber = DDS_DomainParticipant_create_subscriber(domainParticipant, NULL, NULL, 0);
	if (!subscriber) {
		fprintf(stderr, "Error creating subscriber.\r\n");
		return -1;
	}
	printf("[%d] Created subscriber.\r\n", mstime() - startTime);
	// sleep(1);

	/* Register types... */
	retCode = acceptance_high_end_ConfigTypeSupport_register_type(domainParticipant, NULL);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode));
		return -1;
	}
	printf("[%d] Registered config type.\r\n", mstime() - startTime);
	retCode = acceptance_high_end_StateTypeSupport_register_type(domainParticipant, NULL);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode));
		return -1;
	}
	printf("[%d] Registered state type.\r\n", mstime() - startTime);
	retCode = acceptance_high_end_StatisticTypeSupport_register_type(domainParticipant, NULL);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode));
		return -1;
	}
	printf("[%d] Registered statistic type.\r\n", mstime() - startTime);
	// sleep(1);

	/* Create topics... */
	for (i = 0; i < nofConfigTopics; i++) {
		char topicName[32];
		sprintf(topicName, "ConfigTopic%d", firstConfigTopic + i);
		configTopicName[i] = topicName;
		configTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_ConfigTypeSupport_get_type_name(), NULL, NULL, 0);
		if (!configTopic[i]) {
			fprintf(stderr, "Error creating topic.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d config topics.\r\n", mstime() - startTime, nofConfigTopics);
	for (i = 0; i < nofStateTopics; i++) {
		char topicName[32];
		sprintf(topicName, "StateTopic%d", firstStateTopic + i);
		stateTopicName[i] = topicName;
		stateTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_StateTypeSupport_get_type_name(), NULL, NULL, 0);
		if (!stateTopic[i]) {
			fprintf(stderr, "Error creating topic.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d state topics.\r\n", mstime() - startTime, nofStateTopics);
	for (i = 0; i < nofStatisticTopics; i++) {
		char topicName[32];
		sprintf(topicName, "StatisticTopic%d", firstStatisticTopic + i);
		statisticTopicName[i] = topicName;
		statisticTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_StatisticTypeSupport_get_type_name(), NULL, NULL, 0);
		if (!statisticTopic[i]) {
			fprintf(stderr, "Error creating topic.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d statistic topics.\r\n", mstime() - startTime, nofStatisticTopics);
	// sleep(1);

	/* Create data writers... */
	DDS_Publisher_get_default_datawriter_qos(publisher, &dataWriterQos);
	dataWriterQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
	dataWriterQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
	for (i = 0; i < nofConfigTopics; i++) {
		configDataWriter[i] = DDS_Publisher_create_datawriter(publisher, configTopic[i], &dataWriterQos, NULL, 0);
		if (!configDataWriter[i]) {
			fprintf(stderr, "Error creating data writer.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d config data writers.\r\n", mstime() - startTime, nofConfigTopics);
	// sleep(1);

	/* Create data readers... */
	DDS_Subscriber_get_default_datareader_qos(subscriber, &dataReaderQos);
	dataReaderQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
	dataReaderQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
	for (i = 0; i < nofConfigTopics; i++) {
		configDataReader[i] = DDS_Subscriber_create_datareader(subscriber, DDS_DomainParticipant_lookup_topicdescription(domainParticipant, configTopicName[i]), &dataReaderQos, &configDataReaderListener, DDS_DATA_AVAILABLE_STATUS);
		if (!configDataReader[i]) {
			fprintf(stderr, "Error creating data reader.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d config data readers.\r\n", mstime() - startTime, nofConfigTopics);
	DDS_Subscriber_get_default_datareader_qos(subscriber, &dataReaderQos);
	dataReaderQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
	dataReaderQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
	for (i = 0; i < nofStateTopics; i++) {
		stateDataReader[i] = DDS_Subscriber_create_datareader(subscriber, DDS_DomainParticipant_lookup_topicdescription(domainParticipant, stateTopicName[i]), &dataReaderQos, &stateDataReaderListener, DDS_DATA_AVAILABLE_STATUS);
		if (!stateDataReader[i]) {
			fprintf(stderr, "Error creating data reader.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d state data readers.\r\n", mstime() - startTime, nofStateTopics);
	DDS_Subscriber_get_default_datareader_qos(subscriber, &dataReaderQos);
	for (i = 0; i < nofStatisticTopics; i++) {
		statisticDataReader[i] = DDS_Subscriber_create_datareader(subscriber, DDS_DomainParticipant_lookup_topicdescription(domainParticipant, statisticTopicName[i]), &dataReaderQos, &statisticDataReaderListener, DDS_DATA_AVAILABLE_STATUS);
		if (!statisticDataReader[i]) {
			fprintf(stderr, "Error creating data reader.\r\n");
			return -1;
		}
	}
	printf("[%d] Created %d statistic data readers.\r\n", mstime() - startTime, nofStatisticTopics);
	// sleep(1);

	/* Lookup instances... */
	/*for (i = 0; i < nofConfigTopics; i++) {
		for (j = 0; j < nofConfigInstances; j++) {
			config.key = j;
			configInstance[i][j] = acceptance_high_end_ConfigDataReader_lookup_instance(configDataReader[i], &config);
			if (!configInstance[i][j]) {
				fprintf(stderr, "Error looking up instance.\r\n");
				break;
			}
		}
	}
	printf("[%d] Looked up %d config instances.\r\n", mstime() - startTime, nofConfigTopics * nofConfigInstances);
	for (i = 0; i < nofStateTopics; i++) {
		for (j = 0; j < nofStateInstances; j++) {
			state.key = j;
			stateInstance[i][j] = acceptance_high_end_StateDataReader_lookup_instance(stateDataReader[i], &state);
			if (!stateInstance[i][j]) {
				fprintf(stderr, "Error looking up instance.\r\n");
				break;
			}
		}
	}
	printf("[%d] Looked up %d state instances.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances);
	for (i = 0; i < nofStatisticTopics; i++) {
		for (j = 0; j < nofStatisticInstances; j++) {
			statistic.key = j;
			statisticInstance[i][j] = acceptance_high_end_StatisticDataReader_lookup_instance(statisticDataReader[i], &statistic);
			if (!statisticInstance[i][j]) {
				fprintf(stderr, "Error looking up instance.\r\n");
				break;
			}
		}
	}
	printf("[%d] Looked up %d statistic instances.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances);*/
	// sleep(1);

	if (stagedLoading) {
		char file_name[24];
		sprintf(file_name, "/tmp/acceptStageLoad0");
		FILE *f = fopen(file_name, "w");
		fclose(f);
	}

	int waitTime = mstime();
	int _nofConfigSamples = 0;
	int _nofStateSamples = 0;
	int _nofStatisticSamples = 0;
	while ((mstime() - waitTime) < (TEST_TIME * 1000)) {
		if ((nofConfigSamples > _nofConfigSamples) || (nofStateSamples > _nofStateSamples) || (nofStatisticSamples > _nofStatisticSamples)) {
			printf("[%d] Received %d config samples.\r\n", mstime() - startTime, nofConfigSamples);
			printf("[%d] Received %d state samples.\r\n", mstime() - startTime, nofStateSamples);
			printf("[%d] Received %d statistic samples.\r\n", mstime() - startTime, nofStatisticSamples);
			_nofConfigSamples = nofConfigSamples;
			_nofStateSamples = nofStateSamples;
			_nofStatisticSamples = nofStatisticSamples;
		}
		sleep(1);
	}

	/* Delete contained entities... */
//	printf (" -- Deleting contained entities.\r\n");
	retCode = DDS_DomainParticipant_delete_contained_entities(domainParticipant);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error deleting contained entities.\r\n");
		return -1;
	}

//	printf ("contained entities deleted!\r\n");

	/* Delete domain participants... */
	retCode = DDS_DomainParticipantFactory_delete_participant(domainParticipant);
	if (retCode != DDS_RETCODE_OK) {
		fprintf(stderr, "Error deleting domain participant.\r\n");
		return -1;
	}

	printf ("[%d] mgmt completed successfully.\r\n", mstime() - startTime);
	return 0;
}