Пример #1
0
DDS_Topic DDS_DomainParticipant_create_topic (DDS_DomainParticipant   dp,
					      const char              *topic_name,
					      const char              *type_name,
					      const DDS_TopicQos      *qos,
					      const DDS_TopicListener *listener,
					      DDS_StatusMask          mask)
{
	Topic_t		*tp;
	int		new_topic;

	ctrc_begind (DCPS_ID, DCPS_DP_C_TOP, &dp, sizeof (dp));
	ctrc_contd (topic_name, strlen (topic_name) + 1);
	ctrc_contd (type_name, strlen (type_name) + 1);
	ctrc_contd (&qos, sizeof (qos));
	ctrc_contd (&listener, sizeof (listener));
	ctrc_contd (&mask, sizeof (mask));
	ctrc_endd ();

	prof_start (dcps_create_topic);

	/* Get Domain Participant. */
	if (!domain_ptr (dp, 1, NULL)) {
		log_printf (DCPS_ID, 0, "create_topic(%s): domain doesn't exist!\r\n", topic_name);
		return (NULL);
	}
	if (qos == DDS_TOPIC_QOS_DEFAULT)
		qos = &dp->def_topic_qos;
	else if (!qos_valid_topic_qos (qos)) {
		log_printf (DCPS_ID, 0, "create_topic(%s): invalid topic QoS!\r\n", topic_name);
		lock_release (dp->lock);
		return (NULL);
	}

#ifdef DDS_SECURITY

	/* Check if security policy allows this topic. */
	if (check_create_topic (dp->participant.p_permissions, topic_name, qos)) {
		log_printf (DCPS_ID, 0, "create_topic(%s): topic create not allowed!\r\n", topic_name);
		lock_release (dp->lock);
		return (NULL);
	}
#endif

	/* New topic: create topic context. */
	tp = topic_create (&dp->participant, NULL, topic_name, type_name, &new_topic);
	if (!tp) {
		log_printf (DCPS_ID, 0, "create_topic (%s): out of memory for topic!\r\n", topic_name);
		lock_release (dp->lock);
		return (NULL);
	}

	/* Set Qos fields appropriately. */
	if (new_topic)
		tp->qos = qos_topic_new (qos);
	else if (tp->nlrefs == 1) /* First real QoS setting. */
		qos_topic_update (&tp->qos, qos);

	/* Check if the supplied listener can be set on the topic. Ok, if no
	   listener was previously set or the supplied listener is the same as
	   the previously set listener. */
	if (listener) {
		if (!new_topic && 
		    memcmp (&tp->listener, listener, sizeof (tp->listener)))
			log_printf (DCPS_ID, 0, "create_topic(%s): existing listener updated!\r\n", topic_name);
		tp->listener = *listener;
	}

	/* Check if the mask is the same. */
	if (!new_topic && mask && mask != tp->mask)
		log_printf (DCPS_ID, 0, "create_topic(%s): existing mask updated!\r\n", topic_name);

	tp->mask = mask;
	lock_release (dp->lock);

	if (dp->autoenable)
		DDS_Topic_enable ((DDS_Topic) tp);

	prof_stop (dcps_create_topic, 1);

	return (tp);
}
Пример #2
0
static void test_qos (int enabled)
{
	DDS_DomainParticipantFactoryQos	qos;
	DDS_DomainParticipant		p;
	DDS_Publisher			pub;
	DDS_Subscriber			sub;
	DDS_DataWriter			dw;
	DDS_DataReader			dr;
	DDS_Topic			t;
	DDS_TopicDescription		td;
	DDS_DataReaderQos		rq, refrq;
	DDS_ReturnCode_t		r;
	static unsigned char		data [] = { 0x77, 0x88, 0xaa, 0xbb, 0xcc, 0xdd };
	unsigned char			d2 [sizeof (data) + 1];
	unsigned			n;
	int				err;

	v_printf (" - Set factory QoS to %sabled.\r\n", (enabled) ? "en" : "dis");
	r = DDS_DomainParticipantFactory_get_qos (&qos);
	fail_unless (r == DDS_RETCODE_OK);
	qos.entity_factory.autoenable_created_entities = enabled;
	r = DDS_DomainParticipantFactory_set_qos (&qos);
	fail_unless (r == DDS_RETCODE_OK);

	p = DDS_DomainParticipantFactory_create_participant (0, DDS_PARTICIPANT_QOS_DEFAULT, NULL, 0);
	fail_unless (p != NULL);
	r = register_HelloWorldData_type (p);
	fail_unless (r == DDS_RETCODE_OK);

	t = DDS_DomainParticipant_create_topic (p, "HelloWorld", TYPE_NAME, DDS_TOPIC_QOS_DEFAULT, NULL, 0);
	fail_unless (t != NULL);

	td = DDS_DomainParticipant_lookup_topicdescription (p, "HelloWorld");
	fail_unless (td != NULL);

	sub = DDS_DomainParticipant_create_subscriber (p, NULL, NULL, 0);
	fail_unless (sub != NULL);

	DDS_DataReaderQos__init (&refrq);
	err = dds_seq_from_array (&refrq.user_data, data, sizeof (data));
	fail_unless (err == 0);

	v_printf (" - Create datareader with specific QoS parameters.\r\n");
	dr = DDS_Subscriber_create_datareader (sub, td, &refrq, NULL, 0);
	fail_unless (dr != NULL);

	memset (&rq, 0, sizeof (rq));
	r = DDS_DataReader_get_qos (dr, &rq);
	n = dds_seq_to_array (&rq.user_data, d2, sizeof (d2));
	fail_unless (r == DDS_RETCODE_OK &&
		     DDS_SEQ_LENGTH (refrq.user_data.value) == sizeof (data));
	n = dds_seq_to_array (&rq.user_data, d2, sizeof (d2));
	fail_unless (n == sizeof (data) && !memcmp (data, d2, sizeof (data)));
	DDS_DataReaderQos__clear (&rq);
	r = DDS_Subscriber_delete_datareader (sub, dr);
	fail_unless (r == DDS_RETCODE_OK);

	v_printf (" - Create datareader with default QoS parameters.\r\n");
	dr = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0);
	fail_unless (dr != NULL);
	pub = DDS_DomainParticipant_create_publisher (p, DDS_PUBLISHER_QOS_DEFAULT, NULL, 0);
	fail_unless (sub != NULL);
	dw = DDS_Publisher_create_datawriter (pub, t, DDS_DATAWRITER_QOS_DEFAULT, NULL, 0);
	fail_unless (dw != NULL);

	v_printf (" - Update datareader QoS parameters.\r\n");
	r = DDS_DataReader_get_qos (dr, &rq);
	fail_unless (r == DDS_RETCODE_OK);
	DDS_DataReaderQos__clear (&refrq);
	fail_unless (r == DDS_RETCODE_OK && !memcmp (&rq, &refrq, sizeof (refrq)));
	err = dds_seq_from_array (&refrq.user_data, data, sizeof (data));
	fail_unless (err == 0);

	r = DDS_DataReader_set_qos (dr, &refrq);
	fail_unless (r == DDS_RETCODE_OK);

	delay ();
	r = DDS_DataReader_get_qos (dr, &rq);
	fail_unless (r == DDS_RETCODE_OK &&
		     DDS_SEQ_LENGTH (rq.user_data.value) == sizeof (data));
	n = dds_seq_to_array (&rq.user_data, d2, sizeof (d2));
	fail_unless (n == sizeof (data) && !memcmp (data, d2, sizeof (data)));

	DDS_DataReaderQos__clear (&refrq);
	DDS_DataReaderQos__clear (&rq);

	delay ();
	if (!enabled) {
		v_printf (" - Enable all entities.\r\n");
		r = DDS_DomainParticipant_enable (p);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_Topic_enable (t);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_Publisher_enable (pub);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_Subscriber_enable (sub);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_DataWriter_enable (dw);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_DataReader_enable (dr);
		fail_unless (r == DDS_RETCODE_OK);
		sleep (1);
	}
	r = DDS_Publisher_delete_datawriter (pub, dw);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_Subscriber_delete_datareader (sub, dr);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_publisher (p, pub);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_subscriber (p, sub);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_topic (p, t);
	fail_unless (r == DDS_RETCODE_OK);

	unregister_HelloWorldData_type (p);
	r = DDS_DomainParticipantFactory_delete_participant (p);
	fail_unless (r == DDS_RETCODE_OK);
}
Пример #3
0
static void test_qos (int enabled)
{
	DDS_DomainParticipantFactoryQos	qos;
	DDS_DomainParticipant		p;
	DDS_Publisher			pub;
	DDS_Subscriber			sub;
	DDS_DataWriter			dw;
	DDS_DataReader			dr;
	DDS_Topic			t;
	DDS_TopicDescription		td;
	DDS_SubscriberQos		psq, refsq;
	DDS_ReturnCode_t		r;
	static char			*buf [] = { "Hello", "World" };
	static unsigned char		data [] = { 0x77, 0x88, 0xaa, 0xbb, 0xcc };
	unsigned char			d2 [sizeof (data) + 1];
	unsigned			n;
	size_t				i;
	int				err;

	v_printf (" - Set factory QoS to %sabled.\r\n", (enabled) ? "en" : "dis");
	r = DDS_DomainParticipantFactory_get_qos (&qos);
	fail_unless (r == DDS_RETCODE_OK);
	qos.entity_factory.autoenable_created_entities = enabled;
	r = DDS_DomainParticipantFactory_set_qos (&qos);
	fail_unless (r == DDS_RETCODE_OK);

	p = DDS_DomainParticipantFactory_create_participant (1, DDS_PARTICIPANT_QOS_DEFAULT, NULL, 0);
	fail_unless (p != NULL);
	r = register_HelloWorldData_type (p);
	fail_unless (r == DDS_RETCODE_OK);

	DDS_SubscriberQos__init (&refsq);
	for (i = 0; (size_t) i < sizeof (buf) / sizeof (char *); i++) {
		err = dds_seq_append (&refsq.partition.name, &buf [i]);
		fail_unless (err == 0);
	}
	err = dds_seq_from_array (&refsq.group_data, data, sizeof (data));
	fail_unless (err == 0);
	v_printf (" - Create subscriber with specific QoS parameters.\r\n");
	sub = DDS_DomainParticipant_create_subscriber (p, &refsq, NULL, 0);
	fail_unless (sub != NULL);
	memset (&psq, 0, sizeof (psq));
	r = DDS_Subscriber_get_qos (sub, &psq);
	fail_unless (r == DDS_RETCODE_OK &&
	             DDS_SEQ_LENGTH (refsq.partition.name) == DDS_SEQ_LENGTH (psq.partition.name) &&
		     DDS_SEQ_LENGTH (refsq.group_data.value) == sizeof (data));
	DDS_SEQ_FOREACH (refsq.partition.name, i)
		fail_unless (!strcmp (DDS_SEQ_ITEM (psq.partition.name, i),
				      DDS_SEQ_ITEM (refsq.partition.name, i)));
	n = dds_seq_to_array (&psq.group_data, d2, sizeof (d2));
	fail_unless (n == sizeof (data) && !memcmp (data, d2, sizeof (data)));
	DDS_SubscriberQos__clear (&psq);
	r = DDS_DomainParticipant_delete_subscriber (p, sub);
	fail_unless (r == DDS_RETCODE_OK);

	v_printf (" - Create topic/publisher/writer/subscriber/reader entities.\r\n");
	t = DDS_DomainParticipant_create_topic (p, "HelloWorld", TYPE_NAME, DDS_TOPIC_QOS_DEFAULT, NULL, 0);
	fail_unless (t != NULL);
	td = DDS_DomainParticipant_lookup_topicdescription (p, "HelloWorld");
	fail_unless (td != NULL);
	pub = DDS_DomainParticipant_create_publisher (p, DDS_PUBLISHER_QOS_DEFAULT, NULL, 0);
	fail_unless (pub != NULL);
	dw = DDS_Publisher_create_datawriter (pub, t, DDS_DATAWRITER_QOS_DEFAULT, NULL, 0);
	fail_unless (dw != NULL);
	sub = DDS_DomainParticipant_create_subscriber (p, DDS_SUBSCRIBER_QOS_DEFAULT, NULL, 0);
	fail_unless (sub != NULL);
	dr = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0);
	fail_unless (dr != NULL);

	v_printf (" - Update subscriber QoS.\r\n");
	r = DDS_Subscriber_get_qos (sub, &psq);
	fail_unless (r == DDS_RETCODE_OK);
	DDS_SubscriberQos__clear (&refsq);
	fail_unless (r == DDS_RETCODE_OK && !memcmp (&psq, &refsq, sizeof (refsq)));
	for (i = 0; (size_t) i < sizeof (buf) / sizeof (char *); i++) {
		err = dds_seq_append (&refsq.partition.name, &buf [i]);
		fail_unless (err == 0);
	}
	err = dds_seq_from_array (&refsq.group_data, data, sizeof (data));
	fail_unless (err == 0);

	r = DDS_Subscriber_set_qos (sub, &refsq);
	fail_unless (r == DDS_RETCODE_OK);

	delay ();
	r = DDS_Subscriber_get_qos (sub, &psq);
	fail_unless (r == DDS_RETCODE_OK &&
	             DDS_SEQ_LENGTH (refsq.partition.name) == DDS_SEQ_LENGTH (psq.partition.name) &&
		     DDS_SEQ_LENGTH (psq.group_data.value) == sizeof (data));
	DDS_SEQ_FOREACH (psq.partition.name, i)
		fail_unless (!strcmp (DDS_SEQ_ITEM (psq.partition.name, i),
				      DDS_SEQ_ITEM (refsq.partition.name, i)));
	n = dds_seq_to_array (&psq.group_data, d2, sizeof (d2));
	fail_unless (n == sizeof (data) && !memcmp (data, d2, sizeof (data)));
	DDS_SubscriberQos__clear (&refsq);
	DDS_SubscriberQos__clear (&psq);

	delay ();
	if (!enabled) {
		v_printf (" - Enable child entities.\r\n");
		r = DDS_DomainParticipant_enable (p);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_Topic_enable (t);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_Publisher_enable (pub);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_Subscriber_enable (sub);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_DataWriter_enable (dw);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_DataReader_enable (dr);
		fail_unless (r == DDS_RETCODE_OK);
		sleep (1);
	}

	v_printf (" - Delete child entities.\r\n");
	r = DDS_Publisher_delete_datawriter (pub, dw);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_Subscriber_delete_datareader (sub, dr);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_publisher (p, pub);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_subscriber (p, sub);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_topic (p, t);
	fail_unless (r == DDS_RETCODE_OK);

	unregister_HelloWorldData_type (p);
	r = DDS_DomainParticipantFactory_delete_participant (p);
	fail_unless (r == DDS_RETCODE_OK);
}