Ejemplo n.º 1
0
DDS_ReturnCode_t
DDS_DomainParticipant_delete_simulated_multitopic(
    DDS_DomainParticipant participant,
    DDS_TopicDescription smt 
)
{
    DDS_ReturnCode_t status;
    struct MsgListenerState *listener_state;
    
    /* Obtain all entities mentioned in the listener state. */
    listener_state = (struct MsgListenerState *) msgListener->listener_data;

    /* Remove the DataWriter */
    status = DDS_Publisher_delete_datawriter(multiPub, listener_state->namedMessageDW);
    checkStatus(status, "DDS_Publisher_delete_datawriter");
    
    /* Remove the Publisher. */
    status = DDS_DomainParticipant_delete_publisher(participant, multiPub);
    checkStatus(status, "DDS_DomainParticipant_delete_publisher");
    
    /* Remove the QueryCondition and its parameters. */
    DDS_free(listener_state->nameFinderParams);
    status = DDS_DataReader_delete_readcondition(
        listener_state->nameServiceDR,
        listener_state->nameFinder);
    checkStatus(status, "DDS_DataReader_delete_readcondition");
    
    /* Remove the DataReaders. */
    status = DDS_Subscriber_delete_datareader(multiSub, listener_state->nameServiceDR);
    checkStatus(status, "DDS_Subscriber_delete_datareader");
    status = DDS_Subscriber_delete_datareader(multiSub, listener_state->chatMessageDR);
    checkStatus(status, "DDS_Subscriber_delete_datareader");
    
    /* Remove the DataReaderListener and its state. */
    free(listener_state);
    DDS_free(msgListener);
    
    /* Remove the Subscriber. */
    status = DDS_DomainParticipant_delete_subscriber(participant, multiSub);
    checkStatus(status, "DDS_DomainParticipant_delete_subscriber");
    
    /* Remove the ContentFilteredTopic. */
    status = DDS_DomainParticipant_delete_contentfilteredtopic(participant, filteredMessageTopic);
    checkStatus(status, "DDS_DomainParticipant_delete_contentfilteredtopic");
    
    /* Remove all other topics. */
    status = DDS_DomainParticipant_delete_topic(participant, namedMessageTopic);
    checkStatus(status, "DDS_DomainParticipant_delete_topic (namedMessageTopic)");
    status = DDS_DomainParticipant_delete_topic(participant, nameServiceTopic);
    checkStatus(status, "DDS_DomainParticipant_delete_topic (nameServiceTopic)");
    status = DDS_DomainParticipant_delete_topic(participant, chatMessageTopic);
    checkStatus(status, "DDS_DomainParticipant_delete_topic (chatMessageTopic)");
    
    return status;
}
Ejemplo n.º 2
0
DDS_ContentFilteredTopic DDS_DomainParticipant_create_contentfilteredtopic (
					DDS_DomainParticipant dp,
					const char            *topic_name,
					DDS_Topic             related_topic,
					const char            *filter_expr,
					DDS_StringSeq         *expr_pars)
{
	Topic_t			*tp;
	BCProgram		bc_program;
	FilteredTopic_t		*ftp;
	DDS_ReturnCode_t	ret;
	int			error;
	static const char	ddssql [] = "DDSSQL";

	ctrc_begind (DCPS_ID, DCPS_DP_C_FTOP, &dp, sizeof (dp));
	ctrc_contd (topic_name, strlen (topic_name) + 1);
	ctrc_contd (related_topic, sizeof (DDS_Topic));
	ctrc_contd (filter_expr, strlen (filter_expr) + 1);
	ctrc_contd (&expr_pars, sizeof (expr_pars));
	ctrc_endd ();

	prof_start (dcps_create_ftopic);

	/* Check some required parameters. */
	if (!filter_expr)
		return (NULL);

	/* 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);
	}

	/* Get Original Topic descriptor. */
	tp = topic_ptr (related_topic, 1, &ret);
	if (!tp || tp->domain != dp) {
		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, NULL)) {
		log_printf (DCPS_ID, 0, "create_topic(%s): topic create not allowed!\r\n", topic_name);
		lock_release (dp->lock);
		return (NULL);
	}
#endif

	/* Check filter validity. */
	ret = sql_parse_filter (tp->type->type_support, filter_expr, &bc_program);
	if (ret)
		goto free_locks;

	/* Check required # of parameters. */
	if (expr_pars && DDS_SEQ_LENGTH (*expr_pars) < bc_program.npars)
		goto free_program;

	/* Create the content-filtered topic. */
	ftp = filtered_topic_create (dp, tp, topic_name);
	if (!ftp)
		goto free_program;

	/* Setup filtered topic data. */
	ftp->data.filter.expression = str_new_cstr (filter_expr);
	if (!ftp->data.filter.expression)
		goto free_filtered_topic;

	if (expr_pars) {
		ftp->data.filter.expression_pars = dcps_new_str_pars (expr_pars, &error);
		if (!ftp->data.filter.expression_pars && error)
			goto pars_failed;
	}
	else
		ftp->data.filter.expression_pars = NULL;

	ftp->data.filter.name = str_ref (ftp->topic.name);
	ftp->data.filter.related_name = str_ref (ftp->related->name);
	ftp->data.filter.class_name = str_new_cstr (ddssql);
	if (!ftp->data.filter.name || !ftp->data.filter.related_name || !ftp->data.filter.class_name)
		goto pars_failed;

	ftp->data.program = bc_program;

	bc_cache_init (&ftp->data.cache);

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

	prof_stop (dcps_create_ftopic, 1);
	return (ftp);

    pars_failed:
	lock_release (tp->lock);
	lock_release (dp->lock);
	DDS_DomainParticipant_delete_contentfilteredtopic (dp, ftp);
	return (NULL);

    free_filtered_topic:
    	filtered_topic_delete (ftp);

    free_program:
	xfree (bc_program.buffer);

    free_locks:
	lock_release (tp->lock);
	lock_release (dp->lock);
	return (NULL);
}