Exemple #1
0
DDS::ReturnCode_t
DDS::OpenSplice::Utils::timeIsValid(
    const DDS::Time_t &time,
    os_int64 maxSupportedSeconds)
{
    DDS::ReturnCode_t result = DDS::RETCODE_BAD_PARAMETER;
    os_int64 sec = time.sec;

    if ((time.sec >= 0) && (C_TIME_NANOS(time.nanosec) < 1000000000ULL)) {
        result = DDS::RETCODE_OK;
    } else if ((time.sec == TIMESTAMP_INVALID_SEC) && (time.nanosec == TIMESTAMP_INVALID_NSEC)) {
        CPP_REPORT(result, "Time_t is invalid");
    } else if (sec > maxSupportedSeconds) {
         result = DDS::RETCODE_BAD_PARAMETER;
         if (sec <= OS_TIME_MAX_VALID_SECONDS) {
             CPP_REPORT(result, "Time value [%" PA_PRId64".%u] is not supported, support for time beyond year 2038 is not enabled",
                        sec, time.nanosec);
         } else {
             CPP_REPORT(result, "Time value [%" PA_PRId64".%u] is not supported the time is too large", sec, time.nanosec);
         }
    } else {
        os_int64 sec = time.sec;
        CPP_REPORT(result, "Time_t is invalid, seconds '%" PA_PRId64"', nanoseconds '%u'", sec, time.nanosec);
    }

    return result;
}
Exemple #2
0
DDS::ReturnCode_t
DDS::OpenSplice::ReadCondition::attachToWaitset (
    DDS::WaitSet *waitset
)
{
    DDS::ReturnCode_t result;

    result = this->write_lock ();
    if (result == DDS::RETCODE_OK) {
        if (!this->deinitializing) {
            if (!waitsets->containsElement(waitset)) {
                /* Don't _duplicate the waitset to avoid cyclic references messing up the garbage collection;
                 * it will detach itself when it is destructed. */
                result = waitset->wlReq_attachGeneralCondition(this, u_observable(uQuery));
                if (result == DDS::RETCODE_OK) {
                    DDS::Boolean insertOK;
                    insertOK = waitsets->insertElement(waitset);
                    if (!insertOK) {
                        result = DDS::RETCODE_OUT_OF_RESOURCES;
                        CPP_REPORT(result, "Could not attach to Waitset.");
                    }
                    assert(insertOK);
                }
            } else {
                result = DDS::RETCODE_OK;
            }
        } else {
            /* Do not allow a Condition that is already deinitializing to be attached to a WaitSet. */
            result = DDS::RETCODE_ALREADY_DELETED;
            CPP_REPORT(result, "This ReadCondition is being deleted.");
        }
        this->unlock ();
    }
    return result;
}
Exemple #3
0
DDS::ReturnCode_t
DDS::OpenSplice::Utils::copyTimeIn(
    const DDS::Time_t &from,
    os_timeW &to,
    os_int64 maxSupportedSeconds)
{
    DDS::ReturnCode_t result = DDS::RETCODE_OK;
    os_int64 sec = from.sec;

    if ((from.sec == TIMESTAMP_INVALID_SEC) && (from.nanosec == TIMESTAMP_INVALID_NSEC)) {
        to = OS_TIMEW_INVALID;
    } else if (sec > maxSupportedSeconds) {
        result = DDS::RETCODE_BAD_PARAMETER;
        if (sec <= OS_TIME_MAX_VALID_SECONDS) {
            CPP_REPORT(result, "Time value [%" PA_PRId64".%u] is not supported, support for time beyond year 2038 is not enabled",
                      sec, from.nanosec);
        } else {
            CPP_REPORT(result, "Time value [%" PA_PRId64".%u] is not supported the time is too large", sec, from.nanosec);
        }
    } else if ((from.sec >= 0 && from.nanosec < 1000000000)) {
        to = OS_TIMEW_INIT(from.sec, from.nanosec);
    } else {
        result = DDS::RETCODE_BAD_PARAMETER;
    }

    return result;
}
Exemple #4
0
DDS::ReturnCode_t
DDS::OpenSplice::DataReader::wlReq_deinit ()
{
    DDS::ReturnCode_t result;

    if (this->pimpl->views->getNrElements() != 0) {
        result = DDS::RETCODE_PRECONDITION_NOT_MET;
        CPP_REPORT(result, "DataReader still contains %d DataReaderView entities.",
            this->pimpl->views->getNrElements());
    } else if (this->pimpl->conditions->getNrElements() != 0) {
        result = DDS::RETCODE_PRECONDITION_NOT_MET;
        CPP_REPORT(result, "DataReader still contains %d Condition entities.",
            this->pimpl->conditions->getNrElements());
    } else {
        this->disable_callbacks();

        if (this->pimpl->topic != NULL) {
            result = this->pimpl->topic->write_lock();
            if (result == DDS::RETCODE_OK) {
                this->pimpl->topic->wlReq_decrNrUsers();
                this->pimpl->topic->unlock();
            }
            DDS::release (this->pimpl->topic);
            this->pimpl->topic = NULL;
        }
        if (this->pimpl->subscriber != NULL) {
            DDS::release (this->pimpl->subscriber);
            this->pimpl->subscriber = NULL;
        }
        result = DDS::OpenSplice::Entity::wlReq_deinit();
    }

    return result;
}
DDS::ReturnCode_t
DDS::OpenSplice::DataReaderView::nlReq_init (
    DDS::OpenSplice::DataReader *reader,
    const char *name,
    const DDS::DataReaderViewQos &qos)
{
    DDS::ReturnCode_t result;
    u_dataViewQos uQos = NULL;
    u_dataView uView = NULL;

    assert (reader != NULL);
    assert (name != NULL);
    /* qos consistency already checked in create_view */
    assert (DDS::OpenSplice::Utils::qosIsConsistent(qos) == DDS::RETCODE_OK);

    uQos = u_dataViewQosNew(NULL);
    if (uQos) {
        result = DDS::OpenSplice::Utils::copyQosIn(qos, uQos);
        if (result == DDS::RETCODE_OK) {

            uView = u_dataViewNew(
                    u_dataReader(reader->rlReq_get_user_entity()),
                    name,
                    uQos);

            if (uView) {
                result = DDS::OpenSplice::Entity::nlReq_init (u_entity (uView));
                if (result == DDS::RETCODE_OK) {
                    (void) DDS::DataReader::_duplicate(reader);
                    this->pimpl->reader = reader;
                    setDomainId(reader->getDomainId());
                }
                if (result == DDS::RETCODE_OK) {
                    result = this->pimpl->conditions->init();
                }
            } else {
                result = DDS::RETCODE_OUT_OF_RESOURCES;
                CPP_REPORT(result, "Could not create DataReaderView.");
            }
        }
        u_dataViewQosFree(uQos);
    } else {
        result = DDS::RETCODE_OUT_OF_RESOURCES;
        CPP_REPORT(result, "Could not copy DataReaderViewQos.");
    }

    return result;
}
Exemple #6
0
DDS::ReturnCode_t
DDS::OpenSplice::ReadCondition::take_next_instance (
    DDS::OpenSplice::Entity *source,
    void *data_seq,
    DDS::SampleInfoSeq &info_seq,
    const long max_samples,
    DDS::InstanceHandle_t a_handle,
    void*)
{
    DDS::ReturnCode_t result = DDS::RETCODE_BAD_PARAMETER;

    CPP_REPORT_STACK();

    if (source->rlReq_get_kind() == DATAREADER) {
        result = (dynamic_cast<FooDataReader_impl*>(source))->take_next_instance_internal(data_seq, info_seq, max_samples, a_handle, this->get_sample_state_mask(), this->get_view_state_mask(), this->get_instance_state_mask());
    } else if (source->rlReq_get_kind() == DATAREADERVIEW) {
        result = (dynamic_cast<FooDataReaderView_impl*>(source))->take_next_instance_internal(data_seq, info_seq, max_samples, a_handle, this->get_sample_state_mask(), this->get_view_state_mask(), this->get_instance_state_mask());
    } else {
        CPP_REPORT(result, "Invalid source Entity kind");
    }

    CPP_REPORT_FLUSH(this, (result != DDS::RETCODE_OK) && (result != DDS::RETCODE_NO_DATA) && (result != DDS::RETCODE_HANDLE_EXPIRED));

    return result;
}
Exemple #7
0
DDS::ReturnCode_t
DDS::OpenSplice::ReadCondition::nlReq_init (
    DDS::OpenSplice::Entity *reader,
    DDS::SampleStateMask sample_states,
    DDS::ViewStateMask view_states,
    DDS::InstanceStateMask instance_states)
{
    DDS::ReturnCode_t result = DDS::RETCODE_OK;
    u_reader uReader = NULL;
    u_sampleMask mask = statesMask(sample_states, view_states, instance_states);
    const os_char *kind;

    this->reader = reader;
    this->sample_states = sample_states;
    this->view_states = view_states;
    this->instance_states = instance_states;

    result = DDS::OpenSplice::Condition::nlReq_init();
    if (result == DDS::RETCODE_OK) {
        setDomainId(reader->getDomainId());
        if (reader->rlReq_get_kind() == DATAREADERVIEW) {
            uReader = u_reader(dynamic_cast<DataReaderView*>(reader)->rlReq_get_user_entity ());
            kind = "DataReaderView";
        } else {
            assert (reader->rlReq_get_kind() == DATAREADER);
            uReader = u_reader(dynamic_cast<DataReader*>(reader)->rlReq_get_user_entity ());
            kind = "DataReader";
        }

        if (uReader) {
            if (this->uQuery == NULL) { // Query condition can initialize uQuery before ReadCondition::nlReq_init is called
                                        // from QueryCondition::nlReq_init. In that case, do not create a query here
                this->uQuery = u_queryNew(uReader, NULL, "1=1", NULL, 0, mask);
                if (this->uQuery == NULL) {
                    result = DDS::RETCODE_ERROR;
                    CPP_REPORT(result, "Could not create ReadCondition.");
                }
            }
        } else {
            result = DDS::RETCODE_BAD_PARAMETER;
            CPP_REPORT(result, "%s is not initialized.", kind);
        }
    }
    return result;

}
Exemple #8
0
DDS::ReturnCode_t
DDS::OpenSplice::Utils::booleanIsValid(
    const DDS::Boolean value)
{
    DDS::ReturnCode_t result = DDS::RETCODE_BAD_PARAMETER;

    if (value == (DDS::Boolean)TRUE || value == (DDS::Boolean)FALSE) {
        result = DDS::RETCODE_OK;
    } else {
        CPP_REPORT(result, "Boolean invalid");
    }

    return result;
}
Exemple #9
0
DDS::ReturnCode_t
DDS::OpenSplice::ReadCondition::wlReq_detachFromWaitset (
    DDS::WaitSet *waitset
)
{
    DDS::ReturnCode_t result = DDS::RETCODE_OK;

    if (waitsets->removeElement(waitset)) {
        result = waitset->wlReq_detachGeneralCondition(this, u_observable(uQuery));
    } else {
        /* Unable to take the given waitset is not a problem when de-initializing. */
        if (!this->deinitializing) {
            result = DDS::RETCODE_PRECONDITION_NOT_MET;
            CPP_REPORT(result, "This ReadCondition is being deleted.");
        }
    }
    return result;
}
DDS::ReturnCode_t
DDS::OpenSplice::DataReaderView::wlReq_deinit ()
{
    DDS::ReturnCode_t result;

    if (this->pimpl->conditions->getNrElements() != 0) {
        result = DDS::RETCODE_PRECONDITION_NOT_MET;
        CPP_REPORT(result, "DataReaderView still contains '%d' Condition entities.",
            this->pimpl->conditions->getNrElements());
    } else {
        if (this->pimpl->reader != NULL) {
            DDS::release (this->pimpl->reader);
            this->pimpl->reader = NULL;
        }
        result = DDS::OpenSplice::Entity::wlReq_deinit();
    }

    return result;
}
Exemple #11
0
DDS::ReturnCode_t
DDS::OpenSplice::Utils::durationIsValid(
    const DDS::Duration_t &duration)
{
    DDS::ReturnCode_t result = DDS::RETCODE_BAD_PARAMETER;

    /* Duration is valid, only when range below 1 billion,
     * or when both fields are equal to DURATION_INFINITE.
     */
    if ((duration.sec == DDS::DURATION_INFINITE_SEC &&
         duration.nanosec == DDS::DURATION_INFINITE_NSEC) ||
        (duration.nanosec < 1000000000ULL) )
    {
        result = DDS::RETCODE_OK;
    } else {
        CPP_REPORT(result, "Duration_t is invalid, seconds '%d', nanoseconds '%d'.",
            duration.sec, duration.nanosec);
    }

    return result;
}
Exemple #12
0
DDS::ReturnCode_t
DDS::OpenSplice::DataReader::nlReq_init (
    DDS::OpenSplice::Subscriber *subscriber,
    const DDS::DataReaderQos &qos,
    DDS::OpenSplice::TopicDescription *a_topic,
    const char *name)
{
    DDS::OpenSplice::ContentFilteredTopic *contentFilteredTopic;
    DDS::ULong i = 0;
    DDS::ULong length = 0;
    DDS::ULong bytes = 0;
    DDS::ReturnCode_t result = DDS::RETCODE_OK;
    u_readerQos uReaderQos = NULL;
    u_dataReader uReader = NULL;
    const char *expression = NULL;
    c_value *uParameters = NULL;

    assert (subscriber != NULL);
    /* Only check for QoS consistency here in debug builds. It's unnecessary to
       to verify it twice in release builds. */
    assert (DDS::OpenSplice::Utils::qosIsConsistent (qos) == DDS::RETCODE_OK);
    assert (a_topic != NULL);
    assert (name != NULL);

    uReaderQos = u_readerQosNew (NULL);
    if (uReaderQos != NULL) {
        result = DDS::OpenSplice::Utils::copyQosIn (qos, uReaderQos);
    } else {
        result = DDS::RETCODE_OUT_OF_RESOURCES;
        CPP_REPORT(result, "Could not copy DataReaderQos.");
    }

    if (result == DDS::RETCODE_OK) {
        result = this->pimpl->views->init();
    }

    if (result == DDS::RETCODE_OK) {
        result = this->pimpl->conditions->init();
    }

    if (result == DDS::RETCODE_OK) {
        result = a_topic->write_lock();
        if (result == DDS::RETCODE_OK) {
            expression = a_topic->rlReq_get_topic_expression ();
            assert(expression);
            switch (a_topic->rlReq_get_kind()) {
                case DDS::OpenSplice::CONTENTFILTEREDTOPIC:
                    contentFilteredTopic =
                        dynamic_cast<DDS::OpenSplice::ContentFilteredTopic *>(a_topic);
                    if (contentFilteredTopic != NULL) {
                        length = contentFilteredTopic->filterParameters.length ();
                        if(length > 0) {
                            bytes = length * sizeof (struct c_value);
                            uParameters = (c_value *)os_malloc (bytes);
                            for (i = 0; i < length; i++) {
                                const c_string param = (const c_string) contentFilteredTopic->filterParameters[i].in();
                                uParameters[i] = c_stringValue(param);
                            }
                        }
                    } else {
                        result = DDS::RETCODE_BAD_PARAMETER;
                        CPP_REPORT(result, "a_topic invalid, not of type '%s'",
                            "DDS::OpenSplice::ContentFilteredTopic");
                    }
                    break;
                case DDS::OpenSplice::TOPIC:
                default:
                    uParameters = NULL;
                    break;
            }
        }

        if (result == DDS::RETCODE_OK) {
            uReader = u_dataReaderNew (
                u_subscriber (subscriber->rlReq_get_user_entity ()),
                name,
                expression,
                uParameters,
                length,
                uReaderQos);
            if (uReader == NULL) {
                result = DDS::RETCODE_OUT_OF_RESOURCES;
                CPP_REPORT(result, "Could not create DataReader.");
            }
        }

        if (result == DDS::RETCODE_OK) {
            result = DDS::OpenSplice::Entity::nlReq_init (u_entity (uReader));
            if (result == DDS::RETCODE_OK) {
                (void) DDS::Subscriber::_duplicate(subscriber);
                this->pimpl->subscriber = subscriber;
                (void) DDS::TopicDescription::_duplicate(a_topic);
                this->pimpl->topic = a_topic;
                a_topic->wlReq_incrNrUsers();
                setDomainId(subscriber->getDomainId());

            }
        }

        a_topic->unlock();
    }

    if (uReaderQos) {
        u_readerQosFree (uReaderQos);
    }
    if (uParameters) {
        os_free (uParameters);
    }

    return result;
}